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,299 @@
1
+ import * as React from 'react'
2
+ import { createPortal } from 'react-dom'
3
+ import { CheckIcon, CopyIcon, XIcon } from 'lucide-react'
4
+ import {
5
+ Button,
6
+ Dialog,
7
+ DialogContent,
8
+ DialogDescription,
9
+ DialogFooter,
10
+ DialogHeader,
11
+ DialogTitle,
12
+ Input,
13
+ } from '@chatluna/ui-kit'
14
+ import { toast } from '@chatluna/ui-client/client'
15
+ import { useT } from '../i18n'
16
+ import { EntityDialog, type EntityDialogTarget } from '../environment/entity-dialog'
17
+ import { SandboxAvatar } from '../shared/avatar'
18
+ import { useDiscardConfirm } from '../shared/discard-confirm'
19
+ import { useRetained } from '../shared/use-retained'
20
+ import { OverlayScrollbar } from '../shared/overlay-scrollbar'
21
+ import { clampFloatingPanelPosition, getFloatingPanelPosition, isFloatingPanelInteractiveTarget } from '../shared/floating-panel'
22
+ import { buildGroupProfileCardModel, buildProfileCardModel, groupProfileCardFields, type ProfileCardModel } from '../webqq/profile-card'
23
+ import type { SandboxDialogs } from './context'
24
+ import './profile-card.css'
25
+ import { errorText, type WorkspaceStore } from './store'
26
+ import { useSandbox, useWorkspace } from './context'
27
+
28
+ type TextDialog =
29
+ | { kind: 'remark', targetId: string, value: string }
30
+ | { kind: 'card' | 'name' | 'title', targetId: string, groupId: string, value: string }
31
+ | { kind: 'rename', conversationId: string, value: string }
32
+
33
+ export interface OverlayState {
34
+ entity?: { mode: 'edit' | 'delete', target: EntityDialogTarget }
35
+ text?: TextDialog
36
+ profile?: { card: ProfileCardModel, x: number, y: number }
37
+ }
38
+
39
+ /** 二级面的打开意图:工作区把它们收成一份状态,由 {@link OverlayHost} 统一渲染。 */
40
+ export function useOverlayState(store: WorkspaceStore) {
41
+ const t = useT()
42
+ const [state, setState] = React.useState<OverlayState>({})
43
+ const dialogs = React.useMemo<SandboxDialogs>(() => {
44
+ const anchorOf = (anchor?: { x: number, y: number }) => anchor ?? { x: window.innerWidth / 2 - 160, y: window.innerHeight / 3 }
45
+ return {
46
+ openEntity: (mode, target) => setState((value) => ({ ...value, entity: { mode, target } })),
47
+ openRemark: (targetId) => {
48
+ const snapshot = store.snapshot
49
+ const operatorId = store.getView().currentOperatorId ?? ''
50
+ const friendship = snapshot?.friendships.find(({ participantIds }) => participantIds.includes(operatorId) && participantIds.includes(targetId))
51
+ setState((value) => ({ ...value, text: { kind: 'remark', targetId, value: friendship?.remarks[operatorId] ?? '' } }))
52
+ },
53
+ openGroupAction: (kind, targetId, groupId) => {
54
+ const group = store.snapshot?.groups.find(({ id }) => id === groupId)
55
+ if (!group) return
56
+ const member = group.members.find(({ participantId }) => participantId === targetId)
57
+ const value = kind === 'name' ? group.name : kind === 'title' ? member?.title ?? '' : member?.card ?? ''
58
+ setState((current) => ({ ...current, text: { kind, targetId, groupId: group.id, value } }))
59
+ },
60
+ openConversationRename: (conversationId) => {
61
+ const instance = store.snapshot?.conversationInstances?.find(({ id }) => id === conversationId)
62
+ if (instance) setState((value) => ({ ...value, text: { kind: 'rename', conversationId, value: instance.title ?? '' } }))
63
+ },
64
+ openProfile: (participantId, anchor) => {
65
+ const snapshot = store.snapshot
66
+ if (!snapshot) return
67
+ const view = store.getView()
68
+ const conversation = [...snapshot.conversations, ...(snapshot.conversationInstances ?? [])].find(({ id }) => id === view.activeConversationId)
69
+ const groupId = conversation && 'groupId' in conversation ? conversation.groupId : undefined
70
+ const card = buildProfileCardModel(t, { snapshot, participantId, viewerId: view.currentOperatorId, groupId })
71
+ if (card) setState((value) => ({ ...value, profile: { card, ...anchorOf(anchor) } }))
72
+ },
73
+ openGroupProfile: (groupId, anchor) => {
74
+ const group = store.snapshot?.groups.find(({ id }) => id === groupId)
75
+ if (group) setState((value) => ({ ...value, profile: { card: buildGroupProfileCardModel(t, group), ...anchorOf(anchor) } }))
76
+ },
77
+ }
78
+ }, [store, t])
79
+ return { state, setState, dialogs }
80
+ }
81
+
82
+ export function OverlayHost({ state, setState }: {
83
+ state: OverlayState
84
+ setState: React.Dispatch<React.SetStateAction<OverlayState>>
85
+ }) {
86
+ const entity = useRetained(state.entity)
87
+ return (
88
+ <>
89
+ <EntityDialog
90
+ open={!!state.entity}
91
+ mode={entity?.mode ?? 'edit'}
92
+ target={entity?.target}
93
+ onOpenChange={(open) => !open && setState((value) => ({ ...value, entity: undefined }))}
94
+ />
95
+ <TextActionDialog dialog={state.text} onClose={() => setState((value) => ({ ...value, text: undefined }))} />
96
+ {state.profile && <ProfileCard {...state.profile} onClose={() => setState((value) => ({ ...value, profile: undefined }))} />}
97
+ </>
98
+ )
99
+ }
100
+
101
+ /** 备注、群名片、群名称、专属头衔与会话实例改名共用一个单行输入对话框。 */
102
+ function TextActionDialog({ dialog, onClose }: { dialog?: TextDialog, onClose(): void }) {
103
+ const t = useT()
104
+ const { store } = useSandbox()
105
+ const [value, setValue] = React.useState('')
106
+ const [busy, setBusy] = React.useState(false)
107
+ const [error, setError] = React.useState('')
108
+ const shown = useRetained(dialog)
109
+ const { requestClose, confirm } = useDiscardConfirm(!!dialog && value !== dialog.value, onClose)
110
+
111
+ // 布局阶段回填:打开的首帧就是本次的值,不闪出上一次输入的内容。
112
+ React.useLayoutEffect(() => {
113
+ if (!dialog) return
114
+ setValue(dialog.value)
115
+ setError('')
116
+ }, [dialog])
117
+
118
+ const submit = async () => {
119
+ if (!dialog || busy) return
120
+ setBusy(true)
121
+ setError('')
122
+ try {
123
+ if (dialog.kind === 'remark') await store.performFriendAction({ action: 'set-remark', targetId: dialog.targetId, remark: value })
124
+ else if (dialog.kind === 'rename') await store.renameConversationInstance({ conversationId: dialog.conversationId, title: value })
125
+ else if (dialog.kind === 'name') await store.performGroupAction({ action: 'set-name', groupId: dialog.groupId, name: value })
126
+ else if (dialog.kind === 'title') await store.performGroupAction({ action: 'set-title', groupId: dialog.groupId, targetId: dialog.targetId, title: value })
127
+ else await store.performGroupAction({ action: 'set-card', groupId: dialog.groupId, targetId: dialog.targetId, card: value })
128
+ onClose()
129
+ } catch (failure) {
130
+ setError(errorText(failure, t('sandbox.common.failed')))
131
+ } finally {
132
+ setBusy(false)
133
+ }
134
+ }
135
+
136
+ const kind = shown?.kind ?? 'remark'
137
+ return (
138
+ <Dialog open={!!dialog} onOpenChange={(open) => !open && requestClose()}>
139
+ <DialogContent>
140
+ <DialogHeader>
141
+ <DialogTitle>{t(`sandbox.text.${kind}.title`)}</DialogTitle>
142
+ <DialogDescription>{t(`sandbox.text.${kind}.description`)}</DialogDescription>
143
+ </DialogHeader>
144
+ <Input
145
+ autoFocus
146
+ value={value}
147
+ placeholder={t(`sandbox.text.${kind}.placeholder`)}
148
+ onChange={(event) => setValue(event.target.value)}
149
+ onKeyDown={(event) => {
150
+ if (event.key === 'Enter' && !event.nativeEvent.isComposing) void submit()
151
+ }}
152
+ />
153
+ {error && <p role="alert" className="text-xs text-destructive">{error}</p>}
154
+ <DialogFooter>
155
+ <Button variant="outline" onClick={requestClose}>{t('sandbox.common.cancel')}</Button>
156
+ <Button disabled={busy} onClick={submit}>{busy ? t('sandbox.common.saving') : t('sandbox.common.save')}</Button>
157
+ </DialogFooter>
158
+ {confirm}
159
+ </DialogContent>
160
+ </Dialog>
161
+ )
162
+ }
163
+
164
+ const PROFILE_WIDTH = 320
165
+ /** 首帧定位用的估计高度;挂载后按实际高度重新收进视口。 */
166
+ const PROFILE_HEIGHT = 380
167
+
168
+ /** 资料卡:在点击位置附近浮出,可拖动头部移动,点外部或 Esc 关闭。 */
169
+ function ProfileCard({ card, x, y, onClose }: { card: ProfileCardModel, x: number, y: number, onClose(): void }) {
170
+ const t = useT()
171
+ const { resolveAvatar } = useWorkspace()
172
+ const panel = React.useRef<HTMLElement>(null)
173
+ const scroller = React.useRef<HTMLDivElement>(null)
174
+ const [position, setPosition] = React.useState(() => getFloatingPanelPosition({ x, y }, { width: window.innerWidth, height: window.innerHeight }, { width: PROFILE_WIDTH, height: PROFILE_HEIGHT }))
175
+ const drag = React.useRef<{ id: number, x: number, y: number, left: number, top: number } | undefined>(undefined)
176
+
177
+ // 资料卡最高 32rem,字段多时比估计高度高;在绘制前按实际尺寸重新定位,下缘不越出视口。
178
+ React.useLayoutEffect(() => {
179
+ const size = panel.current
180
+ ? { width: panel.current.offsetWidth, height: panel.current.offsetHeight }
181
+ : { width: PROFILE_WIDTH, height: PROFILE_HEIGHT }
182
+ setPosition(getFloatingPanelPosition({ x, y }, { width: window.innerWidth, height: window.innerHeight }, size))
183
+ }, [card, x, y])
184
+
185
+ React.useEffect(() => {
186
+ const onPointerDown = (event: PointerEvent) => {
187
+ if (panel.current?.contains(event.target as Node)) return
188
+ onClose()
189
+ }
190
+ const onKey = (event: KeyboardEvent) => {
191
+ if (event.key === 'Escape') onClose()
192
+ }
193
+ // 延后一帧挂载,避免打开资料卡的那次点击立刻把它关掉。
194
+ const timer = setTimeout(() => document.addEventListener('pointerdown', onPointerDown))
195
+ window.addEventListener('keydown', onKey)
196
+ return () => {
197
+ clearTimeout(timer)
198
+ document.removeEventListener('pointerdown', onPointerDown)
199
+ window.removeEventListener('keydown', onKey)
200
+ }
201
+ }, [onClose])
202
+
203
+ const sections = groupProfileCardFields(t, card.fields)
204
+ return createPortal(
205
+ <section
206
+ ref={panel}
207
+ aria-label={t('sandbox.profile.title')}
208
+ className="sandbox-glass fixed z-50 flex max-h-[min(32rem,calc(100vh-24px))] w-80 flex-col overflow-hidden rounded-xl bg-popover text-sm leading-6 text-popover-foreground shadow-popup ring-1 ring-border animate-in fade-in-0 zoom-in-95"
209
+ style={{ left: position.x, top: position.y }}
210
+ >
211
+ <Button variant="ghost" size="icon-xs" className="sandbox-profile-close" aria-label={t('sandbox.common.close')} onClick={onClose}><XIcon /></Button>
212
+ <div ref={scroller} className="sandbox-profile-scroller">
213
+ <header
214
+ className="sandbox-profile-hero"
215
+ onPointerDown={(event) => {
216
+ if (event.button !== 0 || isFloatingPanelInteractiveTarget(event.target) || !panel.current) return
217
+ const rect = panel.current.getBoundingClientRect()
218
+ drag.current = { id: event.pointerId, x: event.clientX, y: event.clientY, left: rect.left, top: rect.top }
219
+ event.currentTarget.setPointerCapture(event.pointerId)
220
+ }}
221
+ onPointerMove={(event) => {
222
+ const state = drag.current
223
+ if (!state || state.id !== event.pointerId || !panel.current) return
224
+ setPosition(clampFloatingPanelPosition(
225
+ { x: state.left + event.clientX - state.x, y: state.top + event.clientY - state.y },
226
+ { width: window.innerWidth, height: window.innerHeight },
227
+ { width: panel.current.offsetWidth, height: panel.current.offsetHeight },
228
+ ))
229
+ }}
230
+ onPointerUp={() => {
231
+ drag.current = undefined
232
+ }}
233
+ >
234
+ <SandboxAvatar kind={card.avatarKind} name={card.name} src={resolveAvatar(card.avatar)} className="sandbox-profile-avatar" />
235
+ <div className="sandbox-profile-identity">
236
+ <h2 className="sandbox-profile-name">{card.name}</h2>
237
+ <div className="sandbox-profile-id">
238
+ <span>{card.identityLabel} {card.participantId}</span>
239
+ <CopyIdButton value={card.participantId} />
240
+ </div>
241
+ {card.personalNote && <p className="sandbox-profile-note">{card.personalNote}</p>}
242
+ </div>
243
+ </header>
244
+ <div className="sandbox-profile-body">
245
+ {sections.map((section) => (
246
+ <section key={section.group}>
247
+ <h3 className="sandbox-profile-section-title">{section.label}</h3>
248
+ {section.group === 'group' ? (
249
+ <dl className="sandbox-profile-stats">
250
+ {section.fields.map((field) => (
251
+ <div key={field.label} className="sandbox-profile-stat">
252
+ <dt>{field.label}</dt>
253
+ <dd>{field.value}</dd>
254
+ </div>
255
+ ))}
256
+ </dl>
257
+ ) : (
258
+ <dl className="sandbox-profile-fields">
259
+ {section.fields.map((field) => (
260
+ <div key={`${field.label}:${field.value}`} className="sandbox-profile-field">
261
+ <dt>{field.label}</dt>
262
+ <dd>{field.value}</dd>
263
+ </div>
264
+ ))}
265
+ </dl>
266
+ )}
267
+ </section>
268
+ ))}
269
+ </div>
270
+ </div>
271
+ <OverlayScrollbar target={scroller} className="sandbox-profile-scrollbar" />
272
+ </section>,
273
+ document.body,
274
+ )
275
+ }
276
+
277
+ /** 号码旁的复制按钮:复制成功后短暂换成对勾。 */
278
+ function CopyIdButton({ value }: { value: string }) {
279
+ const t = useT()
280
+ const [copied, setCopied] = React.useState(false)
281
+ React.useEffect(() => {
282
+ if (!copied) return
283
+ const timer = setTimeout(() => setCopied(false), 1500)
284
+ return () => clearTimeout(timer)
285
+ }, [copied])
286
+ const copy = async () => {
287
+ try {
288
+ await navigator.clipboard.writeText(value)
289
+ setCopied(true)
290
+ } catch {
291
+ toast.error(t('sandbox.records.copyFailed'))
292
+ }
293
+ }
294
+ return (
295
+ <Button variant="ghost" size="icon-xs" aria-label={t(copied ? 'sandbox.profile.copied' : 'sandbox.profile.copyId')} onClick={() => void copy()}>
296
+ {copied ? <CheckIcon /> : <CopyIcon />}
297
+ </Button>
298
+ )
299
+ }
@@ -0,0 +1,164 @@
1
+ /*
2
+ * 资料卡(overlay-host.tsx 的 ProfileCard)。只按 sandbox-profile- 类名选择;
3
+ * 本文件不分层,压过 ui-kit 在宿主 utilities 层里的工具类。卡片本身的玻璃底来自 glass.css。
4
+ */
5
+
6
+ /* 正文视口隐藏原生滚动条,由 .sandbox-profile-scrollbar 自绘(SCROLLBAR.md)。 */
7
+ .sandbox-profile-scroller {
8
+ min-height: 0;
9
+ overflow-y: auto;
10
+ scrollbar-width: none;
11
+ }
12
+
13
+ .sandbox-profile-scroller::-webkit-scrollbar {
14
+ display: none;
15
+ }
16
+
17
+ /* 轨道上下让出卡片的 12px 圆角。 */
18
+ .sandbox-profile-scrollbar {
19
+ top: 12px;
20
+ bottom: 12px;
21
+ }
22
+
23
+ .sandbox-profile-close {
24
+ position: absolute;
25
+ top: 8px;
26
+ right: 8px;
27
+ z-index: 6;
28
+ }
29
+
30
+ /* 头部兼作拖动把手:浅色渐变底与正文区分,不再单设标题栏。 */
31
+ .sandbox-profile-hero {
32
+ display: flex;
33
+ align-items: center;
34
+ gap: 14px;
35
+ padding: 22px 44px 18px 18px;
36
+ background: linear-gradient(180deg, color-mix(in oklab, var(--muted) 90%, transparent), transparent);
37
+ touch-action: none;
38
+ user-select: none;
39
+ }
40
+
41
+ .sandbox-profile-avatar {
42
+ width: 64px;
43
+ height: 64px;
44
+ }
45
+
46
+ .sandbox-profile-avatar > span:first-child {
47
+ font-size: 20px;
48
+ box-shadow: 0 0 0 3px var(--popover);
49
+ }
50
+
51
+ .sandbox-profile-identity {
52
+ display: flex;
53
+ min-width: 0;
54
+ flex-direction: column;
55
+ gap: 2px;
56
+ }
57
+
58
+ .sandbox-profile-name {
59
+ overflow: hidden;
60
+ font-size: 17px;
61
+ font-weight: 600;
62
+ line-height: 24px;
63
+ text-overflow: ellipsis;
64
+ white-space: nowrap;
65
+ }
66
+
67
+ .sandbox-profile-id {
68
+ display: flex;
69
+ align-items: center;
70
+ gap: 2px;
71
+ color: var(--muted-foreground);
72
+ font-size: 12px;
73
+ line-height: 20px;
74
+ font-variant-numeric: tabular-nums;
75
+ }
76
+
77
+ .sandbox-profile-note {
78
+ display: -webkit-box;
79
+ margin-top: 2px;
80
+ overflow: hidden;
81
+ color: var(--muted-foreground);
82
+ font-size: 12px;
83
+ line-height: 18px;
84
+ -webkit-box-orient: vertical;
85
+ -webkit-line-clamp: 2;
86
+ }
87
+
88
+ .sandbox-profile-body {
89
+ display: flex;
90
+ flex-direction: column;
91
+ gap: 14px;
92
+ padding: 0 16px 16px;
93
+ }
94
+
95
+ .sandbox-profile-section-title {
96
+ margin: 0 4px 6px;
97
+ color: var(--muted-foreground);
98
+ font-size: 11px;
99
+ font-weight: 500;
100
+ line-height: 16px;
101
+ }
102
+
103
+ /* 字段行:圆角分组,行间细分隔线。 */
104
+ .sandbox-profile-fields {
105
+ overflow: hidden;
106
+ border-radius: 10px;
107
+ background: color-mix(in oklab, var(--muted) 60%, transparent);
108
+ }
109
+
110
+ .sandbox-profile-field {
111
+ display: flex;
112
+ justify-content: space-between;
113
+ gap: 12px;
114
+ padding: 7px 12px;
115
+ font-size: 12px;
116
+ line-height: 18px;
117
+ }
118
+
119
+ .sandbox-profile-field + .sandbox-profile-field {
120
+ border-top: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
121
+ }
122
+
123
+ .sandbox-profile-field dt {
124
+ flex-shrink: 0;
125
+ color: var(--muted-foreground);
126
+ }
127
+
128
+ .sandbox-profile-field dd {
129
+ min-width: 0;
130
+ font-weight: 500;
131
+ text-align: right;
132
+ overflow-wrap: anywhere;
133
+ }
134
+
135
+ /* 群资料的计数改成并排的数字块。 */
136
+ .sandbox-profile-stats {
137
+ display: grid;
138
+ grid-template-columns: repeat(2, minmax(0, 1fr));
139
+ gap: 8px;
140
+ }
141
+
142
+ .sandbox-profile-stat {
143
+ display: flex;
144
+ /* dl 里 dt 在前,数字显示在上。 */
145
+ flex-direction: column-reverse;
146
+ justify-content: flex-end;
147
+ gap: 2px;
148
+ padding: 10px 12px;
149
+ border-radius: 10px;
150
+ background: color-mix(in oklab, var(--muted) 60%, transparent);
151
+ }
152
+
153
+ .sandbox-profile-stat dd {
154
+ font-size: 18px;
155
+ font-weight: 600;
156
+ line-height: 24px;
157
+ font-variant-numeric: tabular-nums;
158
+ }
159
+
160
+ .sandbox-profile-stat dt {
161
+ color: var(--muted-foreground);
162
+ font-size: 11px;
163
+ line-height: 16px;
164
+ }
@@ -0,0 +1,28 @@
1
+ import { includesConversationParticipant, listConversations } from '../../src/conversation-resolution'
2
+ import type { SandboxSnapshot } from '../../src/types'
3
+
4
+ export interface SandboxWorkspaceSelection {
5
+ currentOperatorId?: string
6
+ activeConversationId?: string
7
+ }
8
+
9
+ export function resolveWorkspaceSelection(
10
+ snapshot: SandboxSnapshot,
11
+ preferred: SandboxWorkspaceSelection,
12
+ ): SandboxWorkspaceSelection {
13
+ const currentOperator = snapshot.participants.find(({ id }) => id === preferred.currentOperatorId)
14
+ ?? snapshot.participants.find(({ kind }) => kind === 'user')
15
+ ?? snapshot.participants[0]
16
+ // 会话实例也参与选中恢复:新建实例后立刻被选中,刷新页面不该把选中弹回根会话。
17
+ const conversations = currentOperator
18
+ ? listConversations(snapshot)
19
+ .filter((conversation) => includesConversationParticipant(snapshot, conversation, currentOperator.id))
20
+ : []
21
+ const activeConversation = conversations.find(({ id }) => id === preferred.activeConversationId)
22
+ ?? conversations[0]
23
+
24
+ return {
25
+ currentOperatorId: currentOperator?.id,
26
+ activeConversationId: activeConversation?.id,
27
+ }
28
+ }