@openviking/react 0.1.2 → 0.1.4

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 (249) hide show
  1. package/LICENSE.arco-design +21 -0
  2. package/README.md +25 -15
  3. package/dist/0~0.js +19 -0
  4. package/dist/2~0.js +2360 -0
  5. package/dist/2~0.js.LICENSE.txt +23 -0
  6. package/dist/3c~0.js +2206 -0
  7. package/dist/3~0.js +1205 -1982
  8. package/dist/4~0.js +18 -0
  9. package/dist/9~0.js +43 -0
  10. package/dist/ae~0.js +487 -0
  11. package/dist/ark-message-list-view~0.js +530 -119
  12. package/dist/a~0.js +1289 -10
  13. package/dist/c7~0.js +38 -2
  14. package/dist/ck~0.js +23 -0
  15. package/dist/client/index.d.ts +2 -1
  16. package/dist/client/paths.d.ts +64 -0
  17. package/dist/client/provider.d.ts +5 -3
  18. package/dist/client/response.d.ts +31 -0
  19. package/dist/client/sse.d.ts +39 -0
  20. package/dist/client/stream.d.ts +26 -0
  21. package/dist/client/types.d.ts +109 -5
  22. package/dist/client.js +2 -239
  23. package/dist/components/agent-connect/agent-connect-copy.d.ts +19 -33
  24. package/dist/components/agent-connect/agent-connect-design.d.ts +1935 -167
  25. package/dist/components/agent-connect/agent-connect-instructions.d.ts +135 -0
  26. package/dist/components/agent-connect/locales/en-US.d.ts +20 -0
  27. package/dist/components/agent-connect/locales/zh-CN.d.ts +3 -0
  28. package/dist/components/agent-connect/style.css +14 -2
  29. package/dist/components/agent-connect/types.d.ts +2 -1
  30. package/dist/components/directory-tour/directory-tour.d.ts +3 -0
  31. package/dist/components/directory-tour/index.d.ts +3 -0
  32. package/dist/components/directory-tour/locales/en-US.d.ts +3 -0
  33. package/dist/components/directory-tour/locales/zh-CN.d.ts +3 -0
  34. package/dist/components/directory-tour/steps.d.ts +5 -0
  35. package/dist/components/directory-tour/style.css +237 -0
  36. package/dist/components/directory-tour/style.js +0 -0
  37. package/dist/components/directory-tour/types.d.ts +42 -0
  38. package/dist/components/directory-tour/use-tour-anchor.d.ts +5 -0
  39. package/dist/components/directory-tour/use-tour-position.d.ts +12 -0
  40. package/dist/components/directory-tour.js +40 -0
  41. package/dist/components/file-browser-entries/file-browser-entries-icons.d.ts +18 -0
  42. package/dist/components/file-browser-entries/file-browser-entries.d.ts +14 -0
  43. package/dist/components/file-browser-entries/index.d.ts +1 -0
  44. package/dist/components/file-browser-entries/labels.d.ts +3 -0
  45. package/dist/components/file-browser-entries/locales/en-US.d.ts +6 -0
  46. package/dist/components/file-browser-entries/locales/zh-CN.d.ts +6 -0
  47. package/dist/components/file-browser-entries/style.css +905 -0
  48. package/dist/components/file-browser-entries/style.js +0 -0
  49. package/dist/components/file-browser-entries/types.d.ts +63 -0
  50. package/dist/components/file-browser-entries.js +1 -0
  51. package/dist/components/file-preview/file-preview-adapters.d.ts +2 -1
  52. package/dist/components/file-preview/file-preview-body.d.ts +2 -1
  53. package/dist/components/file-preview/file-preview-breadcrumb-menu.d.ts +2 -1
  54. package/dist/components/file-preview/file-preview-breadcrumb.d.ts +2 -1
  55. package/dist/components/file-preview/file-preview-directory.d.ts +33 -0
  56. package/dist/components/file-preview/file-preview-handle-adapters.d.ts +2 -1
  57. package/dist/components/file-preview/file-preview-header.d.ts +25 -3
  58. package/dist/components/file-preview/file-preview-image-frame.d.ts +5 -0
  59. package/dist/components/file-preview/file-preview-labels.d.ts +2 -14
  60. package/dist/components/file-preview/file-preview-level-tabs.d.ts +7 -0
  61. package/dist/components/file-preview/file-preview-markdown-images.d.ts +13 -0
  62. package/dist/components/file-preview/file-preview-panels.d.ts +44 -0
  63. package/dist/components/file-preview/file-preview-state.d.ts +10 -3
  64. package/dist/components/file-preview/file-preview-viewer.d.ts +2 -1
  65. package/dist/components/file-preview/file-preview.d.ts +1 -1
  66. package/dist/components/file-preview/index.d.ts +2 -1
  67. package/dist/components/file-preview/level-selection.d.ts +25 -0
  68. package/dist/components/file-preview/locales/en-US.d.ts +16 -0
  69. package/dist/components/file-preview/locales/zh-CN.d.ts +16 -0
  70. package/dist/components/file-preview/style.css +234 -3
  71. package/dist/components/file-preview/types.d.ts +134 -11
  72. package/dist/components/file-preview/use-directory-level.d.ts +30 -0
  73. package/dist/components/file-preview/use-file-preview-actions-context.d.ts +6 -2
  74. package/dist/components/file-preview/use-file-preview-actions.d.ts +1 -1
  75. package/dist/components/file-preview/use-file-preview-levels.d.ts +7 -0
  76. package/dist/components/file-preview/use-file-preview-view-state.d.ts +15 -0
  77. package/dist/components/file-preview.js +1 -1
  78. package/dist/components/file-tree/file-tree-info-labels.d.ts +0 -15
  79. package/dist/components/file-tree/file-tree-info-tooltip.d.ts +7 -7
  80. package/dist/components/file-tree/file-tree-labels.d.ts +4 -0
  81. package/dist/components/file-tree/file-tree-row-context.d.ts +0 -5
  82. package/dist/components/file-tree/file-tree-row-shared.d.ts +1 -4
  83. package/dist/components/file-tree/file-tree-toolbar.d.ts +11 -0
  84. package/dist/components/file-tree/file-tree-tooltip-surface.d.ts +8 -8
  85. package/dist/components/file-tree/locales/en-US.d.ts +69 -0
  86. package/dist/components/file-tree/locales/zh-CN.d.ts +69 -0
  87. package/dist/components/file-tree/style.css +207 -42
  88. package/dist/components/file-tree/types.d.ts +58 -10
  89. package/dist/components/file-tree/use-file-tree-actions.d.ts +4 -1
  90. package/dist/components/scope-switcher/labels.d.ts +3 -0
  91. package/dist/components/scope-switcher/locales/en-US.d.ts +8 -0
  92. package/dist/components/scope-switcher/locales/zh-CN.d.ts +8 -0
  93. package/dist/components/scope-switcher/scope-panel.d.ts +1 -1
  94. package/dist/components/scope-switcher/scope-switcher.d.ts +1 -1
  95. package/dist/components/scope-switcher/style.css +14 -2
  96. package/dist/components/scope-switcher/types.d.ts +11 -5
  97. package/dist/components/style.css +10144 -6840
  98. package/dist/components/tui/locales/en-US.d.ts +35 -0
  99. package/dist/components/tui/locales/zh-CN.d.ts +35 -0
  100. package/dist/components/tui/style.css +310 -18
  101. package/dist/components/tui/tui-copy-button.d.ts +1 -1
  102. package/dist/components/tui/tui-empty.d.ts +25 -0
  103. package/dist/components/tui/tui-labels.d.ts +2 -2
  104. package/dist/components/tui/tui.d.ts +1 -1
  105. package/dist/components/tui/types.d.ts +35 -12
  106. package/dist/components/tui.js +1 -1
  107. package/dist/components/viking-bot/ark-adapter.d.ts +2 -0
  108. package/dist/components/viking-bot/ark-message-body.d.ts +1 -7
  109. package/dist/components/viking-bot/ark-message-list-view.d.ts +1 -1
  110. package/dist/components/viking-bot/ark-message-row.d.ts +3 -1
  111. package/dist/components/viking-bot/bot-popover.d.ts +9 -0
  112. package/dist/components/viking-bot/capabilities.d.ts +49 -0
  113. package/dist/components/viking-bot/composer-attachments.d.ts +13 -0
  114. package/dist/components/viking-bot/composer-controls.d.ts +10 -0
  115. package/dist/components/viking-bot/composer-footer.d.ts +17 -0
  116. package/dist/components/viking-bot/composer-references.d.ts +20 -0
  117. package/dist/components/viking-bot/composer-text.d.ts +10 -0
  118. package/dist/components/viking-bot/index.d.ts +3 -1
  119. package/dist/components/viking-bot/interaction/ask-human-fields.d.ts +1 -1
  120. package/dist/components/viking-bot/interaction/labels.d.ts +2 -1
  121. package/dist/components/viking-bot/interaction/locales/en-US.d.ts +17 -0
  122. package/dist/components/viking-bot/interaction/locales/zh-CN.d.ts +17 -0
  123. package/dist/components/viking-bot/interaction/types.d.ts +8 -3
  124. package/dist/components/viking-bot/interaction/viking-bot-interaction.d.ts +1 -1
  125. package/dist/components/viking-bot/labels.d.ts +2 -0
  126. package/dist/components/viking-bot/locales/en-US.d.ts +40 -0
  127. package/dist/components/viking-bot/locales/zh-CN.d.ts +40 -0
  128. package/dist/components/viking-bot/markdown-links.d.ts +27 -0
  129. package/dist/components/viking-bot/message-activity.d.ts +7 -0
  130. package/dist/components/viking-bot/message-code-block.d.ts +8 -0
  131. package/dist/components/viking-bot/message-footer.d.ts +8 -0
  132. package/dist/components/viking-bot/message-markdown.d.ts +9 -0
  133. package/dist/components/viking-bot/model.d.ts +37 -3
  134. package/dist/components/viking-bot/quick-input-tracker.d.ts +16 -0
  135. package/dist/components/viking-bot/quick-inputs.d.ts +6 -0
  136. package/dist/components/viking-bot/reference-picker.d.ts +16 -0
  137. package/dist/components/viking-bot/session-actions.d.ts +11 -0
  138. package/dist/components/viking-bot/style.css +1486 -48
  139. package/dist/components/viking-bot/tool-activity.d.ts +9 -0
  140. package/dist/components/viking-bot/tool-result-links.d.ts +6 -0
  141. package/dist/components/viking-bot/types.d.ts +21 -9
  142. package/dist/components/viking-bot/use-quick-input.d.ts +17 -0
  143. package/dist/components/viking-bot/viking-bot.d.ts +1 -6
  144. package/dist/components/viking-bot/welcome.d.ts +8 -0
  145. package/dist/components/viking-bot.js +1 -1
  146. package/dist/c~0.js +533 -66
  147. package/dist/e~0.js +333 -0
  148. package/dist/file-preview-viewer~0.js +90 -8
  149. package/dist/f~0.js +39 -47
  150. package/dist/h~0.js +5 -1
  151. package/dist/icons/console-icons.d.ts +12 -0
  152. package/dist/icons/index.d.ts +2 -0
  153. package/dist/icons/viking-bot-icons.d.ts +6 -0
  154. package/dist/icons.js +1 -0
  155. package/dist/index.d.ts +4 -0
  156. package/dist/index.js +3 -1
  157. package/dist/k~0.js +1 -0
  158. package/dist/lg~0.js +155 -0
  159. package/dist/lk~0.js +37 -8
  160. package/dist/l~0.js +1447 -25
  161. package/dist/modules/console/command-messages.d.ts +19 -0
  162. package/dist/modules/console/command-parser.d.ts +15 -0
  163. package/dist/modules/console/command-specs.d.ts +15 -0
  164. package/dist/modules/console/commands.d.ts +6 -0
  165. package/dist/modules/console/console-history.d.ts +10 -0
  166. package/dist/modules/console/console-toolbar.d.ts +18 -0
  167. package/dist/modules/console/console.d.ts +1 -3
  168. package/dist/modules/console/controller.d.ts +17 -0
  169. package/dist/modules/console/index.d.ts +2 -0
  170. package/dist/modules/console/labels.d.ts +61 -0
  171. package/dist/modules/console/locales/en-US.d.ts +49 -0
  172. package/dist/modules/console/locales/zh-CN.d.ts +3 -0
  173. package/dist/modules/console/localize-records.d.ts +11 -0
  174. package/dist/modules/console/results.d.ts +2 -0
  175. package/dist/modules/console/style.css +10905 -15
  176. package/dist/modules/console/types.d.ts +59 -80
  177. package/dist/modules/console/use-console.d.ts +3 -0
  178. package/dist/modules/console.js +1 -1
  179. package/dist/modules/file-browser/file-browser-detail-icons.d.ts +10 -0
  180. package/dist/modules/file-browser/file-browser-detail.d.ts +34 -0
  181. package/dist/modules/file-browser/file-browser-empty.d.ts +3 -0
  182. package/dist/modules/file-browser/file-browser-failure.d.ts +22 -0
  183. package/dist/modules/file-browser/file-browser-icons.d.ts +18 -0
  184. package/dist/modules/file-browser/file-browser-labels.d.ts +27 -0
  185. package/dist/modules/file-browser/file-browser-layout.d.ts +27 -0
  186. package/dist/modules/file-browser/file-browser-toolbar.d.ts +17 -0
  187. package/dist/modules/file-browser/file-browser-tree-pane.d.ts +32 -0
  188. package/dist/modules/file-browser/file-browser.d.ts +14 -5
  189. package/dist/modules/file-browser/find-result.d.ts +24 -0
  190. package/dist/modules/file-browser/fs-directories.d.ts +33 -0
  191. package/dist/modules/file-browser/fs-file-kind.d.ts +19 -0
  192. package/dist/modules/file-browser/fs-icon.d.ts +17 -0
  193. package/dist/modules/file-browser/fs-model.d.ts +106 -0
  194. package/dist/modules/file-browser/fs-page.d.ts +16 -0
  195. package/dist/modules/file-browser/fs-path.d.ts +16 -0
  196. package/dist/modules/file-browser/fs-read-directory.d.ts +16 -0
  197. package/dist/modules/file-browser/fs-scope.d.ts +22 -0
  198. package/dist/modules/file-browser/fs-stat.d.ts +25 -0
  199. package/dist/modules/file-browser/index.d.ts +3 -1
  200. package/dist/modules/file-browser/locales/en-US.d.ts +25 -0
  201. package/dist/modules/file-browser/locales/zh-CN.d.ts +25 -0
  202. package/dist/modules/file-browser/style.css +6388 -41
  203. package/dist/modules/file-browser/types.d.ts +206 -52
  204. package/dist/modules/file-browser/use-container-width.d.ts +17 -0
  205. package/dist/modules/file-browser/use-file-browser.d.ts +54 -0
  206. package/dist/modules/file-browser/use-fs-preview.d.ts +65 -0
  207. package/dist/modules/file-browser/use-fs-search.d.ts +35 -0
  208. package/dist/modules/file-browser/use-fs-tree.d.ts +43 -0
  209. package/dist/modules/file-browser/use-request-scope.d.ts +39 -0
  210. package/dist/modules/file-browser.js +1 -1
  211. package/dist/modules/scope-cascade/labels.d.ts +6 -0
  212. package/dist/modules/scope-cascade/locales/en-US.d.ts +6 -0
  213. package/dist/modules/scope-cascade/locales/zh-CN.d.ts +3 -0
  214. package/dist/modules/scope-cascade/scope-cascade.d.ts +1 -1
  215. package/dist/modules/scope-cascade/style.css +14 -2
  216. package/dist/modules/scope-cascade/types.d.ts +3 -0
  217. package/dist/modules/style.css +17338 -77
  218. package/dist/nx~0.js +15 -0
  219. package/dist/n~0.js +403 -144
  220. package/dist/o~0.js +106 -0
  221. package/dist/p~0.js +27 -0
  222. package/dist/rslib-runtime~0.js +42 -0
  223. package/dist/r~0.js +152 -0
  224. package/dist/shared/components/divider/divider.d.ts +18 -0
  225. package/dist/shared/components/divider/index.d.ts +1 -0
  226. package/dist/shared/components/divider/types.d.ts +35 -0
  227. package/dist/shared/components/drawer/drawer.d.ts +13 -0
  228. package/dist/shared/components/drawer/index.d.ts +1 -0
  229. package/dist/shared/components/overlay/types.d.ts +7 -0
  230. package/dist/shared/components/{tooltip/use-tooltip-position.d.ts → overlay/use-overlay-position.d.ts} +6 -6
  231. package/dist/shared/components/popover/index.d.ts +1 -0
  232. package/dist/shared/components/popover/popover.d.ts +23 -0
  233. package/dist/shared/components/popover/types.d.ts +50 -0
  234. package/dist/shared/components/resizable/clamp.d.ts +13 -0
  235. package/dist/shared/components/resizable/index.d.ts +2 -0
  236. package/dist/shared/components/resizable/resizable-handle.d.ts +25 -0
  237. package/dist/shared/components/resizable/types.d.ts +48 -0
  238. package/dist/shared/components/tooltip/types.d.ts +5 -5
  239. package/dist/shared/components/tooltip/use-portal-theme.d.ts +3 -0
  240. package/dist/shared/locale.d.ts +6 -0
  241. package/dist/style.css +27753 -7176
  242. package/dist/u~0.js +75 -58
  243. package/dist/viking-bot-composer~0.js +434 -77
  244. package/dist/viking-bot-interaction~0.js +11 -11
  245. package/package.json +18 -4
  246. package/dist/components/file-tree/file-tree-tooltip.d.ts +0 -17
  247. package/dist/components/tui/tui-labels-zh.d.ts +0 -2
  248. package/dist/g~0.js +0 -1207
  249. package/dist/modules/file-browser/file-browser-toolbar-button.d.ts +0 -10
package/dist/c~0.js CHANGED
@@ -1,7 +1,30 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Suspense, forwardRef, lazy } from "react";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { Suspense, createContext, forwardRef, lazy, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { resolveLocale } from "./nx~0.js";
5
+ import { useOverlayPosition } from "./o~0.js";
6
+ import { Tooltip } from "./r~0.js";
7
+ import { VikingBotIcon } from "./lg~0.js";
3
8
  import { VikingBotInteraction } from "./w~0.js";
4
- const DEFAULT_LABELS = {
9
+ const en_US_messages = {
10
+ activityRunning: 'Running',
11
+ activityCompleted: 'Completed',
12
+ toolInput: 'Input',
13
+ toolOutput: 'Output',
14
+ similarity: 'Similarity',
15
+ sessionHistory: 'Session history',
16
+ newSession: 'New session',
17
+ emptySessions: 'No sessions yet',
18
+ loading: 'Loading…',
19
+ loadMore: 'Load more',
20
+ reference: 'Reference a file or directory',
21
+ searchReferences: 'Search files and directories',
22
+ emptyReferences: 'No matching files or directories',
23
+ removeReference: 'Remove reference',
24
+ expandReference: 'Expand {name}',
25
+ collapseReference: 'Collapse {name}',
26
+ welcomeTitle: 'Welcome to VikingBot',
27
+ welcomeDescription: 'Connect your resources, memories and context to turn your data into usable knowledge.',
5
28
  placeholder: 'Ask VikingBot anything',
6
29
  send: 'Send',
7
30
  stop: 'Stop',
@@ -18,11 +41,402 @@ const DEFAULT_LABELS = {
18
41
  toolError: 'Failed',
19
42
  context: 'Context',
20
43
  empty: 'Start a conversation',
21
- newSession: 'New chat',
22
44
  retry: 'Retry',
23
45
  scrollToLatest: 'Scroll to latest',
24
46
  unavailable: 'VikingBot is unavailable'
25
47
  };
48
+ const en_US = en_US_messages;
49
+ const zh_CN_messages = {
50
+ activityRunning: '执行中',
51
+ activityCompleted: '已执行',
52
+ toolInput: '输入',
53
+ toolOutput: '输出',
54
+ similarity: '相似度',
55
+ sessionHistory: '历史会话',
56
+ newSession: '新建会话',
57
+ emptySessions: '暂无历史会话',
58
+ loading: '加载中…',
59
+ loadMore: '加载更多',
60
+ reference: '引用文件或目录',
61
+ searchReferences: '搜索文件或目录',
62
+ emptyReferences: '暂无匹配的文件或目录',
63
+ removeReference: '移除引用',
64
+ expandReference: '展开 {name}',
65
+ collapseReference: '收起 {name}',
66
+ welcomeTitle: '欢迎使用 VikingBot',
67
+ welcomeDescription: '连接你的资料、记忆与上下文,让每一份数据都成为可用的知识。',
68
+ placeholder: '向 VikingBot 提问',
69
+ send: '发送',
70
+ stop: '停止',
71
+ attach: '添加资源',
72
+ removeAttachment: '移除附件',
73
+ copy: '复制',
74
+ copied: '已复制',
75
+ reasoning: '推理',
76
+ thinking: '思考中',
77
+ tool: '工具调用',
78
+ toolPending: '等待中',
79
+ toolRunning: '正在调用',
80
+ toolCompleted: '已调用',
81
+ toolError: '调用失败',
82
+ context: '上下文',
83
+ empty: '开始对话',
84
+ retry: '重试',
85
+ scrollToLatest: '滚动到最新消息',
86
+ unavailable: 'VikingBot 暂不可用'
87
+ };
88
+ const zh_CN = zh_CN_messages;
89
+ const LOCALES = {
90
+ 'en-US': en_US,
91
+ 'zh-CN': zh_CN
92
+ };
93
+ const DEFAULT_LABELS = en_US;
94
+ function resolveVikingBotLabels(locale, labels) {
95
+ return resolveLocale(LOCALES, locale, labels);
96
+ }
97
+ const subscribe = ()=>()=>{};
98
+ function BotPopover({ label, trigger: renderTrigger, children, placement = 'bottom', onOpen }) {
99
+ const mounted = useSyncExternalStore(subscribe, ()=>true, ()=>false);
100
+ const native = mounted && 'popover' in HTMLElement.prototype;
101
+ const [open, setOpen] = useState(false);
102
+ const [surface, setSurface] = useState(null);
103
+ const anchor = useRef(null);
104
+ const id = useId();
105
+ const position = useOverlayPosition(open, anchor, surface, placement, 'end');
106
+ const close = ()=>{
107
+ if (native) surface?.hidePopover();
108
+ else setOpen(false);
109
+ anchor.current?.querySelector('button')?.focus();
110
+ };
111
+ useEffect(()=>{
112
+ if (!surface) return;
113
+ const toggle = ()=>{
114
+ const expanded = surface.matches(':popover-open');
115
+ setOpen(expanded);
116
+ if (expanded) onOpen?.();
117
+ };
118
+ if (native) surface.addEventListener('toggle', toggle);
119
+ return ()=>surface.removeEventListener('toggle', toggle);
120
+ }, [
121
+ native,
122
+ surface,
123
+ onOpen
124
+ ]);
125
+ useEffect(()=>{
126
+ if (!open) return;
127
+ (surface?.querySelector('input, button') ?? surface)?.focus();
128
+ }, [
129
+ open,
130
+ surface
131
+ ]);
132
+ useEffect(()=>{
133
+ if (native || !open) return;
134
+ const outside = (event)=>{
135
+ const node = event.target;
136
+ if (!anchor.current?.contains(node) && !surface?.contains(node)) setOpen(false);
137
+ };
138
+ const escape = (event)=>{
139
+ if ('Escape' !== event.key) return;
140
+ setOpen(false);
141
+ anchor.current?.querySelector('button')?.focus();
142
+ };
143
+ document.addEventListener('mousedown', outside);
144
+ document.addEventListener('keydown', escape);
145
+ return ()=>{
146
+ document.removeEventListener('mousedown', outside);
147
+ document.removeEventListener('keydown', escape);
148
+ };
149
+ }, [
150
+ native,
151
+ open,
152
+ surface
153
+ ]);
154
+ const invoker = native ? {
155
+ popovertarget: id
156
+ } : {};
157
+ return /*#__PURE__*/ jsxs("span", {
158
+ className: "ov-viking-bot__popover-anchor",
159
+ ref: anchor,
160
+ children: [
161
+ renderTrigger({
162
+ ...invoker,
163
+ 'aria-haspopup': 'dialog',
164
+ 'aria-controls': id,
165
+ 'aria-expanded': open,
166
+ onClick: native ? void 0 : ()=>{
167
+ setOpen(!open);
168
+ if (!open) onOpen?.();
169
+ }
170
+ }),
171
+ mounted ? /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
172
+ ref: setSurface,
173
+ id: id,
174
+ popover: "auto",
175
+ role: "dialog",
176
+ tabIndex: -1,
177
+ "aria-label": label,
178
+ hidden: !native && !open,
179
+ className: `ov-viking-bot__popover ov-viking-bot__popover--${placement}`,
180
+ style: {
181
+ top: position.top,
182
+ left: position.left
183
+ },
184
+ children: open ? children(close) : null
185
+ }), document.body) : null
186
+ ]
187
+ });
188
+ }
189
+ function VikingBotSessionActions({ sessions, extra, labels: overrides, locale }) {
190
+ const labels = resolveVikingBotLabels(locale, overrides);
191
+ return /*#__PURE__*/ jsxs("div", {
192
+ className: "ov-viking-bot__session-actions",
193
+ children: [
194
+ extra,
195
+ sessions ? /*#__PURE__*/ jsxs(Fragment, {
196
+ children: [
197
+ /*#__PURE__*/ jsx(BotPopover, {
198
+ label: labels.sessionHistory,
199
+ onOpen: sessions.onOpenHistory,
200
+ trigger: (props)=>/*#__PURE__*/ jsx(Tooltip, {
201
+ content: labels.sessionHistory,
202
+ disabled: true === props['aria-expanded'],
203
+ children: /*#__PURE__*/ jsx("button", {
204
+ ...props,
205
+ type: "button",
206
+ className: "ov-viking-bot__header-action",
207
+ "aria-label": labels.sessionHistory,
208
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
209
+ name: "history"
210
+ })
211
+ })
212
+ }),
213
+ children: (close)=>/*#__PURE__*/ jsxs("div", {
214
+ className: "ov-viking-bot__session-history",
215
+ "aria-busy": sessions.isLoading,
216
+ children: [
217
+ sessions.isLoading ? /*#__PURE__*/ jsx("p", {
218
+ role: "status",
219
+ children: labels.loading
220
+ }) : null,
221
+ sessions.error ? /*#__PURE__*/ jsx("p", {
222
+ role: "alert",
223
+ children: sessions.error
224
+ }) : null,
225
+ sessions.isLoading || sessions.error || sessions.items.length ? null : /*#__PURE__*/ jsx("p", {
226
+ className: "ov-viking-bot__empty-history",
227
+ children: labels.emptySessions
228
+ }),
229
+ /*#__PURE__*/ jsx("ul", {
230
+ children: sessions.items.map((item)=>{
231
+ const date = new Date(item.updatedAt ?? '');
232
+ const validDate = Number.isFinite(date.getTime());
233
+ return /*#__PURE__*/ jsx("li", {
234
+ children: /*#__PURE__*/ jsxs("button", {
235
+ type: "button",
236
+ "aria-current": sessions.currentId === item.id || void 0,
237
+ onClick: ()=>{
238
+ close();
239
+ sessions.onSelect(item.id);
240
+ },
241
+ children: [
242
+ /*#__PURE__*/ jsx("span", {
243
+ children: item.title
244
+ }),
245
+ validDate ? /*#__PURE__*/ jsx("time", {
246
+ dateTime: item.updatedAt,
247
+ children: new Intl.DateTimeFormat(locale, {
248
+ dateStyle: 'short',
249
+ timeStyle: 'short'
250
+ }).format(date)
251
+ }) : null
252
+ ]
253
+ })
254
+ }, item.id);
255
+ })
256
+ }),
257
+ sessions.hasMore && sessions.onLoadMore ? /*#__PURE__*/ jsx("button", {
258
+ type: "button",
259
+ disabled: sessions.isLoading,
260
+ onClick: sessions.onLoadMore,
261
+ children: labels.loadMore
262
+ }) : null
263
+ ]
264
+ })
265
+ }),
266
+ /*#__PURE__*/ jsx(Tooltip, {
267
+ content: labels.newSession,
268
+ children: /*#__PURE__*/ jsx("button", {
269
+ type: "button",
270
+ className: "ov-viking-bot__header-action",
271
+ "aria-label": labels.newSession,
272
+ onClick: sessions.onNew,
273
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
274
+ name: "newSession"
275
+ })
276
+ })
277
+ })
278
+ ]
279
+ }) : null
280
+ ]
281
+ });
282
+ }
283
+ function QuickInputs({ items, onSelect, disabled }) {
284
+ if (!items?.length) return null;
285
+ return /*#__PURE__*/ jsx("div", {
286
+ className: "ov-viking-bot__quick-inputs",
287
+ children: items.map((item)=>/*#__PURE__*/ jsxs("button", {
288
+ type: "button",
289
+ disabled: disabled,
290
+ onClick: ()=>onSelect(item),
291
+ children: [
292
+ item.icon,
293
+ item.label
294
+ ]
295
+ }, item.id))
296
+ });
297
+ }
298
+ function VikingBotWelcome({ labels, quickInputs, onSelect, disabled }) {
299
+ return /*#__PURE__*/ jsxs("div", {
300
+ className: "ov-viking-bot__home",
301
+ children: [
302
+ /*#__PURE__*/ jsxs("div", {
303
+ className: "ov-viking-bot__home-intro",
304
+ children: [
305
+ /*#__PURE__*/ jsxs("div", {
306
+ className: "ov-viking-bot__home-illustration",
307
+ "aria-hidden": "true",
308
+ children: [
309
+ /*#__PURE__*/ jsx("span", {
310
+ className: "ov-viking-bot__home-bulb",
311
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
312
+ name: "bulb",
313
+ width: 24,
314
+ height: 24,
315
+ fill: "none"
316
+ })
317
+ }),
318
+ /*#__PURE__*/ jsx("span", {
319
+ className: "ov-viking-bot__home-book",
320
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
321
+ name: "book",
322
+ width: 24,
323
+ height: 24,
324
+ viewBox: "-2.833333 -3.5 20 19.2"
325
+ })
326
+ }),
327
+ /*#__PURE__*/ jsx("span", {
328
+ className: "ov-viking-bot__home-video",
329
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
330
+ name: "video",
331
+ width: 24,
332
+ height: 24
333
+ })
334
+ })
335
+ ]
336
+ }),
337
+ /*#__PURE__*/ jsxs("div", {
338
+ className: "ov-viking-bot__home-text",
339
+ children: [
340
+ /*#__PURE__*/ jsx("h2", {
341
+ children: labels.welcomeTitle
342
+ }),
343
+ /*#__PURE__*/ jsx("p", {
344
+ children: labels.welcomeDescription
345
+ })
346
+ ]
347
+ })
348
+ ]
349
+ }),
350
+ /*#__PURE__*/ jsx(QuickInputs, {
351
+ items: quickInputs,
352
+ onSelect: onSelect,
353
+ disabled: disabled
354
+ })
355
+ ]
356
+ });
357
+ }
358
+ function editRange(before, after, caret) {
359
+ let prefix = 0;
360
+ while(prefix < before.length && prefix < after.length && before[prefix] === after[prefix])prefix++;
361
+ let suffix = 0;
362
+ while(suffix < before.length && suffix < after.length && before[before.length - 1 - suffix] === after[after.length - 1 - suffix])suffix++;
363
+ const delta = after.length - before.length;
364
+ if (prefix + suffix <= Math.min(before.length, after.length)) return {
365
+ from: prefix,
366
+ to: before.length - suffix,
367
+ delta
368
+ };
369
+ if (void 0 !== caret) {
370
+ const oldEnd = caret - delta;
371
+ if (oldEnd >= 0 && oldEnd <= before.length && caret >= 0 && caret <= after.length && before.slice(oldEnd) === after.slice(caret)) return {
372
+ from: Math.min(prefix, oldEnd, caret),
373
+ to: oldEnd,
374
+ delta
375
+ };
376
+ }
377
+ }
378
+ function createQuickInputTracker(initial, previous) {
379
+ let text = previous?.text ?? initial;
380
+ let range = previous?.range ? {
381
+ ...previous.range
382
+ } : void 0;
383
+ const edit = (next, caret)=>{
384
+ if (text === next) return;
385
+ const change = editRange(text, next, caret);
386
+ if (range) if (change) {
387
+ if (change.to <= range.from) range = {
388
+ from: range.from + change.delta,
389
+ to: range.to + change.delta
390
+ };
391
+ else if (change.from < range.to) range = void 0;
392
+ } else range = void 0;
393
+ text = next;
394
+ };
395
+ edit(initial);
396
+ return {
397
+ snapshot: ()=>({
398
+ text,
399
+ range
400
+ }),
401
+ edit,
402
+ release () {
403
+ range = void 0;
404
+ },
405
+ insert (value, prompt) {
406
+ edit(value);
407
+ const prefix = range ? text.slice(0, range.from) : text.trim() ? `${text}\n` : '';
408
+ const suffix = range ? text.slice(range.to) : '';
409
+ text = prefix + prompt + suffix;
410
+ range = {
411
+ from: prefix.length,
412
+ to: prefix.length + prompt.length
413
+ };
414
+ return text;
415
+ }
416
+ };
417
+ }
418
+ const QuickInputScope = createContext(null);
419
+ function useQuickInput(value, onChange, onSelect, ownsScope = false) {
420
+ const inherited = useContext(QuickInputScope);
421
+ const [local, setLocal] = useState(()=>({
422
+ value,
423
+ tracker: createQuickInputTracker(value)
424
+ }));
425
+ if (local.value !== value) setLocal({
426
+ value,
427
+ tracker: createQuickInputTracker(value, local.tracker.snapshot())
428
+ });
429
+ const tracker = ownsScope ? local.tracker : inherited ?? local.tracker;
430
+ return {
431
+ tracker,
432
+ select (input) {
433
+ if (onSelect) {
434
+ if (tracker === local.tracker) tracker.release();
435
+ onSelect(input);
436
+ } else onChange(tracker.insert(value, input.prompt));
437
+ }
438
+ };
439
+ }
26
440
  const View = /*#__PURE__*/ lazy(async ()=>{
27
441
  const { VikingBotComposerView } = await import("./viking-bot-composer~0.js");
28
442
  return {
@@ -49,7 +463,9 @@ const toReasoningItem = (part, index)=>({
49
463
  part.text
50
464
  ] : [],
51
465
  visibility: 'contentAllowed',
52
- durationMs: part.durationMs
466
+ durationMs: part.durationMs,
467
+ startedAt: void 0 === part.startedAt ? void 0 : new Date(part.startedAt).getTime(),
468
+ completedAt: void 0 === part.completedAt ? void 0 : new Date(part.completedAt).getTime()
53
469
  });
54
470
  const toToolItem = (part)=>({
55
471
  id: part.id,
@@ -59,9 +475,33 @@ const toToolItem = (part)=>({
59
475
  tool: part.name,
60
476
  arguments: part.input,
61
477
  resultPreview: part.output,
62
- durationMs: part.durationMs
478
+ error: 'error' === part.status ? part.output : void 0,
479
+ durationMs: part.durationMs,
480
+ startedAt: void 0 === part.startedAt ? void 0 : new Date(part.startedAt).getTime(),
481
+ completedAt: void 0 === part.completedAt ? void 0 : new Date(part.completedAt).getTime()
63
482
  });
64
483
  const isActivityPart = (part)=>'reasoning' === part.type || 'tool' === part.type;
484
+ function mergeToolResults(parts) {
485
+ const results = new Map(parts.flatMap((part)=>'tool_result' === part.type ? [
486
+ [
487
+ part.id,
488
+ part
489
+ ]
490
+ ] : []));
491
+ const calls = new Set(parts.flatMap((part)=>'tool' === part.type ? [
492
+ part.id
493
+ ] : []));
494
+ return parts.filter((part)=>'tool_result' !== part.type || !calls.has(part.id)).map((part)=>{
495
+ if ('tool' !== part.type) return part;
496
+ const result = results.get(part.id);
497
+ return result ? {
498
+ ...part,
499
+ output: result.output,
500
+ results: result.results ?? part.results,
501
+ status: result.isError ? 'error' : 'completed'
502
+ } : part;
503
+ });
504
+ }
65
505
  function groupActivityParts(parts) {
66
506
  const groups = new Map();
67
507
  const order = [];
@@ -115,10 +555,7 @@ function ListSkeleton() {
115
555
  });
116
556
  }
117
557
  function VikingBotMessageList(props) {
118
- const labels = {
119
- ...DEFAULT_LABELS,
120
- ...props.labels
121
- };
558
+ const labels = resolveVikingBotLabels(props.locale, props.labels);
122
559
  const items = toRenderItems(props.messages, props.streaming);
123
560
  if (0 === items.length) return /*#__PURE__*/ jsx("div", {
124
561
  className: "ov-viking-bot__empty",
@@ -131,12 +568,25 @@ function VikingBotMessageList(props) {
131
568
  })
132
569
  });
133
570
  }
134
- function VikingBot({ messages, className, streaming, draft, attachments, isSending, isAvailable = true, unavailableMessage, emptyState, header, footer, children, messageList, composer, interaction, interactionSlot, listKey, composerRef, onDraftChange, onFilesAdded, onAttachmentRemove, onSend, onCancel, onOpenUri, onCopy, onMessageAction, labels: overrides, ...rest }) {
135
- const labels = {
136
- ...DEFAULT_LABELS,
137
- ...overrides
138
- };
571
+ function VikingBot({ messages, className, streaming, draft, attachments, isSending, isAvailable = true, unavailableMessage, emptyState, header, sessions, headerActions, locale, quickInputs, onQuickInputSelect, references, footer, children, messageList, composer, interaction, interactionSlot, listKey, composerRef, onDraftChange, onFilesAdded, onAttachmentRemove, onSend, onCancel, onOpenUri, onCopy, onMessageAction, labels: overrides, ...rest }) {
572
+ const labels = resolveVikingBotLabels(locale, overrides);
139
573
  const hasMessages = messages.length > 0;
574
+ const localComposer = useRef(null);
575
+ const inputRef = composerRef ?? localComposer;
576
+ const shortcuts = useQuickInput(draft ?? '', (next)=>{
577
+ if (inputRef.current) inputRef.current.setText(next);
578
+ else onDraftChange?.(next);
579
+ }, onQuickInputSelect, true);
580
+ const selectQuickInput = (item)=>{
581
+ shortcuts.select(item);
582
+ inputRef.current?.focus();
583
+ };
584
+ const renderedHeader = void 0 !== header ? header : sessions || headerActions ? /*#__PURE__*/ jsx(VikingBotSessionActions, {
585
+ sessions: sessions,
586
+ extra: headerActions,
587
+ labels: labels,
588
+ locale: locale
589
+ }) : null;
140
590
  if (children) return /*#__PURE__*/ jsx("div", {
141
591
  className: [
142
592
  'ov-viking-bot',
@@ -145,57 +595,74 @@ function VikingBot({ messages, className, streaming, draft, attachments, isSendi
145
595
  ...rest,
146
596
  children: children
147
597
  });
148
- return /*#__PURE__*/ jsxs("div", {
149
- className: [
150
- 'ov-viking-bot',
151
- className
152
- ].filter(Boolean).join(' '),
153
- ...rest,
154
- children: [
155
- header ? /*#__PURE__*/ jsx("div", {
156
- className: "ov-viking-bot__header",
157
- children: header
158
- }) : null,
159
- isAvailable ? null : /*#__PURE__*/ jsx("p", {
160
- className: "ov-viking-bot__unavailable",
161
- role: "status",
162
- children: unavailableMessage ?? labels.unavailable
163
- }),
164
- /*#__PURE__*/ jsx("div", {
165
- className: "ov-viking-bot__body",
166
- children: !hasMessages && emptyState ? /*#__PURE__*/ jsx("div", {
167
- className: "ov-viking-bot__empty",
168
- children: emptyState
169
- }) : messageList ?? /*#__PURE__*/ jsx(VikingBotMessageList, {
170
- messages: messages,
171
- streaming: streaming,
172
- listKey: listKey,
173
- onOpenUri: onOpenUri,
174
- onCopy: onCopy,
175
- onMessageAction: onMessageAction,
598
+ return /*#__PURE__*/ jsx(QuickInputScope.Provider, {
599
+ value: shortcuts.tracker,
600
+ children: /*#__PURE__*/ jsxs("div", {
601
+ className: [
602
+ 'ov-viking-bot',
603
+ className
604
+ ].filter(Boolean).join(' '),
605
+ ...rest,
606
+ children: [
607
+ renderedHeader ? /*#__PURE__*/ jsx("div", {
608
+ className: "ov-viking-bot__header",
609
+ children: renderedHeader
610
+ }) : null,
611
+ isAvailable ? null : /*#__PURE__*/ jsx("p", {
612
+ className: "ov-viking-bot__unavailable",
613
+ role: "status",
614
+ children: unavailableMessage ?? labels.unavailable
615
+ }),
616
+ /*#__PURE__*/ jsx("div", {
617
+ className: "ov-viking-bot__body",
618
+ children: void 0 !== messageList ? messageList : hasMessages || streaming ? /*#__PURE__*/ jsx(VikingBotMessageList, {
619
+ locale: locale,
620
+ messages: messages,
621
+ streaming: streaming,
622
+ listKey: listKey,
623
+ onOpenUri: onOpenUri,
624
+ onCopy: onCopy,
625
+ onMessageAction: onMessageAction,
626
+ labels: overrides
627
+ }) : /*#__PURE__*/ jsx("div", {
628
+ className: `ov-viking-bot__empty${void 0 === emptyState ? ' ov-viking-bot__empty--welcome' : ''}`,
629
+ children: void 0 === emptyState ? /*#__PURE__*/ jsx(VikingBotWelcome, {
630
+ labels: labels,
631
+ quickInputs: quickInputs,
632
+ onSelect: selectQuickInput,
633
+ disabled: isSending || !isAvailable || !onDraftChange && !onQuickInputSelect
634
+ }) : emptyState
635
+ })
636
+ }),
637
+ footer ? /*#__PURE__*/ jsx("div", {
638
+ className: "ov-viking-bot__footer",
639
+ children: footer
640
+ }) : null,
641
+ interaction ? interactionSlot ?? /*#__PURE__*/ jsx(VikingBotInteraction, {
642
+ ...interaction,
643
+ locale: locale
644
+ }) : composer ?? (void 0 !== draft ? /*#__PURE__*/ jsx(lazy_composer_VikingBotComposer, {
645
+ locale: locale,
646
+ ref: inputRef,
647
+ value: draft,
648
+ attachments: attachments,
649
+ disabled: !isAvailable,
650
+ isSending: isSending,
651
+ references: references,
652
+ quickInputs: hasMessages || streaming || void 0 !== emptyState ? quickInputs : void 0,
653
+ onQuickInputSelect: selectQuickInput,
654
+ onValueChange: onDraftChange ? (next)=>{
655
+ shortcuts.tracker.edit(next);
656
+ onDraftChange(next);
657
+ } : void 0,
658
+ onFilesAdded: onFilesAdded,
659
+ onAttachmentRemove: onAttachmentRemove,
660
+ onSend: onSend,
661
+ onCancel: onCancel,
176
662
  labels: overrides
177
- })
178
- }),
179
- footer ? /*#__PURE__*/ jsx("div", {
180
- className: "ov-viking-bot__footer",
181
- children: footer
182
- }) : null,
183
- interaction ? interactionSlot ?? /*#__PURE__*/ jsx(VikingBotInteraction, {
184
- ...interaction
185
- }) : composer ?? (void 0 !== draft ? /*#__PURE__*/ jsx(lazy_composer_VikingBotComposer, {
186
- ref: composerRef,
187
- value: draft,
188
- attachments: attachments,
189
- disabled: !isAvailable,
190
- isSending: isSending,
191
- onValueChange: onDraftChange,
192
- onFilesAdded: onFilesAdded,
193
- onAttachmentRemove: onAttachmentRemove,
194
- onSend: onSend,
195
- onCancel: onCancel,
196
- labels: overrides
197
- }) : null)
198
- ]
663
+ }) : null)
664
+ ]
665
+ })
199
666
  });
200
667
  }
201
- export { DEFAULT_LABELS, VikingBot, VikingBotMessageList, groupActivityParts, lazy_composer_VikingBotComposer as VikingBotComposer, toRenderItems };
668
+ export { BotPopover, DEFAULT_LABELS, QuickInputs, VikingBot, VikingBotMessageList, VikingBotSessionActions, groupActivityParts, lazy_composer_VikingBotComposer as VikingBotComposer, mergeToolResults, resolveVikingBotLabels, toRenderItems, useQuickInput };