@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/a~0.js CHANGED
@@ -1,21 +1,1307 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- function Console({ className, style, labels }) {
3
- return /*#__PURE__*/ jsxs("div", {
4
- className: [
5
- 'ov-module-placeholder',
6
- className
7
- ].filter(Boolean).join(' '),
8
- style: style,
2
+ import { useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { resolveLocale, mergeLabels } from "./nx~0.js";
5
+ import { useOvSignal, useOvClient, createOvClient, isOvClientError } from "./ae~0.js";
6
+ import { useLocale, LocaleProvider } from "./28~0.js";
7
+ import { new_sessionreact, historyreact } from "./lg~0.js";
8
+ import { useOverlayPosition } from "./o~0.js";
9
+ import { Tooltip } from "./r~0.js";
10
+ import { VikingBotSessionActions, VikingBot } from "./c~0.js";
11
+ import { Tui } from "./3c~0.js";
12
+ const command_specs_uri = {
13
+ name: 'uri',
14
+ kind: 'uri'
15
+ };
16
+ const limit = {
17
+ name: 'limit',
18
+ kind: 'integer',
19
+ min: 1
20
+ };
21
+ const recursive = {
22
+ name: 'recursive',
23
+ kind: 'boolean'
24
+ };
25
+ const wait = {
26
+ name: 'wait',
27
+ kind: 'boolean'
28
+ };
29
+ const taskId = {
30
+ name: 'id'
31
+ };
32
+ const COMMAND_SPECS = [
33
+ {
34
+ name: 'help'
35
+ },
36
+ {
37
+ name: 'clear'
38
+ },
39
+ {
40
+ name: 'health',
41
+ skeleton: 'status',
42
+ request: ()=>({
43
+ method: 'GET',
44
+ path: '/health'
45
+ })
46
+ },
47
+ {
48
+ name: 'status',
49
+ skeleton: 'status',
50
+ request: ()=>({
51
+ method: 'GET',
52
+ path: '/api/v1/system/status'
53
+ })
54
+ },
55
+ ...[
56
+ 'ls',
57
+ 'tree'
58
+ ].map((name)=>({
59
+ name,
60
+ positional: [
61
+ {
62
+ ...command_specs_uri,
63
+ optional: true
64
+ }
65
+ ],
66
+ flags: [
67
+ limit,
68
+ {
69
+ name: 'offset',
70
+ kind: 'integer'
71
+ },
72
+ ...'tree' === name ? [
73
+ {
74
+ name: 'level_limit',
75
+ kind: 'integer',
76
+ min: 1
77
+ }
78
+ ] : [
79
+ recursive
80
+ ]
81
+ ],
82
+ skeleton: 'tree',
83
+ request: (values)=>({
84
+ method: 'GET',
85
+ path: `/api/v1/fs/${name}`,
86
+ query: {
87
+ uri: 'viking://',
88
+ limit: 100,
89
+ ...values,
90
+ output: 'original'
91
+ }
92
+ })
93
+ })),
94
+ {
95
+ name: 'stat',
96
+ positional: [
97
+ command_specs_uri
98
+ ],
99
+ skeleton: 'status',
100
+ request: (query)=>({
101
+ method: 'GET',
102
+ path: '/api/v1/fs/stat',
103
+ query
104
+ })
105
+ },
106
+ ...[
107
+ 'read',
108
+ 'abstract',
109
+ 'overview'
110
+ ].map((name)=>({
111
+ name,
112
+ positional: [
113
+ command_specs_uri
114
+ ],
115
+ flags: 'read' === name ? [
116
+ {
117
+ name: 'offset',
118
+ kind: 'integer'
119
+ },
120
+ {
121
+ ...limit,
122
+ min: -1
123
+ }
124
+ ] : [],
125
+ skeleton: 'resource',
126
+ request: (query)=>({
127
+ method: 'GET',
128
+ path: `/api/v1/content/${name}`,
129
+ query
130
+ })
131
+ })),
132
+ ...[
133
+ 'find',
134
+ 'search'
135
+ ].map((name)=>({
136
+ name,
137
+ positional: [
138
+ {
139
+ name: 'query'
140
+ }
141
+ ],
142
+ flags: [
143
+ {
144
+ name: 'target_uri',
145
+ kind: 'uri'
146
+ },
147
+ limit
148
+ ],
149
+ skeleton: 'search',
150
+ request: (body)=>({
151
+ method: 'POST',
152
+ path: `/api/v1/search/${name}`,
153
+ body
154
+ })
155
+ })),
156
+ ...[
157
+ 'grep',
158
+ 'glob'
159
+ ].map((name)=>({
160
+ name,
161
+ positional: [
162
+ {
163
+ name: 'pattern'
164
+ }
165
+ ],
166
+ flags: [
167
+ command_specs_uri,
168
+ {
169
+ name: 'node_limit',
170
+ kind: 'integer',
171
+ min: 1
172
+ },
173
+ ...'grep' === name ? [
174
+ {
175
+ name: 'case_insensitive',
176
+ kind: 'boolean'
177
+ }
178
+ ] : []
179
+ ],
180
+ skeleton: 'search',
181
+ request: (values)=>({
182
+ method: 'POST',
183
+ path: `/api/v1/search/${name}`,
184
+ body: {
185
+ uri: 'viking://',
186
+ ...values
187
+ }
188
+ })
189
+ })),
190
+ {
191
+ name: 'mkdir',
192
+ positional: [
193
+ command_specs_uri
194
+ ],
195
+ flags: [
196
+ {
197
+ name: "description"
198
+ }
199
+ ],
200
+ skeleton: 'write',
201
+ request: (body)=>({
202
+ method: 'POST',
203
+ path: '/api/v1/fs/mkdir',
204
+ body
205
+ })
206
+ },
207
+ ...[
208
+ 'cp',
209
+ 'mv'
210
+ ].map((name)=>({
211
+ name,
212
+ positional: [
213
+ {
214
+ name: 'from_uri',
215
+ kind: 'uri'
216
+ },
217
+ {
218
+ name: 'to_uri',
219
+ kind: 'uri'
220
+ }
221
+ ],
222
+ flags: 'cp' === name ? [
223
+ recursive
224
+ ] : [],
225
+ skeleton: 'write',
226
+ request: (body)=>({
227
+ method: 'POST',
228
+ path: `/api/v1/fs/${name}`,
229
+ body
230
+ })
231
+ })),
232
+ {
233
+ name: 'rm',
234
+ positional: [
235
+ command_specs_uri
236
+ ],
237
+ flags: [
238
+ recursive,
239
+ wait
240
+ ],
241
+ skeleton: 'write',
242
+ request: (query)=>({
243
+ method: 'DELETE',
244
+ path: '/api/v1/fs',
245
+ query
246
+ })
247
+ },
248
+ {
249
+ name: 'write',
250
+ positional: [
251
+ command_specs_uri,
252
+ {
253
+ name: 'content'
254
+ }
255
+ ],
256
+ flags: [
257
+ {
258
+ name: 'mode',
259
+ choices: [
260
+ 'create',
261
+ 'replace',
262
+ 'append'
263
+ ]
264
+ },
265
+ wait
266
+ ],
267
+ skeleton: 'write',
268
+ request: (body)=>({
269
+ method: 'POST',
270
+ path: '/api/v1/content/write',
271
+ body
272
+ })
273
+ },
274
+ {
275
+ name: 'task list',
276
+ flags: [
277
+ limit,
278
+ {
279
+ name: 'status'
280
+ },
281
+ {
282
+ name: 'task_type'
283
+ }
284
+ ],
285
+ skeleton: 'status',
286
+ request: (query)=>({
287
+ method: 'GET',
288
+ path: '/api/v1/tasks',
289
+ query
290
+ })
291
+ },
292
+ {
293
+ name: 'task status',
294
+ positional: [
295
+ taskId
296
+ ],
297
+ skeleton: 'status',
298
+ request: ({ id })=>({
299
+ method: 'GET',
300
+ path: `/api/v1/tasks/${encodeURIComponent(String(id))}`
301
+ })
302
+ },
303
+ {
304
+ name: 'task cancel',
305
+ positional: [
306
+ taskId
307
+ ],
308
+ skeleton: 'write',
309
+ request: ({ id })=>({
310
+ method: 'POST',
311
+ path: `/api/v1/tasks/${encodeURIComponent(String(id))}/cancel`
312
+ })
313
+ }
314
+ ];
315
+ const messages = {
316
+ labels: {
317
+ conversation: 'VikingBot',
318
+ command: 'Terminal',
319
+ mode: 'Panel mode',
320
+ description: 'Connect your resources, memories and context to turn your data into usable knowledge.',
321
+ clear: 'New session',
322
+ history: 'Command history',
323
+ emptyHistory: 'No command history yet'
324
+ },
325
+ commands: {
326
+ grep: 'Match text in resources',
327
+ glob: 'Match resource paths',
328
+ help: 'Show available commands',
329
+ clear: 'Clear local records',
330
+ health: 'Check server health',
331
+ status: 'Show system status',
332
+ ls: 'List directory entries',
333
+ tree: 'List a resource tree',
334
+ stat: 'Inspect a resource',
335
+ read: 'Read file content',
336
+ abstract: 'Read an L0 abstract',
337
+ overview: 'Read an L1 overview',
338
+ find: 'Find matching context',
339
+ search: 'Search with query planning',
340
+ mkdir: 'Create a directory',
341
+ cp: 'Copy a resource',
342
+ mv: 'Move a resource',
343
+ rm: 'Remove a resource',
344
+ write: 'Write text content',
345
+ 'task list': 'List background tasks',
346
+ 'task status': 'Inspect a background task',
347
+ 'task cancel': 'Request task cancellation'
348
+ },
349
+ availableCommands: 'Available commands',
350
+ messages: {
351
+ cancelled: ()=>'Request cancelled; the server may still process an accepted operation.',
352
+ unknownCommand: ()=>'Unknown command. Enter ov help for available commands.',
353
+ shellSyntax: ()=>'Shell syntax is not supported.',
354
+ unclosedQuote: ()=>'Unclosed quote or escape.',
355
+ unexpectedArgument: (value)=>`Unexpected argument: ${value}`,
356
+ duplicateArgument: (value)=>`Duplicate argument: ${value}`,
357
+ missingValue: (value)=>`Missing value: ${value}`,
358
+ expectedUri: (value)=>`Expected a Viking URI: ${value}`,
359
+ invalidArgument: (value)=>`Invalid ${value}`,
360
+ missingArgument: (value)=>`Missing ${value}`
361
+ }
362
+ };
363
+ const en_US = messages;
364
+ const zh_CN_messages = {
365
+ labels: {
366
+ conversation: 'VikingBot',
367
+ command: '终端',
368
+ mode: '面板模式',
369
+ description: '连接你的资料、记忆与上下文,让每一份数据都成为可用的知识',
370
+ clear: '新建会话',
371
+ history: '命令历史',
372
+ emptyHistory: '暂无命令历史'
373
+ },
374
+ commands: {
375
+ grep: '匹配资源文本',
376
+ glob: '匹配资源路径',
377
+ help: '查看可用命令',
378
+ clear: '清空本地记录',
379
+ health: '检查服务健康状态',
380
+ status: '查看系统状态',
381
+ ls: '列出目录内容',
382
+ tree: '查看资源树',
383
+ stat: '查看资源属性',
384
+ read: '读取文件内容',
385
+ abstract: '读取 L0 摘要',
386
+ overview: '读取 L1 概览',
387
+ find: '检索匹配上下文',
388
+ search: '通过查询规划检索',
389
+ mkdir: '创建目录',
390
+ cp: '复制资源',
391
+ mv: '移动资源',
392
+ rm: '删除资源',
393
+ write: '写入文本内容',
394
+ 'task list': '列出后台任务',
395
+ 'task status': '查看后台任务',
396
+ 'task cancel': '请求取消后台任务'
397
+ },
398
+ availableCommands: '可用命令',
399
+ messages: {
400
+ cancelled: ()=>'请求已取消;服务端可能仍在处理已接收的操作。',
401
+ unknownCommand: ()=>'未知命令。输入 ov help 查看可用命令。',
402
+ shellSyntax: ()=>'不支持 Shell 语法。',
403
+ unclosedQuote: ()=>'引号或转义未闭合。',
404
+ unexpectedArgument: (value)=>`未知参数:${value}`,
405
+ duplicateArgument: (value)=>`重复参数:${value}`,
406
+ missingValue: (value)=>`参数缺少值:${value}`,
407
+ expectedUri: (value)=>`需要 Viking URI:${value}`,
408
+ invalidArgument: (value)=>`无效参数 ${value}`,
409
+ missingArgument: (value)=>`缺少参数 ${value}`
410
+ }
411
+ };
412
+ const zh_CN = zh_CN_messages;
413
+ function resolveConsoleLocale(locale) {
414
+ return resolveLocale({
415
+ 'en-US': en_US,
416
+ 'zh-CN': zh_CN
417
+ }, locale);
418
+ }
419
+ function consoleLabels(locale, overrides) {
420
+ const defaults = resolveConsoleLocale(locale).labels;
421
+ const merged = mergeLabels(defaults, overrides);
422
+ const legacy = {
423
+ emptyTitle: overrides?.commandTitle,
424
+ emptyDescription: overrides?.commandDescription,
425
+ quickStart: overrides?.quickStart
426
+ };
427
+ return {
428
+ ...merged,
429
+ tui: mergeLabels(Object.fromEntries(Object.entries(legacy).filter(([, value])=>null != value)), overrides?.tui),
430
+ vikingBot: mergeLabels({
431
+ welcomeDescription: overrides?.description ?? defaults.description
432
+ }, overrides?.vikingBot)
433
+ };
434
+ }
435
+ function formatConsoleMessage(message, locale) {
436
+ const format = resolveConsoleLocale(locale).messages[message.code];
437
+ const text = format(message.value ?? '');
438
+ return message.usage ? `${text}\n${message.usage}` : text;
439
+ }
440
+ class ConsoleCommandError extends Error {
441
+ code;
442
+ value;
443
+ usage;
444
+ constructor(code, value, usage, locale = 'en-US'){
445
+ super(formatConsoleMessage({
446
+ code,
447
+ value,
448
+ usage
449
+ }, locale)), this.code = code, this.value = value, this.usage = usage;
450
+ }
451
+ }
452
+ function tokenize(input) {
453
+ const tokens = [];
454
+ let value = '', quote = '', escaped = false, started = false, literal = false;
455
+ for (const character of input.trim())if (escaped) {
456
+ value += character;
457
+ escaped = false;
458
+ started = true;
459
+ } else if ('\\' === character && "'" !== quote) {
460
+ escaped = true;
461
+ literal = true;
462
+ } else if (quote) if (character === quote) quote = '';
463
+ else value += character;
464
+ else if ('"' === character || "'" === character) {
465
+ quote = character;
466
+ started = true;
467
+ literal = true;
468
+ } else if (/\s/.test(character)) {
469
+ if (started) tokens.push({
470
+ value,
471
+ literal
472
+ });
473
+ value = '';
474
+ started = false;
475
+ literal = false;
476
+ } else {
477
+ if ('|;&<>`$'.includes(character)) throw new ConsoleCommandError('shellSyntax');
478
+ value += character;
479
+ started = true;
480
+ }
481
+ if (quote || escaped) throw new ConsoleCommandError('unclosedQuote');
482
+ if (started) tokens.push({
483
+ value,
484
+ literal
485
+ });
486
+ if (tokens[0]?.value === 'ov') tokens.shift();
487
+ if (tokens[0]?.value.startsWith('/')) tokens[0].value = tokens[0].value.slice(1);
488
+ return tokens;
489
+ }
490
+ function parseArguments(tokens, positional, flags = []) {
491
+ const result = {};
492
+ let index = 0;
493
+ let options = true;
494
+ for(let cursor = 0; cursor < tokens.length; cursor++){
495
+ const current = tokens[cursor];
496
+ const token = current.value;
497
+ if (options && !current.literal && '--' === token) {
498
+ options = false;
499
+ continue;
500
+ }
501
+ const flag = options && !current.literal && token.startsWith('--');
502
+ const argument = flag ? flags.find((item)=>token === `--${item.name}`) : positional[index++];
503
+ if (!argument) throw new ConsoleCommandError('unexpectedArgument', token);
504
+ if (Object.hasOwn(result, argument.name)) throw new ConsoleCommandError('duplicateArgument', token);
505
+ const next = flag && 'boolean' !== argument.kind ? tokens[++cursor] : current;
506
+ if (!next || flag && 'boolean' !== argument.kind && !next.literal && next.value.startsWith('--')) throw new ConsoleCommandError('missingValue', token);
507
+ const value = flag && 'boolean' === argument.kind ? 'true' : next.value;
508
+ if ('uri' === argument.kind && !/^viking:\/\//.test(value)) throw new ConsoleCommandError('expectedUri', value);
509
+ if (argument.choices && !argument.choices.includes(value)) throw new ConsoleCommandError('invalidArgument', `${argument.name}: ${value}`);
510
+ if ('integer' === argument.kind) {
511
+ const number = Number(value);
512
+ if (!/^-?\d+$/.test(value) || !Number.isSafeInteger(number) || number < (argument.min ?? 0)) throw new ConsoleCommandError('invalidArgument', `${argument.name}: ${value}`);
513
+ result[argument.name] = number;
514
+ } else result[argument.name] = 'boolean' === argument.kind ? true : value;
515
+ }
516
+ for (const argument of positional)if (!argument.optional && void 0 === result[argument.name]) throw new ConsoleCommandError('missingArgument', argument.name);
517
+ return result;
518
+ }
519
+ function object(value) {
520
+ return null === value || 'object' != typeof value || Array.isArray(value) ? {} : value;
521
+ }
522
+ function results_text(value) {
523
+ return 'string' == typeof value ? value : JSON.stringify(value, null, 2) ?? '';
524
+ }
525
+ function formatResult(name, data, values) {
526
+ if ([
527
+ 'read',
528
+ 'abstract',
529
+ 'overview'
530
+ ].includes(name)) return {
531
+ variant: 'resource-preview',
532
+ title: String(values.uri).split('/').pop() || String(values.uri),
533
+ uri: String(values.uri),
534
+ content: results_text(data)
535
+ };
536
+ if ([
537
+ 'ls',
538
+ 'tree'
539
+ ].includes(name) && Array.isArray(data)) return {
540
+ variant: 'resource-tree',
541
+ items: data.map((entry, index)=>{
542
+ const item = object(entry);
543
+ const uri = 'string' == typeof item.uri ? item.uri : void 0;
544
+ return {
545
+ id: `${index}`,
546
+ title: 'string' == typeof entry ? entry : results_text(item.name ?? item.rel_path ?? uri ?? index),
547
+ uri,
548
+ metaLabel: 'string' == typeof item.abstract ? item.abstract : void 0
549
+ };
550
+ })
551
+ };
552
+ const result = object(data);
553
+ if ([
554
+ 'find',
555
+ 'search'
556
+ ].includes(name)) {
557
+ const items = [];
558
+ for (const key of [
559
+ 'memories',
560
+ 'resources',
561
+ 'skills'
562
+ ]){
563
+ const entries = result[key];
564
+ if (Array.isArray(entries)) for (const entry of entries){
565
+ const item = object(entry);
566
+ const uri = 'string' == typeof item.uri ? item.uri : void 0;
567
+ items.push({
568
+ id: `${key}-${items.length}`,
569
+ title: uri?.split('/').pop() || uri || key,
570
+ uri,
571
+ metaLabel: uri,
572
+ typeLabel: 'string' == typeof item.context_type ? item.context_type : key,
573
+ levelLabel: 'number' == typeof item.level ? `L${item.level}` : void 0,
574
+ scoreLabel: 'number' == typeof item.score ? item.score.toFixed(3) : void 0,
575
+ preview: 'string' == typeof item.abstract ? item.abstract : void 0
576
+ });
577
+ }
578
+ }
579
+ return {
580
+ variant: 'search-list',
581
+ items
582
+ };
583
+ }
584
+ if ([
585
+ 'stat',
586
+ 'status',
587
+ 'health',
588
+ 'task status',
589
+ 'task cancel'
590
+ ].includes(name) && Object.keys(result).length) return {
591
+ variant: 'status',
592
+ rows: Object.entries(result).map(([label, value])=>({
593
+ label,
594
+ value: results_text(value),
595
+ variant: 'object' == typeof value ? 'pre' : 'inline'
596
+ }))
597
+ };
598
+ return {
599
+ variant: 'text',
600
+ text: results_text(data)
601
+ };
602
+ }
603
+ function consoleCommands(locale) {
604
+ const text = resolveConsoleLocale(locale);
605
+ return COMMAND_SPECS.map((spec)=>({
606
+ name: spec.name,
607
+ inputText: `ov ${spec.name}`,
608
+ description: text.commands[spec.name],
609
+ usage: [
610
+ 'ov',
611
+ spec.name,
612
+ ...(spec.positional ?? []).map((arg)=>arg.optional ? `[${arg.name}]` : `<${arg.name}>`),
613
+ ...(spec.flags ?? []).map((flag)=>`[--${flag.name}${'boolean' === flag.kind ? '' : ` <${flag.name}>`}]`)
614
+ ].join(' '),
615
+ params: spec.positional?.map((arg)=>({
616
+ label: arg.name,
617
+ description: 'uri' === arg.kind ? 'viking://…' : arg.name,
618
+ required: !arg.optional
619
+ })),
620
+ options: spec.flags?.map((flag)=>({
621
+ token: `--${flag.name}`,
622
+ description: flag.choices?.join(' | ') ?? flag.name
623
+ })),
624
+ skeleton: spec.skeleton
625
+ }));
626
+ }
627
+ function createCommandHelp(locale) {
628
+ return {
629
+ variant: 'command-help',
630
+ sections: [
631
+ {
632
+ key: 'commands',
633
+ label: resolveConsoleLocale(locale).availableCommands,
634
+ items: consoleCommands(locale).map((item)=>({
635
+ key: item.name,
636
+ name: item.usage,
637
+ description: item.description
638
+ }))
639
+ }
640
+ ]
641
+ };
642
+ }
643
+ async function executeCommand(input, client, options, locale) {
644
+ const tokens = tokenize(input);
645
+ const spec = [
646
+ ...COMMAND_SPECS
647
+ ].sort((a, b)=>b.name.length - a.name.length).find((item)=>item.name.split(' ').every((part, index)=>tokens[index]?.value === part));
648
+ if (!spec) throw new ConsoleCommandError('unknownCommand');
649
+ let values;
650
+ try {
651
+ values = parseArguments(tokens.slice(spec.name.split(' ').length), spec.positional ?? [], spec.flags);
652
+ } catch (error) {
653
+ const usage = consoleCommands(locale).find((item)=>item.name === spec.name).usage;
654
+ if (error instanceof ConsoleCommandError) throw new ConsoleCommandError(error.code, error.value, usage);
655
+ throw error;
656
+ }
657
+ if (!spec.request) return createCommandHelp(locale);
658
+ const data = await client.request({
659
+ ...spec.request(values),
660
+ options
661
+ });
662
+ return formatResult(spec.name, data, values);
663
+ }
664
+ function localizeConsoleRecords(records, locale) {
665
+ return records.map(({ localMessage, ...record })=>{
666
+ if (localMessage) return {
667
+ ...record,
668
+ content: {
669
+ variant: 'text',
670
+ text: formatConsoleMessage(localMessage, locale)
671
+ }
672
+ };
673
+ if (record.content?.variant === 'command-help') return {
674
+ ...record,
675
+ content: createCommandHelp(locale)
676
+ };
677
+ return record;
678
+ });
679
+ }
680
+ function createConsoleController(client, options = {}) {
681
+ let state = {
682
+ records: [],
683
+ command: '',
684
+ conversationDraft: '',
685
+ isExecuting: false
686
+ };
687
+ const listeners = new Set();
688
+ let running;
689
+ let active = false;
690
+ let sequence = 0;
691
+ let cancelRunning;
692
+ const update = (patch)=>{
693
+ state = {
694
+ ...state,
695
+ ...patch
696
+ };
697
+ listeners.forEach((listener)=>listener());
698
+ };
699
+ const cancel = ()=>cancelRunning?.();
700
+ const clear = ()=>{
701
+ cancel();
702
+ update({
703
+ records: [],
704
+ command: '',
705
+ error: void 0,
706
+ failedCommand: void 0
707
+ });
708
+ };
709
+ async function execute(input = state.command, locale = 'en-US') {
710
+ const command = input.trim();
711
+ if (!active || running || !command) return;
712
+ try {
713
+ const tokens = tokenize(command);
714
+ if (tokens[0]?.value === 'clear') {
715
+ parseArguments(tokens.slice(1), []);
716
+ clear();
717
+ update({
718
+ command: ''
719
+ });
720
+ return;
721
+ }
722
+ } catch {}
723
+ const controller = new AbortController();
724
+ const signal = options.signal ? AbortSignal.any([
725
+ options.signal,
726
+ controller.signal
727
+ ]) : controller.signal;
728
+ running = controller;
729
+ const id = `command-${++sequence}`;
730
+ const current = ()=>active && running === controller;
731
+ const finish = (message)=>{
732
+ if (!current()) return;
733
+ running = void 0;
734
+ cancelRunning = void 0;
735
+ update({
736
+ isExecuting: false,
737
+ records: state.records.map((record)=>record.id === id ? {
738
+ ...record,
739
+ status: 'error',
740
+ localMessage: message,
741
+ content: {
742
+ variant: 'text',
743
+ text: formatConsoleMessage(message, 'en-US')
744
+ }
745
+ } : record)
746
+ });
747
+ };
748
+ const onAbort = ()=>finish({
749
+ code: 'cancelled'
750
+ });
751
+ cancelRunning = ()=>{
752
+ controller.abort();
753
+ signal.removeEventListener('abort', onAbort);
754
+ };
755
+ update({
756
+ command: '',
757
+ isExecuting: true,
758
+ error: void 0,
759
+ failedCommand: void 0,
760
+ records: [
761
+ ...state.records,
762
+ {
763
+ id,
764
+ command,
765
+ status: 'pending',
766
+ createdAtMs: Date.now()
767
+ }
768
+ ]
769
+ });
770
+ signal.addEventListener('abort', onAbort, {
771
+ once: true
772
+ });
773
+ try {
774
+ if (signal.aborted) return void onAbort();
775
+ const content = await executeCommand(command, client, {
776
+ ...options,
777
+ signal
778
+ }, locale);
779
+ if (!current() || signal.aborted) return;
780
+ update({
781
+ records: state.records.map((record)=>record.id === id ? {
782
+ ...record,
783
+ status: 'success',
784
+ content
785
+ } : record)
786
+ });
787
+ } catch (error) {
788
+ if (!current() || signal.aborted) return;
789
+ const localMessage = error instanceof ConsoleCommandError ? {
790
+ code: error.code,
791
+ value: error.value,
792
+ usage: error.usage
793
+ } : void 0;
794
+ const message = isOvClientError(error) ? `${error.code}: ${error.message}` : error instanceof Error ? error.message : String(error);
795
+ update({
796
+ error,
797
+ failedCommand: command,
798
+ records: state.records.map((record)=>record.id === id ? {
799
+ ...record,
800
+ status: 'error',
801
+ localMessage,
802
+ content: {
803
+ variant: 'text',
804
+ text: message
805
+ }
806
+ } : record)
807
+ });
808
+ } finally{
809
+ signal.removeEventListener('abort', onAbort);
810
+ if (current()) {
811
+ running = void 0;
812
+ cancelRunning = void 0;
813
+ update({
814
+ isExecuting: false
815
+ });
816
+ }
817
+ }
818
+ }
819
+ return {
820
+ subscribe: (listener)=>{
821
+ listeners.add(listener);
822
+ return ()=>{
823
+ listeners.delete(listener);
824
+ };
825
+ },
826
+ getSnapshot: ()=>state,
827
+ start () {
828
+ active = true;
829
+ return ()=>{
830
+ cancel();
831
+ active = false;
832
+ };
833
+ },
834
+ execute,
835
+ cancel,
836
+ clear,
837
+ setCommand: (command)=>update({
838
+ command
839
+ }),
840
+ setConversationDraft: (conversationDraft)=>update({
841
+ conversationDraft
842
+ }),
843
+ retry: (locale)=>state.failedCommand ? execute(state.failedCommand, locale) : Promise.resolve()
844
+ };
845
+ }
846
+ function useConsole({ mode: controlledMode, defaultMode = 'conversation', locale: localeProp, scopeKey, onModeChange, requestOptions = {} } = {}) {
847
+ const locale = useLocale(localeProp);
848
+ const inherited = useOvClient();
849
+ const inheritedSignal = useOvSignal();
850
+ const [fallback] = useState(()=>createOvClient());
851
+ const client = inherited ?? fallback;
852
+ const { baseURL, apiKey, accountId, userId, resourceId, signal = inheritedSignal } = requestOptions;
853
+ const controller = useMemo(()=>createConsoleController(client, {
854
+ baseURL,
855
+ apiKey,
856
+ accountId,
857
+ userId,
858
+ resourceId,
859
+ signal
860
+ }), [
861
+ client,
862
+ baseURL,
863
+ apiKey,
864
+ accountId,
865
+ userId,
866
+ resourceId,
867
+ signal,
868
+ scopeKey
869
+ ]);
870
+ useEffect(()=>controller.start(), [
871
+ controller
872
+ ]);
873
+ const state = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
874
+ const [internalMode, setInternalMode] = useState(defaultMode);
875
+ const mode = controlledMode ?? internalMode;
876
+ const records = useMemo(()=>localizeConsoleRecords(state.records, locale), [
877
+ state.records,
878
+ locale
879
+ ]);
880
+ const error = useMemo(()=>state.error instanceof ConsoleCommandError ? new ConsoleCommandError(state.error.code, state.error.value, state.error.usage, locale) : state.error, [
881
+ state.error,
882
+ locale
883
+ ]);
884
+ return {
885
+ ...state,
886
+ records,
887
+ error,
888
+ mode,
889
+ commands: consoleCommands(locale),
890
+ setMode (next) {
891
+ if (next === mode) return;
892
+ if (void 0 === controlledMode) setInternalMode(next);
893
+ onModeChange?.(next);
894
+ },
895
+ setCommand: controller.setCommand,
896
+ setConversationDraft: controller.setConversationDraft,
897
+ execute: (command)=>controller.execute(command, locale),
898
+ retry: ()=>controller.retry(locale),
899
+ cancel: controller.cancel,
900
+ clear: controller.clear
901
+ };
902
+ }
903
+ const SvgConversation = (props)=>/*#__PURE__*/ jsx("svg", {
904
+ xmlns: "http://www.w3.org/2000/svg",
905
+ fill: "none",
906
+ preserveAspectRatio: "none",
907
+ viewBox: "0 0 12.928 12.867",
908
+ ...props,
909
+ children: /*#__PURE__*/ jsx("path", {
910
+ stroke: "currentColor",
911
+ strokeLinecap: "round",
912
+ strokeLinejoin: "round",
913
+ strokeWidth: 1.2,
914
+ d: "M2.988 5.983a5 5 0 0 1-.055-.716C2.933 2.689 5.036.6 7.631.6c2.594 0 4.697 2.09 4.697 4.667a4.6 4.6 0 0 1-.303 1.653c-.041.107-.061.16-.07.202a.5.5 0 0 0-.014.113c-.001.042.004.09.016.183l.235 1.908c.025.206.038.31.004.385a.3.3 0 0 1-.15.146c-.076.033-.18.018-.385-.012l-1.858-.273a1.4 1.4 0 0 0-.19-.02.5.5 0 0 0-.116.012c-.044.009-.099.03-.21.07a4.7 4.7 0 0 1-2.374.245m-3.028 2.388c1.73 0 3.132-1.437 3.132-3.209S5.615 5.85 3.885 5.85.754 7.286.754 9.058c0 .357.056.7.16 1.02.045.135.067.202.074.248a.5.5 0 0 1 .006.125c-.002.046-.014.1-.037.205L.6 12.266l1.747-.238c.095-.013.143-.02.185-.02.043.001.067.004.11.012.04.008.101.03.223.072.32.113.663.175 1.02.175"
915
+ })
916
+ });
917
+ const conversationreact = SvgConversation;
918
+ const SvgTerminal = (props)=>/*#__PURE__*/ jsx("svg", {
919
+ xmlns: "http://www.w3.org/2000/svg",
920
+ fill: "none",
921
+ preserveAspectRatio: "none",
922
+ viewBox: "0 0 11.7 11.7",
923
+ ...props,
924
+ children: /*#__PURE__*/ jsx("path", {
925
+ stroke: "currentColor",
926
+ strokeLinecap: "round",
927
+ strokeLinejoin: "round",
928
+ strokeWidth: 1.2,
929
+ d: "m2.933 7.6 1.75-1.75-1.75-1.75m3.5 3.5h2.334M3.4 11.1h4.9c.98 0 1.47 0 1.845-.19a1.75 1.75 0 0 0 .764-.765c.191-.375.191-.865.191-1.845V3.4c0-.98 0-1.47-.19-1.844a1.75 1.75 0 0 0-.765-.765C9.77.6 9.28.6 8.3.6H3.4c-.98 0-1.47 0-1.844.19a1.75 1.75 0 0 0-.765.766C.6 1.93.6 2.42.6 3.4v4.9c0 .98 0 1.47.19 1.845.169.329.436.597.766.764.374.191.864.191 1.844.191"
930
+ })
931
+ });
932
+ const terminalreact = SvgTerminal;
933
+ const SvgHistoryEmpty = (props)=>/*#__PURE__*/ jsxs("svg", {
934
+ xmlns: "http://www.w3.org/2000/svg",
935
+ width: 259,
936
+ height: 140,
937
+ fill: "none",
938
+ viewBox: "0 0 259 140",
939
+ ...props,
9
940
  children: [
10
- /*#__PURE__*/ jsx("p", {
11
- className: "ov-module-placeholder__title",
12
- children: labels?.conversation ?? 'Console'
941
+ /*#__PURE__*/ jsx("path", {
942
+ stroke: "var(--ov-ui-color-border-2, var(--ov-ui-border-2-default))",
943
+ strokeDasharray: "2 2",
944
+ d: "M0 28h259M0 56h259M0 84h259M0 112h259M37 0v140M75 0v140M117 0v140M159 0v140M199 0v140M235 0v140",
945
+ opacity: 0.36,
946
+ style: {
947
+ maskImage: "radial-gradient(ellipse at center,currentColor,transparent 72%)"
948
+ }
13
949
  }),
14
- /*#__PURE__*/ jsx("p", {
15
- className: "ov-module-placeholder__description",
16
- children: labels?.description ?? 'Placeholder. Functionality is not available yet.'
950
+ /*#__PURE__*/ jsx("path", {
951
+ fill: "var(--ov-ui-color-bg-1, var(--ov-ui-bg-1-default))",
952
+ d: "m95 81 8-22q1-3 4-3h45q3 0 4 3l8 22v17q0 6-6 6h-57q-6 0-6-6Z"
953
+ }),
954
+ /*#__PURE__*/ jsx("path", {
955
+ fill: "currentColor",
956
+ d: "m102 81 7-16q1-2 4-2h33q3 0 4 2l7 16h-18q0 11-9.5 11T120 81Z",
957
+ opacity: 0.15
958
+ }),
959
+ /*#__PURE__*/ jsxs("g", {
960
+ stroke: "currentColor",
961
+ strokeLinecap: "round",
962
+ strokeLinejoin: "round",
963
+ strokeWidth: 1.5,
964
+ children: [
965
+ /*#__PURE__*/ jsx("path", {
966
+ d: "m95 81 8-22q1-3 4-3h45q3 0 4 3l8 22v17q0 6-6 6h-57q-6 0-6-6Z"
967
+ }),
968
+ /*#__PURE__*/ jsx("path", {
969
+ d: "M96 81h5m5 0h12q2 0 2 2 0 10 9.5 10t9.5-10q0-2 2-2h22"
970
+ }),
971
+ /*#__PURE__*/ jsx("path", {
972
+ d: "m108 38 9 8m13-12v12m22-8-9 8",
973
+ opacity: 0.8
974
+ })
975
+ ]
17
976
  })
18
977
  ]
19
978
  });
979
+ const history_emptyreact = SvgHistoryEmpty;
980
+ const icons = {
981
+ conversation: conversationreact,
982
+ command: terminalreact,
983
+ history: historyreact,
984
+ newSession: new_sessionreact,
985
+ historyEmpty: history_emptyreact
986
+ };
987
+ function ConsoleIcon({ name }) {
988
+ const Icon = icons[name];
989
+ return /*#__PURE__*/ jsx(Icon, {
990
+ "aria-hidden": "true",
991
+ focusable: "false"
992
+ });
993
+ }
994
+ const subscribe = ()=>()=>{};
995
+ const clientSnapshot = ()=>true;
996
+ const serverSnapshot = ()=>false;
997
+ function historyTime(record, locale) {
998
+ const date = new Date(record.createdAtMs ?? 0 / 0);
999
+ if (!Number.isFinite(date.getTime())) return record.createdAt ?? '';
1000
+ const parts = Object.fromEntries(new Intl.DateTimeFormat(locale, {
1001
+ year: 'numeric',
1002
+ month: '2-digit',
1003
+ day: '2-digit',
1004
+ hour: '2-digit',
1005
+ minute: '2-digit',
1006
+ hourCycle: 'h23'
1007
+ }).formatToParts(date).map(({ type, value })=>[
1008
+ type,
1009
+ value
1010
+ ]));
1011
+ return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}`;
1012
+ }
1013
+ function ConsoleHistory({ records, isExecuting, locale, labels, onRecall }) {
1014
+ const mounted = useSyncExternalStore(subscribe, clientSnapshot, serverSnapshot);
1015
+ const native = mounted && 'popover' in HTMLElement.prototype && 'function' == typeof HTMLElement.prototype.showPopover;
1016
+ const [open, setOpen] = useState(false);
1017
+ const [surface, setSurface] = useState(null);
1018
+ const trigger = useRef(null);
1019
+ const id = useId();
1020
+ const position = useOverlayPosition(open, trigger, surface, 'bottom', 'end');
1021
+ const close = ()=>{
1022
+ if (native) surface?.hidePopover();
1023
+ else setOpen(false);
1024
+ };
1025
+ useEffect(()=>{
1026
+ if (!native || !surface) return;
1027
+ const onToggle = ()=>setOpen(surface.matches(':popover-open'));
1028
+ surface.addEventListener('toggle', onToggle);
1029
+ return ()=>surface.removeEventListener('toggle', onToggle);
1030
+ }, [
1031
+ native,
1032
+ surface
1033
+ ]);
1034
+ useEffect(()=>{
1035
+ if (native || !open) return;
1036
+ const outside = (event)=>{
1037
+ const target = event.target;
1038
+ if (!trigger.current?.contains(target) && !surface?.contains(target)) setOpen(false);
1039
+ };
1040
+ const escape = (event)=>{
1041
+ if ('Escape' !== event.key) return;
1042
+ setOpen(false);
1043
+ trigger.current?.querySelector('button')?.focus();
1044
+ };
1045
+ document.addEventListener('mousedown', outside);
1046
+ document.addEventListener('keydown', escape);
1047
+ return ()=>{
1048
+ document.removeEventListener('mousedown', outside);
1049
+ document.removeEventListener('keydown', escape);
1050
+ };
1051
+ }, [
1052
+ native,
1053
+ open,
1054
+ surface
1055
+ ]);
1056
+ const invoker = native ? 'commandForElement' in HTMLButtonElement.prototype ? {
1057
+ commandfor: id,
1058
+ command: 'toggle-popover'
1059
+ } : {
1060
+ popovertarget: id
1061
+ } : {};
1062
+ return /*#__PURE__*/ jsxs("div", {
1063
+ className: "ov-console__history",
1064
+ ref: trigger,
1065
+ children: [
1066
+ /*#__PURE__*/ jsx(Tooltip, {
1067
+ content: labels.history,
1068
+ className: "ov-console__action-tooltip",
1069
+ children: /*#__PURE__*/ jsx("button", {
1070
+ ...invoker,
1071
+ type: "button",
1072
+ className: "ov-console__action",
1073
+ "aria-label": labels.history,
1074
+ "aria-haspopup": "dialog",
1075
+ "aria-controls": id,
1076
+ "aria-expanded": open,
1077
+ "data-open": open || void 0,
1078
+ onClick: native ? void 0 : ()=>setOpen(!open),
1079
+ children: /*#__PURE__*/ jsx(ConsoleIcon, {
1080
+ name: "history"
1081
+ })
1082
+ })
1083
+ }),
1084
+ mounted ? /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx("div", {
1085
+ ref: setSurface,
1086
+ id: id,
1087
+ popover: "auto",
1088
+ role: "dialog",
1089
+ "aria-label": labels.history,
1090
+ hidden: !native && !open,
1091
+ className: "ov-tooltip ov-console__history-content",
1092
+ style: {
1093
+ top: position.top,
1094
+ left: position.left
1095
+ },
1096
+ children: records.length ? /*#__PURE__*/ jsx("ul", {
1097
+ children: [
1098
+ ...records
1099
+ ].reverse().map((record)=>/*#__PURE__*/ jsx("li", {
1100
+ children: /*#__PURE__*/ jsxs("button", {
1101
+ type: "button",
1102
+ disabled: isExecuting,
1103
+ onClick: ()=>{
1104
+ close();
1105
+ onRecall(record.command);
1106
+ },
1107
+ children: [
1108
+ /*#__PURE__*/ jsx("span", {
1109
+ className: "ov-console__history-command",
1110
+ children: record.command
1111
+ }),
1112
+ /*#__PURE__*/ jsx("span", {
1113
+ className: "ov-console__history-time",
1114
+ children: historyTime(record, locale)
1115
+ })
1116
+ ]
1117
+ })
1118
+ }, record.id))
1119
+ }) : /*#__PURE__*/ jsxs("div", {
1120
+ className: "ov-console__history-empty",
1121
+ children: [
1122
+ /*#__PURE__*/ jsx("span", {
1123
+ className: "ov-console__history-illustration",
1124
+ children: /*#__PURE__*/ jsx(ConsoleIcon, {
1125
+ name: "historyEmpty"
1126
+ })
1127
+ }),
1128
+ /*#__PURE__*/ jsx("span", {
1129
+ children: labels.emptyHistory
1130
+ })
1131
+ ]
1132
+ })
1133
+ }), document.body) : null
1134
+ ]
1135
+ });
1136
+ }
1137
+ function ConsoleToolbar({ mode, panelId, locale, labels, records, isExecuting, onModeChange, onClear, onRecall, children, conversationActions }) {
1138
+ const [sessionVersion, setSessionVersion] = useState(0);
1139
+ return /*#__PURE__*/ jsxs("div", {
1140
+ className: "ov-console__toolbar",
1141
+ children: [
1142
+ /*#__PURE__*/ jsx("div", {
1143
+ className: "ov-console__modes",
1144
+ role: "group",
1145
+ "aria-label": labels.mode,
1146
+ children: [
1147
+ 'conversation',
1148
+ 'command'
1149
+ ].map((value)=>/*#__PURE__*/ jsxs("button", {
1150
+ className: "ov-console__mode",
1151
+ type: "button",
1152
+ "aria-label": labels[value],
1153
+ title: labels[value],
1154
+ "aria-pressed": mode === value,
1155
+ "aria-controls": `${panelId}-${value}`,
1156
+ onClick: ()=>onModeChange(value),
1157
+ children: [
1158
+ /*#__PURE__*/ jsx(ConsoleIcon, {
1159
+ name: value
1160
+ }),
1161
+ mode === value ? /*#__PURE__*/ jsx("span", {
1162
+ children: labels[value]
1163
+ }) : null
1164
+ ]
1165
+ }, value))
1166
+ }),
1167
+ children ? /*#__PURE__*/ jsx("div", {
1168
+ className: "ov-console__toolbar-slot",
1169
+ children: children
1170
+ }) : null,
1171
+ 'command' === mode ? /*#__PURE__*/ jsxs("div", {
1172
+ className: "ov-console__actions",
1173
+ children: [
1174
+ /*#__PURE__*/ jsx(ConsoleHistory, {
1175
+ records: records,
1176
+ isExecuting: isExecuting,
1177
+ locale: locale,
1178
+ labels: labels,
1179
+ onRecall: onRecall
1180
+ }, sessionVersion),
1181
+ /*#__PURE__*/ jsx(Tooltip, {
1182
+ content: labels.clear,
1183
+ className: "ov-console__action-tooltip",
1184
+ children: /*#__PURE__*/ jsx("button", {
1185
+ className: "ov-console__action",
1186
+ type: "button",
1187
+ "aria-label": labels.clear,
1188
+ onClick: ()=>{
1189
+ setSessionVersion((version)=>version + 1);
1190
+ onClear();
1191
+ },
1192
+ children: /*#__PURE__*/ jsx(ConsoleIcon, {
1193
+ name: "newSession"
1194
+ })
1195
+ })
1196
+ })
1197
+ ]
1198
+ }) : conversationActions
1199
+ ]
1200
+ });
1201
+ }
1202
+ const DEFAULT_QUICK_COMMANDS = [
1203
+ 'help',
1204
+ 'ls',
1205
+ 'find',
1206
+ 'read',
1207
+ 'status'
1208
+ ];
1209
+ function Console({ mode, defaultMode, locale: localeProp, quickCommands = DEFAULT_QUICK_COMMANDS, scopeKey, requestOptions, onModeChange, onOpenUri, conversation, slots, labels: overrides, className, ...rest }) {
1210
+ const locale = useLocale(localeProp);
1211
+ const state = useConsole({
1212
+ mode,
1213
+ defaultMode,
1214
+ locale,
1215
+ scopeKey,
1216
+ requestOptions,
1217
+ onModeChange
1218
+ });
1219
+ const labels = consoleLabels(locale, overrides);
1220
+ const { sessions, headerActions, ...conversationProps } = conversation ?? {};
1221
+ const botLocale = conversationProps.locale ?? locale;
1222
+ const botLabels = {
1223
+ ...consoleLabels(botLocale, overrides).vikingBot,
1224
+ ...conversationProps.labels
1225
+ };
1226
+ const id = useId();
1227
+ const commandPanel = useRef(null);
1228
+ const fillCommand = (command)=>{
1229
+ state.setCommand(command);
1230
+ commandPanel.current?.querySelector('textarea')?.focus({
1231
+ preventScroll: true
1232
+ });
1233
+ };
1234
+ return /*#__PURE__*/ jsx(LocaleProvider, {
1235
+ locale: locale,
1236
+ children: /*#__PURE__*/ jsxs("div", {
1237
+ ...rest,
1238
+ className: [
1239
+ 'ov-console',
1240
+ className
1241
+ ].filter(Boolean).join(' '),
1242
+ children: [
1243
+ /*#__PURE__*/ jsx(ConsoleToolbar, {
1244
+ mode: state.mode,
1245
+ panelId: id,
1246
+ locale: locale,
1247
+ labels: labels,
1248
+ records: state.records,
1249
+ isExecuting: state.isExecuting,
1250
+ onModeChange: (next)=>state.setMode(next),
1251
+ onClear: ()=>{
1252
+ state.clear();
1253
+ fillCommand('');
1254
+ },
1255
+ onRecall: fillCommand,
1256
+ conversationActions: /*#__PURE__*/ jsx(VikingBotSessionActions, {
1257
+ sessions: sessions,
1258
+ extra: headerActions,
1259
+ labels: botLabels,
1260
+ locale: botLocale
1261
+ }),
1262
+ children: slots?.toolbar
1263
+ }),
1264
+ /*#__PURE__*/ jsx("div", {
1265
+ id: `${id}-conversation`,
1266
+ className: "ov-console__panel",
1267
+ hidden: 'conversation' !== state.mode,
1268
+ children: 'conversation' === state.mode ? /*#__PURE__*/ jsx(VikingBot, {
1269
+ ...conversationProps,
1270
+ onOpenUri: conversationProps.onOpenUri ?? onOpenUri,
1271
+ messages: conversationProps.messages ?? [],
1272
+ draft: conversationProps.draft ?? state.conversationDraft,
1273
+ onDraftChange: void 0 === conversationProps.draft ? (value)=>{
1274
+ state.setConversationDraft(value);
1275
+ conversationProps.onDraftChange?.(value);
1276
+ } : conversationProps.onDraftChange,
1277
+ footer: slots?.conversationContext ?? conversationProps.footer,
1278
+ locale: botLocale,
1279
+ labels: botLabels
1280
+ }) : null
1281
+ }),
1282
+ /*#__PURE__*/ jsxs("div", {
1283
+ id: `${id}-command`,
1284
+ ref: commandPanel,
1285
+ className: "ov-console__panel",
1286
+ hidden: 'command' !== state.mode,
1287
+ children: [
1288
+ slots?.commandHelp,
1289
+ /*#__PURE__*/ jsx(Tui, {
1290
+ records: state.records,
1291
+ value: state.command,
1292
+ commands: state.commands,
1293
+ locale: locale,
1294
+ disabled: state.isExecuting,
1295
+ quickCommands: quickCommands,
1296
+ onValueChange: state.setCommand,
1297
+ onSubmit: (command)=>void state.execute(command),
1298
+ onOpenUri: onOpenUri,
1299
+ labels: labels.tui
1300
+ })
1301
+ ]
1302
+ })
1303
+ ]
1304
+ })
1305
+ });
20
1306
  }
21
- export { Console };
1307
+ export { Console, useConsole };