@openviking/react 0.1.3 → 0.1.5

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