@zhin.js/adapter-sandbox 1.1.32 → 1.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/README.md +1 -0
- package/lib/endpoint.js +4 -1
- package/lib/protocol.d.ts +13 -2
- package/lib/protocol.js +69 -8
- package/package.json +42 -35
- package/pages/index/RichTextEditor.js +50 -0
- package/pages/index/RichTextEditor.tsx +49 -0
- package/pages/index/SandboxChat.js +53 -16
- package/pages/index/SandboxChat.tsx +113 -34
- package/pages/index/composerCommands.js +41 -0
- package/pages/index/composerCommands.ts +56 -0
- package/pages/index/messages.js +10 -1
- package/pages/index/messages.ts +10 -1
- package/pages/index/segmentFallback.js +83 -0
- package/pages/index/segmentFallback.ts +78 -0
- package/pages/index/styles.js +18 -4
- package/pages/index/styles.ts +18 -4
- package/plugin.js +0 -3
- package/src/endpoint.ts +4 -1
- package/src/protocol.ts +78 -8
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
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
5
|
import { cn, 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
|
-
import {
|
|
8
|
+
import { isApprovalPrompt, readSandboxCommandHints } from './composerCommands.js';
|
|
9
|
+
import { isJsxNode, segmentFallbackText, segmentPreviewText } from './segmentFallback.js';
|
|
10
|
+
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';
|
|
9
11
|
import RichTextEditor, {} from './RichTextEditor.js';
|
|
10
12
|
import HtmlMessage from './HtmlMessage.js';
|
|
11
13
|
import { sandboxStyles } from './styles.js';
|
|
@@ -45,7 +47,7 @@ export default function Sandbox(props = {}) {
|
|
|
45
47
|
const [faceSearchQuery, setFaceSearchQuery] = useState('');
|
|
46
48
|
const atSuggestions = [
|
|
47
49
|
{ id: 'actor-owner', name: sandboxText(locale, "当前用户") }, { id: 'actor-reviewer', name: sandboxText(locale, "审阅者") },
|
|
48
|
-
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id:
|
|
50
|
+
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id: endpointId, name: endpointId }
|
|
49
51
|
];
|
|
50
52
|
const [previewSegments, setPreviewSegments] = useState([]);
|
|
51
53
|
const [composerMode, setComposerMode] = useState('write');
|
|
@@ -58,6 +60,11 @@ export default function Sandbox(props = {}) {
|
|
|
58
60
|
const [senderName, setSenderName] = useState('Developer');
|
|
59
61
|
const [senderRole, setSenderRole] = useState('master');
|
|
60
62
|
const [showSenderSettings, setShowSenderSettings] = useState(false);
|
|
63
|
+
/** Runbar overflow: identity, run settings, inspector and clear live here (#1250). */
|
|
64
|
+
const [showMoreActions, setShowMoreActions] = useState(false);
|
|
65
|
+
/** Live binding of the current socket; drives the Host-provided quick commands. */
|
|
66
|
+
const [readyConnectionId, setReadyConnectionId] = useState(undefined);
|
|
67
|
+
const [commandHints, setCommandHints] = useState(null);
|
|
61
68
|
const [showNewSession, setShowNewSession] = useState(false);
|
|
62
69
|
const [newSessionName, setNewSessionName] = useState('');
|
|
63
70
|
const [newSessionScope, setNewSessionScope] = useState('private');
|
|
@@ -178,6 +185,19 @@ export default function Sandbox(props = {}) {
|
|
|
178
185
|
}
|
|
179
186
|
};
|
|
180
187
|
useEffect(() => { fetchFaceList(); }, []);
|
|
188
|
+
// Quick commands come from the Host's command index and the endpoint's commandPrefix;
|
|
189
|
+
// without an answer the composer offers none rather than guessing.
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
setCommandHints(null);
|
|
192
|
+
if (!readyConnectionId || !canExecute)
|
|
193
|
+
return;
|
|
194
|
+
const controller = new AbortController();
|
|
195
|
+
void readSandboxCommandHints(readyConnectionId, { type: activeChannel.type, id: activeChannel.id }, locale, controller.signal, socketRequestContextRef.current ?? undefined).then((hints) => {
|
|
196
|
+
if (!controller.signal.aborted)
|
|
197
|
+
setCommandHints(hints);
|
|
198
|
+
});
|
|
199
|
+
return () => controller.abort();
|
|
200
|
+
}, [readyConnectionId, canExecute, activeChannel.type, activeChannel.id, locale]);
|
|
181
201
|
const subscribeToScene = (scene) => {
|
|
182
202
|
// Old Hosts parse unknown JSON as chat, so control frames require this explicit handshake.
|
|
183
203
|
if (connectionRef.current.protocol !== SANDBOX_SCOPED_PROTOCOL || !connectionRef.current.canExecute)
|
|
@@ -205,6 +225,7 @@ export default function Sandbox(props = {}) {
|
|
|
205
225
|
endpointIdRef.current = data.endpoint || data.bot || 'sandbox-bot';
|
|
206
226
|
setBotName(endpointIdRef.current);
|
|
207
227
|
connectionRef.current = { protocol: data.protocol, connectionId: data.connectionId, ownerId: data.id, canExecute: data.canExecute !== false };
|
|
228
|
+
setReadyConnectionId(data.connectionId);
|
|
208
229
|
setCanExecute(data.canExecute !== false);
|
|
209
230
|
setTransportNotice(data.canExecute === false ? sandboxText(locale, "当前 Token 只有演示权限,任务运行已禁用。") : null);
|
|
210
231
|
if (data.shellIsolation) {
|
|
@@ -533,12 +554,19 @@ export default function Sandbox(props = {}) {
|
|
|
533
554
|
if (typeof segment === 'string') {
|
|
534
555
|
return _jsx(MarkdownContent, { text: segment, className: isSent ? 'zhin-markdown--inverse' : undefined }, index);
|
|
535
556
|
}
|
|
557
|
+
// Unrendered JSX (or a segment without data) is read as text with `[button]` labels, never as raw JSON.
|
|
558
|
+
if (isJsxNode(segment) || !segment.data || typeof segment.data !== 'object') {
|
|
559
|
+
const fallback = segmentFallbackText(segment);
|
|
560
|
+
return fallback
|
|
561
|
+
? _jsx(MarkdownContent, { text: fallback, className: isSent ? 'zhin-markdown--inverse' : undefined }, index)
|
|
562
|
+
: _jsxs("span", { className: "sandbox-segment-note", children: ["[", String(segment.type), "]"] }, index);
|
|
563
|
+
}
|
|
536
564
|
const d = segment.data;
|
|
537
565
|
switch (segment.type) {
|
|
538
566
|
case 'text':
|
|
539
567
|
case 'markdown':
|
|
540
568
|
case 'md':
|
|
541
|
-
return _jsx(MarkdownContent, { text:
|
|
569
|
+
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);
|
|
542
570
|
case 'html':
|
|
543
571
|
return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? d.content ?? d.text ?? '') }, index);
|
|
544
572
|
case 'code':
|
|
@@ -642,8 +670,12 @@ export default function Sandbox(props = {}) {
|
|
|
642
670
|
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))
|
|
643
671
|
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));
|
|
644
672
|
}
|
|
645
|
-
default:
|
|
646
|
-
|
|
673
|
+
default: {
|
|
674
|
+
const fallback = segmentFallbackText(segment);
|
|
675
|
+
return fallback
|
|
676
|
+
? _jsx(MarkdownContent, { text: fallback, className: isSent ? 'zhin-markdown--inverse' : undefined }, index)
|
|
677
|
+
: _jsxs("span", { className: "sandbox-segment-note", children: ["[", segment.type, "]"] }, index);
|
|
678
|
+
}
|
|
647
679
|
}
|
|
648
680
|
});
|
|
649
681
|
};
|
|
@@ -861,7 +893,7 @@ export default function Sandbox(props = {}) {
|
|
|
861
893
|
}) }), _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')
|
|
862
894
|
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
|
|
863
895
|
? _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, "对话与轨迹")] })
|
|
864
|
-
: _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsxs("button", { type: "button", className: cn("sandbox-
|
|
896
|
+
: _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}`), children: [senderName.trim() || senderId.trim() || 'dev-user', " \u00B7 ", senderRole] })] }), _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("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) => {
|
|
865
897
|
const safetyMode = event.target.value;
|
|
866
898
|
updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) });
|
|
867
899
|
}, 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) => {
|
|
@@ -873,18 +905,26 @@ export default function Sandbox(props = {}) {
|
|
|
873
905
|
return previous;
|
|
874
906
|
return retirePlaygroundInteractions(previous, activeChannel, segments);
|
|
875
907
|
});
|
|
876
|
-
}, 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 ? (_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) => {
|
|
908
|
+
}, 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) => {
|
|
877
909
|
if (msg.recalledMessageId)
|
|
878
910
|
return _jsx("p", { className: "agent-playground-history-notice", children: sandboxText(locale, '消息已撤回') }, msg.id);
|
|
879
|
-
const isApproval = msg
|
|
911
|
+
const isApproval = isApprovalPrompt(msg);
|
|
880
912
|
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])));
|
|
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 }) }),
|
|
913
|
+
}), !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',
|
|
914
|
+
// Keyboard-reachable (WCAG 2.1.1). A mouse click must not keep focus on the chip,
|
|
915
|
+
// and the prefill moves focus into the composer, so Enter sends the draft
|
|
916
|
+
// rather than re-activating the chip after a late layout shift (#1250).
|
|
917
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
918
|
+
// Pre-fill the composer (never overwriting a draft); sending stays an explicit Enter / Send.
|
|
919
|
+
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') {
|
|
882
920
|
e.preventDefault();
|
|
883
921
|
commitMediaUrl();
|
|
884
922
|
} } }), _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()
|
|
885
923
|
? _jsx(MarkdownContent, { text: inputText })
|
|
886
924
|
: _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("
|
|
925
|
+
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
|
|
926
|
+
? sandboxText(locale, "命令以 {0} 开头", [commandHints.prefix])
|
|
927
|
+
: 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) => {
|
|
888
928
|
const item = presentTraceEvent(event, locale);
|
|
889
929
|
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));
|
|
890
930
|
}) })) : (_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) => {
|
|
@@ -904,13 +944,10 @@ function taskStatusLabel(status, locale = 'zh-CN') {
|
|
|
904
944
|
}
|
|
905
945
|
function messageText(segments) {
|
|
906
946
|
return segments.map((segment) => {
|
|
907
|
-
const data = segment.data;
|
|
908
|
-
if (segment.type === 'text' || segment.type === 'markdown' || segment.type === 'md') {
|
|
909
|
-
return String(data.text ?? data.content ?? '');
|
|
910
|
-
}
|
|
947
|
+
const data = (segment.data ?? {});
|
|
911
948
|
if (segment.type === 'mention' || segment.type === 'at')
|
|
912
949
|
return `@${String(data.name ?? data.target ?? '')}`;
|
|
913
|
-
return
|
|
950
|
+
return segmentPreviewText(segment);
|
|
914
951
|
}).join(' ').trim();
|
|
915
952
|
}
|
|
916
953
|
function formatDuration(durationMs, locale = 'zh-CN') {
|
|
@@ -11,14 +11,16 @@ import {
|
|
|
11
11
|
import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL, type SandboxRequestContext } from './sandboxTransport.js';
|
|
12
12
|
import { createWorkspaceDirectoryController, type DirectoryStatus } from './workspaceDirectoryState.js';
|
|
13
13
|
import type { SandboxWorkspaceScope } from './workspaceDirectory.js';
|
|
14
|
+
import { isApprovalPrompt, readSandboxCommandHints, type SandboxCommandHints } from './composerCommands.js';
|
|
15
|
+
import { isJsxNode, segmentFallbackText, segmentPreviewText } from './segmentFallback.js';
|
|
14
16
|
import {
|
|
15
17
|
User, Bot, Users, Trash2, Send, Hash, MessageSquare,
|
|
16
|
-
Wifi, WifiOff, Smile, Image, X, Check,
|
|
18
|
+
Wifi, WifiOff, Smile, Image, X, Check, Search,
|
|
17
19
|
Video, Music, Plus, PanelRight, ExternalLink, RefreshCw,
|
|
18
20
|
Sparkles, Activity, Wrench, Coins, CircleAlert, Gauge,
|
|
19
21
|
SlidersHorizontal, FolderOpen, ShieldCheck, Network,
|
|
20
22
|
Square, RotateCcw, FileDiff, Terminal, FlaskConical, ChevronDown,
|
|
21
|
-
FileDown, ListChecks,
|
|
23
|
+
FileDown, ListChecks, MoreHorizontal, Keyboard, AtSign,
|
|
22
24
|
} from 'lucide-react';
|
|
23
25
|
import RichTextEditor, { type RichTextEditorRef } from './RichTextEditor.js';
|
|
24
26
|
import HtmlMessage from './HtmlMessage.js';
|
|
@@ -97,7 +99,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
97
99
|
const [faceSearchQuery, setFaceSearchQuery] = useState('')
|
|
98
100
|
const atSuggestions = [
|
|
99
101
|
{ id: 'actor-owner', name: sandboxText(locale, "当前用户") }, { id: 'actor-reviewer', name: sandboxText(locale, "审阅者") },
|
|
100
|
-
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id:
|
|
102
|
+
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id: endpointId, name: endpointId }
|
|
101
103
|
]
|
|
102
104
|
const [previewSegments, setPreviewSegments] = useState<MessageSegment[]>([])
|
|
103
105
|
const [composerMode, setComposerMode] = useState<'write' | 'preview'>('write')
|
|
@@ -110,6 +112,11 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
110
112
|
const [senderName, setSenderName] = useState('Developer')
|
|
111
113
|
const [senderRole, setSenderRole] = useState<'master' | 'admin' | 'member'>('master')
|
|
112
114
|
const [showSenderSettings, setShowSenderSettings] = useState(false)
|
|
115
|
+
/** Runbar overflow: identity, run settings, inspector and clear live here (#1250). */
|
|
116
|
+
const [showMoreActions, setShowMoreActions] = useState(false)
|
|
117
|
+
/** Live binding of the current socket; drives the Host-provided quick commands. */
|
|
118
|
+
const [readyConnectionId, setReadyConnectionId] = useState<string | undefined>(undefined)
|
|
119
|
+
const [commandHints, setCommandHints] = useState<SandboxCommandHints | null>(null)
|
|
113
120
|
const [showNewSession, setShowNewSession] = useState(false)
|
|
114
121
|
const [newSessionName, setNewSessionName] = useState('')
|
|
115
122
|
const [newSessionScope, setNewSessionScope] = useState<SandboxScope>('private')
|
|
@@ -232,6 +239,19 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
232
239
|
|
|
233
240
|
useEffect(() => { fetchFaceList() }, [])
|
|
234
241
|
|
|
242
|
+
// Quick commands come from the Host's command index and the endpoint's commandPrefix;
|
|
243
|
+
// without an answer the composer offers none rather than guessing.
|
|
244
|
+
useEffect(() => {
|
|
245
|
+
setCommandHints(null)
|
|
246
|
+
if (!readyConnectionId || !canExecute) return
|
|
247
|
+
const controller = new AbortController()
|
|
248
|
+
void readSandboxCommandHints(readyConnectionId, { type: activeChannel.type, id: activeChannel.id }, locale, controller.signal,
|
|
249
|
+
socketRequestContextRef.current ?? undefined).then((hints) => {
|
|
250
|
+
if (!controller.signal.aborted) setCommandHints(hints)
|
|
251
|
+
})
|
|
252
|
+
return () => controller.abort()
|
|
253
|
+
}, [readyConnectionId, canExecute, activeChannel.type, activeChannel.id, locale])
|
|
254
|
+
|
|
235
255
|
const subscribeToScene = (scene: Pick<Channel, 'id' | 'type'>) => {
|
|
236
256
|
// Old Hosts parse unknown JSON as chat, so control frames require this explicit handshake.
|
|
237
257
|
if (connectionRef.current.protocol !== SANDBOX_SCOPED_PROTOCOL || !connectionRef.current.canExecute) return
|
|
@@ -266,6 +286,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
266
286
|
endpointIdRef.current = data.endpoint || data.bot || 'sandbox-bot'
|
|
267
287
|
setBotName(endpointIdRef.current)
|
|
268
288
|
connectionRef.current = { protocol: data.protocol, connectionId: data.connectionId, ownerId: data.id, canExecute: data.canExecute !== false }
|
|
289
|
+
setReadyConnectionId(data.connectionId)
|
|
269
290
|
setCanExecute(data.canExecute !== false)
|
|
270
291
|
setTransportNotice(data.canExecute === false ? sandboxText(locale, "当前 Token 只有演示权限,任务运行已禁用。") : null)
|
|
271
292
|
if (data.shellIsolation) {
|
|
@@ -579,12 +600,19 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
579
600
|
if (typeof segment === 'string') {
|
|
580
601
|
return <MarkdownContent key={index} text={segment} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
581
602
|
}
|
|
603
|
+
// Unrendered JSX (or a segment without data) is read as text with `[button]` labels, never as raw JSON.
|
|
604
|
+
if (isJsxNode(segment) || !segment.data || typeof segment.data !== 'object') {
|
|
605
|
+
const fallback = segmentFallbackText(segment)
|
|
606
|
+
return fallback
|
|
607
|
+
? <MarkdownContent key={index} text={fallback} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
608
|
+
: <span key={index} className="sandbox-segment-note">[{String(segment.type)}]</span>
|
|
609
|
+
}
|
|
582
610
|
const d = segment.data as Record<string, unknown>
|
|
583
611
|
switch (segment.type) {
|
|
584
612
|
case 'text':
|
|
585
613
|
case 'markdown':
|
|
586
614
|
case 'md':
|
|
587
|
-
return <MarkdownContent key={index} text={
|
|
615
|
+
return <MarkdownContent key={index} text={typeof d.text === 'string' ? d.text : typeof d.content === 'string' ? d.content : segmentFallbackText(segment) ?? ''} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
588
616
|
case 'html':
|
|
589
617
|
return <HtmlMessage locale={locale} key={index} html={String(d.html ?? d.content ?? d.text ?? '')} />
|
|
590
618
|
case 'code':
|
|
@@ -831,8 +859,12 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
831
859
|
</div>
|
|
832
860
|
)
|
|
833
861
|
}
|
|
834
|
-
default:
|
|
835
|
-
|
|
862
|
+
default: {
|
|
863
|
+
const fallback = segmentFallbackText(segment)
|
|
864
|
+
return fallback
|
|
865
|
+
? <MarkdownContent key={index} text={fallback} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
866
|
+
: <span key={index} className="sandbox-segment-note">[{segment.type}]</span>
|
|
867
|
+
}
|
|
836
868
|
}
|
|
837
869
|
})
|
|
838
870
|
}
|
|
@@ -1149,20 +1181,44 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1149
1181
|
{props.renderConversationDetails
|
|
1150
1182
|
? <button type="button" disabled={!canExecute} aria-expanded={showConversationDetails} aria-controls="sandbox-conversation-details" onClick={() => setShowConversationDetails((visible) => !visible)}><ListChecks size={14} />{sandboxText(locale, "对话与轨迹")}</button>
|
|
1151
1183
|
: <a href={agentSessionsPath(sessionKey)}><ExternalLink size={14} />{sandboxText(locale, "对话与轨迹")}</a>}
|
|
1152
|
-
<
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1184
|
+
<div className="sandbox-more">
|
|
1185
|
+
<button
|
|
1186
|
+
type="button"
|
|
1187
|
+
className={cn("sandbox-more-trigger", (showMoreActions || showSenderSettings || showRunSettings) && 'active')}
|
|
1188
|
+
aria-haspopup="menu"
|
|
1189
|
+
aria-expanded={showMoreActions}
|
|
1190
|
+
onClick={() => setShowMoreActions((visible) => !visible)}
|
|
1191
|
+
aria-label={sandboxText(locale, "更多操作")}
|
|
1192
|
+
title={sandboxText(locale, "更多操作")}
|
|
1193
|
+
>
|
|
1194
|
+
<MoreHorizontal size={16} />
|
|
1195
|
+
</button>
|
|
1196
|
+
{showMoreActions && (
|
|
1197
|
+
<>
|
|
1198
|
+
<div className="sandbox-more-backdrop" onClick={() => setShowMoreActions(false)} />
|
|
1199
|
+
<div className="sandbox-more-menu" role="menu" aria-label={sandboxText(locale, "更多操作")}>
|
|
1200
|
+
<button type="button" role="menuitemcheckbox" aria-checked={showSenderSettings}
|
|
1201
|
+
onClick={() => { setShowSenderSettings((visible) => !visible); setShowMoreActions(false) }}>
|
|
1202
|
+
<User size={14} />
|
|
1203
|
+
<span>{sandboxText(locale, "模拟发送者")}</span>
|
|
1204
|
+
<em className={cn("sandbox-role-badge", `is-${senderRole}`)}>{senderName.trim() || senderId.trim() || 'dev-user'} · {senderRole}</em>
|
|
1205
|
+
</button>
|
|
1206
|
+
<button type="button" role="menuitemcheckbox" aria-checked={showRunSettings}
|
|
1207
|
+
onClick={() => { setShowRunSettings((visible) => !visible); setShowMoreActions(false) }}>
|
|
1208
|
+
<SlidersHorizontal size={14} /><span>{sandboxText(locale, "配置运行环境")}</span>
|
|
1209
|
+
</button>
|
|
1210
|
+
<button type="button" role="menuitemcheckbox" aria-checked={showInspector} aria-controls="sandbox-run-inspector"
|
|
1211
|
+
onClick={() => { setShowInspector(!showInspector); setShowMoreActions(false) }}>
|
|
1212
|
+
<PanelRight size={14} /><span>{sandboxText(locale, "切换运行检查器")}</span>
|
|
1213
|
+
</button>
|
|
1214
|
+
<button type="button" role="menuitem" className="is-danger"
|
|
1215
|
+
onClick={() => { setConfirmClear(true); setShowMoreActions(false) }}>
|
|
1216
|
+
<Trash2 size={14} /><span>{sandboxText(locale, "清空当前会话")}</span>
|
|
1217
|
+
</button>
|
|
1218
|
+
</div>
|
|
1219
|
+
</>
|
|
1220
|
+
)}
|
|
1221
|
+
</div>
|
|
1166
1222
|
</div>
|
|
1167
1223
|
</header>
|
|
1168
1224
|
|
|
@@ -1328,7 +1384,12 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1328
1384
|
{history.error ? <p role="alert">{history.error} <button type="button" disabled={history.loading} onClick={() => void history.refresh()}>{sandboxText(locale, '重试')}</button></p> : null}
|
|
1329
1385
|
{history.hasMore ? <button type="button" disabled={history.loading} onClick={() => void history.loadEarlier()}>{sandboxText(locale, '加载更早记录')}</button> : null}
|
|
1330
1386
|
</div> : null}
|
|
1331
|
-
{channelMessages.length === 0 ? (
|
|
1387
|
+
{channelMessages.length === 0 && history.loading ? (
|
|
1388
|
+
// Same full-height box as the empty state, so loaded history does not move the composer under the cursor.
|
|
1389
|
+
<div className="agent-playground-empty" role="status">
|
|
1390
|
+
<p>{sandboxText(locale, "正在加载会话记录…")}</p>
|
|
1391
|
+
</div>
|
|
1392
|
+
) : channelMessages.length === 0 ? (
|
|
1332
1393
|
<div className="agent-playground-empty">
|
|
1333
1394
|
<span className="agent-playground-empty-mark"><Sparkles size={24} /></span>
|
|
1334
1395
|
<div><h2>{sandboxText(locale, "开始一次可观察的 Agent 运行")}</h2><p>{sandboxText(locale, "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。")}</p></div>
|
|
@@ -1342,7 +1403,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1342
1403
|
<div className="agent-playground-message-list">
|
|
1343
1404
|
{channelMessages.map((msg) => {
|
|
1344
1405
|
if (msg.recalledMessageId) return <p key={msg.id} className="agent-playground-history-notice">{sandboxText(locale, '消息已撤回')}</p>
|
|
1345
|
-
const isApproval = msg
|
|
1406
|
+
const isApproval = isApprovalPrompt(msg)
|
|
1346
1407
|
return (
|
|
1347
1408
|
<React.Fragment key={JSON.stringify([msg.channelType, msg.channelId, msg.type, msg.id])}>
|
|
1348
1409
|
<article className={cn("agent-playground-message", msg.type === 'sent' ? "is-user" : "is-agent", isApproval && "is-approval")}>
|
|
@@ -1388,14 +1449,24 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1388
1449
|
onClick={() => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false) }} title={sandboxText(locale, "插入音频 URL")}>
|
|
1389
1450
|
<Music size={16} />
|
|
1390
1451
|
</button>
|
|
1452
|
+
<button type="button" className="sandbox-tool-button"
|
|
1453
|
+
onClick={() => { editorRef.current?.insertAt(endpointId, endpointId); setShowFacePicker(false); setMediaPanel(null) }}
|
|
1454
|
+
title={sandboxText(locale, "@ 机器人(插入 [@{0}])", [endpointId])} aria-label={sandboxText(locale, "@ 机器人")}>
|
|
1455
|
+
<AtSign size={16} />
|
|
1456
|
+
</button>
|
|
1391
1457
|
<div className="sandbox-quick-commands" role="toolbar" aria-label={locale === 'en' ? 'Quick commands' : '快捷命令'}>
|
|
1392
|
-
{
|
|
1458
|
+
{(commandHints?.quick ?? []).map((cmd) => (
|
|
1393
1459
|
<button
|
|
1394
1460
|
key={cmd}
|
|
1395
1461
|
type="button"
|
|
1396
1462
|
className="sandbox-command-chip"
|
|
1397
1463
|
disabled={!canExecute || directoryStatus.mode === 'loading'}
|
|
1398
|
-
|
|
1464
|
+
// Keyboard-reachable (WCAG 2.1.1). A mouse click must not keep focus on the chip,
|
|
1465
|
+
// and the prefill moves focus into the composer, so Enter sends the draft
|
|
1466
|
+
// rather than re-activating the chip after a late layout shift (#1250).
|
|
1467
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
1468
|
+
// Pre-fill the composer (never overwriting a draft); sending stays an explicit Enter / Send.
|
|
1469
|
+
onClick={() => editorRef.current?.setText(cmd)}
|
|
1399
1470
|
>
|
|
1400
1471
|
<Terminal size={11} />
|
|
1401
1472
|
<span>{cmd}</span>
|
|
@@ -1512,11 +1583,22 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1512
1583
|
<Send size={16} /> {sandboxText(locale, "发送")}</button>
|
|
1513
1584
|
</div>
|
|
1514
1585
|
|
|
1515
|
-
{/* Hints */}
|
|
1516
|
-
<
|
|
1517
|
-
<
|
|
1518
|
-
<
|
|
1519
|
-
|
|
1586
|
+
{/* Hints: collapsed by default so the composer stays one line tall (#1250). */}
|
|
1587
|
+
<details className="sandbox-hints">
|
|
1588
|
+
<summary><Keyboard size={12} /> {sandboxText(locale, "快捷操作与语法")}</summary>
|
|
1589
|
+
<ul>
|
|
1590
|
+
<li><span className="sandbox-hint-key">Enter</span> {sandboxText(locale, "发送")}</li>
|
|
1591
|
+
<li><span className="sandbox-hint-key">Shift+Enter</span> {sandboxText(locale, "换行")}</li>
|
|
1592
|
+
<li><span className="sandbox-hint-key">```ts</span> {sandboxText(locale, "代码块")}</li>
|
|
1593
|
+
<li><span className="sandbox-hint-key">{sandboxText(locale, "**文本**")}</span> {sandboxText(locale, "加粗")}</li>
|
|
1594
|
+
<li><span className="sandbox-hint-key">{sandboxText(locale, "[@名称]")}</span> {sandboxText(locale, "@某人")}</li>
|
|
1595
|
+
<li><span className="sandbox-hint-key">[@{endpointId}]</span> {sandboxText(locale, "@机器人(群聊里唤起机器人,也可点 @ 按钮插入)")}</li>
|
|
1596
|
+
<li><span className="sandbox-hint-key">[image:URL]</span> <span className="sandbox-hint-key">[video:URL]</span> <span className="sandbox-hint-key">[audio:URL]</span> {sandboxText(locale, "媒体")}</li>
|
|
1597
|
+
{commandHints && <li><Terminal size={11} /> {commandHints.prefix
|
|
1598
|
+
? sandboxText(locale, "命令以 {0} 开头", [commandHints.prefix])
|
|
1599
|
+
: sandboxText(locale, "命令无需前缀")}</li>}
|
|
1600
|
+
</ul>
|
|
1601
|
+
</details>
|
|
1520
1602
|
</section>
|
|
1521
1603
|
</main>
|
|
1522
1604
|
|
|
@@ -1656,12 +1738,9 @@ function taskStatusLabel(status: 'running' | 'completed' | 'failed' | 'cancelled
|
|
|
1656
1738
|
|
|
1657
1739
|
function messageText(segments: readonly MessageSegment[]): string {
|
|
1658
1740
|
return segments.map((segment) => {
|
|
1659
|
-
const data = segment.data as Record<string, unknown>
|
|
1660
|
-
if (segment.type === 'text' || segment.type === 'markdown' || segment.type === 'md') {
|
|
1661
|
-
return String(data.text ?? data.content ?? '')
|
|
1662
|
-
}
|
|
1741
|
+
const data = (segment.data ?? {}) as Record<string, unknown>
|
|
1663
1742
|
if (segment.type === 'mention' || segment.type === 'at') return `@${String(data.name ?? data.target ?? '')}`
|
|
1664
|
-
return
|
|
1743
|
+
return segmentPreviewText(segment)
|
|
1665
1744
|
}).join(' ').trim()
|
|
1666
1745
|
}
|
|
1667
1746
|
|