chatluna-plugin-onebot-sandbox 1.0.0
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 +21 -0
- package/README.md +20 -0
- package/client/app.tsx +306 -0
- package/client/chat/chat-pane.tsx +303 -0
- package/client/chat/composer.css +635 -0
- package/client/chat/composer.tsx +646 -0
- package/client/chat/details-panel.tsx +196 -0
- package/client/chat/emoji-picker.tsx +70 -0
- package/client/chat/extension-mark.tsx +16 -0
- package/client/chat/forward.tsx +257 -0
- package/client/chat/image-preview.tsx +93 -0
- package/client/chat/member-menu.tsx +64 -0
- package/client/chat/message-list.tsx +617 -0
- package/client/chat/messages.css +1018 -0
- package/client/chat/notifications.tsx +83 -0
- package/client/chat/reactions.tsx +52 -0
- package/client/chat/search-panel.tsx +231 -0
- package/client/chat/sidebar.tsx +424 -0
- package/client/chat/webqq-view.tsx +71 -0
- package/client/environment/avatar-picker.tsx +92 -0
- package/client/environment/create-popover.tsx +228 -0
- package/client/environment/directory-model.ts +63 -0
- package/client/environment/entity-dialog.css +383 -0
- package/client/environment/entity-dialog.tsx +442 -0
- package/client/environment/page.css +14 -0
- package/client/environment/page.tsx +280 -0
- package/client/i18n.ts +19 -0
- package/client/index.ts +17 -0
- package/client/locales/en.yml +617 -0
- package/client/locales/zh.yml +617 -0
- package/client/mcp/capability-catalog.tsx +277 -0
- package/client/mcp/credential-manager.tsx +257 -0
- package/client/onebot-debug/page.tsx +329 -0
- package/client/records/record-layout.tsx +429 -0
- package/client/records/records.css +259 -0
- package/client/settings/about.tsx +43 -0
- package/client/settings/draft.ts +47 -0
- package/client/settings/localize.ts +76 -0
- package/client/settings/page.tsx +210 -0
- package/client/settings/settings.css +47 -0
- package/client/shared/avatar.tsx +35 -0
- package/client/shared/confirm-dialog.tsx +44 -0
- package/client/shared/controls.css +17 -0
- package/client/shared/discard-confirm.tsx +45 -0
- package/client/shared/floating-panel.ts +40 -0
- package/client/shared/format-duration.ts +22 -0
- package/client/shared/format-time.ts +49 -0
- package/client/shared/glass.css +150 -0
- package/client/shared/implementation.ts +12 -0
- package/client/shared/overlay-scrollbar.css +45 -0
- package/client/shared/overlay-scrollbar.tsx +123 -0
- package/client/shared/use-element-width.ts +19 -0
- package/client/shared/use-retained.ts +12 -0
- package/client/test-call/page.tsx +260 -0
- package/client/test-space/agent-visuals.tsx +121 -0
- package/client/test-space/observe-overlay.tsx +42 -0
- package/client/test-space/overview.tsx +267 -0
- package/client/test-space/spaces.css +201 -0
- package/client/test-space/thumbnail-capture.ts +63 -0
- package/client/test-space/thumbnail-scale.ts +21 -0
- package/client/test-space/use-space-list.ts +35 -0
- package/client/test-space/zoom.ts +197 -0
- package/client/webqq/composer-draft-host.ts +578 -0
- package/client/webqq/composer-draft.ts +81 -0
- package/client/webqq/conversation-tree.ts +155 -0
- package/client/webqq/emoji-catalog.ts +78 -0
- package/client/webqq/fork-boundary.ts +28 -0
- package/client/webqq/forward-cluster.ts +20 -0
- package/client/webqq/forward-dialog-stack.ts +74 -0
- package/client/webqq/forward-preview.ts +40 -0
- package/client/webqq/friend-menu.ts +17 -0
- package/client/webqq/group-display.ts +18 -0
- package/client/webqq/group-menu.ts +25 -0
- package/client/webqq/mention.ts +4 -0
- package/client/webqq/message-capabilities.ts +37 -0
- package/client/webqq/message-cluster.ts +68 -0
- package/client/webqq/message-presentation.ts +197 -0
- package/client/webqq/message-reveal.ts +31 -0
- package/client/webqq/message-search-date.ts +40 -0
- package/client/webqq/message-selection.ts +85 -0
- package/client/webqq/notification-requests.ts +20 -0
- package/client/webqq/participant-presentation.ts +128 -0
- package/client/webqq/profile-card.ts +199 -0
- package/client/webqq/relationship-directory.ts +62 -0
- package/client/webqq/thinking-panel.ts +7 -0
- package/client/webqq/user-stack.ts +53 -0
- package/client/workspace/agent-overlay-effect.ts +238 -0
- package/client/workspace/context.tsx +117 -0
- package/client/workspace/overlay-host.tsx +299 -0
- package/client/workspace/profile-card.css +164 -0
- package/client/workspace/state.ts +28 -0
- package/client/workspace/store.ts +388 -0
- package/client/workspace/use-test-spaces.ts +21 -0
- package/dist/.vite/manifest.json +21 -0
- package/dist/app-63rfTh6w.js +85 -0
- package/dist/client.css +4 -0
- package/dist/client.js +1 -0
- package/lib/account-profile.d.ts +17 -0
- package/lib/account-profile.d.ts.map +1 -0
- package/lib/base-dir.d.ts +4 -0
- package/lib/base-dir.d.ts.map +1 -0
- package/lib/bot.d.ts +185 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/builtin-avatar-options.d.ts +11 -0
- package/lib/builtin-avatar-options.d.ts.map +1 -0
- package/lib/builtin-avatars.d.ts +6 -0
- package/lib/builtin-avatars.d.ts.map +1 -0
- package/lib/channel-assignee.d.ts +52 -0
- package/lib/channel-assignee.d.ts.map +1 -0
- package/lib/chatluna/conversation-lines.d.ts +46 -0
- package/lib/chatluna/conversation-lines.d.ts.map +1 -0
- package/lib/chatluna/runtime.d.ts +26 -0
- package/lib/chatluna/runtime.d.ts.map +1 -0
- package/lib/chatluna/state.d.ts +67 -0
- package/lib/chatluna/state.d.ts.map +1 -0
- package/lib/chatluna/thinking.d.ts +10 -0
- package/lib/chatluna/thinking.d.ts.map +1 -0
- package/lib/chatluna/tools.d.ts +36 -0
- package/lib/chatluna/tools.d.ts.map +1 -0
- package/lib/chatluna/wakeup.d.ts +143 -0
- package/lib/chatluna/wakeup.d.ts.map +1 -0
- package/lib/console-contract.d.ts +131 -0
- package/lib/console-contract.d.ts.map +1 -0
- package/lib/console.d.ts +31 -0
- package/lib/console.d.ts.map +1 -0
- package/lib/control-service.d.ts +425 -0
- package/lib/control-service.d.ts.map +1 -0
- package/lib/conversation-resolution.d.ts +157 -0
- package/lib/conversation-resolution.d.ts.map +1 -0
- package/lib/error-detail.d.ts +3 -0
- package/lib/error-detail.d.ts.map +1 -0
- package/lib/inbound-delivery.d.ts +156 -0
- package/lib/inbound-delivery.d.ts.map +1 -0
- package/lib/index.d.ts +76 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12834 -0
- package/lib/index.js.map +1 -0
- package/lib/lifecycle.d.ts +8 -0
- package/lib/lifecycle.d.ts.map +1 -0
- package/lib/mcp/arguments.d.ts +71 -0
- package/lib/mcp/arguments.d.ts.map +1 -0
- package/lib/mcp/call-records.d.ts +32 -0
- package/lib/mcp/call-records.d.ts.map +1 -0
- package/lib/mcp/http-api.d.ts +147 -0
- package/lib/mcp/http-api.d.ts.map +1 -0
- package/lib/mcp/page-cursor.d.ts +37 -0
- package/lib/mcp/page-cursor.d.ts.map +1 -0
- package/lib/mcp/server.d.ts +60 -0
- package/lib/mcp/server.d.ts.map +1 -0
- package/lib/mcp/service.d.ts +219 -0
- package/lib/mcp/service.d.ts.map +1 -0
- package/lib/mcp/tool-registry.d.ts +113 -0
- package/lib/mcp/tool-registry.d.ts.map +1 -0
- package/lib/mcp/types.d.ts +144 -0
- package/lib/mcp/types.d.ts.map +1 -0
- package/lib/media-storage.d.ts +33 -0
- package/lib/media-storage.d.ts.map +1 -0
- package/lib/message-capabilities.d.ts +78 -0
- package/lib/message-capabilities.d.ts.map +1 -0
- package/lib/onebot-debug.d.ts +115 -0
- package/lib/onebot-debug.d.ts.map +1 -0
- package/lib/onebot-message.d.ts +23 -0
- package/lib/onebot-message.d.ts.map +1 -0
- package/lib/onebot-profiles.d.ts +45 -0
- package/lib/onebot-profiles.d.ts.map +1 -0
- package/lib/persistence.d.ts +148 -0
- package/lib/persistence.d.ts.map +1 -0
- package/lib/random.d.ts +5 -0
- package/lib/random.d.ts.map +1 -0
- package/lib/record-store.d.ts +80 -0
- package/lib/record-store.d.ts.map +1 -0
- package/lib/relationship-actions.d.ts +157 -0
- package/lib/relationship-actions.d.ts.map +1 -0
- package/lib/scope-directory.d.ts +105 -0
- package/lib/scope-directory.d.ts.map +1 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/test-spaces.d.ts +69 -0
- package/lib/test-spaces.d.ts.map +1 -0
- package/lib/types.d.ts +739 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/webui.d.ts +26 -0
- package/lib/webui.d.ts.map +1 -0
- package/package.json +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# chatluna-plugin-onebot-sandbox
|
|
2
|
+
|
|
3
|
+
在 ChatLuna v2 的 WebUI 中提供模拟 QQ(OneBot v11)环境,用于验证 ChatLuna 及其插件在私聊、群聊中的真实行为。
|
|
4
|
+
|
|
5
|
+
## Config
|
|
6
|
+
|
|
7
|
+
| Key | Type | Default | Description |
|
|
8
|
+
| --- | --- | --- | --- |
|
|
9
|
+
| `persistenceMode` | `'memory' \| 'database'` | `'database'` | 模拟环境状态存储方式 |
|
|
10
|
+
| `sandboxTimBubbleTail` | `boolean` | `true` | 显示气泡小尖角 |
|
|
11
|
+
| `sandboxMarkRecalledMessages` | `boolean` | `true` | 保留撤回气泡并显示撤回线 |
|
|
12
|
+
| `sceneMessageLimit` | `number` | `2000` | 每个空间保留的场景消息条数上限 |
|
|
13
|
+
| `sceneMessageMaxBytes` | `number` | `8388608` | 每个空间场景 JSON 的字节上限 |
|
|
14
|
+
| `testEndpoint.mcp` | `{ enabled, path }` | `{ false, '/mcp' }` | MCP 测试端点 |
|
|
15
|
+
| `testEndpoint.http` | `{ enabled, path }` | `{ false, '/api' }` | HTTP 测试端点 |
|
|
16
|
+
| `testEndpoint.shared` | object | — | 监听地址、端口、来源与 Origin 白名单、TLS 与调用配额 |
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/client/app.tsx
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useNavigate, useParams, useSearchParams } from 'react-router'
|
|
3
|
+
import { Badge, Button, cn, Spinner, Tabs, TabsList, TabsTrigger, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@chatluna/ui-kit'
|
|
4
|
+
import { toast, useLive } from '@chatluna/ui-client/client'
|
|
5
|
+
import { useT } from './i18n'
|
|
6
|
+
import { WebqqView } from './chat/webqq-view'
|
|
7
|
+
import { EnvironmentPage } from './environment/page'
|
|
8
|
+
import { OneBotDebugPage } from './onebot-debug/page'
|
|
9
|
+
import { useSettingsDraft } from './settings/draft'
|
|
10
|
+
import { SettingsPage } from './settings/page'
|
|
11
|
+
import { TestCallPage } from './test-call/page'
|
|
12
|
+
import { AgentControlIcon } from './test-space/agent-visuals'
|
|
13
|
+
import { AgentObserveOverlay } from './test-space/observe-overlay'
|
|
14
|
+
import { SpaceOverview, type SpaceCardAction } from './test-space/overview'
|
|
15
|
+
import { captureWorkspaceThumbnail, type WorkspaceThumbnailCapture } from './test-space/thumbnail-capture'
|
|
16
|
+
import { useSpaceList } from './test-space/use-space-list'
|
|
17
|
+
import { captureCardZoomRect, captureZoomRect, settleZoom, zoomWorkspaceFromRect } from './test-space/zoom'
|
|
18
|
+
import { SandboxProvider } from './workspace/context'
|
|
19
|
+
import { OverlayHost, useOverlayState } from './workspace/overlay-host'
|
|
20
|
+
import { bindStoreTranslator, errorText, invoke, WorkspaceStore } from './workspace/store'
|
|
21
|
+
import './shared/glass.css'
|
|
22
|
+
import './shared/controls.css'
|
|
23
|
+
|
|
24
|
+
type View = 'messages' | 'debug' | 'test-calls' | 'environment' | 'spaces' | 'settings'
|
|
25
|
+
|
|
26
|
+
const VIEWS: View[] = ['messages', 'debug', 'test-calls', 'environment', 'spaces', 'settings']
|
|
27
|
+
/** 分段标签里的工作区;AI 测试空间与源插件一样单独钉在页头右端。 */
|
|
28
|
+
const TAB_VIEWS: View[] = ['messages', 'debug', 'test-calls', 'environment', 'settings']
|
|
29
|
+
/** 空间内部只有消息工作区;调试、环境与设置都属于整个沙盒,从总览以外的入口进入时落在主环境。 */
|
|
30
|
+
const SPACE_TAB_VIEWS: View[] = ['messages']
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 沙盒工作台。路由 `/onebot-sandbox/:view?` 选择工作区,`?space=<id>` 让消息工作区定域到某个 AI 测试空间;
|
|
34
|
+
* 预设与模型请求分别交给 ChatLuna 自带的预设页与 trace 页,沙盒不再各做一份。服务端只推送
|
|
35
|
+
* 「哪个空间变了」的失效信号,工作区收到后串行重读。
|
|
36
|
+
*/
|
|
37
|
+
export function SandboxApp() {
|
|
38
|
+
const t = useT()
|
|
39
|
+
bindStoreTranslator(t)
|
|
40
|
+
const navigate = useNavigate()
|
|
41
|
+
const params = useParams()
|
|
42
|
+
const [searchParams] = useSearchParams()
|
|
43
|
+
const view = VIEWS.find((id) => id === params['view']) ?? 'messages'
|
|
44
|
+
const spaceId = view === 'messages' ? searchParams.get('space') ?? undefined : undefined
|
|
45
|
+
|
|
46
|
+
// 每个空间一份 store,进出空间时复用:进入前先把目标 store 读好,工作区首帧就能画出来接住缩放动画。
|
|
47
|
+
const stores = React.useRef(new Map<string, WorkspaceStore>())
|
|
48
|
+
const storeFor = React.useCallback((id: string | undefined) => {
|
|
49
|
+
const key = id ?? 'main'
|
|
50
|
+
let store = stores.current.get(key)
|
|
51
|
+
if (!store) stores.current.set(key, store = new WorkspaceStore(id))
|
|
52
|
+
return store
|
|
53
|
+
}, [])
|
|
54
|
+
const store = storeFor(spaceId)
|
|
55
|
+
const mainStore = storeFor(undefined)
|
|
56
|
+
|
|
57
|
+
const { state, setState, dialogs } = useOverlayState(store)
|
|
58
|
+
const viewState = React.useSyncExternalStore(store.subscribe, store.getView, store.getView)
|
|
59
|
+
const signal = useLive('onebot-sandbox.signal')
|
|
60
|
+
const tick = signal.data?.scenes[spaceId ?? '']
|
|
61
|
+
const startedAt = signal.data?.startedAt
|
|
62
|
+
const { spaces, loaded: spacesLoaded, reload: reloadSpaces } = useSpaceList()
|
|
63
|
+
const [captures, setCaptures] = React.useState<Record<string, WorkspaceThumbnailCapture>>({})
|
|
64
|
+
const [spaceBusy, setSpaceBusy] = React.useState(false)
|
|
65
|
+
const root = React.useRef<HTMLDivElement>(null)
|
|
66
|
+
const stage = React.useRef<HTMLDivElement>(null)
|
|
67
|
+
// 页头高度:消息页让聊天列延伸到页头背后(glass.css 的 .sandbox-chat-pane),需要准确的像素值。
|
|
68
|
+
const header = React.useRef<HTMLDivElement>(null)
|
|
69
|
+
const [headerHeight, setHeaderHeight] = React.useState(0)
|
|
70
|
+
React.useLayoutEffect(() => {
|
|
71
|
+
const element = header.current
|
|
72
|
+
if (!element) return
|
|
73
|
+
const measure = () => setHeaderHeight(element.getBoundingClientRect().height)
|
|
74
|
+
measure()
|
|
75
|
+
const observer = new ResizeObserver(measure)
|
|
76
|
+
observer.observe(element)
|
|
77
|
+
return () => observer.disconnect()
|
|
78
|
+
}, [])
|
|
79
|
+
const enterZoom = React.useRef<DOMRect | undefined>(undefined)
|
|
80
|
+
const exitZoom = React.useRef<{ key: string, rect: DOMRect } | undefined>(undefined)
|
|
81
|
+
// 进入空间的放大期间,总览留在工作区背后播完推近淡出:key 是被点的卡片,top 把它钉在原来的位置。
|
|
82
|
+
const [launch, setLaunch] = React.useState<{ key: string, top: number }>()
|
|
83
|
+
const space = spaceId ? spaces.find(({ id }) => id === spaceId) : undefined
|
|
84
|
+
// 与源插件一致,入口图标跟随 MCP 服务器活动:有测试调用正在进行时转动并带光环。
|
|
85
|
+
const mcpRunning = signal.data?.mcpRunning ?? false
|
|
86
|
+
const spacesLabel = t(mcpRunning ? 'sandbox.nav.spacesRunning' : 'sandbox.nav.spaces')
|
|
87
|
+
const settingsDirty = useSettingsDraft().dirty
|
|
88
|
+
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
store.activate()
|
|
91
|
+
void store.load()
|
|
92
|
+
setState({})
|
|
93
|
+
return () => store.dispose()
|
|
94
|
+
}, [store, setState])
|
|
95
|
+
|
|
96
|
+
// 地址里的空间已被删除时退回主环境,不停在一个读不到的空间上。
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
if (spaceId && spacesLoaded && !spaces.some(({ id }) => id === spaceId)) navigate('/onebot-sandbox/messages', { replace: true })
|
|
99
|
+
}, [spaceId, spaces, spacesLoaded, navigate])
|
|
100
|
+
|
|
101
|
+
// 首个信号只是订阅时的快照,不代表变化;之后每次序号变化都触发一次重读。换空间后重新认一次快照。
|
|
102
|
+
const seen = React.useRef<{ store: WorkspaceStore, tick: number } | undefined>(undefined)
|
|
103
|
+
React.useEffect(() => {
|
|
104
|
+
if (tick === undefined) return
|
|
105
|
+
if (seen.current?.store === store && seen.current.tick !== tick) store.notifySceneChanged()
|
|
106
|
+
seen.current = { store, tick }
|
|
107
|
+
}, [tick, store])
|
|
108
|
+
|
|
109
|
+
// 保存设置会让插件按新配置重启:启动时刻一变就整体重读,外观等随工作区下发的设置随之生效。
|
|
110
|
+
const started = React.useRef<number | undefined>(undefined)
|
|
111
|
+
React.useEffect(() => {
|
|
112
|
+
if (startedAt === undefined) return
|
|
113
|
+
if (started.current !== undefined && started.current !== startedAt) {
|
|
114
|
+
if (store.getView().workspace) store.notifySceneChanged()
|
|
115
|
+
else void store.load()
|
|
116
|
+
}
|
|
117
|
+
started.current = startedAt
|
|
118
|
+
}, [startedAt, store])
|
|
119
|
+
|
|
120
|
+
// 进入空间:工作区在新路由的首帧从被点击的卡片处连续放大就位。
|
|
121
|
+
React.useLayoutEffect(() => {
|
|
122
|
+
const rect = enterZoom.current
|
|
123
|
+
if (!rect || view !== 'messages') return
|
|
124
|
+
enterZoom.current = undefined
|
|
125
|
+
const backdrop = root.current?.querySelector<HTMLElement>('.sandbox-space-overview.is-backdrop')
|
|
126
|
+
const card = launch && backdrop?.querySelector<HTMLElement>(`[data-space-id="${CSS.escape(launch.key)}"]`)
|
|
127
|
+
if (stage.current) zoomWorkspaceFromRect(stage.current, rect, backdrop, card, () => setLaunch(undefined))
|
|
128
|
+
else setLaunch(undefined)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const runSpaceTask = async (task: () => Promise<unknown>) => {
|
|
132
|
+
setSpaceBusy(true)
|
|
133
|
+
try {
|
|
134
|
+
await task()
|
|
135
|
+
} catch (error) {
|
|
136
|
+
toast.error(t('sandbox.spaces.actionFailed'), { description: errorText(error) })
|
|
137
|
+
} finally {
|
|
138
|
+
setSpaceBusy(false)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const enterSpace = async (id?: string) => {
|
|
143
|
+
// 新建的空间还没有卡片,从创建卡片处起步。
|
|
144
|
+
const key = id ?? 'main'
|
|
145
|
+
const rect = captureCardZoomRect(document.querySelector(`[data-space-id="${CSS.escape(key)}"]`) ?? document.querySelector('.sandbox-space-create'))
|
|
146
|
+
const target = storeFor(id)
|
|
147
|
+
target.activate()
|
|
148
|
+
await target.load()
|
|
149
|
+
enterZoom.current = rect
|
|
150
|
+
const overview = root.current?.querySelector('.sandbox-space-overview')
|
|
151
|
+
if (rect && overview && root.current) setLaunch({ key, top: overview.getBoundingClientRect().top - root.current.getBoundingClientRect().top })
|
|
152
|
+
navigate(id ? `/onebot-sandbox/messages?space=${encodeURIComponent(id)}` : '/onebot-sandbox/messages')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const openOverview = async () => {
|
|
156
|
+
// 离开前克隆消息工作区当前画面作为该空间的缩略图,并记下位置,让总览里对应卡片从这里缩回网格位。
|
|
157
|
+
// 进入动画还没播完就退出时先让它就位,克隆与起点都取静止的画面。
|
|
158
|
+
settleZoom()
|
|
159
|
+
const workspace = view === 'messages' ? stage.current : null
|
|
160
|
+
if (workspace) {
|
|
161
|
+
const key = spaceId ?? 'main'
|
|
162
|
+
const capture = captureWorkspaceThumbnail(workspace)
|
|
163
|
+
setCaptures((value) => ({ ...value, [key]: capture }))
|
|
164
|
+
const rect = captureZoomRect(workspace)
|
|
165
|
+
exitZoom.current = rect && { key, rect }
|
|
166
|
+
} else {
|
|
167
|
+
// 总览的清理可能放回过一个没播完的起点;从其他标签页进入时不沿用它。
|
|
168
|
+
exitZoom.current = undefined
|
|
169
|
+
}
|
|
170
|
+
// 先取数据再切视图,卡片的初始变换才能赶在首帧写入。
|
|
171
|
+
await reloadSpaces().catch(() => {})
|
|
172
|
+
navigate('/onebot-sandbox/spaces')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const actOnSpace = (action: SpaceCardAction | 'take-over' | 'terminate', id: string) => runSpaceTask(async () => {
|
|
176
|
+
if (action === 'return') await invoke('onebot-sandbox.return-test-space', { spaceId: id })
|
|
177
|
+
else if (action === 'reactivate') await invoke('onebot-sandbox.reactivate-test-space', { spaceId: id })
|
|
178
|
+
else if (action === 'take-over') await invoke('onebot-sandbox.take-over-test-space', { spaceId: id })
|
|
179
|
+
else if (action === 'terminate') await invoke('onebot-sandbox.terminate-test-space', { spaceId: id })
|
|
180
|
+
else {
|
|
181
|
+
await invoke('onebot-sandbox.delete-test-space', { spaceId: id })
|
|
182
|
+
stores.current.delete(id)
|
|
183
|
+
setCaptures(({ [id]: _, ...rest }) => rest)
|
|
184
|
+
}
|
|
185
|
+
await reloadSpaces()
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
const createSpace = () => runSpaceTask(async () => {
|
|
189
|
+
const created = await invoke('onebot-sandbox.create-test-space', {})
|
|
190
|
+
await reloadSpaces()
|
|
191
|
+
await enterSpace(created.id)
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const selectView = (next: View) => {
|
|
195
|
+
if (next === 'spaces') void openOverview()
|
|
196
|
+
else navigate(`/onebot-sandbox/${next}`)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const loading = (
|
|
200
|
+
<div className="flex flex-1 flex-col items-center justify-center gap-3 text-xs text-muted-foreground">
|
|
201
|
+
{viewState.loadError ? (
|
|
202
|
+
<>
|
|
203
|
+
<p role="alert" className="text-destructive">{viewState.loadError}</p>
|
|
204
|
+
<Button size="sm" variant="outline" onClick={() => void store.load()}>{t('sandbox.common.retry')}</Button>
|
|
205
|
+
</>
|
|
206
|
+
) : <Spinner />}
|
|
207
|
+
</div>
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<TooltipProvider>
|
|
212
|
+
<SandboxProvider store={store} dialogs={dialogs}>
|
|
213
|
+
{/*
|
|
214
|
+
* 进出空间的缩放动画里,推近的总览与放大的卡片都会越出根节点;不裁掉的话 v2 外壳的滚动容器会把它们算进
|
|
215
|
+
* 可滚动范围,Chrome 随即冒出横竖滚动条、内容区变窄,动画终点跟着错位。用 clip 而不是 hidden:
|
|
216
|
+
* 根节点不成为滚动容器,也不像 filter 那样截断里面的毛玻璃采样。
|
|
217
|
+
*/}
|
|
218
|
+
<div ref={root} className="relative flex h-full min-h-0 flex-col bg-background text-sm leading-6 text-foreground" style={{ overflow: 'clip' }}>
|
|
219
|
+
{/* 页头用 v2 页面的标题与分段标签,压成一行,把高度留给工作区。 */}
|
|
220
|
+
<Tabs
|
|
221
|
+
ref={header}
|
|
222
|
+
value={view}
|
|
223
|
+
className={cn('shrink-0 gap-4 px-6 py-3 data-horizontal:flex-row data-horizontal:items-center', view === 'messages' && 'sandbox-page-header')}
|
|
224
|
+
onValueChange={(value) => selectView(value as View)}
|
|
225
|
+
>
|
|
226
|
+
<h1 className="shrink-0 text-lg font-semibold">{t('onebot-sandbox.title')}</h1>
|
|
227
|
+
<TabsList className="sandbox-scroll-strip min-w-0 max-w-full justify-start overflow-x-auto" aria-label={t('sandbox.nav.label')}>
|
|
228
|
+
{(spaceId ? SPACE_TAB_VIEWS : TAB_VIEWS).map((id) => (
|
|
229
|
+
<TabsTrigger key={id} value={id}>
|
|
230
|
+
{t(`sandbox.nav.${id}`)}
|
|
231
|
+
{/* 离开设置页时草稿保留(settings/draft.ts),这里提示还有没保存的修改。 */}
|
|
232
|
+
{id === 'settings' && settingsDirty && <span role="img" aria-label={t('sandbox.settings.unsaved')} className="size-1.5 shrink-0 rounded-full bg-primary" />}
|
|
233
|
+
</TabsTrigger>
|
|
234
|
+
))}
|
|
235
|
+
</TabsList>
|
|
236
|
+
{/* Badge 是 inline-flex,text-overflow 对它无效;省略号要落在内层的块上。 */}
|
|
237
|
+
{space && <Badge variant="secondary" className="min-w-0 max-w-60"><span className="truncate">{t('sandbox.spaces.current', { name: space.name })}</span></Badge>}
|
|
238
|
+
<Tooltip>
|
|
239
|
+
<TooltipTrigger render={(
|
|
240
|
+
<Button
|
|
241
|
+
variant="ghost"
|
|
242
|
+
size="icon"
|
|
243
|
+
className={cn('ml-auto shrink-0 overflow-visible', view === 'spaces' && 'bg-accent text-accent-foreground')}
|
|
244
|
+
// 运行态与被控覆盖层同色,取 v2 主题的 --primary(spaces.css)。
|
|
245
|
+
style={mcpRunning ? { color: 'var(--primary)' } : undefined}
|
|
246
|
+
aria-label={spacesLabel}
|
|
247
|
+
aria-current={view === 'spaces' ? 'page' : undefined}
|
|
248
|
+
onClick={() => selectView('spaces')}
|
|
249
|
+
/>
|
|
250
|
+
)}>
|
|
251
|
+
<AgentControlIcon running={mcpRunning} />
|
|
252
|
+
</TooltipTrigger>
|
|
253
|
+
<TooltipContent>{spacesLabel}</TooltipContent>
|
|
254
|
+
</Tooltip>
|
|
255
|
+
</Tabs>
|
|
256
|
+
{/* 总览与工作区分两个位置渲染:进入空间时总览不卸载,留在背后做背景动画,缩略图不必重新渲染。 */}
|
|
257
|
+
{(view === 'spaces' || (launch && view === 'messages')) && (
|
|
258
|
+
<SpaceOverview
|
|
259
|
+
spaces={spaces}
|
|
260
|
+
mainStore={mainStore}
|
|
261
|
+
captures={captures}
|
|
262
|
+
exitZoom={exitZoom}
|
|
263
|
+
launching={view === 'spaces' ? undefined : launch}
|
|
264
|
+
onEnter={(id) => void runSpaceTask(() => enterSpace(id))}
|
|
265
|
+
onCreate={() => void createSpace()}
|
|
266
|
+
onAction={(action, id) => void actOnSpace(action, id)}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
{view === 'settings' ? <SettingsPage /> : view === 'spaces' ? null : viewState.workspace ? (
|
|
270
|
+
<>
|
|
271
|
+
{view === 'messages' && (
|
|
272
|
+
<div
|
|
273
|
+
ref={stage}
|
|
274
|
+
className="sandbox-stage relative flex min-h-0 flex-1"
|
|
275
|
+
style={{
|
|
276
|
+
'--sandbox-accent': viewState.workspace.appearance.sandboxAccentColor,
|
|
277
|
+
'--sandbox-page-header-height': `${headerHeight}px`,
|
|
278
|
+
} as React.CSSProperties}
|
|
279
|
+
>
|
|
280
|
+
<WebqqView />
|
|
281
|
+
</div>
|
|
282
|
+
)}
|
|
283
|
+
{/* 被控覆盖层挂在根节点上,连页头一起罩住;不放进 .sandbox-stage,否则进入空间的缩放动画会把它一起缩放、裁成卡片形状。 */}
|
|
284
|
+
{view === 'messages' && space?.status === 'running' && (
|
|
285
|
+
<AgentObserveOverlay
|
|
286
|
+
spaceName={space.name}
|
|
287
|
+
busy={spaceBusy}
|
|
288
|
+
style={{
|
|
289
|
+
'--sandbox-accent': viewState.workspace.appearance.sandboxAccentColor,
|
|
290
|
+
'--sandbox-page-header-height': `${headerHeight}px`,
|
|
291
|
+
} as React.CSSProperties}
|
|
292
|
+
onTakeOver={() => void actOnSpace('take-over', space.id)}
|
|
293
|
+
onTerminate={() => void actOnSpace('terminate', space.id)}
|
|
294
|
+
/>
|
|
295
|
+
)}
|
|
296
|
+
{view === 'debug' && <OneBotDebugPage />}
|
|
297
|
+
{view === 'test-calls' && <TestCallPage />}
|
|
298
|
+
{view === 'environment' && <EnvironmentPage />}
|
|
299
|
+
<OverlayHost state={state} setState={setState} />
|
|
300
|
+
</>
|
|
301
|
+
) : loading}
|
|
302
|
+
</div>
|
|
303
|
+
</SandboxProvider>
|
|
304
|
+
</TooltipProvider>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { ChevronLeftIcon, EllipsisIcon, SearchIcon, Share2Icon } from 'lucide-react'
|
|
3
|
+
import { Button, cn } from '@chatluna/ui-kit'
|
|
4
|
+
import { buildMessageCapabilityMap } from '../webqq/message-capabilities'
|
|
5
|
+
import { buildForwardPreviewMap } from '../webqq/forward-preview'
|
|
6
|
+
import { buildConversationTree, toRecentForwardTargets } from '../webqq/conversation-tree'
|
|
7
|
+
import { getFriendDirectory, getGroupDirectory } from '../webqq/relationship-directory'
|
|
8
|
+
import {
|
|
9
|
+
closeForwardStack,
|
|
10
|
+
loadForwardDialogFrame,
|
|
11
|
+
pushForwardFrame,
|
|
12
|
+
type ForwardDialogFrame,
|
|
13
|
+
} from '../webqq/forward-dialog-stack'
|
|
14
|
+
import { enterMessageSelection, exitMessageSelection, resolveForwardConfirmation, toggleMessageSelection, type MessageSelectionState } from '../webqq/message-selection'
|
|
15
|
+
import { formatMentionContent } from '../webqq/mention'
|
|
16
|
+
import type { FriendMenuState } from '../webqq/friend-menu'
|
|
17
|
+
import type { SandboxMessage } from '../../src/types'
|
|
18
|
+
import { useT } from '../i18n'
|
|
19
|
+
import { SandboxAvatar } from '../shared/avatar'
|
|
20
|
+
import { conversationMessagesOf } from '../workspace/store'
|
|
21
|
+
import { useSandbox, useWorkspace } from '../workspace/context'
|
|
22
|
+
import { Composer, type ComposerHandle } from './composer'
|
|
23
|
+
import { EmojiPicker } from './emoji-picker'
|
|
24
|
+
import { ForwardTargetDialog, ForwardViewer, type ForwardTargets } from './forward'
|
|
25
|
+
import { ImagePreview } from './image-preview'
|
|
26
|
+
import { MessageList, type MessageListHandle } from './message-list'
|
|
27
|
+
import { MessageSearchPanel } from './search-panel'
|
|
28
|
+
|
|
29
|
+
// 多选条悬浮在消息区底部(glass.css 的 .sandbox-selection-bar:最小高 48px、距底 16px),再留 16px 间隙。
|
|
30
|
+
const SELECTION_BAR_SPACE = 80
|
|
31
|
+
|
|
32
|
+
export function ChatPane({ detailsVisible, onToggleDetails, onBack, mentionBridge, className }: {
|
|
33
|
+
detailsVisible: boolean
|
|
34
|
+
/** 信息栏的成员菜单借这条桥把 @ 插进本聊天区的发送框。 */
|
|
35
|
+
mentionBridge?: React.RefObject<(participantId: string) => void>
|
|
36
|
+
/** 不传时不显示信息栏按钮(私聊没有信息栏)。 */
|
|
37
|
+
onToggleDetails?(): void
|
|
38
|
+
onBack?(): void
|
|
39
|
+
className?: string
|
|
40
|
+
}) {
|
|
41
|
+
const t = useT()
|
|
42
|
+
const { store, run, dialogs } = useSandbox()
|
|
43
|
+
const workspace = useWorkspace()
|
|
44
|
+
const { snapshot, conversation, group, peer, bot, operatorId, participants, participantNames, resolveAvatar } = workspace
|
|
45
|
+
const list = React.useRef<MessageListHandle>(null)
|
|
46
|
+
const composer = React.useRef<ComposerHandle>(null)
|
|
47
|
+
const [replyTo, setReplyTo] = React.useState('')
|
|
48
|
+
const [reactionTarget, setReactionTarget] = React.useState('')
|
|
49
|
+
const [selection, setSelection] = React.useState<MessageSelectionState>(exitMessageSelection())
|
|
50
|
+
const [forwardTargetOpen, setForwardTargetOpen] = React.useState(false)
|
|
51
|
+
const [forwardStack, setForwardStack] = React.useState<ForwardDialogFrame[]>([])
|
|
52
|
+
const [imageUrl, setImageUrl] = React.useState('')
|
|
53
|
+
// 悬浮发送框回报的占位高度,初值按单行胶囊估算(44 + 28),首帧不至于让末条消息被遮住。
|
|
54
|
+
const [composerSpace, setComposerSpace] = React.useState(72)
|
|
55
|
+
const [searchOpen, setSearchOpen] = React.useState(false)
|
|
56
|
+
|
|
57
|
+
const messages = React.useMemo(() => conversationMessagesOf(snapshot, conversation?.id), [snapshot, conversation?.id])
|
|
58
|
+
const replyMessages = React.useMemo(() => {
|
|
59
|
+
const byId = new Map(snapshot.messages.map((message) => [message.id, message]))
|
|
60
|
+
return Object.fromEntries(messages.flatMap(({ replyToMessageId }) => {
|
|
61
|
+
const reply = replyToMessageId ? byId.get(replyToMessageId) : undefined
|
|
62
|
+
return reply ? [[reply.id, reply] as const] : []
|
|
63
|
+
})) as Record<string, SandboxMessage>
|
|
64
|
+
}, [messages, snapshot.messages])
|
|
65
|
+
const forwardPreviews = React.useMemo(() => buildForwardPreviewMap(messages, snapshot.forwards ?? []), [messages, snapshot.forwards])
|
|
66
|
+
const capabilities = React.useMemo(() => buildMessageCapabilityMap({ messages, conversation, operatorId, group }), [messages, conversation, operatorId, group])
|
|
67
|
+
const friendMenuStates = React.useMemo<Record<string, FriendMenuState>>(() => {
|
|
68
|
+
if (!operatorId) return {}
|
|
69
|
+
return Object.fromEntries(snapshot.participants.map(({ id: targetId }) => [targetId, {
|
|
70
|
+
isFriend: snapshot.friendships.some(({ participantIds }) => participantIds.includes(operatorId) && participantIds.includes(targetId)),
|
|
71
|
+
pendingOutgoing: snapshot.requests.some((request) => request.type === 'friend' && request.requesterId === operatorId && request.targetId === targetId),
|
|
72
|
+
pendingIncoming: snapshot.requests.some((request) => request.type === 'friend' && request.requesterId === targetId && request.targetId === operatorId),
|
|
73
|
+
}]))
|
|
74
|
+
}, [snapshot, operatorId])
|
|
75
|
+
const mentionCandidates = React.useMemo(() => group?.members.flatMap((member) => {
|
|
76
|
+
const participant = participants[member.participantId]
|
|
77
|
+
if (!participant) return []
|
|
78
|
+
const card = member.card?.trim()
|
|
79
|
+
return [{
|
|
80
|
+
id: member.participantId,
|
|
81
|
+
name: card || participant.name,
|
|
82
|
+
avatar: participant.avatar,
|
|
83
|
+
kind: participant.isBot ? 'bot' as const : 'user' as const,
|
|
84
|
+
keywords: card && card !== participant.name ? [participant.name] : undefined,
|
|
85
|
+
}]
|
|
86
|
+
}) ?? [], [group, participants])
|
|
87
|
+
const forwardTargets = React.useMemo<ForwardTargets>(() => ({
|
|
88
|
+
recent: toRecentForwardTargets(buildConversationTree({ scene: snapshot, conversations: workspace.conversations, operatorId, resolveAvatar, emptyPreview: t('sandbox.chat.emptyPreview') })),
|
|
89
|
+
friends: getFriendDirectory(snapshot, operatorId).filter((entry) => entry.isFriend && entry.conversationId).map((entry) => ({
|
|
90
|
+
conversationId: entry.conversationId!,
|
|
91
|
+
title: entry.displayName,
|
|
92
|
+
subtitle: t(entry.statusKey, { name: entry.participantName }),
|
|
93
|
+
avatar: resolveAvatar(entry.avatar),
|
|
94
|
+
avatarKind: entry.isBot ? 'bot' as const : 'user' as const,
|
|
95
|
+
})),
|
|
96
|
+
groups: getGroupDirectory(snapshot, operatorId).filter((entry) => entry.member && entry.conversationId).map((entry) => ({
|
|
97
|
+
conversationId: entry.conversationId!,
|
|
98
|
+
title: entry.name,
|
|
99
|
+
subtitle: t('sandbox.chat.groupSubtitle', { id: entry.id, count: entry.members.length }),
|
|
100
|
+
avatar: resolveAvatar(entry.avatar),
|
|
101
|
+
avatarKind: 'group' as const,
|
|
102
|
+
})),
|
|
103
|
+
}), [snapshot, workspace.conversations, operatorId, resolveAvatar, t])
|
|
104
|
+
const chatLunaStates = workspace.workspace.chatLunaStates.filter(({ conversationId }) => conversationId === conversation?.id)
|
|
105
|
+
|
|
106
|
+
// 换会话时清掉与上一个会话绑定的临时状态。
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
setReplyTo('')
|
|
109
|
+
setReactionTarget('')
|
|
110
|
+
setSelection(exitMessageSelection())
|
|
111
|
+
setForwardTargetOpen(false)
|
|
112
|
+
setForwardStack(closeForwardStack())
|
|
113
|
+
setSearchOpen(false)
|
|
114
|
+
}, [conversation?.id])
|
|
115
|
+
|
|
116
|
+
// Esc 的优先级:先关转发目标,再退出多选,最后关闭查找。
|
|
117
|
+
React.useEffect(() => {
|
|
118
|
+
const onKey = (event: KeyboardEvent) => {
|
|
119
|
+
if (event.key !== 'Escape' || !selection.active || forwardTargetOpen) return
|
|
120
|
+
event.preventDefault()
|
|
121
|
+
setSelection(exitMessageSelection())
|
|
122
|
+
}
|
|
123
|
+
window.addEventListener('keydown', onKey)
|
|
124
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
125
|
+
}, [selection.active, forwardTargetOpen])
|
|
126
|
+
|
|
127
|
+
const mentionMember = (id: string) => composer.current?.insertMention({ id, name: mentionCandidates.find((candidate) => candidate.id === id)?.name ?? participantNames[id] ?? id })
|
|
128
|
+
React.useEffect(() => {
|
|
129
|
+
if (mentionBridge) mentionBridge.current = mentionMember
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const selectionContext = { messageCapabilities: capabilities }
|
|
133
|
+
const replyMessage = messages.find(({ id }) => id === replyTo)
|
|
134
|
+
const conversationId = conversation?.id
|
|
135
|
+
|
|
136
|
+
const openForward = async (input: { forwardId?: string, messageId?: string }, mode: 'replace' | 'push') => {
|
|
137
|
+
const frame = await loadForwardDialogFrame({ input, load: (request) => store.getForwardMessage(request) })
|
|
138
|
+
if (frame) setForwardStack((stack) => pushForwardFrame(stack, frame, mode))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const title = conversation?.title ?? group?.name ?? peer?.name ?? conversation?.id ?? t('sandbox.chat.pick')
|
|
142
|
+
const rootTitle = group?.name ?? peer?.name ?? ''
|
|
143
|
+
const instancePrefix = conversation?.kind === 'instance' ? `${rootTitle} · ` : ''
|
|
144
|
+
const subtitle = group
|
|
145
|
+
? `${instancePrefix}${t('sandbox.chat.groupSubtitle', { id: group.id, count: group.members.length })}`
|
|
146
|
+
: bot ? `${instancePrefix}${t('sandbox.chat.botSubtitle')}` : peer ? `${instancePrefix}${t('sandbox.chat.friendSubtitle')}` : t('sandbox.chat.none')
|
|
147
|
+
const avatarKind = group ? 'group' : bot ? 'bot' : 'user'
|
|
148
|
+
const openTitleProfile = (event: React.MouseEvent) => {
|
|
149
|
+
const anchor = { x: event.clientX, y: event.clientY }
|
|
150
|
+
if (group) dialogs.openGroupProfile(group.id, anchor)
|
|
151
|
+
else if (peer) dialogs.openProfile(peer.id, anchor)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<main className={cn('sandbox-chat-pane flex min-h-0 min-w-0 flex-1 flex-col bg-background', className)}>
|
|
156
|
+
<header className="sandbox-chat-header flex h-14 shrink-0 items-center gap-2 border-b border-border px-3">
|
|
157
|
+
{onBack && (
|
|
158
|
+
<Button variant="ghost" size="icon-sm" aria-label={t('sandbox.chat.back')} onClick={onBack}><ChevronLeftIcon /></Button>
|
|
159
|
+
)}
|
|
160
|
+
<button type="button" className="flex min-w-0 items-center gap-2.5 rounded-lg px-1 py-1 text-left hover:bg-accent/60 disabled:hover:bg-transparent" disabled={!group && !peer} aria-label={t('sandbox.chat.viewProfileOf', { name: title })} onClick={openTitleProfile}>
|
|
161
|
+
<SandboxAvatar kind={avatarKind} name={title} src={resolveAvatar(group?.avatar ?? peer?.avatar)} className="size-8" />
|
|
162
|
+
<span className="flex min-w-0 flex-col">
|
|
163
|
+
<strong className="truncate text-sm font-medium">{title}</strong>
|
|
164
|
+
<span className="truncate text-[11px] text-muted-foreground">{subtitle}</span>
|
|
165
|
+
</span>
|
|
166
|
+
</button>
|
|
167
|
+
<div className="ml-auto flex min-w-0 items-center gap-1">
|
|
168
|
+
{searchOpen && conversation ? (
|
|
169
|
+
<MessageSearchPanel
|
|
170
|
+
adapter={{
|
|
171
|
+
conversationId,
|
|
172
|
+
search: (input) => store.searchConversationMessages(input),
|
|
173
|
+
isLoaded: (messageId) => conversationMessagesOf(store.snapshot ?? snapshot, conversationId).some(({ id }) => id === messageId),
|
|
174
|
+
canLoadMore: () => !!visibleConversation(store, conversationId)?.hasMoreMessages,
|
|
175
|
+
oldestLoadedId: () => conversationMessagesOf(store.snapshot ?? snapshot, conversationId)[0]?.id,
|
|
176
|
+
loadMore: () => conversationId ? store.loadEarlierMessages(conversationId) : Promise.resolve(),
|
|
177
|
+
reveal: (messageId) => list.current?.revealMessage(messageId) ?? false,
|
|
178
|
+
}}
|
|
179
|
+
onClose={() => setSearchOpen(false)}
|
|
180
|
+
/>
|
|
181
|
+
) : (
|
|
182
|
+
<Button variant="ghost" size="icon" disabled={!conversation} aria-label={t('sandbox.search.label')} onClick={() => {
|
|
183
|
+
setSelection(exitMessageSelection())
|
|
184
|
+
setSearchOpen(true)
|
|
185
|
+
}}>
|
|
186
|
+
<SearchIcon />
|
|
187
|
+
</Button>
|
|
188
|
+
)}
|
|
189
|
+
{onToggleDetails && (
|
|
190
|
+
<Button variant="ghost" size="icon" aria-pressed={detailsVisible} aria-label={t(detailsVisible ? 'sandbox.details.close' : 'sandbox.details.open')} onClick={onToggleDetails}>
|
|
191
|
+
<EllipsisIcon />
|
|
192
|
+
</Button>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
</header>
|
|
196
|
+
{conversation ? (
|
|
197
|
+
<>
|
|
198
|
+
<div className="sandbox-chat-stage relative flex min-h-0 flex-1 flex-col">
|
|
199
|
+
<MessageList
|
|
200
|
+
ref={list}
|
|
201
|
+
bottomSpace={selection.active ? SELECTION_BAR_SPACE : composerSpace}
|
|
202
|
+
messages={messages}
|
|
203
|
+
chatLunaStates={chatLunaStates}
|
|
204
|
+
replyMessages={replyMessages}
|
|
205
|
+
forwardPreviews={forwardPreviews}
|
|
206
|
+
capabilities={capabilities}
|
|
207
|
+
friendMenuStates={friendMenuStates}
|
|
208
|
+
hasMoreMessages={!!conversation.hasMoreMessages}
|
|
209
|
+
scrollKey={`${store.spaceId ?? 'main'}:${conversation.id}`}
|
|
210
|
+
selectionMode={selection.active}
|
|
211
|
+
selectedIds={[...selection.messageIds]}
|
|
212
|
+
onReply={(id) => {
|
|
213
|
+
setReplyTo(id)
|
|
214
|
+
requestAnimationFrame(() => composer.current?.focus())
|
|
215
|
+
}}
|
|
216
|
+
onBranch={(messageId) => run(t('sandbox.error.branch'), () => store.branchConversationInstance({ conversationId: conversation.id, messageId }))}
|
|
217
|
+
onRecall={(messageId) => run(t('sandbox.error.recall'), () => store.recallMessage({ conversationId: conversation.id, messageId }))}
|
|
218
|
+
onReact={(messageId, emojiId, enabled) => run(t('sandbox.error.react'), () => store.setMessageReaction({ conversationId: conversation.id, messageId, emojiId, enabled }))}
|
|
219
|
+
onOpenReactionPicker={(id) => !selection.active && setReactionTarget(id)}
|
|
220
|
+
onEnterSelection={(id) => {
|
|
221
|
+
const next = enterMessageSelection(id, selectionContext)
|
|
222
|
+
if (!next) return
|
|
223
|
+
setReplyTo('')
|
|
224
|
+
setSearchOpen(false)
|
|
225
|
+
setSelection(next)
|
|
226
|
+
}}
|
|
227
|
+
onToggleSelection={(id) => setSelection((state) => toggleMessageSelection(state, id, selectionContext))}
|
|
228
|
+
onOpenForward={(input) => void openForward(input, 'replace')}
|
|
229
|
+
onOpenImage={setImageUrl}
|
|
230
|
+
onLoadHistory={() => store.loadEarlierMessages(conversation.id)}
|
|
231
|
+
onClearConversation={() => run(t('sandbox.error.clear'), () => store.clearConversationMessages({ conversationId: conversation.id }))}
|
|
232
|
+
onMention={mentionMember}
|
|
233
|
+
/>
|
|
234
|
+
{!selection.active && (
|
|
235
|
+
<Composer
|
|
236
|
+
ref={composer}
|
|
237
|
+
replyingTo={replyMessage ? {
|
|
238
|
+
id: replyMessage.id,
|
|
239
|
+
authorName: participantNames[replyMessage.authorId] ?? replyMessage.authorId,
|
|
240
|
+
content: formatMentionContent(replyMessage.content, participantNames),
|
|
241
|
+
} : undefined}
|
|
242
|
+
mentionCandidates={mentionCandidates}
|
|
243
|
+
onClearReply={() => setReplyTo('')}
|
|
244
|
+
onOpenImage={setImageUrl}
|
|
245
|
+
onSpaceChange={setComposerSpace}
|
|
246
|
+
onSend={async (intent) => {
|
|
247
|
+
if (intent.media?.length) {
|
|
248
|
+
await store.sendMediaMessage({ conversationId: intent.conversationId, media: intent.media, content: intent.content || undefined, replyToMessageId: intent.replyToMessageId })
|
|
249
|
+
} else {
|
|
250
|
+
await store.sendMessage({ conversationId: intent.conversationId, content: intent.content, replyToMessageId: intent.replyToMessageId })
|
|
251
|
+
}
|
|
252
|
+
}}
|
|
253
|
+
/>
|
|
254
|
+
)}
|
|
255
|
+
{selection.active && (
|
|
256
|
+
<div role="toolbar" aria-label={t('sandbox.chat.selectionToolbar')} className="sandbox-selection-bar">
|
|
257
|
+
<strong className="text-[13px] font-medium">{t('sandbox.chat.selected', { count: selection.messageIds.length })}</strong>
|
|
258
|
+
<div className="flex gap-2">
|
|
259
|
+
<Button variant="outline" onClick={() => setSelection(exitMessageSelection())}>{t('sandbox.common.cancel')}</Button>
|
|
260
|
+
<Button disabled={!selection.messageIds.length} onClick={() => setForwardTargetOpen(true)}><Share2Icon />{t('sandbox.forward.send')}</Button>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
)}
|
|
264
|
+
</div>
|
|
265
|
+
</>
|
|
266
|
+
) : (
|
|
267
|
+
<div className="flex flex-1 items-center justify-center text-sm text-muted-foreground">{t('sandbox.chat.pick')}</div>
|
|
268
|
+
)}
|
|
269
|
+
<EmojiPicker
|
|
270
|
+
open={!!reactionTarget}
|
|
271
|
+
onOpenChange={(open) => !open && setReactionTarget('')}
|
|
272
|
+
onSelect={(emojiId) => {
|
|
273
|
+
if (conversation && reactionTarget) void run(t('sandbox.error.react'), () => store.setMessageReaction({ conversationId: conversation.id, messageId: reactionTarget, emojiId, enabled: true }))
|
|
274
|
+
}}
|
|
275
|
+
/>
|
|
276
|
+
<ForwardTargetDialog
|
|
277
|
+
open={forwardTargetOpen}
|
|
278
|
+
targets={forwardTargets}
|
|
279
|
+
onOpenChange={setForwardTargetOpen}
|
|
280
|
+
onConfirm={async (targetId) => {
|
|
281
|
+
const confirmation = resolveForwardConfirmation(selection, targetId, selectionContext)
|
|
282
|
+
if (confirmation.kind === 'reject') throw new Error(t('sandbox.forward.noSelectable'))
|
|
283
|
+
await store.sendForwardMessage({ conversationId: targetId, messageIds: [...confirmation.messageIds] })
|
|
284
|
+
setSelection(exitMessageSelection())
|
|
285
|
+
}}
|
|
286
|
+
/>
|
|
287
|
+
<ForwardViewer
|
|
288
|
+
stack={forwardStack}
|
|
289
|
+
imageOpen={!!imageUrl}
|
|
290
|
+
onCloseFrom={(depth) => setForwardStack((stack) => depth ? stack.slice(0, depth) : closeForwardStack())}
|
|
291
|
+
onOpenForward={(forwardId) => void openForward({ forwardId }, 'push')}
|
|
292
|
+
onOpenImage={setImageUrl}
|
|
293
|
+
/>
|
|
294
|
+
{imageUrl && <ImagePreview url={imageUrl} onClose={() => setImageUrl('')} />}
|
|
295
|
+
</main>
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function visibleConversation(store: ReturnType<typeof useSandbox>['store'], conversationId: string | undefined) {
|
|
300
|
+
const snapshot = store.snapshot
|
|
301
|
+
if (!snapshot || !conversationId) return undefined
|
|
302
|
+
return [...snapshot.conversations, ...(snapshot.conversationInstances ?? [])].find(({ id }) => id === conversationId)
|
|
303
|
+
}
|