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.
Files changed (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -0
  3. package/client/app.tsx +306 -0
  4. package/client/chat/chat-pane.tsx +303 -0
  5. package/client/chat/composer.css +635 -0
  6. package/client/chat/composer.tsx +646 -0
  7. package/client/chat/details-panel.tsx +196 -0
  8. package/client/chat/emoji-picker.tsx +70 -0
  9. package/client/chat/extension-mark.tsx +16 -0
  10. package/client/chat/forward.tsx +257 -0
  11. package/client/chat/image-preview.tsx +93 -0
  12. package/client/chat/member-menu.tsx +64 -0
  13. package/client/chat/message-list.tsx +617 -0
  14. package/client/chat/messages.css +1018 -0
  15. package/client/chat/notifications.tsx +83 -0
  16. package/client/chat/reactions.tsx +52 -0
  17. package/client/chat/search-panel.tsx +231 -0
  18. package/client/chat/sidebar.tsx +424 -0
  19. package/client/chat/webqq-view.tsx +71 -0
  20. package/client/environment/avatar-picker.tsx +92 -0
  21. package/client/environment/create-popover.tsx +228 -0
  22. package/client/environment/directory-model.ts +63 -0
  23. package/client/environment/entity-dialog.css +383 -0
  24. package/client/environment/entity-dialog.tsx +442 -0
  25. package/client/environment/page.css +14 -0
  26. package/client/environment/page.tsx +280 -0
  27. package/client/i18n.ts +19 -0
  28. package/client/index.ts +17 -0
  29. package/client/locales/en.yml +617 -0
  30. package/client/locales/zh.yml +617 -0
  31. package/client/mcp/capability-catalog.tsx +277 -0
  32. package/client/mcp/credential-manager.tsx +257 -0
  33. package/client/onebot-debug/page.tsx +329 -0
  34. package/client/records/record-layout.tsx +429 -0
  35. package/client/records/records.css +259 -0
  36. package/client/settings/about.tsx +43 -0
  37. package/client/settings/draft.ts +47 -0
  38. package/client/settings/localize.ts +76 -0
  39. package/client/settings/page.tsx +210 -0
  40. package/client/settings/settings.css +47 -0
  41. package/client/shared/avatar.tsx +35 -0
  42. package/client/shared/confirm-dialog.tsx +44 -0
  43. package/client/shared/controls.css +17 -0
  44. package/client/shared/discard-confirm.tsx +45 -0
  45. package/client/shared/floating-panel.ts +40 -0
  46. package/client/shared/format-duration.ts +22 -0
  47. package/client/shared/format-time.ts +49 -0
  48. package/client/shared/glass.css +150 -0
  49. package/client/shared/implementation.ts +12 -0
  50. package/client/shared/overlay-scrollbar.css +45 -0
  51. package/client/shared/overlay-scrollbar.tsx +123 -0
  52. package/client/shared/use-element-width.ts +19 -0
  53. package/client/shared/use-retained.ts +12 -0
  54. package/client/test-call/page.tsx +260 -0
  55. package/client/test-space/agent-visuals.tsx +121 -0
  56. package/client/test-space/observe-overlay.tsx +42 -0
  57. package/client/test-space/overview.tsx +267 -0
  58. package/client/test-space/spaces.css +201 -0
  59. package/client/test-space/thumbnail-capture.ts +63 -0
  60. package/client/test-space/thumbnail-scale.ts +21 -0
  61. package/client/test-space/use-space-list.ts +35 -0
  62. package/client/test-space/zoom.ts +197 -0
  63. package/client/webqq/composer-draft-host.ts +578 -0
  64. package/client/webqq/composer-draft.ts +81 -0
  65. package/client/webqq/conversation-tree.ts +155 -0
  66. package/client/webqq/emoji-catalog.ts +78 -0
  67. package/client/webqq/fork-boundary.ts +28 -0
  68. package/client/webqq/forward-cluster.ts +20 -0
  69. package/client/webqq/forward-dialog-stack.ts +74 -0
  70. package/client/webqq/forward-preview.ts +40 -0
  71. package/client/webqq/friend-menu.ts +17 -0
  72. package/client/webqq/group-display.ts +18 -0
  73. package/client/webqq/group-menu.ts +25 -0
  74. package/client/webqq/mention.ts +4 -0
  75. package/client/webqq/message-capabilities.ts +37 -0
  76. package/client/webqq/message-cluster.ts +68 -0
  77. package/client/webqq/message-presentation.ts +197 -0
  78. package/client/webqq/message-reveal.ts +31 -0
  79. package/client/webqq/message-search-date.ts +40 -0
  80. package/client/webqq/message-selection.ts +85 -0
  81. package/client/webqq/notification-requests.ts +20 -0
  82. package/client/webqq/participant-presentation.ts +128 -0
  83. package/client/webqq/profile-card.ts +199 -0
  84. package/client/webqq/relationship-directory.ts +62 -0
  85. package/client/webqq/thinking-panel.ts +7 -0
  86. package/client/webqq/user-stack.ts +53 -0
  87. package/client/workspace/agent-overlay-effect.ts +238 -0
  88. package/client/workspace/context.tsx +117 -0
  89. package/client/workspace/overlay-host.tsx +299 -0
  90. package/client/workspace/profile-card.css +164 -0
  91. package/client/workspace/state.ts +28 -0
  92. package/client/workspace/store.ts +388 -0
  93. package/client/workspace/use-test-spaces.ts +21 -0
  94. package/dist/.vite/manifest.json +21 -0
  95. package/dist/app-63rfTh6w.js +85 -0
  96. package/dist/client.css +4 -0
  97. package/dist/client.js +1 -0
  98. package/lib/account-profile.d.ts +17 -0
  99. package/lib/account-profile.d.ts.map +1 -0
  100. package/lib/base-dir.d.ts +4 -0
  101. package/lib/base-dir.d.ts.map +1 -0
  102. package/lib/bot.d.ts +185 -0
  103. package/lib/bot.d.ts.map +1 -0
  104. package/lib/builtin-avatar-options.d.ts +11 -0
  105. package/lib/builtin-avatar-options.d.ts.map +1 -0
  106. package/lib/builtin-avatars.d.ts +6 -0
  107. package/lib/builtin-avatars.d.ts.map +1 -0
  108. package/lib/channel-assignee.d.ts +52 -0
  109. package/lib/channel-assignee.d.ts.map +1 -0
  110. package/lib/chatluna/conversation-lines.d.ts +46 -0
  111. package/lib/chatluna/conversation-lines.d.ts.map +1 -0
  112. package/lib/chatluna/runtime.d.ts +26 -0
  113. package/lib/chatluna/runtime.d.ts.map +1 -0
  114. package/lib/chatluna/state.d.ts +67 -0
  115. package/lib/chatluna/state.d.ts.map +1 -0
  116. package/lib/chatluna/thinking.d.ts +10 -0
  117. package/lib/chatluna/thinking.d.ts.map +1 -0
  118. package/lib/chatluna/tools.d.ts +36 -0
  119. package/lib/chatluna/tools.d.ts.map +1 -0
  120. package/lib/chatluna/wakeup.d.ts +143 -0
  121. package/lib/chatluna/wakeup.d.ts.map +1 -0
  122. package/lib/console-contract.d.ts +131 -0
  123. package/lib/console-contract.d.ts.map +1 -0
  124. package/lib/console.d.ts +31 -0
  125. package/lib/console.d.ts.map +1 -0
  126. package/lib/control-service.d.ts +425 -0
  127. package/lib/control-service.d.ts.map +1 -0
  128. package/lib/conversation-resolution.d.ts +157 -0
  129. package/lib/conversation-resolution.d.ts.map +1 -0
  130. package/lib/error-detail.d.ts +3 -0
  131. package/lib/error-detail.d.ts.map +1 -0
  132. package/lib/inbound-delivery.d.ts +156 -0
  133. package/lib/inbound-delivery.d.ts.map +1 -0
  134. package/lib/index.d.ts +76 -0
  135. package/lib/index.d.ts.map +1 -0
  136. package/lib/index.js +12834 -0
  137. package/lib/index.js.map +1 -0
  138. package/lib/lifecycle.d.ts +8 -0
  139. package/lib/lifecycle.d.ts.map +1 -0
  140. package/lib/mcp/arguments.d.ts +71 -0
  141. package/lib/mcp/arguments.d.ts.map +1 -0
  142. package/lib/mcp/call-records.d.ts +32 -0
  143. package/lib/mcp/call-records.d.ts.map +1 -0
  144. package/lib/mcp/http-api.d.ts +147 -0
  145. package/lib/mcp/http-api.d.ts.map +1 -0
  146. package/lib/mcp/page-cursor.d.ts +37 -0
  147. package/lib/mcp/page-cursor.d.ts.map +1 -0
  148. package/lib/mcp/server.d.ts +60 -0
  149. package/lib/mcp/server.d.ts.map +1 -0
  150. package/lib/mcp/service.d.ts +219 -0
  151. package/lib/mcp/service.d.ts.map +1 -0
  152. package/lib/mcp/tool-registry.d.ts +113 -0
  153. package/lib/mcp/tool-registry.d.ts.map +1 -0
  154. package/lib/mcp/types.d.ts +144 -0
  155. package/lib/mcp/types.d.ts.map +1 -0
  156. package/lib/media-storage.d.ts +33 -0
  157. package/lib/media-storage.d.ts.map +1 -0
  158. package/lib/message-capabilities.d.ts +78 -0
  159. package/lib/message-capabilities.d.ts.map +1 -0
  160. package/lib/onebot-debug.d.ts +115 -0
  161. package/lib/onebot-debug.d.ts.map +1 -0
  162. package/lib/onebot-message.d.ts +23 -0
  163. package/lib/onebot-message.d.ts.map +1 -0
  164. package/lib/onebot-profiles.d.ts +45 -0
  165. package/lib/onebot-profiles.d.ts.map +1 -0
  166. package/lib/persistence.d.ts +148 -0
  167. package/lib/persistence.d.ts.map +1 -0
  168. package/lib/random.d.ts +5 -0
  169. package/lib/random.d.ts.map +1 -0
  170. package/lib/record-store.d.ts +80 -0
  171. package/lib/record-store.d.ts.map +1 -0
  172. package/lib/relationship-actions.d.ts +157 -0
  173. package/lib/relationship-actions.d.ts.map +1 -0
  174. package/lib/scope-directory.d.ts +105 -0
  175. package/lib/scope-directory.d.ts.map +1 -0
  176. package/lib/settings.d.ts +33 -0
  177. package/lib/settings.d.ts.map +1 -0
  178. package/lib/test-spaces.d.ts +69 -0
  179. package/lib/test-spaces.d.ts.map +1 -0
  180. package/lib/types.d.ts +739 -0
  181. package/lib/types.d.ts.map +1 -0
  182. package/lib/webui.d.ts +26 -0
  183. package/lib/webui.d.ts.map +1 -0
  184. package/package.json +112 -0
@@ -0,0 +1,424 @@
1
+ import * as React from 'react'
2
+ import {
3
+ BellIcon,
4
+ ChevronDownIcon,
5
+ ClockIcon,
6
+ IdCardIcon,
7
+ MessageCircleIcon,
8
+ PencilIcon,
9
+ PlusIcon,
10
+ SearchIcon,
11
+ TagIcon,
12
+ Trash2Icon,
13
+ UserIcon,
14
+ UserMinusIcon,
15
+ UserPlusIcon,
16
+ UsersIcon,
17
+ } from 'lucide-react'
18
+ import {
19
+ Badge,
20
+ Button,
21
+ cn,
22
+ ContextMenu,
23
+ ContextMenuContent,
24
+ ContextMenuItem,
25
+ ContextMenuSeparator,
26
+ ContextMenuTrigger,
27
+ Input,
28
+ Popover,
29
+ PopoverContent,
30
+ PopoverTrigger,
31
+ ScrollArea,
32
+ Tabs,
33
+ TabsList,
34
+ TabsTrigger,
35
+ } from '@chatluna/ui-kit'
36
+ import { getSandboxBots } from '../../src/types'
37
+ import { useT } from '../i18n'
38
+ import { SandboxAvatar } from '../shared/avatar'
39
+ import { CreateEntityPopover } from '../environment/create-popover'
40
+ import { buildConversationTree, type ConversationTreeNode, type ConversationTreeRow } from '../webqq/conversation-tree'
41
+ import { getIncomingNotificationRequests } from '../webqq/notification-requests'
42
+ import { getFriendDirectory, getGroupDirectory } from '../webqq/relationship-directory'
43
+ import { useSandbox, useWorkspace } from '../workspace/context'
44
+ import { ExtensionMark } from './extension-mark'
45
+ import { NotificationList } from './notifications'
46
+
47
+ type SidebarTab = 'recent' | 'friends' | 'groups'
48
+
49
+ export function ChatSidebar({ onSelectConversation, className }: {
50
+ onSelectConversation(conversationId: string): void
51
+ className?: string
52
+ }) {
53
+ const t = useT()
54
+ const { store, run, dialogs } = useSandbox()
55
+ const workspace = useWorkspace()
56
+ const { snapshot, operatorId, operator, conversation, group: currentGroup, resolveAvatar } = workspace
57
+ const [tab, setTab] = React.useState<SidebarTab>('recent')
58
+ const [query, setQuery] = React.useState('')
59
+ const [expanded, setExpanded] = React.useState<Record<string, boolean>>({})
60
+
61
+ const tree = React.useMemo(() => buildConversationTree({
62
+ scene: snapshot,
63
+ conversations: workspace.conversations,
64
+ operatorId,
65
+ resolveAvatar,
66
+ emptyPreview: t('sandbox.chat.emptyPreview'),
67
+ }), [snapshot, workspace.conversations, operatorId, resolveAvatar, t])
68
+ const notifications = getIncomingNotificationRequests(snapshot, operatorId)
69
+ const pending = notifications.friends.length + notifications.groups.length
70
+ const bots = getSandboxBots(snapshot)
71
+
72
+ // 选中会话实例时自动展开它所属的根会话,避免选中项藏在折叠里。
73
+ React.useEffect(() => {
74
+ if (conversation?.kind !== 'instance') return
75
+ setExpanded((value) => value[conversation.rootConversationId] ? value : { ...value, [conversation.rootConversationId]: true })
76
+ }, [conversation])
77
+
78
+ const needle = query.trim().toLowerCase()
79
+ const friends = tab === 'friends'
80
+ ? getFriendDirectory(snapshot, operatorId).filter(({ id, displayName }) => !needle || id.includes(needle) || displayName.toLowerCase().includes(needle))
81
+ : []
82
+ const groups = tab === 'groups'
83
+ ? getGroupDirectory(snapshot, operatorId).filter(({ id, name }) => !needle || id.includes(needle) || name.toLowerCase().includes(needle))
84
+ : []
85
+ const empty = tab === 'recent' ? !tree.length : tab === 'friends' ? !friends.length : !groups.length
86
+ // 新建的测试空间没有任何账号,也就没有发送框里的「添加测试账号」入口;会话栏顶部先给一个。
87
+ const noAccount = !operator && tab !== 'groups'
88
+
89
+ const friendAction = (label: string, input: Parameters<typeof store.performFriendAction>[0]) => run(label, () => store.performFriendAction(input))
90
+ const groupAction = (label: string, input: Parameters<typeof store.performGroupAction>[0]) => run(label, () => store.performGroupAction(input))
91
+
92
+ const tabs: Array<{ id: SidebarTab, icon: typeof ClockIcon }> = [
93
+ { id: 'recent', icon: ClockIcon },
94
+ { id: 'friends', icon: UserIcon },
95
+ { id: 'groups', icon: UsersIcon },
96
+ ]
97
+
98
+ return (
99
+ <aside className={cn('flex min-h-0 w-72 shrink-0 flex-col border-r border-border bg-sidebar/40', className)} aria-label={t('sandbox.sidebar.label')}>
100
+ <header className="flex items-center gap-1 px-3 pt-3 pb-2">
101
+ <Tabs
102
+ className="min-w-0 flex-1"
103
+ value={tab}
104
+ onValueChange={(value) => {
105
+ setTab(value as SidebarTab)
106
+ setQuery('')
107
+ }}
108
+ >
109
+ <TabsList className="w-full" aria-label={t('sandbox.sidebar.tabs')}>
110
+ {tabs.map(({ id, icon: Icon }) => (
111
+ <TabsTrigger key={id} value={id} className="gap-1 px-1.5 text-xs">
112
+ <Icon className="size-3.5" />
113
+ {t(`sandbox.sidebar.${id}`)}
114
+ </TabsTrigger>
115
+ ))}
116
+ </TabsList>
117
+ </Tabs>
118
+ <Popover>
119
+ <PopoverTrigger render={(
120
+ <Button variant="ghost" size="icon" className="relative" aria-label={pending ? t('sandbox.notice.labelCount', { count: pending }) : t('sandbox.notice.label')}>
121
+ <BellIcon />
122
+ {pending > 0 && <span className="absolute top-1 right-1 size-2 rounded-full bg-destructive" />}
123
+ </Button>
124
+ )} />
125
+ <PopoverContent align="end" className="sandbox-glass w-80 p-0">
126
+ <NotificationList requests={notifications} />
127
+ </PopoverContent>
128
+ </Popover>
129
+ </header>
130
+ {tab !== 'recent' && (
131
+ <div className="px-3 pb-2"><div className="relative">
132
+ <SearchIcon className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
133
+ <Input
134
+ type="search"
135
+ className="sandbox-search-input h-8 pl-8!"
136
+ value={query}
137
+ autoComplete="off"
138
+ aria-label={t('sandbox.sidebar.search')}
139
+ placeholder={t(tab === 'friends' ? 'sandbox.sidebar.searchFriends' : 'sandbox.sidebar.searchGroups')}
140
+ onChange={(event) => setQuery(event.target.value)}
141
+ />
142
+ </div></div>
143
+ )}
144
+ <ScrollArea className="min-h-0 flex-1">
145
+ <div className="flex flex-col gap-0.5 px-2 pb-3">
146
+ {noAccount && (
147
+ <CreateEntityPopover
148
+ type="participant"
149
+ trigger={(
150
+ <button type="button" className="flex items-center gap-3 rounded-lg px-2 py-2 text-left transition-colors hover:bg-accent">
151
+ <span className="flex size-9 items-center justify-center rounded-full border border-dashed border-border text-muted-foreground"><PlusIcon className="size-4" /></span>
152
+ <span className="flex min-w-0 flex-col">
153
+ <strong className="text-[13px] font-medium">{t('sandbox.create.participant')}</strong>
154
+ <small className="text-xs text-muted-foreground">{t('sandbox.sidebar.addAccountHint')}</small>
155
+ </span>
156
+ </button>
157
+ )}
158
+ />
159
+ )}
160
+ {tab === 'groups' && (
161
+ <CreateEntityPopover
162
+ type="group"
163
+ operator={operator}
164
+ bots={bots}
165
+ trigger={(
166
+ <button type="button" className="flex items-center gap-3 rounded-lg px-2 py-2 text-left transition-colors hover:bg-accent">
167
+ <span className="flex size-9 items-center justify-center rounded-full border border-dashed border-border text-muted-foreground"><PlusIcon className="size-4" /></span>
168
+ <span className="flex min-w-0 flex-col">
169
+ <strong className="text-[13px] font-medium">{t('sandbox.sidebar.addGroup')}</strong>
170
+ <small className="text-xs text-muted-foreground">{t('sandbox.sidebar.addGroupHint')}</small>
171
+ </span>
172
+ </button>
173
+ )}
174
+ />
175
+ )}
176
+ {tab === 'recent' && tree.map((node) => (
177
+ <ConversationNode
178
+ key={node.id}
179
+ node={node}
180
+ activeId={conversation?.id}
181
+ expanded={!!expanded[node.id]}
182
+ onToggle={() => setExpanded((value) => ({ ...value, [node.id]: !value[node.id] }))}
183
+ onSelect={onSelectConversation}
184
+ />
185
+ ))}
186
+ {friends.map((entry) => (
187
+ <ContextMenu key={entry.id}>
188
+ <ContextMenuTrigger render={(
189
+ <DirectoryRow
190
+ kind={entry.isBot ? 'bot' : 'user'}
191
+ title={entry.displayName}
192
+ subtitle={t(entry.statusKey, { name: entry.participantName })}
193
+ avatar={resolveAvatar(entry.avatar)}
194
+ active={!!entry.conversationId && entry.conversationId === conversation?.id}
195
+ status={t(entry.isFriend ? 'sandbox.sidebar.added' : entry.pendingOutgoing || entry.pendingIncoming ? 'sandbox.sidebar.pending' : 'sandbox.sidebar.notAdded')}
196
+ // 还没有私聊会话(非好友)时打开资料卡,加好友等操作在资料卡与右键菜单里。
197
+ onClick={(event) => entry.conversationId
198
+ ? onSelectConversation(entry.conversationId)
199
+ : dialogs.openProfile(entry.id, { x: event.clientX, y: event.clientY })}
200
+ />
201
+ )} />
202
+ <ContextMenuContent className="sandbox-glass">
203
+ <ContextMenuItem onClick={() => dialogs.openProfile(entry.id)}><IdCardIcon />{t('sandbox.menu.profile')}</ContextMenuItem>
204
+ {!entry.isFriend && !entry.pendingOutgoing && !entry.pendingIncoming && (
205
+ <ContextMenuItem onClick={() => friendAction(t('sandbox.error.friend'), { action: 'request', targetId: entry.id, comment: t('sandbox.friend.requestComment') })}>
206
+ <UserPlusIcon />{t('sandbox.menu.requestFriend')}<ExtensionMark />
207
+ </ContextMenuItem>
208
+ )}
209
+ {entry.pendingOutgoing && <ContextMenuItem disabled><ClockIcon />{t('sandbox.menu.waitingPeer')}</ContextMenuItem>}
210
+ {entry.pendingIncoming && <ContextMenuItem disabled><BellIcon />{t('sandbox.menu.handleInNotice')}</ContextMenuItem>}
211
+ {entry.isFriend && (
212
+ <>
213
+ <ContextMenuItem onClick={() => dialogs.openRemark(entry.id)}><TagIcon />{t('sandbox.menu.remark')}<ExtensionMark /></ContextMenuItem>
214
+ <ContextMenuItem variant="destructive" onClick={() => friendAction(t('sandbox.error.friend'), { action: 'delete', targetId: entry.id })}>
215
+ <UserMinusIcon />{t('sandbox.menu.deleteFriend')}
216
+ </ContextMenuItem>
217
+ </>
218
+ )}
219
+ {/* 与服务端一致,只能邀请好友入群。 */}
220
+ {entry.isFriend && currentGroup && !currentGroup.members.some(({ participantId }) => participantId === entry.id) && (
221
+ <ContextMenuItem onClick={() => groupAction(t('sandbox.error.group'), { action: 'invite', groupId: currentGroup.id, targetId: entry.id })}>
222
+ <UserPlusIcon />{t('sandbox.menu.inviteToGroup')}<ExtensionMark />
223
+ </ContextMenuItem>
224
+ )}
225
+ <ContextMenuSeparator />
226
+ <EntityMenuItems target={{ type: entry.isBot ? 'bot' : 'user', id: entry.id }} />
227
+ </ContextMenuContent>
228
+ </ContextMenu>
229
+ ))}
230
+ {groups.map((entry) => (
231
+ <ContextMenu key={entry.id}>
232
+ <ContextMenuTrigger render={(
233
+ <DirectoryRow
234
+ kind="group"
235
+ title={entry.name}
236
+ subtitle={t('sandbox.chat.groupSubtitle', { id: entry.id, count: entry.members.length })}
237
+ avatar={resolveAvatar(entry.avatar)}
238
+ active={!!entry.conversationId && entry.conversationId === conversation?.id}
239
+ status={t(entry.member ? 'sandbox.sidebar.joined' : entry.pending ? 'sandbox.sidebar.pending' : 'sandbox.sidebar.notJoined')}
240
+ onClick={() => entry.conversationId && onSelectConversation(entry.conversationId)}
241
+ />
242
+ )} />
243
+ <ContextMenuContent className="sandbox-glass">
244
+ {!entry.member && !entry.pending && (
245
+ <ContextMenuItem onClick={() => groupAction(t('sandbox.error.group'), { action: 'request-join', groupId: entry.id, comment: t('sandbox.group.requestComment') })}>
246
+ <UserPlusIcon />{t('sandbox.menu.requestJoin')}<ExtensionMark />
247
+ </ContextMenuItem>
248
+ )}
249
+ {!entry.member && entry.pending && <ContextMenuItem disabled><ClockIcon />{t('sandbox.menu.waitingAdmin')}</ContextMenuItem>}
250
+ {entry.member && <GroupRootItems groupId={entry.id} role={entry.member.role} />}
251
+ <ContextMenuSeparator />
252
+ <EntityMenuItems target={{ type: 'group', id: entry.id }} />
253
+ </ContextMenuContent>
254
+ </ContextMenu>
255
+ ))}
256
+ {empty && (
257
+ <p className="px-3 py-8 text-center text-xs text-muted-foreground">
258
+ {t(needle ? 'sandbox.sidebar.empty' : `sandbox.sidebar.none.${tab}`)}
259
+ </p>
260
+ )}
261
+ </div>
262
+ </ScrollArea>
263
+ </aside>
264
+ )
265
+ }
266
+
267
+ const DirectoryRow = React.forwardRef<HTMLButtonElement, React.ComponentProps<'button'> & {
268
+ kind: 'user' | 'bot' | 'group'
269
+ title: string
270
+ subtitle: string
271
+ avatar?: string
272
+ status?: string
273
+ time?: string
274
+ active?: boolean
275
+ }>(function DirectoryRow({ kind, title, subtitle, avatar, status, time, active, className, ...props }, ref) {
276
+ return (
277
+ <button
278
+ ref={ref}
279
+ type="button"
280
+ className={cn(
281
+ 'flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition-colors hover:bg-accent',
282
+ active && 'bg-accent',
283
+ className,
284
+ )}
285
+ aria-current={active || undefined}
286
+ {...props}
287
+ >
288
+ <SandboxAvatar kind={kind} name={title} src={avatar} />
289
+ <span className="flex min-w-0 flex-1 flex-col gap-0.5">
290
+ <span className="flex items-center gap-2">
291
+ <strong className="truncate text-[13px] font-medium">{title}</strong>
292
+ {time && <time className="ml-auto shrink-0 text-[11px] text-muted-foreground">{time}</time>}
293
+ </span>
294
+ <small className="truncate text-xs text-muted-foreground">{subtitle}</small>
295
+ </span>
296
+ {status && <Badge variant="outline" className="shrink-0 text-[10px] text-muted-foreground">{status}</Badge>}
297
+ </button>
298
+ )
299
+ })
300
+
301
+ function ConversationNode({ node, activeId, expanded, onToggle, onSelect }: {
302
+ node: ConversationTreeNode
303
+ activeId?: string
304
+ expanded: boolean
305
+ onToggle(): void
306
+ onSelect(id: string): void
307
+ }) {
308
+ const t = useT()
309
+ const { store, run, dialogs } = useSandbox()
310
+ const count = node.children.length
311
+ return (
312
+ <div className="flex flex-col">
313
+ <ContextMenu>
314
+ <ContextMenuTrigger render={(
315
+ <div className="group relative">
316
+ <DirectoryRow
317
+ kind={node.avatarKind}
318
+ title={node.title}
319
+ subtitle={node.preview}
320
+ avatar={node.avatar}
321
+ time={node.time}
322
+ active={node.id === activeId}
323
+ className={count ? 'pr-12!' : undefined}
324
+ onClick={() => onSelect(node.id)}
325
+ />
326
+ {count > 0 && (
327
+ <button
328
+ type="button"
329
+ className="absolute top-1/2 right-2 flex h-6 -translate-y-1/2 items-center gap-0.5 rounded-md px-1.5 text-[11px] text-muted-foreground hover:bg-background hover:text-foreground"
330
+ aria-expanded={expanded}
331
+ aria-label={t(expanded ? 'sandbox.sidebar.collapse' : 'sandbox.sidebar.expand', { count })}
332
+ onClick={(event) => {
333
+ event.stopPropagation()
334
+ onToggle()
335
+ }}
336
+ >
337
+ {count}
338
+ <ChevronDownIcon className={cn('size-3.5 transition-transform duration-200 ease-spring', expanded && 'rotate-180')} />
339
+ </button>
340
+ )}
341
+ </div>
342
+ )} />
343
+ <ContextMenuContent className="sandbox-glass">
344
+ {node.groupId && <GroupRootItems groupId={node.groupId} role={node.actorRole} />}
345
+ <ContextMenuItem onClick={() => run(t('sandbox.error.createConversation'), () => store.createConversationInstance(node.id))}>
346
+ <PlusIcon />{t('sandbox.menu.newConversation')}
347
+ </ContextMenuItem>
348
+ <ContextMenuSeparator />
349
+ <EntityMenuItems target={node.entityTarget} />
350
+ </ContextMenuContent>
351
+ </ContextMenu>
352
+ {expanded && (
353
+ <div className="ml-6 flex flex-col gap-0.5 border-l border-border pl-2">
354
+ {node.children.map((child) => (
355
+ <ContextMenu key={child.id}>
356
+ <ContextMenuTrigger render={<InstanceRow row={child} active={child.id === activeId} onClick={() => onSelect(child.id)} />} />
357
+ <ContextMenuContent className="sandbox-glass">
358
+ <ContextMenuItem onClick={() => dialogs.openConversationRename(child.id)}><PencilIcon />{t('sandbox.menu.renameConversation')}</ContextMenuItem>
359
+ <ContextMenuItem variant="destructive" onClick={() => run(t('sandbox.error.deleteConversation'), () => store.deleteConversationInstance(child.id))}>
360
+ <Trash2Icon />{t('sandbox.menu.deleteConversation')}
361
+ </ContextMenuItem>
362
+ </ContextMenuContent>
363
+ </ContextMenu>
364
+ ))}
365
+ </div>
366
+ )}
367
+ </div>
368
+ )
369
+ }
370
+
371
+ const InstanceRow = React.forwardRef<HTMLButtonElement, React.ComponentProps<'button'> & { row: ConversationTreeRow, active: boolean }>(
372
+ function InstanceRow({ row, active, className, ...props }, ref) {
373
+ return (
374
+ <button
375
+ ref={ref}
376
+ type="button"
377
+ className={cn('flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-accent', active && 'bg-accent', className)}
378
+ aria-current={active || undefined}
379
+ {...props}
380
+ >
381
+ <MessageCircleIcon className="size-3.5 shrink-0 text-muted-foreground" />
382
+ <span className="flex min-w-0 flex-1 flex-col">
383
+ <span className="flex items-center gap-2">
384
+ <strong className="truncate text-xs font-medium">{row.title}</strong>
385
+ {row.time && <time className="ml-auto shrink-0 text-[11px] text-muted-foreground">{row.time}</time>}
386
+ </span>
387
+ <small className="truncate text-[11px] text-muted-foreground">{row.preview}</small>
388
+ </span>
389
+ </button>
390
+ )
391
+ },
392
+ )
393
+
394
+ /** 已加入群组的根会话菜单:改群名需要管理员,群主不能直接退群。 */
395
+ function GroupRootItems({ groupId, role }: { groupId: string, role?: 'owner' | 'admin' | 'member' }) {
396
+ const t = useT()
397
+ const { store, run, dialogs } = useSandbox()
398
+ return (
399
+ <>
400
+ <ContextMenuItem disabled={role === 'member'} onClick={() => dialogs.openGroupAction('name', '', groupId)}>
401
+ <PencilIcon />{t(role === 'member' ? 'sandbox.menu.renameGroupNeedAdmin' : 'sandbox.menu.renameGroup')}
402
+ </ContextMenuItem>
403
+ <ContextMenuItem
404
+ disabled={role === 'owner'}
405
+ variant="destructive"
406
+ onClick={() => run(t('sandbox.error.group'), () => store.performGroupAction({ action: 'leave', groupId }))}
407
+ >
408
+ <UserMinusIcon />{t(role === 'owner' ? 'sandbox.menu.ownerCannotLeave' : 'sandbox.menu.leaveGroup')}
409
+ </ContextMenuItem>
410
+ </>
411
+ )
412
+ }
413
+
414
+ export function EntityMenuItems({ target }: { target: { type: 'user' | 'bot' | 'group', id: string } }) {
415
+ const t = useT()
416
+ const { dialogs } = useSandbox()
417
+ const kind = t(`sandbox.kind.${target.type}`)
418
+ return (
419
+ <>
420
+ <ContextMenuItem onClick={() => dialogs.openEntity('edit', target)}><PencilIcon />{t('sandbox.menu.editEntity', { kind })}<ExtensionMark /></ContextMenuItem>
421
+ <ContextMenuItem variant="destructive" onClick={() => dialogs.openEntity('delete', target)}><Trash2Icon />{t('sandbox.menu.deleteEntity', { kind })}<ExtensionMark /></ContextMenuItem>
422
+ </>
423
+ )
424
+ }
@@ -0,0 +1,71 @@
1
+ import * as React from 'react'
2
+ import { cn } from '@chatluna/ui-kit'
3
+ import { useElementWidth } from '../shared/use-element-width'
4
+ import { useSandbox, useWorkspace } from '../workspace/context'
5
+ import { ChatPane } from './chat-pane'
6
+ import { DetailsPanel } from './details-panel'
7
+ import { ChatSidebar } from './sidebar'
8
+
9
+ type Region = 'contacts' | 'chat' | 'details'
10
+
11
+ /** 会话列表与信息栏各 288px(w-72)。 */
12
+ const COLUMN_WIDTH = 288
13
+ /** 信息栏自动展开时聊天区至少保留的宽度:发送框 460px 两侧各留 48px 才能完整居中。 */
14
+ const CHAT_MIN_WIDTH = 556
15
+ /** 窄于此宽度时三个区域互斥显示。 */
16
+ const NARROW_WIDTH = 640
17
+
18
+ /**
19
+ * WebQQ 三栏:会话列表、聊天区与群聊信息栏(私聊没有信息栏)。按沙盒自身宽度而不是视口宽度分档(左侧还有 v2 外壳侧栏):
20
+ * 三栏都放下且聊天区不窄于 {@link CHAT_MIN_WIDTH} 时默认展开信息栏;窄于 {@link NARROW_WIDTH} 时三个区域
21
+ * 互斥显示,聊天区提供返回会话列表的入口。
22
+ */
23
+ export function WebqqView() {
24
+ const { store } = useSandbox()
25
+ const { workspace, group } = useWorkspace()
26
+ const [root, width] = useElementWidth<HTMLDivElement>()
27
+ const wide = width >= COLUMN_WIDTH * 2 + CHAT_MIN_WIDTH
28
+ const narrow = width > 0 && width < NARROW_WIDTH
29
+ const [detailsPreference, setDetailsPreference] = React.useState<'auto' | 'open' | 'closed'>('auto')
30
+ const [selectedRegion, setRegion] = React.useState<Region>('chat')
31
+ // 信息栏只有群聊有(群公告与成员);切到私聊时窄屏落回聊天区,宽屏不渲染第三栏。
32
+ const region = selectedRegion === 'details' && !group ? 'chat' : selectedRegion
33
+ const detailsVisible = Boolean(group) && (detailsPreference === 'auto' ? wide : detailsPreference === 'open')
34
+
35
+ // 跨过宽窄断点时回到该宽度下的默认展开态。
36
+ React.useEffect(() => setDetailsPreference('auto'), [wide])
37
+
38
+ const toggleDetails = () => {
39
+ if (narrow) return setRegion((value) => value === 'details' ? 'chat' : 'details')
40
+ setDetailsPreference(detailsVisible ? 'closed' : 'open')
41
+ }
42
+ const mention = React.useRef<(participantId: string) => void>(() => {})
43
+
44
+ return (
45
+ // 强调色由插件设置决定,消息气泡与发送框(`messages.css`、`composer.css`)都从这里继承。
46
+ // min-w-0 不能省:否则最小内容宽度(会话栏 + 聊天区)把根节点撑出容器,测得的宽度永远进不了窄屏档。
47
+ <div ref={root} className="sandbox-webqq flex min-h-0 min-w-0 flex-1 border-t border-border" style={{ '--sandbox-accent': workspace.appearance.sandboxAccentColor } as React.CSSProperties}>
48
+ <ChatSidebar
49
+ className={cn(narrow && region !== 'contacts' && 'hidden', narrow && 'w-full')}
50
+ onSelectConversation={(conversationId) => {
51
+ store.selectConversation(conversationId)
52
+ if (narrow) setRegion('chat')
53
+ }}
54
+ />
55
+ <ChatPane
56
+ className={cn(narrow && region !== 'chat' && 'hidden', !narrow && !wide && detailsVisible && 'hidden')}
57
+ detailsVisible={narrow ? region === 'details' : detailsVisible}
58
+ onToggleDetails={group ? toggleDetails : undefined}
59
+ onBack={narrow ? () => setRegion('contacts') : undefined}
60
+ mentionBridge={mention}
61
+ />
62
+ {(narrow ? region === 'details' : detailsVisible) && (
63
+ <DetailsPanel
64
+ className={cn(narrow && 'w-full border-l-0', !narrow && !wide && 'flex-1')}
65
+ onClose={narrow ? () => setRegion('chat') : () => setDetailsPreference('closed')}
66
+ onMention={(participantId) => mention.current(participantId)}
67
+ />
68
+ )}
69
+ </div>
70
+ )
71
+ }
@@ -0,0 +1,92 @@
1
+ import * as React from 'react'
2
+ import { ArrowLeftIcon, ChevronRightIcon, UploadIcon } from 'lucide-react'
3
+ import { Button } from '@chatluna/ui-kit'
4
+ import { BUILTIN_AVATARS, type BuiltinAvatar, type BuiltinAvatarKind } from '../../src/builtin-avatar-options'
5
+ import { useT } from '../i18n'
6
+
7
+ function avatarDataUrl(avatar: BuiltinAvatar) {
8
+ const bytes = new TextEncoder().encode(avatar.svg)
9
+ let binary = ''
10
+ for (const byte of bytes) binary += String.fromCharCode(byte)
11
+ return `data:image/svg+xml;base64,${btoa(binary)}`
12
+ }
13
+
14
+ /** 头像选择:内置头像或本地图片,选定后以 Data URL 交回,服务端负责导入成受控媒体。用于浮层内原地切换的二级视图。 */
15
+ export function AvatarPicker({ kind, onBack, onSelect }: {
16
+ kind: BuiltinAvatarKind
17
+ onBack(): void
18
+ onSelect(avatar: string): void
19
+ }) {
20
+ const t = useT()
21
+ return (
22
+ <section className="flex flex-col gap-4" aria-label={t('sandbox.avatar.title')}>
23
+ <header className="flex items-start gap-2">
24
+ <Button type="button" variant="ghost" size="icon-sm" aria-label={t('sandbox.avatar.back')} onClick={onBack}>
25
+ <ArrowLeftIcon />
26
+ </Button>
27
+ <div className="flex flex-col gap-1">
28
+ <strong className="text-sm font-medium">{t('sandbox.avatar.title')}</strong>
29
+ <p className="text-xs text-muted-foreground">{t('sandbox.avatar.description')}</p>
30
+ </div>
31
+ </header>
32
+ <AvatarChoices kind={kind} onSelect={onSelect} />
33
+ </section>
34
+ )
35
+ }
36
+
37
+ /** 头像候选:内置头像网格与本地上传入口。弹窗里作为二级窗口的正文,标题与关闭按钮由弹窗提供。 */
38
+ export function AvatarChoices({ kind, onSelect }: {
39
+ kind: BuiltinAvatarKind
40
+ onSelect(avatar: string): void
41
+ }) {
42
+ const t = useT()
43
+ const [error, setError] = React.useState('')
44
+ const fileInput = React.useRef<HTMLInputElement>(null)
45
+
46
+ const readLocal = (event: React.ChangeEvent<HTMLInputElement>) => {
47
+ const file = event.target.files?.[0]
48
+ event.target.value = ''
49
+ if (!file) return
50
+ if (!file.type.startsWith('image/')) return setError(t('sandbox.avatar.notImage'))
51
+ const reader = new FileReader()
52
+ reader.addEventListener('load', () => {
53
+ if (typeof reader.result !== 'string') return
54
+ setError('')
55
+ onSelect(reader.result)
56
+ })
57
+ reader.addEventListener('error', () => setError(t('sandbox.avatar.readFailed')))
58
+ reader.readAsDataURL(file)
59
+ }
60
+
61
+ return (
62
+ <div className="flex flex-col gap-4">
63
+ <div className="grid grid-cols-4 gap-2">
64
+ {BUILTIN_AVATARS[kind].map((avatar) => (
65
+ <button
66
+ key={avatar.id}
67
+ type="button"
68
+ className="aspect-square overflow-hidden rounded-full ring-1 ring-border transition-transform duration-150 ease-spring hover:scale-105 focus-visible:outline-2 focus-visible:outline-ring"
69
+ aria-label={t('sandbox.avatar.builtin', { id: avatar.id })}
70
+ onClick={() => onSelect(avatarDataUrl(avatar))}
71
+ >
72
+ <img src={avatarDataUrl(avatar)} alt="" className="size-full" />
73
+ </button>
74
+ ))}
75
+ </div>
76
+ <input ref={fileInput} type="file" className="hidden" accept="image/png,image/jpeg,image/webp,image/gif,image/svg+xml" onChange={readLocal} />
77
+ <button
78
+ type="button"
79
+ className="flex items-center gap-3 rounded-lg border border-border px-3 py-2 text-left transition-colors hover:bg-accent"
80
+ onClick={() => fileInput.current?.click()}
81
+ >
82
+ <span className="flex size-8 items-center justify-center rounded-md bg-muted"><UploadIcon className="size-4" /></span>
83
+ <span className="flex min-w-0 flex-1 flex-col">
84
+ <strong className="text-[13px] font-medium">{t('sandbox.avatar.upload')}</strong>
85
+ <small className="text-xs text-muted-foreground">{t('sandbox.avatar.uploadHint')}</small>
86
+ </span>
87
+ <ChevronRightIcon className="size-4 text-muted-foreground" />
88
+ </button>
89
+ {error && <p role="alert" className="text-xs text-destructive">{error}</p>}
90
+ </div>
91
+ )
92
+ }