@zhin.js/adapter-sandbox 1.1.35 → 1.2.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.
@@ -1,7 +1,6 @@
1
1
  import { sandboxText, type SandboxLocale } from './messages.js';
2
2
  import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
3
3
  import {
4
- cn,
5
4
  CodeBlock,
6
5
  MarkdownContent,
7
6
  resolveMediaSrc,
@@ -23,11 +22,18 @@ import {
23
22
  Square, RotateCcw, FileDiff, Terminal, FlaskConical, ChevronDown,
24
23
  FileDown, ListChecks, MoreHorizontal, Keyboard, AtSign,
25
24
  } from 'lucide-react';
25
+ import {
26
+ Alert, AlertDescription, AlertTitle, Badge, Button, ConfirmDialog, DropdownMenu, DropdownMenuCheckboxItem,
27
+ DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, Input, ListItemButton,
28
+ SelectField, Switch, Tabs, TabsList, TabsTrigger, cn, usePageChrome,
29
+ } from '@zhin.js/console-ui';
26
30
  import RichTextEditor, { type RichTextEditorRef } from './RichTextEditor.js';
27
31
  import HtmlMessage from './HtmlMessage.js';
28
32
  import { sandboxStyles } from './styles.js';
33
+ import { workspaceStyles } from './workspaceStyles.js';
29
34
  import ConversationRecoveryPanel from './ConversationRecoveryPanel.js';
30
35
  import { useSandboxHistory } from './useSandboxHistory.js';
36
+ import { quietOutcomeNotice, readMessageOutcome } from './conversationRecovery.js';
31
37
  import {
32
38
  agentSessionsPath,
33
39
  buildAgentRunReport,
@@ -92,6 +98,8 @@ export default function Sandbox(props: SandboxPageProps = {}) {
92
98
  const [directoryStatus, setDirectoryStatus] = useState<DirectoryStatus>({ mode: 'loading', error: null })
93
99
  const [workspaceScope, setWorkspaceScope] = useState<SandboxWorkspaceScope | null>(null)
94
100
  const [transportNotice, setTransportNotice] = useState<string | null>(null)
101
+ // #1250 (`unaddressed-message-no-record`): why the last message got no reply, from its settled outcome.
102
+ const [outcomeNotice, setOutcomeNotice] = useState<{ messageId: string; sessionKey: string; text: string } | null>(null)
95
103
  const [shellIsolation, setShellIsolation] = useState<{ available: boolean; provider: string; message: string } | null>(null)
96
104
  const [inspectorView, setInspectorView] = useState<'runs' | 'artifacts'>('runs')
97
105
  const [expandedArtifact, setExpandedArtifact] = useState<string | null>(null)
@@ -126,8 +134,6 @@ export default function Sandbox(props: SandboxPageProps = {}) {
126
134
  const [identitySetup, setIdentitySetup] = useState<{ status: 'idle' | 'busy' | 'done' | 'unsupported' } | { status: 'failed'; message: string }>({ status: 'idle' })
127
135
  const asMe = wantsAsMe(speakerMode, consoleUser)
128
136
  const [showSenderSettings, setShowSenderSettings] = useState(false)
129
- /** Runbar overflow: identity, run settings, inspector and clear live here (#1250). */
130
- const [showMoreActions, setShowMoreActions] = useState(false)
131
137
  /** Live binding of the current socket; drives the Host-provided quick commands. */
132
138
  const [readyConnectionId, setReadyConnectionId] = useState<string | undefined>(undefined)
133
139
  const [commandHints, setCommandHints] = useState<SandboxCommandHints | null>(null)
@@ -247,7 +253,13 @@ export default function Sandbox(props: SandboxPageProps = {}) {
247
253
 
248
254
  const [inlineNotices, setInlineNotices] = useState<{ emoji: boolean; parse: boolean }>({ emoji: false, parse: false })
249
255
  const fetchFaceList = async () => {
250
- try { const res = await fetch('https://face.viki.moe/metadata.json'); setFaceList(await res.json()) }
256
+ try {
257
+ const res = await fetch('https://face.viki.moe/metadata.json')
258
+ const body: unknown = res.ok ? await res.json() : undefined
259
+ // A failed or malformed response must not break the page (the face picker just stays empty).
260
+ if (!Array.isArray(body)) throw new Error(`unexpected face list response (${res.status})`)
261
+ setFaceList(body as Face[])
262
+ }
251
263
  catch (err) { console.error('[Sandbox] Failed to fetch face list:', err); setInlineNotices((n) => ({ ...n, emoji: true })) }
252
264
  }
253
265
 
@@ -633,7 +645,8 @@ export default function Sandbox(props: SandboxPageProps = {}) {
633
645
  case 'md':
634
646
  return <MarkdownContent key={index} text={typeof d.text === 'string' ? d.text : typeof d.content === 'string' ? d.content : segmentFallbackText(segment) ?? ''} className={isSent ? 'zhin-markdown--inverse' : undefined} />
635
647
  case 'html':
636
- return <HtmlMessage locale={locale} key={index} html={String(d.html ?? d.content ?? d.text ?? '')} />
648
+ return <HtmlMessage locale={locale} key={index} html={String(d.html ?? d.content ?? d.text ?? '')}
649
+ width={typeof d.width === 'number' ? d.width : undefined} />
637
650
  case 'code':
638
651
  return <CodeBlock key={index} code={String(d.code ?? d.text ?? d.content ?? '')} language={String(d.language ?? d.lang ?? '')} />
639
652
  case 'mention':
@@ -777,18 +790,16 @@ export default function Sandbox(props: SandboxPageProps = {}) {
777
790
  const label = String(btn.label ?? btn.text ?? btn.title ?? btn.id ?? `Action ${bi + 1}`)
778
791
  const payload = String(btn.payload ?? btn.value ?? btn.url ?? btn.id ?? label)
779
792
  return (
780
- <button
793
+ <Button
781
794
  key={`${payload}-${bi}`}
782
795
  type="button"
796
+ size="sm"
797
+ variant={interactionVariant(btn.style === 'primary', btn.style === 'danger')}
783
798
  disabled={Boolean(btn.disabled) || isSent || resolved || !canExecute || !allowInteraction}
784
799
  onClick={() => { if (sendInteractiveAction(payload, messageId)) onInteractionSubmitted?.() }}
785
- className={cn(
786
- btn.style === 'primary' && 'is-primary',
787
- btn.style === 'danger' && 'is-danger',
788
- )}
789
800
  >
790
801
  {label}
791
- </button>
802
+ </Button>
792
803
  )
793
804
  })}
794
805
  </div>
@@ -836,17 +847,15 @@ export default function Sandbox(props: SandboxPageProps = {}) {
836
847
  return (
837
848
  <div key={index} className="agent-playground-approval-actions">
838
849
  <div>
839
- <button
850
+ <Button
840
851
  type="button"
852
+ size="sm"
853
+ variant={interactionVariant(d.style === 'primary', d.style === 'danger')}
841
854
  disabled={Boolean(d.disabled) || isSent || resolved || !canExecute || !allowInteraction}
842
855
  onClick={() => { if (sendInteractiveAction(payload, messageId)) onInteractionSubmitted?.() }}
843
- className={cn(
844
- d.style === 'primary' && 'is-primary',
845
- d.style === 'danger' && 'is-danger',
846
- )}
847
856
  >
848
857
  {label}
849
- </button>
858
+ </Button>
850
859
  </div>
851
860
  </div>
852
861
  )
@@ -859,18 +868,19 @@ export default function Sandbox(props: SandboxPageProps = {}) {
859
868
  {rows.map((row, ri) => (
860
869
  <div key={ri}>
861
870
  {row.map((btn) => (
862
- <button
871
+ <Button
863
872
  key={btn.payload}
864
873
  type="button"
874
+ size="sm"
875
+ variant={interactionVariant(
876
+ btn.style === 'primary' || /^允许/u.test(btn.label),
877
+ btn.style === 'danger' || /拒绝|取消/u.test(btn.label),
878
+ )}
865
879
  disabled={btn.disabled || isSent || resolved || !canExecute || !allowInteraction}
866
880
  onClick={() => { if (sendInteractiveAction(btn.payload, messageId)) onInteractionSubmitted?.() }}
867
- className={cn(
868
- (btn.style === 'primary' || /^允许/u.test(btn.label)) && 'is-primary',
869
- (btn.style === 'danger' || /拒绝|取消/u.test(btn.label)) && 'is-danger',
870
- )}
871
881
  >
872
882
  {btn.label}
873
- </button>
883
+ </Button>
874
884
  ))}
875
885
  </div>
876
886
  ))}
@@ -888,6 +898,26 @@ export default function Sandbox(props: SandboxPageProps = {}) {
888
898
  })
889
899
  }
890
900
 
901
+ /** Reads the sent message's outcome a few times while it settles; a reply-less one gets a notice. */
902
+ const watchQuietOutcome = (messageId: string, scene: Channel) => {
903
+ const connectionId = connectionRef.current.connectionId
904
+ if (!connectionId) return
905
+ const key = buildSandboxSessionKey(endpointIdRef.current, scene.type, scene.id)
906
+ const requestContext = socketRequestContextRef.current ?? captureSandboxRequestContext()
907
+ const delays = [3_000, 8_000, 20_000]
908
+ const attempt = (index: number) => {
909
+ window.setTimeout(() => {
910
+ if (connectionRef.current.connectionId !== connectionId) return
911
+ void readMessageOutcome(connectionId, key, messageId, localeRef.current, undefined, requestContext).then((outcome) => {
912
+ if (outcome === undefined) { if (index + 1 < delays.length) attempt(index + 1); return }
913
+ const text = quietOutcomeNotice(outcome, localeRef.current)
914
+ if (text) setOutcomeNotice({ messageId, sessionKey: key, text })
915
+ }).catch(() => { /* silent-ok: the notice is optional; the run log keeps the outcome */ })
916
+ }, delays[index])
917
+ }
918
+ attempt(0)
919
+ }
920
+
891
921
  const handleSendMessage = (_text: string, segments: MessageSegment[]) => {
892
922
  if (!connectionRef.current.canExecute || directoryModeRef.current === 'loading' || !hasRenderableSegments(segments)) return
893
923
  const scene = activeChannelRef.current
@@ -908,6 +938,8 @@ export default function Sandbox(props: SandboxPageProps = {}) {
908
938
  }
909
939
  void directoryControllerRef.current?.save(scene, true)
910
940
  setPendingRefreshEpoch((epoch) => epoch + 1)
941
+ setOutcomeNotice(null)
942
+ watchQuietOutcome(newMessage.id, scene)
911
943
  setMessages((prev) => mergePlaygroundMessage(prev, newMessage))
912
944
  setInputText(''); setPreviewSegments([]); setComposerMode('write')
913
945
  editorRef.current?.clear()
@@ -1040,11 +1072,11 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1040
1072
  </div>
1041
1073
  <div className="agent-playground-inline-run-actions">
1042
1074
  {currentTask.status === 'running' ? (
1043
- <button type="button" className="is-stop" onClick={() => void stopActiveTask()} disabled={stoppingTask}><Square size={12} />{stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")}</button>
1075
+ <Button type="button" size="sm" variant="destructive-outline" onClick={() => void stopActiveTask()} disabled={stoppingTask}><Square />{stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")}</Button>
1044
1076
  ) : currentTaskMessage ? (
1045
- <button type="button" onClick={retryCurrentTask}><RotateCcw size={13} />{sandboxText(locale, "重试")}</button>
1077
+ <Button type="button" size="sm" variant="outline" onClick={retryCurrentTask}><RotateCcw />{sandboxText(locale, "重试")}</Button>
1046
1078
  ) : null}
1047
- <button type="button" onClick={exportCurrentRun} title={sandboxText(locale, "导出 Markdown 运行报告")}><FileDown size={13} />{sandboxText(locale, "导出")}</button>
1079
+ <Button type="button" size="sm" variant="outline" onClick={exportCurrentRun} title={sandboxText(locale, "导出 Markdown 运行报告")}><FileDown />{sandboxText(locale, "导出")}</Button>
1048
1080
  </div>
1049
1081
  </div>
1050
1082
  <dl className="agent-playground-inline-run-metrics">
@@ -1068,86 +1100,92 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1068
1100
  ) : <div className="agent-playground-inline-run-empty">{sandboxText(locale, "正在等待第一条运行事件…")}</div>
1069
1101
  )}
1070
1102
  <footer>
1071
- <button type="button" aria-expanded={inlineRunExpanded} onClick={() => setInlineRunExpanded((expanded) => !expanded)}>
1072
- <ChevronDown size={13} />{inlineRunExpanded ? sandboxText(locale, "收起步骤") : sandboxText(locale, "查看 {0} 个步骤", [currentRunSteps.length])}
1073
- </button>
1074
- <button type="button" onClick={() => { setInspectorView(currentRunArtifacts.length > 0 ? 'artifacts' : 'runs'); setShowInspector(true) }}>
1075
- {currentRunArtifacts.length > 0 ? sandboxText(locale, "{0} 个变更与产物", [currentRunArtifacts.length]) : sandboxText(locale, "打开运行检查器")}<PanelRight size={13} />
1076
- </button>
1103
+ <Button type="button" size="sm" variant="ghost" aria-expanded={inlineRunExpanded} onClick={() => setInlineRunExpanded((expanded) => !expanded)}>
1104
+ <ChevronDown />{inlineRunExpanded ? sandboxText(locale, "收起步骤") : sandboxText(locale, "查看 {0} 个步骤", [currentRunSteps.length])}
1105
+ </Button>
1106
+ <Button type="button" size="sm" variant="ghost" onClick={() => { setInspectorView(currentRunArtifacts.length > 0 ? 'artifacts' : 'runs'); setShowInspector(true) }}>
1107
+ {currentRunArtifacts.length > 0 ? sandboxText(locale, "{0} 个变更与产物", [currentRunArtifacts.length]) : sandboxText(locale, "打开运行检查器")}<PanelRight />
1108
+ </Button>
1077
1109
  </footer>
1078
1110
  </article>
1079
1111
  ) : null
1080
1112
 
1081
1113
  const recoveryConnectionId = connectionRef.current.connectionId
1082
- return (
1083
- <section className={cn("zhin-sandbox agent-playground-shell", showInspector && "has-inspector")}>
1084
- <style>{`${sandboxStyles}
1085
- .sandbox-sender-trigger { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 6px; }
1086
- .sandbox-role-badge { font-style: normal; font-size: 10px; font-weight: 600; text-transform: uppercase; padding: 1px 6px; border-radius: 999px; background: rgba(148,163,184,0.18); color: inherit; }
1087
- .sandbox-role-badge.is-master { background: rgba(245,158,11,0.18); color: #d97706; }
1088
- .sandbox-role-badge.is-admin { background: rgba(59,130,246,0.18); color: #2563eb; }
1089
- .sandbox-role-badge.is-member { background: rgba(16,185,129,0.16); color: #059669; }
1090
- .sandbox-role-badge.is-zhin { text-transform: none; background: rgba(139,92,246,0.16); color: #7c3aed; }
1091
- .sandbox-role-switcher { display: inline-flex; gap: 4px; }
1092
- .sandbox-role-option { padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.3); font-size: 12px; cursor: pointer; background: transparent; color: inherit; text-transform: capitalize; }
1093
- .sandbox-role-option.active { font-weight: 600; border-color: currentColor; background: rgba(59,130,246,0.12); }
1094
- .sandbox-sender-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
1095
- .sandbox-sender-presets button { font-size: 11px; padding: 3px 8px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.28); background: transparent; color: inherit; cursor: pointer; }
1096
- .sandbox-quick-commands { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: 6px; }
1097
- .sandbox-command-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid rgba(148,163,184,0.28); background: transparent; color: inherit; cursor: pointer; }
1098
- .sandbox-command-chip:hover:not(:disabled) { border-color: rgba(59,130,246,0.5); background: rgba(59,130,246,0.08); }
1099
- .sandbox-command-chip:disabled { opacity: 0.45; cursor: not-allowed; }
1100
- .sandbox-rich-card { border: 1px solid rgba(148,163,184,0.28); border-radius: 10px; overflow: hidden; margin-top: 6px; max-width: 440px; background: rgba(148,163,184,0.06); }
1101
- .sandbox-rich-card-image { width: 100%; max-height: 200px; object-fit: cover; display: block; }
1102
- .sandbox-rich-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
1103
- .sandbox-rich-card-title { font-weight: 600; font-size: 14px; }
1104
- .sandbox-rich-card-subtitle { font-size: 12px; opacity: 0.75; }
1105
- .sandbox-rich-card-desc { font-size: 13px; }
1106
- .sandbox-rich-card-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin: 4px 0 0; }
1107
- .sandbox-rich-card-field { background: rgba(148,163,184,0.08); padding: 4px 8px; border-radius: 6px; }
1108
- .sandbox-rich-card-field dt { font-size: 11px; opacity: 0.7; }
1109
- .sandbox-rich-card-field dd { margin: 0; font-size: 12px; font-weight: 500; }
1110
- .sandbox-card-link-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.3); text-decoration: none; color: inherit; }
1111
- .sandbox-share-card { display: flex; gap: 10px; align-items: center; border: 1px solid rgba(148,163,184,0.28); border-radius: 10px; padding: 8px 12px; margin-top: 6px; max-width: 440px; background: rgba(148,163,184,0.06); }
1112
- .sandbox-share-card-thumb { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
1113
- .sandbox-share-card-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
1114
- .sandbox-share-card-title { font-weight: 600; font-size: 13px; }
1115
- .sandbox-share-card-title a { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: underline; }
1116
- .sandbox-share-card-desc { font-size: 12px; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }
1117
- .sandbox-share-card-url { font-size: 11px; opacity: 0.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1118
- `}</style>
1119
- <div className="agent-playground-mobilebar">
1120
- <button type="button" aria-expanded={showChannelList} onClick={() => setShowChannelList(!showChannelList)}><MessageSquare size={17} />{sandboxText(locale, "会话列表")}</button>
1121
- <strong>{sandboxText(locale, "会话")}</strong>
1122
- <button type="button" aria-expanded={showInspector} aria-controls="sandbox-run-inspector" onClick={() => setShowInspector(!showInspector)}><PanelRight size={17} />{sandboxText(locale, "检查器")}</button>
1114
+ const narrowLayout = useMediaQuery(DRAWER_LAYOUT_QUERY)
1115
+ const compactRunbar = useMediaQuery(COMPACT_RUNBAR_QUERY)
1116
+ const openConversationDetails = () => setShowConversationDetails((visible) => !visible)
1117
+ const directoryLoading = directoryStatus.mode === 'loading'
1118
+ // ADR 0063 决策 2 / D18: the page header belongs to the Console shell. The two pane toggles the narrow
1119
+ // layout needs go to the shell's header actions; without a shell the page draws them itself.
1120
+ const chromeActions = useMemo(() => (
1121
+ <>
1122
+ {narrowLayout && (
1123
+ <Button type="button" variant="outline" aria-expanded={showChannelList} onClick={() => setShowChannelList((visible) => !visible)}>
1124
+ <MessageSquare />{sandboxText(locale, "会话列表")}
1125
+ </Button>
1126
+ )}
1127
+ <Button type="button" variant="outline" aria-expanded={showInspector} aria-controls="sandbox-run-inspector" onClick={() => setShowInspector((visible) => !visible)}>
1128
+ <PanelRight />{sandboxText(locale, "检查器")}
1129
+ </Button>
1130
+ </>
1131
+ ), [locale, narrowLayout, showChannelList, showInspector])
1132
+ const hosted = usePageChrome({ actions: chromeActions })
1133
+ const connectionBadge = (
1134
+ <span className={cn("agent-playground-connection", connected && "is-online")} role="img"
1135
+ aria-label={connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket")}
1136
+ title={connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket")}>
1137
+ {connected ? <Wifi size={12} /> : <WifiOff size={12} />}
1138
+ </span>
1139
+ )
1140
+ const notice = (key: string, options: { title?: string; message: React.ReactNode; tone?: 'default' | 'destructive'; role?: 'alert' | 'status'; action: React.ReactNode }) => (
1141
+ <Alert key={key} variant={options.tone ?? 'default'} role={options.role ?? 'status'} className="sandbox-alert">
1142
+ <div className="sandbox-alert-copy">
1143
+ {options.title && <AlertTitle>{options.title}</AlertTitle>}
1144
+ <AlertDescription>{options.message}</AlertDescription>
1123
1145
  </div>
1146
+ {options.action}
1147
+ </Alert>
1148
+ )
1149
+ return (
1150
+ <section className={cn("zhin-sandbox agent-playground-shell", showInspector && "has-inspector", hosted && "is-hosted")}>
1151
+ <style>{`${workspaceStyles}
1152
+ ${sandboxStyles}`}</style>
1153
+ {!hosted && (
1154
+ <div className="agent-playground-mobilebar">
1155
+ {chromeActions}
1156
+ </div>
1157
+ )}
1124
1158
 
1125
1159
  <nav className={cn("channel-sidebar agent-playground-sessions", showChannelList && "show")} aria-label={sandboxText(locale, "会话列表")}>
1126
- <div className="agent-playground-brand">
1127
- <div>
1160
+ {!hosted && (
1161
+ <div className="agent-playground-brand">
1128
1162
  <div>
1129
- <span className="agent-playground-mark"><Sparkles size={16} /></span>
1130
- <div><h2>{sandboxText(locale, "会话")}</h2><small>Conversations</small></div>
1163
+ <div>
1164
+ <span className="agent-playground-mark"><Sparkles size={16} /></span>
1165
+ <div><h2>{sandboxText(locale, "会话")}</h2></div>
1166
+ </div>
1167
+ {connectionBadge}
1131
1168
  </div>
1132
- <span className={cn("agent-playground-connection", connected && "is-online")} title={connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket")}>
1133
- {connected ? <Wifi size={12} /> : <WifiOff size={12} />}
1134
- </span>
1135
1169
  </div>
1136
- </div>
1170
+ )}
1137
1171
 
1138
- <div className="agent-playground-section-label"><span>{sandboxText(locale, "会话列表")}</span><span>{channels.length}</span><button type="button" disabled={directoryStatus.mode === 'loading'} aria-label={sandboxText(locale, "刷新会话目录")} onClick={() => void directoryControllerRef.current?.refresh()}><RefreshCw size={13} /></button></div>
1172
+ <div className="agent-playground-section-label">
1173
+ <span>{sandboxText(locale, "会话列表")}</span><span>{channels.length}</span>
1174
+ {hosted && connectionBadge}
1175
+ <Button type="button" variant="ghost" size="icon" disabled={directoryLoading} aria-label={sandboxText(locale, "刷新会话目录")} title={sandboxText(locale, "刷新会话目录")} onClick={() => void directoryControllerRef.current?.refresh()}><RefreshCw /></Button>
1176
+ </div>
1139
1177
  <div className="agent-playground-session-list">
1140
1178
  {channels.map((channel) => {
1141
1179
  const isActive = activeChannel.id === channel.id && activeChannel.type === channel.type
1142
1180
  return (
1143
- <button type="button" key={`${channel.type}:${channel.id}`} disabled={directoryStatus.mode === 'loading'} aria-current={isActive ? 'page' : undefined} className={cn("agent-playground-session", isActive && "active")} onClick={() => switchChannel(channel)}>
1181
+ <ListItemButton key={`${channel.type}:${channel.id}`} disabled={directoryLoading} aria-current={isActive ? 'page' : undefined} className={cn("agent-playground-session", isActive && "active")} onClick={() => switchChannel(channel)}>
1144
1182
  <span className="agent-playground-session-icon">{getChannelIcon(channel.type)}</span>
1145
1183
  <div className="agent-playground-session-copy">
1146
1184
  <div className="agent-playground-session-title">{channel.name}</div>
1147
1185
  <div className="agent-playground-session-scope">{channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域")}</div>
1148
1186
  </div>
1149
1187
  {channel.unread > 0 && <span className="agent-playground-unread">{channel.unread}</span>}
1150
- </button>
1188
+ </ListItemButton>
1151
1189
  )
1152
1190
  })}
1153
1191
  </div>
@@ -1155,25 +1193,25 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1155
1193
  <div className="agent-playground-new-session">
1156
1194
  {showNewSession ? (
1157
1195
  <div className="agent-playground-new-form">
1158
- <input value={newSessionName} onChange={(event) => setNewSessionName(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter') addSession() }} placeholder={sandboxText(locale, "会话名称")} autoFocus />
1196
+ <Input value={newSessionName} onChange={(event) => setNewSessionName(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter') addSession() }} placeholder={sandboxText(locale, "会话名称")} aria-label={sandboxText(locale, "会话名称")} autoFocus />
1159
1197
  <div className="agent-playground-scope-picker" role="group" aria-label={sandboxText(locale, "消息作用域")}>
1160
1198
  {(['private', 'group', 'channel'] as SandboxScope[]).map((scope) => (
1161
- <button type="button" key={scope} aria-pressed={newSessionScope === scope} className={cn(newSessionScope === scope && 'active')} onClick={() => setNewSessionScope(scope)}>
1199
+ <ListItemButton key={scope} aria-pressed={newSessionScope === scope} className={cn(newSessionScope === scope && 'active')} onClick={() => setNewSessionScope(scope)}>
1162
1200
  {scope === 'private' ? sandboxText(locale, "单用户") : scope === 'group' ? sandboxText(locale, "群组") : sandboxText(locale, "频道")}
1163
- </button>
1201
+ </ListItemButton>
1164
1202
  ))}
1165
1203
  </div>
1166
1204
  <div className="agent-playground-new-actions">
1167
- <button type="button" onClick={() => setShowNewSession(false)}>{sandboxText(locale, "取消")}</button>
1168
- <button type="button" className="primary" onClick={addSession}>{sandboxText(locale, "创建")}</button>
1205
+ <Button type="button" variant="outline" onClick={() => setShowNewSession(false)}>{sandboxText(locale, "取消")}</Button>
1206
+ <Button type="button" onClick={addSession}>{sandboxText(locale, "创建")}</Button>
1169
1207
  </div>
1170
1208
  </div>
1171
1209
  ) : (
1172
- <button type="button" disabled={directoryStatus.mode === 'loading'} className="agent-playground-add" onClick={() => setShowNewSession(true)}><Plus size={15} />{sandboxText(locale, "新建会话")}</button>
1210
+ <Button type="button" variant="outline" disabled={directoryLoading} className="sandbox-block-button" onClick={() => setShowNewSession(true)}><Plus />{sandboxText(locale, "新建会话")}</Button>
1173
1211
  )}
1174
1212
  </div>
1175
1213
  <div className="agent-playground-endpoint">
1176
- <span>{directoryStatus.mode === 'loading' ? sandboxText(locale, "正在读取会话目录") : directoryStatus.mode === 'server' && !directoryStatus.error ? sandboxText(locale, "Host 会话目录") : persistenceStatus === 'saved' ? sandboxText(locale, "会话已持久化") : sandboxText(locale, "会话保存失败")}</span>
1214
+ <span>{directoryLoading ? sandboxText(locale, "正在读取会话目录") : directoryStatus.mode === 'server' && !directoryStatus.error ? sandboxText(locale, "Host 会话目录") : persistenceStatus === 'saved' ? sandboxText(locale, "会话已持久化") : sandboxText(locale, "会话保存失败")}</span>
1177
1215
  <strong>{endpointId}</strong>
1178
1216
  </div>
1179
1217
  </nav>
@@ -1185,7 +1223,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1185
1223
  <div className="agent-playground-run-identity">
1186
1224
  <span className="agent-playground-run-icon">{getChannelIcon(activeChannel.type)}</span>
1187
1225
  <div title={sessionKey}>
1188
- <div className="agent-playground-run-title"><h1 title={activeChannel.name}>{activeChannel.name}</h1><span>{scopeLabel}</span></div>
1226
+ <div className="agent-playground-run-title"><h2 title={activeChannel.name}>{activeChannel.name}</h2><span>{scopeLabel}</span></div>
1189
1227
  </div>
1190
1228
  </div>
1191
1229
  <div className="agent-playground-run-actions">
@@ -1194,56 +1232,57 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1194
1232
  {currentTask ? taskStatusLabel(currentTask.status, locale) : sandboxText(locale, "{0} 条消息", [channelMessages.length])}
1195
1233
  </span>
1196
1234
  {currentTask?.status === 'running' ? (
1197
- <button type="button" className="agent-playground-stop" onClick={() => void stopActiveTask()} disabled={stoppingTask} aria-label={sandboxText(locale, "停止当前任务")}><Square size={13} />{stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")}</button>
1198
- ) : lastUserMessage ? (
1199
- <button type="button" onClick={retryLastTask} aria-label={sandboxText(locale, "重新运行上一个任务")}><RotateCcw size={14} />{sandboxText(locale, "重试")}</button>
1235
+ <Button type="button" size="sm" variant="destructive-outline" onClick={() => void stopActiveTask()} disabled={stoppingTask} aria-label={sandboxText(locale, "停止当前任务")}><Square />{stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")}</Button>
1236
+ ) : lastUserMessage && !compactRunbar ? (
1237
+ <Button type="button" size="sm" variant="outline" onClick={retryLastTask} aria-label={sandboxText(locale, "重新运行上一个任务")}><RotateCcw />{sandboxText(locale, "重试")}</Button>
1200
1238
  ) : null}
1201
- {props.renderConversationDetails
1202
- ? <button type="button" disabled={!canExecute} aria-expanded={showConversationDetails} aria-controls="sandbox-conversation-details" onClick={() => setShowConversationDetails((visible) => !visible)}><ListChecks size={14} />{sandboxText(locale, "对话与轨迹")}</button>
1203
- : <a href={agentSessionsPath(sessionKey)}><ExternalLink size={14} />{sandboxText(locale, "对话与轨迹")}</a>}
1204
- <div className="sandbox-more">
1205
- <button
1206
- type="button"
1207
- className={cn("sandbox-more-trigger", (showMoreActions || showSenderSettings || showRunSettings) && 'active')}
1208
- aria-haspopup="menu"
1209
- aria-expanded={showMoreActions}
1210
- onClick={() => setShowMoreActions((visible) => !visible)}
1211
- aria-label={sandboxText(locale, "更多操作")}
1212
- title={sandboxText(locale, "更多操作")}
1213
- >
1214
- <MoreHorizontal size={16} />
1215
- </button>
1216
- {showMoreActions && (
1217
- <>
1218
- <div className="sandbox-more-backdrop" onClick={() => setShowMoreActions(false)} />
1219
- <div className="sandbox-more-menu" role="menu" aria-label={sandboxText(locale, "更多操作")}>
1220
- <button type="button" role="menuitemcheckbox" aria-checked={showSenderSettings}
1221
- onClick={() => { setShowSenderSettings((visible) => !visible); setShowMoreActions(false) }}>
1222
- <User size={14} />
1223
- <span>{sandboxText(locale, "模拟发送者")}</span>
1224
- <em className={cn("sandbox-role-badge", `is-${senderRole}`)} title={locale === 'en' ? 'Simulated platform standing (not a zhin role)' : '模拟的平台身份(不是 zhin 角色)'}>{asMe ? sandboxText(locale, "我的聊天身份") : (senderName.trim() || senderId.trim() || 'dev-user')} · {platformStandingLabel(senderRole, locale)}</em>
1225
- {serverRole && (serverRole.simulated
1226
- ? <em className="sandbox-role-badge is-simulated" title={sandboxText(locale, "客户端自填的发送者不解析 zhin 角色")}>{sandboxText(locale, "模拟身份,无角色")}</em>
1227
- : <em className="sandbox-role-badge is-zhin" title={locale === 'en' ? 'Resolved by the server: zhin role · Agent trust tier' : '服务端解析:zhin 角色 · Agent 信任档位'}>
1228
- {`zhin: ${serverRole.chatRole ?? (locale === 'en' ? 'none' : '无')} · ${serverRole.trustLevel}`}
1229
- </em>)}
1230
- </button>
1231
- <button type="button" role="menuitemcheckbox" aria-checked={showRunSettings}
1232
- onClick={() => { setShowRunSettings((visible) => !visible); setShowMoreActions(false) }}>
1233
- <SlidersHorizontal size={14} /><span>{sandboxText(locale, "配置运行环境")}</span>
1234
- </button>
1235
- <button type="button" role="menuitemcheckbox" aria-checked={showInspector} aria-controls="sandbox-run-inspector"
1236
- onClick={() => { setShowInspector(!showInspector); setShowMoreActions(false) }}>
1237
- <PanelRight size={14} /><span>{sandboxText(locale, "切换运行检查器")}</span>
1238
- </button>
1239
- <button type="button" role="menuitem" className="is-danger"
1240
- onClick={() => { setConfirmClear(true); setShowMoreActions(false) }}>
1241
- <Trash2 size={14} /><span>{sandboxText(locale, "清空当前会话")}</span>
1242
- </button>
1243
- </div>
1244
- </>
1245
- )}
1246
- </div>
1239
+ {compactRunbar ? null : props.renderConversationDetails
1240
+ ? <Button type="button" size="sm" variant="outline" disabled={!canExecute} aria-expanded={showConversationDetails} aria-controls="sandbox-conversation-details" onClick={openConversationDetails}><ListChecks />{sandboxText(locale, "对话与轨迹")}</Button>
1241
+ : <Button asChild size="sm" variant="outline"><a href={agentSessionsPath(sessionKey)}><ExternalLink />{sandboxText(locale, "对话与轨迹")}</a></Button>}
1242
+ <DropdownMenu>
1243
+ <DropdownMenuTrigger asChild>
1244
+ <Button
1245
+ type="button"
1246
+ size="icon"
1247
+ variant="ghost"
1248
+ className={cn((showSenderSettings || showRunSettings) && 'is-active')}
1249
+ aria-label={sandboxText(locale, "更多操作")}
1250
+ title={sandboxText(locale, "更多操作")}
1251
+ >
1252
+ <MoreHorizontal />
1253
+ </Button>
1254
+ </DropdownMenuTrigger>
1255
+ <DropdownMenuContent align="end">
1256
+ {compactRunbar && currentTask?.status !== 'running' && lastUserMessage && (
1257
+ <DropdownMenuItem onSelect={retryLastTask}><RotateCcw />{sandboxText(locale, "重试")}</DropdownMenuItem>
1258
+ )}
1259
+ {compactRunbar && (props.renderConversationDetails
1260
+ ? <DropdownMenuItem disabled={!canExecute} onSelect={openConversationDetails}><ListChecks />{sandboxText(locale, "对话与轨迹")}</DropdownMenuItem>
1261
+ : <DropdownMenuItem asChild><a href={agentSessionsPath(sessionKey)}><ExternalLink />{sandboxText(locale, "对话与轨迹")}</a></DropdownMenuItem>)}
1262
+ {compactRunbar && <DropdownMenuSeparator />}
1263
+ <DropdownMenuCheckboxItem checked={showSenderSettings} onCheckedChange={(checked) => setShowSenderSettings(checked === true)}>
1264
+ <span className="flex flex-wrap items-center gap-2">
1265
+ <span>{sandboxText(locale, "模拟发送者")}</span>
1266
+ <Badge variant="secondary" size="sm" title={locale === 'en' ? 'Simulated platform standing (not a zhin role)' : '模拟的平台身份(不是 zhin 角色)'}>{asMe ? sandboxText(locale, "我的聊天身份") : (senderName.trim() || senderId.trim() || 'dev-user')} · {platformStandingLabel(senderRole, locale)}</Badge>
1267
+ {serverRole && (serverRole.simulated
1268
+ ? <Badge variant="secondary" size="sm" title={sandboxText(locale, "客户端自填的发送者不解析 zhin 角色")}>{sandboxText(locale, "模拟身份,无角色")}</Badge>
1269
+ : <Badge variant="secondary" size="sm" title={locale === 'en' ? 'Resolved by the server: zhin role · Agent trust tier' : '服务端解析:zhin 角色 · Agent 信任档位'}>
1270
+ {`zhin: ${serverRole.chatRole ?? (locale === 'en' ? 'none' : '无')} · ${serverRole.trustLevel}`}
1271
+ </Badge>)}
1272
+ </span>
1273
+ </DropdownMenuCheckboxItem>
1274
+ <DropdownMenuCheckboxItem checked={showRunSettings} onCheckedChange={(checked) => setShowRunSettings(checked === true)}>
1275
+ {sandboxText(locale, "配置运行环境")}
1276
+ </DropdownMenuCheckboxItem>
1277
+ <DropdownMenuCheckboxItem checked={showInspector} aria-controls="sandbox-run-inspector" onCheckedChange={(checked) => setShowInspector(checked === true)}>
1278
+ {sandboxText(locale, "切换运行检查器")}
1279
+ </DropdownMenuCheckboxItem>
1280
+ <DropdownMenuSeparator />
1281
+ <DropdownMenuItem className="text-destructive" onSelect={() => setConfirmClear(true)}>
1282
+ <Trash2 />{sandboxText(locale, "清空当前会话")}
1283
+ </DropdownMenuItem>
1284
+ </DropdownMenuContent>
1285
+ </DropdownMenu>
1247
1286
  </div>
1248
1287
  </header>
1249
1288
 
@@ -1251,8 +1290,8 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1251
1290
  <section className="agent-playground-run-settings sandbox-sender-settings" aria-label={locale === 'en' ? 'Simulated sender' : '模拟发送者配置'}>
1252
1291
  <div className="sandbox-speaker-mode">
1253
1292
  <label className="sandbox-speaker-toggle">
1254
- <input type="checkbox" checked={speakerMode === 'me'} disabled={!consoleUser}
1255
- onChange={(event) => setSpeakerMode(event.target.checked ? 'me' : 'simulated')} />
1293
+ <Switch checked={speakerMode === 'me'} disabled={!consoleUser}
1294
+ onCheckedChange={(checked) => setSpeakerMode(checked ? 'me' : 'simulated')} />
1256
1295
  <span>{sandboxText(locale, "以我的聊天身份发言")}</span>
1257
1296
  </label>
1258
1297
  <p>
@@ -1270,12 +1309,12 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1270
1309
  {asMe && serverRole?.asMeUnavailable === 'no-identity' && (
1271
1310
  <div className="sandbox-speaker-setup" role="status">
1272
1311
  <span>{sandboxText(locale, "你在 Sandbox 上还没有聊天身份,上一条消息按模拟身份发送。")}</span>
1273
- <button type="button" disabled={identitySetup.status === 'busy'} onClick={() => {
1312
+ <Button type="button" size="sm" variant="outline" disabled={identitySetup.status === 'busy'} onClick={() => {
1274
1313
  setIdentitySetup({ status: 'busy' })
1275
1314
  void ensureSandboxChatIdentity(socketRequestContextRef.current ?? undefined).then((result) => {
1276
1315
  setIdentitySetup(result.status === 'ok' ? { status: 'done' } : result)
1277
1316
  })
1278
- }}>{sandboxText(locale, "在 Sandbox 上创建我的聊天身份")}</button>
1317
+ }}>{sandboxText(locale, "在 Sandbox 上创建我的聊天身份")}</Button>
1279
1318
  {identitySetup.status === 'done' && <em>{sandboxText(locale, "已创建,下一条消息生效。")}</em>}
1280
1319
  {identitySetup.status === 'unsupported' && <em>{sandboxText(locale, "当前 Host 不支持,请升级。")}</em>}
1281
1320
  {identitySetup.status === 'failed' && <em>{identitySetup.message}</em>}
@@ -1284,7 +1323,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1284
1323
  </div>
1285
1324
  <label>
1286
1325
  <span><User size={14} />{locale === 'en' ? 'Sender ID (simulated, no role)' : '发送者 ID(模拟身份,无角色)'}</span>
1287
- <input
1326
+ <Input
1288
1327
  value={senderId}
1289
1328
  disabled={asMe}
1290
1329
  onChange={(event) => setSenderId(event.target.value)}
@@ -1294,7 +1333,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1294
1333
  </label>
1295
1334
  <label>
1296
1335
  <span>{locale === 'en' ? 'Sender Name' : '发送者昵称'}</span>
1297
- <input
1336
+ <Input
1298
1337
  value={senderName}
1299
1338
  disabled={asMe}
1300
1339
  onChange={(event) => setSenderName(event.target.value)}
@@ -1302,107 +1341,123 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1302
1341
  spellCheck={false}
1303
1342
  />
1304
1343
  </label>
1305
- <label>
1344
+ <div className="sandbox-field">
1306
1345
  <span><ShieldCheck size={14} />{locale === 'en' ? 'Platform standing (not a zhin role)' : '平台身份(不是 zhin 角色)'}</span>
1307
1346
  <div className="sandbox-role-switcher" role="group" aria-label={locale === 'en' ? 'Platform standing' : '平台身份'}>
1308
1347
  {(['member', 'admin', 'master'] as const).map((role) => (
1309
- <button
1348
+ <ListItemButton
1310
1349
  key={role}
1311
- type="button"
1312
1350
  aria-pressed={senderRole === role}
1313
1351
  className={cn("sandbox-role-option", `is-${role}`, senderRole === role && "active")}
1314
1352
  onClick={() => setSenderRole(role)}
1315
1353
  >
1316
1354
  {platformStandingLabel(role, locale)}
1317
- </button>
1355
+ </ListItemButton>
1318
1356
  ))}
1319
1357
  </div>
1320
- </label>
1358
+ </div>
1321
1359
  <div className="sandbox-sender-presets">
1322
- <button type="button" onClick={() => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master') }}>{locale === 'en' ? 'Group owner (platform standing, dev-user)' : '群主(平台身份,dev-user)'}</button>
1323
- <button type="button" onClick={() => { setSenderId('admin-user'); setSenderName('Admin'); setSenderRole('admin') }}>Admin (admin-user)</button>
1324
- <button type="button" onClick={() => { setSenderId('member-user'); setSenderName('Member'); setSenderRole('member') }}>Member (member-user)</button>
1360
+ <Button type="button" size="sm" variant="outline" onClick={() => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master') }}>{locale === 'en' ? 'Group owner (platform standing, dev-user)' : '群主(平台身份,dev-user)'}</Button>
1361
+ <Button type="button" size="sm" variant="outline" onClick={() => { setSenderId('admin-user'); setSenderName('Admin'); setSenderRole('admin') }}>Admin (admin-user)</Button>
1362
+ <Button type="button" size="sm" variant="outline" onClick={() => { setSenderId('member-user'); setSenderName('Member'); setSenderRole('member') }}>Member (member-user)</Button>
1325
1363
  </div>
1326
1364
  </section>
1327
1365
  )}
1328
1366
 
1329
- {cancellationFeedback && <div className="agent-playground-confirm" role={cancellationFeedback.kind === 'error' ? 'alert' : 'status'}>
1330
- <div><span>{cancellationFeedback.message}</span></div>
1331
- <button type="button" onClick={() => setCancellationFeedback(null)}>{sandboxText(locale, "知道了")}</button>
1332
- </div>}
1367
+ {cancellationFeedback && notice('cancellation', {
1368
+ message: cancellationFeedback.message,
1369
+ tone: cancellationFeedback.kind === 'error' ? 'destructive' : 'default',
1370
+ role: cancellationFeedback.kind === 'error' ? 'alert' : 'status',
1371
+ action: <Button type="button" size="sm" variant="outline" onClick={() => setCancellationFeedback(null)}>{sandboxText(locale, "知道了")}</Button>,
1372
+ })}
1333
1373
 
1334
- {confirmClear && (
1335
- <div className="agent-playground-confirm" role="alert">
1336
- <div><strong>{sandboxText(locale, "清空当前测试记录?")}</strong><span>{sandboxText(locale, "只移除“")}{activeChannel.name}{sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")}</span></div>
1337
- <button type="button" onClick={() => setConfirmClear(false)}>{sandboxText(locale, "取消")}</button>
1338
- <button type="button" className="danger" onClick={clearMessages}>{sandboxText(locale, "确认清空")}</button>
1339
- </div>
1340
- )}
1374
+ <ConfirmDialog
1375
+ open={confirmClear}
1376
+ onOpenChange={setConfirmClear}
1377
+ title={sandboxText(locale, "清空当前测试记录?")}
1378
+ description={`${sandboxText(locale, "只移除“")}${activeChannel.name}${sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")}`}
1379
+ confirmLabel={sandboxText(locale, "确认清空")}
1380
+ cancelLabel={sandboxText(locale, "取消")}
1381
+ variant="destructive"
1382
+ onConfirm={clearMessages}
1383
+ />
1341
1384
 
1342
- {(['emoji', 'parse'] as const).filter((kind) => inlineNotices[kind]).map((kind) => (
1343
- <div key={kind} className="sandbox-notice" role="status">
1344
- <CircleAlert size={14} />
1345
- <span>{kind === 'emoji' ? sandboxText(locale, "表情列表加载失败,表情选择器暂不可用。") : sandboxText(locale, "收到一条无法解析的消息,已忽略。")}</span>
1346
- <button type="button" onClick={() => setInlineNotices((n) => ({ ...n, [kind]: false }))}>{sandboxText(locale, "知道了")}</button>
1347
- </div>
1348
- ))}
1385
+ {(['emoji', 'parse'] as const).filter((kind) => inlineNotices[kind]).map((kind) => notice(kind, {
1386
+ message: kind === 'emoji' ? sandboxText(locale, "表情列表加载失败,表情选择器暂不可用。") : sandboxText(locale, "收到一条无法解析的消息,已忽略。"),
1387
+ action: <Button type="button" size="sm" variant="outline" onClick={() => setInlineNotices((n) => ({ ...n, [kind]: false }))}>{sandboxText(locale, "知道了")}</Button>,
1388
+ }))}
1349
1389
 
1350
- {transportNotice && (
1351
- <div className="agent-playground-confirm" role="status">
1352
- <div><strong>{sandboxText(locale, "运行暂不可用")}</strong><span>{transportNotice}</span></div>
1353
- <button type="button" onClick={() => setTransportNotice(null)}>{sandboxText(locale, "知道了")}</button>
1354
- </div>
1355
- )}
1390
+ {outcomeNotice && outcomeNotice.sessionKey === sessionKey && notice('outcome', {
1391
+ title: sandboxText(locale, "这条消息没有回复"),
1392
+ message: outcomeNotice.text,
1393
+ role: 'status',
1394
+ action: <Button type="button" size="sm" variant="outline" onClick={() => setOutcomeNotice(null)}>{sandboxText(locale, "知道了")}</Button>,
1395
+ })}
1356
1396
 
1357
- {directoryStatus.error && <div className="agent-playground-confirm" role="alert">
1358
- <div><strong>{sandboxText(locale, "会话目录")}</strong><span>{directoryStatus.error}</span></div>
1359
- <button type="button" onClick={() => void directoryControllerRef.current?.refresh()}>{sandboxText(locale, "重新读取")}</button>
1360
- </div>}
1397
+ {transportNotice && notice('transport', {
1398
+ title: sandboxText(locale, "运行暂不可用"),
1399
+ message: transportNotice,
1400
+ action: <Button type="button" size="sm" variant="outline" onClick={() => setTransportNotice(null)}>{sandboxText(locale, "知道了")}</Button>,
1401
+ })}
1402
+
1403
+ {directoryStatus.error && notice('directory', {
1404
+ title: sandboxText(locale, "会话目录"),
1405
+ message: directoryStatus.error,
1406
+ tone: 'destructive',
1407
+ role: 'alert',
1408
+ action: <Button type="button" size="sm" variant="outline" onClick={() => void directoryControllerRef.current?.refresh()}>{sandboxText(locale, "重新读取")}</Button>,
1409
+ })}
1361
1410
 
1362
1411
  {showRunSettings && (
1363
1412
  <section className="agent-playground-run-settings" aria-label={sandboxText(locale, "运行配置")}>
1364
1413
  <label className="agent-playground-directory-field">
1365
1414
  <span><FolderOpen size={14} />{sandboxText(locale, "工作目录")}</span>
1366
- <input
1367
- disabled={directoryStatus.mode === 'loading'}
1415
+ <Input
1416
+ disabled={directoryLoading}
1368
1417
  value={activeChannel.runConfig.workingDirectory}
1369
1418
  onChange={(event) => updateRunConfig({ workingDirectory: event.target.value })}
1370
1419
  placeholder={sandboxText(locale, "使用 Host 项目目录")}
1371
1420
  spellCheck={false}
1372
1421
  />
1373
1422
  </label>
1374
- <label>
1423
+ <div className="sandbox-field">
1375
1424
  <span><ShieldCheck size={14} />{sandboxText(locale, "安全策略")}</span>
1376
- <select disabled={directoryStatus.mode === 'loading'} value={activeChannel.runConfig.safetyMode} onChange={(event) => {
1377
- const safetyMode = event.target.value as SandboxAgentRunConfig['safetyMode']
1378
- updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) })
1379
- }}>
1380
- <option value="read-only">{sandboxText(locale, "只读")}</option>
1381
- <option value="workspace-write">{sandboxText(locale, "工作区写入")}</option>
1382
- <option value="danger-full-access">{sandboxText(locale, "完全访问")}</option>
1383
- </select>
1384
- </label>
1385
- <label>
1425
+ <SelectField
1426
+ aria-label={sandboxText(locale, "安全策略")}
1427
+ disabled={directoryLoading}
1428
+ value={activeChannel.runConfig.safetyMode}
1429
+ options={[
1430
+ { value: 'read-only', label: sandboxText(locale, "只读") },
1431
+ { value: 'workspace-write', label: sandboxText(locale, "工作区写入") },
1432
+ { value: 'danger-full-access', label: sandboxText(locale, "完全访问") },
1433
+ ]}
1434
+ onValueChange={(value) => {
1435
+ const safetyMode = value as SandboxAgentRunConfig['safetyMode']
1436
+ updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) })
1437
+ }}
1438
+ />
1439
+ </div>
1440
+ <div className="sandbox-field">
1386
1441
  <span>{sandboxText(locale, "审批策略")}</span>
1387
- <select
1442
+ <SelectField
1443
+ aria-label={sandboxText(locale, "审批策略")}
1388
1444
  value={activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode}
1389
1445
  disabled={activeChannel.runConfig.safetyMode !== 'workspace-write'}
1390
- onChange={(event) => updateRunConfig({ approvalMode: event.target.value as SandboxAgentRunConfig['approvalMode'] })}
1391
- >
1392
- <option value="ask">{sandboxText(locale, "按需确认")}</option>
1393
- <option value="auto">{sandboxText(locale, "审核 Agent 自动判断")}</option>
1394
- <option value="bypass">{sandboxText(locale, "绕过审批")}</option>
1395
- </select>
1396
- </label>
1446
+ options={[
1447
+ { value: 'ask', label: sandboxText(locale, "按需确认") },
1448
+ { value: 'auto', label: sandboxText(locale, "审核 Agent 自动判断") },
1449
+ { value: 'bypass', label: sandboxText(locale, "绕过审批") },
1450
+ ]}
1451
+ onValueChange={(value) => updateRunConfig({ approvalMode: value as SandboxAgentRunConfig['approvalMode'] })}
1452
+ />
1453
+ </div>
1397
1454
  <label className="agent-playground-network-toggle">
1398
1455
  <span><Network size={14} />{sandboxText(locale, "网络访问")}</span>
1399
- <input
1400
- type="checkbox"
1456
+ <Switch
1401
1457
  checked={activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess}
1402
1458
  disabled={activeChannel.runConfig.safetyMode === 'danger-full-access'}
1403
- onChange={(event) => updateRunConfig({ networkAccess: event.target.checked })}
1459
+ onCheckedChange={(checked) => updateRunConfig({ networkAccess: checked })}
1404
1460
  />
1405
- <i aria-hidden="true" />
1406
1461
  </label>
1407
1462
  {activeChannel.runConfig.safetyMode === 'danger-full-access' && (
1408
1463
  <p><CircleAlert size={14} />{sandboxText(locale, "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。")}</p>
@@ -1432,7 +1487,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1432
1487
 
1433
1488
  {showConversationDetails && props.renderConversationDetails && (
1434
1489
  <section id="sandbox-conversation-details" className="agent-playground-conversation-details" aria-label={sandboxText(locale, "对话与轨迹")}>
1435
- <button type="button" className="agent-playground-details-back" onClick={() => setShowConversationDetails(false)}><MessageSquare size={14} />{sandboxText(locale, "返回会话")}</button>
1490
+ <Button type="button" size="sm" variant="ghost" className="sandbox-details-back" onClick={() => setShowConversationDetails(false)}><MessageSquare />{sandboxText(locale, "返回会话")}</Button>
1436
1491
  {props.renderConversationDetails({ sessionKey, canExecute, connectionId: connectionRef.current.connectionId })}
1437
1492
  </section>
1438
1493
  )}
@@ -1441,8 +1496,8 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1441
1496
  <section className="agent-playground-conversation" hidden={showConversationDetails} aria-label={sandboxText(locale, "Agent 对话")}>
1442
1497
  <div className="agent-playground-message-scroll" aria-busy={history.loading}>
1443
1498
  {history.hasMore || history.error ? <div className="agent-playground-history-navigation">
1444
- {history.error ? <p role="alert">{history.error} <button type="button" disabled={history.loading} onClick={() => void history.refresh()}>{sandboxText(locale, '重试')}</button></p> : null}
1445
- {history.hasMore ? <button type="button" disabled={history.loading} onClick={() => void history.loadEarlier()}>{sandboxText(locale, '加载更早记录')}</button> : null}
1499
+ {history.error ? <p role="alert">{history.error} <Button type="button" size="sm" variant="outline" disabled={history.loading} onClick={() => void history.refresh()}>{sandboxText(locale, '重试')}</Button></p> : null}
1500
+ {history.hasMore ? <Button type="button" size="sm" variant="outline" disabled={history.loading} onClick={() => void history.loadEarlier()}>{sandboxText(locale, '加载更早记录')}</Button> : null}
1446
1501
  </div> : null}
1447
1502
  {channelMessages.length === 0 && history.loading ? (
1448
1503
  // Same full-height box as the empty state, so loaded history does not move the composer under the cursor.
@@ -1454,9 +1509,9 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1454
1509
  <span className="agent-playground-empty-mark"><Sparkles size={24} /></span>
1455
1510
  <div><h2>{sandboxText(locale, "开始一次可观察的 Agent 运行")}</h2><p>{sandboxText(locale, "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。")}</p></div>
1456
1511
  <div className="agent-playground-prompts">
1457
- <button type="button" onClick={() => runPrompt(sandboxText(locale, "介绍当前 Agent 可以使用的能力,并给出三个具体示例。"))}>{sandboxText(locale, "探索可用能力")}</button>
1458
- <button type="button" onClick={() => runPrompt(sandboxText(locale, "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。"))}>{sandboxText(locale, "测试富文本输出")}</button>
1459
- <button type="button" onClick={() => runPrompt(sandboxText(locale, "分析一个任务从推理、工具调用到最终回复的完整执行路径。"))}>{sandboxText(locale, "观察执行路径")}</button>
1512
+ <ListItemButton onClick={() => runPrompt(sandboxText(locale, "介绍当前 Agent 可以使用的能力,并给出三个具体示例。"))}>{sandboxText(locale, "探索可用能力")}</ListItemButton>
1513
+ <ListItemButton onClick={() => runPrompt(sandboxText(locale, "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。"))}>{sandboxText(locale, "测试富文本输出")}</ListItemButton>
1514
+ <ListItemButton onClick={() => runPrompt(sandboxText(locale, "分析一个任务从推理、工具调用到最终回复的完整执行路径。"))}>{sandboxText(locale, "观察执行路径")}</ListItemButton>
1460
1515
  </div>
1461
1516
  </div>
1462
1517
  ) : (
@@ -1493,34 +1548,33 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1493
1548
  <section className="agent-playground-composer" hidden={showConversationDetails} aria-label={sandboxText(locale, "任务输入")}>
1494
1549
  {/* Toolbar */}
1495
1550
  <div className="sandbox-toolbar">
1496
- <button type="button" className={cn("sandbox-tool-button", showFacePicker && "is-active")}
1497
- onClick={() => { setShowFacePicker(!showFacePicker); setMediaPanel(null) }} title={sandboxText(locale, "插入表情")}>
1498
- <Smile size={16} />
1499
- </button>
1500
- <button type="button" className={cn("sandbox-tool-button", mediaPanel === 'image' && "is-active")}
1501
- onClick={() => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false) }} title={sandboxText(locale, "插入图片 URL")}>
1502
- <Image size={16} />
1503
- </button>
1504
- <button type="button" className={cn("sandbox-tool-button", mediaPanel === 'video' && "is-active")}
1505
- onClick={() => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false) }} title={sandboxText(locale, "插入视频 URL")}>
1506
- <Video size={16} />
1507
- </button>
1508
- <button type="button" className={cn("sandbox-tool-button", mediaPanel === 'audio' && "is-active")}
1509
- onClick={() => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false) }} title={sandboxText(locale, "插入音频 URL")}>
1510
- <Music size={16} />
1511
- </button>
1512
- <button type="button" className="sandbox-tool-button"
1551
+ <Button type="button" variant={showFacePicker ? 'secondary' : 'ghost'} size="icon" aria-pressed={showFacePicker}
1552
+ onClick={() => { setShowFacePicker(!showFacePicker); setMediaPanel(null) }} aria-label={sandboxText(locale, "插入表情")} title={sandboxText(locale, "插入表情")}>
1553
+ <Smile />
1554
+ </Button>
1555
+ <Button type="button" variant={mediaPanel === 'image' ? 'secondary' : 'ghost'} size="icon" aria-pressed={mediaPanel === 'image'}
1556
+ onClick={() => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false) }} aria-label={sandboxText(locale, "插入图片 URL")} title={sandboxText(locale, "插入图片 URL")}>
1557
+ <Image />
1558
+ </Button>
1559
+ <Button type="button" variant={mediaPanel === 'video' ? 'secondary' : 'ghost'} size="icon" aria-pressed={mediaPanel === 'video'}
1560
+ onClick={() => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false) }} aria-label={sandboxText(locale, "插入视频 URL")} title={sandboxText(locale, "插入视频 URL")}>
1561
+ <Video />
1562
+ </Button>
1563
+ <Button type="button" variant={mediaPanel === 'audio' ? 'secondary' : 'ghost'} size="icon" aria-pressed={mediaPanel === 'audio'}
1564
+ onClick={() => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false) }} aria-label={sandboxText(locale, "插入音频 URL")} title={sandboxText(locale, "插入音频 URL")}>
1565
+ <Music />
1566
+ </Button>
1567
+ <Button type="button" variant="ghost" size="icon"
1513
1568
  onClick={() => { editorRef.current?.insertAt(endpointId, endpointId); setShowFacePicker(false); setMediaPanel(null) }}
1514
1569
  title={sandboxText(locale, "@ 机器人(插入 [@{0}])", [endpointId])} aria-label={sandboxText(locale, "@ 机器人")}>
1515
- <AtSign size={16} />
1516
- </button>
1570
+ <AtSign />
1571
+ </Button>
1517
1572
  <div className="sandbox-quick-commands" role="toolbar" aria-label={locale === 'en' ? 'Quick commands' : '快捷命令'}>
1518
1573
  {(commandHints?.quick ?? []).map((cmd) => (
1519
- <button
1574
+ <ListItemButton
1520
1575
  key={cmd}
1521
- type="button"
1522
1576
  className="sandbox-command-chip"
1523
- disabled={!canExecute || directoryStatus.mode === 'loading'}
1577
+ disabled={!canExecute || directoryLoading}
1524
1578
  // Keyboard-reachable (WCAG 2.1.1). A mouse click must not keep focus on the chip,
1525
1579
  // and the prefill moves focus into the composer, so Enter sends the draft
1526
1580
  // rather than re-activating the chip after a late layout shift (#1250).
@@ -1530,10 +1584,9 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1530
1584
  >
1531
1585
  <Terminal size={11} />
1532
1586
  <span>{cmd}</span>
1533
- </button>
1587
+ </ListItemButton>
1534
1588
  ))}
1535
- <button
1536
- type="button"
1589
+ <ListItemButton
1537
1590
  className="sandbox-command-chip is-clear"
1538
1591
  disabled={channelMessages.length === 0}
1539
1592
  onClick={clearMessages}
@@ -1541,30 +1594,32 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1541
1594
  >
1542
1595
  <Trash2 size={11} />
1543
1596
  <span>{locale === 'en' ? 'Clear' : '清屏'}</span>
1544
- </button>
1597
+ </ListItemButton>
1545
1598
  </div>
1546
1599
  <div className="sandbox-toolbar-spacer" />
1547
- <div className="sandbox-composer-tabs" role="tablist" aria-label={sandboxText(locale, "消息编辑模式")}>
1548
- <button type="button" role="tab" aria-selected={composerMode === 'write'} className={cn(composerMode === 'write' && 'active')} onClick={() => setComposerMode('write')}>{sandboxText(locale, "编写")}</button>
1549
- <button type="button" role="tab" aria-selected={composerMode === 'preview'} className={cn(composerMode === 'preview' && 'active')} onClick={() => setComposerMode('preview')}>{sandboxText(locale, "预览")}</button>
1550
- </div>
1600
+ <Tabs value={composerMode} onValueChange={(value) => setComposerMode(value === 'preview' ? 'preview' : 'write')}>
1601
+ <TabsList aria-label={sandboxText(locale, "消息编辑模式")}>
1602
+ <TabsTrigger value="write">{sandboxText(locale, "编写")}</TabsTrigger>
1603
+ <TabsTrigger value="preview">{sandboxText(locale, "预览")}</TabsTrigger>
1604
+ </TabsList>
1605
+ </Tabs>
1551
1606
  {inputText && (
1552
- <button type="button" className="sandbox-tool-button"
1553
- onClick={() => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write') }} aria-label={sandboxText(locale, "清空输入")}><X size={16} /></button>
1607
+ <Button type="button" variant="ghost" size="icon"
1608
+ onClick={() => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write') }} aria-label={sandboxText(locale, "清空输入")} title={sandboxText(locale, "清空输入")}><X /></Button>
1554
1609
  )}
1555
1610
  </div>
1556
1611
 
1557
1612
  {/* Face picker */}
1558
1613
  {showFacePicker && (
1559
1614
  <div className="sandbox-panel">
1560
- <input value={faceSearchQuery} onChange={(e) => setFaceSearchQuery(e.target.value)}
1561
- placeholder={sandboxText(locale, "搜索表情...")} className="sandbox-input" />
1615
+ <Input value={faceSearchQuery} onChange={(e) => setFaceSearchQuery(e.target.value)}
1616
+ placeholder={sandboxText(locale, "搜索表情...")} aria-label={sandboxText(locale, "搜索表情...")} />
1562
1617
  <div className="sandbox-face-grid">
1563
1618
  {filteredFaces.slice(0, 80).map((face) => (
1564
- <button key={face.id} onClick={() => insertFace(face.id)} title={face.name}
1565
- className="sandbox-face-button" type="button">
1566
- <img src={`https://face.viki.moe/apng/${face.id}.png`} alt={face.name} className="sandbox-face-img" />
1567
- </button>
1619
+ <ListItemButton key={face.id} onClick={() => insertFace(face.id)} title={face.name} aria-label={face.name}
1620
+ className="sandbox-face-button">
1621
+ <img src={`https://face.viki.moe/apng/${face.id}.png`} alt="" className="sandbox-face-img" />
1622
+ </ListItemButton>
1568
1623
  ))}
1569
1624
  </div>
1570
1625
  {filteredFaces.length === 0 && (
@@ -1583,20 +1638,19 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1583
1638
  {mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)")}
1584
1639
  {mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")}
1585
1640
  </p>
1586
- <input
1641
+ <Input
1587
1642
  value={mediaUrl}
1588
1643
  onChange={(e) => setMediaUrl(e.target.value)}
1589
1644
  placeholder={mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…")}
1590
- className="sandbox-input"
1645
+ aria-label={mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…")}
1591
1646
  onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); commitMediaUrl() } }}
1592
1647
  />
1593
- <button
1648
+ <Button
1594
1649
  type="button"
1595
- className="sandbox-submit"
1596
1650
  onClick={commitMediaUrl}
1597
1651
  disabled={!mediaUrl.trim()}
1598
1652
  >
1599
- <Check size={14} /> {sandboxText(locale, "插入到输入框")}</button>
1653
+ <Check />{sandboxText(locale, "插入到输入框")}</Button>
1600
1654
  </div>
1601
1655
  )}
1602
1656
 
@@ -1619,13 +1673,14 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1619
1673
  </div>
1620
1674
  )}
1621
1675
  {atPopoverPosition && (
1622
- <div className="sandbox-at-popover"
1676
+ <div className="sandbox-at-popover" role="listbox" aria-label={sandboxText(locale, "@ 机器人")}
1623
1677
  style={{ top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }}>
1624
1678
  {filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (
1625
- <div key={user.id} className="sandbox-at-item" onClick={() => selectAtUser(user)}>
1679
+ <ListItemButton key={user.id} role="option" aria-selected={false} className="sandbox-at-item"
1680
+ onMouseDown={(event) => event.preventDefault()} onClick={() => selectAtUser(user)}>
1626
1681
  <User size={16} />
1627
- <div><div className="sandbox-at-name">{user.name}</div><div className="sandbox-at-id">ID: {user.id}</div></div>
1628
- </div>
1682
+ <span><span className="sandbox-at-name">{user.name}</span><span className="sandbox-at-id">ID: {user.id}</span></span>
1683
+ </ListItemButton>
1629
1684
  )) : (
1630
1685
  <div className="sandbox-empty-hint">
1631
1686
  <Search size={20} />
@@ -1635,12 +1690,11 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1635
1690
  </div>
1636
1691
  )}
1637
1692
  </div>
1638
- <button
1693
+ <Button
1639
1694
  type="button"
1640
- className="sandbox-send"
1641
1695
  onClick={() => { const c = editorRef.current?.getContent(); if (c) handleSendMessage(c.text, c.segments) }}
1642
- disabled={!canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments)}>
1643
- <Send size={16} /> {sandboxText(locale, "发送")}</button>
1696
+ disabled={!canExecute || directoryLoading || !hasRenderableSegments(previewSegments)}>
1697
+ <Send />{sandboxText(locale, "发送")}</Button>
1644
1698
  </div>
1645
1699
 
1646
1700
  {/* Hints: collapsed by default so the composer stays one line tall (#1250). */}
@@ -1666,15 +1720,17 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1666
1720
  <div className="agent-playground-inspector-head">
1667
1721
  <div><span>Run inspector</span><h2>{sandboxText(locale, "运行检查器")}</h2></div>
1668
1722
  <div>
1669
- <button type="button" onClick={() => void loadTrace()} aria-label={sandboxText(locale, "刷新 Agent Trace")} disabled={traceLoading}><RefreshCw size={15} className={cn(traceLoading && 'is-spinning')} /></button>
1670
- <button type="button" className="agent-playground-inspector-close" onClick={() => setShowInspector(false)} aria-label={sandboxText(locale, "关闭运行检查器")}><X size={15} /></button>
1723
+ <Button type="button" variant="ghost" size="icon" onClick={() => void loadTrace()} aria-label={sandboxText(locale, "刷新 Agent Trace")} title={sandboxText(locale, "刷新 Agent Trace")} disabled={traceLoading}><RefreshCw className={cn(traceLoading && 'is-spinning')} /></Button>
1724
+ <Button type="button" variant="ghost" size="icon" onClick={() => setShowInspector(false)} aria-label={sandboxText(locale, "关闭运行检查器")} title={sandboxText(locale, "关闭运行检查器")}><X /></Button>
1671
1725
  </div>
1672
1726
  </div>
1673
1727
 
1674
- <div className="agent-playground-inspector-tabs" role="tablist" aria-label={sandboxText(locale, "检查器视图")}>
1675
- <button type="button" role="tab" aria-selected={inspectorView === 'runs'} className={cn(inspectorView === 'runs' && 'active')} onClick={() => setInspectorView('runs')}><Activity size={13} />{sandboxText(locale, "任务")}</button>
1676
- <button type="button" role="tab" aria-selected={inspectorView === 'artifacts'} className={cn(inspectorView === 'artifacts' && 'active')} onClick={() => setInspectorView('artifacts')}><FileDiff size={13} />{sandboxText(locale, "变更与产物")}<span>{workbenchArtifacts.length}</span></button>
1677
- </div>
1728
+ <Tabs value={inspectorView} onValueChange={(value) => setInspectorView(value === 'artifacts' ? 'artifacts' : 'runs')}>
1729
+ <TabsList className="sandbox-inspector-tabs" aria-label={sandboxText(locale, "检查器视图")}>
1730
+ <TabsTrigger value="runs"><Activity size={13} />{sandboxText(locale, "任务")}</TabsTrigger>
1731
+ <TabsTrigger value="artifacts"><FileDiff size={13} />{sandboxText(locale, "变更与产物")}<span className="sandbox-tab-count">{workbenchArtifacts.length}</span></TabsTrigger>
1732
+ </TabsList>
1733
+ </Tabs>
1678
1734
 
1679
1735
  <div className={"agent-playground-inspector-view"} hidden={inspectorView !== 'runs'}>
1680
1736
 
@@ -1756,12 +1812,12 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1756
1812
  const expanded = expandedArtifact === artifact.id
1757
1813
  return (
1758
1814
  <article key={artifact.id} className={cn(`is-${artifact.status}`, expanded && 'is-expanded')}>
1759
- <button type="button" onClick={() => setExpandedArtifact(expanded ? null : artifact.id)} aria-expanded={expanded}>
1815
+ <ListItemButton onClick={() => setExpandedArtifact(expanded ? null : artifact.id)} aria-expanded={expanded}>
1760
1816
  <span className="agent-playground-artifact-icon"><ArtifactIcon size={14} /></span>
1761
1817
  <span><strong>{artifact.title}</strong><small>{artifact.path ?? artifact.detail ?? artifact.kind}</small></span>
1762
1818
  <em>{artifact.status}</em>
1763
1819
  <ChevronDown size={14} />
1764
- </button>
1820
+ </ListItemButton>
1765
1821
  {expanded && (
1766
1822
  <div className="agent-playground-artifact-detail">
1767
1823
  {artifact.path && <code>{artifact.path}</code>}
@@ -1789,6 +1845,30 @@ export default function Sandbox(props: SandboxPageProps = {}) {
1789
1845
  )
1790
1846
  }
1791
1847
 
1848
+ /** Below the Console `lg` breakpoint (64rem) the conversation list is a drawer (see the workspace styles), so it needs a toggle. */
1849
+ const DRAWER_LAYOUT_QUERY = '(width < 64rem)'
1850
+ /** On phones the run bar keeps only the run state, Stop and 「更多」; the rest moves into the menu (D18 第 7 条). */
1851
+ const COMPACT_RUNBAR_QUERY = '(width < 48rem)'
1852
+ function useMediaQuery(media: string): boolean {
1853
+ const [matches, setMatches] = useState(() => typeof window !== 'undefined' && typeof window.matchMedia === 'function'
1854
+ && window.matchMedia(media).matches)
1855
+ useEffect(() => {
1856
+ if (typeof window.matchMedia !== 'function') return
1857
+ const query = window.matchMedia(media)
1858
+ const update = () => setMatches(query.matches)
1859
+ update()
1860
+ query.addEventListener('change', update)
1861
+ return () => query.removeEventListener('change', update)
1862
+ }, [media])
1863
+ return matches
1864
+ }
1865
+
1866
+ /** ADR 0063 决策 5: a dangerous choice is an outline button with destructive text, never a solid red one. */
1867
+ function interactionVariant(primary: boolean, danger: boolean): 'default' | 'destructive-outline' | 'outline' {
1868
+ if (danger) return 'destructive-outline'
1869
+ return primary ? 'default' : 'outline'
1870
+ }
1871
+
1792
1872
  function taskStatusLabel(status: 'running' | 'completed' | 'failed' | 'cancelled', locale: SandboxLocale = 'zh-CN'): string {
1793
1873
  if (status === 'running') return sandboxText(locale, "Agent 运行中")
1794
1874
  if (status === 'completed') return sandboxText(locale, "最近任务已完成")