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,429 @@
1
+ import * as React from 'react'
2
+ import {
3
+ ArrowDownWideNarrowIcon,
4
+ ArrowUpNarrowWideIcon,
5
+ CalendarClockIcon,
6
+ CheckIcon,
7
+ ClockIcon,
8
+ CopyIcon,
9
+ FilterIcon,
10
+ RefreshCwIcon,
11
+ Trash2Icon,
12
+ type LucideIcon,
13
+ } from 'lucide-react'
14
+ import {
15
+ AlertDialog,
16
+ AlertDialogAction,
17
+ AlertDialogCancel,
18
+ AlertDialogContent,
19
+ AlertDialogDescription,
20
+ AlertDialogFooter,
21
+ AlertDialogHeader,
22
+ AlertDialogTitle,
23
+ Badge,
24
+ Button,
25
+ cn,
26
+ Popover,
27
+ PopoverContent,
28
+ PopoverTrigger,
29
+ Spinner,
30
+ Switch,
31
+ } from '@chatluna/ui-kit'
32
+ import { toast } from '@chatluna/ui-client/client'
33
+ import { useT } from '../i18n'
34
+ import { formatDuration } from '../shared/format-duration'
35
+ import { OverlayScrollbar } from '../shared/overlay-scrollbar'
36
+ import './records.css'
37
+
38
+ /** 自动刷新开着且页面可见时的轮询间隔。 */
39
+ const LIVE_REFRESH_INTERVAL_MS = 2000
40
+
41
+ export type SortOrder = 'asc' | 'desc'
42
+
43
+ /**
44
+ * 记录工作台的页框:OneBot 调试与测试调用共用「说明 + 自动刷新/刷新/清理 + 列表|详情」的版式,
45
+ * 两页只各自提供筛选项、列表行与详情内容。
46
+ */
47
+ export function RecordPage({ title, description, loading, error, live, onLiveChange, onRefresh, clear, children }: {
48
+ title: string
49
+ description: string
50
+ loading: boolean
51
+ error: string
52
+ live: boolean
53
+ onLiveChange(live: boolean): void
54
+ onRefresh(): void
55
+ clear: { label: string, title: string, description: string, disabled: boolean, onConfirm(): Promise<void> | void }
56
+ children: React.ReactNode
57
+ }) {
58
+ const t = useT()
59
+ const [confirming, setConfirming] = React.useState(false)
60
+ return (
61
+ <section aria-label={title} className="flex min-h-0 flex-1 flex-col gap-4 overflow-hidden px-6 pt-3 pb-6 text-sm leading-5">
62
+ <header className="flex flex-wrap items-center justify-between gap-3">
63
+ <p className="min-w-0 text-xs text-muted-foreground">{description}</p>
64
+ <div className="flex items-center gap-2">
65
+ <label className="mr-1 flex items-center gap-2 text-xs text-muted-foreground">
66
+ <Switch checked={live} onCheckedChange={(checked) => onLiveChange(checked === true)} />
67
+ {t('sandbox.records.live')}
68
+ </label>
69
+ <Button variant="outline" size="sm" disabled={loading} onClick={onRefresh}><RefreshCwIcon />{t('sandbox.records.refresh')}</Button>
70
+ <Button variant="outline" size="sm" className="text-destructive" disabled={loading || clear.disabled} onClick={() => setConfirming(true)}><Trash2Icon />{clear.label}</Button>
71
+ </div>
72
+ </header>
73
+ {error && <p role="alert" className="text-xs text-destructive">{error}</p>}
74
+ <div className="grid min-h-0 flex-1 grid-rows-[minmax(10rem,40%)_minmax(0,1fr)] gap-4 md:grid-cols-[minmax(16rem,22rem)_minmax(0,1fr)] md:grid-rows-1">
75
+ {children}
76
+ </div>
77
+ <AlertDialog open={confirming} onOpenChange={setConfirming}>
78
+ <AlertDialogContent>
79
+ <AlertDialogHeader>
80
+ <AlertDialogTitle>{clear.title}</AlertDialogTitle>
81
+ <AlertDialogDescription>{clear.description}</AlertDialogDescription>
82
+ </AlertDialogHeader>
83
+ <AlertDialogFooter>
84
+ <AlertDialogCancel>{t('sandbox.common.cancel')}</AlertDialogCancel>
85
+ <AlertDialogAction variant="destructive" onClick={() => {
86
+ setConfirming(false)
87
+ void clear.onConfirm()
88
+ }}>{clear.label}</AlertDialogAction>
89
+ </AlertDialogFooter>
90
+ </AlertDialogContent>
91
+ </AlertDialog>
92
+ </section>
93
+ )
94
+ }
95
+
96
+ /** 左栏:标题、时间排序切换与筛选浮层;筛选浮层关闭时由调用方提交筛选。 */
97
+ export function RecordListPane({ label, order, onToggleOrder, filter, loading, empty, children }: {
98
+ label: string
99
+ order: SortOrder
100
+ onToggleOrder(): void
101
+ filter: { active: boolean, summary: string, open: boolean, onOpenChange(open: boolean): void, content: React.ReactNode }
102
+ loading: boolean
103
+ empty: boolean
104
+ children: React.ReactNode
105
+ }) {
106
+ const t = useT()
107
+ const scroller = React.useRef<HTMLDivElement>(null)
108
+ const OrderIcon = order === 'asc' ? ArrowUpNarrowWideIcon : ArrowDownWideNarrowIcon
109
+ return (
110
+ <section aria-label={label} className="flex min-h-0 flex-col overflow-hidden rounded-xl ring-1 ring-border">
111
+ <header className="flex h-12 shrink-0 items-center justify-between gap-2 border-b border-border pr-2 pl-4">
112
+ <h2 className="text-[13px] font-medium">{label}</h2>
113
+ <div className="flex items-center gap-1">
114
+ <Button
115
+ variant="ghost"
116
+ size="sm"
117
+ aria-label={t(order === 'asc' ? 'sandbox.records.orderAscHint' : 'sandbox.records.orderDescHint')}
118
+ onClick={onToggleOrder}
119
+ >
120
+ <OrderIcon />{t(order === 'asc' ? 'sandbox.records.orderAsc' : 'sandbox.records.orderDesc')}
121
+ </Button>
122
+ <Popover open={filter.open} onOpenChange={filter.onOpenChange}>
123
+ <PopoverTrigger render={(
124
+ <Button
125
+ variant={filter.active ? 'secondary' : 'ghost'}
126
+ size="icon-sm"
127
+ aria-label={t('sandbox.records.filterLabel', { summary: filter.summary })}
128
+ />
129
+ )}>
130
+ <FilterIcon />
131
+ </PopoverTrigger>
132
+ <PopoverContent align="end" className="sandbox-glass flex w-72 flex-col gap-3">{filter.content}</PopoverContent>
133
+ </Popover>
134
+ </div>
135
+ </header>
136
+ {loading && empty ? (
137
+ <div className="flex flex-1 items-center justify-center"><Spinner /></div>
138
+ ) : empty ? (
139
+ <p className="flex flex-1 items-center justify-center p-6 text-center text-xs text-muted-foreground">{t('sandbox.records.empty')}</p>
140
+ ) : (
141
+ <div className="relative flex min-h-0 flex-1 flex-col">
142
+ <div ref={scroller} className="sandbox-record-scroller flex min-h-0 flex-1 flex-col gap-0.5 overflow-y-auto p-1.5">{children}</div>
143
+ <OverlayScrollbar target={scroller} className="sandbox-record-scrollbar" />
144
+ </div>
145
+ )}
146
+ </section>
147
+ )
148
+ }
149
+
150
+ /**
151
+ * 列表行:状态圆点 + 名称 + 右侧小标签一行,时间、耗时与 `meta`(来源、凭证等)一行。
152
+ * 时间只写时分秒,跨天的记录补上月日;完整时间放在悬停提示里。
153
+ */
154
+ export function RecordItem({ active, onClick, title, status, tag, time, duration, meta = [] }: {
155
+ active: boolean
156
+ onClick(): void
157
+ title: string
158
+ status: 'success' | 'error'
159
+ tag?: string
160
+ time: string
161
+ duration: number
162
+ meta?: React.ReactNode[]
163
+ }) {
164
+ const t = useT()
165
+ return (
166
+ <button
167
+ type="button"
168
+ aria-current={active ? 'true' : undefined}
169
+ className={cn('sandbox-record-item', active && 'is-active')}
170
+ onClick={onClick}
171
+ >
172
+ <span className="flex min-w-0 items-center gap-2">
173
+ <span
174
+ role="img"
175
+ aria-label={t(status === 'error' ? 'sandbox.records.statusError' : 'sandbox.records.statusSuccess')}
176
+ className={cn('sandbox-record-dot', status === 'error' && 'is-error')}
177
+ />
178
+ <strong className={cn('min-w-0 flex-1 truncate font-mono text-[13px] leading-5 font-medium', status === 'error' && 'text-destructive')}>{title}</strong>
179
+ {tag && <RecordTag>{tag}</RecordTag>}
180
+ </span>
181
+ <span className="sandbox-record-item-meta">
182
+ <time dateTime={time} title={formatRecordTime(time)}>{formatListTime(time)}</time>
183
+ <span>{formatDuration(duration)}</span>
184
+ {meta.map((item, index) => <span key={index} className="min-w-0 truncate">{item}</span>)}
185
+ </span>
186
+ </button>
187
+ )
188
+ }
189
+
190
+ /** 方向(EVENT/ACTION)、传输方式(MCP/HTTP)这类等宽小标签。 */
191
+ export function RecordTag({ children }: { children: React.ReactNode }) {
192
+ return <span className="sandbox-record-tag">{children}</span>
193
+ }
194
+
195
+ function RecordTiming({ time, duration }: { time: string, duration: number }) {
196
+ return (
197
+ <span className="flex flex-wrap items-center gap-x-3 gap-y-0.5 text-[11px] text-muted-foreground tabular-nums">
198
+ <time dateTime={time} className="flex items-center gap-1"><CalendarClockIcon className="size-3.5" />{formatRecordTime(time)}</time>
199
+ <span className="flex items-center gap-1"><ClockIcon className="size-3.5" />{formatDuration(duration)}</span>
200
+ </span>
201
+ )
202
+ }
203
+
204
+ /**
205
+ * 右栏:未选中、读取中与详情三态。详情的标题栏(`RecordDetailHeader`)固定在顶部,只有正文滚动;
206
+ * `scrollKey` 变化(换了一条记录)时正文回到顶部。
207
+ */
208
+ export function RecordDetailPane({ label, loading, header, scrollKey, children }: {
209
+ label: string
210
+ loading: boolean
211
+ header?: React.ReactNode
212
+ scrollKey?: string
213
+ children?: React.ReactNode
214
+ }) {
215
+ const t = useT()
216
+ const scroller = React.useRef<HTMLElement>(null)
217
+ React.useLayoutEffect(() => {
218
+ scroller.current?.scrollTo({ top: 0 })
219
+ }, [scrollKey])
220
+ return (
221
+ <section aria-label={label} className="flex min-h-0 flex-col overflow-hidden rounded-xl ring-1 ring-border">
222
+ {children ? (
223
+ <>
224
+ {header}
225
+ <div className="relative flex min-h-0 flex-1 flex-col">
226
+ <article ref={scroller} className="sandbox-record-scroller flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-5 pt-4 pb-6">{children}</article>
227
+ <OverlayScrollbar target={scroller} className="sandbox-record-scrollbar" />
228
+ </div>
229
+ </>
230
+ ) : loading ? (
231
+ <div className="flex flex-1 items-center justify-center"><Spinner /></div>
232
+ ) : (
233
+ <p className="flex flex-1 items-center justify-center p-6 text-center text-xs text-muted-foreground">{t('sandbox.records.pick')}</p>
234
+ )}
235
+ </section>
236
+ )
237
+ }
238
+
239
+ /** 详情标题栏:名称与状态徽标一行,时间与耗时一行,与左栏的标题栏同样以细线分隔正文。 */
240
+ export function RecordDetailHeader({ title, badges, time, duration }: {
241
+ title: string
242
+ badges: React.ReactNode
243
+ time: string
244
+ duration: number
245
+ }) {
246
+ return (
247
+ <header className="flex shrink-0 flex-col gap-1.5 border-b border-border px-5 py-3.5">
248
+ <span className="flex min-w-0 flex-wrap items-center gap-2">
249
+ <h2 className="min-w-0 truncate font-mono text-[15px] leading-6 font-semibold">{title}</h2>
250
+ {badges}
251
+ </span>
252
+ <RecordTiming time={time} duration={duration} />
253
+ </header>
254
+ )
255
+ }
256
+
257
+ export function StatusBadge({ status }: { status: 'success' | 'error' }) {
258
+ const t = useT()
259
+ return status === 'error'
260
+ ? <Badge variant="destructive">{t('sandbox.records.statusError')}</Badge>
261
+ : <Badge variant="secondary" className="text-emerald-700 dark:text-emerald-400">{t('sandbox.records.statusSuccess')}</Badge>
262
+ }
263
+
264
+ /** 元信息网格:每项小标签在上、值在下,列数随面板宽度增减(`records.css`)。 */
265
+ export function MetaList({ children }: { children: React.ReactNode }) {
266
+ return <dl className="sandbox-record-meta">{children}</dl>
267
+ }
268
+
269
+ /** `wide` 的项独占一整行,用于关联实体这类长值。 */
270
+ export function MetaRow({ icon: Icon, label, value, wide }: { icon: LucideIcon, label: string, value: React.ReactNode, wide?: boolean }) {
271
+ return (
272
+ <div className={cn('sandbox-record-meta-item', wide && 'is-wide')}>
273
+ <dt className="sandbox-record-meta-label"><Icon />{label}</dt>
274
+ <dd className="sandbox-record-meta-value">{value}</dd>
275
+ </div>
276
+ )
277
+ }
278
+
279
+ /** 一组「键 值」小片,例如关联实体的 userId、groupId。 */
280
+ export function MetaChips({ items }: { items: Array<[string, React.ReactNode]> }) {
281
+ return (
282
+ <span className="sandbox-record-chips">
283
+ {items.map(([key, value]) => (
284
+ <span key={key} className="sandbox-record-chip"><span className="sandbox-record-chip-key">{key}</span>{value}</span>
285
+ ))}
286
+ </span>
287
+ )
288
+ }
289
+
290
+ /** 提示卡片:错误诊断(`destructive`)与会话观察等需要先读到的说明。 */
291
+ export function RecordNotice({ icon: Icon, title, tone, children }: { icon: LucideIcon, title: string, tone?: 'destructive', children: React.ReactNode }) {
292
+ return (
293
+ <section className={cn('sandbox-record-notice', tone === 'destructive' && 'is-destructive')}>
294
+ <Icon />
295
+ <div className="min-w-0">
296
+ <h3 className="sandbox-record-notice-title">{title}</h3>
297
+ <div className="sandbox-record-notice-body">{children}</div>
298
+ </div>
299
+ </section>
300
+ )
301
+ }
302
+
303
+ export function RecordSection({ icon: Icon, title, children }: { icon: LucideIcon, title: string, children: React.ReactNode }) {
304
+ return (
305
+ <section className="flex flex-col gap-2">
306
+ <h3 className="flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
307
+ <Icon className="size-3.5" />{title}
308
+ </h3>
309
+ {children}
310
+ </section>
311
+ )
312
+ }
313
+
314
+ /** 只给 `JSON.stringify` 的输出着色:字符串先于数字匹配,键名和值里的数字不会被拆开。 */
315
+ const JSON_TOKEN = /("(?:\\.|[^"\\])*")(\s*:)?|\b(?:true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|[{}[\],]/g
316
+
317
+ function highlightJson(text: string): React.ReactNode[] {
318
+ const parts: React.ReactNode[] = []
319
+ let last = 0
320
+ for (const match of text.matchAll(JSON_TOKEN)) {
321
+ const [token, string, colon] = match
322
+ if (match.index > last) parts.push(text.slice(last, match.index))
323
+ const kind = string !== undefined
324
+ ? colon ? 'key' : 'string'
325
+ : /^[{}[\],]$/.test(token) ? 'punct' : /^[tfn]/.test(token) ? 'literal' : 'number'
326
+ parts.push(<span key={match.index} className={`sandbox-json-${kind}`}>{string ?? token}</span>)
327
+ if (colon) parts.push(colon)
328
+ last = match.index + token.length
329
+ }
330
+ if (last < text.length) parts.push(text.slice(last))
331
+ return parts
332
+ }
333
+
334
+ /** JSON 代码块:语法着色,悬停时右上角浮现复制按钮。不设内层滚动,随详情正文一起滚。 */
335
+ export function JsonBlock({ value }: { value: unknown }) {
336
+ const t = useT()
337
+ const text = React.useMemo(() => JSON.stringify(value, null, 2) ?? String(value), [value])
338
+ const tokens = React.useMemo(() => highlightJson(text), [text])
339
+ const [copied, setCopied] = React.useState(false)
340
+ React.useEffect(() => {
341
+ if (!copied) return
342
+ const timer = setTimeout(() => setCopied(false), 1500)
343
+ return () => clearTimeout(timer)
344
+ }, [copied])
345
+ const copy = async () => {
346
+ try {
347
+ await navigator.clipboard.writeText(text)
348
+ setCopied(true)
349
+ } catch {
350
+ toast.error(t('sandbox.records.copyFailed'))
351
+ }
352
+ }
353
+ return (
354
+ <div className="sandbox-record-code">
355
+ <pre>{tokens}</pre>
356
+ <Button
357
+ variant="outline"
358
+ size="icon-sm"
359
+ className="sandbox-record-code-copy"
360
+ aria-label={t(copied ? 'sandbox.records.copied' : 'sandbox.records.copy')}
361
+ onClick={() => void copy()}
362
+ >
363
+ {copied ? <CheckIcon /> : <CopyIcon />}
364
+ </Button>
365
+ </div>
366
+ )
367
+ }
368
+
369
+ /** 筛选浮层里的一行:标签在上、控件在下。 */
370
+ export function FilterField({ label, children }: { label: string, children: React.ReactNode }) {
371
+ return (
372
+ <label className="flex flex-col gap-1.5 text-xs">
373
+ <span className="text-muted-foreground">{label}</span>
374
+ {children}
375
+ </label>
376
+ )
377
+ }
378
+
379
+ /** 列表里的时间:当天只写时分秒,其余补上月日。 */
380
+ function formatListTime(value: string) {
381
+ const date = new Date(value)
382
+ const full = formatRecordTime(value)
383
+ const today = new Date()
384
+ const sameDay = date.getFullYear() === today.getFullYear() && date.getMonth() === today.getMonth() && date.getDate() === today.getDate()
385
+ return sameDay ? full.slice(11) : full.slice(5)
386
+ }
387
+
388
+ export function formatRecordTime(value: string) {
389
+ const date = new Date(value)
390
+ const pad = (part: number) => String(part).padStart(2, '0')
391
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
392
+ }
393
+
394
+ /**
395
+ * 进入页面时读一次;打开自动刷新后,页面可见期间每 2 秒重读,隐藏标签页时暂停。
396
+ * `refresh` 每次渲染都可能是新函数,借 ref 读最新一份,计时器不随之重建。
397
+ */
398
+ export function useRecordRefresh(live: boolean, refresh: () => void) {
399
+ const latest = React.useRef(refresh)
400
+ latest.current = refresh
401
+
402
+ React.useEffect(() => {
403
+ latest.current()
404
+ }, [])
405
+
406
+ React.useEffect(() => {
407
+ if (!live) return
408
+ let timer: ReturnType<typeof setInterval> | undefined
409
+ const sync = () => {
410
+ const visible = document.visibilityState === 'visible'
411
+ if (visible && !timer) timer = setInterval(() => latest.current(), LIVE_REFRESH_INTERVAL_MS)
412
+ if (!visible && timer) {
413
+ clearInterval(timer)
414
+ timer = undefined
415
+ }
416
+ }
417
+ sync()
418
+ document.addEventListener('visibilitychange', sync)
419
+ return () => {
420
+ document.removeEventListener('visibilitychange', sync)
421
+ if (timer) clearInterval(timer)
422
+ }
423
+ }, [live])
424
+ }
425
+
426
+ export function orderByTime<T extends { createdAt: string }>(records: readonly T[], order: SortOrder, tieBreak: (left: T, right: T) => number) {
427
+ const sign = order === 'asc' ? 1 : -1
428
+ return [...records].sort((left, right) => sign * (left.createdAt.localeCompare(right.createdAt) || tieBreak(left, right)))
429
+ }
@@ -0,0 +1,259 @@
1
+ /*
2
+ * 记录工作台的详情面板(records/record-layout.tsx),OneBot 调试与测试调用共用。
3
+ * 只按 sandbox-record- 类名选择;本文件不分层,压过 ui-kit 在宿主 utilities 层里的工具类。
4
+ */
5
+
6
+ /* 正文视口隐藏原生滚动条,由 .sandbox-record-scrollbar 自绘(SCROLLBAR.md)。 */
7
+ .sandbox-record-scroller {
8
+ scrollbar-width: none;
9
+ }
10
+
11
+ /* 轨道上端紧贴标题栏下方,下端让出面板的 12px 圆角。 */
12
+ .sandbox-record-scrollbar {
13
+ top: 4px;
14
+ bottom: 12px;
15
+ }
16
+
17
+ /* 列表行(RecordItem)。 */
18
+ .sandbox-record-item {
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: 3px;
22
+ padding: 9px 12px;
23
+ border-radius: 8px;
24
+ text-align: left;
25
+ transition: background-color 0.15s ease;
26
+ }
27
+
28
+ .sandbox-record-item:hover {
29
+ background: color-mix(in oklab, var(--accent) 60%, transparent);
30
+ }
31
+
32
+ .sandbox-record-item.is-active {
33
+ background: var(--accent);
34
+ color: var(--accent-foreground);
35
+ }
36
+
37
+ .sandbox-record-item:focus-visible {
38
+ outline: 2px solid var(--ring);
39
+ outline-offset: -2px;
40
+ }
41
+
42
+ .sandbox-record-dot {
43
+ width: 7px;
44
+ height: 7px;
45
+ flex-shrink: 0;
46
+ border-radius: 999px;
47
+ background: #10b981;
48
+ box-shadow: 0 0 0 3px color-mix(in oklab, #10b981 16%, transparent);
49
+ }
50
+
51
+ .sandbox-record-dot.is-error {
52
+ background: var(--destructive);
53
+ box-shadow: 0 0 0 3px color-mix(in oklab, var(--destructive) 16%, transparent);
54
+ }
55
+
56
+ /* 第二行与名称左缘对齐(圆点 7px + 间距 8px),各项之间以圆点分隔。 */
57
+ .sandbox-record-item-meta {
58
+ display: flex;
59
+ min-width: 0;
60
+ align-items: center;
61
+ padding-left: 15px;
62
+ font-size: 11px;
63
+ line-height: 16px;
64
+ color: var(--muted-foreground);
65
+ font-variant-numeric: tabular-nums;
66
+ }
67
+
68
+ .sandbox-record-item-meta > * + *::before {
69
+ content: '·';
70
+ margin: 0 6px;
71
+ opacity: 0.6;
72
+ }
73
+
74
+ .sandbox-record-tag {
75
+ display: inline-flex;
76
+ flex-shrink: 0;
77
+ align-items: center;
78
+ height: 18px;
79
+ padding: 0 6px;
80
+ border-radius: 5px;
81
+ background: color-mix(in oklab, var(--muted) 80%, transparent);
82
+ box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--border) 80%, transparent);
83
+ color: var(--muted-foreground);
84
+ font-family: var(--font-mono, ui-monospace, monospace);
85
+ font-size: 10px;
86
+ font-weight: 500;
87
+ letter-spacing: 0.04em;
88
+ }
89
+
90
+ /* 元信息:小标签在上、值在下的多列网格,列数随面板宽度增减。 */
91
+ .sandbox-record-meta {
92
+ display: grid;
93
+ grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
94
+ gap: 14px 24px;
95
+ margin: 0;
96
+ padding: 14px 16px;
97
+ border-radius: 10px;
98
+ background: color-mix(in oklab, var(--muted) 55%, transparent);
99
+ }
100
+
101
+ .sandbox-record-meta-item {
102
+ display: flex;
103
+ min-width: 0;
104
+ flex-direction: column;
105
+ gap: 4px;
106
+ }
107
+
108
+ .sandbox-record-meta-item.is-wide {
109
+ grid-column: 1 / -1;
110
+ }
111
+
112
+ .sandbox-record-meta-label {
113
+ display: flex;
114
+ align-items: center;
115
+ gap: 5px;
116
+ font-size: 11px;
117
+ line-height: 16px;
118
+ color: var(--muted-foreground);
119
+ }
120
+
121
+ .sandbox-record-meta-label svg {
122
+ width: 13px;
123
+ height: 13px;
124
+ flex-shrink: 0;
125
+ }
126
+
127
+ .sandbox-record-meta-value {
128
+ margin: 0;
129
+ min-width: 0;
130
+ font-size: 13px;
131
+ line-height: 20px;
132
+ font-weight: 500;
133
+ overflow-wrap: anywhere;
134
+ }
135
+
136
+ /* 关联实体等「键 值」对:等宽小片,键用弱化色。 */
137
+ .sandbox-record-chips {
138
+ display: flex;
139
+ flex-wrap: wrap;
140
+ gap: 6px;
141
+ }
142
+
143
+ .sandbox-record-chip {
144
+ display: inline-flex;
145
+ min-width: 0;
146
+ align-items: baseline;
147
+ gap: 6px;
148
+ padding: 1px 8px;
149
+ border-radius: 6px;
150
+ background: var(--background);
151
+ box-shadow: inset 0 0 0 1px var(--border);
152
+ font-family: var(--font-mono, ui-monospace, monospace);
153
+ font-size: 12px;
154
+ line-height: 20px;
155
+ font-weight: 400;
156
+ }
157
+
158
+ .sandbox-record-chip-key {
159
+ color: var(--muted-foreground);
160
+ }
161
+
162
+ /* 提示卡片:错误诊断与会话观察。 */
163
+ .sandbox-record-notice {
164
+ display: flex;
165
+ gap: 10px;
166
+ padding: 12px 14px;
167
+ border-radius: 10px;
168
+ background: color-mix(in oklab, var(--muted) 55%, transparent);
169
+ box-shadow: inset 0 0 0 1px var(--border);
170
+ }
171
+
172
+ .sandbox-record-notice.is-destructive {
173
+ background: color-mix(in oklab, var(--destructive) 7%, transparent);
174
+ box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--destructive) 24%, transparent);
175
+ }
176
+
177
+ .sandbox-record-notice > svg {
178
+ width: 16px;
179
+ height: 16px;
180
+ flex-shrink: 0;
181
+ margin-top: 2px;
182
+ color: var(--muted-foreground);
183
+ }
184
+
185
+ .sandbox-record-notice.is-destructive > svg,
186
+ .sandbox-record-notice.is-destructive .sandbox-record-notice-title {
187
+ color: var(--destructive);
188
+ }
189
+
190
+ .sandbox-record-notice-title {
191
+ font-size: 13px;
192
+ line-height: 20px;
193
+ font-weight: 500;
194
+ }
195
+
196
+ .sandbox-record-notice-body {
197
+ margin-top: 2px;
198
+ font-size: 12px;
199
+ line-height: 20px;
200
+ color: var(--muted-foreground);
201
+ overflow-wrap: anywhere;
202
+ }
203
+
204
+ /* JSON 代码块:不设内层滚动,随面板正文一起滚;复制按钮悬停或聚焦时浮现。 */
205
+ .sandbox-record-code {
206
+ position: relative;
207
+ border-radius: 10px;
208
+ background: color-mix(in oklab, var(--muted) 55%, transparent);
209
+ box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--border) 70%, transparent);
210
+ }
211
+
212
+ .sandbox-record-code pre {
213
+ margin: 0;
214
+ padding: 14px 16px;
215
+ font-family: var(--font-mono, ui-monospace, monospace);
216
+ font-size: 12px;
217
+ line-height: 20px;
218
+ white-space: pre-wrap;
219
+ overflow-wrap: anywhere;
220
+ tab-size: 2;
221
+ }
222
+
223
+ .sandbox-record-code-copy {
224
+ position: absolute;
225
+ top: 8px;
226
+ right: 8px;
227
+ opacity: 0;
228
+ transition: opacity 0.15s ease;
229
+ }
230
+
231
+ .sandbox-record-code:hover .sandbox-record-code-copy,
232
+ .sandbox-record-code:focus-within .sandbox-record-code-copy {
233
+ opacity: 1;
234
+ }
235
+
236
+ @media (hover: none) {
237
+ .sandbox-record-code-copy {
238
+ opacity: 1;
239
+ }
240
+ }
241
+
242
+ /* JSON 语法着色:亮色与暗色各取一组同等饱和度的颜色。 */
243
+ .sandbox-json-key { color: #0f5fb8; }
244
+ .sandbox-json-string { color: #13784a; }
245
+ .sandbox-json-number { color: #b0520e; }
246
+ .sandbox-json-literal { color: #8b3fc7; }
247
+ .sandbox-json-punct { color: var(--muted-foreground); }
248
+
249
+ .dark .sandbox-json-key { color: #7cb7ff; }
250
+ .dark .sandbox-json-string { color: #7fd6a4; }
251
+ .dark .sandbox-json-number { color: #f2a76b; }
252
+ .dark .sandbox-json-literal { color: #c99cf5; }
253
+
254
+ @media (prefers-reduced-motion: reduce) {
255
+ .sandbox-record-code-copy,
256
+ .sandbox-record-item {
257
+ transition: none;
258
+ }
259
+ }