@datalayer/agent-runtimes 0.0.9 → 0.0.11

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 (291) hide show
  1. package/README.md +2 -1
  2. package/lib/{examples/components → components}/AgentConfiguration.d.ts +54 -9
  3. package/lib/components/AgentConfiguration.js +585 -0
  4. package/lib/{examples/components → components}/FooterMetrics.d.ts +1 -2
  5. package/lib/{examples/components → components}/Header.d.ts +1 -6
  6. package/lib/{examples/components → components}/Header.js +5 -39
  7. package/lib/{examples/components → components}/HeaderControls.d.ts +1 -2
  8. package/lib/{examples/components → components}/HeaderControls.js +1 -1
  9. package/lib/{examples/components → components}/LexicalEditor.d.ts +2 -3
  10. package/lib/{examples/components → components}/LexicalEditor.js +2 -2
  11. package/lib/components/MainContent.d.ts +34 -0
  12. package/lib/{examples/components → components}/MainContent.js +18 -9
  13. package/lib/components/McpServerManager.d.ts +30 -0
  14. package/lib/components/McpServerManager.js +331 -0
  15. package/lib/{examples/components → components}/MockFileBrowser.d.ts +1 -2
  16. package/lib/{examples/components → components}/SessionTabs.d.ts +2 -3
  17. package/lib/{examples/components → components}/TimeTravel.d.ts +1 -2
  18. package/lib/components/chat/components/AgentDetails.d.ts +3 -1
  19. package/lib/components/chat/components/AgentDetails.js +472 -22
  20. package/lib/components/chat/components/Chat.d.ts +37 -3
  21. package/lib/components/chat/components/Chat.js +29 -10
  22. package/lib/components/chat/components/ChatFloating.d.ts +27 -2
  23. package/lib/components/chat/components/ChatFloating.js +17 -10
  24. package/lib/components/chat/components/ChatPopupStandalone.js +1 -1
  25. package/lib/components/chat/components/ChatSidebar.d.ts +1 -1
  26. package/lib/components/chat/components/ChatStandalone.d.ts +1 -1
  27. package/lib/components/chat/components/ChatStandalone.js +1 -1
  28. package/lib/components/chat/components/ContextDistribution.d.ts +70 -6
  29. package/lib/components/chat/components/ContextDistribution.js +13 -6
  30. package/lib/components/chat/components/ContextInspector.d.ts +81 -0
  31. package/lib/components/chat/components/ContextInspector.js +263 -0
  32. package/lib/components/chat/components/ContextPanel.d.ts +112 -0
  33. package/lib/components/chat/components/ContextPanel.js +368 -0
  34. package/lib/components/chat/components/base/ChatBase.d.ts +74 -19
  35. package/lib/components/chat/components/base/ChatBase.js +296 -37
  36. package/lib/components/chat/components/index.d.ts +3 -1
  37. package/lib/components/chat/components/index.js +2 -0
  38. package/lib/components/chat/extensions/ExtensionRegistry.d.ts +1 -1
  39. package/lib/components/chat/extensions/index.d.ts +1 -0
  40. package/lib/components/chat/index.d.ts +3 -3
  41. package/lib/components/chat/protocols/AGUIAdapter.js +24 -4
  42. package/lib/components/chat/protocols/VercelAIAdapter.js +35 -1
  43. package/lib/components/chat/store/chatStore.d.ts +2 -3
  44. package/lib/components/chat/store/conversationStore.d.ts +83 -0
  45. package/lib/components/chat/store/conversationStore.js +174 -0
  46. package/lib/components/chat/store/index.d.ts +2 -1
  47. package/lib/components/chat/store/index.js +1 -0
  48. package/lib/components/chat/types/inference.d.ts +17 -0
  49. package/lib/components/chat/types/protocol.d.ts +10 -0
  50. package/lib/components/index.d.ts +23 -0
  51. package/lib/components/index.js +11 -0
  52. package/lib/config/agents/code-ai/agents.d.ts +25 -0
  53. package/lib/config/agents/code-ai/agents.js +70 -0
  54. package/lib/config/agents/code-ai/index.d.ts +1 -0
  55. package/lib/config/agents/code-ai/index.js +5 -0
  56. package/lib/config/agents/codemode-paper/agents.d.ts +29 -0
  57. package/lib/config/agents/codemode-paper/agents.js +288 -0
  58. package/lib/config/agents/codemode-paper/index.d.ts +1 -0
  59. package/lib/config/agents/codemode-paper/index.js +5 -0
  60. package/lib/config/agents/datalayer-ai/agents.d.ts +29 -0
  61. package/lib/config/agents/datalayer-ai/agents.js +267 -0
  62. package/lib/config/agents/datalayer-ai/index.d.ts +1 -0
  63. package/lib/config/agents/datalayer-ai/index.js +5 -0
  64. package/lib/config/agents/index.d.ts +19 -0
  65. package/lib/config/agents/index.js +38 -0
  66. package/lib/config/envvars.d.ts +28 -0
  67. package/lib/config/envvars.js +115 -0
  68. package/lib/config/index.d.ts +5 -0
  69. package/lib/config/index.js +9 -0
  70. package/lib/config/mcpServers.d.ts +18 -0
  71. package/lib/config/mcpServers.js +153 -0
  72. package/lib/config/skills.d.ts +27 -0
  73. package/lib/config/skills.js +60 -0
  74. package/lib/{lib → config}/utils.d.ts +1 -1
  75. package/lib/{lib → config}/utils.js +2 -2
  76. package/lib/examples/AgentRuntimeLexical2Example.d.ts +1 -0
  77. package/lib/examples/AgentRuntimeLexical2Example.js +3 -2
  78. package/lib/examples/AgentRuntimeLexicalExample.d.ts +1 -0
  79. package/lib/examples/AgentRuntimeLexicalExample.js +5 -3
  80. package/lib/examples/AgentRuntimeLexicalSidebarExample.d.ts +1 -0
  81. package/lib/examples/AgentRuntimeLexicalSidebarExample.js +3 -3
  82. package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
  83. package/lib/examples/AgentSpaceFormExample.d.ts +2 -2
  84. package/lib/examples/AgentSpaceFormExample.js +215 -35
  85. package/lib/examples/CopilotKitLexicalExample.d.ts +1 -0
  86. package/lib/examples/CopilotKitLexicalExample.js +3 -2
  87. package/lib/examples/index.d.ts +1 -0
  88. package/lib/examples/stores/notebooks/NotebookExample2.ipynb.json +43 -43
  89. package/lib/hooks/useAGUI.d.ts +1 -1
  90. package/lib/hooks/useAGUI.js +1 -1
  91. package/lib/identity/types.d.ts +1 -1
  92. package/lib/index.d.ts +2 -0
  93. package/lib/index.js +1 -0
  94. package/lib/runtime/index.d.ts +3 -0
  95. package/lib/runtime/runtimeStore.d.ts +3 -4
  96. package/lib/runtime/useAgentConnection.d.ts +2 -3
  97. package/lib/runtime/useAgentRuntime.d.ts +2 -3
  98. package/lib/stories/Cell.stories.js +1 -1
  99. package/lib/tools/adapters/agent-runtimes/notebookHooks.js +1 -0
  100. package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -0
  101. package/lib/types.d.ts +158 -0
  102. package/package.json +5 -6
  103. package/scripts/apply-patches.sh +1 -1
  104. package/scripts/codegen/generate_agents.py +863 -0
  105. package/scripts/codegen/generate_envvars.py +302 -0
  106. package/scripts/codegen/generate_mcp_servers.py +436 -0
  107. package/scripts/codegen/generate_skills.py +334 -0
  108. package/scripts/download-ai-elements.py +35 -20
  109. package/scripts/sync-jupyter.sh +6 -0
  110. package/lib/components/ui/accordion.d.ts +0 -7
  111. package/lib/components/ui/accordion.js +0 -22
  112. package/lib/components/ui/alert-dialog.d.ts +0 -14
  113. package/lib/components/ui/alert-dialog.js +0 -43
  114. package/lib/components/ui/alert.d.ts +0 -9
  115. package/lib/components/ui/alert.js +0 -24
  116. package/lib/components/ui/aspect-ratio.d.ts +0 -3
  117. package/lib/components/ui/aspect-ratio.js +0 -11
  118. package/lib/components/ui/avatar.d.ts +0 -6
  119. package/lib/components/ui/avatar.js +0 -18
  120. package/lib/components/ui/badge.d.ts +0 -9
  121. package/lib/components/ui/badge.js +0 -22
  122. package/lib/components/ui/breadcrumb.d.ts +0 -11
  123. package/lib/components/ui/breadcrumb.js +0 -27
  124. package/lib/components/ui/button-group.d.ts +0 -11
  125. package/lib/components/ui/button-group.js +0 -31
  126. package/lib/components/ui/button.d.ts +0 -13
  127. package/lib/components/ui/button.js +0 -39
  128. package/lib/components/ui/calendar.d.ts +0 -8
  129. package/lib/components/ui/calendar.js +0 -80
  130. package/lib/components/ui/card.d.ts +0 -9
  131. package/lib/components/ui/card.js +0 -24
  132. package/lib/components/ui/carousel.d.ts +0 -19
  133. package/lib/components/ui/carousel.js +0 -95
  134. package/lib/components/ui/chart.d.ts +0 -53
  135. package/lib/components/ui/chart.js +0 -136
  136. package/lib/components/ui/checkbox.d.ts +0 -4
  137. package/lib/components/ui/checkbox.js +0 -13
  138. package/lib/components/ui/collapsible.d.ts +0 -5
  139. package/lib/components/ui/collapsible.js +0 -17
  140. package/lib/components/ui/command.d.ts +0 -18
  141. package/lib/components/ui/command.js +0 -38
  142. package/lib/components/ui/context-menu.d.ts +0 -25
  143. package/lib/components/ui/context-menu.js +0 -55
  144. package/lib/components/ui/dialog.d.ts +0 -15
  145. package/lib/components/ui/dialog.js +0 -40
  146. package/lib/components/ui/drawer.d.ts +0 -13
  147. package/lib/components/ui/drawer.js +0 -39
  148. package/lib/components/ui/dropdown-menu.d.ts +0 -25
  149. package/lib/components/ui/dropdown-menu.js +0 -55
  150. package/lib/components/ui/empty.d.ts +0 -11
  151. package/lib/components/ui/empty.js +0 -37
  152. package/lib/components/ui/field.d.ts +0 -24
  153. package/lib/components/ui/field.js +0 -80
  154. package/lib/components/ui/form.d.ts +0 -24
  155. package/lib/components/ui/form.js +0 -63
  156. package/lib/components/ui/hover-card.d.ts +0 -6
  157. package/lib/components/ui/hover-card.js +0 -18
  158. package/lib/components/ui/input-group.d.ts +0 -19
  159. package/lib/components/ui/input-group.js +0 -69
  160. package/lib/components/ui/input-otp.d.ts +0 -11
  161. package/lib/components/ui/input-otp.js +0 -25
  162. package/lib/components/ui/input.d.ts +0 -3
  163. package/lib/components/ui/input.js +0 -6
  164. package/lib/components/ui/item.d.ts +0 -23
  165. package/lib/components/ui/item.js +0 -66
  166. package/lib/components/ui/kbd.d.ts +0 -3
  167. package/lib/components/ui/kbd.js +0 -13
  168. package/lib/components/ui/label.d.ts +0 -4
  169. package/lib/components/ui/label.js +0 -12
  170. package/lib/components/ui/menubar.d.ts +0 -26
  171. package/lib/components/ui/menubar.js +0 -58
  172. package/lib/components/ui/navigation-menu.d.ts +0 -14
  173. package/lib/components/ui/navigation-menu.js +0 -31
  174. package/lib/components/ui/pagination.d.ts +0 -13
  175. package/lib/components/ui/pagination.js +0 -29
  176. package/lib/components/ui/popover.d.ts +0 -7
  177. package/lib/components/ui/popover.js +0 -21
  178. package/lib/components/ui/progress.d.ts +0 -4
  179. package/lib/components/ui/progress.js +0 -12
  180. package/lib/components/ui/radio-group.d.ts +0 -5
  181. package/lib/components/ui/radio-group.js +0 -16
  182. package/lib/components/ui/resizable.d.ts +0 -8
  183. package/lib/components/ui/resizable.js +0 -19
  184. package/lib/components/ui/scroll-area.d.ts +0 -5
  185. package/lib/components/ui/scroll-area.js +0 -17
  186. package/lib/components/ui/select.d.ts +0 -15
  187. package/lib/components/ui/select.js +0 -42
  188. package/lib/components/ui/separator.d.ts +0 -4
  189. package/lib/components/ui/separator.js +0 -12
  190. package/lib/components/ui/sheet.d.ts +0 -13
  191. package/lib/components/ui/sheet.js +0 -44
  192. package/lib/components/ui/sidebar.d.ts +0 -69
  193. package/lib/components/ui/sidebar.js +0 -216
  194. package/lib/components/ui/skeleton.d.ts +0 -2
  195. package/lib/components/ui/skeleton.js +0 -10
  196. package/lib/components/ui/slider.d.ts +0 -4
  197. package/lib/components/ui/slider.js +0 -18
  198. package/lib/components/ui/sonner.d.ts +0 -3
  199. package/lib/components/ui/sonner.js +0 -25
  200. package/lib/components/ui/spinner.d.ts +0 -2
  201. package/lib/components/ui/spinner.js +0 -11
  202. package/lib/components/ui/switch.d.ts +0 -4
  203. package/lib/components/ui/switch.js +0 -12
  204. package/lib/components/ui/table.d.ts +0 -10
  205. package/lib/components/ui/table.js +0 -32
  206. package/lib/components/ui/tabs.d.ts +0 -7
  207. package/lib/components/ui/tabs.js +0 -21
  208. package/lib/components/ui/textarea.d.ts +0 -3
  209. package/lib/components/ui/textarea.js +0 -6
  210. package/lib/components/ui/toast.d.ts +0 -15
  211. package/lib/components/ui/toast.js +0 -38
  212. package/lib/components/ui/toaster.d.ts +0 -1
  213. package/lib/components/ui/toaster.js +0 -14
  214. package/lib/components/ui/toggle-group.d.ts +0 -9
  215. package/lib/components/ui/toggle-group.js +0 -26
  216. package/lib/components/ui/toggle.d.ts +0 -9
  217. package/lib/components/ui/toggle.js +0 -30
  218. package/lib/components/ui/tooltip.d.ts +0 -7
  219. package/lib/components/ui/tooltip.js +0 -21
  220. package/lib/components/vercel-ai-elements/artifact.d.ts +0 -23
  221. package/lib/components/vercel-ai-elements/artifact.js +0 -24
  222. package/lib/components/vercel-ai-elements/code-block.d.ts +0 -17
  223. package/lib/components/vercel-ai-elements/code-block.js +0 -94
  224. package/lib/components/vercel-ai-elements/conversation.d.ts +0 -15
  225. package/lib/components/vercel-ai-elements/conversation.js +0 -21
  226. package/lib/components/vercel-ai-elements/loader.d.ts +0 -5
  227. package/lib/components/vercel-ai-elements/loader.js +0 -8
  228. package/lib/components/vercel-ai-elements/message.d.ts +0 -46
  229. package/lib/components/vercel-ai-elements/message.js +0 -109
  230. package/lib/components/vercel-ai-elements/model-selector.d.ts +0 -35
  231. package/lib/components/vercel-ai-elements/model-selector.js +0 -22
  232. package/lib/components/vercel-ai-elements/prompt-input.d.ts +0 -195
  233. package/lib/components/vercel-ai-elements/prompt-input.js +0 -589
  234. package/lib/components/vercel-ai-elements/reasoning.d.ts +0 -26
  235. package/lib/components/vercel-ai-elements/reasoning.js +0 -80
  236. package/lib/components/vercel-ai-elements/shimmer.d.ts +0 -9
  237. package/lib/components/vercel-ai-elements/shimmer.js +0 -22
  238. package/lib/components/vercel-ai-elements/sources.d.ts +0 -12
  239. package/lib/components/vercel-ai-elements/sources.js +0 -13
  240. package/lib/components/vercel-ai-elements/suggestion.d.ts +0 -10
  241. package/lib/components/vercel-ai-elements/suggestion.js +0 -16
  242. package/lib/components/vercel-ai-elements/tool.d.ts +0 -23
  243. package/lib/components/vercel-ai-elements/tool.js +0 -52
  244. package/lib/examples/components/AgentConfiguration.js +0 -382
  245. package/lib/examples/components/MainContent.d.ts +0 -19
  246. package/lib/examples/components/index.d.ts +0 -10
  247. package/lib/examples/components/index.js +0 -13
  248. package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.d.ts +0 -12
  249. package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.js +0 -69
  250. package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.d.ts +0 -1
  251. package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.js +0 -85
  252. package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.d.ts +0 -1
  253. package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.js +0 -62
  254. package/lib/examples/vercel-ai-elements/components/ConversationShowcase.d.ts +0 -1
  255. package/lib/examples/vercel-ai-elements/components/ConversationShowcase.js +0 -51
  256. package/lib/examples/vercel-ai-elements/components/LoaderShowcase.d.ts +0 -1
  257. package/lib/examples/vercel-ai-elements/components/LoaderShowcase.js +0 -9
  258. package/lib/examples/vercel-ai-elements/components/MessageShowcase.d.ts +0 -1
  259. package/lib/examples/vercel-ai-elements/components/MessageShowcase.js +0 -56
  260. package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.d.ts +0 -1
  261. package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.js +0 -50
  262. package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.d.ts +0 -1
  263. package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.js +0 -16
  264. package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.d.ts +0 -1
  265. package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.js +0 -72
  266. package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.d.ts +0 -1
  267. package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.js +0 -9
  268. package/lib/examples/vercel-ai-elements/components/SourcesShowcase.d.ts +0 -1
  269. package/lib/examples/vercel-ai-elements/components/SourcesShowcase.js +0 -43
  270. package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.d.ts +0 -1
  271. package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.js +0 -31
  272. package/lib/examples/vercel-ai-elements/components/ToolShowcase.d.ts +0 -1
  273. package/lib/examples/vercel-ai-elements/components/ToolShowcase.js +0 -54
  274. package/lib/examples/vercel-ai-elements/index.d.ts +0 -13
  275. package/lib/examples/vercel-ai-elements/index.js +0 -17
  276. package/lib/examples/vercel-ai-elements/main.d.ts +0 -1
  277. package/lib/examples/vercel-ai-elements/main.js +0 -9
  278. package/lib/examples/vercel-ai-elements/showcase.css +0 -128
  279. package/lib/hooks/useToast.d.ts +0 -44
  280. package/lib/hooks/useToast.js +0 -128
  281. package/patches/@datalayer+jupyter-lexical+1.0.8.patch +0 -11628
  282. package/patches/@datalayer+jupyter-react+2.0.2.patch +0 -5338
  283. package/style/showcase-vercel-ai.css +0 -137
  284. /package/lib/{examples/components → components}/FooterMetrics.js +0 -0
  285. /package/lib/{examples/components → components}/MockFileBrowser.js +0 -0
  286. /package/lib/{examples/components → components}/SessionTabs.js +0 -0
  287. /package/lib/{examples/components → components}/TimeTravel.js +0 -0
  288. /package/lib/{models → types}/AIAgent.d.ts +0 -0
  289. /package/lib/{models → types}/AIAgent.js +0 -0
  290. /package/lib/{models → types}/index.d.ts +0 -0
  291. /package/lib/{models → types}/index.js +0 -0
@@ -1,128 +0,0 @@
1
- /*
2
- * Copyright (c) 2025-2026 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- *
5
- * Showcase-specific styles for Vercel AI Elements
6
- */
7
-
8
- /* Additional showcase-specific styles */
9
- :root {
10
- --showcase-max-width: 1400px;
11
- }
12
-
13
- .showcase-container {
14
- max-width: var(--showcase-max-width);
15
- margin: 0 auto;
16
- }
17
-
18
- /* Ensure proper spacing in showcase examples */
19
- .space-y-8 > * + * {
20
- margin-top: 2rem;
21
- }
22
-
23
- .space-y-4 > * + * {
24
- margin-top: 1rem;
25
- }
26
-
27
- .space-y-3 > * + * {
28
- margin-top: 0.75rem;
29
- }
30
-
31
- .space-y-2 > * + * {
32
- margin-top: 0.5rem;
33
- }
34
-
35
- /* Prose styles for documentation content */
36
- .prose {
37
- color: var(--color-fg-default);
38
- max-width: 65ch;
39
- }
40
-
41
- .prose h1 {
42
- font-size: 2em;
43
- margin-top: 0;
44
- margin-bottom: 0.8em;
45
- line-height: 1.1;
46
- font-weight: 700;
47
- }
48
-
49
- .prose h2 {
50
- font-size: 1.5em;
51
- margin-top: 2em;
52
- margin-bottom: 1em;
53
- line-height: 1.3;
54
- font-weight: 600;
55
- }
56
-
57
- .prose h3 {
58
- font-size: 1.25em;
59
- margin-top: 1.6em;
60
- margin-bottom: 0.6em;
61
- line-height: 1.4;
62
- font-weight: 600;
63
- }
64
-
65
- .prose p {
66
- margin-top: 1.25em;
67
- margin-bottom: 1.25em;
68
- line-height: 1.7;
69
- }
70
-
71
- .prose pre {
72
- background-color: var(--color-canvas-subtle);
73
- border-radius: 0.375rem;
74
- padding: 1em;
75
- overflow-x: auto;
76
- margin-top: 1.7em;
77
- margin-bottom: 1.7em;
78
- }
79
-
80
- .prose code {
81
- background-color: var(--color-canvas-subtle);
82
- border-radius: 0.25rem;
83
- padding: 0.2em 0.4em;
84
- font-size: 0.875em;
85
- font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
86
- }
87
-
88
- .prose pre code {
89
- background-color: transparent;
90
- padding: 0;
91
- font-size: inherit;
92
- }
93
-
94
- .prose ul {
95
- margin-top: 1.25em;
96
- margin-bottom: 1.25em;
97
- padding-left: 1.625em;
98
- list-style-type: disc;
99
- }
100
-
101
- .prose li {
102
- margin-top: 0.5em;
103
- margin-bottom: 0.5em;
104
- }
105
-
106
- .prose strong {
107
- font-weight: 600;
108
- }
109
-
110
- /* Ensure code blocks in examples are visible */
111
- .border {
112
- border-width: 1px;
113
- }
114
-
115
- /* Dark mode adjustments */
116
- @media (prefers-color-scheme: dark) {
117
- .prose {
118
- color: var(--color-fg-default);
119
- }
120
-
121
- .prose code {
122
- background-color: rgba(110, 118, 129, 0.4);
123
- }
124
-
125
- .prose pre {
126
- background-color: rgba(110, 118, 129, 0.2);
127
- }
128
- }
@@ -1,44 +0,0 @@
1
- import * as React from 'react';
2
- import type { ToastActionElement, ToastProps } from '@/components/ui/toast';
3
- type ToasterToast = ToastProps & {
4
- id: string;
5
- title?: React.ReactNode;
6
- description?: React.ReactNode;
7
- action?: ToastActionElement;
8
- };
9
- declare const actionTypes: {
10
- readonly ADD_TOAST: "ADD_TOAST";
11
- readonly UPDATE_TOAST: "UPDATE_TOAST";
12
- readonly DISMISS_TOAST: "DISMISS_TOAST";
13
- readonly REMOVE_TOAST: "REMOVE_TOAST";
14
- };
15
- type ActionType = typeof actionTypes;
16
- type Action = {
17
- type: ActionType['ADD_TOAST'];
18
- toast: ToasterToast;
19
- } | {
20
- type: ActionType['UPDATE_TOAST'];
21
- toast: Partial<ToasterToast>;
22
- } | {
23
- type: ActionType['DISMISS_TOAST'];
24
- toastId?: ToasterToast['id'];
25
- } | {
26
- type: ActionType['REMOVE_TOAST'];
27
- toastId?: ToasterToast['id'];
28
- };
29
- interface State {
30
- toasts: ToasterToast[];
31
- }
32
- export declare const reducer: (state: State, action: Action) => State;
33
- type Toast = Omit<ToasterToast, 'id'>;
34
- declare function toast({ ...props }: Toast): {
35
- id: string;
36
- dismiss: () => void;
37
- update: (props: ToasterToast) => void;
38
- };
39
- declare function useToast(): {
40
- toast: typeof toast;
41
- dismiss: (toastId?: string) => void;
42
- toasts: ToasterToast[];
43
- };
44
- export { useToast, toast };
@@ -1,128 +0,0 @@
1
- /*
2
- * Copyright (c) 2025-2026 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import * as React from 'react';
6
- const TOAST_LIMIT = 1;
7
- const TOAST_REMOVE_DELAY = 1000000;
8
- const actionTypes = {
9
- ADD_TOAST: 'ADD_TOAST',
10
- UPDATE_TOAST: 'UPDATE_TOAST',
11
- DISMISS_TOAST: 'DISMISS_TOAST',
12
- REMOVE_TOAST: 'REMOVE_TOAST',
13
- };
14
- let count = 0;
15
- function genId() {
16
- count = (count + 1) % Number.MAX_SAFE_INTEGER;
17
- return count.toString();
18
- }
19
- const toastTimeouts = new Map();
20
- const addToRemoveQueue = (toastId) => {
21
- if (toastTimeouts.has(toastId)) {
22
- return;
23
- }
24
- const timeout = setTimeout(() => {
25
- toastTimeouts.delete(toastId);
26
- dispatch({
27
- type: 'REMOVE_TOAST',
28
- toastId: toastId,
29
- });
30
- }, TOAST_REMOVE_DELAY);
31
- toastTimeouts.set(toastId, timeout);
32
- };
33
- export const reducer = (state, action) => {
34
- switch (action.type) {
35
- case 'ADD_TOAST':
36
- return {
37
- ...state,
38
- toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
39
- };
40
- case 'UPDATE_TOAST':
41
- return {
42
- ...state,
43
- toasts: state.toasts.map(t => t.id === action.toast.id ? { ...t, ...action.toast } : t),
44
- };
45
- case 'DISMISS_TOAST': {
46
- const { toastId } = action;
47
- if (toastId) {
48
- addToRemoveQueue(toastId);
49
- }
50
- else {
51
- state.toasts.forEach(toast => {
52
- addToRemoveQueue(toast.id);
53
- });
54
- }
55
- return {
56
- ...state,
57
- toasts: state.toasts.map(t => t.id === toastId || toastId === undefined
58
- ? {
59
- ...t,
60
- open: false,
61
- }
62
- : t),
63
- };
64
- }
65
- case 'REMOVE_TOAST':
66
- if (action.toastId === undefined) {
67
- return {
68
- ...state,
69
- toasts: [],
70
- };
71
- }
72
- return {
73
- ...state,
74
- toasts: state.toasts.filter(t => t.id !== action.toastId),
75
- };
76
- }
77
- };
78
- const listeners = [];
79
- let memoryState = { toasts: [] };
80
- function dispatch(action) {
81
- memoryState = reducer(memoryState, action);
82
- listeners.forEach(listener => {
83
- listener(memoryState);
84
- });
85
- }
86
- function toast({ ...props }) {
87
- const id = genId();
88
- const update = (props) => dispatch({
89
- type: 'UPDATE_TOAST',
90
- toast: { ...props, id },
91
- });
92
- const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id });
93
- dispatch({
94
- type: 'ADD_TOAST',
95
- toast: {
96
- ...props,
97
- id,
98
- open: true,
99
- onOpenChange: open => {
100
- if (!open)
101
- dismiss();
102
- },
103
- },
104
- });
105
- return {
106
- id: id,
107
- dismiss,
108
- update,
109
- };
110
- }
111
- function useToast() {
112
- const [state, setState] = React.useState(memoryState);
113
- React.useEffect(() => {
114
- listeners.push(setState);
115
- return () => {
116
- const index = listeners.indexOf(setState);
117
- if (index > -1) {
118
- listeners.splice(index, 1);
119
- }
120
- };
121
- }, [state]);
122
- return {
123
- ...state,
124
- toast,
125
- dismiss: (toastId) => dispatch({ type: 'DISMISS_TOAST', toastId }),
126
- };
127
- }
128
- export { useToast, toast };