@devicai/ui 0.57.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/README.md +186 -0
  2. package/dist/cjs/api/assistantInfo.js.map +1 -1
  3. package/dist/cjs/api/client.js +17 -1
  4. package/dist/cjs/api/client.js.map +1 -1
  5. package/dist/cjs/api/types.js.map +1 -1
  6. package/dist/cjs/components/AICommandBar/AICommandBar.js +12 -8
  7. package/dist/cjs/components/AICommandBar/AICommandBar.js.map +1 -1
  8. package/dist/cjs/components/AICommandBar/useAICommandBar.js +12 -6
  9. package/dist/cjs/components/AICommandBar/useAICommandBar.js.map +1 -1
  10. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js +19 -15
  11. package/dist/cjs/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  12. package/dist/cjs/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
  13. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js +12 -6
  14. package/dist/cjs/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  15. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js +13 -7
  16. package/dist/cjs/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  17. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js +11 -5
  18. package/dist/cjs/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  19. package/dist/cjs/components/ChatDrawer/ChatDrawer.js +28 -13
  20. package/dist/cjs/components/ChatDrawer/ChatDrawer.js.map +1 -1
  21. package/dist/cjs/components/ChatDrawer/ChatInput.js +21 -15
  22. package/dist/cjs/components/ChatDrawer/ChatInput.js.map +1 -1
  23. package/dist/cjs/components/ChatDrawer/ChatMessages.js +54 -13
  24. package/dist/cjs/components/ChatDrawer/ChatMessages.js.map +1 -1
  25. package/dist/cjs/components/ChatDrawer/CompactionWidget.js +13 -4
  26. package/dist/cjs/components/ChatDrawer/CompactionWidget.js.map +1 -1
  27. package/dist/cjs/components/ChatDrawer/ConversationSelector.js +6 -4
  28. package/dist/cjs/components/ChatDrawer/ConversationSelector.js.map +1 -1
  29. package/dist/cjs/components/ChatDrawer/ErrorBoundary.js.map +1 -1
  30. package/dist/cjs/components/ChatDrawer/GuardrailNotice.js +40 -0
  31. package/dist/cjs/components/ChatDrawer/GuardrailNotice.js.map +1 -0
  32. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js +3 -1
  33. package/dist/cjs/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  34. package/dist/cjs/components/ChatDrawer/LimitBanner.js +19 -9
  35. package/dist/cjs/components/ChatDrawer/LimitBanner.js.map +1 -1
  36. package/dist/cjs/components/ChatDrawer/QueueNotice.js +19 -7
  37. package/dist/cjs/components/ChatDrawer/QueueNotice.js.map +1 -1
  38. package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js +17 -5
  39. package/dist/cjs/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
  40. package/dist/cjs/components/ChatDrawer/ReferenceChip.js +3 -1
  41. package/dist/cjs/components/ChatDrawer/ReferenceChip.js.map +1 -1
  42. package/dist/cjs/components/ChatDrawer/ToolTimeline.js.map +1 -1
  43. package/dist/cjs/components/ChatDrawer/UsageBar.js +23 -18
  44. package/dist/cjs/components/ChatDrawer/UsageBar.js.map +1 -1
  45. package/dist/cjs/components/ChatDrawer/pastedText.js.map +1 -1
  46. package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js +20 -9
  47. package/dist/cjs/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
  48. package/dist/cjs/components/Feedback/FeedbackModal.js +5 -1
  49. package/dist/cjs/components/Feedback/FeedbackModal.js.map +1 -1
  50. package/dist/cjs/components/Feedback/MessageActions.js +3 -1
  51. package/dist/cjs/components/Feedback/MessageActions.js.map +1 -1
  52. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js +12 -8
  53. package/dist/cjs/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
  54. package/dist/cjs/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
  55. package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js +5 -3
  56. package/dist/cjs/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
  57. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js +12 -3
  58. package/dist/cjs/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
  59. package/dist/cjs/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  60. package/dist/cjs/components/IntegrationsModal/IntegrationsPanel.js +34 -24
  61. package/dist/cjs/components/IntegrationsModal/IntegrationsPanel.js.map +1 -1
  62. package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js +15 -6
  63. package/dist/cjs/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
  64. package/dist/cjs/components/IntegrationsModal/McpConnectForm.js +15 -7
  65. package/dist/cjs/components/IntegrationsModal/McpConnectForm.js.map +1 -1
  66. package/dist/cjs/components/IntegrationsModal/McpServersSection.js +32 -19
  67. package/dist/cjs/components/IntegrationsModal/McpServersSection.js.map +1 -1
  68. package/dist/cjs/components/IntegrationsModal/integrationChoice.js.map +1 -1
  69. package/dist/cjs/components/IntegrationsModal/useIntegrations.js +3 -1
  70. package/dist/cjs/components/IntegrationsModal/useIntegrations.js.map +1 -1
  71. package/dist/cjs/components/IntegrationsModal/useTenantMcp.js +3 -1
  72. package/dist/cjs/components/IntegrationsModal/useTenantMcp.js.map +1 -1
  73. package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js +63 -40
  74. package/dist/cjs/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
  75. package/dist/cjs/components/theme.js.map +1 -1
  76. package/dist/cjs/hooks/useDevicChat.js +21 -7
  77. package/dist/cjs/hooks/useDevicChat.js.map +1 -1
  78. package/dist/cjs/hooks/useModelInterface.js.map +1 -1
  79. package/dist/cjs/hooks/usePolling.js +117 -7
  80. package/dist/cjs/hooks/usePolling.js.map +1 -1
  81. package/dist/cjs/hooks/useSpeechRecording.js +8 -4
  82. package/dist/cjs/hooks/useSpeechRecording.js.map +1 -1
  83. package/dist/cjs/i18n/translate.js +48 -0
  84. package/dist/cjs/i18n/translate.js.map +1 -0
  85. package/dist/cjs/i18n/useTranslations.js +57 -0
  86. package/dist/cjs/i18n/useTranslations.js.map +1 -0
  87. package/dist/cjs/index.js +11 -0
  88. package/dist/cjs/index.js.map +1 -1
  89. package/dist/cjs/provider/DevicContext.js.map +1 -1
  90. package/dist/cjs/provider/DevicProvider.js +5 -1
  91. package/dist/cjs/provider/DevicProvider.js.map +1 -1
  92. package/dist/cjs/provider/sharedSession.js.map +1 -1
  93. package/dist/cjs/styles.css +1 -1
  94. package/dist/cjs/utils/avatar.js.map +1 -1
  95. package/dist/cjs/utils/consumeChatStream.js +44 -0
  96. package/dist/cjs/utils/consumeChatStream.js.map +1 -0
  97. package/dist/cjs/utils/index.js.map +1 -1
  98. package/dist/cjs/utils/logger.js.map +1 -1
  99. package/dist/cjs/utils/toolGroups.js.map +1 -1
  100. package/dist/esm/api/assistantInfo.js.map +1 -1
  101. package/dist/esm/api/client.d.ts +5 -1
  102. package/dist/esm/api/client.js +17 -1
  103. package/dist/esm/api/client.js.map +1 -1
  104. package/dist/esm/api/types.d.ts +12 -1
  105. package/dist/esm/api/types.js.map +1 -1
  106. package/dist/esm/components/AICommandBar/AICommandBar.js +13 -9
  107. package/dist/esm/components/AICommandBar/AICommandBar.js.map +1 -1
  108. package/dist/esm/components/AICommandBar/AICommandBar.types.d.ts +16 -0
  109. package/dist/esm/components/AICommandBar/useAICommandBar.d.ts +2 -0
  110. package/dist/esm/components/AICommandBar/useAICommandBar.js +13 -7
  111. package/dist/esm/components/AICommandBar/useAICommandBar.js.map +1 -1
  112. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js +19 -15
  113. package/dist/esm/components/AIElementWrapper/AIElementWrapper.js.map +1 -1
  114. package/dist/esm/components/AIElementWrapper/AIElementWrapper.types.d.ts +16 -0
  115. package/dist/esm/components/AIElementWrapper/activeWrapperRegistry.js.map +1 -1
  116. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.d.ts +2 -0
  117. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js +13 -7
  118. package/dist/esm/components/AIElementWrapper/useAIElementWrapper.js.map +1 -1
  119. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js +14 -8
  120. package/dist/esm/components/AIGenerationButton/AIGenerationButton.js.map +1 -1
  121. package/dist/esm/components/AIGenerationButton/AIGenerationButton.types.d.ts +16 -0
  122. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.d.ts +2 -0
  123. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js +12 -6
  124. package/dist/esm/components/AIGenerationButton/useAIGenerationButton.js.map +1 -1
  125. package/dist/esm/components/ChatDrawer/ChatDrawer.js +29 -14
  126. package/dist/esm/components/ChatDrawer/ChatDrawer.js.map +1 -1
  127. package/dist/esm/components/ChatDrawer/ChatDrawer.types.d.ts +41 -0
  128. package/dist/esm/components/ChatDrawer/ChatInput.js +21 -15
  129. package/dist/esm/components/ChatDrawer/ChatInput.js.map +1 -1
  130. package/dist/esm/components/ChatDrawer/ChatMessages.d.ts +1 -1
  131. package/dist/esm/components/ChatDrawer/ChatMessages.js +54 -13
  132. package/dist/esm/components/ChatDrawer/ChatMessages.js.map +1 -1
  133. package/dist/esm/components/ChatDrawer/CompactionWidget.js +13 -4
  134. package/dist/esm/components/ChatDrawer/CompactionWidget.js.map +1 -1
  135. package/dist/esm/components/ChatDrawer/ConversationSelector.js +6 -4
  136. package/dist/esm/components/ChatDrawer/ConversationSelector.js.map +1 -1
  137. package/dist/esm/components/ChatDrawer/ErrorBoundary.js.map +1 -1
  138. package/dist/esm/components/ChatDrawer/GuardrailNotice.d.ts +36 -0
  139. package/dist/esm/components/ChatDrawer/GuardrailNotice.js +38 -0
  140. package/dist/esm/components/ChatDrawer/GuardrailNotice.js.map +1 -0
  141. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js +3 -1
  142. package/dist/esm/components/ChatDrawer/HandoffSubagentWidget.js.map +1 -1
  143. package/dist/esm/components/ChatDrawer/LimitBanner.js +19 -9
  144. package/dist/esm/components/ChatDrawer/LimitBanner.js.map +1 -1
  145. package/dist/esm/components/ChatDrawer/QueueNotice.js +19 -7
  146. package/dist/esm/components/ChatDrawer/QueueNotice.js.map +1 -1
  147. package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js +17 -5
  148. package/dist/esm/components/ChatDrawer/RecalledMemoriesWidget.js.map +1 -1
  149. package/dist/esm/components/ChatDrawer/ReferenceChip.js +3 -1
  150. package/dist/esm/components/ChatDrawer/ReferenceChip.js.map +1 -1
  151. package/dist/esm/components/ChatDrawer/ToolTimeline.js.map +1 -1
  152. package/dist/esm/components/ChatDrawer/UsageBar.js +23 -18
  153. package/dist/esm/components/ChatDrawer/UsageBar.js.map +1 -1
  154. package/dist/esm/components/ChatDrawer/index.d.ts +2 -0
  155. package/dist/esm/components/ChatDrawer/pastedText.js.map +1 -1
  156. package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js +20 -9
  157. package/dist/esm/components/CoreMemoryModal/CoreMemoryModal.js.map +1 -1
  158. package/dist/esm/components/Feedback/FeedbackModal.js +5 -1
  159. package/dist/esm/components/Feedback/FeedbackModal.js.map +1 -1
  160. package/dist/esm/components/Feedback/MessageActions.js +3 -1
  161. package/dist/esm/components/Feedback/MessageActions.js.map +1 -1
  162. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js +12 -8
  163. package/dist/esm/components/IntegrationsModal/ConnectFieldsForm.js.map +1 -1
  164. package/dist/esm/components/IntegrationsModal/IntegrationLogo.js.map +1 -1
  165. package/dist/esm/components/IntegrationsModal/IntegrationsHint.js +5 -3
  166. package/dist/esm/components/IntegrationsModal/IntegrationsHint.js.map +1 -1
  167. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js +12 -3
  168. package/dist/esm/components/IntegrationsModal/IntegrationsLauncher.js.map +1 -1
  169. package/dist/esm/components/IntegrationsModal/IntegrationsModal.js.map +1 -1
  170. package/dist/esm/components/IntegrationsModal/IntegrationsPanel.d.ts +1 -1
  171. package/dist/esm/components/IntegrationsModal/IntegrationsPanel.js +34 -24
  172. package/dist/esm/components/IntegrationsModal/IntegrationsPanel.js.map +1 -1
  173. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.d.ts +1 -1
  174. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js +15 -6
  175. package/dist/esm/components/IntegrationsModal/IntegrationsToggle.js.map +1 -1
  176. package/dist/esm/components/IntegrationsModal/McpConnectForm.js +15 -7
  177. package/dist/esm/components/IntegrationsModal/McpConnectForm.js.map +1 -1
  178. package/dist/esm/components/IntegrationsModal/McpServersSection.js +32 -19
  179. package/dist/esm/components/IntegrationsModal/McpServersSection.js.map +1 -1
  180. package/dist/esm/components/IntegrationsModal/integrationChoice.js.map +1 -1
  181. package/dist/esm/components/IntegrationsModal/useIntegrations.js +3 -1
  182. package/dist/esm/components/IntegrationsModal/useIntegrations.js.map +1 -1
  183. package/dist/esm/components/IntegrationsModal/useTenantMcp.js +3 -1
  184. package/dist/esm/components/IntegrationsModal/useTenantMcp.js.map +1 -1
  185. package/dist/esm/components/ThreadStateTag/ThreadStateTag.js +63 -40
  186. package/dist/esm/components/ThreadStateTag/ThreadStateTag.js.map +1 -1
  187. package/dist/esm/components/theme.js.map +1 -1
  188. package/dist/esm/hooks/index.d.ts +1 -1
  189. package/dist/esm/hooks/useDevicChat.d.ts +6 -0
  190. package/dist/esm/hooks/useDevicChat.js +23 -9
  191. package/dist/esm/hooks/useDevicChat.js.map +1 -1
  192. package/dist/esm/hooks/useModelInterface.js.map +1 -1
  193. package/dist/esm/hooks/usePolling.d.ts +35 -0
  194. package/dist/esm/hooks/usePolling.js +114 -8
  195. package/dist/esm/hooks/usePolling.js.map +1 -1
  196. package/dist/esm/hooks/useSpeechRecording.js +8 -4
  197. package/dist/esm/hooks/useSpeechRecording.js.map +1 -1
  198. package/dist/esm/i18n/index.d.ts +4 -0
  199. package/dist/esm/i18n/translate.d.ts +23 -0
  200. package/dist/esm/i18n/translate.js +43 -0
  201. package/dist/esm/i18n/translate.js.map +1 -0
  202. package/dist/esm/i18n/types.d.ts +27 -0
  203. package/dist/esm/i18n/useTranslations.d.ts +32 -0
  204. package/dist/esm/i18n/useTranslations.js +53 -0
  205. package/dist/esm/i18n/useTranslations.js.map +1 -0
  206. package/dist/esm/index.d.ts +4 -2
  207. package/dist/esm/index.js +3 -0
  208. package/dist/esm/index.js.map +1 -1
  209. package/dist/esm/provider/DevicContext.js.map +1 -1
  210. package/dist/esm/provider/DevicProvider.d.ts +1 -1
  211. package/dist/esm/provider/DevicProvider.js +5 -1
  212. package/dist/esm/provider/DevicProvider.js.map +1 -1
  213. package/dist/esm/provider/sharedSession.js.map +1 -1
  214. package/dist/esm/provider/types.d.ts +51 -0
  215. package/dist/esm/styles.css +1 -1
  216. package/dist/esm/utils/avatar.js.map +1 -1
  217. package/dist/esm/utils/consumeChatStream.d.ts +6 -0
  218. package/dist/esm/utils/consumeChatStream.js +42 -0
  219. package/dist/esm/utils/consumeChatStream.js.map +1 -0
  220. package/dist/esm/utils/index.js.map +1 -1
  221. package/dist/esm/utils/logger.js.map +1 -1
  222. package/dist/esm/utils/toolGroups.js.map +1 -1
  223. package/package.json +3 -1
@@ -0,0 +1,53 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useMemo, useContext } from 'react';
3
+ import { useOptionalDevicContext } from '../provider/DevicContext.js';
4
+ import { createTranslator, mergeTranslations } from './translate.js';
5
+
6
+ /**
7
+ * Dictionary contributed by an enclosing component, on top of the provider's.
8
+ *
9
+ * It exists so `<ChatDrawer options={{ translations }}>` reaches the input,
10
+ * the message list and the dialogs it opens without every one of them taking
11
+ * a prop for it. Nesting merges rather than replaces.
12
+ */
13
+ const TranslationsScope = createContext(undefined);
14
+ /**
15
+ * Scopes a dictionary to a subtree. Rarely needed directly — the components
16
+ * that take a `translations` option already wrap their own subtree with it —
17
+ * but useful to translate one region of a page differently.
18
+ */
19
+ function DevicTranslationsProvider({ translations, children, }) {
20
+ const outer = useContext(TranslationsScope);
21
+ const value = useMemo(() => mergeTranslations(outer, translations), [outer, translations]);
22
+ return (jsx(TranslationsScope.Provider, { value: value, children: children }));
23
+ }
24
+ /**
25
+ * The dictionary in force here: the provider's, plus any scoped by an
26
+ * enclosing component, plus the `local` argument. Later layers win.
27
+ */
28
+ function useTranslationsDictionary(local) {
29
+ const context = useOptionalDevicContext();
30
+ const scoped = useContext(TranslationsScope);
31
+ const global = context?.translations;
32
+ return useMemo(() => mergeTranslations(global, scoped, local), [global, scoped, local]);
33
+ }
34
+ /**
35
+ * Returns `t`, the translator for every text this library renders itself.
36
+ *
37
+ * Works with or without a `DevicProvider`: with no dictionary anywhere it
38
+ * returns the English text unchanged, which is what a component mounted
39
+ * standalone gets.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * const t = useTranslations();
44
+ * <button aria-label={t('New chat')}>…</button>
45
+ * ```
46
+ */
47
+ function useTranslations(local) {
48
+ const dictionary = useTranslationsDictionary(local);
49
+ return useMemo(() => createTranslator(dictionary), [dictionary]);
50
+ }
51
+
52
+ export { DevicTranslationsProvider, useTranslations, useTranslationsDictionary };
53
+ //# sourceMappingURL=useTranslations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTranslations.js","sources":["../../../src/i18n/useTranslations.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from 'react';\nimport { useOptionalDevicContext } from '../provider/DevicContext';\nimport { createTranslator, mergeTranslations } from './translate';\nimport type { DevicTranslations, Translator } from './types';\n\n/**\n * Dictionary contributed by an enclosing component, on top of the provider's.\n *\n * It exists so `<ChatDrawer options={{ translations }}>` reaches the input,\n * the message list and the dialogs it opens without every one of them taking\n * a prop for it. Nesting merges rather than replaces.\n */\nconst TranslationsScope = createContext<DevicTranslations | undefined>(undefined);\n\nexport interface DevicTranslationsProviderProps {\n /** Entries added on top of the enclosing dictionaries. */\n translations?: DevicTranslations;\n children: React.ReactNode;\n}\n\n/**\n * Scopes a dictionary to a subtree. Rarely needed directly — the components\n * that take a `translations` option already wrap their own subtree with it —\n * but useful to translate one region of a page differently.\n */\nexport function DevicTranslationsProvider({\n translations,\n children,\n}: DevicTranslationsProviderProps): JSX.Element {\n const outer = useContext(TranslationsScope);\n const value = useMemo(\n () => mergeTranslations(outer, translations),\n [outer, translations]\n );\n return (\n <TranslationsScope.Provider value={value}>\n {children}\n </TranslationsScope.Provider>\n );\n}\n\n/**\n * The dictionary in force here: the provider's, plus any scoped by an\n * enclosing component, plus the `local` argument. Later layers win.\n */\nexport function useTranslationsDictionary(\n local?: DevicTranslations\n): DevicTranslations | undefined {\n const context = useOptionalDevicContext();\n const scoped = useContext(TranslationsScope);\n const global = context?.translations;\n return useMemo(\n () => mergeTranslations(global, scoped, local),\n [global, scoped, local]\n );\n}\n\n/**\n * Returns `t`, the translator for every text this library renders itself.\n *\n * Works with or without a `DevicProvider`: with no dictionary anywhere it\n * returns the English text unchanged, which is what a component mounted\n * standalone gets.\n *\n * @example\n * ```tsx\n * const t = useTranslations();\n * <button aria-label={t('New chat')}>…</button>\n * ```\n */\nexport function useTranslations(local?: DevicTranslations): Translator {\n const dictionary = useTranslationsDictionary(local);\n return useMemo(() => createTranslator(dictionary), [dictionary]);\n}\n"],"names":["_jsx"],"mappings":";;;;;AAKA;;;;;;AAMG;AACH,MAAM,iBAAiB,GAAG,aAAa,CAAgC,SAAS,CAAC;AAQjF;;;;AAIG;SACa,yBAAyB,CAAC,EACxC,YAAY,EACZ,QAAQ,GACuB,EAAA;AAC/B,IAAA,MAAM,KAAK,GAAG,UAAU,CAAC,iBAAiB,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CACnB,MAAM,iBAAiB,CAAC,KAAK,EAAE,YAAY,CAAC,EAC5C,CAAC,KAAK,EAAE,YAAY,CAAC,CACtB;AACD,IAAA,QACEA,GAAA,CAAC,iBAAiB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA,QAAA,EACrC,QAAQ,EAAA,CACkB;AAEjC;AAEA;;;AAGG;AACG,SAAU,yBAAyB,CACvC,KAAyB,EAAA;AAEzB,IAAA,MAAM,OAAO,GAAG,uBAAuB,EAAE;AACzC,IAAA,MAAM,MAAM,GAAG,UAAU,CAAC,iBAAiB,CAAC;AAC5C,IAAA,MAAM,MAAM,GAAG,OAAO,EAAE,YAAY;IACpC,OAAO,OAAO,CACZ,MAAM,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAC9C,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CACxB;AACH;AAEA;;;;;;;;;;;;AAYG;AACG,SAAU,eAAe,CAAC,KAAyB,EAAA;AACvD,IAAA,MAAM,UAAU,GAAG,yBAAyB,CAAC,KAAK,CAAC;AACnD,IAAA,OAAO,OAAO,CAAC,MAAM,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AAClE;;;;"}
@@ -1,7 +1,9 @@
1
1
  export { DevicProvider, DevicContext, useDevicContext, useOptionalDevicContext } from './provider';
2
2
  export type { DevicProviderConfig, DevicProviderProps, DevicContextValue, TenantMetadata, SubtenantMetadata, AIReference, DrawerRegistration, } from './provider';
3
- export { ChatDrawer, ChatMessages, ChatInput, ToolTimeline, ConversationSelector, HandoffSubagentWidget, ReferenceChip, UsageBar, LimitBanner, QueueNotice, RecalledMemoriesWidget, CompactionWidget } from './components/ChatDrawer';
4
- export type { ChatDrawerProps, ChatDrawerOptions, ChatDrawerHandle, ChatMessagesProps, ChatInputProps, CustomPromptBoxProps, MessageBubbleRenderer, MessageBubbleRendererProps, ToolTimelineProps, AllowedFileTypes, ConversationSelectorProps, HandoffSubagentWidgetProps, ReferenceChipProps, ReferenceChipVariant, SuggestedMessage, UsageBarProps, UsageBarDisplay, UsageBarData, LimitBannerProps, QueueNoticeProps, RecalledMemoriesWidgetProps, RecalledMemoriesRenderer, RecalledMemoriesRendererProps, CompactionWidgetProps, CompactionRenderer, CompactionRendererProps, } from './components/ChatDrawer';
3
+ export { DevicTranslationsProvider, useTranslations, useTranslationsDictionary, createTranslator, translate, mergeTranslations, fillTemplate, } from './i18n';
4
+ export type { DevicTranslations, Translator, DevicTranslationsProviderProps, } from './i18n';
5
+ export { ChatDrawer, ChatMessages, ChatInput, ToolTimeline, ConversationSelector, HandoffSubagentWidget, ReferenceChip, UsageBar, LimitBanner, QueueNotice, RecalledMemoriesWidget, CompactionWidget, GuardrailNotice } from './components/ChatDrawer';
6
+ export type { ChatDrawerProps, ChatDrawerOptions, ChatDrawerHandle, ChatMessagesProps, ChatInputProps, CustomPromptBoxProps, MessageBubbleRenderer, MessageBubbleRendererProps, ToolTimelineProps, AllowedFileTypes, ConversationSelectorProps, HandoffSubagentWidgetProps, ReferenceChipProps, ReferenceChipVariant, SuggestedMessage, UsageBarProps, UsageBarDisplay, UsageBarData, LimitBannerProps, QueueNoticeProps, RecalledMemoriesWidgetProps, RecalledMemoriesRenderer, RecalledMemoriesRendererProps, CompactionWidgetProps, CompactionRenderer, CompactionRendererProps, GuardrailNoticeProps, GuardrailRenderer, GuardrailPayload, } from './components/ChatDrawer';
5
7
  export { CoreMemoryModal, DEFAULT_CORE_MEMORY_LABELS } from './components/CoreMemoryModal';
6
8
  export type { CoreMemoryModalProps, CoreMemoryLabels } from './components/CoreMemoryModal';
7
9
  export { IntegrationsModal, IntegrationsPanel, IntegrationsLauncher, IntegrationsHint, IntegrationLogo, useIntegrations, McpServersSection, McpConnectForm, useTenantMcp, integrationChoiceKey, readIntegrationChoice, writeIntegrationChoice, pruneIntegrationChoice, } from './components/IntegrationsModal';
package/dist/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export { DevicProvider } from './provider/DevicProvider.js';
2
2
  export { DevicContext, useDevicContext, useOptionalDevicContext } from './provider/DevicContext.js';
3
+ export { DevicTranslationsProvider, useTranslations, useTranslationsDictionary } from './i18n/useTranslations.js';
4
+ export { createTranslator, fillTemplate, mergeTranslations, translate } from './i18n/translate.js';
3
5
  export { ChatDrawer } from './components/ChatDrawer/ChatDrawer.js';
4
6
  export { ChatMessages } from './components/ChatDrawer/ChatMessages.js';
5
7
  export { ChatInput } from './components/ChatDrawer/ChatInput.js';
@@ -12,6 +14,7 @@ export { LimitBanner } from './components/ChatDrawer/LimitBanner.js';
12
14
  export { QueueNotice } from './components/ChatDrawer/QueueNotice.js';
13
15
  export { RecalledMemoriesWidget } from './components/ChatDrawer/RecalledMemoriesWidget.js';
14
16
  export { CompactionWidget } from './components/ChatDrawer/CompactionWidget.js';
17
+ export { GuardrailNotice } from './components/ChatDrawer/GuardrailNotice.js';
15
18
  export { CoreMemoryModal, DEFAULT_CORE_MEMORY_LABELS } from './components/CoreMemoryModal/CoreMemoryModal.js';
16
19
  export { IntegrationsModal } from './components/IntegrationsModal/IntegrationsModal.js';
17
20
  export { IntegrationsPanel } from './components/IntegrationsModal/IntegrationsPanel.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"DevicContext.js","sources":["../../../src/provider/DevicContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { DevicContextValue } from './types';\n\n/**\n * Context for Devic configuration\n */\nexport const DevicContext = createContext<DevicContextValue | null>(null);\n\n/**\n * Hook to access the Devic context\n * @throws Error if used outside of DevicProvider\n */\nexport function useDevicContext(): DevicContextValue {\n const context = useContext(DevicContext);\n if (!context) {\n throw new Error(\n 'useDevicContext must be used within a DevicProvider. ' +\n 'Make sure to wrap your component tree with <DevicProvider>.'\n );\n }\n return context;\n}\n\n/**\n * Hook to optionally access the Devic context\n * Returns null if not within a provider (for components that can work standalone)\n */\nexport function useOptionalDevicContext(): DevicContextValue | null {\n return useContext(DevicContext);\n}\n"],"names":[],"mappings":";;AAGA;;AAEG;MACU,YAAY,GAAG,aAAa,CAA2B,IAAI;AAExE;;;AAGG;SACa,eAAe,GAAA;AAC7B,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,uDAAuD;AACvD,YAAA,6DAA6D,CAC9D;IACH;AACA,IAAA,OAAO,OAAO;AAChB;AAEA;;;AAGG;SACa,uBAAuB,GAAA;AACrC,IAAA,OAAO,UAAU,CAAC,YAAY,CAAC;AACjC;;"}
1
+ {"version":3,"file":"DevicContext.js","sources":["../../../src/provider/DevicContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { DevicContextValue } from './types';\n\n/**\n * Context for Devic configuration\n */\nexport const DevicContext = createContext<DevicContextValue | null>(null);\n\n/**\n * Hook to access the Devic context\n * @throws Error if used outside of DevicProvider\n */\nexport function useDevicContext(): DevicContextValue {\n const context = useContext(DevicContext);\n if (!context) {\n throw new Error(\n 'useDevicContext must be used within a DevicProvider. ' +\n 'Make sure to wrap your component tree with <DevicProvider>.'\n );\n }\n return context;\n}\n\n/**\n * Hook to optionally access the Devic context\n * Returns null if not within a provider (for components that can work standalone)\n */\nexport function useOptionalDevicContext(): DevicContextValue | null {\n return useContext(DevicContext);\n}\n"],"names":[],"mappings":";;AAGA;;AAEG;MACU,YAAY,GAAG,aAAa,CAA2B,IAAI;AAExE;;;AAGG;SACa,eAAe,GAAA;AAC7B,IAAA,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,uDAAuD;AACvD,YAAA,6DAA6D,CAC9D;IACH;AACA,IAAA,OAAO,OAAO;AAChB;AAEA;;;AAGG;SACa,uBAAuB,GAAA;AACrC,IAAA,OAAO,UAAU,CAAC,YAAY,CAAC;AACjC;;;;"}
@@ -14,4 +14,4 @@ import type { DevicProviderProps } from './types';
14
14
  * </DevicProvider>
15
15
  * ```
16
16
  */
17
- export declare function DevicProvider({ apiKey, getTenantSession, onSessionExpired, baseUrl, tenantId, tenantMetadata, subtenantId, subtenantMetadata, tags, pollingInterval, debug, children, }: DevicProviderProps): JSX.Element;
17
+ export declare function DevicProvider({ apiKey, getTenantSession, onSessionExpired, baseUrl, tenantId, tenantMetadata, subtenantId, subtenantMetadata, tags, pollingInterval, streaming, translations, debug, children, }: DevicProviderProps): JSX.Element;
@@ -21,7 +21,7 @@ const DEFAULT_BASE_URL = 'https://api.devic.ai';
21
21
  * </DevicProvider>
22
22
  * ```
23
23
  */
24
- function DevicProvider({ apiKey, getTenantSession, onSessionExpired, baseUrl = DEFAULT_BASE_URL, tenantId, tenantMetadata, subtenantId, subtenantMetadata, tags, pollingInterval, debug, children, }) {
24
+ function DevicProvider({ apiKey, getTenantSession, onSessionExpired, baseUrl = DEFAULT_BASE_URL, tenantId, tenantMetadata, subtenantId, subtenantMetadata, tags, pollingInterval, streaming, translations, debug, children, }) {
25
25
  const [references, setReferences] = useState([]);
26
26
  const drawerRef = useRef(null);
27
27
  const addReference = useCallback((ref) => {
@@ -81,6 +81,8 @@ function DevicProvider({ apiKey, getTenantSession, onSessionExpired, baseUrl = D
81
81
  subtenantMetadata,
82
82
  tags,
83
83
  pollingInterval,
84
+ streaming,
85
+ translations,
84
86
  isConfigured: !!apiKey || usesSessions,
85
87
  debug,
86
88
  references,
@@ -102,6 +104,8 @@ function DevicProvider({ apiKey, getTenantSession, onSessionExpired, baseUrl = D
102
104
  subtenantMetadata,
103
105
  tags,
104
106
  pollingInterval,
107
+ streaming,
108
+ translations,
105
109
  debug,
106
110
  references,
107
111
  addReference,
@@ -1 +1 @@
1
- {"version":3,"file":"DevicProvider.js","sources":["../../../src/provider/DevicProvider.tsx"],"sourcesContent":["import React, { useMemo, useState, useRef, useCallback } from 'react';\nimport { DevicContext } from './DevicContext';\nimport { DevicApiClient } from '../api/client';\nimport { createSharedSession } from './sharedSession';\nimport { generateId } from '../utils';\nimport type {\n DevicProviderProps,\n DevicContextValue,\n AIReference,\n DrawerRegistration,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.devic.ai';\n\n/**\n * Provider component for Devic UI configuration\n *\n * @example\n * ```tsx\n * <DevicProvider\n * apiKey=\"devic-xxx\"\n * baseUrl=\"https://api.devic.ai\"\n * tenantId=\"tenant-123\"\n * tenantMetadata={{ userId: '456' }}\n * >\n * <App />\n * </DevicProvider>\n * ```\n */\nexport function DevicProvider({\n apiKey,\n getTenantSession,\n onSessionExpired,\n baseUrl = DEFAULT_BASE_URL,\n tenantId,\n tenantMetadata,\n subtenantId,\n subtenantMetadata,\n tags,\n pollingInterval,\n debug,\n children,\n}: DevicProviderProps): JSX.Element {\n const [references, setReferences] = useState<AIReference[]>([]);\n const drawerRef = useRef<DrawerRegistration | null>(null);\n\n const addReference = useCallback((ref: Omit<AIReference, 'id'>): string => {\n const id = generateId();\n setReferences((prev) => [...prev, { ...ref, id }]);\n return id;\n }, []);\n\n const removeReference = useCallback((id: string) => {\n setReferences((prev) => prev.filter((r) => r.id !== id));\n }, []);\n\n const clearReferences = useCallback(() => {\n setReferences([]);\n }, []);\n\n const registerDrawer = useCallback((handle: DrawerRegistration) => {\n drawerRef.current = handle;\n return () => {\n if (drawerRef.current === handle) {\n drawerRef.current = null;\n }\n };\n }, []);\n\n const openDrawer = useCallback(() => {\n drawerRef.current?.open();\n }, []);\n\n // Both callbacks are read through a ref and handed on as stable wrappers.\n // An inline `getTenantSession={() => …}` is a new function on every render,\n // and passing it straight through would rebuild the client — throwing away\n // the session it holds, so the page fetches a token per render — and rebuild\n // the context, so every component below it would do the same.\n const sessionSourceRef = useRef(getTenantSession);\n sessionSourceRef.current = getTenantSession;\n const expiredRef = useRef(onSessionExpired);\n expiredRef.current = onSessionExpired;\n const usesSessions = !!getTenantSession;\n\n // One session for the whole tree: every component below builds its own API\n // client, and each dedupes only its own renewals — so without this, N clients\n // ask for N tokens. See `createSharedSession`.\n const tenantSession = useMemo(\n () =>\n usesSessions\n ? createSharedSession(() => sessionSourceRef.current!())\n : undefined,\n [usesSessions]\n );\n const sessionExpired = useMemo(() => () => expiredRef.current?.(), []);\n\n const client = useMemo(\n () =>\n new DevicApiClient({\n apiKey,\n baseUrl,\n getTenantSession: tenantSession,\n onSessionExpired: sessionExpired,\n }),\n [apiKey, baseUrl, tenantSession, sessionExpired]\n );\n\n const contextValue = useMemo<DevicContextValue>(\n () => ({\n client,\n apiKey,\n getTenantSession: tenantSession,\n onSessionExpired: sessionExpired,\n baseUrl,\n tenantId,\n tenantMetadata,\n subtenantId,\n subtenantMetadata,\n tags,\n pollingInterval,\n isConfigured: !!apiKey || usesSessions,\n debug,\n references,\n addReference,\n removeReference,\n clearReferences,\n registerDrawer,\n openDrawer,\n }),\n [\n client,\n apiKey,\n tenantSession,\n sessionExpired,\n usesSessions,\n baseUrl,\n tenantId,\n tenantMetadata,\n subtenantId,\n subtenantMetadata,\n tags,\n pollingInterval,\n debug,\n references,\n addReference,\n removeReference,\n clearReferences,\n registerDrawer,\n openDrawer,\n ]\n );\n\n return (\n <DevicContext.Provider value={contextValue}>\n {children}\n </DevicContext.Provider>\n );\n}\n"],"names":["_jsx"],"mappings":";;;;;;;AAYA,MAAM,gBAAgB,GAAG,sBAAsB;AAE/C;;;;;;;;;;;;;;AAcG;AACG,SAAU,aAAa,CAAC,EAC5B,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,GAAG,gBAAgB,EAC1B,QAAQ,EACR,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,IAAI,EACJ,eAAe,EACf,KAAK,EACL,QAAQ,GACW,EAAA;IACnB,MAAM,CAAC,UAAU,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,CAAC,YAAY,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,YAAY,EAAA,QAAA,EACvC,QAAQ,EAAA,CACa;AAE5B;;"}
1
+ {"version":3,"file":"DevicProvider.js","sources":["../../../src/provider/DevicProvider.tsx"],"sourcesContent":["import React, { useMemo, useState, useRef, useCallback } from 'react';\nimport { DevicContext } from './DevicContext';\nimport { DevicApiClient } from '../api/client';\nimport { createSharedSession } from './sharedSession';\nimport { generateId } from '../utils';\nimport type {\n DevicProviderProps,\n DevicContextValue,\n AIReference,\n DrawerRegistration,\n} from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.devic.ai';\n\n/**\n * Provider component for Devic UI configuration\n *\n * @example\n * ```tsx\n * <DevicProvider\n * apiKey=\"devic-xxx\"\n * baseUrl=\"https://api.devic.ai\"\n * tenantId=\"tenant-123\"\n * tenantMetadata={{ userId: '456' }}\n * >\n * <App />\n * </DevicProvider>\n * ```\n */\nexport function DevicProvider({\n apiKey,\n getTenantSession,\n onSessionExpired,\n baseUrl = DEFAULT_BASE_URL,\n tenantId,\n tenantMetadata,\n subtenantId,\n subtenantMetadata,\n tags,\n pollingInterval,\n streaming,\n translations,\n debug,\n children,\n}: DevicProviderProps): JSX.Element {\n const [references, setReferences] = useState<AIReference[]>([]);\n const drawerRef = useRef<DrawerRegistration | null>(null);\n\n const addReference = useCallback((ref: Omit<AIReference, 'id'>): string => {\n const id = generateId();\n setReferences((prev) => [...prev, { ...ref, id }]);\n return id;\n }, []);\n\n const removeReference = useCallback((id: string) => {\n setReferences((prev) => prev.filter((r) => r.id !== id));\n }, []);\n\n const clearReferences = useCallback(() => {\n setReferences([]);\n }, []);\n\n const registerDrawer = useCallback((handle: DrawerRegistration) => {\n drawerRef.current = handle;\n return () => {\n if (drawerRef.current === handle) {\n drawerRef.current = null;\n }\n };\n }, []);\n\n const openDrawer = useCallback(() => {\n drawerRef.current?.open();\n }, []);\n\n // Both callbacks are read through a ref and handed on as stable wrappers.\n // An inline `getTenantSession={() => …}` is a new function on every render,\n // and passing it straight through would rebuild the client — throwing away\n // the session it holds, so the page fetches a token per render — and rebuild\n // the context, so every component below it would do the same.\n const sessionSourceRef = useRef(getTenantSession);\n sessionSourceRef.current = getTenantSession;\n const expiredRef = useRef(onSessionExpired);\n expiredRef.current = onSessionExpired;\n const usesSessions = !!getTenantSession;\n\n // One session for the whole tree: every component below builds its own API\n // client, and each dedupes only its own renewals — so without this, N clients\n // ask for N tokens. See `createSharedSession`.\n const tenantSession = useMemo(\n () =>\n usesSessions\n ? createSharedSession(() => sessionSourceRef.current!())\n : undefined,\n [usesSessions]\n );\n const sessionExpired = useMemo(() => () => expiredRef.current?.(), []);\n\n const client = useMemo(\n () =>\n new DevicApiClient({\n apiKey,\n baseUrl,\n getTenantSession: tenantSession,\n onSessionExpired: sessionExpired,\n }),\n [apiKey, baseUrl, tenantSession, sessionExpired]\n );\n\n const contextValue = useMemo<DevicContextValue>(\n () => ({\n client,\n apiKey,\n getTenantSession: tenantSession,\n onSessionExpired: sessionExpired,\n baseUrl,\n tenantId,\n tenantMetadata,\n subtenantId,\n subtenantMetadata,\n tags,\n pollingInterval,\n streaming,\n translations,\n isConfigured: !!apiKey || usesSessions,\n debug,\n references,\n addReference,\n removeReference,\n clearReferences,\n registerDrawer,\n openDrawer,\n }),\n [\n client,\n apiKey,\n tenantSession,\n sessionExpired,\n usesSessions,\n baseUrl,\n tenantId,\n tenantMetadata,\n subtenantId,\n subtenantMetadata,\n tags,\n pollingInterval,\n streaming,\n translations,\n debug,\n references,\n addReference,\n removeReference,\n clearReferences,\n registerDrawer,\n openDrawer,\n ]\n );\n\n return (\n <DevicContext.Provider value={contextValue}>\n {children}\n </DevicContext.Provider>\n );\n}\n"],"names":["_jsx"],"mappings":";;;;;;;AAYA,MAAM,gBAAgB,GAAG,sBAAsB;AAE/C;;;;;;;;;;;;;;AAcG;AACG,SAAU,aAAa,CAAC,EAC5B,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,G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AAO;QACP,QAAQ;QACR,cAAc;QACd,WAAW;QACX,iBAAiB;QACjB,IAAI;QACJ,eAAe;QACf,SAAS;QACT,YAAY;QACZ,KAAK;QACL,UAAU;QACV,YAAY;QACZ,eAAe;QACf,eAAe;QACf,cAAc;QACd,UAAU;AACX,KAAA,CACF;AAED,IAAA,QACEA,GAAA,CAAC,YAAY,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,YAAY,EAAA,QAAA,EACvC,QAAQ,EAAA,CACa;AAE5B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"sharedSession.js","sources":["../../../src/provider/sharedSession.ts"],"sourcesContent":["import type { TenantSessionToken } from '../api/client';\n\n/**\n * Renew this long before expiry. A little wider than the client's own margin,\n * so the sharing decides when to renew and the clients find a live token rather\n * than each reaching for one.\n */\nconst RENEWAL_MARGIN_MS = 90_000;\n\n/** The `exp` inside a JWT, in epoch ms. Unknown when it cannot be read. */\nfunction expiryOf(token: string): number | undefined {\n try {\n const payload = token.split('.')[1];\n if (!payload) return undefined;\n const json = atob(payload.replace(/-/g, '+').replace(/_/g, '/'));\n const exp = JSON.parse(json)?.exp;\n return typeof exp === 'number' ? exp * 1000 : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Whatever the integrator returned, as a token with an expiry we can compare. */\nexport function normaliseSession(\n result: string | TenantSessionToken,\n): TenantSessionToken {\n if (typeof result === 'string') {\n return { token: result, expiresAt: expiryOf(result) };\n }\n const declared =\n result.expiresAt ??\n (result.expiresIn ? Date.now() + result.expiresIn * 1000 : undefined);\n return { ...result, expiresAt: declared ?? expiryOf(result.token) };\n}\n\n/**\n * One session for a whole tree of components.\n *\n * Every component in this library builds its own API client, and each of those\n * dedupes only its own renewals — so N clients ask for N tokens. Opening the\n * drawer fired three requests at the integrator's backend before anyone had\n * said a word. The sharing belongs where there is exactly one of something,\n * which is the provider, and not in each client, where there is not.\n *\n * `force` is what a client passes after the API refused the token it just used.\n * The cached answer is then known to be dead, so it is skipped: without that, a\n * shared cache would hand the refused token straight back and turn a\n * recoverable 401 into a widget that never speaks again.\n */\nexport function createSharedSession(\n source: () => Promise<string | TenantSessionToken>,\n): (force?: boolean) => Promise<TenantSessionToken> {\n let value: TenantSessionToken | undefined;\n let inFlight: Promise<TenantSessionToken> | undefined;\n\n return (force = false) => {\n const stillGood =\n value &&\n (value.expiresAt === undefined ||\n value.expiresAt - Date.now() > RENEWAL_MARGIN_MS);\n if (stillGood && !force) return Promise.resolve(value!);\n\n if (!inFlight) {\n inFlight = Promise.resolve(source())\n .then((result) => {\n value = normaliseSession(result);\n return value;\n })\n .finally(() => {\n inFlight = undefined;\n });\n }\n return inFlight;\n };\n}\n"],"names":[],"mappings":"AAEA;;;;AAIG;AACH,MAAM,iBAAiB,GAAG,KAAM;AAEhC;AACA,SAAS,QAAQ,CAAC,KAAa,EAAA;AAC7B,IAAA,IAAI;QACF,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACnC,QAAA,IAAI,CAAC,OAAO;AAAE,YAAA,OAAO,SAAS;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAChE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG;AACjC,QAAA,OAAO,OAAO,GAAG,KAAK,QAAQ,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS;IACzD;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,SAAS;IAClB;AACF;AAEA;AACM,SAAU,gBAAgB,CAC9B,MAAmC,EAAA;AAEnC,IAAA,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AAC9B,QAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE;IACvD;AACA,IAAA,MAAM,QAAQ,GACZ,MAAM,CAAC,SAAS;SACf,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC;AACvE,IAAA,OAAO,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;AACrE;AAEA;;;;;;;;;;;;;AAaG;AACG,SAAU,mBAAmB,CACjC,MAAkD,EAAA;AAElD,IAAA,IAAI,KAAqC;AACzC,IAAA,IAAI,QAAiD;AAErD,IAAA,OAAO,CAAC,KAAK,GAAG,KAAK,KAAI;QACvB,MAAM,SAAS,GACb,KAAK;AACL,aAAC,KAAK,CAAC,SAAS,KAAK,SAAS;gBAC5B,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,iBAAiB,CAAC;QACrD,IAAI,SAAS,IAAI,CAAC,KAAK;AAAE,YAAA,OAAO,OAAO,CAAC,OAAO,CAAC,KAAM,CAAC;QAEvD,IAAI,CAAC,QAAQ,EAAE;AACb,YAAA,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;AAChC,iBAAA,IAAI,CAAC,CAAC,MAAM,KAAI;AACf,gBAAA,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC;AAChC,gBAAA,OAAO,KAAK;AACd,YAAA,CAAC;iBACA,OAAO,CAAC,MAAK;gBACZ,QAAQ,GAAG,SAAS;AACtB,YAAA,CAAC,CAAC;QACN;AACA,QAAA,OAAO,QAAQ;AACjB,IAAA,CAAC;AACH;;"}
1
+ {"version":3,"file":"sharedSession.js","sources":["../../../src/provider/sharedSession.ts"],"sourcesContent":["import type { TenantSessionToken } from '../api/client';\n\n/**\n * Renew this long before expiry. A little wider than the client's own margin,\n * so the sharing decides when to renew and the clients find a live token rather\n * than each reaching for one.\n */\nconst RENEWAL_MARGIN_MS = 90_000;\n\n/** The `exp` inside a JWT, in epoch ms. Unknown when it cannot be read. */\nfunction expiryOf(token: string): number | undefined {\n try {\n const payload = token.split('.')[1];\n if (!payload) return undefined;\n const json = atob(payload.replace(/-/g, '+').replace(/_/g, '/'));\n const exp = JSON.parse(json)?.exp;\n return typeof exp === 'number' ? exp * 1000 : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** Whatever the integrator returned, as a token with an expiry we can compare. */\nexport function normaliseSession(\n result: string | TenantSessionToken,\n): TenantSessionToken {\n if (typeof result === 'string') {\n return { token: result, expiresAt: expiryOf(result) };\n }\n const declared =\n result.expiresAt ??\n (result.expiresIn ? Date.now() + result.expiresIn * 1000 : undefined);\n return { ...result, expiresAt: declared ?? expiryOf(result.token) };\n}\n\n/**\n * One session for a whole tree of components.\n *\n * Every component in this library builds its own API client, and each of those\n * dedupes only its own renewals — so N clients ask for N tokens. Opening the\n * drawer fired three requests at the integrator's backend before anyone had\n * said a word. The sharing belongs where there is exactly one of something,\n * which is the provider, and not in each client, where there is not.\n *\n * `force` is what a client passes after the API refused the token it just used.\n * The cached answer is then known to be dead, so it is skipped: without that, a\n * shared cache would hand the refused token straight back and turn a\n * recoverable 401 into a widget that never speaks again.\n */\nexport function createSharedSession(\n source: () => Promise<string | TenantSessionToken>,\n): (force?: boolean) => Promise<TenantSessionToken> {\n let value: TenantSessionToken | undefined;\n let inFlight: Promise<TenantSessionToken> | undefined;\n\n return (force = false) => {\n const stillGood =\n value &&\n (value.expiresAt === undefined ||\n value.expiresAt - Date.now() > RENEWAL_MARGIN_MS);\n if (stillGood && !force) return Promise.resolve(value!);\n\n if (!inFlight) {\n inFlight = Promise.resolve(source())\n .then((result) => {\n value = normaliseSession(result);\n return value;\n })\n .finally(() => {\n inFlight = undefined;\n });\n }\n return inFlight;\n };\n}\n"],"names":[],"mappings":"AAEA;;;;AAIG;AACH,MAAM,iBAAiB,GAAG,KAAM;AAEhC;AACA,SAAS,QAAQ,CAAC,KAAa,EAAA;AAC7B,IAAA,IAAI;QACF,MAAM,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B,CAAC;QACrD,IAAI,SAAS,IAAI,CAAC,KAAK;AAAE,YAAA,OAAO,OAAO,CAAC,OAAO,CAAC,KAAM,CAAC;QAEvD,IAAI,CAAC,QAAQ,EAAE;AACb,YAAA,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;AAChC,iBAAA,IAAI,CAAC,CAAC,MAAM,KAAI;AACf,gBAAA,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC;AAChC,gBAAA,OAAO,KAAK;AACd,YAAA,CAAC;iBACA,OAAO,CAAC,MAAK;gBACZ,QAAQ,GAAG,SAAS;AACtB,YAAA,CAAC,CAAC;QACN;AACA,QAAA,OAAO,QAAQ;AACjB,IAAA,CAAC;AACH;;;;"}
@@ -1,4 +1,5 @@
1
1
  import type { DevicApiClient } from '../api/client';
2
+ import type { DevicTranslations } from '../i18n/types';
2
3
  /**
3
4
  * Tenant-level identity metadata sent to the Devic API. Used for per-tenant
4
5
  * cost attribution and to enrich the tenant record (name, contact, logo).
@@ -138,6 +139,45 @@ export interface DevicProviderConfig {
138
139
  * @default 1000
139
140
  */
140
141
  pollingInterval?: number;
142
+ /**
143
+ * Follow a conversation in progress over a server-sent event stream
144
+ * instead of polling it, for every component under this provider. The
145
+ * assistant's reply then arrives as it is produced, and the request per
146
+ * `pollingInterval` becomes a fallback that only runs while the stream is
147
+ * down. Needs an API that serves `GET .../chats/:chatUid/stream`; against
148
+ * an older one the widgets notice and keep polling. Overridable per
149
+ * component via its own `streaming`.
150
+ *
151
+ * @default false
152
+ */
153
+ streaming?: boolean;
154
+ /**
155
+ * Translations for the texts the library renders itself — the drawer
156
+ * header, the input placeholder, the buttons and tooltips of every widget.
157
+ *
158
+ * A plain `English text → your text` map, so the values come from whatever
159
+ * i18n system the host already runs (i18next, react-intl, a JSON per
160
+ * locale): nothing is looked up here beyond the key. Anything absent stays
161
+ * in English, so a partial dictionary is fine, and texts already
162
+ * configurable on their own (`welcomeMessage`, `inputPlaceholder`, …) keep
163
+ * winning over it.
164
+ *
165
+ * Texts with a `{name}` placeholder keep it in the translation; the
166
+ * placeholders are filled after the lookup, so they may be reordered.
167
+ *
168
+ * @example
169
+ * ```tsx
170
+ * <DevicProvider
171
+ * apiKey="devic-xxx"
172
+ * translations={{
173
+ * 'New chat': 'Nueva conversación',
174
+ * 'Type a message...': 'Escribe un mensaje...',
175
+ * 'Close chat': 'Cerrar el chat',
176
+ * }}
177
+ * >
178
+ * ```
179
+ */
180
+ translations?: DevicTranslations;
141
181
  /**
142
182
  * Enable debug logging to the browser console
143
183
  * @default false
@@ -219,6 +259,17 @@ export interface DevicContextValue {
219
259
  * integrator did not configure one, so each component keeps its own default.
220
260
  */
221
261
  pollingInterval?: number;
262
+ /**
263
+ * Whether conversations are followed over a server-sent event stream.
264
+ * Undefined when the integrator did not choose, so each component keeps its
265
+ * own default.
266
+ */
267
+ streaming?: boolean;
268
+ /**
269
+ * Translations for the texts the library renders itself, keyed by the
270
+ * English text. Undefined when the integrator configured none.
271
+ */
272
+ translations?: DevicTranslations;
222
273
  /**
223
274
  * Whether the provider is properly configured
224
275
  */