chatluna-plugin-onebot-sandbox 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/client/app.tsx +306 -0
- package/client/chat/chat-pane.tsx +303 -0
- package/client/chat/composer.css +635 -0
- package/client/chat/composer.tsx +646 -0
- package/client/chat/details-panel.tsx +196 -0
- package/client/chat/emoji-picker.tsx +70 -0
- package/client/chat/extension-mark.tsx +16 -0
- package/client/chat/forward.tsx +257 -0
- package/client/chat/image-preview.tsx +93 -0
- package/client/chat/member-menu.tsx +64 -0
- package/client/chat/message-list.tsx +617 -0
- package/client/chat/messages.css +1018 -0
- package/client/chat/notifications.tsx +83 -0
- package/client/chat/reactions.tsx +52 -0
- package/client/chat/search-panel.tsx +231 -0
- package/client/chat/sidebar.tsx +424 -0
- package/client/chat/webqq-view.tsx +71 -0
- package/client/environment/avatar-picker.tsx +92 -0
- package/client/environment/create-popover.tsx +228 -0
- package/client/environment/directory-model.ts +63 -0
- package/client/environment/entity-dialog.css +383 -0
- package/client/environment/entity-dialog.tsx +442 -0
- package/client/environment/page.css +14 -0
- package/client/environment/page.tsx +280 -0
- package/client/i18n.ts +19 -0
- package/client/index.ts +17 -0
- package/client/locales/en.yml +617 -0
- package/client/locales/zh.yml +617 -0
- package/client/mcp/capability-catalog.tsx +277 -0
- package/client/mcp/credential-manager.tsx +257 -0
- package/client/onebot-debug/page.tsx +329 -0
- package/client/records/record-layout.tsx +429 -0
- package/client/records/records.css +259 -0
- package/client/settings/about.tsx +43 -0
- package/client/settings/draft.ts +47 -0
- package/client/settings/localize.ts +76 -0
- package/client/settings/page.tsx +210 -0
- package/client/settings/settings.css +47 -0
- package/client/shared/avatar.tsx +35 -0
- package/client/shared/confirm-dialog.tsx +44 -0
- package/client/shared/controls.css +17 -0
- package/client/shared/discard-confirm.tsx +45 -0
- package/client/shared/floating-panel.ts +40 -0
- package/client/shared/format-duration.ts +22 -0
- package/client/shared/format-time.ts +49 -0
- package/client/shared/glass.css +150 -0
- package/client/shared/implementation.ts +12 -0
- package/client/shared/overlay-scrollbar.css +45 -0
- package/client/shared/overlay-scrollbar.tsx +123 -0
- package/client/shared/use-element-width.ts +19 -0
- package/client/shared/use-retained.ts +12 -0
- package/client/test-call/page.tsx +260 -0
- package/client/test-space/agent-visuals.tsx +121 -0
- package/client/test-space/observe-overlay.tsx +42 -0
- package/client/test-space/overview.tsx +267 -0
- package/client/test-space/spaces.css +201 -0
- package/client/test-space/thumbnail-capture.ts +63 -0
- package/client/test-space/thumbnail-scale.ts +21 -0
- package/client/test-space/use-space-list.ts +35 -0
- package/client/test-space/zoom.ts +197 -0
- package/client/webqq/composer-draft-host.ts +578 -0
- package/client/webqq/composer-draft.ts +81 -0
- package/client/webqq/conversation-tree.ts +155 -0
- package/client/webqq/emoji-catalog.ts +78 -0
- package/client/webqq/fork-boundary.ts +28 -0
- package/client/webqq/forward-cluster.ts +20 -0
- package/client/webqq/forward-dialog-stack.ts +74 -0
- package/client/webqq/forward-preview.ts +40 -0
- package/client/webqq/friend-menu.ts +17 -0
- package/client/webqq/group-display.ts +18 -0
- package/client/webqq/group-menu.ts +25 -0
- package/client/webqq/mention.ts +4 -0
- package/client/webqq/message-capabilities.ts +37 -0
- package/client/webqq/message-cluster.ts +68 -0
- package/client/webqq/message-presentation.ts +197 -0
- package/client/webqq/message-reveal.ts +31 -0
- package/client/webqq/message-search-date.ts +40 -0
- package/client/webqq/message-selection.ts +85 -0
- package/client/webqq/notification-requests.ts +20 -0
- package/client/webqq/participant-presentation.ts +128 -0
- package/client/webqq/profile-card.ts +199 -0
- package/client/webqq/relationship-directory.ts +62 -0
- package/client/webqq/thinking-panel.ts +7 -0
- package/client/webqq/user-stack.ts +53 -0
- package/client/workspace/agent-overlay-effect.ts +238 -0
- package/client/workspace/context.tsx +117 -0
- package/client/workspace/overlay-host.tsx +299 -0
- package/client/workspace/profile-card.css +164 -0
- package/client/workspace/state.ts +28 -0
- package/client/workspace/store.ts +388 -0
- package/client/workspace/use-test-spaces.ts +21 -0
- package/dist/.vite/manifest.json +21 -0
- package/dist/app-63rfTh6w.js +85 -0
- package/dist/client.css +4 -0
- package/dist/client.js +1 -0
- package/lib/account-profile.d.ts +17 -0
- package/lib/account-profile.d.ts.map +1 -0
- package/lib/base-dir.d.ts +4 -0
- package/lib/base-dir.d.ts.map +1 -0
- package/lib/bot.d.ts +185 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/builtin-avatar-options.d.ts +11 -0
- package/lib/builtin-avatar-options.d.ts.map +1 -0
- package/lib/builtin-avatars.d.ts +6 -0
- package/lib/builtin-avatars.d.ts.map +1 -0
- package/lib/channel-assignee.d.ts +52 -0
- package/lib/channel-assignee.d.ts.map +1 -0
- package/lib/chatluna/conversation-lines.d.ts +46 -0
- package/lib/chatluna/conversation-lines.d.ts.map +1 -0
- package/lib/chatluna/runtime.d.ts +26 -0
- package/lib/chatluna/runtime.d.ts.map +1 -0
- package/lib/chatluna/state.d.ts +67 -0
- package/lib/chatluna/state.d.ts.map +1 -0
- package/lib/chatluna/thinking.d.ts +10 -0
- package/lib/chatluna/thinking.d.ts.map +1 -0
- package/lib/chatluna/tools.d.ts +36 -0
- package/lib/chatluna/tools.d.ts.map +1 -0
- package/lib/chatluna/wakeup.d.ts +143 -0
- package/lib/chatluna/wakeup.d.ts.map +1 -0
- package/lib/console-contract.d.ts +131 -0
- package/lib/console-contract.d.ts.map +1 -0
- package/lib/console.d.ts +31 -0
- package/lib/console.d.ts.map +1 -0
- package/lib/control-service.d.ts +425 -0
- package/lib/control-service.d.ts.map +1 -0
- package/lib/conversation-resolution.d.ts +157 -0
- package/lib/conversation-resolution.d.ts.map +1 -0
- package/lib/error-detail.d.ts +3 -0
- package/lib/error-detail.d.ts.map +1 -0
- package/lib/inbound-delivery.d.ts +156 -0
- package/lib/inbound-delivery.d.ts.map +1 -0
- package/lib/index.d.ts +76 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12834 -0
- package/lib/index.js.map +1 -0
- package/lib/lifecycle.d.ts +8 -0
- package/lib/lifecycle.d.ts.map +1 -0
- package/lib/mcp/arguments.d.ts +71 -0
- package/lib/mcp/arguments.d.ts.map +1 -0
- package/lib/mcp/call-records.d.ts +32 -0
- package/lib/mcp/call-records.d.ts.map +1 -0
- package/lib/mcp/http-api.d.ts +147 -0
- package/lib/mcp/http-api.d.ts.map +1 -0
- package/lib/mcp/page-cursor.d.ts +37 -0
- package/lib/mcp/page-cursor.d.ts.map +1 -0
- package/lib/mcp/server.d.ts +60 -0
- package/lib/mcp/server.d.ts.map +1 -0
- package/lib/mcp/service.d.ts +219 -0
- package/lib/mcp/service.d.ts.map +1 -0
- package/lib/mcp/tool-registry.d.ts +113 -0
- package/lib/mcp/tool-registry.d.ts.map +1 -0
- package/lib/mcp/types.d.ts +144 -0
- package/lib/mcp/types.d.ts.map +1 -0
- package/lib/media-storage.d.ts +33 -0
- package/lib/media-storage.d.ts.map +1 -0
- package/lib/message-capabilities.d.ts +78 -0
- package/lib/message-capabilities.d.ts.map +1 -0
- package/lib/onebot-debug.d.ts +115 -0
- package/lib/onebot-debug.d.ts.map +1 -0
- package/lib/onebot-message.d.ts +23 -0
- package/lib/onebot-message.d.ts.map +1 -0
- package/lib/onebot-profiles.d.ts +45 -0
- package/lib/onebot-profiles.d.ts.map +1 -0
- package/lib/persistence.d.ts +148 -0
- package/lib/persistence.d.ts.map +1 -0
- package/lib/random.d.ts +5 -0
- package/lib/random.d.ts.map +1 -0
- package/lib/record-store.d.ts +80 -0
- package/lib/record-store.d.ts.map +1 -0
- package/lib/relationship-actions.d.ts +157 -0
- package/lib/relationship-actions.d.ts.map +1 -0
- package/lib/scope-directory.d.ts +105 -0
- package/lib/scope-directory.d.ts.map +1 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/test-spaces.d.ts +69 -0
- package/lib/test-spaces.d.ts.map +1 -0
- package/lib/types.d.ts +739 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/webui.d.ts +26 -0
- package/lib/webui.d.ts.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
ArrowDownToLineIcon,
|
|
4
|
+
ArrowUpToLineIcon,
|
|
5
|
+
AtSignIcon,
|
|
6
|
+
BellIcon,
|
|
7
|
+
CheckIcon,
|
|
8
|
+
ChevronRightIcon,
|
|
9
|
+
ClockIcon,
|
|
10
|
+
CornerUpLeftIcon,
|
|
11
|
+
ExternalLinkIcon,
|
|
12
|
+
GitBranchIcon,
|
|
13
|
+
HandIcon,
|
|
14
|
+
IdCardIcon,
|
|
15
|
+
ListChecksIcon,
|
|
16
|
+
PaperclipIcon,
|
|
17
|
+
ReplyIcon,
|
|
18
|
+
SmilePlusIcon,
|
|
19
|
+
TagIcon,
|
|
20
|
+
Trash2Icon,
|
|
21
|
+
UserMinusIcon,
|
|
22
|
+
UserPlusIcon,
|
|
23
|
+
UsersIcon,
|
|
24
|
+
} from 'lucide-react'
|
|
25
|
+
import {
|
|
26
|
+
cn,
|
|
27
|
+
ContextMenu,
|
|
28
|
+
ContextMenuContent,
|
|
29
|
+
ContextMenuItem,
|
|
30
|
+
ContextMenuSeparator,
|
|
31
|
+
ContextMenuSub,
|
|
32
|
+
ContextMenuSubContent,
|
|
33
|
+
ContextMenuSubTrigger,
|
|
34
|
+
ContextMenuTrigger,
|
|
35
|
+
} from '@chatluna/ui-kit'
|
|
36
|
+
import type { MessageCapabilities } from '../../src/message-capabilities'
|
|
37
|
+
import { useNavigate } from 'react-router'
|
|
38
|
+
import { isRecalledMessage, type SandboxMessage, type SandboxMessageTraceReference } from '../../src/types'
|
|
39
|
+
import { useT } from '../i18n'
|
|
40
|
+
import { SandboxAvatar } from '../shared/avatar'
|
|
41
|
+
import { formatSandboxTimeOfDay } from '../shared/format-time'
|
|
42
|
+
import { OverlayScrollbar } from '../shared/overlay-scrollbar'
|
|
43
|
+
import { getMessageClusterClass, isMergedMessage } from '../webqq/message-cluster'
|
|
44
|
+
import {
|
|
45
|
+
formatMediaSize,
|
|
46
|
+
getEventMessageText,
|
|
47
|
+
getForwardPreview,
|
|
48
|
+
getMessageText,
|
|
49
|
+
getMessageThinking,
|
|
50
|
+
getMessageUsage,
|
|
51
|
+
getReplyMessage,
|
|
52
|
+
isForkBoundary,
|
|
53
|
+
isInheritedMessage,
|
|
54
|
+
readMessageCapabilities,
|
|
55
|
+
resolveReactionToggle,
|
|
56
|
+
shouldRenderAsEvent,
|
|
57
|
+
shouldShowThinking,
|
|
58
|
+
shouldShowUsage,
|
|
59
|
+
type MessagePresentationContext,
|
|
60
|
+
} from '../webqq/message-presentation'
|
|
61
|
+
import {
|
|
62
|
+
getChatFriendActions,
|
|
63
|
+
getCurrentGroupMember,
|
|
64
|
+
getFriendMenuStateOf,
|
|
65
|
+
getMessageAuthorName,
|
|
66
|
+
getMessageGroupMemberActions,
|
|
67
|
+
getMessageRoleBadge,
|
|
68
|
+
hasGroupMemberManagementActions,
|
|
69
|
+
type ParticipantPresentationContext,
|
|
70
|
+
} from '../webqq/participant-presentation'
|
|
71
|
+
import { formatThinkingDuration } from '../webqq/thinking-panel'
|
|
72
|
+
import type { SandboxChatLunaState, SandboxForwardPreview } from '../../src/types'
|
|
73
|
+
import type { FriendMenuState } from '../webqq/friend-menu'
|
|
74
|
+
import { useSandbox, useWorkspace } from '../workspace/context'
|
|
75
|
+
import { ExtensionMark } from './extension-mark'
|
|
76
|
+
import { GroupMemberMenuItems } from './member-menu'
|
|
77
|
+
import { MessageReactions } from './reactions'
|
|
78
|
+
import './messages.css'
|
|
79
|
+
|
|
80
|
+
export interface MessageListHandle {
|
|
81
|
+
revealMessage(messageId: string): boolean
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface MessageListProps {
|
|
85
|
+
messages: SandboxMessage[]
|
|
86
|
+
chatLunaStates: SandboxChatLunaState[]
|
|
87
|
+
replyMessages: Record<string, SandboxMessage>
|
|
88
|
+
forwardPreviews: Record<string, SandboxForwardPreview>
|
|
89
|
+
capabilities: Record<string, MessageCapabilities>
|
|
90
|
+
friendMenuStates: Record<string, FriendMenuState>
|
|
91
|
+
hasMoreMessages: boolean
|
|
92
|
+
scrollKey: string
|
|
93
|
+
/** 悬浮发送框占住的底部高度;内容区按它留白,置底时末条消息不被发送框遮住。 */
|
|
94
|
+
bottomSpace?: number
|
|
95
|
+
selectionMode: boolean
|
|
96
|
+
selectedIds: string[]
|
|
97
|
+
onReply(messageId: string): void
|
|
98
|
+
onBranch(messageId: string): void
|
|
99
|
+
onRecall(messageId: string): void
|
|
100
|
+
onReact(messageId: string, emojiId: string, enabled: boolean): void
|
|
101
|
+
onOpenReactionPicker(messageId: string): void
|
|
102
|
+
onEnterSelection(messageId: string): void
|
|
103
|
+
onToggleSelection(messageId: string): void
|
|
104
|
+
onOpenForward(input: { messageId: string, forwardId: string }): void
|
|
105
|
+
onOpenImage(url: string): void
|
|
106
|
+
onLoadHistory(): Promise<void>
|
|
107
|
+
onClearConversation(): void
|
|
108
|
+
onMention(participantId: string): void
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 每个会话最后一次离开时的滚动位置;贴底离开时只记贴底,回来照样贴底。 */
|
|
112
|
+
const scrollMemory = new Map<string, { top: number, bottom: boolean }>()
|
|
113
|
+
const BOTTOM_THRESHOLD = 48
|
|
114
|
+
|
|
115
|
+
export const MessageList = React.forwardRef<MessageListHandle, MessageListProps>(function MessageList(props, ref) {
|
|
116
|
+
const t = useT()
|
|
117
|
+
const navigate = useNavigate()
|
|
118
|
+
const { store, run, dialogs } = useSandbox()
|
|
119
|
+
const { conversation, group, peer, operatorId, participants, participantNames, resolveAvatar, media, mediaFailures, workspace } = useWorkspace()
|
|
120
|
+
const markRecalled = workspace.appearance.sandboxMarkRecalledMessages
|
|
121
|
+
const bubbleTail = workspace.appearance.sandboxTimBubbleTail
|
|
122
|
+
const bubbleOutline = workspace.appearance.sandboxIncomingBubbleStyle === 'outline'
|
|
123
|
+
const box = React.useRef<HTMLDivElement>(null)
|
|
124
|
+
const content = React.useRef<HTMLOListElement>(null)
|
|
125
|
+
const sticky = React.useRef(true)
|
|
126
|
+
/** 上一次滚动事件时的 scrollTop;只有它变小(用户往上滚)才解除贴底。 */
|
|
127
|
+
const lastTop = React.useRef(0)
|
|
128
|
+
const anchor = React.useRef<{ messageId: string, offset: number } | undefined>(undefined)
|
|
129
|
+
const [historyLoading, setHistoryLoading] = React.useState(false)
|
|
130
|
+
const [highlighted, setHighlighted] = React.useState('')
|
|
131
|
+
const [expandedThinking, setExpandedThinking] = React.useState<Record<string, boolean>>({})
|
|
132
|
+
const highlightTimer = React.useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
133
|
+
|
|
134
|
+
const presentation: MessagePresentationContext & ParticipantPresentationContext = {
|
|
135
|
+
replyMessages: props.replyMessages,
|
|
136
|
+
forwardPreviews: props.forwardPreviews,
|
|
137
|
+
messageCapabilities: props.capabilities,
|
|
138
|
+
participantNames,
|
|
139
|
+
markRecalledMessages: markRecalled,
|
|
140
|
+
currentConversationId: conversation?.id,
|
|
141
|
+
currentOperatorId: operatorId,
|
|
142
|
+
participants,
|
|
143
|
+
friendMenuStates: props.friendMenuStates,
|
|
144
|
+
currentGroup: group,
|
|
145
|
+
}
|
|
146
|
+
const authorName = (id: string) => getMessageAuthorName(id, presentation)
|
|
147
|
+
|
|
148
|
+
const scrollToBottom = () => {
|
|
149
|
+
const element = box.current
|
|
150
|
+
if (element) element.scrollTop = element.scrollHeight
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 切换会话:恢复上次离开时的位置,没有记录或离开时贴底就贴底。
|
|
154
|
+
React.useLayoutEffect(() => {
|
|
155
|
+
const memory = scrollMemory.get(props.scrollKey)
|
|
156
|
+
sticky.current = !memory || memory.bottom
|
|
157
|
+
if (sticky.current) scrollToBottom()
|
|
158
|
+
else if (box.current) box.current.scrollTop = memory!.top
|
|
159
|
+
lastTop.current = box.current?.scrollTop ?? 0
|
|
160
|
+
const key = props.scrollKey
|
|
161
|
+
const element = box.current
|
|
162
|
+
return () => {
|
|
163
|
+
if (element) scrollMemory.set(key, { top: element.scrollTop, bottom: sticky.current })
|
|
164
|
+
}
|
|
165
|
+
}, [props.scrollKey])
|
|
166
|
+
|
|
167
|
+
const tail = `${props.messages.at(-1)?.id ?? ''}:${props.messages.length}:${props.chatLunaStates.filter(({ thinking }) => thinking).length}`
|
|
168
|
+
React.useLayoutEffect(() => {
|
|
169
|
+
const element = box.current
|
|
170
|
+
if (!element) return
|
|
171
|
+
// 加载更早历史后按加载前的锚点补偿,画面不跳。
|
|
172
|
+
const pending = anchor.current
|
|
173
|
+
if (pending) {
|
|
174
|
+
anchor.current = undefined
|
|
175
|
+
const row = element.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(pending.messageId)}"]`)
|
|
176
|
+
if (row) element.scrollTop += row.getBoundingClientRect().top - element.getBoundingClientRect().top - pending.offset
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
if (sticky.current) scrollToBottom()
|
|
180
|
+
}, [tail])
|
|
181
|
+
|
|
182
|
+
// 图片、视频加载会撑高内容;仍在贴底时跟着贴底。
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
const element = content.current
|
|
185
|
+
if (!element || typeof ResizeObserver === 'undefined') return
|
|
186
|
+
const observer = new ResizeObserver(() => {
|
|
187
|
+
if (sticky.current) scrollToBottom()
|
|
188
|
+
})
|
|
189
|
+
observer.observe(element)
|
|
190
|
+
return () => observer.disconnect()
|
|
191
|
+
}, [props.scrollKey, props.messages.length > 0])
|
|
192
|
+
|
|
193
|
+
// 程序置底后的滚动事件下一帧才派发,期间图片加载会把内容撑高;只看离底距离会把这次长高误判成
|
|
194
|
+
// 用户离开底部,ResizeObserver 随之不再跟随。内容长高不会让 scrollTop 变小,用户往上滚才会。
|
|
195
|
+
const handleScroll = () => {
|
|
196
|
+
const element = box.current
|
|
197
|
+
if (!element) return
|
|
198
|
+
const top = element.scrollTop
|
|
199
|
+
if (element.scrollHeight - top - element.clientHeight < BOTTOM_THRESHOLD) sticky.current = true
|
|
200
|
+
else if (top < lastTop.current) sticky.current = false
|
|
201
|
+
lastTop.current = top
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const loadEarlier = async () => {
|
|
205
|
+
const element = box.current
|
|
206
|
+
if (historyLoading || !element) return
|
|
207
|
+
const first = element.querySelector<HTMLElement>('[data-message-id]')
|
|
208
|
+
if (first) anchor.current = { messageId: first.dataset['messageId'] ?? '', offset: first.getBoundingClientRect().top - element.getBoundingClientRect().top }
|
|
209
|
+
sticky.current = false
|
|
210
|
+
setHistoryLoading(true)
|
|
211
|
+
try {
|
|
212
|
+
await props.onLoadHistory()
|
|
213
|
+
} catch {
|
|
214
|
+
anchor.current = undefined
|
|
215
|
+
} finally {
|
|
216
|
+
setHistoryLoading(false)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const revealMessage = (messageId: string) => {
|
|
221
|
+
const element = box.current
|
|
222
|
+
const row = element?.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(messageId)}"]`)
|
|
223
|
+
if (!element || !row) return false
|
|
224
|
+
sticky.current = false
|
|
225
|
+
row.scrollIntoView({ block: 'center', behavior: 'smooth' })
|
|
226
|
+
setHighlighted(messageId)
|
|
227
|
+
clearTimeout(highlightTimer.current)
|
|
228
|
+
highlightTimer.current = setTimeout(() => setHighlighted(''), 1600)
|
|
229
|
+
return true
|
|
230
|
+
}
|
|
231
|
+
React.useImperativeHandle(ref, () => ({ revealMessage }))
|
|
232
|
+
React.useEffect(() => () => clearTimeout(highlightTimer.current), [])
|
|
233
|
+
|
|
234
|
+
const thinkingStates = props.chatLunaStates.filter(({ thinking }) => thinking)
|
|
235
|
+
const empty = !props.messages.length && !thinkingStates.length
|
|
236
|
+
const peerKind = group ? 'group' : participants[conversation?.participantIds?.find((id) => id !== operatorId) ?? '']?.isBot ? 'bot' : 'user'
|
|
237
|
+
|
|
238
|
+
const friendAction = (input: Parameters<typeof store.performFriendAction>[0]) => run(t('sandbox.error.friend'), () => store.performFriendAction(input))
|
|
239
|
+
|
|
240
|
+
const renderMedia = (message: SandboxMessage) => message.media?.map((item) => {
|
|
241
|
+
const source = media[item.id]
|
|
242
|
+
return (
|
|
243
|
+
<div key={item.id} className="sandbox-message-media">
|
|
244
|
+
{!source ? (
|
|
245
|
+
<span className="sandbox-message-media-loading">{mediaFailures[item.id] ? t('sandbox.media.unavailable') : t('sandbox.media.loading')}</span>
|
|
246
|
+
) : item.type === 'image' ? (
|
|
247
|
+
<button type="button" className="sandbox-message-image" aria-label={t('sandbox.media.viewImage')} onClick={(event) => {
|
|
248
|
+
if (props.selectionMode) return
|
|
249
|
+
event.stopPropagation()
|
|
250
|
+
props.onOpenImage(source)
|
|
251
|
+
}}>
|
|
252
|
+
<img src={source} alt={item.name} />
|
|
253
|
+
</button>
|
|
254
|
+
) : item.type === 'audio' ? (
|
|
255
|
+
<audio src={source} controls preload="metadata" />
|
|
256
|
+
) : item.type === 'video' ? (
|
|
257
|
+
<video src={source} controls preload="metadata" />
|
|
258
|
+
) : (
|
|
259
|
+
<a href={source} download={item.name} className="sandbox-message-file">
|
|
260
|
+
<PaperclipIcon className="size-[18px]" />
|
|
261
|
+
<span><strong>{item.name}</strong><small>{formatMediaSize(item.size)}</small></span>
|
|
262
|
+
</a>
|
|
263
|
+
)}
|
|
264
|
+
</div>
|
|
265
|
+
)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<>
|
|
270
|
+
<ContextMenu disabled={props.selectionMode || !conversation}>
|
|
271
|
+
<ContextMenuTrigger
|
|
272
|
+
render={(
|
|
273
|
+
<div
|
|
274
|
+
ref={box}
|
|
275
|
+
className="sandbox-message-scroller min-h-0 flex-1 overflow-y-auto overscroll-contain [overflow-anchor:none]"
|
|
276
|
+
aria-label={t('sandbox.chat.messages')}
|
|
277
|
+
onScroll={handleScroll}
|
|
278
|
+
/>
|
|
279
|
+
)}
|
|
280
|
+
>
|
|
281
|
+
{empty ? (
|
|
282
|
+
<div className="flex h-full flex-col items-center justify-center gap-2 px-6 text-center" style={{ paddingBottom: props.bottomSpace }}>
|
|
283
|
+
<SandboxAvatar kind={peerKind} name={conversation?.title ?? group?.name ?? peer?.name} src={resolveAvatar(group?.avatar ?? peer?.avatar)} className="size-14" />
|
|
284
|
+
{peerKind === 'bot' ? (
|
|
285
|
+
<>
|
|
286
|
+
<h2 className="mt-2 text-sm font-medium">{t('sandbox.chat.emptyBotTitle')}</h2>
|
|
287
|
+
<p className="text-xs text-muted-foreground">{t('sandbox.chat.emptyBotHint')}</p>
|
|
288
|
+
</>
|
|
289
|
+
) : (
|
|
290
|
+
<p className="text-xs text-muted-foreground">{t('sandbox.chat.emptyHint')}</p>
|
|
291
|
+
)}
|
|
292
|
+
</div>
|
|
293
|
+
) : (
|
|
294
|
+
<ol
|
|
295
|
+
ref={content}
|
|
296
|
+
className={cn('sandbox-message-list', bubbleTail && 'has-tail', bubbleOutline && 'has-outline', props.selectionMode && 'is-selecting')}
|
|
297
|
+
style={{ paddingBottom: props.bottomSpace }}
|
|
298
|
+
>
|
|
299
|
+
{props.hasMoreMessages && (
|
|
300
|
+
<li className="sandbox-message-history-row">
|
|
301
|
+
<button type="button" className="sandbox-message-history" disabled={historyLoading} onClick={loadEarlier}>
|
|
302
|
+
{historyLoading ? t('sandbox.common.loading') : t('sandbox.chat.earlier')}
|
|
303
|
+
</button>
|
|
304
|
+
</li>
|
|
305
|
+
)}
|
|
306
|
+
{props.messages.map((message, index) => {
|
|
307
|
+
const outgoing = message.authorId === operatorId
|
|
308
|
+
const direction = outgoing ? 'is-outgoing' : 'is-incoming'
|
|
309
|
+
const capabilities = readMessageCapabilities(message, presentation)
|
|
310
|
+
const merged = isMergedMessage(props.messages, index, operatorId)
|
|
311
|
+
const cluster = getMessageClusterClass(props.messages, index, operatorId)
|
|
312
|
+
const recalled = isRecalledMessage(message)
|
|
313
|
+
const inherited = isInheritedMessage(message, presentation)
|
|
314
|
+
const selected = props.selectedIds.includes(message.id)
|
|
315
|
+
const selectable = props.selectionMode && capabilities.forward
|
|
316
|
+
const reply = getReplyMessage(message, presentation)
|
|
317
|
+
const forward = getForwardPreview(message, presentation)
|
|
318
|
+
const text = getMessageText(message, presentation)
|
|
319
|
+
const badge = getMessageRoleBadge(message.authorId, presentation)
|
|
320
|
+
const isBot = participants[message.authorId]?.isBot
|
|
321
|
+
const thinking = shouldShowThinking(message, presentation) ? getMessageThinking(message) : undefined
|
|
322
|
+
const usage = !thinking && shouldShowUsage(message, presentation) ? getMessageUsage(message)?.usage : undefined
|
|
323
|
+
const boundary = isForkBoundary(props.messages, index, presentation)
|
|
324
|
+
|
|
325
|
+
const header = boundary && (
|
|
326
|
+
<li key={`${message.id}:boundary`} className="sandbox-message-fork-boundary">{t('sandbox.chat.forkBoundary')}</li>
|
|
327
|
+
)
|
|
328
|
+
if (shouldRenderAsEvent(message, presentation)) {
|
|
329
|
+
return (
|
|
330
|
+
<React.Fragment key={message.id}>
|
|
331
|
+
{header}
|
|
332
|
+
<li data-message-id={message.id} className="sandbox-message-event">
|
|
333
|
+
{getEventMessageText(message, authorName)}
|
|
334
|
+
</li>
|
|
335
|
+
</React.Fragment>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const avatarMenu = (
|
|
340
|
+
<ContextMenu disabled={props.selectionMode}>
|
|
341
|
+
<ContextMenuTrigger
|
|
342
|
+
render={(
|
|
343
|
+
<button
|
|
344
|
+
type="button"
|
|
345
|
+
className="sandbox-message-avatar-wrap"
|
|
346
|
+
aria-label={t('sandbox.chat.viewProfileOf', { name: authorName(message.authorId) })}
|
|
347
|
+
onClick={(event) => {
|
|
348
|
+
if (props.selectionMode) return
|
|
349
|
+
event.stopPropagation()
|
|
350
|
+
dialogs.openProfile(message.authorId, { x: event.clientX, y: event.clientY })
|
|
351
|
+
}}
|
|
352
|
+
onContextMenu={(event) => event.stopPropagation()}
|
|
353
|
+
/>
|
|
354
|
+
)}
|
|
355
|
+
>
|
|
356
|
+
<SandboxAvatar kind={isBot ? 'bot' : 'user'} name={authorName(message.authorId)} src={participants[message.authorId]?.avatar} className="size-8" />
|
|
357
|
+
</ContextMenuTrigger>
|
|
358
|
+
<ContextMenuContent className="sandbox-glass">
|
|
359
|
+
<ContextMenuItem onClick={() => dialogs.openProfile(message.authorId)}><IdCardIcon />{t('sandbox.menu.profile')}</ContextMenuItem>
|
|
360
|
+
{!outgoing && (
|
|
361
|
+
<>
|
|
362
|
+
{getMessageGroupMemberActions(message.authorId, presentation).includes('mention') && (
|
|
363
|
+
<ContextMenuItem onClick={() => props.onMention(message.authorId)}><AtSignIcon />{t('sandbox.member.mention')}</ContextMenuItem>
|
|
364
|
+
)}
|
|
365
|
+
{group && conversation && getMessageGroupMemberActions(message.authorId, presentation).includes('poke') && (
|
|
366
|
+
<ContextMenuItem onClick={() => run(t('sandbox.error.group'), () => store.performGroupAction({ action: 'poke', groupId: group.id, targetId: message.authorId, conversationId: conversation.id }))}>
|
|
367
|
+
<HandIcon />{t('sandbox.member.poke')}
|
|
368
|
+
</ContextMenuItem>
|
|
369
|
+
)}
|
|
370
|
+
{hasGroupMemberManagementActions(message.authorId, presentation) && (
|
|
371
|
+
<ContextMenuSub>
|
|
372
|
+
<ContextMenuSubTrigger><UsersIcon />{t('sandbox.member.manage')}</ContextMenuSubTrigger>
|
|
373
|
+
<ContextMenuSubContent className="sandbox-glass">
|
|
374
|
+
<GroupMemberMenuItems target={getCurrentGroupMember(message.authorId, presentation)!} managementOnly />
|
|
375
|
+
</ContextMenuSubContent>
|
|
376
|
+
</ContextMenuSub>
|
|
377
|
+
)}
|
|
378
|
+
{getChatFriendActions(message.authorId, presentation).includes('request') ? (
|
|
379
|
+
<ContextMenuItem onClick={() => friendAction({ action: 'request', targetId: message.authorId, comment: t('sandbox.friend.requestComment') })}>
|
|
380
|
+
<UserPlusIcon />{t('sandbox.menu.requestFriend')}<ExtensionMark />
|
|
381
|
+
</ContextMenuItem>
|
|
382
|
+
) : getFriendMenuStateOf(message.authorId, presentation).pendingOutgoing ? (
|
|
383
|
+
<ContextMenuItem disabled><ClockIcon />{t('sandbox.menu.waitingPeer')}</ContextMenuItem>
|
|
384
|
+
) : getFriendMenuStateOf(message.authorId, presentation).pendingIncoming ? (
|
|
385
|
+
<ContextMenuItem disabled><BellIcon />{t('sandbox.menu.handleInNotice')}</ContextMenuItem>
|
|
386
|
+
) : null}
|
|
387
|
+
{!group && conversation && getChatFriendActions(message.authorId, presentation).includes('poke') && (
|
|
388
|
+
<ContextMenuItem onClick={() => friendAction({ action: 'poke', targetId: message.authorId, conversationId: conversation.id })}><HandIcon />{t('sandbox.member.poke')}</ContextMenuItem>
|
|
389
|
+
)}
|
|
390
|
+
{!group && getChatFriendActions(message.authorId, presentation).includes('remark') && (
|
|
391
|
+
<ContextMenuItem onClick={() => dialogs.openRemark(message.authorId)}><TagIcon />{t('sandbox.menu.remark')}<ExtensionMark /></ContextMenuItem>
|
|
392
|
+
)}
|
|
393
|
+
{!group && getChatFriendActions(message.authorId, presentation).includes('delete') && (
|
|
394
|
+
<ContextMenuItem variant="destructive" onClick={() => friendAction({ action: 'delete', targetId: message.authorId })}><UserMinusIcon />{t('sandbox.menu.deleteFriend')}</ContextMenuItem>
|
|
395
|
+
)}
|
|
396
|
+
</>
|
|
397
|
+
)}
|
|
398
|
+
</ContextMenuContent>
|
|
399
|
+
</ContextMenu>
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
const bubble = (
|
|
403
|
+
<div
|
|
404
|
+
className="sandbox-message-bubble"
|
|
405
|
+
onClickCapture={(event) => {
|
|
406
|
+
if (!props.selectionMode || !selectable) return
|
|
407
|
+
event.preventDefault()
|
|
408
|
+
event.stopPropagation()
|
|
409
|
+
props.onToggleSelection(message.id)
|
|
410
|
+
}}
|
|
411
|
+
>
|
|
412
|
+
{reply && (
|
|
413
|
+
<button
|
|
414
|
+
type="button"
|
|
415
|
+
className="sandbox-message-quote"
|
|
416
|
+
aria-label={t('sandbox.chat.jumpToQuote')}
|
|
417
|
+
onClick={(event) => {
|
|
418
|
+
event.stopPropagation()
|
|
419
|
+
revealMessage(reply.id)
|
|
420
|
+
}}
|
|
421
|
+
>
|
|
422
|
+
<strong className="sandbox-message-quote-title">{authorName(reply.authorId)}</strong>
|
|
423
|
+
<span>{getMessageText(reply, presentation)}</span>
|
|
424
|
+
</button>
|
|
425
|
+
)}
|
|
426
|
+
{message.forwardId ? (
|
|
427
|
+
<button
|
|
428
|
+
type="button"
|
|
429
|
+
className="sandbox-message-quote sandbox-message-forward"
|
|
430
|
+
disabled={!forward}
|
|
431
|
+
aria-label={t('sandbox.forward.open')}
|
|
432
|
+
onClick={(event) => {
|
|
433
|
+
if (props.selectionMode || !forward || !message.forwardId) return
|
|
434
|
+
event.stopPropagation()
|
|
435
|
+
props.onOpenForward({ messageId: message.id, forwardId: message.forwardId })
|
|
436
|
+
}}
|
|
437
|
+
>
|
|
438
|
+
<strong className="sandbox-message-quote-title">{forward?.title || t('sandbox.forward.title')}</strong>
|
|
439
|
+
{forward ? (
|
|
440
|
+
<>
|
|
441
|
+
{forward.lines.map((line, lineIndex) => <span key={lineIndex}>{line}</span>)}
|
|
442
|
+
<span className="sandbox-message-forward-entry">{t('sandbox.forward.total', { count: forward.total })}<ChevronRightIcon className="size-4" /></span>
|
|
443
|
+
</>
|
|
444
|
+
) : <span>{text || t('sandbox.forward.placeholder')}</span>}
|
|
445
|
+
</button>
|
|
446
|
+
) : (
|
|
447
|
+
<>
|
|
448
|
+
{renderMedia(message)}
|
|
449
|
+
{text && <span className="sandbox-message-text">{text}</span>}
|
|
450
|
+
</>
|
|
451
|
+
)}
|
|
452
|
+
{recalled && <span className="sandbox-message-recalled-label">{t('sandbox.chat.recalled')}</span>}
|
|
453
|
+
{!!message.reactions?.length && (
|
|
454
|
+
<MessageReactions
|
|
455
|
+
reactions={message.reactions}
|
|
456
|
+
readonly={!capabilities.react}
|
|
457
|
+
onToggle={(emojiId) => {
|
|
458
|
+
const toggle = resolveReactionToggle(message, emojiId, presentation)
|
|
459
|
+
if (toggle) props.onReact(toggle.messageId, toggle.emojiId, toggle.enabled)
|
|
460
|
+
}}
|
|
461
|
+
/>
|
|
462
|
+
)}
|
|
463
|
+
</div>
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
const trace = message.chatLuna?.trace
|
|
467
|
+
const thinkingExpanded = !!expandedThinking[message.id]
|
|
468
|
+
return (
|
|
469
|
+
<React.Fragment key={message.id}>
|
|
470
|
+
{header}
|
|
471
|
+
<li
|
|
472
|
+
data-message-id={message.id}
|
|
473
|
+
aria-selected={props.selectionMode ? selected : undefined}
|
|
474
|
+
className={cn(
|
|
475
|
+
'sandbox-message-row',
|
|
476
|
+
direction,
|
|
477
|
+
cluster,
|
|
478
|
+
merged && 'is-merged',
|
|
479
|
+
highlighted === message.id && 'is-quote-target',
|
|
480
|
+
recalled && 'is-recalled',
|
|
481
|
+
inherited && 'is-inherited',
|
|
482
|
+
props.selectionMode && 'is-selecting',
|
|
483
|
+
selectable && 'is-selectable',
|
|
484
|
+
)}
|
|
485
|
+
onClick={(event) => {
|
|
486
|
+
if (!selectable) return
|
|
487
|
+
// 右键菜单经 Portal 渲染,React 事件仍沿组件树冒泡到这里:点「多选」进入多选后,同一次点击会把刚选中的这条切回未选。
|
|
488
|
+
if (!event.currentTarget.contains(event.target as Node)) return
|
|
489
|
+
if ((event.target as HTMLElement).closest('a,button,audio,video')) return
|
|
490
|
+
props.onToggleSelection(message.id)
|
|
491
|
+
}}
|
|
492
|
+
>
|
|
493
|
+
{selectable && (
|
|
494
|
+
<span className={cn('sandbox-message-select-marker', selected && 'is-checked')} aria-hidden>
|
|
495
|
+
<CheckIcon className="size-3" strokeWidth={3} />
|
|
496
|
+
</span>
|
|
497
|
+
)}
|
|
498
|
+
<div className="sandbox-message-select-body">
|
|
499
|
+
{avatarMenu}
|
|
500
|
+
<div className="sandbox-message-content">
|
|
501
|
+
{!merged && (
|
|
502
|
+
<div className="sandbox-message-sender-line">
|
|
503
|
+
<span>{authorName(message.authorId)}</span>
|
|
504
|
+
{badge && <span className={cn('sandbox-message-role-badge', `is-${badge.kind}`)}>{badge.title ?? t(`sandbox.role.${badge.kind}`)}</span>}
|
|
505
|
+
</div>
|
|
506
|
+
)}
|
|
507
|
+
<div className="sandbox-message-body">
|
|
508
|
+
<div className="sandbox-message-stack">
|
|
509
|
+
<ContextMenu disabled={recalled || props.selectionMode}>
|
|
510
|
+
{/* 拦截冒泡放在触发器上:放在气泡里会连这一层菜单也收不到事件;放在这里只挡住外层列表的「清空会话记录」菜单。 */}
|
|
511
|
+
<ContextMenuTrigger render={<div className="sandbox-message-bubble-trigger" onContextMenu={(event) => event.stopPropagation()} />}>
|
|
512
|
+
{bubble}
|
|
513
|
+
</ContextMenuTrigger>
|
|
514
|
+
<ContextMenuContent className="sandbox-glass">
|
|
515
|
+
{isBot && trace && (
|
|
516
|
+
<ContextMenuItem onClick={() => navigate(traceHref(trace))}><ExternalLinkIcon />{t('sandbox.chat.openRequest')}</ContextMenuItem>
|
|
517
|
+
)}
|
|
518
|
+
{capabilities.reply && <ContextMenuItem onClick={() => props.onReply(message.id)}><ReplyIcon />{t('sandbox.chat.reply')}</ContextMenuItem>}
|
|
519
|
+
{capabilities.branch && <ContextMenuItem onClick={() => props.onBranch(message.id)}><GitBranchIcon />{t('sandbox.chat.branch')}</ContextMenuItem>}
|
|
520
|
+
{capabilities.react && <ContextMenuItem onClick={() => props.onOpenReactionPicker(message.id)}><SmilePlusIcon />{t('sandbox.chat.react')}</ContextMenuItem>}
|
|
521
|
+
{capabilities.forward && <ContextMenuItem onClick={() => props.onEnterSelection(message.id)}><ListChecksIcon />{t('sandbox.chat.multiSelect')}</ContextMenuItem>}
|
|
522
|
+
{capabilities.recall && (
|
|
523
|
+
<>
|
|
524
|
+
<ContextMenuSeparator />
|
|
525
|
+
<ContextMenuItem variant="destructive" onClick={() => props.onRecall(message.id)}><CornerUpLeftIcon />{t('sandbox.chat.recall')}</ContextMenuItem>
|
|
526
|
+
</>
|
|
527
|
+
)}
|
|
528
|
+
</ContextMenuContent>
|
|
529
|
+
</ContextMenu>
|
|
530
|
+
</div>
|
|
531
|
+
<time className="sandbox-message-time">{formatSandboxTimeOfDay(message.createdAt)}</time>
|
|
532
|
+
</div>
|
|
533
|
+
</div>
|
|
534
|
+
</div>
|
|
535
|
+
</li>
|
|
536
|
+
{thinking ? (
|
|
537
|
+
<li className={cn('sandbox-message-thinking-row', direction, recalled && 'is-recalled')}>
|
|
538
|
+
<button
|
|
539
|
+
type="button"
|
|
540
|
+
className="sandbox-message-thinking-toggle"
|
|
541
|
+
aria-expanded={thinkingExpanded}
|
|
542
|
+
onClick={() => setExpandedThinking((value) => ({ ...value, [message.id]: !value[message.id] }))}
|
|
543
|
+
>
|
|
544
|
+
{thinking.usage && <UsageMetrics input={thinking.usage.inputTokens} output={thinking.usage.outputTokens} />}
|
|
545
|
+
<span className="sandbox-message-thinking-duration">{formatThinkingDuration(t, thinking.thoughtDurationMs)}</span>
|
|
546
|
+
<ChevronRightIcon className={cn('sandbox-message-thinking-chevron', thinkingExpanded && 'is-expanded')} aria-hidden />
|
|
547
|
+
</button>
|
|
548
|
+
{thinkingExpanded && (
|
|
549
|
+
<div className="sandbox-message-thinking-panel">
|
|
550
|
+
<div className="sandbox-message-thinking-content">{thinking.thought}</div>
|
|
551
|
+
</div>
|
|
552
|
+
)}
|
|
553
|
+
</li>
|
|
554
|
+
) : usage && (
|
|
555
|
+
<li className={cn('sandbox-message-thinking-row is-usage-only', direction, recalled && 'is-recalled')}>
|
|
556
|
+
<UsageMetrics input={usage.inputTokens} output={usage.outputTokens} />
|
|
557
|
+
</li>
|
|
558
|
+
)}
|
|
559
|
+
</React.Fragment>
|
|
560
|
+
)
|
|
561
|
+
})}
|
|
562
|
+
{thinkingStates.map((state) => (
|
|
563
|
+
<li
|
|
564
|
+
key={`${state.botParticipantId}:${state.conversationId}`}
|
|
565
|
+
className={cn('sandbox-message-row', state.botParticipantId === operatorId ? 'is-outgoing' : 'is-incoming')}
|
|
566
|
+
>
|
|
567
|
+
<span className="sandbox-message-avatar-wrap">
|
|
568
|
+
<SandboxAvatar kind="bot" name={participants[state.botParticipantId]?.name} src={participants[state.botParticipantId]?.avatar} className="size-8" />
|
|
569
|
+
</span>
|
|
570
|
+
<div className="sandbox-message-content">
|
|
571
|
+
{/* 等待气泡复用普通消息的 sender-line + body 结构:少了包裹层会丢掉两者之间的 6px 间距,
|
|
572
|
+
被替换成真实消息时会整体下跳。 */}
|
|
573
|
+
<div className="sandbox-message-sender-line">
|
|
574
|
+
<span>{participants[state.botParticipantId]?.name ?? state.botParticipantId}</span>
|
|
575
|
+
</div>
|
|
576
|
+
<div className="sandbox-message-body">
|
|
577
|
+
<div className="sandbox-message-bubble" aria-label={t('sandbox.chat.thinking')}>
|
|
578
|
+
<span className="sandbox-message-thinking-dots">
|
|
579
|
+
{[0, 1, 2].map((dot) => <span key={dot} className="sandbox-message-thinking-dot" />)}
|
|
580
|
+
</span>
|
|
581
|
+
</div>
|
|
582
|
+
</div>
|
|
583
|
+
</div>
|
|
584
|
+
</li>
|
|
585
|
+
))}
|
|
586
|
+
</ol>
|
|
587
|
+
)}
|
|
588
|
+
</ContextMenuTrigger>
|
|
589
|
+
<ContextMenuContent className="sandbox-glass">
|
|
590
|
+
<ContextMenuItem variant="destructive" onClick={props.onClearConversation}><Trash2Icon />{t('sandbox.chat.clear')}</ContextMenuItem>
|
|
591
|
+
</ContextMenuContent>
|
|
592
|
+
</ContextMenu>
|
|
593
|
+
{/* 视口从两层毛玻璃表头后面开始;原生轨道也从顶端开始,滚到顶时滑块藏在表头后面,所以隐藏原生条改画这一条。 */}
|
|
594
|
+
<OverlayScrollbar target={box} className="sandbox-message-scrollbar" />
|
|
595
|
+
</>
|
|
596
|
+
)
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
/** ChatLuna 调用的输入、输出 Token 数;图标取 lucide 的到顶、到底箭头,与源插件的自绘图形一致。 */
|
|
600
|
+
function UsageMetrics({ input, output }: { input?: number, output?: number }) {
|
|
601
|
+
const t = useT()
|
|
602
|
+
return (
|
|
603
|
+
<span className="sandbox-message-thinking-usage" aria-label={t('sandbox.chat.usage')}>
|
|
604
|
+
<span className="sandbox-message-thinking-usage-group">
|
|
605
|
+
<ArrowUpToLineIcon className="sandbox-message-thinking-usage-icon" aria-hidden />
|
|
606
|
+
<span>{input ?? '-'}</span>
|
|
607
|
+
<ArrowDownToLineIcon className="sandbox-message-thinking-usage-icon is-output" aria-hidden />
|
|
608
|
+
<span>{output ?? '-'}</span>
|
|
609
|
+
</span>
|
|
610
|
+
</span>
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** v2 trace 页按会话 ID 打开,`turn` 与 `step` 一起出现时定位到这一步产生的回复。 */
|
|
615
|
+
function traceHref({ sessionId, turn, step }: SandboxMessageTraceReference) {
|
|
616
|
+
return `/traces/${encodeURIComponent(sessionId)}?turn=${turn}&step=${step}`
|
|
617
|
+
}
|