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,83 @@
1
+ import * as React from 'react'
2
+ import { Button, cn } from '@chatluna/ui-kit'
3
+ import type { SandboxRelationshipRequest } from '../../src/types'
4
+ import { useT } from '../i18n'
5
+ import { SandboxAvatar } from '../shared/avatar'
6
+ import { errorText } from '../workspace/store'
7
+ import { useSandbox, useWorkspace } from '../workspace/context'
8
+ import type { IncomingNotificationRequests } from '../webqq/notification-requests'
9
+
10
+ function formatNoticeTime(value: string) {
11
+ const date = new Date(value)
12
+ const pad = (part: number) => String(part).padStart(2, '0')
13
+ return `${pad(date.getMonth() + 1)}/${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
14
+ }
15
+
16
+ /** 通知面板:只列出发给当前操作者的好友申请与群通知,逐条同意或拒绝。 */
17
+ export function NotificationList({ requests }: { requests: IncomingNotificationRequests }) {
18
+ const t = useT()
19
+ const { store } = useSandbox()
20
+ const { participants, snapshot } = useWorkspace()
21
+ const [tab, setTab] = React.useState<'friends' | 'groups'>('friends')
22
+ const [handling, setHandling] = React.useState('')
23
+ const [error, setError] = React.useState('')
24
+ const visible = tab === 'friends' ? requests.friends : requests.groups
25
+ const groupName = (id?: string) => snapshot.groups.find((group) => group.id === id)?.name ?? t('sandbox.notice.group')
26
+ const name = (id: string) => participants[id]?.name ?? id
27
+
28
+ const handle = async (request: SandboxRelationshipRequest, approve: boolean) => {
29
+ setHandling(request.id)
30
+ setError('')
31
+ try {
32
+ await store.handleRelationshipRequest(request.id, approve)
33
+ } catch (failure) {
34
+ setError(errorText(failure, t('sandbox.notice.failed')))
35
+ } finally {
36
+ setHandling('')
37
+ }
38
+ }
39
+
40
+ return (
41
+ <div className="flex max-h-96 flex-col">
42
+ <div className="flex gap-1 border-b border-border p-1.5">
43
+ {(['friends', 'groups'] as const).map((id) => (
44
+ <Button
45
+ key={id}
46
+ variant="ghost"
47
+ size="sm"
48
+ className={cn('flex-1', tab === id && 'bg-accent')}
49
+ onClick={() => setTab(id)}
50
+ >
51
+ {t(`sandbox.notice.${id}`)}
52
+ {(id === 'friends' ? requests.friends : requests.groups).length > 0 && (
53
+ <span className="ml-1 rounded-full bg-destructive px-1.5 text-[10px] leading-4 text-white">{(id === 'friends' ? requests.friends : requests.groups).length}</span>
54
+ )}
55
+ </Button>
56
+ ))}
57
+ </div>
58
+ <div className="min-h-0 flex-1 overflow-y-auto p-1.5">
59
+ {error && <p role="alert" className="px-2 py-1 text-xs text-destructive">{error}</p>}
60
+ {!visible.length && <p className="py-8 text-center text-xs text-muted-foreground">{t('sandbox.notice.empty')}</p>}
61
+ {visible.map((request) => (
62
+ <article key={request.id} className="flex items-start gap-2.5 rounded-lg p-2 hover:bg-accent/50">
63
+ <SandboxAvatar kind={participants[request.requesterId]?.isBot ? 'bot' : 'user'} name={name(request.requesterId)} src={participants[request.requesterId]?.avatar} className="size-8" />
64
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5">
65
+ <strong className="truncate text-[13px] font-medium">{request.type === 'friend' ? name(request.requesterId) : groupName(request.groupId)}</strong>
66
+ <span className="truncate text-xs text-muted-foreground">
67
+ {request.type === 'friend'
68
+ ? t('sandbox.notice.fromQQ', { id: request.requesterId })
69
+ : t(request.subType === 'invite' ? 'sandbox.notice.invite' : 'sandbox.notice.join', { name: name(request.requesterId) })}
70
+ </span>
71
+ {request.comment && <small className="truncate text-[11px] text-muted-foreground">{request.comment}</small>}
72
+ <time className="text-[11px] text-muted-foreground">{formatNoticeTime(request.createdAt)}</time>
73
+ </div>
74
+ <div className="flex shrink-0 gap-1">
75
+ <Button size="xs" disabled={handling === request.id} onClick={() => handle(request, true)}>{t('sandbox.notice.approve')}</Button>
76
+ <Button size="xs" variant="outline" disabled={handling === request.id} onClick={() => handle(request, false)}>{t('sandbox.notice.reject')}</Button>
77
+ </div>
78
+ </article>
79
+ ))}
80
+ </div>
81
+ </div>
82
+ )
83
+ }
@@ -0,0 +1,52 @@
1
+ import type { SandboxMessageReaction } from '../../src/types'
2
+ import { SandboxAvatar } from '../shared/avatar'
3
+ import { getSandboxEmojiFace } from '../webqq/emoji-catalog'
4
+ import { useWorkspace } from '../workspace/context'
5
+
6
+ const MAX_VISIBLE_AVATARS = 3
7
+
8
+ /**
9
+ * 表情回应条:每个表情一枚胶囊,带最多三位回应者头像;点一下切换当前操作者自己的回应。
10
+ * 样式在 `messages.css`,胶囊底色取所在气泡的派生色。
11
+ */
12
+ export function MessageReactions({ reactions, readonly, onToggle }: {
13
+ reactions: SandboxMessageReaction[]
14
+ readonly: boolean
15
+ onToggle(emojiId: string): void
16
+ }) {
17
+ const { participants } = useWorkspace()
18
+ return (
19
+ <div className="sandbox-message-reactions">
20
+ {reactions.map((reaction) => {
21
+ const face = getSandboxEmojiFace(reaction.emojiId)
22
+ const visible = reaction.participantIds.slice(0, MAX_VISIBLE_AVATARS)
23
+ return (
24
+ <button
25
+ key={reaction.emojiId}
26
+ type="button"
27
+ className="sandbox-message-reaction"
28
+ disabled={readonly}
29
+ aria-label={`${face?.label ?? reaction.emojiId} ${reaction.participantIds.length}`}
30
+ onClick={(event) => {
31
+ event.stopPropagation()
32
+ onToggle(reaction.emojiId)
33
+ }}
34
+ >
35
+ {face?.url
36
+ ? <img src={face.url} alt={face.label} className="sandbox-message-reaction-emoji" />
37
+ : <span>{face?.label ?? reaction.emojiId}</span>}
38
+ {visible.length > 0 && (
39
+ <span className="sandbox-message-reaction-users">
40
+ {visible.map((id, index) => (
41
+ <span key={id} title={participants[id]?.name ?? id} className="sandbox-message-reaction-avatar" style={{ zIndex: visible.length - index }}>
42
+ <SandboxAvatar kind={participants[id]?.isBot ? 'bot' : 'user'} name={participants[id]?.name ?? id} src={participants[id]?.avatar} className="size-full text-[9px]" badge={false} />
43
+ </span>
44
+ ))}
45
+ </span>
46
+ )}
47
+ </button>
48
+ )
49
+ })}
50
+ </div>
51
+ )
52
+ }
@@ -0,0 +1,231 @@
1
+ import * as React from 'react'
2
+ import { CalendarIcon, SearchIcon, XIcon } from 'lucide-react'
3
+ import { Button, Calendar, cn, InputGroup, InputGroupAddon, InputGroupInput, Popover, PopoverContent, PopoverTrigger } from '@chatluna/ui-kit'
4
+ import type { SandboxMessageSearchHit } from '../../src/types'
5
+ import { useT } from '../i18n'
6
+ import { SandboxAvatar } from '../shared/avatar'
7
+ import { formatMentionContent } from '../webqq/mention'
8
+ import { calendarValueToLocalDate, localDateToCalendarValue, localDateToMessageSearchRange } from '../webqq/message-search-date'
9
+ import { ensureMessageLoaded } from '../webqq/message-reveal'
10
+ import { errorText } from '../workspace/store'
11
+ import { useWorkspace } from '../workspace/context'
12
+
13
+ const PAGE_SIZE = 30
14
+
15
+ export interface MessageSearchAdapter {
16
+ conversationId?: string
17
+ search(input: { conversationId: string, query: string, createdAtStart?: string, createdAtEnd?: string, beforeMessageId?: string, limit: number }): Promise<{ hits: SandboxMessageSearchHit[], nextBeforeMessageId?: string }>
18
+ isLoaded(messageId: string): boolean
19
+ canLoadMore(): boolean
20
+ oldestLoadedId(): string | undefined
21
+ loadMore(): Promise<void>
22
+ reveal(messageId: string): boolean
23
+ }
24
+
25
+ /**
26
+ * 会话内查找:关键词防抖 250ms,可叠加按本地日历日筛选,也可只按日期查。
27
+ * 选中命中项时若消息还没加载,会持续向前翻历史直到加载到它,再滚动并高亮。
28
+ */
29
+ export function MessageSearchPanel({ adapter, onClose }: { adapter: MessageSearchAdapter, onClose(): void }) {
30
+ const t = useT()
31
+ const { participants, participantNames } = useWorkspace()
32
+ const [query, setQuery] = React.useState('')
33
+ const [date, setDate] = React.useState('')
34
+ const [dateOpen, setDateOpen] = React.useState(false)
35
+ const [loading, setLoading] = React.useState(false)
36
+ const [error, setError] = React.useState('')
37
+ const [hits, setHits] = React.useState<SandboxMessageSearchHit[]>([])
38
+ const [next, setNext] = React.useState<string>()
39
+ const [active, setActive] = React.useState('')
40
+ const [revealing, setRevealing] = React.useState('')
41
+ const serial = React.useRef(0)
42
+ const criteria = React.useRef<{ query: string, createdAtStart?: string, createdAtEnd?: string }>({ query: '' })
43
+ const input = React.useRef<HTMLInputElement>(null)
44
+ const latest = React.useRef(adapter)
45
+ latest.current = adapter
46
+
47
+ React.useEffect(() => input.current?.focus(), [])
48
+
49
+ const run = React.useCallback(async (text: string, localDate: string) => {
50
+ const conversationId = latest.current.conversationId
51
+ const range = localDate ? localDateToMessageSearchRange(localDate) : undefined
52
+ const requested = ++serial.current
53
+ criteria.current = { query: text, ...range }
54
+ setActive('')
55
+ setHits([])
56
+ setNext(undefined)
57
+ setError('')
58
+ if (!conversationId || (!text && !range)) return setLoading(false)
59
+ if (localDate && !range) {
60
+ setLoading(false)
61
+ return setError(t('sandbox.search.invalidDate'))
62
+ }
63
+ setLoading(true)
64
+ try {
65
+ const result = await latest.current.search({ conversationId, ...criteria.current, limit: PAGE_SIZE })
66
+ if (requested !== serial.current) return
67
+ setHits(result.hits)
68
+ setNext(result.nextBeforeMessageId)
69
+ } catch (failure) {
70
+ if (requested === serial.current) setError(errorText(failure, t('sandbox.search.failed')))
71
+ } finally {
72
+ if (requested === serial.current) setLoading(false)
73
+ }
74
+ }, [t])
75
+
76
+ React.useEffect(() => {
77
+ const text = query.trim()
78
+ if (!text) {
79
+ void run('', date)
80
+ return
81
+ }
82
+ const timer = setTimeout(() => void run(text, date), 250)
83
+ return () => clearTimeout(timer)
84
+ }, [query, date, run])
85
+
86
+ const loadMore = async () => {
87
+ const conversationId = adapter.conversationId
88
+ if (!conversationId || !next || loading) return
89
+ const requested = ++serial.current
90
+ setLoading(true)
91
+ setError('')
92
+ try {
93
+ const result = await adapter.search({ conversationId, ...criteria.current, beforeMessageId: next, limit: PAGE_SIZE })
94
+ if (requested !== serial.current) return
95
+ setHits((current) => {
96
+ const known = new Set(current.map(({ messageId }) => messageId))
97
+ return [...current, ...result.hits.filter(({ messageId }) => !known.has(messageId))]
98
+ })
99
+ setNext(result.nextBeforeMessageId)
100
+ } catch (failure) {
101
+ if (requested === serial.current) setError(errorText(failure, t('sandbox.search.failed')))
102
+ } finally {
103
+ if (requested === serial.current) setLoading(false)
104
+ }
105
+ }
106
+
107
+ const reveal = async (hit: SandboxMessageSearchHit) => {
108
+ if (revealing) return
109
+ setRevealing(hit.messageId)
110
+ setError('')
111
+ try {
112
+ const loaded = await ensureMessageLoaded({
113
+ messageId: hit.messageId,
114
+ isLoaded: () => latest.current.isLoaded(hit.messageId),
115
+ canLoadMore: () => latest.current.canLoadMore(),
116
+ getOldestLoadedMessageId: () => latest.current.oldestLoadedId(),
117
+ loadMore: () => latest.current.loadMore(),
118
+ })
119
+ if (!loaded) return setError(t('sandbox.search.notLoaded'))
120
+ await new Promise((resolve) => requestAnimationFrame(resolve))
121
+ if (!latest.current.reveal(hit.messageId)) return setError(t('sandbox.search.notFound'))
122
+ setActive(hit.messageId)
123
+ } catch (failure) {
124
+ setError(errorText(failure, t('sandbox.search.revealFailed')))
125
+ } finally {
126
+ setRevealing('')
127
+ }
128
+ }
129
+
130
+ const status = error
131
+ || (loading && !hits.length ? t('sandbox.search.searching') : '')
132
+ || (revealing ? t('sandbox.search.revealing') : '')
133
+ || (!loading && !hits.length ? t('sandbox.search.empty') : '')
134
+ const today = new Date()
135
+
136
+ return (
137
+ // 标题栏变窄时搜索框先收缩,不把会话标题挤没。
138
+ <section role="search" aria-label={t('sandbox.search.label')} className="relative w-72 min-w-36 shrink">
139
+ <InputGroup className="h-8">
140
+ <InputGroupAddon><SearchIcon /></InputGroupAddon>
141
+ <InputGroupInput
142
+ ref={input}
143
+ type="search"
144
+ value={query}
145
+ autoComplete="off"
146
+ className="sandbox-search-input text-[13px]!"
147
+ placeholder={t('sandbox.search.placeholder')}
148
+ aria-label={t('sandbox.search.input')}
149
+ onChange={(event) => setQuery(event.target.value)}
150
+ onKeyDown={(event) => {
151
+ if (event.key !== 'Escape' || dateOpen) return
152
+ event.preventDefault()
153
+ event.stopPropagation()
154
+ onClose()
155
+ }}
156
+ />
157
+ <InputGroupAddon align="inline-end" className="gap-0.5">
158
+ <Popover open={dateOpen} onOpenChange={setDateOpen}>
159
+ <PopoverTrigger render={(
160
+ <Button variant="ghost" size="icon-xs" className={cn(date && 'text-primary')} aria-pressed={!!date} aria-label={date ? t('sandbox.search.dateCurrent', { date }) : t('sandbox.search.date')} />
161
+ )}>
162
+ <CalendarIcon />
163
+ </PopoverTrigger>
164
+ <PopoverContent align="end" className="sandbox-glass w-auto p-0">
165
+ <Calendar
166
+ mode="single"
167
+ captionLayout="dropdown"
168
+ startMonth={new Date(today.getFullYear() - 9, 0)}
169
+ endMonth={today}
170
+ selected={localDateToCalendarValue(date)}
171
+ onSelect={(value) => {
172
+ setDate(calendarValueToLocalDate(value))
173
+ setDateOpen(false)
174
+ }}
175
+ />
176
+ </PopoverContent>
177
+ </Popover>
178
+ <Button
179
+ variant="ghost"
180
+ size="icon-xs"
181
+ aria-label={query || date ? t('sandbox.search.clear') : t('sandbox.search.close')}
182
+ onClick={() => {
183
+ if (query || date) {
184
+ setQuery('')
185
+ setDate('')
186
+ input.current?.focus()
187
+ } else onClose()
188
+ }}
189
+ >
190
+ <XIcon />
191
+ </Button>
192
+ </InputGroupAddon>
193
+ </InputGroup>
194
+ {(query.trim() || date) && (
195
+ <div className="absolute top-10 right-0 z-30 flex max-h-96 w-80 flex-col gap-0.5 overflow-y-auto rounded-xl sandbox-search-results p-1.5 text-popover-foreground shadow-popup ring-1 ring-border" role="listbox" aria-label={t('sandbox.search.results')}>
196
+ {status && <p role="status" aria-live="polite" className="px-2 py-3 text-center text-xs text-muted-foreground">{status}</p>}
197
+ {hits.map((hit) => {
198
+ const author = participants[hit.authorId] ?? { name: hit.authorId, isBot: false }
199
+ return (
200
+ <button
201
+ key={hit.messageId}
202
+ type="button"
203
+ role="option"
204
+ aria-selected={active === hit.messageId}
205
+ disabled={!!revealing}
206
+ className={cn('flex items-start gap-2.5 rounded-lg px-2 py-1.5 text-left hover:bg-accent disabled:opacity-60', active === hit.messageId && 'bg-accent')}
207
+ onClick={() => reveal(hit)}
208
+ >
209
+ <SandboxAvatar kind={author.isBot ? 'bot' : 'user'} name={author.name} src={author.avatar} className="size-7" />
210
+ <span className="flex min-w-0 flex-1 flex-col">
211
+ <span className="flex items-center gap-2">
212
+ <strong className="truncate text-xs font-medium">{author.name}</strong>
213
+ <time className="ml-auto shrink-0 text-[11px] text-muted-foreground" dateTime={hit.createdAt}>
214
+ {new Intl.DateTimeFormat(undefined, { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }).format(new Date(hit.createdAt))}
215
+ </time>
216
+ </span>
217
+ <span className="line-clamp-2 text-xs text-muted-foreground">{formatMentionContent(hit.summary, participantNames)}</span>
218
+ </span>
219
+ </button>
220
+ )
221
+ })}
222
+ {next && hits.length > 0 && (
223
+ <Button variant="ghost" size="sm" disabled={loading || !!revealing} onClick={loadMore}>
224
+ {loading ? t('sandbox.common.loading') : t('sandbox.search.more')}
225
+ </Button>
226
+ )}
227
+ </div>
228
+ )}
229
+ </section>
230
+ )
231
+ }