chatluna-plugin-onebot-sandbox 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/app.tsx +8 -0
- package/client/chat/details-panel.tsx +4 -2
- package/client/chat/search-panel.tsx +2 -1
- package/client/locales/en.yml +3 -0
- package/client/locales/zh.yml +3 -0
- package/client/test-space/overview.tsx +76 -25
- package/client/test-space/spaces.css +2 -1
- package/dist/.vite/manifest.json +1 -1
- package/dist/app-BhlZI8M1.js +85 -0
- package/dist/client.css +2 -2
- package/dist/client.js +1 -1
- package/dist/revisions.json +1 -0
- package/lib/chatluna/user-permissions.d.ts +1 -1
- package/lib/console-contract.d.ts +3 -0
- package/lib/console-contract.d.ts.map +1 -1
- package/lib/console.d.ts.map +1 -1
- package/lib/control-service.d.ts +4 -4
- package/lib/control-service.d.ts.map +1 -1
- package/lib/index.js +51 -25
- package/lib/index.js.map +1 -1
- package/lib/media-storage.d.ts +11 -5
- package/lib/media-storage.d.ts.map +1 -1
- package/lib/test-spaces.d.ts +2 -0
- package/lib/test-spaces.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/app-CP5Q8Jov.js +0 -85
package/client/app.tsx
CHANGED
|
@@ -185,6 +185,13 @@ export function SandboxApp() {
|
|
|
185
185
|
await reloadSpaces()
|
|
186
186
|
})
|
|
187
187
|
|
|
188
|
+
const clearSpaces = () => runSpaceTask(async () => {
|
|
189
|
+
await invoke('onebot-sandbox.delete-all-test-spaces', undefined)
|
|
190
|
+
for (const key of stores.current.keys()) if (key !== 'main') stores.current.delete(key)
|
|
191
|
+
setCaptures(({ main }): Record<string, WorkspaceThumbnailCapture> => main ? { main } : {})
|
|
192
|
+
await reloadSpaces()
|
|
193
|
+
})
|
|
194
|
+
|
|
188
195
|
const createSpace = () => runSpaceTask(async () => {
|
|
189
196
|
const created = await invoke('onebot-sandbox.create-test-space', {})
|
|
190
197
|
await reloadSpaces()
|
|
@@ -264,6 +271,7 @@ export function SandboxApp() {
|
|
|
264
271
|
onEnter={(id) => void runSpaceTask(() => enterSpace(id))}
|
|
265
272
|
onCreate={() => void createSpace()}
|
|
266
273
|
onAction={(action, id) => void actOnSpace(action, id)}
|
|
274
|
+
onClearAll={() => void clearSpaces()}
|
|
267
275
|
/>
|
|
268
276
|
)}
|
|
269
277
|
{view === 'settings' ? <SettingsPage /> : view === 'spaces' ? null : viewState.workspace ? (
|
|
@@ -7,12 +7,14 @@ import {
|
|
|
7
7
|
ContextMenuContent,
|
|
8
8
|
ContextMenuTrigger,
|
|
9
9
|
Input,
|
|
10
|
+
Textarea,
|
|
11
|
+
} from '@chatluna/ui-kit'
|
|
12
|
+
import {
|
|
10
13
|
ResizableHandle,
|
|
11
14
|
type ResizableLayout,
|
|
12
15
|
ResizablePanel,
|
|
13
16
|
ResizablePanelGroup,
|
|
14
|
-
|
|
15
|
-
} from '@chatluna/ui-kit'
|
|
17
|
+
} from '@chatluna/ui-kit/components/resizable'
|
|
16
18
|
import { readStored, writeStored } from '@chatluna/ui-storage'
|
|
17
19
|
import { useT } from '../i18n'
|
|
18
20
|
import { SandboxAvatar } from '../shared/avatar'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { CalendarIcon, SearchIcon, XIcon } from 'lucide-react'
|
|
3
|
-
import { Button,
|
|
3
|
+
import { Button, cn, InputGroup, InputGroupAddon, InputGroupInput, Popover, PopoverContent, PopoverTrigger } from '@chatluna/ui-kit'
|
|
4
|
+
import { Calendar } from '@chatluna/ui-kit/components/calendar'
|
|
4
5
|
import type { SandboxMessageSearchHit } from '../../src/types'
|
|
5
6
|
import { useT } from '../i18n'
|
|
6
7
|
import { SandboxAvatar } from '../shared/avatar'
|
package/client/locales/en.yml
CHANGED
|
@@ -578,6 +578,9 @@ sandbox.sidebar.searchGroups: "Search groups"
|
|
|
578
578
|
sandbox.sidebar.tabs: "Conversation tabs"
|
|
579
579
|
sandbox.source.main: "Main environment"
|
|
580
580
|
sandbox.spaces.actionFailed: "Test space operation failed"
|
|
581
|
+
sandbox.spaces.clearAll: "Clear all"
|
|
582
|
+
sandbox.spaces.clearAllDescription: "All {count} test spaces and their accounts, conversations and messages are deleted. The main environment is not affected. This cannot be undone."
|
|
583
|
+
sandbox.spaces.clearAllTitle: "Clear all test spaces"
|
|
581
584
|
sandbox.spaces.create: "Create test space"
|
|
582
585
|
sandbox.spaces.current: "Test space: {name}"
|
|
583
586
|
sandbox.spaces.delete: "Delete space"
|
package/client/locales/zh.yml
CHANGED
|
@@ -578,6 +578,9 @@ sandbox.sidebar.searchGroups: "搜索群组"
|
|
|
578
578
|
sandbox.sidebar.tabs: "会话分类"
|
|
579
579
|
sandbox.source.main: "主环境"
|
|
580
580
|
sandbox.spaces.actionFailed: "测试空间操作失败"
|
|
581
|
+
sandbox.spaces.clearAll: "清空全部"
|
|
582
|
+
sandbox.spaces.clearAllDescription: "将删除全部 {count} 个测试空间及其中的账号、会话与消息,主环境不受影响,此操作不可撤销。"
|
|
583
|
+
sandbox.spaces.clearAllTitle: "清空所有测试空间"
|
|
581
584
|
sandbox.spaces.create: "创建测试空间"
|
|
582
585
|
sandbox.spaces.current: "测试空间:{name}"
|
|
583
586
|
sandbox.spaces.delete: "删除空间"
|
|
@@ -20,6 +20,8 @@ type Filter = 'all' | SandboxTestSpaceStatus
|
|
|
20
20
|
const FILTERS: Filter[] = ['all', 'running', 'taken-over', 'completed', 'failed']
|
|
21
21
|
const PREVIEW_WIDTH = 1440
|
|
22
22
|
const PREVIEW_HEIGHT = 760
|
|
23
|
+
/** 卡片进入总览视口上下这么远就挂载缩略画面,滚到眼前时已经画好。 */
|
|
24
|
+
const NEAR_MARGIN = 480
|
|
23
25
|
|
|
24
26
|
/** 缩略图里的工作区只负责绘制,任何打开二级面的意图都不响应。 */
|
|
25
27
|
const NOOP_DIALOGS: SandboxDialogs = {
|
|
@@ -40,7 +42,7 @@ const timeFormat = new Intl.DateTimeFormat(undefined, { month: '2-digit', day: '
|
|
|
40
42
|
* `exitZoom` 是从空间退回总览时留下的起点:挂载后让对应卡片从工作区位置缩回网格位,其余卡片错落浮现(`zoom.ts`)。
|
|
41
43
|
* `launching` 表示正在进入某个空间:总览脱离文档流垫在工作区背后播完推近淡出。
|
|
42
44
|
*/
|
|
43
|
-
export function SpaceOverview({ spaces, mainStore, captures, exitZoom, launching, onEnter, onCreate, onAction }: {
|
|
45
|
+
export function SpaceOverview({ spaces, mainStore, captures, exitZoom, launching, onEnter, onCreate, onAction, onClearAll }: {
|
|
44
46
|
spaces: SandboxTestSpaceSummary[]
|
|
45
47
|
mainStore: WorkspaceStore
|
|
46
48
|
captures: Readonly<Record<string, WorkspaceThumbnailCapture>>
|
|
@@ -49,6 +51,7 @@ export function SpaceOverview({ spaces, mainStore, captures, exitZoom, launching
|
|
|
49
51
|
onEnter(spaceId?: string): void
|
|
50
52
|
onCreate(): void
|
|
51
53
|
onAction(action: SpaceCardAction, spaceId: string): void
|
|
54
|
+
onClearAll(): void
|
|
52
55
|
}) {
|
|
53
56
|
const t = useT()
|
|
54
57
|
const [filter, setFilter] = React.useState<Filter>('all')
|
|
@@ -58,6 +61,8 @@ export function SpaceOverview({ spaces, mainStore, captures, exitZoom, launching
|
|
|
58
61
|
const base = mainView.workspace
|
|
59
62
|
const previews = usePreviewStores(spaces, base)
|
|
60
63
|
const visible = filter === 'all' ? spaces : spaces.filter((space) => space.status === filter)
|
|
64
|
+
// 退回总览时 zoomOverviewIn 在本组件的 layout effect 里读这张卡片的缩略画面,比子组件按视口补挂载更早,所以直接挂载。
|
|
65
|
+
const exitKey = exitZoom.current?.key
|
|
61
66
|
const filterItems = FILTERS.map((value) => ({ value, label: t(`sandbox.spaces.filter.${value}`) }))
|
|
62
67
|
|
|
63
68
|
// 进入动画没播完就退回时总览不重新挂载,launching 由有变无也要补一次退回动画。
|
|
@@ -95,17 +100,26 @@ export function SpaceOverview({ spaces, mainStore, captures, exitZoom, launching
|
|
|
95
100
|
>
|
|
96
101
|
<header className="sandbox-space-toolbar">
|
|
97
102
|
<p>{t('sandbox.spaces.summary', { count: spaces.length })}</p>
|
|
98
|
-
<
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
<div className="flex items-center gap-2">
|
|
104
|
+
<Select value={filter} onValueChange={(value) => value && setFilter(value as Filter)} items={filterItems}>
|
|
105
|
+
<SelectTrigger className="w-36" aria-label={t('sandbox.spaces.filterLabel')}><SelectValue /></SelectTrigger>
|
|
106
|
+
<SelectContent className="sandbox-glass">
|
|
107
|
+
{filterItems.map((item) => <SelectItem key={item.value} value={item.value}>{item.label}</SelectItem>)}
|
|
108
|
+
</SelectContent>
|
|
109
|
+
</Select>
|
|
110
|
+
{/* 不跟随筛选:清空的是全部测试空间,主环境不在其中。 */}
|
|
111
|
+
<Button variant="outline" disabled={spaces.length === 0} onClick={() => setConfirm({
|
|
112
|
+
title: t('sandbox.spaces.clearAllTitle'),
|
|
113
|
+
description: t('sandbox.spaces.clearAllDescription', { count: spaces.length }),
|
|
114
|
+
action: t('sandbox.spaces.clearAll'),
|
|
115
|
+
onConfirm: onClearAll,
|
|
116
|
+
})}><Trash2Icon data-icon="inline-start" />{t('sandbox.spaces.clearAll')}</Button>
|
|
117
|
+
</div>
|
|
104
118
|
</header>
|
|
105
119
|
|
|
106
120
|
<div className="sandbox-space-grid">
|
|
107
121
|
<article className="sandbox-space-card is-main" data-space-id="main" tabIndex={0} onClick={openCard()} onKeyDown={openCard()}>
|
|
108
|
-
<SpaceThumbnail capture={captures['main']} store={base ? mainStore : undefined} />
|
|
122
|
+
<SpaceThumbnail capture={captures['main']} store={base ? mainStore : undefined} eager={exitKey === 'main'} />
|
|
109
123
|
<footer>
|
|
110
124
|
<div className="min-w-0">
|
|
111
125
|
<strong className="truncate">{t('sandbox.spaces.main.name')}</strong>
|
|
@@ -126,7 +140,7 @@ export function SpaceOverview({ spaces, mainStore, captures, exitZoom, launching
|
|
|
126
140
|
onClick={openCard(space.id)}
|
|
127
141
|
onKeyDown={openCard(space.id)}
|
|
128
142
|
>
|
|
129
|
-
<SpaceThumbnail capture={captures[space.id]} store={base ? previews.get(space.id) : undefined} running={running} />
|
|
143
|
+
<SpaceThumbnail capture={captures[space.id]} store={base ? previews.get(space.id) : undefined} running={running} eager={exitKey === space.id} />
|
|
130
144
|
<footer>
|
|
131
145
|
<div className="min-w-0">
|
|
132
146
|
<strong className="truncate">{space.name}</strong>
|
|
@@ -191,51 +205,58 @@ function usePreviewStores(spaces: SandboxTestSpaceSummary[], base: SandboxWorksp
|
|
|
191
205
|
/**
|
|
192
206
|
* 卡片缩略图。真实画面的克隆与快照渲染的工作区都按 contain 缩放居中:卡片与页面宽高比不一致时
|
|
193
207
|
* 保留留白,不裁掉页面区域。
|
|
208
|
+
*
|
|
209
|
+
* 每张缩略图都是一整份工作区,空间一多开销就很可观:用 memo 隔开总览的重渲染(主环境信号、轮询换列表),
|
|
210
|
+
* 只有自己的 store 变化时才重绘;离视口较远的卡片先不挂载画面,接近视口时再挂上,挂上后不再卸载。
|
|
194
211
|
*/
|
|
195
|
-
function SpaceThumbnail({ capture, store, running }: {
|
|
212
|
+
const SpaceThumbnail = React.memo(function SpaceThumbnail({ capture, store, running, eager }: {
|
|
196
213
|
capture?: WorkspaceThumbnailCapture
|
|
197
214
|
store?: WorkspaceStore
|
|
198
215
|
running?: boolean
|
|
216
|
+
eager?: boolean
|
|
199
217
|
}) {
|
|
200
218
|
const frame = React.useRef<HTMLDivElement>(null)
|
|
201
219
|
const host = React.useRef<HTMLDivElement>(null)
|
|
202
220
|
const preview = React.useRef<HTMLDivElement>(null)
|
|
221
|
+
const near = useNearViewport(frame, eager)
|
|
222
|
+
const shownCapture = near ? capture : undefined
|
|
223
|
+
const shownStore = near ? store : undefined
|
|
203
224
|
|
|
204
225
|
const scale = React.useCallback(() => {
|
|
205
226
|
const container = frame.current
|
|
206
|
-
const element =
|
|
227
|
+
const element = shownCapture ? host.current?.firstElementChild : preview.current
|
|
207
228
|
if (!container || !(element instanceof HTMLElement)) return
|
|
208
229
|
// 进入总览时卡片正在做 transform 动画,getBoundingClientRect 会读到过渡帧尺寸;用不受祖先变换影响的布局尺寸。
|
|
209
230
|
const transform = calculateContainedWorkspaceThumbnailTransform({
|
|
210
231
|
containerWidth: container.clientWidth,
|
|
211
232
|
containerHeight: container.clientHeight,
|
|
212
|
-
canvasWidth:
|
|
213
|
-
canvasHeight:
|
|
233
|
+
canvasWidth: shownCapture?.width ?? PREVIEW_WIDTH,
|
|
234
|
+
canvasHeight: shownCapture?.height ?? PREVIEW_HEIGHT,
|
|
214
235
|
})
|
|
215
236
|
if (!transform) return
|
|
216
|
-
if (
|
|
217
|
-
element.style.width = `${
|
|
218
|
-
element.style.height = `${
|
|
237
|
+
if (shownCapture) {
|
|
238
|
+
element.style.width = `${shownCapture.width}px`
|
|
239
|
+
element.style.height = `${shownCapture.height}px`
|
|
219
240
|
}
|
|
220
241
|
element.style.transform = `translate(${transform.left}px, ${transform.top}px) scale(${transform.scale})`
|
|
221
|
-
}, [
|
|
242
|
+
}, [shownCapture])
|
|
222
243
|
|
|
223
244
|
React.useLayoutEffect(() => {
|
|
224
245
|
const target = host.current
|
|
225
246
|
if (!target) return
|
|
226
247
|
target.replaceChildren()
|
|
227
|
-
if (!
|
|
228
|
-
const element = instantiateWorkspaceThumbnail(
|
|
248
|
+
if (!shownCapture) return
|
|
249
|
+
const element = instantiateWorkspaceThumbnail(shownCapture)
|
|
229
250
|
target.append(element)
|
|
230
251
|
scale()
|
|
231
252
|
// scrollTop/scrollLeft 只有在克隆节点接入文档、完成布局后才会生效。
|
|
232
|
-
const frameId = requestAnimationFrame(() => restoreWorkspaceThumbnailScroll(
|
|
253
|
+
const frameId = requestAnimationFrame(() => restoreWorkspaceThumbnailScroll(shownCapture, element))
|
|
233
254
|
return () => cancelAnimationFrame(frameId)
|
|
234
|
-
}, [
|
|
255
|
+
}, [shownCapture, scale])
|
|
235
256
|
|
|
236
|
-
// 快照预览要等 store
|
|
257
|
+
// 快照预览要等 store 就绪、卡片接近视口才挂载(刷新后直接落在总览时主环境还没读完),挂上那一刻卡片尺寸不变,
|
|
237
258
|
// ResizeObserver 不会触发,所以把预览是否在场也作为依赖,挂上后补算一次缩放。
|
|
238
|
-
const previewMounted = !
|
|
259
|
+
const previewMounted = !shownCapture && shownStore !== undefined
|
|
239
260
|
React.useLayoutEffect(() => {
|
|
240
261
|
scale()
|
|
241
262
|
const container = frame.current
|
|
@@ -248,9 +269,9 @@ function SpaceThumbnail({ capture, store, running }: {
|
|
|
248
269
|
return (
|
|
249
270
|
<div ref={frame} className="sandbox-space-thumbnail" aria-hidden="true">
|
|
250
271
|
<div ref={host} className="sandbox-space-thumbnail-host" />
|
|
251
|
-
{!
|
|
272
|
+
{!shownCapture && shownStore && (
|
|
252
273
|
<div ref={preview} inert className="sandbox-space-thumbnail-preview">
|
|
253
|
-
<SandboxProvider store={
|
|
274
|
+
<SandboxProvider store={shownStore} dialogs={NOOP_DIALOGS}>
|
|
254
275
|
<PreviewWorkspace />
|
|
255
276
|
</SandboxProvider>
|
|
256
277
|
</div>
|
|
@@ -259,6 +280,36 @@ function SpaceThumbnail({ capture, store, running }: {
|
|
|
259
280
|
{running && <AgentCursor size={16} />}
|
|
260
281
|
</div>
|
|
261
282
|
)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 缩略图所在卡片是否已接近总览视口。挂载时先同步量一次,视口内的卡片在首帧绘制前就挂上画面,
|
|
287
|
+
* 不会先空一帧;其余卡片交给 IntersectionObserver。观察整张卡片而不是缩略图:卡片带
|
|
288
|
+
* `content-visibility: auto`,视口外时里面的元素不做布局。
|
|
289
|
+
*/
|
|
290
|
+
function useNearViewport(target: React.RefObject<HTMLElement | null>, eager = false) {
|
|
291
|
+
const [near, setNear] = React.useState(eager)
|
|
292
|
+
React.useLayoutEffect(() => {
|
|
293
|
+
if (near || eager) {
|
|
294
|
+
if (!near) setNear(true)
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
const card = target.current?.closest<HTMLElement>('.sandbox-space-card')
|
|
298
|
+
if (!card) return
|
|
299
|
+
const root = card.closest<HTMLElement>('.sandbox-space-overview')
|
|
300
|
+
const box = card.getBoundingClientRect()
|
|
301
|
+
const bounds = root?.getBoundingClientRect() ?? new DOMRect(0, 0, window.innerWidth, window.innerHeight)
|
|
302
|
+
if (box.bottom >= bounds.top - NEAR_MARGIN && box.top <= bounds.bottom + NEAR_MARGIN) {
|
|
303
|
+
setNear(true)
|
|
304
|
+
return
|
|
305
|
+
}
|
|
306
|
+
const observer = new IntersectionObserver((entries) => {
|
|
307
|
+
if (entries.some((entry) => entry.isIntersecting)) setNear(true)
|
|
308
|
+
}, { root, rootMargin: `${NEAR_MARGIN}px 0px` })
|
|
309
|
+
observer.observe(card)
|
|
310
|
+
return () => observer.disconnect()
|
|
311
|
+
}, [near, eager, target])
|
|
312
|
+
return near
|
|
262
313
|
}
|
|
263
314
|
|
|
264
315
|
function PreviewWorkspace() {
|
|
@@ -91,7 +91,8 @@
|
|
|
91
91
|
.sandbox-space-create { place-items: center; place-content: center; gap: 10px; border-style: dashed; color: var(--sandbox-muted); }
|
|
92
92
|
|
|
93
93
|
/* 已访问空间克隆离开前的真实工作区 DOM;未访问的空间用固定 1440×760 画布按快照渲染。两者都由 JS 按 contain 居中,卡片比例变化时完整页面不会被裁掉。 */
|
|
94
|
-
|
|
94
|
+
/* 缩略图尺寸固定,contain: strict 把里面的重排(预览重绘、AI 光标按 top/left 游走)关在卡片内,不波及整个网格。 */
|
|
95
|
+
.sandbox-space-thumbnail { position: relative; height: 190px; min-height: 190px; overflow: hidden; background: var(--background); pointer-events: none; contain: strict; }
|
|
95
96
|
.sandbox-space-thumbnail-host { position: absolute; inset: 0; overflow: hidden; }
|
|
96
97
|
.sandbox-space-thumbnail-live,
|
|
97
98
|
.sandbox-space-thumbnail-preview { position: absolute; top: 0; left: 0; display: flex; margin: 0; transform-origin: 0 0; }
|