@openviking/react 0.1.3 → 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 (200) 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 +2267 -29
  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/{1~0.js → ae~0.js} +5 -24
  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/provider.d.ts +5 -3
  16. package/dist/client/types.d.ts +5 -5
  17. package/dist/client.js +2 -1
  18. package/dist/components/agent-connect/agent-connect-copy.d.ts +19 -33
  19. package/dist/components/agent-connect/agent-connect-design.d.ts +1935 -167
  20. package/dist/components/agent-connect/agent-connect-instructions.d.ts +135 -0
  21. package/dist/components/agent-connect/locales/en-US.d.ts +20 -0
  22. package/dist/components/agent-connect/locales/zh-CN.d.ts +3 -0
  23. package/dist/components/agent-connect/style.css +14 -2
  24. package/dist/components/agent-connect/types.d.ts +2 -1
  25. package/dist/components/directory-tour/directory-tour.d.ts +3 -0
  26. package/dist/components/directory-tour/index.d.ts +3 -0
  27. package/dist/components/directory-tour/locales/en-US.d.ts +3 -0
  28. package/dist/components/directory-tour/locales/zh-CN.d.ts +3 -0
  29. package/dist/components/directory-tour/steps.d.ts +5 -0
  30. package/dist/components/directory-tour/style.css +237 -0
  31. package/dist/components/directory-tour/style.js +0 -0
  32. package/dist/components/directory-tour/types.d.ts +42 -0
  33. package/dist/components/directory-tour/use-tour-anchor.d.ts +5 -0
  34. package/dist/components/directory-tour/use-tour-position.d.ts +12 -0
  35. package/dist/components/directory-tour.js +40 -0
  36. package/dist/components/file-browser-entries/file-browser-entries.d.ts +5 -5
  37. package/dist/components/file-browser-entries/labels.d.ts +3 -0
  38. package/dist/components/file-browser-entries/locales/en-US.d.ts +6 -0
  39. package/dist/components/file-browser-entries/locales/zh-CN.d.ts +6 -0
  40. package/dist/components/file-browser-entries/style.css +752 -2
  41. package/dist/components/file-browser-entries/types.d.ts +34 -16
  42. package/dist/components/file-preview/file-preview-adapters.d.ts +2 -1
  43. package/dist/components/file-preview/file-preview-body.d.ts +2 -1
  44. package/dist/components/file-preview/file-preview-breadcrumb-menu.d.ts +2 -1
  45. package/dist/components/file-preview/file-preview-breadcrumb.d.ts +2 -1
  46. package/dist/components/file-preview/file-preview-directory.d.ts +2 -1
  47. package/dist/components/file-preview/file-preview-handle-adapters.d.ts +2 -1
  48. package/dist/components/file-preview/file-preview-header.d.ts +6 -2
  49. package/dist/components/file-preview/file-preview-image-frame.d.ts +5 -0
  50. package/dist/components/file-preview/file-preview-labels.d.ts +2 -14
  51. package/dist/components/file-preview/file-preview-level-tabs.d.ts +7 -0
  52. package/dist/components/file-preview/file-preview-markdown-images.d.ts +13 -0
  53. package/dist/components/file-preview/file-preview-panels.d.ts +5 -2
  54. package/dist/components/file-preview/file-preview-viewer.d.ts +2 -1
  55. package/dist/components/file-preview/file-preview.d.ts +0 -1
  56. package/dist/components/file-preview/index.d.ts +2 -1
  57. package/dist/components/file-preview/locales/en-US.d.ts +16 -0
  58. package/dist/components/file-preview/locales/zh-CN.d.ts +16 -0
  59. package/dist/components/file-preview/style.css +160 -2
  60. package/dist/components/file-preview/types.d.ts +34 -10
  61. package/dist/components/file-preview/use-file-preview-levels.d.ts +7 -0
  62. package/dist/components/file-preview/use-file-preview-view-state.d.ts +15 -0
  63. package/dist/components/file-preview.js +1 -1
  64. package/dist/components/file-tree/file-tree-info-labels.d.ts +0 -15
  65. package/dist/components/file-tree/file-tree-labels.d.ts +4 -0
  66. package/dist/components/file-tree/file-tree-row-shared.d.ts +2 -12
  67. package/dist/components/file-tree/file-tree-toolbar.d.ts +11 -0
  68. package/dist/components/file-tree/locales/en-US.d.ts +69 -0
  69. package/dist/components/file-tree/locales/zh-CN.d.ts +69 -0
  70. package/dist/components/file-tree/style.css +143 -15
  71. package/dist/components/file-tree/types.d.ts +38 -10
  72. package/dist/components/file-tree/use-file-tree-actions.d.ts +4 -1
  73. package/dist/components/scope-switcher/labels.d.ts +3 -0
  74. package/dist/components/scope-switcher/locales/en-US.d.ts +8 -0
  75. package/dist/components/scope-switcher/locales/zh-CN.d.ts +8 -0
  76. package/dist/components/scope-switcher/scope-panel.d.ts +1 -1
  77. package/dist/components/scope-switcher/scope-switcher.d.ts +1 -1
  78. package/dist/components/scope-switcher/style.css +14 -2
  79. package/dist/components/scope-switcher/types.d.ts +11 -5
  80. package/dist/components/style.css +9851 -6812
  81. package/dist/components/tui/locales/en-US.d.ts +35 -0
  82. package/dist/components/tui/locales/zh-CN.d.ts +35 -0
  83. package/dist/components/tui/style.css +310 -18
  84. package/dist/components/tui/tui-copy-button.d.ts +1 -1
  85. package/dist/components/tui/tui-empty.d.ts +25 -0
  86. package/dist/components/tui/tui-labels.d.ts +2 -2
  87. package/dist/components/tui/tui.d.ts +1 -1
  88. package/dist/components/tui/types.d.ts +35 -12
  89. package/dist/components/tui.js +1 -1
  90. package/dist/components/viking-bot/ark-adapter.d.ts +2 -0
  91. package/dist/components/viking-bot/ark-message-body.d.ts +1 -7
  92. package/dist/components/viking-bot/ark-message-list-view.d.ts +1 -1
  93. package/dist/components/viking-bot/ark-message-row.d.ts +3 -1
  94. package/dist/components/viking-bot/bot-popover.d.ts +9 -0
  95. package/dist/components/viking-bot/capabilities.d.ts +49 -0
  96. package/dist/components/viking-bot/composer-attachments.d.ts +13 -0
  97. package/dist/components/viking-bot/composer-controls.d.ts +10 -0
  98. package/dist/components/viking-bot/composer-footer.d.ts +17 -0
  99. package/dist/components/viking-bot/composer-references.d.ts +20 -0
  100. package/dist/components/viking-bot/composer-text.d.ts +10 -0
  101. package/dist/components/viking-bot/index.d.ts +3 -1
  102. package/dist/components/viking-bot/interaction/ask-human-fields.d.ts +1 -1
  103. package/dist/components/viking-bot/interaction/labels.d.ts +2 -1
  104. package/dist/components/viking-bot/interaction/locales/en-US.d.ts +17 -0
  105. package/dist/components/viking-bot/interaction/locales/zh-CN.d.ts +17 -0
  106. package/dist/components/viking-bot/interaction/types.d.ts +8 -3
  107. package/dist/components/viking-bot/interaction/viking-bot-interaction.d.ts +1 -1
  108. package/dist/components/viking-bot/labels.d.ts +2 -0
  109. package/dist/components/viking-bot/locales/en-US.d.ts +40 -0
  110. package/dist/components/viking-bot/locales/zh-CN.d.ts +40 -0
  111. package/dist/components/viking-bot/markdown-links.d.ts +27 -0
  112. package/dist/components/viking-bot/message-activity.d.ts +7 -0
  113. package/dist/components/viking-bot/message-code-block.d.ts +8 -0
  114. package/dist/components/viking-bot/message-footer.d.ts +8 -0
  115. package/dist/components/viking-bot/message-markdown.d.ts +9 -0
  116. package/dist/components/viking-bot/model.d.ts +37 -3
  117. package/dist/components/viking-bot/quick-input-tracker.d.ts +16 -0
  118. package/dist/components/viking-bot/quick-inputs.d.ts +6 -0
  119. package/dist/components/viking-bot/reference-picker.d.ts +16 -0
  120. package/dist/components/viking-bot/session-actions.d.ts +11 -0
  121. package/dist/components/viking-bot/style.css +1486 -48
  122. package/dist/components/viking-bot/tool-activity.d.ts +9 -0
  123. package/dist/components/viking-bot/tool-result-links.d.ts +6 -0
  124. package/dist/components/viking-bot/types.d.ts +21 -9
  125. package/dist/components/viking-bot/use-quick-input.d.ts +17 -0
  126. package/dist/components/viking-bot/viking-bot.d.ts +1 -6
  127. package/dist/components/viking-bot/welcome.d.ts +8 -0
  128. package/dist/components/viking-bot.js +1 -1
  129. package/dist/c~0.js +533 -66
  130. package/dist/e~0.js +333 -0
  131. package/dist/file-preview-viewer~0.js +90 -8
  132. package/dist/f~0.js +39 -47
  133. package/dist/h~0.js +5 -1
  134. package/dist/icons/console-icons.d.ts +12 -0
  135. package/dist/icons/index.d.ts +2 -0
  136. package/dist/icons/viking-bot-icons.d.ts +6 -0
  137. package/dist/icons.js +1 -0
  138. package/dist/index.d.ts +2 -0
  139. package/dist/index.js +2 -1
  140. package/dist/k~0.js +1 -0
  141. package/dist/lg~0.js +155 -0
  142. package/dist/lk~0.js +37 -8
  143. package/dist/l~0.js +102 -119
  144. package/dist/modules/console/command-messages.d.ts +19 -0
  145. package/dist/modules/console/command-parser.d.ts +15 -0
  146. package/dist/modules/console/command-specs.d.ts +15 -0
  147. package/dist/modules/console/commands.d.ts +6 -0
  148. package/dist/modules/console/console-history.d.ts +10 -0
  149. package/dist/modules/console/console-toolbar.d.ts +18 -0
  150. package/dist/modules/console/console.d.ts +1 -3
  151. package/dist/modules/console/controller.d.ts +17 -0
  152. package/dist/modules/console/index.d.ts +2 -0
  153. package/dist/modules/console/labels.d.ts +61 -0
  154. package/dist/modules/console/locales/en-US.d.ts +49 -0
  155. package/dist/modules/console/locales/zh-CN.d.ts +3 -0
  156. package/dist/modules/console/localize-records.d.ts +11 -0
  157. package/dist/modules/console/results.d.ts +2 -0
  158. package/dist/modules/console/style.css +10905 -15
  159. package/dist/modules/console/types.d.ts +59 -80
  160. package/dist/modules/console/use-console.d.ts +3 -0
  161. package/dist/modules/console.js +1 -1
  162. package/dist/modules/file-browser/file-browser-detail.d.ts +2 -1
  163. package/dist/modules/file-browser/file-browser-labels.d.ts +11 -12
  164. package/dist/modules/file-browser/file-browser-toolbar.d.ts +3 -4
  165. package/dist/modules/file-browser/file-browser-tree-pane.d.ts +7 -5
  166. package/dist/modules/file-browser/file-browser.d.ts +1 -1
  167. package/dist/modules/file-browser/fs-read-directory.d.ts +2 -6
  168. package/dist/modules/file-browser/locales/en-US.d.ts +25 -0
  169. package/dist/modules/file-browser/locales/zh-CN.d.ts +25 -0
  170. package/dist/modules/file-browser/style.css +1581 -126
  171. package/dist/modules/file-browser/types.d.ts +38 -29
  172. package/dist/modules/file-browser/use-file-browser.d.ts +6 -1
  173. package/dist/modules/file-browser/use-fs-preview.d.ts +15 -1
  174. package/dist/modules/scope-cascade/labels.d.ts +6 -0
  175. package/dist/modules/scope-cascade/locales/en-US.d.ts +6 -0
  176. package/dist/modules/scope-cascade/locales/zh-CN.d.ts +3 -0
  177. package/dist/modules/scope-cascade/scope-cascade.d.ts +1 -1
  178. package/dist/modules/scope-cascade/style.css +14 -2
  179. package/dist/modules/scope-cascade/types.d.ts +3 -0
  180. package/dist/modules/style.css +15853 -3484
  181. package/dist/nx~0.js +15 -0
  182. package/dist/n~0.js +238 -83
  183. package/dist/o~0.js +10 -7
  184. package/dist/p~0.js +27 -0
  185. package/dist/rslib-runtime~0.js +42 -0
  186. package/dist/r~0.js +152 -0
  187. package/dist/shared/components/drawer/drawer.d.ts +13 -0
  188. package/dist/shared/components/drawer/index.d.ts +1 -0
  189. package/dist/shared/components/overlay/use-overlay-position.d.ts +2 -2
  190. package/dist/shared/components/tooltip/use-portal-theme.d.ts +3 -0
  191. package/dist/shared/locale.d.ts +6 -0
  192. package/dist/style.css +26056 -10636
  193. package/dist/u~0.js +75 -58
  194. package/dist/viking-bot-composer~0.js +434 -77
  195. package/dist/viking-bot-interaction~0.js +11 -11
  196. package/package.json +13 -4
  197. package/dist/30~0.js +0 -1332
  198. package/dist/components/tui/tui-labels-zh.d.ts +0 -2
  199. package/dist/modules/file-browser/tree-info-copy.d.ts +0 -15
  200. package/dist/modules/file-browser/tree-info-copy.zh-CN.d.ts +0 -15
@@ -1,39 +1,398 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Sender } from "@ark-design/ui/sender";
3
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef } from "react";
4
- import { DEFAULT_LABELS } from "./c~0.js";
5
- const HARD_BREAK = 'hardBreak';
6
- const TEXT = 'text';
7
- const toPlainText = (content)=>content.map((item)=>{
8
- if (item.type === HARD_BREAK) return '\n';
9
- return item.type === TEXT ? item.text ?? '' : '';
10
- }).join('').trim();
11
- const toRichText = (text)=>text ? [
3
+ import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from "react";
4
+ import { Tooltip } from "./r~0.js";
5
+ import { VikingBotIcon } from "./lg~0.js";
6
+ import { resolveVikingBotLabels, BotPopover, useQuickInput, QuickInputs } from "./c~0.js";
7
+ import { usePortalTheme } from "./9~0.js";
8
+ import { FileTree as file_tree_FileTree } from "./n~0.js";
9
+ const SvgSend = (props)=>/*#__PURE__*/ jsx("svg", {
10
+ xmlns: "http://www.w3.org/2000/svg",
11
+ fill: "none",
12
+ preserveAspectRatio: "none",
13
+ viewBox: "0 0 9 10.333",
14
+ ...props,
15
+ children: /*#__PURE__*/ jsx("path", {
16
+ fill: "currentColor",
17
+ d: "M4 9.833V1.707L.853 4.854a.5.5 0 1 1-.707-.707l4-4 .038-.035a.5.5 0 0 1 .67.035l4 4a.5.5 0 1 1-.708.707L5 1.707v8.126a.5.5 0 1 1-1 0"
18
+ })
19
+ });
20
+ const sendreact = SvgSend;
21
+ const SvgAttach = (props)=>/*#__PURE__*/ jsx("svg", {
22
+ xmlns: "http://www.w3.org/2000/svg",
23
+ fill: "none",
24
+ preserveAspectRatio: "none",
25
+ viewBox: "0 0 10.208 10.208",
26
+ ...props,
27
+ children: /*#__PURE__*/ jsx("path", {
28
+ fill: "currentColor",
29
+ d: "M4.667 9.77V5.543H.437a.438.438 0 0 1 0-.875h4.23V.437a.437.437 0 1 1 .875 0v4.23H9.77a.437.437 0 1 1 0 .875H5.54V9.77a.437.437 0 1 1-.874 0"
30
+ })
31
+ });
32
+ const attachreact = SvgAttach;
33
+ function VikingBotSubmit({ onSend, onStop, sending, tip, className, label, ...props }) {
34
+ return /*#__PURE__*/ jsx(Tooltip, {
35
+ content: tip ?? label,
36
+ children: /*#__PURE__*/ jsx("button", {
37
+ ...props,
38
+ type: "button",
39
+ className: [
40
+ 'ov-viking-bot__submit',
41
+ className
42
+ ].filter(Boolean).join(' '),
43
+ "aria-label": label,
44
+ onClick: (event)=>void (sending ? onStop : onSend)?.(event.nativeEvent),
45
+ children: sending ? /*#__PURE__*/ jsx("span", {
46
+ className: "ov-viking-bot__stop-icon",
47
+ "aria-hidden": "true"
48
+ }) : /*#__PURE__*/ jsx(sendreact, {
49
+ "aria-hidden": "true",
50
+ focusable: "false"
51
+ })
52
+ })
53
+ });
54
+ }
55
+ function VikingBotAttach({ label, ...props }) {
56
+ return /*#__PURE__*/ jsx(Tooltip, {
57
+ content: label,
58
+ children: /*#__PURE__*/ jsx("button", {
59
+ ...props,
60
+ type: "button",
61
+ className: "ov-viking-bot__attach",
62
+ "aria-label": label,
63
+ children: /*#__PURE__*/ jsx(attachreact, {
64
+ "aria-hidden": "true",
65
+ focusable: "false"
66
+ })
67
+ })
68
+ });
69
+ }
70
+ function ComposerFileButton({ accept, disabled, label, onFiles }) {
71
+ const input = useRef(null);
72
+ return /*#__PURE__*/ jsxs(Fragment, {
73
+ children: [
74
+ /*#__PURE__*/ jsx("input", {
75
+ ref: input,
76
+ type: "file",
77
+ accept: accept,
78
+ multiple: true,
79
+ hidden: true,
80
+ onChange: (event)=>{
81
+ onFiles([
82
+ ...event.target.files ?? []
83
+ ]);
84
+ event.target.value = '';
85
+ }
86
+ }),
87
+ /*#__PURE__*/ jsx(VikingBotAttach, {
88
+ label: label,
89
+ disabled: disabled,
90
+ onClick: ()=>input.current?.click()
91
+ })
92
+ ]
93
+ });
94
+ }
95
+ function ComposerAttachments({ items, onRemove, disabled, labels }) {
96
+ if (!items.length) return null;
97
+ return /*#__PURE__*/ jsx("ul", {
98
+ className: "ov-viking-bot__attachments",
99
+ children: items.map((item)=>/*#__PURE__*/ jsxs("li", {
100
+ children: [
101
+ /*#__PURE__*/ jsx("span", {
102
+ children: item.name
103
+ }),
104
+ 'error' === item.status ? /*#__PURE__*/ jsx("span", {
105
+ className: "ov-viking-bot__attachment-status",
106
+ children: item.errorMessage ?? labels.toolError
107
+ }) : null,
108
+ onRemove ? /*#__PURE__*/ jsx("button", {
109
+ type: "button",
110
+ "aria-label": `${labels.removeAttachment}: ${item.name}`,
111
+ disabled: disabled,
112
+ onClick: ()=>onRemove(item),
113
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
114
+ name: "remove",
115
+ width: 12,
116
+ height: 12
117
+ })
118
+ }) : null
119
+ ]
120
+ }, item.key))
121
+ });
122
+ }
123
+ function ReferencePicker({ config, locale, query: externalQuery, editor, onSelect, labels: overrides }) {
124
+ const labels = resolveVikingBotLabels(locale, overrides);
125
+ const [search, setSearch] = useState('');
126
+ const [active, setActive] = useState(0);
127
+ const [surface, setSurface] = useState(null);
128
+ const anchor = useMemo(()=>({
129
+ current: editor?.view.dom ?? null
130
+ }), [
131
+ editor
132
+ ]);
133
+ usePortalTheme(!!editor, anchor, surface);
134
+ const query = externalQuery ?? search;
135
+ const { onQueryChange } = config;
136
+ const id = useId();
137
+ const rows = query && !config.onQueryChange ? config.rows.filter((row)=>'entry' === row.kind && `${row.name} ${row.uri}`.toLowerCase().includes(query.toLowerCase())) : config.rows;
138
+ const entries = rows.filter((row)=>'entry' === row.kind && !row.disabled);
139
+ const activeEntry = entries[Math.min(active, entries.length - 1)];
140
+ useEffect(()=>{
141
+ onQueryChange?.(query);
142
+ }, [
143
+ query,
144
+ onQueryChange
145
+ ]);
146
+ useEffect(()=>{
147
+ if (!editor) return;
148
+ const keydown = (event)=>{
149
+ if (event.isComposing) return;
150
+ if ('Enter' === event.key) {
151
+ event.preventDefault();
152
+ event.stopImmediatePropagation();
153
+ if (activeEntry && !config.isLoading && !config.error) onSelect(activeEntry);
154
+ return;
155
+ }
156
+ if (config.isLoading || config.error) return;
157
+ if ('ArrowDown' === event.key || 'ArrowUp' === event.key) {
158
+ event.preventDefault();
159
+ event.stopImmediatePropagation();
160
+ setActive((index)=>entries.length ? (index + ('ArrowDown' === event.key ? 1 : -1) + entries.length) % entries.length : 0);
161
+ } else if (('ArrowRight' === event.key || 'ArrowLeft' === event.key) && activeEntry?.type === 'directory') {
162
+ event.preventDefault();
163
+ event.stopImmediatePropagation();
164
+ config.onExpand?.(activeEntry.uri);
165
+ }
166
+ };
167
+ editor.view.dom.addEventListener('keydown', keydown, true);
168
+ return ()=>editor.view.dom.removeEventListener('keydown', keydown, true);
169
+ }, [
170
+ editor,
171
+ activeEntry,
172
+ entries.length,
173
+ onSelect,
174
+ config
175
+ ]);
176
+ return /*#__PURE__*/ jsxs("div", {
177
+ ref: setSurface,
178
+ className: `ov-viking-bot__reference-picker${editor ? ' ov-viking-bot__reference-picker--mention' : ''}`,
179
+ children: [
180
+ editor ? null : /*#__PURE__*/ jsxs("label", {
181
+ htmlFor: id,
182
+ children: [
183
+ labels.searchReferences,
184
+ /*#__PURE__*/ jsx("input", {
185
+ id: id,
186
+ type: "search",
187
+ value: search,
188
+ onChange: (event)=>{
189
+ setSearch(event.target.value);
190
+ setActive(0);
191
+ }
192
+ })
193
+ ]
194
+ }),
195
+ config.error ? /*#__PURE__*/ jsx("p", {
196
+ role: "alert",
197
+ children: config.error
198
+ }) : /*#__PURE__*/ jsx(file_tree_FileTree, {
199
+ locale: locale,
200
+ "aria-label": labels.reference,
201
+ rows: rows,
202
+ isReady: !config.isLoading,
203
+ selectedId: editor ? activeEntry?.id : void 0,
204
+ operations: {
205
+ select: ()=>Promise.resolve(),
206
+ toggleExpand: ()=>Promise.resolve()
207
+ },
208
+ onSelect: onSelect,
209
+ onToggleExpand: (row)=>config.onExpand?.(row.uri),
210
+ renderRowTooltip: ()=>null,
211
+ getRowAttributes: ()=>editor ? {
212
+ onMouseDown: (event)=>event.preventDefault()
213
+ } : {},
214
+ loadingFallback: /*#__PURE__*/ jsx("p", {
215
+ role: "status",
216
+ children: labels.loading
217
+ }),
218
+ emptyFallback: /*#__PURE__*/ jsx("p", {
219
+ role: "status",
220
+ children: labels.emptyReferences
221
+ }),
222
+ labels: {
223
+ expand: labels.expandReference,
224
+ collapse: labels.collapseReference
225
+ }
226
+ })
227
+ ]
228
+ });
229
+ }
230
+ function selectReference(config, item) {
231
+ if (!config.selected.some((entry)=>entry.uri === item.uri)) config.onChange([
232
+ ...config.selected,
12
233
  {
13
- type: TEXT,
14
- text
234
+ uri: item.uri,
235
+ name: item.name,
236
+ type: item.type
15
237
  }
16
- ] : [];
17
- const viking_bot_composer_VikingBotComposerView = /*#__PURE__*/ forwardRef(function({ value, className, attachments = [], disabled, disabledReason, isSending, variant = 'default', accept, maxAttachments = 10, actions, onValueChange, onFilesAdded, onAttachmentRemove, onSend, onCancel, labels: overrides }, ref) {
18
- const labels = {
19
- ...DEFAULT_LABELS,
20
- ...overrides
238
+ ]);
239
+ }
240
+ function composerMention(config, disabled, labels, locale) {
241
+ if (!config) return;
242
+ return {
243
+ option: [],
244
+ shouldShow: ({ editor })=>!disabled && editor.isFocused,
245
+ onSelect: (item, { editor, range })=>{
246
+ const reference = config.rows.find((row)=>'entry' === row.kind && row.uri === item.value);
247
+ if (disabled || !reference || 'entry' !== reference.kind || reference.disabled) return;
248
+ selectReference(config, reference);
249
+ editor.chain().focus().deleteRange(range).run();
250
+ },
251
+ render: ({ query, command, editor })=>disabled ? null : /*#__PURE__*/ jsx(ReferencePicker, {
252
+ locale: locale,
253
+ config: config,
254
+ editor: editor,
255
+ query: query,
256
+ labels: labels,
257
+ onSelect: (item)=>command({
258
+ tagType: 'file',
259
+ label: item.name,
260
+ value: item.uri
261
+ })
262
+ })
21
263
  };
264
+ }
265
+ function ReferenceButton({ locale, config, disabled, labels, senderRef }) {
266
+ return /*#__PURE__*/ jsx(BotPopover, {
267
+ label: labels.reference,
268
+ placement: "top",
269
+ trigger: (props)=>/*#__PURE__*/ jsx(Tooltip, {
270
+ content: labels.reference,
271
+ disabled: true === props['aria-expanded'],
272
+ children: /*#__PURE__*/ jsx("button", {
273
+ ...props,
274
+ className: "ov-viking-bot__attach",
275
+ type: "button",
276
+ "aria-label": labels.reference,
277
+ disabled: disabled,
278
+ children: "@"
279
+ })
280
+ }),
281
+ children: (close)=>/*#__PURE__*/ jsx(ReferencePicker, {
282
+ locale: locale,
283
+ config: config,
284
+ labels: labels,
285
+ onSelect: (item)=>{
286
+ if (disabled) return;
287
+ selectReference(config, item);
288
+ close();
289
+ senderRef.current?.getEditor()?.commands.focus();
290
+ }
291
+ })
292
+ }, disabled ? 'disabled' : 'enabled');
293
+ }
294
+ function ReferenceTags({ config, labels, disabled }) {
295
+ if (!config?.selected.length) return null;
296
+ return /*#__PURE__*/ jsx("ul", {
297
+ className: "ov-viking-bot__reference-tags",
298
+ children: config.selected.map((item)=>/*#__PURE__*/ jsxs("li", {
299
+ children: [
300
+ /*#__PURE__*/ jsx(Tooltip, {
301
+ content: item.uri,
302
+ children: /*#__PURE__*/ jsx("span", {
303
+ children: item.name
304
+ })
305
+ }),
306
+ /*#__PURE__*/ jsx("button", {
307
+ type: "button",
308
+ disabled: disabled,
309
+ "aria-label": `${labels.removeReference}: ${item.name}`,
310
+ onClick: ()=>config.onChange(config.selected.filter((entry)=>entry.uri !== item.uri)),
311
+ children: /*#__PURE__*/ jsx(VikingBotIcon, {
312
+ name: "remove",
313
+ width: 12,
314
+ height: 12
315
+ })
316
+ })
317
+ ]
318
+ }, item.uri))
319
+ });
320
+ }
321
+ function ComposerFooter({ locale, references, senderRef, labels, disabled, filesDisabled, accept, onFiles, actions, submit }) {
322
+ return /*#__PURE__*/ jsxs("div", {
323
+ className: "ov-viking-bot__composer-actions",
324
+ children: [
325
+ /*#__PURE__*/ jsxs("div", {
326
+ className: "ov-viking-bot__composer-tools",
327
+ children: [
328
+ onFiles ? /*#__PURE__*/ jsx(ComposerFileButton, {
329
+ label: labels.attach,
330
+ accept: accept,
331
+ disabled: filesDisabled,
332
+ onFiles: onFiles
333
+ }) : null,
334
+ references ? /*#__PURE__*/ jsx(ReferenceButton, {
335
+ locale: locale,
336
+ config: references,
337
+ labels: labels,
338
+ senderRef: senderRef,
339
+ disabled: disabled
340
+ }) : null,
341
+ actions
342
+ ]
343
+ }),
344
+ submit
345
+ ]
346
+ });
347
+ }
348
+ const toPlainText = (content)=>content.map((item)=>'hardBreak' === item.type ? '\n' : 'text' === item.type ? item.text ?? '' : '').join('');
349
+ function toRichText(text) {
350
+ const content = [];
351
+ text.split('\n').forEach((line, index)=>{
352
+ if (index) content.push({
353
+ type: 'hardBreak'
354
+ });
355
+ if (line) content.push({
356
+ type: 'text',
357
+ text: line
358
+ });
359
+ });
360
+ return content;
361
+ }
362
+ function writeComposerText(sender, text, writing) {
363
+ const previous = writing.current;
364
+ writing.current = true;
365
+ try {
366
+ sender?.setValue(toRichText(text));
367
+ } finally{
368
+ writing.current = previous;
369
+ }
370
+ }
371
+ function composerCaret(sender) {
372
+ const editor = sender?.getEditor();
373
+ if (!editor?.state.selection.empty) return;
374
+ const { doc, selection } = editor.state;
375
+ return doc.textBetween(0, selection.from, '\n', '\n').length;
376
+ }
377
+ const viking_bot_composer_VikingBotComposerView = /*#__PURE__*/ forwardRef(function({ value, locale, className, attachments = [], disabled, disabledReason, isSending, variant = 'default', accept, maxAttachments = 10, actions, quickInputs, onQuickInputSelect, references, onValueChange, onFilesAdded, onAttachmentRemove, onSend, onCancel, labels: overrides }, ref) {
378
+ const labels = resolveVikingBotLabels(locale, overrides);
22
379
  const senderRef = useRef(null);
23
- const fileRef = useRef(null);
380
+ const writing = useRef(false);
24
381
  const readOnly = !onValueChange;
382
+ const locked = Boolean(disabled || readOnly || isSending);
25
383
  const remaining = Math.max(0, maxAttachments - attachments.length);
26
384
  const limitReached = 0 === remaining;
27
385
  const setText = useCallback((text)=>{
28
- senderRef.current?.setValue(toRichText(text));
386
+ writeComposerText(senderRef.current, text, writing);
29
387
  onValueChange?.(text);
30
388
  }, [
31
389
  onValueChange
32
390
  ]);
391
+ const shortcuts = useQuickInput(value, setText, onQuickInputSelect);
33
392
  useEffect(()=>{
34
393
  const current = toPlainText(senderRef.current?.getValue() ?? []);
35
394
  if (current === value) return;
36
- senderRef.current?.setValue(toRichText(value));
395
+ writeComposerText(senderRef.current, value, writing);
37
396
  }, [
38
397
  value
39
398
  ]);
@@ -56,10 +415,13 @@ const viking_bot_composer_VikingBotComposerView = /*#__PURE__*/ forwardRef(funct
56
415
  }));
57
416
  const submit = ()=>{
58
417
  if (!onSend || disabled || isSending) return;
59
- const text = toPlainText(senderRef.current?.getValue() ?? toRichText(value));
418
+ const text = toPlainText(senderRef.current?.getValue() ?? toRichText(value)).trim();
60
419
  onSend({
61
420
  text,
62
- attachments
421
+ attachments,
422
+ ...references ? {
423
+ references: references.selected
424
+ } : {}
63
425
  });
64
426
  };
65
427
  const interceptDrop = Boolean(onFilesAdded);
@@ -89,73 +451,68 @@ const viking_bot_composer_VikingBotComposerView = /*#__PURE__*/ forwardRef(funct
89
451
  role: "status",
90
452
  children: disabledReason
91
453
  }) : null,
92
- attachments.length > 0 ? /*#__PURE__*/ jsx("ul", {
93
- className: "ov-viking-bot__attachments",
94
- children: attachments.map((attachment)=>/*#__PURE__*/ jsxs("li", {
95
- children: [
96
- /*#__PURE__*/ jsx("span", {
97
- children: attachment.name
98
- }),
99
- 'error' === attachment.status ? /*#__PURE__*/ jsx("span", {
100
- className: "ov-viking-bot__attachment-status",
101
- children: attachment.errorMessage ?? labels.toolError
102
- }) : null,
103
- onAttachmentRemove ? /*#__PURE__*/ jsx("button", {
104
- type: "button",
105
- "aria-label": labels.removeAttachment,
106
- disabled: disabled,
107
- onClick: ()=>onAttachmentRemove(attachment),
108
- children: "\xd7"
109
- }) : null
110
- ]
111
- }, attachment.key))
112
- }) : null,
454
+ /*#__PURE__*/ jsx(QuickInputs, {
455
+ items: quickInputs,
456
+ disabled: disabled || readOnly || isSending,
457
+ onSelect: (item)=>{
458
+ shortcuts.select(item);
459
+ senderRef.current?.getEditor()?.commands.focus('end');
460
+ }
461
+ }),
113
462
  /*#__PURE__*/ jsx(Sender, {
114
463
  ref: senderRef,
115
464
  className: "ov-viking-bot__sender",
116
465
  defaultContent: toRichText(value),
117
466
  sending: isSending,
118
- sendDisabled: disabled || readOnly,
467
+ sendDisabled: disabled || readOnly || !isSending && !onSend,
119
468
  onContentChange: (content)=>{
120
- if (!readOnly) onValueChange?.(toPlainText(content));
121
- },
122
- onSend: ()=>{
123
- submit();
469
+ if (readOnly || writing.current) return;
470
+ const next = toPlainText(content);
471
+ shortcuts.tracker.edit(next, composerCaret(senderRef.current));
472
+ onValueChange?.(next);
124
473
  },
474
+ onSend: submit,
125
475
  onStop: ()=>onCancel?.(),
476
+ renderHeader: ()=>/*#__PURE__*/ jsxs(Fragment, {
477
+ children: [
478
+ /*#__PURE__*/ jsx(ReferenceTags, {
479
+ config: references,
480
+ labels: labels,
481
+ disabled: disabled || isSending
482
+ }),
483
+ /*#__PURE__*/ jsx(ComposerAttachments, {
484
+ items: attachments,
485
+ onRemove: onAttachmentRemove,
486
+ labels: labels,
487
+ disabled: disabled || isSending
488
+ })
489
+ ]
490
+ }),
491
+ renderSubmit: (props)=>isSending && !onCancel ? null : /*#__PURE__*/ jsx(VikingBotSubmit, {
492
+ ...props,
493
+ label: isSending ? labels.stop : labels.send
494
+ }),
126
495
  richTextAreaProps: {
496
+ mentionConfig: composerMention(references, locked, labels, locale),
127
497
  placeholder: labels.placeholder,
128
- disabled
498
+ disabled,
499
+ minRows: 1,
500
+ maxRows: 6,
501
+ style: {
502
+ minHeight: 44
503
+ }
129
504
  },
130
- renderFooter: ({ components })=>/*#__PURE__*/ jsxs("div", {
131
- className: "ov-viking-bot__composer-actions",
132
- children: [
133
- components.sendBtnComponent,
134
- onFilesAdded ? /*#__PURE__*/ jsxs(Fragment, {
135
- children: [
136
- /*#__PURE__*/ jsx("input", {
137
- ref: fileRef,
138
- type: "file",
139
- accept: accept,
140
- multiple: true,
141
- hidden: true,
142
- onChange: (event)=>{
143
- reportFiles([
144
- ...event.target.files ?? []
145
- ]);
146
- event.target.value = '';
147
- }
148
- }),
149
- /*#__PURE__*/ jsx("button", {
150
- type: "button",
151
- disabled: disabled || limitReached,
152
- onClick: ()=>fileRef.current?.click(),
153
- children: labels.attach
154
- })
155
- ]
156
- }) : null,
157
- actions
158
- ]
505
+ renderFooter: ({ components })=>/*#__PURE__*/ jsx(ComposerFooter, {
506
+ locale: locale,
507
+ references: references,
508
+ senderRef: senderRef,
509
+ labels: labels,
510
+ disabled: locked,
511
+ filesDisabled: Boolean(disabled || limitReached || isSending),
512
+ accept: accept,
513
+ onFiles: onFilesAdded ? reportFiles : void 0,
514
+ actions: actions,
515
+ submit: components.sendBtnComponent
159
516
  })
160
517
  })
161
518
  ]
@@ -1,8 +1,8 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { AskHuman } from "@ark-design/ui/ask-human";
3
3
  import { useState } from "react";
4
- import { DEFAULT_INTERACTION_LABELS } from "./c7~0.js";
5
- const toFields = (request)=>{
4
+ import { resolveInteractionLabels } from "./c7~0.js";
5
+ const toFields = (request, other)=>{
6
6
  if ('choice' === request.kind) return [
7
7
  {
8
8
  type: 'single-select',
@@ -12,7 +12,9 @@ const toFields = (request)=>{
12
12
  label: option.label,
13
13
  description: option.description
14
14
  })),
15
- allowCustomInput: request.allowCustomInput
15
+ allowCustomInput: request.allowCustomInput ? {
16
+ placeholder: 'object' == typeof request.allowCustomInput ? request.allowCustomInput.placeholder ?? other : other
17
+ } : false
16
18
  }
17
19
  ];
18
20
  if ('repair' === request.kind) return [
@@ -177,7 +179,7 @@ function ScheduleInput({ request, labels, disabled, onChange }) {
177
179
  ]
178
180
  });
179
181
  }
180
- const TextInput = ({ request, disabled, onChange })=>/*#__PURE__*/ jsxs(Fragment, {
182
+ const TextInput = ({ request, label, disabled, onChange })=>/*#__PURE__*/ jsxs(Fragment, {
181
183
  children: [
182
184
  request.description ? /*#__PURE__*/ jsx("p", {
183
185
  children: request.description
@@ -186,16 +188,13 @@ const TextInput = ({ request, disabled, onChange })=>/*#__PURE__*/ jsxs(Fragment
186
188
  className: "ov-viking-bot__interaction-input",
187
189
  defaultValue: request.initialValue,
188
190
  disabled: disabled,
189
- "aria-label": "answer",
191
+ "aria-label": label,
190
192
  onChange: (event)=>onChange(event.target.value)
191
193
  })
192
194
  ]
193
195
  });
194
- function VikingBotInteractionView({ request, className, requestKey, index = 0, total = 1, disabled, submitting, error, onSubmit, onCancel, labels: overrides }) {
195
- const labels = {
196
- ...DEFAULT_INTERACTION_LABELS,
197
- ...overrides
198
- };
196
+ function VikingBotInteractionView({ request, className, requestKey, index = 0, total = 1, disabled, submitting, error, onSubmit, onCancel, locale, labels: overrides }) {
197
+ const labels = resolveInteractionLabels(locale, overrides);
199
198
  const blocked = Boolean(disabled || submitting);
200
199
  const formKey = requestKey ?? `${request.kind}:${index}`;
201
200
  const rootClass = [
@@ -227,7 +226,7 @@ function VikingBotInteractionView({ request, className, requestKey, index = 0, t
227
226
  {
228
227
  key: request.kind,
229
228
  title: request.question,
230
- fields: toFields(request),
229
+ fields: toFields(request, labels.other),
231
230
  extra: {
232
231
  index,
233
232
  total
@@ -266,6 +265,7 @@ function VikingBotInteractionView({ request, className, requestKey, index = 0, t
266
265
  },
267
266
  customRenderFields: {
268
267
  'viking-bot-text': ({ field, onChange })=>/*#__PURE__*/ jsx(TextInput, {
268
+ label: labels.answer,
269
269
  request: field.extra?.request,
270
270
  disabled: blocked,
271
271
  onChange: onChange
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openviking/react",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
- "README.md"
17
+ "README.md",
18
+ "LICENSE.arco-design"
18
19
  ],
19
20
  "sideEffects": [
20
21
  "**/*.css"
@@ -90,7 +91,12 @@
90
91
  "types": "./dist/modules/scope-cascade/index.d.ts",
91
92
  "import": "./dist/modules/scope-cascade.js"
92
93
  },
93
- "./modules/scope-cascade/style.css": "./dist/modules/scope-cascade/style.css"
94
+ "./modules/scope-cascade/style.css": "./dist/modules/scope-cascade/style.css",
95
+ "./components/directory-tour": {
96
+ "types": "./dist/components/directory-tour/index.d.ts",
97
+ "import": "./dist/components/directory-tour.js"
98
+ },
99
+ "./components/directory-tour/style.css": "./dist/components/directory-tour/style.css"
94
100
  },
95
101
  "scripts": {
96
102
  "dev": "rslib build --watch",
@@ -104,7 +110,8 @@
104
110
  "devDependencies": {
105
111
  "@ark-design/ui": "0.0.0-beta.7",
106
112
  "@rsbuild/plugin-react": "^2.1.1",
107
- "@rslib/core": "^1.0.5"
113
+ "@rslib/core": "^1.0.5",
114
+ "@types/react-transition-group": "^4.4.12"
108
115
  },
109
116
  "peerDependenciesMeta": {
110
117
  "@ark-design/ui": {
@@ -112,7 +119,9 @@
112
119
  }
113
120
  },
114
121
  "dependencies": {
122
+ "react-focus-lock": "^2.13.7",
115
123
  "react-markdown": "^10.1.0",
124
+ "react-transition-group": "^4.4.5",
116
125
  "remark-gfm": "^4.0.1"
117
126
  }
118
127
  }