@zhin.js/adapter-sandbox 1.1.36 → 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.
@@ -2,18 +2,21 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { sandboxText } from './messages.js';
4
4
  import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
5
- import { cn, CodeBlock, MarkdownContent, resolveMediaSrc, pickMediaRawUrl, } from '@zhin.js/client';
5
+ import { CodeBlock, MarkdownContent, resolveMediaSrc, pickMediaRawUrl, } from '@zhin.js/client';
6
6
  import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL } from './sandboxTransport.js';
7
7
  import { createWorkspaceDirectoryController } from './workspaceDirectoryState.js';
8
8
  import { isApprovalPrompt, readSandboxCommandHints } from './composerCommands.js';
9
9
  import { ensureSandboxChatIdentity, readServerSpeaker, wantsAsMe } from './chatIdentity.js';
10
10
  import { isJsxNode, segmentFallbackText, segmentPreviewText } from './segmentFallback.js';
11
11
  import { User, Bot, Users, Trash2, Send, Hash, MessageSquare, Wifi, WifiOff, Smile, Image, X, Check, Search, Video, Music, Plus, PanelRight, ExternalLink, RefreshCw, Sparkles, Activity, Wrench, Coins, CircleAlert, Gauge, SlidersHorizontal, FolderOpen, ShieldCheck, Network, Square, RotateCcw, FileDiff, Terminal, FlaskConical, ChevronDown, FileDown, ListChecks, MoreHorizontal, Keyboard, AtSign, } from 'lucide-react';
12
+ import { Alert, AlertDescription, AlertTitle, Badge, Button, ConfirmDialog, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, Input, ListItemButton, SelectField, Switch, Tabs, TabsList, TabsTrigger, cn, usePageChrome, } from '@zhin.js/console-ui';
12
13
  import RichTextEditor, {} from './RichTextEditor.js';
13
14
  import HtmlMessage from './HtmlMessage.js';
14
15
  import { sandboxStyles } from './styles.js';
16
+ import { workspaceStyles } from './workspaceStyles.js';
15
17
  import ConversationRecoveryPanel from './ConversationRecoveryPanel.js';
16
18
  import { useSandboxHistory } from './useSandboxHistory.js';
19
+ import { quietOutcomeNotice, readMessageOutcome } from './conversationRecovery.js';
17
20
  import { agentSessionsPath, buildAgentRunReport, buildSandboxSessionKey, cancelAgentTask, deriveAgentRunSteps, deriveTaskRuns, deriveWorkbenchArtifacts, fetchAgentTrace, loadCachedAgentTrace, mergeTraceSnapshot, presentTraceEvent, summarizeTrace, saveCachedAgentTrace, } from './agentTrace.js';
18
21
  import { createDefaultPlaygroundState, loadPlaygroundState, savePlaygroundState, mergePlaygroundMessage, retirePlaygroundInteractions, } from './playgroundState.js';
19
22
  /** ADR 0060 §5.4: the simulated role is a platform standing (群主 / 管理员 / 成员), never a zhin role. */
@@ -40,6 +43,8 @@ export default function Sandbox(props = {}) {
40
43
  const [directoryStatus, setDirectoryStatus] = useState({ mode: 'loading', error: null });
41
44
  const [workspaceScope, setWorkspaceScope] = useState(null);
42
45
  const [transportNotice, setTransportNotice] = useState(null);
46
+ // #1250 (`unaddressed-message-no-record`): why the last message got no reply, from its settled outcome.
47
+ const [outcomeNotice, setOutcomeNotice] = useState(null);
43
48
  const [shellIsolation, setShellIsolation] = useState(null);
44
49
  const [inspectorView, setInspectorView] = useState('runs');
45
50
  const [expandedArtifact, setExpandedArtifact] = useState(null);
@@ -74,8 +79,6 @@ export default function Sandbox(props = {}) {
74
79
  const [identitySetup, setIdentitySetup] = useState({ status: 'idle' });
75
80
  const asMe = wantsAsMe(speakerMode, consoleUser);
76
81
  const [showSenderSettings, setShowSenderSettings] = useState(false);
77
- /** Runbar overflow: identity, run settings, inspector and clear live here (#1250). */
78
- const [showMoreActions, setShowMoreActions] = useState(false);
79
82
  /** Live binding of the current socket; drives the Host-provided quick commands. */
80
83
  const [readyConnectionId, setReadyConnectionId] = useState(undefined);
81
84
  const [commandHints, setCommandHints] = useState(null);
@@ -191,7 +194,11 @@ export default function Sandbox(props = {}) {
191
194
  const fetchFaceList = async () => {
192
195
  try {
193
196
  const res = await fetch('https://face.viki.moe/metadata.json');
194
- setFaceList(await res.json());
197
+ const body = res.ok ? await res.json() : undefined;
198
+ // A failed or malformed response must not break the page (the face picker just stays empty).
199
+ if (!Array.isArray(body))
200
+ throw new Error(`unexpected face list response (${res.status})`);
201
+ setFaceList(body);
195
202
  }
196
203
  catch (err) {
197
204
  console.error('[Sandbox] Failed to fetch face list:', err);
@@ -586,7 +593,7 @@ export default function Sandbox(props = {}) {
586
593
  case 'md':
587
594
  return _jsx(MarkdownContent, { text: typeof d.text === 'string' ? d.text : typeof d.content === 'string' ? d.content : segmentFallbackText(segment) ?? '', className: isSent ? 'zhin-markdown--inverse' : undefined }, index);
588
595
  case 'html':
589
- return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? d.content ?? d.text ?? '') }, index);
596
+ return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? d.content ?? d.text ?? ''), width: typeof d.width === 'number' ? d.width : undefined }, index);
590
597
  case 'code':
591
598
  return _jsx(CodeBlock, { code: String(d.code ?? d.text ?? d.content ?? ''), language: String(d.language ?? d.lang ?? '') }, index);
592
599
  case 'mention':
@@ -657,8 +664,8 @@ export default function Sandbox(props = {}) {
657
664
  return (_jsxs("div", { className: "sandbox-rich-card", children: [imageSrc && (_jsx("img", { src: imageSrc, alt: title, className: "sandbox-rich-card-image", onError: (e) => { e.target.style.display = 'none'; } })), _jsxs("div", { className: "sandbox-rich-card-body", children: [title && _jsx("div", { className: "sandbox-rich-card-title", children: title }), subtitle && _jsx("div", { className: "sandbox-rich-card-subtitle", children: subtitle }), description && _jsx("div", { className: "sandbox-rich-card-desc", children: _jsx(MarkdownContent, { text: description }) }), fields.length > 0 && (_jsx("dl", { className: "sandbox-rich-card-fields", children: fields.map((field, fi) => (_jsxs("div", { className: "sandbox-rich-card-field", children: [_jsx("dt", { children: String(field.label ?? field.name ?? field.key ?? '') }), _jsx("dd", { children: String(field.value ?? '') })] }, fi))) })), buttons.length > 0 && (_jsx("div", { className: "agent-playground-approval-actions sandbox-rich-card-actions", children: _jsx("div", { children: buttons.map((btn, bi) => {
658
665
  const label = String(btn.label ?? btn.text ?? btn.title ?? btn.id ?? `Action ${bi + 1}`);
659
666
  const payload = String(btn.payload ?? btn.value ?? btn.url ?? btn.id ?? label);
660
- return (_jsx("button", { type: "button", disabled: Boolean(btn.disabled) || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(payload, messageId))
661
- onInteractionSubmitted?.(); }, className: cn(btn.style === 'primary' && 'is-primary', btn.style === 'danger' && 'is-danger'), children: label }, `${payload}-${bi}`));
667
+ return (_jsx(Button, { type: "button", size: "sm", variant: interactionVariant(btn.style === 'primary', btn.style === 'danger'), disabled: Boolean(btn.disabled) || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(payload, messageId))
668
+ onInteractionSubmitted?.(); }, children: label }, `${payload}-${bi}`));
662
669
  }) }) })), !title && !subtitle && !description && fields.length === 0 && buttons.length === 0 && (_jsx(CodeBlock, { code: JSON.stringify(d, null, 2), language: "json" }))] })] }, index));
663
670
  }
664
671
  case 'share': {
@@ -679,14 +686,14 @@ export default function Sandbox(props = {}) {
679
686
  const label = String(d.label ?? d.text ?? d.id ?? 'Button');
680
687
  const payload = String(d.payload ?? d.id ?? label);
681
688
  const resolved = Boolean(messageId && interactionResolved);
682
- return (_jsx("div", { className: "agent-playground-approval-actions", children: _jsx("div", { children: _jsx("button", { type: "button", disabled: Boolean(d.disabled) || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(payload, messageId))
683
- onInteractionSubmitted?.(); }, className: cn(d.style === 'primary' && 'is-primary', d.style === 'danger' && 'is-danger'), children: label }) }) }, index));
689
+ return (_jsx("div", { className: "agent-playground-approval-actions", children: _jsx("div", { children: _jsx(Button, { type: "button", size: "sm", variant: interactionVariant(d.style === 'primary', d.style === 'danger'), disabled: Boolean(d.disabled) || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(payload, messageId))
690
+ onInteractionSubmitted?.(); }, children: label }) }) }, index));
684
691
  }
685
692
  case 'keyboard': {
686
693
  const rows = d.rows ?? [];
687
694
  const resolved = Boolean(messageId && interactionResolved);
688
- return (_jsxs("div", { className: "agent-playground-approval-actions", children: [rows.map((row, ri) => (_jsx("div", { children: row.map((btn) => (_jsx("button", { type: "button", disabled: btn.disabled || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(btn.payload, messageId))
689
- onInteractionSubmitted?.(); }, className: cn((btn.style === 'primary' || /^允许/u.test(btn.label)) && 'is-primary', (btn.style === 'danger' || /拒绝|取消/u.test(btn.label)) && 'is-danger'), children: btn.label }, btn.payload))) }, ri))), resolved && _jsxs("small", { children: [_jsx(Check, { size: 12 }), sandboxText(locale, "已提交本次选择")] })] }, index));
695
+ return (_jsxs("div", { className: "agent-playground-approval-actions", children: [rows.map((row, ri) => (_jsx("div", { children: row.map((btn) => (_jsx(Button, { type: "button", size: "sm", variant: interactionVariant(btn.style === 'primary' || /^允许/u.test(btn.label), btn.style === 'danger' || /拒绝|取消/u.test(btn.label)), disabled: btn.disabled || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(btn.payload, messageId))
696
+ onInteractionSubmitted?.(); }, children: btn.label }, btn.payload))) }, ri))), resolved && _jsxs("small", { children: [_jsx(Check, { size: 12 }), sandboxText(locale, "已提交本次选择")] })] }, index));
690
697
  }
691
698
  default: {
692
699
  const fallback = segmentFallbackText(segment);
@@ -697,6 +704,32 @@ export default function Sandbox(props = {}) {
697
704
  }
698
705
  });
699
706
  };
707
+ /** Reads the sent message's outcome a few times while it settles; a reply-less one gets a notice. */
708
+ const watchQuietOutcome = (messageId, scene) => {
709
+ const connectionId = connectionRef.current.connectionId;
710
+ if (!connectionId)
711
+ return;
712
+ const key = buildSandboxSessionKey(endpointIdRef.current, scene.type, scene.id);
713
+ const requestContext = socketRequestContextRef.current ?? captureSandboxRequestContext();
714
+ const delays = [3_000, 8_000, 20_000];
715
+ const attempt = (index) => {
716
+ window.setTimeout(() => {
717
+ if (connectionRef.current.connectionId !== connectionId)
718
+ return;
719
+ void readMessageOutcome(connectionId, key, messageId, localeRef.current, undefined, requestContext).then((outcome) => {
720
+ if (outcome === undefined) {
721
+ if (index + 1 < delays.length)
722
+ attempt(index + 1);
723
+ return;
724
+ }
725
+ const text = quietOutcomeNotice(outcome, localeRef.current);
726
+ if (text)
727
+ setOutcomeNotice({ messageId, sessionKey: key, text });
728
+ }).catch(() => { });
729
+ }, delays[index]);
730
+ };
731
+ attempt(0);
732
+ };
700
733
  const handleSendMessage = (_text, segments) => {
701
734
  if (!connectionRef.current.canExecute || directoryModeRef.current === 'loading' || !hasRenderableSegments(segments))
702
735
  return;
@@ -718,6 +751,8 @@ export default function Sandbox(props = {}) {
718
751
  }
719
752
  void directoryControllerRef.current?.save(scene, true);
720
753
  setPendingRefreshEpoch((epoch) => epoch + 1);
754
+ setOutcomeNotice(null);
755
+ watchQuietOutcome(newMessage.id, scene);
721
756
  setMessages((prev) => mergePlaygroundMessage(prev, newMessage));
722
757
  setInputText('');
723
758
  setPreviewSegments([]);
@@ -870,63 +905,73 @@ export default function Sandbox(props = {}) {
870
905
  link.remove();
871
906
  window.setTimeout(() => URL.revokeObjectURL(url), 0);
872
907
  };
873
- const inlineRunCard = currentTask ? (_jsxs("article", { className: cn('agent-playground-inline-run', `is-${currentTask.status}`), "aria-live": currentTask.status === 'running' ? 'polite' : undefined, children: [_jsx("span", { className: "agent-playground-inline-run-rail", "aria-hidden": "true" }), _jsxs("div", { className: "agent-playground-inline-run-head", children: [_jsx("span", { className: "agent-playground-inline-run-icon", children: _jsx(ListChecks, { size: 17 }) }), _jsxs("div", { className: "agent-playground-inline-run-copy", children: [_jsx("span", { children: currentTask.status === 'running' ? 'Live agent run' : 'Agent run summary' }), _jsx("h3", { children: taskStatusLabel(currentTask.status, locale) }), currentTaskMessage && _jsx("p", { children: messageText(currentTaskMessage.content) })] }), _jsxs("div", { className: "agent-playground-inline-run-actions", children: [currentTask.status === 'running' ? (_jsxs("button", { type: "button", className: "is-stop", onClick: () => void stopActiveTask(), disabled: stoppingTask, children: [_jsx(Square, { size: 12 }), stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")] })) : currentTaskMessage ? (_jsxs("button", { type: "button", onClick: retryCurrentTask, children: [_jsx(RotateCcw, { size: 13 }), sandboxText(locale, "重试")] })) : null, _jsxs("button", { type: "button", onClick: exportCurrentRun, title: sandboxText(locale, "导出 Markdown 运行报告"), children: [_jsx(FileDown, { size: 13 }), sandboxText(locale, "导出")] })] })] }), _jsxs("dl", { className: "agent-playground-inline-run-metrics", children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: currentTask.durationMs === undefined ? sandboxText(locale, "进行中") : formatDuration(currentTask.durationMs, locale) })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "步骤") }), _jsx("dd", { children: currentRunSteps.length })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: currentTask.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: currentTask.tokenCount.toLocaleString(locale) })] }), _jsxs("div", { className: cn(currentTask.problemCount > 0 && 'has-problem'), children: [_jsx("dt", { children: sandboxText(locale, "异常") }), _jsx("dd", { children: currentTask.problemCount })] })] }), inlineRunExpanded && (currentRunSteps.length > 0 ? (_jsx("ol", { className: "agent-playground-inline-run-steps", children: currentRunSteps.map((step) => (_jsxs("li", { className: cn(`is-${step.status}`), children: [_jsx("i", { "aria-hidden": "true" }), _jsxs("div", { children: [_jsx("strong", { children: step.title }), step.detail && _jsx("small", { children: step.detail })] }), _jsx("span", { children: step.durationMs === undefined ? runStepStatusLabel(step.status, locale) : formatDuration(step.durationMs, locale) })] }, step.id))) })) : _jsx("div", { className: "agent-playground-inline-run-empty", children: sandboxText(locale, "正在等待第一条运行事件…") })), _jsxs("footer", { children: [_jsxs("button", { type: "button", "aria-expanded": inlineRunExpanded, onClick: () => setInlineRunExpanded((expanded) => !expanded), children: [_jsx(ChevronDown, { size: 13 }), inlineRunExpanded ? sandboxText(locale, "收起步骤") : sandboxText(locale, "查看 {0} 个步骤", [currentRunSteps.length])] }), _jsxs("button", { type: "button", onClick: () => { setInspectorView(currentRunArtifacts.length > 0 ? 'artifacts' : 'runs'); setShowInspector(true); }, children: [currentRunArtifacts.length > 0 ? sandboxText(locale, "{0} 个变更与产物", [currentRunArtifacts.length]) : sandboxText(locale, "打开运行检查器"), _jsx(PanelRight, { size: 13 })] })] })] })) : null;
908
+ const inlineRunCard = currentTask ? (_jsxs("article", { className: cn('agent-playground-inline-run', `is-${currentTask.status}`), "aria-live": currentTask.status === 'running' ? 'polite' : undefined, children: [_jsx("span", { className: "agent-playground-inline-run-rail", "aria-hidden": "true" }), _jsxs("div", { className: "agent-playground-inline-run-head", children: [_jsx("span", { className: "agent-playground-inline-run-icon", children: _jsx(ListChecks, { size: 17 }) }), _jsxs("div", { className: "agent-playground-inline-run-copy", children: [_jsx("span", { children: currentTask.status === 'running' ? 'Live agent run' : 'Agent run summary' }), _jsx("h3", { children: taskStatusLabel(currentTask.status, locale) }), currentTaskMessage && _jsx("p", { children: messageText(currentTaskMessage.content) })] }), _jsxs("div", { className: "agent-playground-inline-run-actions", children: [currentTask.status === 'running' ? (_jsxs(Button, { type: "button", size: "sm", variant: "destructive-outline", onClick: () => void stopActiveTask(), disabled: stoppingTask, children: [_jsx(Square, {}), stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")] })) : currentTaskMessage ? (_jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: retryCurrentTask, children: [_jsx(RotateCcw, {}), sandboxText(locale, "重试")] })) : null, _jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: exportCurrentRun, title: sandboxText(locale, "导出 Markdown 运行报告"), children: [_jsx(FileDown, {}), sandboxText(locale, "导出")] })] })] }), _jsxs("dl", { className: "agent-playground-inline-run-metrics", children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: currentTask.durationMs === undefined ? sandboxText(locale, "进行中") : formatDuration(currentTask.durationMs, locale) })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "步骤") }), _jsx("dd", { children: currentRunSteps.length })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: currentTask.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: currentTask.tokenCount.toLocaleString(locale) })] }), _jsxs("div", { className: cn(currentTask.problemCount > 0 && 'has-problem'), children: [_jsx("dt", { children: sandboxText(locale, "异常") }), _jsx("dd", { children: currentTask.problemCount })] })] }), inlineRunExpanded && (currentRunSteps.length > 0 ? (_jsx("ol", { className: "agent-playground-inline-run-steps", children: currentRunSteps.map((step) => (_jsxs("li", { className: cn(`is-${step.status}`), children: [_jsx("i", { "aria-hidden": "true" }), _jsxs("div", { children: [_jsx("strong", { children: step.title }), step.detail && _jsx("small", { children: step.detail })] }), _jsx("span", { children: step.durationMs === undefined ? runStepStatusLabel(step.status, locale) : formatDuration(step.durationMs, locale) })] }, step.id))) })) : _jsx("div", { className: "agent-playground-inline-run-empty", children: sandboxText(locale, "正在等待第一条运行事件…") })), _jsxs("footer", { children: [_jsxs(Button, { type: "button", size: "sm", variant: "ghost", "aria-expanded": inlineRunExpanded, onClick: () => setInlineRunExpanded((expanded) => !expanded), children: [_jsx(ChevronDown, {}), inlineRunExpanded ? sandboxText(locale, "收起步骤") : sandboxText(locale, "查看 {0} 个步骤", [currentRunSteps.length])] }), _jsxs(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => { setInspectorView(currentRunArtifacts.length > 0 ? 'artifacts' : 'runs'); setShowInspector(true); }, children: [currentRunArtifacts.length > 0 ? sandboxText(locale, "{0} 个变更与产物", [currentRunArtifacts.length]) : sandboxText(locale, "打开运行检查器"), _jsx(PanelRight, {})] })] })] })) : null;
874
909
  const recoveryConnectionId = connectionRef.current.connectionId;
875
- return (_jsxs("section", { className: cn("zhin-sandbox agent-playground-shell", showInspector && "has-inspector"), children: [_jsx("style", { children: `${sandboxStyles}
876
- .sandbox-sender-trigger { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 6px; }
877
- .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; }
878
- .sandbox-role-badge.is-master { background: rgba(245,158,11,0.18); color: #d97706; }
879
- .sandbox-role-badge.is-admin { background: rgba(59,130,246,0.18); color: #2563eb; }
880
- .sandbox-role-badge.is-member { background: rgba(16,185,129,0.16); color: #059669; }
881
- .sandbox-role-badge.is-zhin { text-transform: none; background: rgba(139,92,246,0.16); color: #7c3aed; }
882
- .sandbox-role-switcher { display: inline-flex; gap: 4px; }
883
- .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; }
884
- .sandbox-role-option.active { font-weight: 600; border-color: currentColor; background: rgba(59,130,246,0.12); }
885
- .sandbox-sender-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
886
- .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; }
887
- .sandbox-quick-commands { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: 6px; }
888
- .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; }
889
- .sandbox-command-chip:hover:not(:disabled) { border-color: rgba(59,130,246,0.5); background: rgba(59,130,246,0.08); }
890
- .sandbox-command-chip:disabled { opacity: 0.45; cursor: not-allowed; }
891
- .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); }
892
- .sandbox-rich-card-image { width: 100%; max-height: 200px; object-fit: cover; display: block; }
893
- .sandbox-rich-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
894
- .sandbox-rich-card-title { font-weight: 600; font-size: 14px; }
895
- .sandbox-rich-card-subtitle { font-size: 12px; opacity: 0.75; }
896
- .sandbox-rich-card-desc { font-size: 13px; }
897
- .sandbox-rich-card-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin: 4px 0 0; }
898
- .sandbox-rich-card-field { background: rgba(148,163,184,0.08); padding: 4px 8px; border-radius: 6px; }
899
- .sandbox-rich-card-field dt { font-size: 11px; opacity: 0.7; }
900
- .sandbox-rich-card-field dd { margin: 0; font-size: 12px; font-weight: 500; }
901
- .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; }
902
- .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); }
903
- .sandbox-share-card-thumb { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
904
- .sandbox-share-card-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
905
- .sandbox-share-card-title { font-weight: 600; font-size: 13px; }
906
- .sandbox-share-card-title a { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: underline; }
907
- .sandbox-share-card-desc { font-size: 12px; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }
908
- .sandbox-share-card-url { font-size: 11px; opacity: 0.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
909
- ` }), _jsxs("div", { className: "agent-playground-mobilebar", children: [_jsxs("button", { type: "button", "aria-expanded": showChannelList, onClick: () => setShowChannelList(!showChannelList), children: [_jsx(MessageSquare, { size: 17 }), sandboxText(locale, "会话列表")] }), _jsx("strong", { children: sandboxText(locale, "会话") }), _jsxs("button", { type: "button", "aria-expanded": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => setShowInspector(!showInspector), children: [_jsx(PanelRight, { size: 17 }), sandboxText(locale, "检查器")] })] }), _jsxs("nav", { className: cn("channel-sidebar agent-playground-sessions", showChannelList && "show"), "aria-label": sandboxText(locale, "会话列表"), children: [_jsx("div", { className: "agent-playground-brand", children: _jsxs("div", { children: [_jsxs("div", { children: [_jsx("span", { className: "agent-playground-mark", children: _jsx(Sparkles, { size: 16 }) }), _jsxs("div", { children: [_jsx("h2", { children: sandboxText(locale, "会话") }), _jsx("small", { children: "Conversations" })] })] }), _jsx("span", { className: cn("agent-playground-connection", connected && "is-online"), title: connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket"), children: connected ? _jsx(Wifi, { size: 12 }) : _jsx(WifiOff, { size: 12 }) })] }) }), _jsxs("div", { className: "agent-playground-section-label", children: [_jsx("span", { children: sandboxText(locale, "会话列表") }), _jsx("span", { children: channels.length }), _jsx("button", { type: "button", disabled: directoryStatus.mode === 'loading', "aria-label": sandboxText(locale, "刷新会话目录"), onClick: () => void directoryControllerRef.current?.refresh(), children: _jsx(RefreshCw, { size: 13 }) })] }), _jsx("div", { className: "agent-playground-session-list", children: channels.map((channel) => {
910
+ const narrowLayout = useMediaQuery(DRAWER_LAYOUT_QUERY);
911
+ const compactRunbar = useMediaQuery(COMPACT_RUNBAR_QUERY);
912
+ const openConversationDetails = () => setShowConversationDetails((visible) => !visible);
913
+ const directoryLoading = directoryStatus.mode === 'loading';
914
+ // ADR 0063 决策 2 / D18: the page header belongs to the Console shell. The two pane toggles the narrow
915
+ // layout needs go to the shell's header actions; without a shell the page draws them itself.
916
+ const chromeActions = useMemo(() => (_jsxs(_Fragment, { children: [narrowLayout && (_jsxs(Button, { type: "button", variant: "outline", "aria-expanded": showChannelList, onClick: () => setShowChannelList((visible) => !visible), children: [_jsx(MessageSquare, {}), sandboxText(locale, "会话列表")] })), _jsxs(Button, { type: "button", variant: "outline", "aria-expanded": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => setShowInspector((visible) => !visible), children: [_jsx(PanelRight, {}), sandboxText(locale, "检查器")] })] })), [locale, narrowLayout, showChannelList, showInspector]);
917
+ const hosted = usePageChrome({ actions: chromeActions });
918
+ const connectionBadge = (_jsx("span", { className: cn("agent-playground-connection", connected && "is-online"), role: "img", "aria-label": connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket"), title: connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket"), children: connected ? _jsx(Wifi, { size: 12 }) : _jsx(WifiOff, { size: 12 }) }));
919
+ const notice = (key, options) => (_jsxs(Alert, { variant: options.tone ?? 'default', role: options.role ?? 'status', className: "sandbox-alert", children: [_jsxs("div", { className: "sandbox-alert-copy", children: [options.title && _jsx(AlertTitle, { children: options.title }), _jsx(AlertDescription, { children: options.message })] }), options.action] }, key));
920
+ return (_jsxs("section", { className: cn("zhin-sandbox agent-playground-shell", showInspector && "has-inspector", hosted && "is-hosted"), children: [_jsx("style", { children: `${workspaceStyles}
921
+ ${sandboxStyles}` }), !hosted && (_jsx("div", { className: "agent-playground-mobilebar", children: chromeActions })), _jsxs("nav", { className: cn("channel-sidebar agent-playground-sessions", showChannelList && "show"), "aria-label": sandboxText(locale, "会话列表"), children: [!hosted && (_jsx("div", { className: "agent-playground-brand", children: _jsxs("div", { children: [_jsxs("div", { children: [_jsx("span", { className: "agent-playground-mark", children: _jsx(Sparkles, { size: 16 }) }), _jsx("div", { children: _jsx("h2", { children: sandboxText(locale, "会话") }) })] }), connectionBadge] }) })), _jsxs("div", { className: "agent-playground-section-label", children: [_jsx("span", { children: sandboxText(locale, "会话列表") }), _jsx("span", { children: channels.length }), hosted && connectionBadge, _jsx(Button, { type: "button", variant: "ghost", size: "icon", disabled: directoryLoading, "aria-label": sandboxText(locale, "刷新会话目录"), title: sandboxText(locale, "刷新会话目录"), onClick: () => void directoryControllerRef.current?.refresh(), children: _jsx(RefreshCw, {}) })] }), _jsx("div", { className: "agent-playground-session-list", children: channels.map((channel) => {
910
922
  const isActive = activeChannel.id === channel.id && activeChannel.type === channel.type;
911
- return (_jsxs("button", { type: "button", disabled: directoryStatus.mode === 'loading', "aria-current": isActive ? 'page' : undefined, className: cn("agent-playground-session", isActive && "active"), onClick: () => switchChannel(channel), children: [_jsx("span", { className: "agent-playground-session-icon", children: getChannelIcon(channel.type) }), _jsxs("div", { className: "agent-playground-session-copy", children: [_jsx("div", { className: "agent-playground-session-title", children: channel.name }), _jsx("div", { className: "agent-playground-session-scope", children: channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域") })] }), channel.unread > 0 && _jsx("span", { className: "agent-playground-unread", children: channel.unread })] }, `${channel.type}:${channel.id}`));
912
- }) }), _jsx("div", { className: "agent-playground-new-session", children: showNewSession ? (_jsxs("div", { className: "agent-playground-new-form", children: [_jsx("input", { value: newSessionName, onChange: (event) => setNewSessionName(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter')
913
- addSession(); }, placeholder: sandboxText(locale, "会话名称"), autoFocus: true }), _jsx("div", { className: "agent-playground-scope-picker", role: "group", "aria-label": sandboxText(locale, "消息作用域"), children: ['private', 'group', 'channel'].map((scope) => (_jsx("button", { type: "button", "aria-pressed": newSessionScope === scope, className: cn(newSessionScope === scope && 'active'), onClick: () => setNewSessionScope(scope), children: scope === 'private' ? sandboxText(locale, "单用户") : scope === 'group' ? sandboxText(locale, "群组") : sandboxText(locale, "频道") }, scope))) }), _jsxs("div", { className: "agent-playground-new-actions", children: [_jsx("button", { type: "button", onClick: () => setShowNewSession(false), children: sandboxText(locale, "取消") }), _jsx("button", { type: "button", className: "primary", onClick: addSession, children: sandboxText(locale, "创建") })] })] })) : (_jsxs("button", { type: "button", disabled: directoryStatus.mode === 'loading', className: "agent-playground-add", onClick: () => setShowNewSession(true), children: [_jsx(Plus, { size: 15 }), sandboxText(locale, "新建会话")] })) }), _jsxs("div", { className: "agent-playground-endpoint", children: [_jsx("span", { children: directoryStatus.mode === 'loading' ? sandboxText(locale, "正在读取会话目录") : directoryStatus.mode === 'server' && !directoryStatus.error ? sandboxText(locale, "Host 会话目录") : persistenceStatus === 'saved' ? sandboxText(locale, "会话已持久化") : sandboxText(locale, "会话保存失败") }), _jsx("strong", { children: endpointId })] })] }), showChannelList && _jsx("div", { className: "channel-overlay", onClick: () => setShowChannelList(false) }), _jsxs("main", { className: "chat-area agent-playground-main", children: [_jsxs("header", { className: "agent-playground-runbar", children: [_jsxs("div", { className: "agent-playground-run-identity", children: [_jsx("span", { className: "agent-playground-run-icon", children: getChannelIcon(activeChannel.type) }), _jsx("div", { title: sessionKey, children: _jsxs("div", { className: "agent-playground-run-title", children: [_jsx("h1", { title: activeChannel.name, children: activeChannel.name }), _jsx("span", { children: scopeLabel })] }) })] }), _jsxs("div", { className: "agent-playground-run-actions", children: [_jsxs("span", { className: cn("agent-playground-run-state", currentTask?.status === 'running' && "is-running", currentTask?.status === 'failed' && 'has-problem'), children: [currentTask?.status === 'running' ? _jsx(Activity, { size: 14 }) : _jsx(Gauge, { size: 14 }), currentTask ? taskStatusLabel(currentTask.status, locale) : sandboxText(locale, "{0} 条消息", [channelMessages.length])] }), currentTask?.status === 'running' ? (_jsxs("button", { type: "button", className: "agent-playground-stop", onClick: () => void stopActiveTask(), disabled: stoppingTask, "aria-label": sandboxText(locale, "停止当前任务"), children: [_jsx(Square, { size: 13 }), stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")] })) : lastUserMessage ? (_jsxs("button", { type: "button", onClick: retryLastTask, "aria-label": sandboxText(locale, "重新运行上一个任务"), children: [_jsx(RotateCcw, { size: 14 }), sandboxText(locale, "重试")] })) : null, props.renderConversationDetails
914
- ? _jsxs("button", { type: "button", disabled: !canExecute, "aria-expanded": showConversationDetails, "aria-controls": "sandbox-conversation-details", onClick: () => setShowConversationDetails((visible) => !visible), children: [_jsx(ListChecks, { size: 14 }), sandboxText(locale, "对话与轨迹")] })
915
- : _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsxs("div", { className: "sandbox-more", children: [_jsx("button", { type: "button", className: cn("sandbox-more-trigger", (showMoreActions || showSenderSettings || showRunSettings) && 'active'), "aria-haspopup": "menu", "aria-expanded": showMoreActions, onClick: () => setShowMoreActions((visible) => !visible), "aria-label": sandboxText(locale, "更多操作"), title: sandboxText(locale, "更多操作"), children: _jsx(MoreHorizontal, { size: 16 }) }), showMoreActions && (_jsxs(_Fragment, { children: [_jsx("div", { className: "sandbox-more-backdrop", onClick: () => setShowMoreActions(false) }), _jsxs("div", { className: "sandbox-more-menu", role: "menu", "aria-label": sandboxText(locale, "更多操作"), children: [_jsxs("button", { type: "button", role: "menuitemcheckbox", "aria-checked": showSenderSettings, onClick: () => { setShowSenderSettings((visible) => !visible); setShowMoreActions(false); }, children: [_jsx(User, { size: 14 }), _jsx("span", { children: sandboxText(locale, "模拟发送者") }), _jsxs("em", { className: cn("sandbox-role-badge", `is-${senderRole}`), title: locale === 'en' ? 'Simulated platform standing (not a zhin role)' : '模拟的平台身份(不是 zhin 角色)', children: [asMe ? sandboxText(locale, "我的聊天身份") : (senderName.trim() || senderId.trim() || 'dev-user'), " \u00B7 ", platformStandingLabel(senderRole, locale)] }), serverRole && (serverRole.simulated
916
- ? _jsx("em", { className: "sandbox-role-badge is-simulated", title: sandboxText(locale, "客户端自填的发送者不解析 zhin 角色"), children: sandboxText(locale, "模拟身份,无角色") })
917
- : _jsx("em", { className: "sandbox-role-badge is-zhin", title: locale === 'en' ? 'Resolved by the server: zhin role · Agent trust tier' : '服务端解析:zhin 角色 · Agent 信任档位', children: `zhin: ${serverRole.chatRole ?? (locale === 'en' ? 'none' : '无')} · ${serverRole.trustLevel}` }))] }), _jsxs("button", { type: "button", role: "menuitemcheckbox", "aria-checked": showRunSettings, onClick: () => { setShowRunSettings((visible) => !visible); setShowMoreActions(false); }, children: [_jsx(SlidersHorizontal, { size: 14 }), _jsx("span", { children: sandboxText(locale, "配置运行环境") })] }), _jsxs("button", { type: "button", role: "menuitemcheckbox", "aria-checked": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => { setShowInspector(!showInspector); setShowMoreActions(false); }, children: [_jsx(PanelRight, { size: 14 }), _jsx("span", { children: sandboxText(locale, "切换运行检查器") })] }), _jsxs("button", { type: "button", role: "menuitem", className: "is-danger", onClick: () => { setConfirmClear(true); setShowMoreActions(false); }, children: [_jsx(Trash2, { size: 14 }), _jsx("span", { children: sandboxText(locale, "清空当前会话") })] })] })] }))] })] })] }), showSenderSettings && (_jsxs("section", { className: "agent-playground-run-settings sandbox-sender-settings", "aria-label": locale === 'en' ? 'Simulated sender' : '模拟发送者配置', children: [_jsxs("div", { className: "sandbox-speaker-mode", children: [_jsxs("label", { className: "sandbox-speaker-toggle", children: [_jsx("input", { type: "checkbox", checked: speakerMode === 'me', disabled: !consoleUser, onChange: (event) => setSpeakerMode(event.target.checked ? 'me' : 'simulated') }), _jsx("span", { children: sandboxText(locale, "以我的聊天身份发言") })] }), _jsx("p", { children: !consoleUser
923
+ return (_jsxs(ListItemButton, { disabled: directoryLoading, "aria-current": isActive ? 'page' : undefined, className: cn("agent-playground-session", isActive && "active"), onClick: () => switchChannel(channel), children: [_jsx("span", { className: "agent-playground-session-icon", children: getChannelIcon(channel.type) }), _jsxs("div", { className: "agent-playground-session-copy", children: [_jsx("div", { className: "agent-playground-session-title", children: channel.name }), _jsx("div", { className: "agent-playground-session-scope", children: channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域") })] }), channel.unread > 0 && _jsx("span", { className: "agent-playground-unread", children: channel.unread })] }, `${channel.type}:${channel.id}`));
924
+ }) }), _jsx("div", { className: "agent-playground-new-session", children: showNewSession ? (_jsxs("div", { className: "agent-playground-new-form", children: [_jsx(Input, { value: newSessionName, onChange: (event) => setNewSessionName(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter')
925
+ addSession(); }, placeholder: sandboxText(locale, "会话名称"), "aria-label": sandboxText(locale, "会话名称"), autoFocus: true }), _jsx("div", { className: "agent-playground-scope-picker", role: "group", "aria-label": sandboxText(locale, "消息作用域"), children: ['private', 'group', 'channel'].map((scope) => (_jsx(ListItemButton, { "aria-pressed": newSessionScope === scope, className: cn(newSessionScope === scope && 'active'), onClick: () => setNewSessionScope(scope), children: scope === 'private' ? sandboxText(locale, "单用户") : scope === 'group' ? sandboxText(locale, "群组") : sandboxText(locale, "频道") }, scope))) }), _jsxs("div", { className: "agent-playground-new-actions", children: [_jsx(Button, { type: "button", variant: "outline", onClick: () => setShowNewSession(false), children: sandboxText(locale, "取消") }), _jsx(Button, { type: "button", onClick: addSession, children: sandboxText(locale, "创建") })] })] })) : (_jsxs(Button, { type: "button", variant: "outline", disabled: directoryLoading, className: "sandbox-block-button", onClick: () => setShowNewSession(true), children: [_jsx(Plus, {}), sandboxText(locale, "新建会话")] })) }), _jsxs("div", { className: "agent-playground-endpoint", children: [_jsx("span", { children: directoryLoading ? sandboxText(locale, "正在读取会话目录") : directoryStatus.mode === 'server' && !directoryStatus.error ? sandboxText(locale, "Host 会话目录") : persistenceStatus === 'saved' ? sandboxText(locale, "会话已持久化") : sandboxText(locale, "会话保存失败") }), _jsx("strong", { children: endpointId })] })] }), showChannelList && _jsx("div", { className: "channel-overlay", onClick: () => setShowChannelList(false) }), _jsxs("main", { className: "chat-area agent-playground-main", children: [_jsxs("header", { className: "agent-playground-runbar", children: [_jsxs("div", { className: "agent-playground-run-identity", children: [_jsx("span", { className: "agent-playground-run-icon", children: getChannelIcon(activeChannel.type) }), _jsx("div", { title: sessionKey, children: _jsxs("div", { className: "agent-playground-run-title", children: [_jsx("h2", { title: activeChannel.name, children: activeChannel.name }), _jsx("span", { children: scopeLabel })] }) })] }), _jsxs("div", { className: "agent-playground-run-actions", children: [_jsxs("span", { className: cn("agent-playground-run-state", currentTask?.status === 'running' && "is-running", currentTask?.status === 'failed' && 'has-problem'), children: [currentTask?.status === 'running' ? _jsx(Activity, { size: 14 }) : _jsx(Gauge, { size: 14 }), currentTask ? taskStatusLabel(currentTask.status, locale) : sandboxText(locale, "{0} 条消息", [channelMessages.length])] }), currentTask?.status === 'running' ? (_jsxs(Button, { type: "button", size: "sm", variant: "destructive-outline", onClick: () => void stopActiveTask(), disabled: stoppingTask, "aria-label": sandboxText(locale, "停止当前任务"), children: [_jsx(Square, {}), stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")] })) : lastUserMessage && !compactRunbar ? (_jsxs(Button, { type: "button", size: "sm", variant: "outline", onClick: retryLastTask, "aria-label": sandboxText(locale, "重新运行上一个任务"), children: [_jsx(RotateCcw, {}), sandboxText(locale, "重试")] })) : null, compactRunbar ? null : props.renderConversationDetails
926
+ ? _jsxs(Button, { type: "button", size: "sm", variant: "outline", disabled: !canExecute, "aria-expanded": showConversationDetails, "aria-controls": "sandbox-conversation-details", onClick: openConversationDetails, children: [_jsx(ListChecks, {}), sandboxText(locale, "对话与轨迹")] })
927
+ : _jsx(Button, { asChild: true, size: "sm", variant: "outline", children: _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, {}), sandboxText(locale, "对话与轨迹")] }) }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { type: "button", size: "icon", variant: "ghost", className: cn((showSenderSettings || showRunSettings) && 'is-active'), "aria-label": sandboxText(locale, "更多操作"), title: sandboxText(locale, "更多操作"), children: _jsx(MoreHorizontal, {}) }) }), _jsxs(DropdownMenuContent, { align: "end", children: [compactRunbar && currentTask?.status !== 'running' && lastUserMessage && (_jsxs(DropdownMenuItem, { onSelect: retryLastTask, children: [_jsx(RotateCcw, {}), sandboxText(locale, "重试")] })), compactRunbar && (props.renderConversationDetails
928
+ ? _jsxs(DropdownMenuItem, { disabled: !canExecute, onSelect: openConversationDetails, children: [_jsx(ListChecks, {}), sandboxText(locale, "对话与轨迹")] })
929
+ : _jsx(DropdownMenuItem, { asChild: true, children: _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, {}), sandboxText(locale, "对话与轨迹")] }) })), compactRunbar && _jsx(DropdownMenuSeparator, {}), _jsx(DropdownMenuCheckboxItem, { checked: showSenderSettings, onCheckedChange: (checked) => setShowSenderSettings(checked === true), children: _jsxs("span", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { children: sandboxText(locale, "模拟发送者") }), _jsxs(Badge, { variant: "secondary", size: "sm", title: locale === 'en' ? 'Simulated platform standing (not a zhin role)' : '模拟的平台身份(不是 zhin 角色)', children: [asMe ? sandboxText(locale, "我的聊天身份") : (senderName.trim() || senderId.trim() || 'dev-user'), " \u00B7 ", platformStandingLabel(senderRole, locale)] }), serverRole && (serverRole.simulated
930
+ ? _jsx(Badge, { variant: "secondary", size: "sm", title: sandboxText(locale, "客户端自填的发送者不解析 zhin 角色"), children: sandboxText(locale, "模拟身份,无角色") })
931
+ : _jsx(Badge, { variant: "secondary", size: "sm", title: locale === 'en' ? 'Resolved by the server: zhin role · Agent trust tier' : '服务端解析:zhin 角色 · Agent 信任档位', children: `zhin: ${serverRole.chatRole ?? (locale === 'en' ? 'none' : '无')} · ${serverRole.trustLevel}` }))] }) }), _jsx(DropdownMenuCheckboxItem, { checked: showRunSettings, onCheckedChange: (checked) => setShowRunSettings(checked === true), children: sandboxText(locale, "配置运行环境") }), _jsx(DropdownMenuCheckboxItem, { checked: showInspector, "aria-controls": "sandbox-run-inspector", onCheckedChange: (checked) => setShowInspector(checked === true), children: sandboxText(locale, "切换运行检查器") }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { className: "text-destructive", onSelect: () => setConfirmClear(true), children: [_jsx(Trash2, {}), sandboxText(locale, "清空当前会话")] })] })] })] })] }), showSenderSettings && (_jsxs("section", { className: "agent-playground-run-settings sandbox-sender-settings", "aria-label": locale === 'en' ? 'Simulated sender' : '模拟发送者配置', children: [_jsxs("div", { className: "sandbox-speaker-mode", children: [_jsxs("label", { className: "sandbox-speaker-toggle", children: [_jsx(Switch, { checked: speakerMode === 'me', disabled: !consoleUser, onCheckedChange: (checked) => setSpeakerMode(checked ? 'me' : 'simulated') }), _jsx("span", { children: sandboxText(locale, "以我的聊天身份发言") })] }), _jsx("p", { children: !consoleUser
918
932
  ? sandboxText(locale, "当前连接没有 Console 用户(未登录或 --standalone),所有消息都按模拟身份处理,不解析 zhin 角色。")
919
933
  : asMe
920
934
  ? sandboxText(locale, "以链接到你 Console 账号的聊天身份发言,角色按你的聊天角色解析。")
921
- : sandboxText(locale, "模拟身份,无角色:自填的发送者 ID 只用于模拟别人,不解析 zhin 角色。") }), asMe && serverRole?.asMeUnavailable === 'needs-global-iam' && (_jsx("div", { className: "sandbox-speaker-setup", role: "status", children: _jsx("span", { children: sandboxText(locale, "链接到你的聊天身份持有全局角色,以它发言需要全局 iam.manage 权限;上一条消息按模拟身份(无角色)发送。") }) })), asMe && serverRole?.asMeUnavailable === 'no-identity' && (_jsxs("div", { className: "sandbox-speaker-setup", role: "status", children: [_jsx("span", { children: sandboxText(locale, "你在 Sandbox 上还没有聊天身份,上一条消息按模拟身份发送。") }), _jsx("button", { type: "button", disabled: identitySetup.status === 'busy', onClick: () => {
935
+ : sandboxText(locale, "模拟身份,无角色:自填的发送者 ID 只用于模拟别人,不解析 zhin 角色。") }), asMe && serverRole?.asMeUnavailable === 'needs-global-iam' && (_jsx("div", { className: "sandbox-speaker-setup", role: "status", children: _jsx("span", { children: sandboxText(locale, "链接到你的聊天身份持有全局角色,以它发言需要全局 iam.manage 权限;上一条消息按模拟身份(无角色)发送。") }) })), asMe && serverRole?.asMeUnavailable === 'no-identity' && (_jsxs("div", { className: "sandbox-speaker-setup", role: "status", children: [_jsx("span", { children: sandboxText(locale, "你在 Sandbox 上还没有聊天身份,上一条消息按模拟身份发送。") }), _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: identitySetup.status === 'busy', onClick: () => {
922
936
  setIdentitySetup({ status: 'busy' });
923
937
  void ensureSandboxChatIdentity(socketRequestContextRef.current ?? undefined).then((result) => {
924
938
  setIdentitySetup(result.status === 'ok' ? { status: 'done' } : result);
925
939
  });
926
- }, children: sandboxText(locale, "在 Sandbox 上创建我的聊天身份") }), identitySetup.status === 'done' && _jsx("em", { children: sandboxText(locale, "已创建,下一条消息生效。") }), identitySetup.status === 'unsupported' && _jsx("em", { children: sandboxText(locale, "当前 Host 不支持,请升级。") }), identitySetup.status === 'failed' && _jsx("em", { children: identitySetup.message })] }))] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(User, { size: 14 }), locale === 'en' ? 'Sender ID (simulated, no role)' : '发送者 ID(模拟身份,无角色)'] }), _jsx("input", { value: senderId, disabled: asMe, onChange: (event) => setSenderId(event.target.value), placeholder: "dev-user", spellCheck: false })] }), _jsxs("label", { children: [_jsx("span", { children: locale === 'en' ? 'Sender Name' : '发送者昵称' }), _jsx("input", { value: senderName, disabled: asMe, onChange: (event) => setSenderName(event.target.value), placeholder: "Developer", spellCheck: false })] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), locale === 'en' ? 'Platform standing (not a zhin role)' : '平台身份(不是 zhin 角色)'] }), _jsx("div", { className: "sandbox-role-switcher", role: "group", "aria-label": locale === 'en' ? 'Platform standing' : '平台身份', children: ['member', 'admin', 'master'].map((role) => (_jsx("button", { type: "button", "aria-pressed": senderRole === role, className: cn("sandbox-role-option", `is-${role}`, senderRole === role && "active"), onClick: () => setSenderRole(role), children: platformStandingLabel(role, locale) }, role))) })] }), _jsxs("div", { className: "sandbox-sender-presets", children: [_jsx("button", { type: "button", onClick: () => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master'); }, children: locale === 'en' ? 'Group owner (platform standing, dev-user)' : '群主(平台身份,dev-user)' }), _jsx("button", { type: "button", onClick: () => { setSenderId('admin-user'); setSenderName('Admin'); setSenderRole('admin'); }, children: "Admin (admin-user)" }), _jsx("button", { type: "button", onClick: () => { setSenderId('member-user'); setSenderName('Member'); setSenderRole('member'); }, children: "Member (member-user)" })] })] })), cancellationFeedback && _jsxs("div", { className: "agent-playground-confirm", role: cancellationFeedback.kind === 'error' ? 'alert' : 'status', children: [_jsx("div", { children: _jsx("span", { children: cancellationFeedback.message }) }), _jsx("button", { type: "button", onClick: () => setCancellationFeedback(null), children: sandboxText(locale, "知道了") })] }), confirmClear && (_jsxs("div", { className: "agent-playground-confirm", role: "alert", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "清空当前测试记录?") }), _jsxs("span", { children: [sandboxText(locale, "只移除“"), activeChannel.name, sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")] })] }), _jsx("button", { type: "button", onClick: () => setConfirmClear(false), children: sandboxText(locale, "取消") }), _jsx("button", { type: "button", className: "danger", onClick: clearMessages, children: sandboxText(locale, "确认清空") })] })), ['emoji', 'parse'].filter((kind) => inlineNotices[kind]).map((kind) => (_jsxs("div", { className: "sandbox-notice", role: "status", children: [_jsx(CircleAlert, { size: 14 }), _jsx("span", { children: kind === 'emoji' ? sandboxText(locale, "表情列表加载失败,表情选择器暂不可用。") : sandboxText(locale, "收到一条无法解析的消息,已忽略。") }), _jsx("button", { type: "button", onClick: () => setInlineNotices((n) => ({ ...n, [kind]: false })), children: sandboxText(locale, "知道了") })] }, kind))), transportNotice && (_jsxs("div", { className: "agent-playground-confirm", role: "status", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "运行暂不可用") }), _jsx("span", { children: transportNotice })] }), _jsx("button", { type: "button", onClick: () => setTransportNotice(null), children: sandboxText(locale, "知道了") })] })), directoryStatus.error && _jsxs("div", { className: "agent-playground-confirm", role: "alert", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "会话目录") }), _jsx("span", { children: directoryStatus.error })] }), _jsx("button", { type: "button", onClick: () => void directoryControllerRef.current?.refresh(), children: sandboxText(locale, "重新读取") })] }), showRunSettings && (_jsxs("section", { className: "agent-playground-run-settings", "aria-label": sandboxText(locale, "运行配置"), children: [_jsxs("label", { className: "agent-playground-directory-field", children: [_jsxs("span", { children: [_jsx(FolderOpen, { size: 14 }), sandboxText(locale, "工作目录")] }), _jsx("input", { disabled: directoryStatus.mode === 'loading', value: activeChannel.runConfig.workingDirectory, onChange: (event) => updateRunConfig({ workingDirectory: event.target.value }), placeholder: sandboxText(locale, "使用 Host 项目目录"), spellCheck: false })] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), sandboxText(locale, "安全策略")] }), _jsxs("select", { disabled: directoryStatus.mode === 'loading', value: activeChannel.runConfig.safetyMode, onChange: (event) => {
927
- const safetyMode = event.target.value;
940
+ }, children: sandboxText(locale, "在 Sandbox 上创建我的聊天身份") }), identitySetup.status === 'done' && _jsx("em", { children: sandboxText(locale, "已创建,下一条消息生效。") }), identitySetup.status === 'unsupported' && _jsx("em", { children: sandboxText(locale, "当前 Host 不支持,请升级。") }), identitySetup.status === 'failed' && _jsx("em", { children: identitySetup.message })] }))] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(User, { size: 14 }), locale === 'en' ? 'Sender ID (simulated, no role)' : '发送者 ID(模拟身份,无角色)'] }), _jsx(Input, { value: senderId, disabled: asMe, onChange: (event) => setSenderId(event.target.value), placeholder: "dev-user", spellCheck: false })] }), _jsxs("label", { children: [_jsx("span", { children: locale === 'en' ? 'Sender Name' : '发送者昵称' }), _jsx(Input, { value: senderName, disabled: asMe, onChange: (event) => setSenderName(event.target.value), placeholder: "Developer", spellCheck: false })] }), _jsxs("div", { className: "sandbox-field", children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), locale === 'en' ? 'Platform standing (not a zhin role)' : '平台身份(不是 zhin 角色)'] }), _jsx("div", { className: "sandbox-role-switcher", role: "group", "aria-label": locale === 'en' ? 'Platform standing' : '平台身份', children: ['member', 'admin', 'master'].map((role) => (_jsx(ListItemButton, { "aria-pressed": senderRole === role, className: cn("sandbox-role-option", `is-${role}`, senderRole === role && "active"), onClick: () => setSenderRole(role), children: platformStandingLabel(role, locale) }, role))) })] }), _jsxs("div", { className: "sandbox-sender-presets", children: [_jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master'); }, children: locale === 'en' ? 'Group owner (platform standing, dev-user)' : '群主(平台身份,dev-user)' }), _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => { setSenderId('admin-user'); setSenderName('Admin'); setSenderRole('admin'); }, children: "Admin (admin-user)" }), _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => { setSenderId('member-user'); setSenderName('Member'); setSenderRole('member'); }, children: "Member (member-user)" })] })] })), cancellationFeedback && notice('cancellation', {
941
+ message: cancellationFeedback.message,
942
+ tone: cancellationFeedback.kind === 'error' ? 'destructive' : 'default',
943
+ role: cancellationFeedback.kind === 'error' ? 'alert' : 'status',
944
+ action: _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setCancellationFeedback(null), children: sandboxText(locale, "知道了") }),
945
+ }), _jsx(ConfirmDialog, { open: confirmClear, onOpenChange: setConfirmClear, title: sandboxText(locale, "清空当前测试记录?"), description: `${sandboxText(locale, "只移除“")}${activeChannel.name}${sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")}`, confirmLabel: sandboxText(locale, "确认清空"), cancelLabel: sandboxText(locale, "取消"), variant: "destructive", onConfirm: clearMessages }), ['emoji', 'parse'].filter((kind) => inlineNotices[kind]).map((kind) => notice(kind, {
946
+ message: kind === 'emoji' ? sandboxText(locale, "表情列表加载失败,表情选择器暂不可用。") : sandboxText(locale, "收到一条无法解析的消息,已忽略。"),
947
+ action: _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setInlineNotices((n) => ({ ...n, [kind]: false })), children: sandboxText(locale, "知道了") }),
948
+ })), outcomeNotice && outcomeNotice.sessionKey === sessionKey && notice('outcome', {
949
+ title: sandboxText(locale, "这条消息没有回复"),
950
+ message: outcomeNotice.text,
951
+ role: 'status',
952
+ action: _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setOutcomeNotice(null), children: sandboxText(locale, "知道了") }),
953
+ }), transportNotice && notice('transport', {
954
+ title: sandboxText(locale, "运行暂不可用"),
955
+ message: transportNotice,
956
+ action: _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => setTransportNotice(null), children: sandboxText(locale, "知道了") }),
957
+ }), directoryStatus.error && notice('directory', {
958
+ title: sandboxText(locale, "会话目录"),
959
+ message: directoryStatus.error,
960
+ tone: 'destructive',
961
+ role: 'alert',
962
+ action: _jsx(Button, { type: "button", size: "sm", variant: "outline", onClick: () => void directoryControllerRef.current?.refresh(), children: sandboxText(locale, "重新读取") }),
963
+ }), showRunSettings && (_jsxs("section", { className: "agent-playground-run-settings", "aria-label": sandboxText(locale, "运行配置"), children: [_jsxs("label", { className: "agent-playground-directory-field", children: [_jsxs("span", { children: [_jsx(FolderOpen, { size: 14 }), sandboxText(locale, "工作目录")] }), _jsx(Input, { disabled: directoryLoading, value: activeChannel.runConfig.workingDirectory, onChange: (event) => updateRunConfig({ workingDirectory: event.target.value }), placeholder: sandboxText(locale, "使用 Host 项目目录"), spellCheck: false })] }), _jsxs("div", { className: "sandbox-field", children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), sandboxText(locale, "安全策略")] }), _jsx(SelectField, { "aria-label": sandboxText(locale, "安全策略"), disabled: directoryLoading, value: activeChannel.runConfig.safetyMode, options: [
964
+ { value: 'read-only', label: sandboxText(locale, "只读") },
965
+ { value: 'workspace-write', label: sandboxText(locale, "工作区写入") },
966
+ { value: 'danger-full-access', label: sandboxText(locale, "完全访问") },
967
+ ], onValueChange: (value) => {
968
+ const safetyMode = value;
928
969
  updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) });
929
- }, children: [_jsx("option", { value: "read-only", children: sandboxText(locale, "只读") }), _jsx("option", { value: "workspace-write", children: sandboxText(locale, "工作区写入") }), _jsx("option", { value: "danger-full-access", children: sandboxText(locale, "完全访问") })] })] }), _jsxs("label", { children: [_jsx("span", { children: sandboxText(locale, "审批策略") }), _jsxs("select", { value: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode, disabled: activeChannel.runConfig.safetyMode !== 'workspace-write', onChange: (event) => updateRunConfig({ approvalMode: event.target.value }), children: [_jsx("option", { value: "ask", children: sandboxText(locale, "按需确认") }), _jsx("option", { value: "auto", children: sandboxText(locale, "审核 Agent 自动判断") }), _jsx("option", { value: "bypass", children: sandboxText(locale, "绕过审批") })] })] }), _jsxs("label", { className: "agent-playground-network-toggle", children: [_jsxs("span", { children: [_jsx(Network, { size: 14 }), sandboxText(locale, "网络访问")] }), _jsx("input", { type: "checkbox", checked: activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess, disabled: activeChannel.runConfig.safetyMode === 'danger-full-access', onChange: (event) => updateRunConfig({ networkAccess: event.target.checked }) }), _jsx("i", { "aria-hidden": "true" })] }), activeChannel.runConfig.safetyMode === 'danger-full-access' && (_jsxs("p", { children: [_jsx(CircleAlert, { size: 14 }), sandboxText(locale, "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。")] })), activeChannel.runConfig.safetyMode !== 'danger-full-access' && shellIsolation?.available === false && (_jsxs("p", { children: [_jsx(CircleAlert, { size: 14 }), sandboxText(locale, "安全 Shell 需要可用的 Docker daemon;当前仅文件工具可运行。"), shellIsolation.message] }))] })), canExecute && recoveryConnectionId && (_jsx(ConversationRecoveryPanel, { connectionId: recoveryConnectionId, sessionKey: sessionKey, locale: locale, hidden: showConversationDetails, pendingRefreshEpoch: pendingRefreshEpoch, onRetiredInteractions: (retired) => {
970
+ } })] }), _jsxs("div", { className: "sandbox-field", children: [_jsx("span", { children: sandboxText(locale, "审批策略") }), _jsx(SelectField, { "aria-label": sandboxText(locale, "审批策略"), value: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode, disabled: activeChannel.runConfig.safetyMode !== 'workspace-write', options: [
971
+ { value: 'ask', label: sandboxText(locale, "按需确认") },
972
+ { value: 'auto', label: sandboxText(locale, "审核 Agent 自动判断") },
973
+ { value: 'bypass', label: sandboxText(locale, "绕过审批") },
974
+ ], onValueChange: (value) => updateRunConfig({ approvalMode: value }) })] }), _jsxs("label", { className: "agent-playground-network-toggle", children: [_jsxs("span", { children: [_jsx(Network, { size: 14 }), sandboxText(locale, "网络访问")] }), _jsx(Switch, { checked: activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess, disabled: activeChannel.runConfig.safetyMode === 'danger-full-access', onCheckedChange: (checked) => updateRunConfig({ networkAccess: checked }) })] }), activeChannel.runConfig.safetyMode === 'danger-full-access' && (_jsxs("p", { children: [_jsx(CircleAlert, { size: 14 }), sandboxText(locale, "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。")] })), activeChannel.runConfig.safetyMode !== 'danger-full-access' && shellIsolation?.available === false && (_jsxs("p", { children: [_jsx(CircleAlert, { size: 14 }), sandboxText(locale, "安全 Shell 需要可用的 Docker daemon;当前仅文件工具可运行。"), shellIsolation.message] }))] })), canExecute && recoveryConnectionId && (_jsx(ConversationRecoveryPanel, { connectionId: recoveryConnectionId, sessionKey: sessionKey, locale: locale, hidden: showConversationDetails, pendingRefreshEpoch: pendingRefreshEpoch, onRetiredInteractions: (retired) => {
930
975
  const segments = retired.flatMap(interaction => interaction.segments);
931
976
  setMessages(previous => {
932
977
  const current = activeChannelRef.current;
@@ -935,34 +980,58 @@ export default function Sandbox(props = {}) {
935
980
  return previous;
936
981
  return retirePlaygroundInteractions(previous, activeChannel, segments);
937
982
  });
938
- }, requestContext: socketRequestContextRef.current ?? undefined, renderInteraction: (segments, id, submitted, onSubmitted) => renderMessageSegments(segments, false, id, submitted, onSubmitted) }, JSON.stringify([recoveryConnectionId, sessionKey]))), showConversationDetails && props.renderConversationDetails && (_jsxs("section", { id: "sandbox-conversation-details", className: "agent-playground-conversation-details", "aria-label": sandboxText(locale, "对话与轨迹"), children: [_jsxs("button", { type: "button", className: "agent-playground-details-back", onClick: () => setShowConversationDetails(false), children: [_jsx(MessageSquare, { size: 14 }), sandboxText(locale, "返回会话")] }), props.renderConversationDetails({ sessionKey, canExecute, connectionId: connectionRef.current.connectionId })] })), _jsx("section", { className: "agent-playground-conversation", hidden: showConversationDetails, "aria-label": sandboxText(locale, "Agent 对话"), children: _jsxs("div", { className: "agent-playground-message-scroll", "aria-busy": history.loading, children: [history.hasMore || history.error ? _jsxs("div", { className: "agent-playground-history-navigation", children: [history.error ? _jsxs("p", { role: "alert", children: [history.error, " ", _jsx("button", { type: "button", disabled: history.loading, onClick: () => void history.refresh(), children: sandboxText(locale, '重试') })] }) : null, history.hasMore ? _jsx("button", { type: "button", disabled: history.loading, onClick: () => void history.loadEarlier(), children: sandboxText(locale, '加载更早记录') }) : null] }) : null, channelMessages.length === 0 && history.loading ? (_jsx("div", { className: "agent-playground-empty", role: "status", children: _jsx("p", { children: sandboxText(locale, "正在加载会话记录…") }) })) : channelMessages.length === 0 ? (_jsxs("div", { className: "agent-playground-empty", children: [_jsx("span", { className: "agent-playground-empty-mark", children: _jsx(Sparkles, { size: 24 }) }), _jsxs("div", { children: [_jsx("h2", { children: sandboxText(locale, "开始一次可观察的 Agent 运行") }), _jsx("p", { children: sandboxText(locale, "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。") })] }), _jsxs("div", { className: "agent-playground-prompts", children: [_jsx("button", { type: "button", onClick: () => runPrompt(sandboxText(locale, "介绍当前 Agent 可以使用的能力,并给出三个具体示例。")), children: sandboxText(locale, "探索可用能力") }), _jsx("button", { type: "button", onClick: () => runPrompt(sandboxText(locale, "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。")), children: sandboxText(locale, "测试富文本输出") }), _jsx("button", { type: "button", onClick: () => runPrompt(sandboxText(locale, "分析一个任务从推理、工具调用到最终回复的完整执行路径。")), children: sandboxText(locale, "观察执行路径") })] })] })) : (_jsxs("div", { className: "agent-playground-message-list", children: [channelMessages.map((msg) => {
983
+ }, requestContext: socketRequestContextRef.current ?? undefined, renderInteraction: (segments, id, submitted, onSubmitted) => renderMessageSegments(segments, false, id, submitted, onSubmitted) }, JSON.stringify([recoveryConnectionId, sessionKey]))), showConversationDetails && props.renderConversationDetails && (_jsxs("section", { id: "sandbox-conversation-details", className: "agent-playground-conversation-details", "aria-label": sandboxText(locale, "对话与轨迹"), children: [_jsxs(Button, { type: "button", size: "sm", variant: "ghost", className: "sandbox-details-back", onClick: () => setShowConversationDetails(false), children: [_jsx(MessageSquare, {}), sandboxText(locale, "返回会话")] }), props.renderConversationDetails({ sessionKey, canExecute, connectionId: connectionRef.current.connectionId })] })), _jsx("section", { className: "agent-playground-conversation", hidden: showConversationDetails, "aria-label": sandboxText(locale, "Agent 对话"), children: _jsxs("div", { className: "agent-playground-message-scroll", "aria-busy": history.loading, children: [history.hasMore || history.error ? _jsxs("div", { className: "agent-playground-history-navigation", children: [history.error ? _jsxs("p", { role: "alert", children: [history.error, " ", _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: history.loading, onClick: () => void history.refresh(), children: sandboxText(locale, '重试') })] }) : null, history.hasMore ? _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: history.loading, onClick: () => void history.loadEarlier(), children: sandboxText(locale, '加载更早记录') }) : null] }) : null, channelMessages.length === 0 && history.loading ? (_jsx("div", { className: "agent-playground-empty", role: "status", children: _jsx("p", { children: sandboxText(locale, "正在加载会话记录…") }) })) : channelMessages.length === 0 ? (_jsxs("div", { className: "agent-playground-empty", children: [_jsx("span", { className: "agent-playground-empty-mark", children: _jsx(Sparkles, { size: 24 }) }), _jsxs("div", { children: [_jsx("h2", { children: sandboxText(locale, "开始一次可观察的 Agent 运行") }), _jsx("p", { children: sandboxText(locale, "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。") })] }), _jsxs("div", { className: "agent-playground-prompts", children: [_jsx(ListItemButton, { onClick: () => runPrompt(sandboxText(locale, "介绍当前 Agent 可以使用的能力,并给出三个具体示例。")), children: sandboxText(locale, "探索可用能力") }), _jsx(ListItemButton, { onClick: () => runPrompt(sandboxText(locale, "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。")), children: sandboxText(locale, "测试富文本输出") }), _jsx(ListItemButton, { onClick: () => runPrompt(sandboxText(locale, "分析一个任务从推理、工具调用到最终回复的完整执行路径。")), children: sandboxText(locale, "观察执行路径") })] })] })) : (_jsxs("div", { className: "agent-playground-message-list", children: [channelMessages.map((msg) => {
939
984
  if (msg.recalledMessageId)
940
985
  return _jsx("p", { className: "agent-playground-history-notice", children: sandboxText(locale, '消息已撤回') }, msg.id);
941
986
  const isApproval = isApprovalPrompt(msg);
942
987
  return (_jsxs(React.Fragment, { children: [_jsxs("article", { className: cn("agent-playground-message", msg.type === 'sent' ? "is-user" : "is-agent", isApproval && "is-approval"), children: [_jsx("span", { className: "agent-playground-message-avatar", children: msg.type === 'received' ? _jsx(Bot, { size: 16 }) : _jsx(User, { size: 16 }) }), _jsxs("div", { className: "agent-playground-message-main", children: [_jsxs("div", { className: "agent-playground-message-meta", children: [_jsx("strong", { children: isApproval ? sandboxText(locale, "需要你的确认") : msg.type === 'received' ? endpointId : msg.senderId === connectionRef.current.ownerId ? sandboxText(locale, "你") : msg.senderName || msg.senderId }), isApproval && _jsx("span", { children: "approval required" }), msg.recalled && _jsx("span", { children: sandboxText(locale, '已撤回') }), _jsx("time", { children: new Date(msg.timestamp).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' }) })] }), _jsx("div", { className: "agent-playground-message-content", children: renderMessageSegments(msg.content, msg.type === 'sent', msg.id, msg.interactionResolved === true, undefined, msg.interactionReadOnly !== true) })] })] }), currentTaskMessage?.id === msg.id && inlineRunCard] }, JSON.stringify([msg.channelType, msg.channelId, msg.type, msg.id])));
943
- }), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] }))] }) }), _jsxs("section", { className: "agent-playground-composer", hidden: showConversationDetails, "aria-label": sandboxText(locale, "任务输入"), children: [_jsxs("div", { className: "sandbox-toolbar", children: [_jsx("button", { type: "button", className: cn("sandbox-tool-button", showFacePicker && "is-active"), onClick: () => { setShowFacePicker(!showFacePicker); setMediaPanel(null); }, title: sandboxText(locale, "插入表情"), children: _jsx(Smile, { size: 16 }) }), _jsx("button", { type: "button", className: cn("sandbox-tool-button", mediaPanel === 'image' && "is-active"), onClick: () => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false); }, title: sandboxText(locale, "插入图片 URL"), children: _jsx(Image, { size: 16 }) }), _jsx("button", { type: "button", className: cn("sandbox-tool-button", mediaPanel === 'video' && "is-active"), onClick: () => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false); }, title: sandboxText(locale, "插入视频 URL"), children: _jsx(Video, { size: 16 }) }), _jsx("button", { type: "button", className: cn("sandbox-tool-button", mediaPanel === 'audio' && "is-active"), onClick: () => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false); }, title: sandboxText(locale, "插入音频 URL"), children: _jsx(Music, { size: 16 }) }), _jsx("button", { type: "button", className: "sandbox-tool-button", onClick: () => { editorRef.current?.insertAt(endpointId, endpointId); setShowFacePicker(false); setMediaPanel(null); }, title: sandboxText(locale, "@ 机器人(插入 [@{0}])", [endpointId]), "aria-label": sandboxText(locale, "@ 机器人"), children: _jsx(AtSign, { size: 16 }) }), _jsxs("div", { className: "sandbox-quick-commands", role: "toolbar", "aria-label": locale === 'en' ? 'Quick commands' : '快捷命令', children: [(commandHints?.quick ?? []).map((cmd) => (_jsxs("button", { type: "button", className: "sandbox-command-chip", disabled: !canExecute || directoryStatus.mode === 'loading',
988
+ }), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] }))] }) }), _jsxs("section", { className: "agent-playground-composer", hidden: showConversationDetails, "aria-label": sandboxText(locale, "任务输入"), children: [_jsxs("div", { className: "sandbox-toolbar", children: [_jsx(Button, { type: "button", variant: showFacePicker ? 'secondary' : 'ghost', size: "icon", "aria-pressed": showFacePicker, onClick: () => { setShowFacePicker(!showFacePicker); setMediaPanel(null); }, "aria-label": sandboxText(locale, "插入表情"), title: sandboxText(locale, "插入表情"), children: _jsx(Smile, {}) }), _jsx(Button, { type: "button", variant: mediaPanel === 'image' ? 'secondary' : 'ghost', size: "icon", "aria-pressed": mediaPanel === 'image', onClick: () => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false); }, "aria-label": sandboxText(locale, "插入图片 URL"), title: sandboxText(locale, "插入图片 URL"), children: _jsx(Image, {}) }), _jsx(Button, { type: "button", variant: mediaPanel === 'video' ? 'secondary' : 'ghost', size: "icon", "aria-pressed": mediaPanel === 'video', onClick: () => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false); }, "aria-label": sandboxText(locale, "插入视频 URL"), title: sandboxText(locale, "插入视频 URL"), children: _jsx(Video, {}) }), _jsx(Button, { type: "button", variant: mediaPanel === 'audio' ? 'secondary' : 'ghost', size: "icon", "aria-pressed": mediaPanel === 'audio', onClick: () => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false); }, "aria-label": sandboxText(locale, "插入音频 URL"), title: sandboxText(locale, "插入音频 URL"), children: _jsx(Music, {}) }), _jsx(Button, { type: "button", variant: "ghost", size: "icon", onClick: () => { editorRef.current?.insertAt(endpointId, endpointId); setShowFacePicker(false); setMediaPanel(null); }, title: sandboxText(locale, "@ 机器人(插入 [@{0}])", [endpointId]), "aria-label": sandboxText(locale, "@ 机器人"), children: _jsx(AtSign, {}) }), _jsxs("div", { className: "sandbox-quick-commands", role: "toolbar", "aria-label": locale === 'en' ? 'Quick commands' : '快捷命令', children: [(commandHints?.quick ?? []).map((cmd) => (_jsxs(ListItemButton, { className: "sandbox-command-chip", disabled: !canExecute || directoryLoading,
944
989
  // Keyboard-reachable (WCAG 2.1.1). A mouse click must not keep focus on the chip,
945
990
  // and the prefill moves focus into the composer, so Enter sends the draft
946
991
  // rather than re-activating the chip after a late layout shift (#1250).
947
992
  onMouseDown: (event) => event.preventDefault(),
948
993
  // Pre-fill the composer (never overwriting a draft); sending stays an explicit Enter / Send.
949
- onClick: () => editorRef.current?.setText(cmd), children: [_jsx(Terminal, { size: 11 }), _jsx("span", { children: cmd })] }, cmd))), _jsxs("button", { type: "button", className: "sandbox-command-chip is-clear", disabled: channelMessages.length === 0, onClick: clearMessages, title: sandboxText(locale, "清空当前会话"), children: [_jsx(Trash2, { size: 11 }), _jsx("span", { children: locale === 'en' ? 'Clear' : '清屏' })] })] }), _jsx("div", { className: "sandbox-toolbar-spacer" }), _jsxs("div", { className: "sandbox-composer-tabs", role: "tablist", "aria-label": sandboxText(locale, "消息编辑模式"), children: [_jsx("button", { type: "button", role: "tab", "aria-selected": composerMode === 'write', className: cn(composerMode === 'write' && 'active'), onClick: () => setComposerMode('write'), children: sandboxText(locale, "编写") }), _jsx("button", { type: "button", role: "tab", "aria-selected": composerMode === 'preview', className: cn(composerMode === 'preview' && 'active'), onClick: () => setComposerMode('preview'), children: sandboxText(locale, "预览") })] }), inputText && (_jsx("button", { type: "button", className: "sandbox-tool-button", onClick: () => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write'); }, "aria-label": sandboxText(locale, "清空输入"), children: _jsx(X, { size: 16 }) }))] }), showFacePicker && (_jsxs("div", { className: "sandbox-panel", children: [_jsx("input", { value: faceSearchQuery, onChange: (e) => setFaceSearchQuery(e.target.value), placeholder: sandboxText(locale, "搜索表情..."), className: "sandbox-input" }), _jsx("div", { className: "sandbox-face-grid", children: filteredFaces.slice(0, 80).map((face) => (_jsx("button", { onClick: () => insertFace(face.id), title: face.name, className: "sandbox-face-button", type: "button", children: _jsx("img", { src: `https://face.viki.moe/apng/${face.id}.png`, alt: face.name, className: "sandbox-face-img" }) }, face.id))) }), filteredFaces.length === 0 && (_jsxs("div", { className: "sandbox-empty-hint", children: [_jsx(Search, { size: 28 }), _jsx("span", { children: sandboxText(locale, "未找到匹配的表情") })] }))] })), mediaPanel && (_jsxs("div", { className: "sandbox-panel", children: [_jsxs("p", { className: "sandbox-panel-hint", children: [mediaPanel === 'image' && sandboxText(locale, "支持 http(s) 图片链接或 data URL"), mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)"), mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")] }), _jsx("input", { value: mediaUrl, onChange: (e) => setMediaUrl(e.target.value), placeholder: mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…"), className: "sandbox-input", onKeyDown: (e) => { if (e.key === 'Enter') {
994
+ onClick: () => editorRef.current?.setText(cmd), children: [_jsx(Terminal, { size: 11 }), _jsx("span", { children: cmd })] }, cmd))), _jsxs(ListItemButton, { className: "sandbox-command-chip is-clear", disabled: channelMessages.length === 0, onClick: clearMessages, title: sandboxText(locale, "清空当前会话"), children: [_jsx(Trash2, { size: 11 }), _jsx("span", { children: locale === 'en' ? 'Clear' : '清屏' })] })] }), _jsx("div", { className: "sandbox-toolbar-spacer" }), _jsx(Tabs, { value: composerMode, onValueChange: (value) => setComposerMode(value === 'preview' ? 'preview' : 'write'), children: _jsxs(TabsList, { "aria-label": sandboxText(locale, "消息编辑模式"), children: [_jsx(TabsTrigger, { value: "write", children: sandboxText(locale, "编写") }), _jsx(TabsTrigger, { value: "preview", children: sandboxText(locale, "预览") })] }) }), inputText && (_jsx(Button, { type: "button", variant: "ghost", size: "icon", onClick: () => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write'); }, "aria-label": sandboxText(locale, "清空输入"), title: sandboxText(locale, "清空输入"), children: _jsx(X, {}) }))] }), showFacePicker && (_jsxs("div", { className: "sandbox-panel", children: [_jsx(Input, { value: faceSearchQuery, onChange: (e) => setFaceSearchQuery(e.target.value), placeholder: sandboxText(locale, "搜索表情..."), "aria-label": sandboxText(locale, "搜索表情...") }), _jsx("div", { className: "sandbox-face-grid", children: filteredFaces.slice(0, 80).map((face) => (_jsx(ListItemButton, { onClick: () => insertFace(face.id), title: face.name, "aria-label": face.name, className: "sandbox-face-button", children: _jsx("img", { src: `https://face.viki.moe/apng/${face.id}.png`, alt: "", className: "sandbox-face-img" }) }, face.id))) }), filteredFaces.length === 0 && (_jsxs("div", { className: "sandbox-empty-hint", children: [_jsx(Search, { size: 28 }), _jsx("span", { children: sandboxText(locale, "未找到匹配的表情") })] }))] })), mediaPanel && (_jsxs("div", { className: "sandbox-panel", children: [_jsxs("p", { className: "sandbox-panel-hint", children: [mediaPanel === 'image' && sandboxText(locale, "支持 http(s) 图片链接或 data URL"), mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)"), mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")] }), _jsx(Input, { value: mediaUrl, onChange: (e) => setMediaUrl(e.target.value), placeholder: mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…"), "aria-label": mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…"), onKeyDown: (e) => { if (e.key === 'Enter') {
950
995
  e.preventDefault();
951
996
  commitMediaUrl();
952
- } } }), _jsxs("button", { type: "button", className: "sandbox-submit", onClick: commitMediaUrl, disabled: !mediaUrl.trim(), children: [_jsx(Check, { size: 14 }), " ", sandboxText(locale, "插入到输入框")] })] })), _jsxs("div", { className: "sandbox-editor-row", children: [_jsxs("div", { className: "sandbox-editor-wrap", children: [_jsx("div", { hidden: composerMode !== 'write', children: _jsx(RichTextEditor, { locale: locale, ref: editorRef, placeholder: sandboxText(locale, "向 {0} 发送消息,支持 Markdown...", [activeChannel.name]), onSend: handleSendMessage, onChange: handleEditorChange, onAtTrigger: handleAtTrigger, minHeight: "44px", maxHeight: "200px" }) }), composerMode === 'preview' && (_jsx("div", { className: "sandbox-markdown-preview", role: "tabpanel", children: inputText.trim()
997
+ } } }), _jsxs(Button, { type: "button", onClick: commitMediaUrl, disabled: !mediaUrl.trim(), children: [_jsx(Check, {}), sandboxText(locale, "插入到输入框")] })] })), _jsxs("div", { className: "sandbox-editor-row", children: [_jsxs("div", { className: "sandbox-editor-wrap", children: [_jsx("div", { hidden: composerMode !== 'write', children: _jsx(RichTextEditor, { locale: locale, ref: editorRef, placeholder: sandboxText(locale, "向 {0} 发送消息,支持 Markdown...", [activeChannel.name]), onSend: handleSendMessage, onChange: handleEditorChange, onAtTrigger: handleAtTrigger, minHeight: "44px", maxHeight: "200px" }) }), composerMode === 'preview' && (_jsx("div", { className: "sandbox-markdown-preview", role: "tabpanel", children: inputText.trim()
953
998
  ? _jsx(MarkdownContent, { text: inputText })
954
- : _jsx("span", { className: "sandbox-markdown-preview-empty", children: sandboxText(locale, "输入 Markdown 后可在这里检查最终效果") }) })), atPopoverPosition && (_jsx("div", { className: "sandbox-at-popover", style: { top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }, children: filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (_jsxs("div", { className: "sandbox-at-item", onClick: () => selectAtUser(user), children: [_jsx(User, { size: 16 }), _jsxs("div", { children: [_jsx("div", { className: "sandbox-at-name", children: user.name }), _jsxs("div", { className: "sandbox-at-id", children: ["ID: ", user.id] })] })] }, user.id))) : (_jsxs("div", { className: "sandbox-empty-hint", children: [_jsx(Search, { size: 20 }), _jsx("span", { children: sandboxText(locale, "未找到匹配的用户") })] })) }))] }), _jsxs("button", { type: "button", className: "sandbox-send", onClick: () => { const c = editorRef.current?.getContent(); if (c)
955
- handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("details", { className: "sandbox-hints", children: [_jsxs("summary", { children: [_jsx(Keyboard, { size: 12 }), " ", sandboxText(locale, "快捷操作与语法")] }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "Enter" }), " ", sandboxText(locale, "发送")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "Shift+Enter" }), " ", sandboxText(locale, "换行")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "```ts" }), " ", sandboxText(locale, "代码块")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人")] }), _jsxs("li", { children: [_jsxs("span", { className: "sandbox-hint-key", children: ["[@", endpointId, "]"] }), " ", sandboxText(locale, "@机器人(群聊里唤起机器人,也可点 @ 按钮插入)")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "[image:URL]" }), " ", _jsx("span", { className: "sandbox-hint-key", children: "[video:URL]" }), " ", _jsx("span", { className: "sandbox-hint-key", children: "[audio:URL]" }), " ", sandboxText(locale, "媒体")] }), commandHints && _jsxs("li", { children: [_jsx(Terminal, { size: 11 }), " ", commandHints.prefix
999
+ : _jsx("span", { className: "sandbox-markdown-preview-empty", children: sandboxText(locale, "输入 Markdown 后可在这里检查最终效果") }) })), atPopoverPosition && (_jsx("div", { className: "sandbox-at-popover", role: "listbox", "aria-label": sandboxText(locale, "@ 机器人"), style: { top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }, children: filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (_jsxs(ListItemButton, { role: "option", "aria-selected": false, className: "sandbox-at-item", onMouseDown: (event) => event.preventDefault(), onClick: () => selectAtUser(user), children: [_jsx(User, { size: 16 }), _jsxs("span", { children: [_jsx("span", { className: "sandbox-at-name", children: user.name }), _jsxs("span", { className: "sandbox-at-id", children: ["ID: ", user.id] })] })] }, user.id))) : (_jsxs("div", { className: "sandbox-empty-hint", children: [_jsx(Search, { size: 20 }), _jsx("span", { children: sandboxText(locale, "未找到匹配的用户") })] })) }))] }), _jsxs(Button, { type: "button", onClick: () => { const c = editorRef.current?.getContent(); if (c)
1000
+ handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryLoading || !hasRenderableSegments(previewSegments), children: [_jsx(Send, {}), sandboxText(locale, "发送")] })] }), _jsxs("details", { className: "sandbox-hints", children: [_jsxs("summary", { children: [_jsx(Keyboard, { size: 12 }), " ", sandboxText(locale, "快捷操作与语法")] }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "Enter" }), " ", sandboxText(locale, "发送")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "Shift+Enter" }), " ", sandboxText(locale, "换行")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "```ts" }), " ", sandboxText(locale, "代码块")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人")] }), _jsxs("li", { children: [_jsxs("span", { className: "sandbox-hint-key", children: ["[@", endpointId, "]"] }), " ", sandboxText(locale, "@机器人(群聊里唤起机器人,也可点 @ 按钮插入)")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "[image:URL]" }), " ", _jsx("span", { className: "sandbox-hint-key", children: "[video:URL]" }), " ", _jsx("span", { className: "sandbox-hint-key", children: "[audio:URL]" }), " ", sandboxText(locale, "媒体")] }), commandHints && _jsxs("li", { children: [_jsx(Terminal, { size: 11 }), " ", commandHints.prefix
956
1001
  ? sandboxText(locale, "命令以 {0} 开头", [commandHints.prefix])
957
- : sandboxText(locale, "命令无需前缀")] })] })] })] })] }), _jsxs("aside", { id: "sandbox-run-inspector", className: cn("agent-playground-inspector", showInspector && "show"), hidden: !showInspector, "aria-hidden": !showInspector, "aria-label": sandboxText(locale, "运行检查器"), children: [_jsxs("div", { className: "agent-playground-inspector-head", children: [_jsxs("div", { children: [_jsx("span", { children: "Run inspector" }), _jsx("h2", { children: sandboxText(locale, "运行检查器") })] }), _jsxs("div", { children: [_jsx("button", { type: "button", onClick: () => void loadTrace(), "aria-label": sandboxText(locale, "刷新 Agent Trace"), disabled: traceLoading, children: _jsx(RefreshCw, { size: 15, className: cn(traceLoading && 'is-spinning') }) }), _jsx("button", { type: "button", className: "agent-playground-inspector-close", onClick: () => setShowInspector(false), "aria-label": sandboxText(locale, "关闭运行检查器"), children: _jsx(X, { size: 15 }) })] })] }), _jsxs("div", { className: "agent-playground-inspector-tabs", role: "tablist", "aria-label": sandboxText(locale, "检查器视图"), children: [_jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'runs', className: cn(inspectorView === 'runs' && 'active'), onClick: () => setInspectorView('runs'), children: [_jsx(Activity, { size: 13 }), sandboxText(locale, "任务")] }), _jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'artifacts', className: cn(inspectorView === 'artifacts' && 'active'), onClick: () => setInspectorView('artifacts'), children: [_jsx(FileDiff, { size: 13 }), sandboxText(locale, "变更与产物"), _jsx("span", { children: workbenchArtifacts.length })] })] }), _jsxs("div", { className: "agent-playground-inspector-view", hidden: inspectorView !== 'runs', children: [_jsxs("section", { className: "agent-playground-inspector-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "运行概览") }), _jsx("small", { children: traceSummary.activeTurns > 0 ? 'live' : 'idle' })] }), _jsxs("div", { className: "agent-playground-metrics", children: [_jsxs("div", { children: [_jsx(Activity, {}), _jsx("strong", { children: traceSummary.eventCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "事件") })] }), _jsxs("div", { children: [_jsx(Wrench, {}), _jsx("strong", { children: traceSummary.toolCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "工具") })] }), _jsxs("div", { children: [_jsx(Coins, {}), _jsx("strong", { children: traceSummary.tokenCount.toLocaleString(locale) }), _jsx("span", { children: "Token" })] }), _jsxs("div", { className: cn(traceSummary.problemCount > 0 && 'has-problem'), children: [_jsx(CircleAlert, {}), _jsx("strong", { children: traceSummary.problemCount }), _jsx("span", { children: sandboxText(locale, "异常") })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section", children: [_jsx("div", { className: "agent-playground-inspector-title", children: _jsx("span", { children: sandboxText(locale, "上下文") }) }), _jsxs("dl", { className: "agent-playground-context-list", children: [_jsxs("div", { children: [_jsx("dt", { children: "Endpoint" }), _jsx("dd", { children: endpointId })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scope" }), _jsx("dd", { children: activeChannel.type })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scene" }), _jsx("dd", { children: activeChannel.id })] }), _jsxs("div", { children: [_jsx("dt", { children: "Workdir" }), _jsx("dd", { title: activeChannel.runConfig.workingDirectory, children: activeChannel.runConfig.workingDirectory || 'Host project root' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Security" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Approval" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Network" }), _jsx("dd", { children: activeChannel.runConfig.networkAccess ? 'enabled' : 'disabled' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Isolation" }), _jsx("dd", { className: cn(shellIsolation?.available && 'is-online'), children: shellIsolation ? `${shellIsolation.provider}: ${shellIsolation.available ? 'ready' : 'unavailable'}` : 'checking' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Transport" }), _jsx("dd", { className: cn(connected && 'is-online'), children: connected ? 'WebSocket online' : 'reconnecting' })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-task-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "任务历史") }), _jsxs("small", { children: [taskRuns.length, " runs"] })] }), taskRuns.length > 0 ? (_jsx("div", { className: "agent-playground-task-list", children: taskRuns.slice(0, 8).map((run) => (_jsxs("article", { className: cn(`is-${run.status}`), children: [_jsx("i", {}), _jsxs("div", { children: [_jsx("strong", { children: taskStatusLabel(run.status, locale) }), _jsx("code", { children: run.turnId.slice(0, 10) })] }), _jsxs("dl", { children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: run.durationMs === undefined ? sandboxText(locale, "进行中") : `${run.durationMs.toLocaleString(locale)} ms` })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: run.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: run.tokenCount.toLocaleString(locale) })] })] })] }, run.id))) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "运行任务后会在这里形成可回溯记录") })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-trace-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "最近执行") }), _jsx("small", { children: "2s sync" })] }), traceNotice && _jsxs("div", { className: "agent-playground-trace-notice", role: "alert", children: [_jsx(CircleAlert, { size: 16 }), _jsx("span", { children: traceNotice })] }), traceLoading && !trace ? (_jsxs("div", { className: "agent-playground-trace-loading", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : recentTraceEvents.length ? (_jsx("div", { className: "agent-playground-trace-list", children: recentTraceEvents.map((event) => {
1002
+ : sandboxText(locale, "命令无需前缀")] })] })] })] })] }), _jsxs("aside", { id: "sandbox-run-inspector", className: cn("agent-playground-inspector", showInspector && "show"), hidden: !showInspector, "aria-hidden": !showInspector, "aria-label": sandboxText(locale, "运行检查器"), children: [_jsxs("div", { className: "agent-playground-inspector-head", children: [_jsxs("div", { children: [_jsx("span", { children: "Run inspector" }), _jsx("h2", { children: sandboxText(locale, "运行检查器") })] }), _jsxs("div", { children: [_jsx(Button, { type: "button", variant: "ghost", size: "icon", onClick: () => void loadTrace(), "aria-label": sandboxText(locale, "刷新 Agent Trace"), title: sandboxText(locale, "刷新 Agent Trace"), disabled: traceLoading, children: _jsx(RefreshCw, { className: cn(traceLoading && 'is-spinning') }) }), _jsx(Button, { type: "button", variant: "ghost", size: "icon", onClick: () => setShowInspector(false), "aria-label": sandboxText(locale, "关闭运行检查器"), title: sandboxText(locale, "关闭运行检查器"), children: _jsx(X, {}) })] })] }), _jsx(Tabs, { value: inspectorView, onValueChange: (value) => setInspectorView(value === 'artifacts' ? 'artifacts' : 'runs'), children: _jsxs(TabsList, { className: "sandbox-inspector-tabs", "aria-label": sandboxText(locale, "检查器视图"), children: [_jsxs(TabsTrigger, { value: "runs", children: [_jsx(Activity, { size: 13 }), sandboxText(locale, "任务")] }), _jsxs(TabsTrigger, { value: "artifacts", children: [_jsx(FileDiff, { size: 13 }), sandboxText(locale, "变更与产物"), _jsx("span", { className: "sandbox-tab-count", children: workbenchArtifacts.length })] })] }) }), _jsxs("div", { className: "agent-playground-inspector-view", hidden: inspectorView !== 'runs', children: [_jsxs("section", { className: "agent-playground-inspector-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "运行概览") }), _jsx("small", { children: traceSummary.activeTurns > 0 ? 'live' : 'idle' })] }), _jsxs("div", { className: "agent-playground-metrics", children: [_jsxs("div", { children: [_jsx(Activity, {}), _jsx("strong", { children: traceSummary.eventCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "事件") })] }), _jsxs("div", { children: [_jsx(Wrench, {}), _jsx("strong", { children: traceSummary.toolCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "工具") })] }), _jsxs("div", { children: [_jsx(Coins, {}), _jsx("strong", { children: traceSummary.tokenCount.toLocaleString(locale) }), _jsx("span", { children: "Token" })] }), _jsxs("div", { className: cn(traceSummary.problemCount > 0 && 'has-problem'), children: [_jsx(CircleAlert, {}), _jsx("strong", { children: traceSummary.problemCount }), _jsx("span", { children: sandboxText(locale, "异常") })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section", children: [_jsx("div", { className: "agent-playground-inspector-title", children: _jsx("span", { children: sandboxText(locale, "上下文") }) }), _jsxs("dl", { className: "agent-playground-context-list", children: [_jsxs("div", { children: [_jsx("dt", { children: "Endpoint" }), _jsx("dd", { children: endpointId })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scope" }), _jsx("dd", { children: activeChannel.type })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scene" }), _jsx("dd", { children: activeChannel.id })] }), _jsxs("div", { children: [_jsx("dt", { children: "Workdir" }), _jsx("dd", { title: activeChannel.runConfig.workingDirectory, children: activeChannel.runConfig.workingDirectory || 'Host project root' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Security" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Approval" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Network" }), _jsx("dd", { children: activeChannel.runConfig.networkAccess ? 'enabled' : 'disabled' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Isolation" }), _jsx("dd", { className: cn(shellIsolation?.available && 'is-online'), children: shellIsolation ? `${shellIsolation.provider}: ${shellIsolation.available ? 'ready' : 'unavailable'}` : 'checking' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Transport" }), _jsx("dd", { className: cn(connected && 'is-online'), children: connected ? 'WebSocket online' : 'reconnecting' })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-task-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "任务历史") }), _jsxs("small", { children: [taskRuns.length, " runs"] })] }), taskRuns.length > 0 ? (_jsx("div", { className: "agent-playground-task-list", children: taskRuns.slice(0, 8).map((run) => (_jsxs("article", { className: cn(`is-${run.status}`), children: [_jsx("i", {}), _jsxs("div", { children: [_jsx("strong", { children: taskStatusLabel(run.status, locale) }), _jsx("code", { children: run.turnId.slice(0, 10) })] }), _jsxs("dl", { children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: run.durationMs === undefined ? sandboxText(locale, "进行中") : `${run.durationMs.toLocaleString(locale)} ms` })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: run.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: run.tokenCount.toLocaleString(locale) })] })] })] }, run.id))) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "运行任务后会在这里形成可回溯记录") })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-trace-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "最近执行") }), _jsx("small", { children: "2s sync" })] }), traceNotice && _jsxs("div", { className: "agent-playground-trace-notice", role: "alert", children: [_jsx(CircleAlert, { size: 16 }), _jsx("span", { children: traceNotice })] }), traceLoading && !trace ? (_jsxs("div", { className: "agent-playground-trace-loading", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : recentTraceEvents.length ? (_jsx("div", { className: "agent-playground-trace-list", children: recentTraceEvents.map((event) => {
958
1003
  const item = presentTraceEvent(event, locale);
959
1004
  return (_jsxs("div", { className: cn("agent-playground-trace-item", `is-${item.tone}`), children: [_jsx("span", { className: "agent-playground-trace-dot" }), _jsxs("div", { children: [_jsx("strong", { children: item.title }), item.detail ? _jsx("small", { children: item.detail }) : null] }), _jsx("time", { children: new Date(event.recordedAt).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit' }) })] }, event.sequence));
960
1005
  }) })) : (_jsxs("div", { className: "agent-playground-trace-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "发送任务后显示推理与工具轨迹") })] }))] })] }), _jsx("div", { className: "agent-playground-inspector-view", hidden: inspectorView !== 'artifacts', children: _jsxs("section", { className: "agent-playground-inspector-section agent-playground-artifact-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "文件与命令产物") }), _jsxs("small", { children: [workbenchArtifacts.length, " items"] })] }), workbenchArtifacts.length > 0 ? (_jsx("div", { className: "agent-playground-artifact-list", children: workbenchArtifacts.map((artifact) => {
961
1006
  const ArtifactIcon = artifact.kind === 'file-change' ? FileDiff : artifact.kind === 'test' ? FlaskConical : Terminal;
962
1007
  const expanded = expandedArtifact === artifact.id;
963
- return (_jsxs("article", { className: cn(`is-${artifact.status}`, expanded && 'is-expanded'), children: [_jsxs("button", { type: "button", onClick: () => setExpandedArtifact(expanded ? null : artifact.id), "aria-expanded": expanded, children: [_jsx("span", { className: "agent-playground-artifact-icon", children: _jsx(ArtifactIcon, { size: 14 }) }), _jsxs("span", { children: [_jsx("strong", { children: artifact.title }), _jsx("small", { children: artifact.path ?? artifact.detail ?? artifact.kind })] }), _jsx("em", { children: artifact.status }), _jsx(ChevronDown, { size: 14 })] }), expanded && (_jsxs("div", { className: "agent-playground-artifact-detail", children: [artifact.path && _jsx("code", { children: artifact.path }), canExecute && artifact.projectFilePath && (_jsxs("a", { href: `/files?${new URLSearchParams({ path: artifact.projectFilePath })}`, target: "_blank", rel: "noopener noreferrer", className: "sandbox-file-link", children: [_jsx(ExternalLink, { size: 13 }), sandboxText(locale, "打开当前文件")] })), artifact.diff ? _jsx("pre", { children: artifact.diff }) : _jsx("pre", { children: artifact.detail || sandboxText(locale, "暂无输出") }), _jsxs("footer", { children: [_jsx("span", { children: artifact.durationMs === undefined ? sandboxText(locale, "等待结果") : `${artifact.durationMs.toLocaleString(locale)} ms` }), _jsx("code", { children: artifact.turnId.slice(0, 12) })] })] }))] }, artifact.id));
1008
+ return (_jsxs("article", { className: cn(`is-${artifact.status}`, expanded && 'is-expanded'), children: [_jsxs(ListItemButton, { onClick: () => setExpandedArtifact(expanded ? null : artifact.id), "aria-expanded": expanded, children: [_jsx("span", { className: "agent-playground-artifact-icon", children: _jsx(ArtifactIcon, { size: 14 }) }), _jsxs("span", { children: [_jsx("strong", { children: artifact.title }), _jsx("small", { children: artifact.path ?? artifact.detail ?? artifact.kind })] }), _jsx("em", { children: artifact.status }), _jsx(ChevronDown, { size: 14 })] }), expanded && (_jsxs("div", { className: "agent-playground-artifact-detail", children: [artifact.path && _jsx("code", { children: artifact.path }), canExecute && artifact.projectFilePath && (_jsxs("a", { href: `/files?${new URLSearchParams({ path: artifact.projectFilePath })}`, target: "_blank", rel: "noopener noreferrer", className: "sandbox-file-link", children: [_jsx(ExternalLink, { size: 13 }), sandboxText(locale, "打开当前文件")] })), artifact.diff ? _jsx("pre", { children: artifact.diff }) : _jsx("pre", { children: artifact.detail || sandboxText(locale, "暂无输出") }), _jsxs("footer", { children: [_jsx("span", { children: artifact.durationMs === undefined ? sandboxText(locale, "等待结果") : `${artifact.durationMs.toLocaleString(locale)} ms` }), _jsx("code", { children: artifact.turnId.slice(0, 12) })] })] }))] }, artifact.id));
964
1009
  }) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(FileDiff, { size: 18 }), _jsx("span", { children: sandboxText(locale, "Agent 修改文件、执行命令或测试后,产物会集中出现在这里") })] })] }) }), _jsxs("a", { className: "agent-playground-studio-link", href: agentSessionsPath(sessionKey), children: [_jsxs("span", { children: [_jsx(ExternalLink, { size: 15 }), sandboxText(locale, "对话与轨迹")] }), _jsx("code", { children: sessionKey })] })] }), showInspector && _jsx("div", { className: "agent-playground-inspector-overlay", onClick: () => setShowInspector(false) })] }));
965
1010
  }
1011
+ /** Below the Console `lg` breakpoint (64rem) the conversation list is a drawer (see the workspace styles), so it needs a toggle. */
1012
+ const DRAWER_LAYOUT_QUERY = '(width < 64rem)';
1013
+ /** On phones the run bar keeps only the run state, Stop and 「更多」; the rest moves into the menu (D18 第 7 条). */
1014
+ const COMPACT_RUNBAR_QUERY = '(width < 48rem)';
1015
+ function useMediaQuery(media) {
1016
+ const [matches, setMatches] = useState(() => typeof window !== 'undefined' && typeof window.matchMedia === 'function'
1017
+ && window.matchMedia(media).matches);
1018
+ useEffect(() => {
1019
+ if (typeof window.matchMedia !== 'function')
1020
+ return;
1021
+ const query = window.matchMedia(media);
1022
+ const update = () => setMatches(query.matches);
1023
+ update();
1024
+ query.addEventListener('change', update);
1025
+ return () => query.removeEventListener('change', update);
1026
+ }, [media]);
1027
+ return matches;
1028
+ }
1029
+ /** ADR 0063 决策 5: a dangerous choice is an outline button with destructive text, never a solid red one. */
1030
+ function interactionVariant(primary, danger) {
1031
+ if (danger)
1032
+ return 'destructive-outline';
1033
+ return primary ? 'default' : 'outline';
1034
+ }
966
1035
  function taskStatusLabel(status, locale = 'zh-CN') {
967
1036
  if (status === 'running')
968
1037
  return sandboxText(locale, "Agent 运行中");