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