@zhin.js/adapter-sandbox 1.1.24 → 1.1.26

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,11 +2,11 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } 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, adapterConsoleStyles, CodeBlock, MarkdownContent, resolveMediaSrc, pickMediaRawUrl, } from '@zhin.js/client';
6
- import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL } from './sandboxTransport';
5
+ import { cn, CodeBlock, MarkdownContent, resolveMediaSrc, pickMediaRawUrl, } from '@zhin.js/client';
6
+ import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL } from './sandboxTransport.js';
7
7
  import { createWorkspaceDirectoryController } from './workspaceDirectoryState.js';
8
8
  import { User, Bot, Users, Trash2, Send, Hash, MessageSquare, Wifi, WifiOff, Smile, Image, X, Check, Info, 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, } from 'lucide-react';
9
- import RichTextEditor, {} from './RichTextEditor';
9
+ import RichTextEditor, {} from './RichTextEditor.js';
10
10
  import HtmlMessage from './HtmlMessage.js';
11
11
  import { sandboxStyles } from './styles.js';
12
12
  import ConversationRecoveryPanel from './ConversationRecoveryPanel.js';
@@ -54,6 +54,10 @@ export default function Sandbox(props = {}) {
54
54
  const [showConversationDetails, setShowConversationDetails] = useState(false);
55
55
  const [pendingRefreshEpoch, setPendingRefreshEpoch] = useState(0);
56
56
  const [showRunSettings, setShowRunSettings] = useState(false);
57
+ const [senderId, setSenderId] = useState('dev-user');
58
+ const [senderName, setSenderName] = useState('Developer');
59
+ const [senderRole, setSenderRole] = useState('master');
60
+ const [showSenderSettings, setShowSenderSettings] = useState(false);
57
61
  const [showNewSession, setShowNewSession] = useState(false);
58
62
  const [newSessionName, setNewSessionName] = useState('');
59
63
  const [newSessionScope, setNewSessionScope] = useState('private');
@@ -162,6 +166,7 @@ export default function Sandbox(props = {}) {
162
166
  messages,
163
167
  }) ? 'saved' : 'error');
164
168
  }, [activeChannel.id, channels, messages, directoryStatus.mode]);
169
+ const [inlineNotices, setInlineNotices] = useState({ emoji: false, parse: false });
165
170
  const fetchFaceList = async () => {
166
171
  try {
167
172
  const res = await fetch('https://face.viki.moe/metadata.json');
@@ -169,6 +174,7 @@ export default function Sandbox(props = {}) {
169
174
  }
170
175
  catch (err) {
171
176
  console.error('[Sandbox] Failed to fetch face list:', err);
177
+ setInlineNotices((n) => ({ ...n, emoji: true }));
172
178
  }
173
179
  };
174
180
  useEffect(() => { fetchFaceList(); }, []);
@@ -266,7 +272,7 @@ export default function Sandbox(props = {}) {
266
272
  id: data.messageId ?? createSandboxMessageId(), type: isInput ? 'sent' : 'received', channelType,
267
273
  interactionReadOnly: false,
268
274
  channelId: sceneId, channelName, senderId: isInput ? data.senderId || connectionRef.current.ownerId || 'owner' : 'endpoint',
269
- senderName: isInput ? sandboxText(locale, "当前用户") : data.bot || endpointIdRef.current, content, timestamp: data.timestamp,
275
+ senderName: isInput ? (typeof data.senderName === 'string' && data.senderName.trim() ? data.senderName.trim() : sandboxText(locale, "当前用户")) : data.bot || endpointIdRef.current, content, timestamp: data.timestamp,
270
276
  ...(Number.isSafeInteger(data.revision) && data.revision > 0 ? { revision: data.revision } : {}),
271
277
  ...(typeof data.streaming === 'boolean' ? { streaming: data.streaming } : {}),
272
278
  }));
@@ -276,8 +282,11 @@ export default function Sandbox(props = {}) {
276
282
  return false;
277
283
  const scene = activeChannelRef.current;
278
284
  const segments = [{ type: 'action', data: { id: payload, payload } }];
285
+ const resolvedSenderId = senderId.trim() || connectionRef.current.ownerId || 'dev-user';
286
+ const resolvedSenderName = senderName.trim() || sandboxText(localeRef.current, "测试用户");
279
287
  if (!submitSandboxFrame(wsRef.current, {
280
288
  type: scene.type, id: scene.id, messageId: createSandboxMessageId(), content: segments,
289
+ senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole,
281
290
  agentRun: scene.runConfig, timestamp: Date.now(),
282
291
  })) {
283
292
  setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,审批选择未发送。"));
@@ -354,6 +363,7 @@ export default function Sandbox(props = {}) {
354
363
  }
355
364
  catch (err) {
356
365
  console.error('[Sandbox] Failed to parse message:', err);
366
+ setInlineNotices((n) => ({ ...n, parse: true }));
357
367
  }
358
368
  };
359
369
  ws.onclose = () => {
@@ -479,7 +489,7 @@ export default function Sandbox(props = {}) {
479
489
  }, [sessionKey, loadTrace]);
480
490
  const parseTextToSegments = (text) => {
481
491
  const segments = [];
482
- const regex = /\[@([^\]]+)\]|\[face:(\d+)\]|\[image:([^\]]+)\]|\[video:([^\]]+)\]|\[audio:([^\]]+)\]/g;
492
+ const regex = /\[@([^\[\]]+)\]|\[face:(\d+)\]|\[image:([^\[\]]+)\]|\[video:([^\[\]]+)\]|\[audio:([^\[\]]+)\]/g;
483
493
  let lastIndex = 0;
484
494
  let match;
485
495
  while ((match = regex.exec(text)) !== null) {
@@ -519,7 +529,6 @@ export default function Sandbox(props = {}) {
519
529
  });
520
530
  };
521
531
  const renderMessageSegments = (segments, isSent, messageId, interactionResolved = false, onInteractionSubmitted, allowInteraction = true) => {
522
- const ring = isSent ? 'ring-1 ring-primary-foreground/25' : 'ring-1 ring-border/60';
523
532
  return segments.map((segment, index) => {
524
533
  if (typeof segment === 'string') {
525
534
  return _jsx(MarkdownContent, { text: segment, className: isSent ? 'zhin-markdown--inverse' : undefined }, index);
@@ -531,46 +540,101 @@ export default function Sandbox(props = {}) {
531
540
  case 'md':
532
541
  return _jsx(MarkdownContent, { text: String(d.text ?? d.content ?? ''), className: isSent ? 'zhin-markdown--inverse' : undefined }, index);
533
542
  case 'html':
534
- return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? '') }, index);
543
+ return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? d.content ?? d.text ?? '') }, index);
535
544
  case 'code':
536
545
  return _jsx(CodeBlock, { code: String(d.code ?? d.text ?? d.content ?? ''), language: String(d.language ?? d.lang ?? '') }, index);
537
546
  case 'mention':
538
547
  case 'at':
539
- return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-accent text-accent-foreground text-xs mx-0.5", children: ["@", String(d.name ?? d.target ?? d.qq ?? '')] }, index);
548
+ return _jsxs("span", { className: "sandbox-chip is-mention", children: ["@", String(d.name ?? d.target ?? d.qq ?? '')] }, index);
540
549
  case 'face':
541
- return _jsx("img", { src: `https://face.viki.moe/apng/${d.id}.png`, alt: String(d.name ?? ''), className: "w-6 h-6 inline-block align-middle mx-0.5", title: String(d.name ?? d.id ?? '') }, index);
550
+ return _jsx("img", { src: `https://face.viki.moe/apng/${d.id}.png`, alt: String(d.name ?? ''), className: "sandbox-inline-face", title: String(d.name ?? d.id ?? '') }, index);
542
551
  case 'dice':
543
- return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5", children: ["\uD83C\uDFB2 ", d.result != null ? sandboxText(locale, "点数 {0}", [String(d.result)]) : sandboxText(locale, "骰子")] }, index);
552
+ return _jsxs("span", { className: "sandbox-chip", children: ["\uD83C\uDFB2 ", d.result != null ? sandboxText(locale, "点数 {0}", [String(d.result)]) : sandboxText(locale, "骰子")] }, index);
544
553
  case 'rps':
545
- return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5", children: ["\u270A ", d.result != null ? sandboxText(locale, "结果 {0}", [String(d.result)]) : sandboxText(locale, "猜拳")] }, index);
554
+ return _jsxs("span", { className: "sandbox-chip", children: ["\u270A ", d.result != null ? sandboxText(locale, "结果 {0}", [String(d.result)]) : sandboxText(locale, "猜拳")] }, index);
546
555
  case 'image': {
547
556
  const raw = pickMediaRawUrl(d);
548
557
  const src = resolveMediaSrc(raw, 'image');
549
558
  if (!src)
550
- return _jsx("span", { className: "text-xs opacity-70", children: sandboxText(locale, "[图片]") }, index);
551
- return (_jsx("a", { href: src, target: "_blank", rel: "noreferrer", className: "block my-1", children: _jsx("img", { src: src, alt: "", className: cn('max-w-[min(320px,88vw)] rounded-lg block', ring, 'ring-offset-0'), onError: (e) => { e.target.style.display = 'none'; } }) }, index));
559
+ return _jsx("span", { className: "sandbox-segment-note", children: sandboxText(locale, "[图片]") }, index);
560
+ return (_jsx("a", { href: src, target: "_blank", rel: "noreferrer", className: "sandbox-media-link", children: _jsx("img", { src: src, alt: "", className: "sandbox-media-image", onError: (e) => { e.target.style.display = 'none'; } }) }, index));
552
561
  }
553
562
  case 'video': {
554
563
  const raw = pickMediaRawUrl(d);
555
564
  const src = resolveMediaSrc(raw, 'video');
556
565
  if (!src)
557
- return _jsx("span", { className: "text-xs opacity-70", children: sandboxText(locale, "[视频无地址]") }, index);
558
- return (_jsx("video", { src: src, controls: true, playsInline: true, preload: "metadata", className: cn('max-w-[min(360px,92vw)] max-h-72 rounded-lg my-1 bg-black/10', ring) }, index));
566
+ return _jsx("span", { className: "sandbox-segment-note", children: sandboxText(locale, "[视频无地址]") }, index);
567
+ return (_jsx("video", { src: src, controls: true, playsInline: true, preload: "metadata", className: "sandbox-media-video" }, index));
559
568
  }
560
569
  case 'audio':
561
570
  case 'record': {
562
571
  const raw = pickMediaRawUrl(d);
563
572
  const src = resolveMediaSrc(raw, 'audio');
564
573
  if (!src)
565
- return _jsx("span", { className: "text-xs opacity-70", children: sandboxText(locale, "[音频无地址]") }, index);
566
- return (_jsx("audio", { src: src, controls: true, preload: "metadata", className: cn('w-full max-w-sm my-2 h-10', isSent && 'opacity-95') }, index));
574
+ return _jsx("span", { className: "sandbox-segment-note", children: sandboxText(locale, "[音频无地址]") }, index);
575
+ return (_jsx("audio", { src: src, controls: true, preload: "metadata", className: "sandbox-media-audio" }, index));
567
576
  }
568
577
  case 'reply':
569
- return (_jsxs("div", { className: "mb-1 rounded-md border border-dashed px-2 py-1 text-xs opacity-90", children: [sandboxText(locale, "↩ 引用消息 #"), String(d.message_id ?? d.id ?? '')] }, index));
578
+ return (_jsxs("div", { className: "sandbox-reply-quote", children: [sandboxText(locale, "↩ 引用消息 #"), String(d.message_id ?? d.id ?? '')] }, index));
570
579
  case 'forward': {
571
580
  const messages = d.messages;
572
581
  const title = String(d.title ?? sandboxText(locale, "聊天记录"));
573
- return (_jsxs("div", { className: "my-1 rounded-md border bg-background/40 px-2 py-2 text-xs space-y-1", children: [_jsxs("div", { className: "font-medium", children: ["\uD83D\uDCE8 ", title] }), Array.isArray(messages) && messages.length > 0 ? (_jsxs("div", { className: "space-y-1 pl-2 border-l-2 border-muted", children: [messages.slice(0, 3).map((batch, bi) => (_jsx("div", { className: "opacity-90", children: batch.map((s, si) => (_jsx("span", { children: s.type === 'text' ? String(s.data?.text ?? '') : `[${s.type ?? 'seg'}]` }, si))) }, bi))), messages.length > 3 && _jsxs("div", { className: "opacity-60", children: [sandboxText(locale, "…共"), messages.length, " ", sandboxText(locale, "条")] })] })) : (_jsx("div", { className: "opacity-70", children: sandboxText(locale, "[合并转发]") }))] }, index));
582
+ return (_jsxs("div", { className: "sandbox-forward", children: [_jsxs("div", { className: "sandbox-forward-title", children: ["\uD83D\uDCE8 ", title] }), Array.isArray(messages) && messages.length > 0 ? (_jsxs("div", { className: "sandbox-forward-list", children: [messages.slice(0, 3).map((batch, bi) => (_jsx("div", { children: batch.map((s, si) => (_jsx("span", { children: s.type === 'text' ? String(s.data?.text ?? '') : `[${s.type ?? 'seg'}]` }, si))) }, bi))), messages.length > 3 && _jsxs("div", { className: "sandbox-forward-more", children: [sandboxText(locale, "…共"), messages.length, " ", sandboxText(locale, "条")] })] })) : (_jsx("div", { className: "sandbox-forward-empty", children: sandboxText(locale, "[合并转发]") }))] }, index));
583
+ }
584
+ case 'card': {
585
+ const title = typeof d.title === 'string' ? d.title : '';
586
+ const subtitle = typeof d.subtitle === 'string' ? d.subtitle : '';
587
+ const description = typeof d.description === 'string'
588
+ ? d.description
589
+ : typeof d.content === 'string'
590
+ ? d.content
591
+ : typeof d.summary === 'string'
592
+ ? d.summary
593
+ : '';
594
+ const rawImage = typeof d.image === 'string'
595
+ ? d.image
596
+ : typeof d.thumbnail === 'string'
597
+ ? d.thumbnail
598
+ : typeof d.imageUrl === 'string'
599
+ ? d.imageUrl
600
+ : pickMediaRawUrl(d);
601
+ const imageSrc = rawImage ? resolveMediaSrc(rawImage, 'image') : undefined;
602
+ const fields = Array.isArray(d.fields)
603
+ ? d.fields
604
+ : [];
605
+ const buttons = Array.isArray(d.buttons)
606
+ ? d.buttons
607
+ : Array.isArray(d.actions)
608
+ ? d.actions
609
+ : [];
610
+ const resolved = Boolean(messageId && interactionResolved);
611
+ 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) => {
612
+ const label = String(btn.label ?? btn.text ?? btn.title ?? btn.id ?? `Action ${bi + 1}`);
613
+ const payload = String(btn.payload ?? btn.value ?? btn.url ?? btn.id ?? label);
614
+ return (_jsx("button", { type: "button", disabled: Boolean(btn.disabled) || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(payload, messageId))
615
+ onInteractionSubmitted?.(); }, className: cn(btn.style === 'primary' && 'is-primary', btn.style === 'danger' && 'is-danger'), children: label }, `${payload}-${bi}`));
616
+ }) }) })), !title && !subtitle && !description && fields.length === 0 && buttons.length === 0 && (_jsx(CodeBlock, { code: JSON.stringify(d, null, 2), language: "json" }))] })] }, index));
617
+ }
618
+ case 'share': {
619
+ const url = typeof d.url === 'string' ? d.url : '';
620
+ const title = String(d.title ?? (url || 'Share'));
621
+ const description = typeof d.description === 'string'
622
+ ? d.description
623
+ : typeof d.content === 'string'
624
+ ? d.content
625
+ : typeof d.artist === 'string'
626
+ ? d.artist
627
+ : '';
628
+ const rawImage = typeof d.image === 'string' ? d.image : pickMediaRawUrl(d);
629
+ const imageSrc = rawImage ? resolveMediaSrc(rawImage, 'image') : undefined;
630
+ return (_jsxs("div", { className: "sandbox-share-card", children: [imageSrc && (_jsx("img", { src: imageSrc, alt: title, className: "sandbox-share-card-thumb", onError: (e) => { e.target.style.display = 'none'; } })), _jsxs("div", { className: "sandbox-share-card-main", children: [_jsx("div", { className: "sandbox-share-card-title", children: _jsxs("span", { children: [title, " ", _jsx(ExternalLink, { size: 12 })] }) }), description && _jsx("div", { className: "sandbox-share-card-desc", children: description }), url && _jsx("div", { className: "sandbox-share-card-url", children: url })] })] }, index));
631
+ }
632
+ case 'button': {
633
+ const label = String(d.label ?? d.text ?? d.id ?? 'Button');
634
+ const payload = String(d.payload ?? d.id ?? label);
635
+ const resolved = Boolean(messageId && interactionResolved);
636
+ 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))
637
+ onInteractionSubmitted?.(); }, className: cn(d.style === 'primary' && 'is-primary', d.style === 'danger' && 'is-danger'), children: label }) }) }, index));
574
638
  }
575
639
  case 'keyboard': {
576
640
  const rows = d.rows ?? [];
@@ -579,7 +643,7 @@ export default function Sandbox(props = {}) {
579
643
  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));
580
644
  }
581
645
  default:
582
- return _jsxs("span", { className: "text-xs opacity-70", children: ["[", segment.type, "]"] }, index);
646
+ return _jsxs("span", { className: "sandbox-segment-note", children: ["[", segment.type, "]"] }, index);
583
647
  }
584
648
  });
585
649
  };
@@ -587,13 +651,16 @@ export default function Sandbox(props = {}) {
587
651
  if (!connectionRef.current.canExecute || directoryModeRef.current === 'loading' || !hasRenderableSegments(segments))
588
652
  return;
589
653
  const scene = activeChannelRef.current;
654
+ const resolvedSenderId = senderId.trim() || connectionRef.current.ownerId || 'dev-user';
655
+ const resolvedSenderName = senderName.trim() || sandboxText(localeRef.current, "测试用户");
590
656
  const newMessage = {
591
657
  id: createSandboxMessageId(), type: 'sent', channelType: scene.type, channelId: scene.id,
592
- channelName: scene.name, senderId: connectionRef.current.ownerId || 'test_user',
593
- senderName: sandboxText(localeRef.current, "测试用户"), content: segments, timestamp: Date.now(),
658
+ channelName: scene.name, senderId: resolvedSenderId,
659
+ senderName: resolvedSenderName, content: segments, timestamp: Date.now(),
594
660
  };
595
661
  if (!submitSandboxFrame(wsRef.current, {
596
662
  type: scene.type, id: scene.id, messageId: newMessage.id, content: segments,
663
+ senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole,
597
664
  agentRun: scene.runConfig, timestamp: newMessage.timestamp,
598
665
  })) {
599
666
  setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,消息未发送。"));
@@ -755,13 +822,46 @@ export default function Sandbox(props = {}) {
755
822
  };
756
823
  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;
757
824
  const recoveryConnectionId = connectionRef.current.connectionId;
758
- return (_jsxs("section", { className: cn("zhin-console-surface zhin-sandbox agent-playground-shell", showInspector && "has-inspector"), children: [_jsxs("style", { children: [adapterConsoleStyles, sandboxStyles] }), _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", { className: "flex justify-between items-center", children: [_jsxs("div", { className: "flex items-center gap-2", 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) => {
825
+ return (_jsxs("section", { className: cn("zhin-sandbox agent-playground-shell", showInspector && "has-inspector"), children: [_jsx("style", { children: `${sandboxStyles}
826
+ .sandbox-sender-trigger { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 6px; }
827
+ .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; }
828
+ .sandbox-role-badge.is-master { background: rgba(245,158,11,0.18); color: #d97706; }
829
+ .sandbox-role-badge.is-admin { background: rgba(59,130,246,0.18); color: #2563eb; }
830
+ .sandbox-role-badge.is-member { background: rgba(16,185,129,0.16); color: #059669; }
831
+ .sandbox-role-switcher { display: inline-flex; gap: 4px; }
832
+ .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; }
833
+ .sandbox-role-option.active { font-weight: 600; border-color: currentColor; background: rgba(59,130,246,0.12); }
834
+ .sandbox-sender-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
835
+ .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; }
836
+ .sandbox-quick-commands { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: 6px; }
837
+ .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; }
838
+ .sandbox-command-chip:hover:not(:disabled) { border-color: rgba(59,130,246,0.5); background: rgba(59,130,246,0.08); }
839
+ .sandbox-command-chip:disabled { opacity: 0.45; cursor: not-allowed; }
840
+ .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); }
841
+ .sandbox-rich-card-image { width: 100%; max-height: 200px; object-fit: cover; display: block; }
842
+ .sandbox-rich-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
843
+ .sandbox-rich-card-title { font-weight: 600; font-size: 14px; }
844
+ .sandbox-rich-card-subtitle { font-size: 12px; opacity: 0.75; }
845
+ .sandbox-rich-card-desc { font-size: 13px; }
846
+ .sandbox-rich-card-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin: 4px 0 0; }
847
+ .sandbox-rich-card-field { background: rgba(148,163,184,0.08); padding: 4px 8px; border-radius: 6px; }
848
+ .sandbox-rich-card-field dt { font-size: 11px; opacity: 0.7; }
849
+ .sandbox-rich-card-field dd { margin: 0; font-size: 12px; font-weight: 500; }
850
+ .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; }
851
+ .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); }
852
+ .sandbox-share-card-thumb { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
853
+ .sandbox-share-card-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
854
+ .sandbox-share-card-title { font-weight: 600; font-size: 13px; }
855
+ .sandbox-share-card-title a { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: underline; }
856
+ .sandbox-share-card-desc { font-size: 12px; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }
857
+ .sandbox-share-card-url { font-size: 11px; opacity: 0.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
858
+ ` }), _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) => {
759
859
  const isActive = activeChannel.id === channel.id && activeChannel.type === channel.type;
760
- 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: "flex-1 min-w-0", children: [_jsx("div", { className: "text-sm font-medium truncate", children: channel.name }), _jsx("div", { className: "text-xs text-muted-foreground", children: channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域") })] }), channel.unread > 0 && _jsx("span", { className: "inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1", children: channel.unread })] }, `${channel.type}:${channel.id}`));
860
+ 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}`));
761
861
  }) }), _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')
762
862
  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
763
863
  ? _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, "对话与轨迹")] })
764
- : _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsx("button", { type: "button", className: cn(showRunSettings && 'active'), "aria-expanded": showRunSettings, onClick: () => setShowRunSettings((visible) => !visible), "aria-label": sandboxText(locale, "配置运行环境"), children: _jsx(SlidersHorizontal, { size: 16 }) }), _jsx("button", { type: "button", "aria-expanded": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => setShowInspector(!showInspector), "aria-label": sandboxText(locale, "切换运行检查器"), children: _jsx(PanelRight, { size: 16 }) }), _jsx("button", { type: "button", onClick: () => setConfirmClear(true), "aria-label": sandboxText(locale, "清空当前会话"), children: _jsx(Trash2, { size: 15 }) })] })] }), 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, "确认清空") })] })), 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) => {
864
+ : _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsxs("button", { type: "button", className: cn("sandbox-sender-trigger", showSenderSettings && "active"), "aria-expanded": showSenderSettings, onClick: () => setShowSenderSettings((visible) => !visible), title: locale === 'en' ? 'Simulated sender identity & role' : '模拟发送者身份与角色', children: [_jsx(User, { size: 14 }), _jsx("span", { children: senderName.trim() || senderId.trim() || 'dev-user' }), _jsx("em", { className: cn("sandbox-role-badge", `is-${senderRole}`), children: senderRole })] }), _jsx("button", { type: "button", className: cn(showRunSettings && 'active'), "aria-expanded": showRunSettings, onClick: () => setShowRunSettings((visible) => !visible), "aria-label": sandboxText(locale, "配置运行环境"), children: _jsx(SlidersHorizontal, { size: 16 }) }), _jsx("button", { type: "button", "aria-expanded": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => setShowInspector(!showInspector), "aria-label": sandboxText(locale, "切换运行检查器"), children: _jsx(PanelRight, { size: 16 }) }), _jsx("button", { type: "button", onClick: () => setConfirmClear(true), "aria-label": sandboxText(locale, "清空当前会话"), children: _jsx(Trash2, { size: 15 }) })] })] }), showSenderSettings && (_jsxs("section", { className: "agent-playground-run-settings sandbox-sender-settings", "aria-label": locale === 'en' ? 'Simulated sender' : '模拟发送者配置', children: [_jsxs("label", { children: [_jsxs("span", { children: [_jsx(User, { size: 14 }), locale === 'en' ? 'Sender ID' : '发送者 ID'] }), _jsx("input", { value: senderId, 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, onChange: (event) => setSenderName(event.target.value), placeholder: "Developer", spellCheck: false })] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), locale === 'en' ? 'Sender Role' : '角色权限'] }), _jsx("div", { className: "sandbox-role-switcher", role: "group", "aria-label": locale === 'en' ? 'Sender role' : '角色权限', 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: role }, role))) })] }), _jsxs("div", { className: "sandbox-sender-presets", children: [_jsx("button", { type: "button", onClick: () => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master'); }, children: "Master (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) => {
765
865
  const safetyMode = event.target.value;
766
866
  updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) });
767
867
  }, 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) => {
@@ -778,19 +878,19 @@ export default function Sandbox(props = {}) {
778
878
  return _jsx("p", { className: "agent-playground-history-notice", children: sandboxText(locale, '消息已撤回') }, msg.id);
779
879
  const isApproval = msg.type === 'received' && msg.interactionReadOnly !== true && msg.content.some((segment) => segment.type === 'keyboard');
780
880
  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])));
781
- }), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] }))] }) }), _jsxs("section", { className: "agent-playground-composer", hidden: showConversationDetails, "aria-label": sandboxText(locale, "任务输入"), children: [_jsxs("div", { className: "flex gap-2 items-center flex-wrap", children: [_jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", showFacePicker ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setShowFacePicker(!showFacePicker); setMediaPanel(null); }, title: sandboxText(locale, "插入表情"), children: _jsx(Smile, { size: 16 }) }), _jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", mediaPanel === 'image' ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false); }, title: sandboxText(locale, "插入图片 URL"), children: _jsx(Image, { size: 16 }) }), _jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", mediaPanel === 'video' ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false); }, title: sandboxText(locale, "插入视频 URL"), children: _jsx(Video, { size: 16 }) }), _jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", mediaPanel === 'audio' ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false); }, title: sandboxText(locale, "插入音频 URL"), children: _jsx(Music, { size: 16 }) }), _jsx("div", { className: "flex-1 min-w-[1rem]" }), _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", { className: "h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors", onClick: () => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write'); }, "aria-label": sandboxText(locale, "清空输入"), children: _jsx(X, { size: 16 }) }))] }), showFacePicker && (_jsxs("div", { className: "p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2", children: [_jsx("input", { value: faceSearchQuery, onChange: (e) => setFaceSearchQuery(e.target.value), placeholder: sandboxText(locale, "搜索表情..."), className: "w-full h-8 rounded-md border bg-transparent px-2 text-sm" }), _jsx("div", { className: "grid grid-cols-8 gap-1", children: filteredFaces.slice(0, 80).map((face) => (_jsx("button", { onClick: () => insertFace(face.id), title: face.name, className: "w-10 h-10 rounded-md border flex items-center justify-center hover:bg-accent transition-colors", children: _jsx("img", { src: `https://face.viki.moe/apng/${face.id}.png`, alt: face.name, className: "w-8 h-8" }) }, face.id))) }), filteredFaces.length === 0 && (_jsxs("div", { className: "flex flex-col items-center gap-2 py-4", children: [_jsx(Search, { size: 32, className: "text-muted-foreground/30" }), _jsx("span", { className: "text-sm text-muted-foreground", children: sandboxText(locale, "未找到匹配的表情") })] }))] })), mediaPanel && (_jsxs("div", { className: "p-3 rounded-md border bg-muted/30 space-y-2", children: [_jsxs("p", { className: "text-xs text-muted-foreground", 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: "w-full h-8 rounded-md border border-input bg-background px-2 text-sm", onKeyDown: (e) => { if (e.key === 'Enter') {
881
+ }), !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 }) }), _jsxs("div", { className: "sandbox-quick-commands", role: "toolbar", "aria-label": locale === 'en' ? 'Quick commands' : '快捷命令', children: [['/help', 'help', 'ping', '/status'].map((cmd) => (_jsxs("button", { type: "button", className: "sandbox-command-chip", disabled: !canExecute || directoryStatus.mode === 'loading', onClick: () => runPrompt(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') {
782
882
  e.preventDefault();
783
883
  commitMediaUrl();
784
- } } }), _jsxs("button", { type: "button", className: "inline-flex items-center gap-1 h-8 px-3 rounded-md bg-primary text-primary-foreground text-sm disabled:opacity-50", onClick: commitMediaUrl, disabled: !mediaUrl.trim(), children: [_jsx(Check, { size: 14 }), " ", sandboxText(locale, "插入到输入框")] })] })), _jsxs("div", { className: "flex gap-2 items-start", children: [_jsxs("div", { className: "flex-1 relative", children: [_jsx("div", { className: composerMode === 'write' ? 'block' : 'hidden', 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()
884
+ } } }), _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()
785
885
  ? _jsx(MarkdownContent, { text: inputText })
786
- : _jsx("span", { className: "sandbox-markdown-preview-empty", children: sandboxText(locale, "输入 Markdown 后可在这里检查最终效果") }) })), atPopoverPosition && (_jsx("div", { className: "absolute z-50 rounded-lg border bg-popover shadow-md min-w-60 max-h-72 overflow-y-auto p-1", style: { top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }, children: filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (_jsxs("div", { className: "flex items-center gap-2 p-2 rounded-md cursor-pointer hover:bg-accent transition-colors", onClick: () => selectAtUser(user), children: [_jsx(User, { size: 16, className: "text-muted-foreground" }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "text-sm font-medium", children: user.name }), _jsxs("div", { className: "text-xs text-muted-foreground", children: ["ID: ", user.id] })] })] }, user.id))) : (_jsxs("div", { className: "flex flex-col items-center gap-2 p-4", children: [_jsx(Search, { size: 20, className: "text-muted-foreground/50" }), _jsx("span", { className: "text-xs text-muted-foreground", children: sandboxText(locale, "未找到匹配的用户") })] })) }))] }), _jsxs("button", { className: "inline-flex items-center gap-1.5 h-10 px-4 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 transition-colors hover:bg-primary/90", onClick: () => { const c = editorRef.current?.getContent(); if (c)
787
- handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("div", { className: "flex items-center gap-2 flex-wrap text-xs text-muted-foreground", children: [_jsx(Info, { size: 12 }), " ", sandboxText(locale, "快捷操作:"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "Enter" }), " ", sandboxText(locale, "发送"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "Shift+Enter" }), " ", sandboxText(locale, "换行"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "```ts" }), " ", sandboxText(locale, "代码块"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "[video:URL]" }), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "[audio:URL]" })] })] })] }), _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 && 'animate-spin') }) }), _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: cn("agent-playground-inspector-view", inspectorView !== 'runs' && 'hidden'), 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) => {
886
+ : _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)
887
+ handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("div", { className: "sandbox-hints", children: [_jsx(Info, { size: 12 }), " ", sandboxText(locale, "快捷操作:"), _jsx("span", { className: "sandbox-hint-key", children: "Enter" }), " ", sandboxText(locale, "发送"), _jsx("span", { className: "sandbox-hint-key", children: "Shift+Enter" }), " ", sandboxText(locale, "换行"), _jsx("span", { className: "sandbox-hint-key", children: "```ts" }), " ", sandboxText(locale, "代码块"), _jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗"), _jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人"), _jsx("span", { className: "sandbox-hint-key", children: "[video:URL]" }), _jsx("span", { className: "sandbox-hint-key", children: "[audio:URL]" })] })] })] }), _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) => {
788
888
  const item = presentTraceEvent(event, locale);
789
889
  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));
790
- }) })) : (_jsxs("div", { className: "agent-playground-trace-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "发送任务后显示推理与工具轨迹") })] }))] })] }), _jsx("div", { className: cn("agent-playground-inspector-view", inspectorView !== 'artifacts' && 'hidden'), 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) => {
890
+ }) })) : (_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) => {
791
891
  const ArtifactIcon = artifact.kind === 'file-change' ? FileDiff : artifact.kind === 'test' ? FlaskConical : Terminal;
792
892
  const expanded = expandedArtifact === artifact.id;
793
- 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: "inline-flex items-center gap-1 text-primary hover:underline", 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));
893
+ 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));
794
894
  }) })) : _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) })] }));
795
895
  }
796
896
  function taskStatusLabel(status, locale = 'zh-CN') {