@zhin.js/adapter-sandbox 1.1.33 → 1.1.35
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 +109 -0
- package/README.md +6 -1
- package/lib/adapter.js +12 -1
- package/lib/console.d.ts +23 -0
- package/lib/console.js +46 -0
- package/lib/endpoint.d.ts +24 -2
- package/lib/endpoint.js +84 -5
- package/lib/protocol.d.ts +25 -2
- package/lib/protocol.js +79 -8
- package/package.json +43 -36
- package/pages/index/RichTextEditor.js +50 -0
- package/pages/index/RichTextEditor.tsx +49 -0
- package/pages/index/SandboxChat.js +86 -19
- package/pages/index/SandboxChat.tsx +181 -42
- package/pages/index/chatIdentity.js +47 -0
- package/pages/index/chatIdentity.ts +66 -0
- package/pages/index/composerCommands.js +41 -0
- package/pages/index/composerCommands.ts +56 -0
- package/pages/index/messages.js +22 -1
- package/pages/index/messages.ts +22 -1
- package/pages/index/segmentFallback.js +83 -0
- package/pages/index/segmentFallback.ts +78 -0
- package/pages/index/styles.js +25 -4
- package/pages/index/styles.ts +25 -4
- package/plugin.js +6 -2
- package/src/adapter.ts +7 -1
- package/src/console.ts +50 -0
- package/src/endpoint.ts +81 -6
- package/src/protocol.ts +96 -8
|
@@ -1,11 +1,14 @@
|
|
|
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 { ensureSandboxChatIdentity, readServerSpeaker, wantsAsMe } from './chatIdentity.js';
|
|
10
|
+
import { isJsxNode, segmentFallbackText, segmentPreviewText } from './segmentFallback.js';
|
|
11
|
+
import { User, Bot, Users, Trash2, Send, Hash, MessageSquare, Wifi, WifiOff, Smile, Image, X, Check, Search, Video, Music, Plus, PanelRight, ExternalLink, RefreshCw, Sparkles, Activity, Wrench, Coins, CircleAlert, Gauge, SlidersHorizontal, FolderOpen, ShieldCheck, Network, Square, RotateCcw, FileDiff, Terminal, FlaskConical, ChevronDown, FileDown, ListChecks, MoreHorizontal, Keyboard, AtSign, } from 'lucide-react';
|
|
9
12
|
import RichTextEditor, {} from './RichTextEditor.js';
|
|
10
13
|
import HtmlMessage from './HtmlMessage.js';
|
|
11
14
|
import { sandboxStyles } from './styles.js';
|
|
@@ -13,6 +16,12 @@ import ConversationRecoveryPanel from './ConversationRecoveryPanel.js';
|
|
|
13
16
|
import { useSandboxHistory } from './useSandboxHistory.js';
|
|
14
17
|
import { agentSessionsPath, buildAgentRunReport, buildSandboxSessionKey, cancelAgentTask, deriveAgentRunSteps, deriveTaskRuns, deriveWorkbenchArtifacts, fetchAgentTrace, loadCachedAgentTrace, mergeTraceSnapshot, presentTraceEvent, summarizeTrace, saveCachedAgentTrace, } from './agentTrace.js';
|
|
15
18
|
import { createDefaultPlaygroundState, loadPlaygroundState, savePlaygroundState, mergePlaygroundMessage, retirePlaygroundInteractions, } from './playgroundState.js';
|
|
19
|
+
/** ADR 0060 §5.4: the simulated role is a platform standing (群主 / 管理员 / 成员), never a zhin role. */
|
|
20
|
+
function platformStandingLabel(role, locale) {
|
|
21
|
+
if (locale === 'en')
|
|
22
|
+
return role === 'master' ? 'group owner' : role === 'admin' ? 'group admin' : 'member';
|
|
23
|
+
return role === 'master' ? '群主' : role === 'admin' ? '群管理员' : '成员';
|
|
24
|
+
}
|
|
16
25
|
export default function Sandbox(props = {}) {
|
|
17
26
|
const [locale, setLocale] = useState('zh-CN');
|
|
18
27
|
const localeRef = useRef('zh-CN');
|
|
@@ -45,7 +54,7 @@ export default function Sandbox(props = {}) {
|
|
|
45
54
|
const [faceSearchQuery, setFaceSearchQuery] = useState('');
|
|
46
55
|
const atSuggestions = [
|
|
47
56
|
{ id: 'actor-owner', name: sandboxText(locale, "当前用户") }, { id: 'actor-reviewer', name: sandboxText(locale, "审阅者") },
|
|
48
|
-
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id:
|
|
57
|
+
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id: endpointId, name: endpointId }
|
|
49
58
|
];
|
|
50
59
|
const [previewSegments, setPreviewSegments] = useState([]);
|
|
51
60
|
const [composerMode, setComposerMode] = useState('write');
|
|
@@ -57,7 +66,19 @@ export default function Sandbox(props = {}) {
|
|
|
57
66
|
const [senderId, setSenderId] = useState('dev-user');
|
|
58
67
|
const [senderName, setSenderName] = useState('Developer');
|
|
59
68
|
const [senderRole, setSenderRole] = useState('master');
|
|
69
|
+
// ADR 0060 §5.4: what the server resolved for the last message sent (speaker, zhin role, Agent trust tier).
|
|
70
|
+
const [serverRole, setServerRole] = useState(null);
|
|
71
|
+
// 「以我的聊天身份发言」 (default) vs a simulated sender; only a signed-in Console user can speak as themselves.
|
|
72
|
+
const [speakerMode, setSpeakerMode] = useState('me');
|
|
73
|
+
const [consoleUser, setConsoleUser] = useState(false);
|
|
74
|
+
const [identitySetup, setIdentitySetup] = useState({ status: 'idle' });
|
|
75
|
+
const asMe = wantsAsMe(speakerMode, consoleUser);
|
|
60
76
|
const [showSenderSettings, setShowSenderSettings] = useState(false);
|
|
77
|
+
/** Runbar overflow: identity, run settings, inspector and clear live here (#1250). */
|
|
78
|
+
const [showMoreActions, setShowMoreActions] = useState(false);
|
|
79
|
+
/** Live binding of the current socket; drives the Host-provided quick commands. */
|
|
80
|
+
const [readyConnectionId, setReadyConnectionId] = useState(undefined);
|
|
81
|
+
const [commandHints, setCommandHints] = useState(null);
|
|
61
82
|
const [showNewSession, setShowNewSession] = useState(false);
|
|
62
83
|
const [newSessionName, setNewSessionName] = useState('');
|
|
63
84
|
const [newSessionScope, setNewSessionScope] = useState('private');
|
|
@@ -178,6 +199,19 @@ export default function Sandbox(props = {}) {
|
|
|
178
199
|
}
|
|
179
200
|
};
|
|
180
201
|
useEffect(() => { fetchFaceList(); }, []);
|
|
202
|
+
// Quick commands come from the Host's command index and the endpoint's commandPrefix;
|
|
203
|
+
// without an answer the composer offers none rather than guessing.
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
setCommandHints(null);
|
|
206
|
+
if (!readyConnectionId || !canExecute)
|
|
207
|
+
return;
|
|
208
|
+
const controller = new AbortController();
|
|
209
|
+
void readSandboxCommandHints(readyConnectionId, { type: activeChannel.type, id: activeChannel.id }, locale, controller.signal, socketRequestContextRef.current ?? undefined).then((hints) => {
|
|
210
|
+
if (!controller.signal.aborted)
|
|
211
|
+
setCommandHints(hints);
|
|
212
|
+
});
|
|
213
|
+
return () => controller.abort();
|
|
214
|
+
}, [readyConnectionId, canExecute, activeChannel.type, activeChannel.id, locale]);
|
|
181
215
|
const subscribeToScene = (scene) => {
|
|
182
216
|
// Old Hosts parse unknown JSON as chat, so control frames require this explicit handshake.
|
|
183
217
|
if (connectionRef.current.protocol !== SANDBOX_SCOPED_PROTOCOL || !connectionRef.current.canExecute)
|
|
@@ -205,7 +239,9 @@ export default function Sandbox(props = {}) {
|
|
|
205
239
|
endpointIdRef.current = data.endpoint || data.bot || 'sandbox-bot';
|
|
206
240
|
setBotName(endpointIdRef.current);
|
|
207
241
|
connectionRef.current = { protocol: data.protocol, connectionId: data.connectionId, ownerId: data.id, canExecute: data.canExecute !== false };
|
|
242
|
+
setReadyConnectionId(data.connectionId);
|
|
208
243
|
setCanExecute(data.canExecute !== false);
|
|
244
|
+
setConsoleUser(data.consoleUser === true);
|
|
209
245
|
setTransportNotice(data.canExecute === false ? sandboxText(locale, "当前 Token 只有演示权限,任务运行已禁用。") : null);
|
|
210
246
|
if (data.shellIsolation) {
|
|
211
247
|
setShellIsolation({
|
|
@@ -249,6 +285,9 @@ export default function Sandbox(props = {}) {
|
|
|
249
285
|
const channelType = data.conversation?.type ?? (data.type === 'group' || data.type === 'channel' ? data.type : 'private');
|
|
250
286
|
const sceneId = data.conversation?.id ?? data.id;
|
|
251
287
|
const isInput = data.direction === 'inbound';
|
|
288
|
+
const speaker = isInput ? readServerSpeaker(data) : null;
|
|
289
|
+
if (speaker)
|
|
290
|
+
setServerRole(speaker);
|
|
252
291
|
// Interactive choices are transport inputs, not another chat turn or an approval result.
|
|
253
292
|
if (isInput && content.every((segment) => segment.type === 'action'))
|
|
254
293
|
return;
|
|
@@ -271,7 +310,7 @@ export default function Sandbox(props = {}) {
|
|
|
271
310
|
setMessages((prev) => mergePlaygroundMessage(prev, {
|
|
272
311
|
id: data.messageId ?? createSandboxMessageId(), type: isInput ? 'sent' : 'received', channelType,
|
|
273
312
|
interactionReadOnly: false,
|
|
274
|
-
channelId: sceneId, channelName, senderId: isInput ? data.senderId || connectionRef.current.ownerId || 'owner' : 'endpoint',
|
|
313
|
+
channelId: sceneId, channelName, senderId: isInput ? data.displaySenderId || data.senderId || connectionRef.current.ownerId || 'owner' : 'endpoint',
|
|
275
314
|
senderName: isInput ? (typeof data.senderName === 'string' && data.senderName.trim() ? data.senderName.trim() : sandboxText(locale, "当前用户")) : data.bot || endpointIdRef.current, content, timestamp: data.timestamp,
|
|
276
315
|
...(Number.isSafeInteger(data.revision) && data.revision > 0 ? { revision: data.revision } : {}),
|
|
277
316
|
...(typeof data.streaming === 'boolean' ? { streaming: data.streaming } : {}),
|
|
@@ -286,7 +325,7 @@ export default function Sandbox(props = {}) {
|
|
|
286
325
|
const resolvedSenderName = senderName.trim() || sandboxText(localeRef.current, "测试用户");
|
|
287
326
|
if (!submitSandboxFrame(wsRef.current, {
|
|
288
327
|
type: scene.type, id: scene.id, messageId: createSandboxMessageId(), content: segments,
|
|
289
|
-
senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole,
|
|
328
|
+
senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole, ...(asMe ? { asMe: true } : {}),
|
|
290
329
|
agentRun: scene.runConfig, timestamp: Date.now(),
|
|
291
330
|
})) {
|
|
292
331
|
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,审批选择未发送。"));
|
|
@@ -533,12 +572,19 @@ export default function Sandbox(props = {}) {
|
|
|
533
572
|
if (typeof segment === 'string') {
|
|
534
573
|
return _jsx(MarkdownContent, { text: segment, className: isSent ? 'zhin-markdown--inverse' : undefined }, index);
|
|
535
574
|
}
|
|
575
|
+
// Unrendered JSX (or a segment without data) is read as text with `[button]` labels, never as raw JSON.
|
|
576
|
+
if (isJsxNode(segment) || !segment.data || typeof segment.data !== 'object') {
|
|
577
|
+
const fallback = segmentFallbackText(segment);
|
|
578
|
+
return fallback
|
|
579
|
+
? _jsx(MarkdownContent, { text: fallback, className: isSent ? 'zhin-markdown--inverse' : undefined }, index)
|
|
580
|
+
: _jsxs("span", { className: "sandbox-segment-note", children: ["[", String(segment.type), "]"] }, index);
|
|
581
|
+
}
|
|
536
582
|
const d = segment.data;
|
|
537
583
|
switch (segment.type) {
|
|
538
584
|
case 'text':
|
|
539
585
|
case 'markdown':
|
|
540
586
|
case 'md':
|
|
541
|
-
return _jsx(MarkdownContent, { text:
|
|
587
|
+
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
588
|
case 'html':
|
|
543
589
|
return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? d.content ?? d.text ?? '') }, index);
|
|
544
590
|
case 'code':
|
|
@@ -642,8 +688,12 @@ export default function Sandbox(props = {}) {
|
|
|
642
688
|
return (_jsxs("div", { className: "agent-playground-approval-actions", children: [rows.map((row, ri) => (_jsx("div", { children: row.map((btn) => (_jsx("button", { type: "button", disabled: btn.disabled || isSent || resolved || !canExecute || !allowInteraction, onClick: () => { if (sendInteractiveAction(btn.payload, messageId))
|
|
643
689
|
onInteractionSubmitted?.(); }, className: cn((btn.style === 'primary' || /^允许/u.test(btn.label)) && 'is-primary', (btn.style === 'danger' || /拒绝|取消/u.test(btn.label)) && 'is-danger'), children: btn.label }, btn.payload))) }, ri))), resolved && _jsxs("small", { children: [_jsx(Check, { size: 12 }), sandboxText(locale, "已提交本次选择")] })] }, index));
|
|
644
690
|
}
|
|
645
|
-
default:
|
|
646
|
-
|
|
691
|
+
default: {
|
|
692
|
+
const fallback = segmentFallbackText(segment);
|
|
693
|
+
return fallback
|
|
694
|
+
? _jsx(MarkdownContent, { text: fallback, className: isSent ? 'zhin-markdown--inverse' : undefined }, index)
|
|
695
|
+
: _jsxs("span", { className: "sandbox-segment-note", children: ["[", segment.type, "]"] }, index);
|
|
696
|
+
}
|
|
647
697
|
}
|
|
648
698
|
});
|
|
649
699
|
};
|
|
@@ -660,7 +710,7 @@ export default function Sandbox(props = {}) {
|
|
|
660
710
|
};
|
|
661
711
|
if (!submitSandboxFrame(wsRef.current, {
|
|
662
712
|
type: scene.type, id: scene.id, messageId: newMessage.id, content: segments,
|
|
663
|
-
senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole,
|
|
713
|
+
senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole, ...(asMe ? { asMe: true } : {}),
|
|
664
714
|
agentRun: scene.runConfig, timestamp: newMessage.timestamp,
|
|
665
715
|
})) {
|
|
666
716
|
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,消息未发送。"));
|
|
@@ -828,6 +878,7 @@ export default function Sandbox(props = {}) {
|
|
|
828
878
|
.sandbox-role-badge.is-master { background: rgba(245,158,11,0.18); color: #d97706; }
|
|
829
879
|
.sandbox-role-badge.is-admin { background: rgba(59,130,246,0.18); color: #2563eb; }
|
|
830
880
|
.sandbox-role-badge.is-member { background: rgba(16,185,129,0.16); color: #059669; }
|
|
881
|
+
.sandbox-role-badge.is-zhin { text-transform: none; background: rgba(139,92,246,0.16); color: #7c3aed; }
|
|
831
882
|
.sandbox-role-switcher { display: inline-flex; gap: 4px; }
|
|
832
883
|
.sandbox-role-option { padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.3); font-size: 12px; cursor: pointer; background: transparent; color: inherit; text-transform: capitalize; }
|
|
833
884
|
.sandbox-role-option.active { font-weight: 600; border-color: currentColor; background: rgba(59,130,246,0.12); }
|
|
@@ -861,7 +912,18 @@ export default function Sandbox(props = {}) {
|
|
|
861
912
|
}) }), _jsx("div", { className: "agent-playground-new-session", children: showNewSession ? (_jsxs("div", { className: "agent-playground-new-form", children: [_jsx("input", { value: newSessionName, onChange: (event) => setNewSessionName(event.target.value), onKeyDown: (event) => { if (event.key === 'Enter')
|
|
862
913
|
addSession(); }, placeholder: sandboxText(locale, "会话名称"), autoFocus: true }), _jsx("div", { className: "agent-playground-scope-picker", role: "group", "aria-label": sandboxText(locale, "消息作用域"), children: ['private', 'group', 'channel'].map((scope) => (_jsx("button", { type: "button", "aria-pressed": newSessionScope === scope, className: cn(newSessionScope === scope && 'active'), onClick: () => setNewSessionScope(scope), children: scope === 'private' ? sandboxText(locale, "单用户") : scope === 'group' ? sandboxText(locale, "群组") : sandboxText(locale, "频道") }, scope))) }), _jsxs("div", { className: "agent-playground-new-actions", children: [_jsx("button", { type: "button", onClick: () => setShowNewSession(false), children: sandboxText(locale, "取消") }), _jsx("button", { type: "button", className: "primary", onClick: addSession, children: sandboxText(locale, "创建") })] })] })) : (_jsxs("button", { type: "button", disabled: directoryStatus.mode === 'loading', className: "agent-playground-add", onClick: () => setShowNewSession(true), children: [_jsx(Plus, { size: 15 }), sandboxText(locale, "新建会话")] })) }), _jsxs("div", { className: "agent-playground-endpoint", children: [_jsx("span", { children: directoryStatus.mode === 'loading' ? sandboxText(locale, "正在读取会话目录") : directoryStatus.mode === 'server' && !directoryStatus.error ? sandboxText(locale, "Host 会话目录") : persistenceStatus === 'saved' ? sandboxText(locale, "会话已持久化") : sandboxText(locale, "会话保存失败") }), _jsx("strong", { children: endpointId })] })] }), showChannelList && _jsx("div", { className: "channel-overlay", onClick: () => setShowChannelList(false) }), _jsxs("main", { className: "chat-area agent-playground-main", children: [_jsxs("header", { className: "agent-playground-runbar", children: [_jsxs("div", { className: "agent-playground-run-identity", children: [_jsx("span", { className: "agent-playground-run-icon", children: getChannelIcon(activeChannel.type) }), _jsx("div", { title: sessionKey, children: _jsxs("div", { className: "agent-playground-run-title", children: [_jsx("h1", { title: activeChannel.name, children: activeChannel.name }), _jsx("span", { children: scopeLabel })] }) })] }), _jsxs("div", { className: "agent-playground-run-actions", children: [_jsxs("span", { className: cn("agent-playground-run-state", currentTask?.status === 'running' && "is-running", currentTask?.status === 'failed' && 'has-problem'), children: [currentTask?.status === 'running' ? _jsx(Activity, { size: 14 }) : _jsx(Gauge, { size: 14 }), currentTask ? taskStatusLabel(currentTask.status, locale) : sandboxText(locale, "{0} 条消息", [channelMessages.length])] }), currentTask?.status === 'running' ? (_jsxs("button", { type: "button", className: "agent-playground-stop", onClick: () => void stopActiveTask(), disabled: stoppingTask, "aria-label": sandboxText(locale, "停止当前任务"), children: [_jsx(Square, { size: 13 }), stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")] })) : lastUserMessage ? (_jsxs("button", { type: "button", onClick: retryLastTask, "aria-label": sandboxText(locale, "重新运行上一个任务"), children: [_jsx(RotateCcw, { size: 14 }), sandboxText(locale, "重试")] })) : null, props.renderConversationDetails
|
|
863
914
|
? _jsxs("button", { type: "button", disabled: !canExecute, "aria-expanded": showConversationDetails, "aria-controls": "sandbox-conversation-details", onClick: () => setShowConversationDetails((visible) => !visible), children: [_jsx(ListChecks, { size: 14 }), sandboxText(locale, "对话与轨迹")] })
|
|
864
|
-
: _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsxs("
|
|
915
|
+
: _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsxs("div", { className: "sandbox-more", children: [_jsx("button", { type: "button", className: cn("sandbox-more-trigger", (showMoreActions || showSenderSettings || showRunSettings) && 'active'), "aria-haspopup": "menu", "aria-expanded": showMoreActions, onClick: () => setShowMoreActions((visible) => !visible), "aria-label": sandboxText(locale, "更多操作"), title: sandboxText(locale, "更多操作"), children: _jsx(MoreHorizontal, { size: 16 }) }), showMoreActions && (_jsxs(_Fragment, { children: [_jsx("div", { className: "sandbox-more-backdrop", onClick: () => setShowMoreActions(false) }), _jsxs("div", { className: "sandbox-more-menu", role: "menu", "aria-label": sandboxText(locale, "更多操作"), children: [_jsxs("button", { type: "button", role: "menuitemcheckbox", "aria-checked": showSenderSettings, onClick: () => { setShowSenderSettings((visible) => !visible); setShowMoreActions(false); }, children: [_jsx(User, { size: 14 }), _jsx("span", { children: sandboxText(locale, "模拟发送者") }), _jsxs("em", { className: cn("sandbox-role-badge", `is-${senderRole}`), title: locale === 'en' ? 'Simulated platform standing (not a zhin role)' : '模拟的平台身份(不是 zhin 角色)', children: [asMe ? sandboxText(locale, "我的聊天身份") : (senderName.trim() || senderId.trim() || 'dev-user'), " \u00B7 ", platformStandingLabel(senderRole, locale)] }), serverRole && (serverRole.simulated
|
|
916
|
+
? _jsx("em", { className: "sandbox-role-badge is-simulated", title: sandboxText(locale, "客户端自填的发送者不解析 zhin 角色"), children: sandboxText(locale, "模拟身份,无角色") })
|
|
917
|
+
: _jsx("em", { className: "sandbox-role-badge is-zhin", title: locale === 'en' ? 'Resolved by the server: zhin role · Agent trust tier' : '服务端解析:zhin 角色 · Agent 信任档位', children: `zhin: ${serverRole.chatRole ?? (locale === 'en' ? 'none' : '无')} · ${serverRole.trustLevel}` }))] }), _jsxs("button", { type: "button", role: "menuitemcheckbox", "aria-checked": showRunSettings, onClick: () => { setShowRunSettings((visible) => !visible); setShowMoreActions(false); }, children: [_jsx(SlidersHorizontal, { size: 14 }), _jsx("span", { children: sandboxText(locale, "配置运行环境") })] }), _jsxs("button", { type: "button", role: "menuitemcheckbox", "aria-checked": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => { setShowInspector(!showInspector); setShowMoreActions(false); }, children: [_jsx(PanelRight, { size: 14 }), _jsx("span", { children: sandboxText(locale, "切换运行检查器") })] }), _jsxs("button", { type: "button", role: "menuitem", className: "is-danger", onClick: () => { setConfirmClear(true); setShowMoreActions(false); }, children: [_jsx(Trash2, { size: 14 }), _jsx("span", { children: sandboxText(locale, "清空当前会话") })] })] })] }))] })] })] }), showSenderSettings && (_jsxs("section", { className: "agent-playground-run-settings sandbox-sender-settings", "aria-label": locale === 'en' ? 'Simulated sender' : '模拟发送者配置', children: [_jsxs("div", { className: "sandbox-speaker-mode", children: [_jsxs("label", { className: "sandbox-speaker-toggle", children: [_jsx("input", { type: "checkbox", checked: speakerMode === 'me', disabled: !consoleUser, onChange: (event) => setSpeakerMode(event.target.checked ? 'me' : 'simulated') }), _jsx("span", { children: sandboxText(locale, "以我的聊天身份发言") })] }), _jsx("p", { children: !consoleUser
|
|
918
|
+
? sandboxText(locale, "当前连接没有 Console 用户(未登录或 --standalone),所有消息都按模拟身份处理,不解析 zhin 角色。")
|
|
919
|
+
: asMe
|
|
920
|
+
? sandboxText(locale, "以链接到你 Console 账号的聊天身份发言,角色按你的聊天角色解析。")
|
|
921
|
+
: sandboxText(locale, "模拟身份,无角色:自填的发送者 ID 只用于模拟别人,不解析 zhin 角色。") }), asMe && serverRole?.asMeUnavailable === 'needs-global-iam' && (_jsx("div", { className: "sandbox-speaker-setup", role: "status", children: _jsx("span", { children: sandboxText(locale, "链接到你的聊天身份持有全局角色,以它发言需要全局 iam.manage 权限;上一条消息按模拟身份(无角色)发送。") }) })), asMe && serverRole?.asMeUnavailable === 'no-identity' && (_jsxs("div", { className: "sandbox-speaker-setup", role: "status", children: [_jsx("span", { children: sandboxText(locale, "你在 Sandbox 上还没有聊天身份,上一条消息按模拟身份发送。") }), _jsx("button", { type: "button", disabled: identitySetup.status === 'busy', onClick: () => {
|
|
922
|
+
setIdentitySetup({ status: 'busy' });
|
|
923
|
+
void ensureSandboxChatIdentity(socketRequestContextRef.current ?? undefined).then((result) => {
|
|
924
|
+
setIdentitySetup(result.status === 'ok' ? { status: 'done' } : result);
|
|
925
|
+
});
|
|
926
|
+
}, children: sandboxText(locale, "在 Sandbox 上创建我的聊天身份") }), identitySetup.status === 'done' && _jsx("em", { children: sandboxText(locale, "已创建,下一条消息生效。") }), identitySetup.status === 'unsupported' && _jsx("em", { children: sandboxText(locale, "当前 Host 不支持,请升级。") }), identitySetup.status === 'failed' && _jsx("em", { children: identitySetup.message })] }))] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(User, { size: 14 }), locale === 'en' ? 'Sender ID (simulated, no role)' : '发送者 ID(模拟身份,无角色)'] }), _jsx("input", { value: senderId, disabled: asMe, onChange: (event) => setSenderId(event.target.value), placeholder: "dev-user", spellCheck: false })] }), _jsxs("label", { children: [_jsx("span", { children: locale === 'en' ? 'Sender Name' : '发送者昵称' }), _jsx("input", { value: senderName, disabled: asMe, onChange: (event) => setSenderName(event.target.value), placeholder: "Developer", spellCheck: false })] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), locale === 'en' ? 'Platform standing (not a zhin role)' : '平台身份(不是 zhin 角色)'] }), _jsx("div", { className: "sandbox-role-switcher", role: "group", "aria-label": locale === 'en' ? 'Platform standing' : '平台身份', children: ['member', 'admin', 'master'].map((role) => (_jsx("button", { type: "button", "aria-pressed": senderRole === role, className: cn("sandbox-role-option", `is-${role}`, senderRole === role && "active"), onClick: () => setSenderRole(role), children: platformStandingLabel(role, locale) }, role))) })] }), _jsxs("div", { className: "sandbox-sender-presets", children: [_jsx("button", { type: "button", onClick: () => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master'); }, children: locale === 'en' ? 'Group owner (platform standing, dev-user)' : '群主(平台身份,dev-user)' }), _jsx("button", { type: "button", onClick: () => { setSenderId('admin-user'); setSenderName('Admin'); setSenderRole('admin'); }, children: "Admin (admin-user)" }), _jsx("button", { type: "button", onClick: () => { setSenderId('member-user'); setSenderName('Member'); setSenderRole('member'); }, children: "Member (member-user)" })] })] })), cancellationFeedback && _jsxs("div", { className: "agent-playground-confirm", role: cancellationFeedback.kind === 'error' ? 'alert' : 'status', children: [_jsx("div", { children: _jsx("span", { children: cancellationFeedback.message }) }), _jsx("button", { type: "button", onClick: () => setCancellationFeedback(null), children: sandboxText(locale, "知道了") })] }), confirmClear && (_jsxs("div", { className: "agent-playground-confirm", role: "alert", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "清空当前测试记录?") }), _jsxs("span", { children: [sandboxText(locale, "只移除“"), activeChannel.name, sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")] })] }), _jsx("button", { type: "button", onClick: () => setConfirmClear(false), children: sandboxText(locale, "取消") }), _jsx("button", { type: "button", className: "danger", onClick: clearMessages, children: sandboxText(locale, "确认清空") })] })), ['emoji', 'parse'].filter((kind) => inlineNotices[kind]).map((kind) => (_jsxs("div", { className: "sandbox-notice", role: "status", children: [_jsx(CircleAlert, { size: 14 }), _jsx("span", { children: kind === 'emoji' ? sandboxText(locale, "表情列表加载失败,表情选择器暂不可用。") : sandboxText(locale, "收到一条无法解析的消息,已忽略。") }), _jsx("button", { type: "button", onClick: () => setInlineNotices((n) => ({ ...n, [kind]: false })), children: sandboxText(locale, "知道了") })] }, kind))), transportNotice && (_jsxs("div", { className: "agent-playground-confirm", role: "status", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "运行暂不可用") }), _jsx("span", { children: transportNotice })] }), _jsx("button", { type: "button", onClick: () => setTransportNotice(null), children: sandboxText(locale, "知道了") })] })), directoryStatus.error && _jsxs("div", { className: "agent-playground-confirm", role: "alert", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "会话目录") }), _jsx("span", { children: directoryStatus.error })] }), _jsx("button", { type: "button", onClick: () => void directoryControllerRef.current?.refresh(), children: sandboxText(locale, "重新读取") })] }), showRunSettings && (_jsxs("section", { className: "agent-playground-run-settings", "aria-label": sandboxText(locale, "运行配置"), children: [_jsxs("label", { className: "agent-playground-directory-field", children: [_jsxs("span", { children: [_jsx(FolderOpen, { size: 14 }), sandboxText(locale, "工作目录")] }), _jsx("input", { disabled: directoryStatus.mode === 'loading', value: activeChannel.runConfig.workingDirectory, onChange: (event) => updateRunConfig({ workingDirectory: event.target.value }), placeholder: sandboxText(locale, "使用 Host 项目目录"), spellCheck: false })] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), sandboxText(locale, "安全策略")] }), _jsxs("select", { disabled: directoryStatus.mode === 'loading', value: activeChannel.runConfig.safetyMode, onChange: (event) => {
|
|
865
927
|
const safetyMode = event.target.value;
|
|
866
928
|
updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) });
|
|
867
929
|
}, children: [_jsx("option", { value: "read-only", children: sandboxText(locale, "只读") }), _jsx("option", { value: "workspace-write", children: sandboxText(locale, "工作区写入") }), _jsx("option", { value: "danger-full-access", children: sandboxText(locale, "完全访问") })] })] }), _jsxs("label", { children: [_jsx("span", { children: sandboxText(locale, "审批策略") }), _jsxs("select", { value: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode, disabled: activeChannel.runConfig.safetyMode !== 'workspace-write', onChange: (event) => updateRunConfig({ approvalMode: event.target.value }), children: [_jsx("option", { value: "ask", children: sandboxText(locale, "按需确认") }), _jsx("option", { value: "auto", children: sandboxText(locale, "审核 Agent 自动判断") }), _jsx("option", { value: "bypass", children: sandboxText(locale, "绕过审批") })] })] }), _jsxs("label", { className: "agent-playground-network-toggle", children: [_jsxs("span", { children: [_jsx(Network, { size: 14 }), sandboxText(locale, "网络访问")] }), _jsx("input", { type: "checkbox", checked: activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess, disabled: activeChannel.runConfig.safetyMode === 'danger-full-access', onChange: (event) => updateRunConfig({ networkAccess: event.target.checked }) }), _jsx("i", { "aria-hidden": "true" })] }), activeChannel.runConfig.safetyMode === 'danger-full-access' && (_jsxs("p", { children: [_jsx(CircleAlert, { size: 14 }), sandboxText(locale, "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。")] })), activeChannel.runConfig.safetyMode !== 'danger-full-access' && shellIsolation?.available === false && (_jsxs("p", { children: [_jsx(CircleAlert, { size: 14 }), sandboxText(locale, "安全 Shell 需要可用的 Docker daemon;当前仅文件工具可运行。"), shellIsolation.message] }))] })), canExecute && recoveryConnectionId && (_jsx(ConversationRecoveryPanel, { connectionId: recoveryConnectionId, sessionKey: sessionKey, locale: locale, hidden: showConversationDetails, pendingRefreshEpoch: pendingRefreshEpoch, onRetiredInteractions: (retired) => {
|
|
@@ -873,18 +935,26 @@ export default function Sandbox(props = {}) {
|
|
|
873
935
|
return previous;
|
|
874
936
|
return retirePlaygroundInteractions(previous, activeChannel, segments);
|
|
875
937
|
});
|
|
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) => {
|
|
938
|
+
}, requestContext: socketRequestContextRef.current ?? undefined, renderInteraction: (segments, id, submitted, onSubmitted) => renderMessageSegments(segments, false, id, submitted, onSubmitted) }, JSON.stringify([recoveryConnectionId, sessionKey]))), showConversationDetails && props.renderConversationDetails && (_jsxs("section", { id: "sandbox-conversation-details", className: "agent-playground-conversation-details", "aria-label": sandboxText(locale, "对话与轨迹"), children: [_jsxs("button", { type: "button", className: "agent-playground-details-back", onClick: () => setShowConversationDetails(false), children: [_jsx(MessageSquare, { size: 14 }), sandboxText(locale, "返回会话")] }), props.renderConversationDetails({ sessionKey, canExecute, connectionId: connectionRef.current.connectionId })] })), _jsx("section", { className: "agent-playground-conversation", hidden: showConversationDetails, "aria-label": sandboxText(locale, "Agent 对话"), children: _jsxs("div", { className: "agent-playground-message-scroll", "aria-busy": history.loading, children: [history.hasMore || history.error ? _jsxs("div", { className: "agent-playground-history-navigation", children: [history.error ? _jsxs("p", { role: "alert", children: [history.error, " ", _jsx("button", { type: "button", disabled: history.loading, onClick: () => void history.refresh(), children: sandboxText(locale, '重试') })] }) : null, history.hasMore ? _jsx("button", { type: "button", disabled: history.loading, onClick: () => void history.loadEarlier(), children: sandboxText(locale, '加载更早记录') }) : null] }) : null, channelMessages.length === 0 && history.loading ? (_jsx("div", { className: "agent-playground-empty", role: "status", children: _jsx("p", { children: sandboxText(locale, "正在加载会话记录…") }) })) : channelMessages.length === 0 ? (_jsxs("div", { className: "agent-playground-empty", children: [_jsx("span", { className: "agent-playground-empty-mark", children: _jsx(Sparkles, { size: 24 }) }), _jsxs("div", { children: [_jsx("h2", { children: sandboxText(locale, "开始一次可观察的 Agent 运行") }), _jsx("p", { children: sandboxText(locale, "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。") })] }), _jsxs("div", { className: "agent-playground-prompts", children: [_jsx("button", { type: "button", onClick: () => runPrompt(sandboxText(locale, "介绍当前 Agent 可以使用的能力,并给出三个具体示例。")), children: sandboxText(locale, "探索可用能力") }), _jsx("button", { type: "button", onClick: () => runPrompt(sandboxText(locale, "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。")), children: sandboxText(locale, "测试富文本输出") }), _jsx("button", { type: "button", onClick: () => runPrompt(sandboxText(locale, "分析一个任务从推理、工具调用到最终回复的完整执行路径。")), children: sandboxText(locale, "观察执行路径") })] })] })) : (_jsxs("div", { className: "agent-playground-message-list", children: [channelMessages.map((msg) => {
|
|
877
939
|
if (msg.recalledMessageId)
|
|
878
940
|
return _jsx("p", { className: "agent-playground-history-notice", children: sandboxText(locale, '消息已撤回') }, msg.id);
|
|
879
|
-
const isApproval = msg
|
|
941
|
+
const isApproval = isApprovalPrompt(msg);
|
|
880
942
|
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 }) }),
|
|
943
|
+
}), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] }))] }) }), _jsxs("section", { className: "agent-playground-composer", hidden: showConversationDetails, "aria-label": sandboxText(locale, "任务输入"), children: [_jsxs("div", { className: "sandbox-toolbar", children: [_jsx("button", { type: "button", className: cn("sandbox-tool-button", showFacePicker && "is-active"), onClick: () => { setShowFacePicker(!showFacePicker); setMediaPanel(null); }, title: sandboxText(locale, "插入表情"), children: _jsx(Smile, { size: 16 }) }), _jsx("button", { type: "button", className: cn("sandbox-tool-button", mediaPanel === 'image' && "is-active"), onClick: () => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false); }, title: sandboxText(locale, "插入图片 URL"), children: _jsx(Image, { size: 16 }) }), _jsx("button", { type: "button", className: cn("sandbox-tool-button", mediaPanel === 'video' && "is-active"), onClick: () => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false); }, title: sandboxText(locale, "插入视频 URL"), children: _jsx(Video, { size: 16 }) }), _jsx("button", { type: "button", className: cn("sandbox-tool-button", mediaPanel === 'audio' && "is-active"), onClick: () => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false); }, title: sandboxText(locale, "插入音频 URL"), children: _jsx(Music, { size: 16 }) }), _jsx("button", { type: "button", className: "sandbox-tool-button", onClick: () => { editorRef.current?.insertAt(endpointId, endpointId); setShowFacePicker(false); setMediaPanel(null); }, title: sandboxText(locale, "@ 机器人(插入 [@{0}])", [endpointId]), "aria-label": sandboxText(locale, "@ 机器人"), children: _jsx(AtSign, { size: 16 }) }), _jsxs("div", { className: "sandbox-quick-commands", role: "toolbar", "aria-label": locale === 'en' ? 'Quick commands' : '快捷命令', children: [(commandHints?.quick ?? []).map((cmd) => (_jsxs("button", { type: "button", className: "sandbox-command-chip", disabled: !canExecute || directoryStatus.mode === 'loading',
|
|
944
|
+
// Keyboard-reachable (WCAG 2.1.1). A mouse click must not keep focus on the chip,
|
|
945
|
+
// and the prefill moves focus into the composer, so Enter sends the draft
|
|
946
|
+
// rather than re-activating the chip after a late layout shift (#1250).
|
|
947
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
948
|
+
// Pre-fill the composer (never overwriting a draft); sending stays an explicit Enter / Send.
|
|
949
|
+
onClick: () => editorRef.current?.setText(cmd), children: [_jsx(Terminal, { size: 11 }), _jsx("span", { children: cmd })] }, cmd))), _jsxs("button", { type: "button", className: "sandbox-command-chip is-clear", disabled: channelMessages.length === 0, onClick: clearMessages, title: sandboxText(locale, "清空当前会话"), children: [_jsx(Trash2, { size: 11 }), _jsx("span", { children: locale === 'en' ? 'Clear' : '清屏' })] })] }), _jsx("div", { className: "sandbox-toolbar-spacer" }), _jsxs("div", { className: "sandbox-composer-tabs", role: "tablist", "aria-label": sandboxText(locale, "消息编辑模式"), children: [_jsx("button", { type: "button", role: "tab", "aria-selected": composerMode === 'write', className: cn(composerMode === 'write' && 'active'), onClick: () => setComposerMode('write'), children: sandboxText(locale, "编写") }), _jsx("button", { type: "button", role: "tab", "aria-selected": composerMode === 'preview', className: cn(composerMode === 'preview' && 'active'), onClick: () => setComposerMode('preview'), children: sandboxText(locale, "预览") })] }), inputText && (_jsx("button", { type: "button", className: "sandbox-tool-button", onClick: () => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write'); }, "aria-label": sandboxText(locale, "清空输入"), children: _jsx(X, { size: 16 }) }))] }), showFacePicker && (_jsxs("div", { className: "sandbox-panel", children: [_jsx("input", { value: faceSearchQuery, onChange: (e) => setFaceSearchQuery(e.target.value), placeholder: sandboxText(locale, "搜索表情..."), className: "sandbox-input" }), _jsx("div", { className: "sandbox-face-grid", children: filteredFaces.slice(0, 80).map((face) => (_jsx("button", { onClick: () => insertFace(face.id), title: face.name, className: "sandbox-face-button", type: "button", children: _jsx("img", { src: `https://face.viki.moe/apng/${face.id}.png`, alt: face.name, className: "sandbox-face-img" }) }, face.id))) }), filteredFaces.length === 0 && (_jsxs("div", { className: "sandbox-empty-hint", children: [_jsx(Search, { size: 28 }), _jsx("span", { children: sandboxText(locale, "未找到匹配的表情") })] }))] })), mediaPanel && (_jsxs("div", { className: "sandbox-panel", children: [_jsxs("p", { className: "sandbox-panel-hint", children: [mediaPanel === 'image' && sandboxText(locale, "支持 http(s) 图片链接或 data URL"), mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)"), mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")] }), _jsx("input", { value: mediaUrl, onChange: (e) => setMediaUrl(e.target.value), placeholder: mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…"), className: "sandbox-input", onKeyDown: (e) => { if (e.key === 'Enter') {
|
|
882
950
|
e.preventDefault();
|
|
883
951
|
commitMediaUrl();
|
|
884
952
|
} } }), _jsxs("button", { type: "button", className: "sandbox-submit", onClick: commitMediaUrl, disabled: !mediaUrl.trim(), children: [_jsx(Check, { size: 14 }), " ", sandboxText(locale, "插入到输入框")] })] })), _jsxs("div", { className: "sandbox-editor-row", children: [_jsxs("div", { className: "sandbox-editor-wrap", children: [_jsx("div", { hidden: composerMode !== 'write', children: _jsx(RichTextEditor, { locale: locale, ref: editorRef, placeholder: sandboxText(locale, "向 {0} 发送消息,支持 Markdown...", [activeChannel.name]), onSend: handleSendMessage, onChange: handleEditorChange, onAtTrigger: handleAtTrigger, minHeight: "44px", maxHeight: "200px" }) }), composerMode === 'preview' && (_jsx("div", { className: "sandbox-markdown-preview", role: "tabpanel", children: inputText.trim()
|
|
885
953
|
? _jsx(MarkdownContent, { text: inputText })
|
|
886
954
|
: _jsx("span", { className: "sandbox-markdown-preview-empty", children: sandboxText(locale, "输入 Markdown 后可在这里检查最终效果") }) })), atPopoverPosition && (_jsx("div", { className: "sandbox-at-popover", style: { top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }, children: filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (_jsxs("div", { className: "sandbox-at-item", onClick: () => selectAtUser(user), children: [_jsx(User, { size: 16 }), _jsxs("div", { children: [_jsx("div", { className: "sandbox-at-name", children: user.name }), _jsxs("div", { className: "sandbox-at-id", children: ["ID: ", user.id] })] })] }, user.id))) : (_jsxs("div", { className: "sandbox-empty-hint", children: [_jsx(Search, { size: 20 }), _jsx("span", { children: sandboxText(locale, "未找到匹配的用户") })] })) }))] }), _jsxs("button", { type: "button", className: "sandbox-send", onClick: () => { const c = editorRef.current?.getContent(); if (c)
|
|
887
|
-
handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("
|
|
955
|
+
handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("details", { className: "sandbox-hints", children: [_jsxs("summary", { children: [_jsx(Keyboard, { size: 12 }), " ", sandboxText(locale, "快捷操作与语法")] }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "Enter" }), " ", sandboxText(locale, "发送")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "Shift+Enter" }), " ", sandboxText(locale, "换行")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "```ts" }), " ", sandboxText(locale, "代码块")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人")] }), _jsxs("li", { children: [_jsxs("span", { className: "sandbox-hint-key", children: ["[@", endpointId, "]"] }), " ", sandboxText(locale, "@机器人(群聊里唤起机器人,也可点 @ 按钮插入)")] }), _jsxs("li", { children: [_jsx("span", { className: "sandbox-hint-key", children: "[image:URL]" }), " ", _jsx("span", { className: "sandbox-hint-key", children: "[video:URL]" }), " ", _jsx("span", { className: "sandbox-hint-key", children: "[audio:URL]" }), " ", sandboxText(locale, "媒体")] }), commandHints && _jsxs("li", { children: [_jsx(Terminal, { size: 11 }), " ", commandHints.prefix
|
|
956
|
+
? sandboxText(locale, "命令以 {0} 开头", [commandHints.prefix])
|
|
957
|
+
: sandboxText(locale, "命令无需前缀")] })] })] })] })] }), _jsxs("aside", { id: "sandbox-run-inspector", className: cn("agent-playground-inspector", showInspector && "show"), hidden: !showInspector, "aria-hidden": !showInspector, "aria-label": sandboxText(locale, "运行检查器"), children: [_jsxs("div", { className: "agent-playground-inspector-head", children: [_jsxs("div", { children: [_jsx("span", { children: "Run inspector" }), _jsx("h2", { children: sandboxText(locale, "运行检查器") })] }), _jsxs("div", { children: [_jsx("button", { type: "button", onClick: () => void loadTrace(), "aria-label": sandboxText(locale, "刷新 Agent Trace"), disabled: traceLoading, children: _jsx(RefreshCw, { size: 15, className: cn(traceLoading && 'is-spinning') }) }), _jsx("button", { type: "button", className: "agent-playground-inspector-close", onClick: () => setShowInspector(false), "aria-label": sandboxText(locale, "关闭运行检查器"), children: _jsx(X, { size: 15 }) })] })] }), _jsxs("div", { className: "agent-playground-inspector-tabs", role: "tablist", "aria-label": sandboxText(locale, "检查器视图"), children: [_jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'runs', className: cn(inspectorView === 'runs' && 'active'), onClick: () => setInspectorView('runs'), children: [_jsx(Activity, { size: 13 }), sandboxText(locale, "任务")] }), _jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'artifacts', className: cn(inspectorView === 'artifacts' && 'active'), onClick: () => setInspectorView('artifacts'), children: [_jsx(FileDiff, { size: 13 }), sandboxText(locale, "变更与产物"), _jsx("span", { children: workbenchArtifacts.length })] })] }), _jsxs("div", { className: "agent-playground-inspector-view", hidden: inspectorView !== 'runs', children: [_jsxs("section", { className: "agent-playground-inspector-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "运行概览") }), _jsx("small", { children: traceSummary.activeTurns > 0 ? 'live' : 'idle' })] }), _jsxs("div", { className: "agent-playground-metrics", children: [_jsxs("div", { children: [_jsx(Activity, {}), _jsx("strong", { children: traceSummary.eventCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "事件") })] }), _jsxs("div", { children: [_jsx(Wrench, {}), _jsx("strong", { children: traceSummary.toolCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "工具") })] }), _jsxs("div", { children: [_jsx(Coins, {}), _jsx("strong", { children: traceSummary.tokenCount.toLocaleString(locale) }), _jsx("span", { children: "Token" })] }), _jsxs("div", { className: cn(traceSummary.problemCount > 0 && 'has-problem'), children: [_jsx(CircleAlert, {}), _jsx("strong", { children: traceSummary.problemCount }), _jsx("span", { children: sandboxText(locale, "异常") })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section", children: [_jsx("div", { className: "agent-playground-inspector-title", children: _jsx("span", { children: sandboxText(locale, "上下文") }) }), _jsxs("dl", { className: "agent-playground-context-list", children: [_jsxs("div", { children: [_jsx("dt", { children: "Endpoint" }), _jsx("dd", { children: endpointId })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scope" }), _jsx("dd", { children: activeChannel.type })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scene" }), _jsx("dd", { children: activeChannel.id })] }), _jsxs("div", { children: [_jsx("dt", { children: "Workdir" }), _jsx("dd", { title: activeChannel.runConfig.workingDirectory, children: activeChannel.runConfig.workingDirectory || 'Host project root' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Security" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Approval" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Network" }), _jsx("dd", { children: activeChannel.runConfig.networkAccess ? 'enabled' : 'disabled' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Isolation" }), _jsx("dd", { className: cn(shellIsolation?.available && 'is-online'), children: shellIsolation ? `${shellIsolation.provider}: ${shellIsolation.available ? 'ready' : 'unavailable'}` : 'checking' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Transport" }), _jsx("dd", { className: cn(connected && 'is-online'), children: connected ? 'WebSocket online' : 'reconnecting' })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-task-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "任务历史") }), _jsxs("small", { children: [taskRuns.length, " runs"] })] }), taskRuns.length > 0 ? (_jsx("div", { className: "agent-playground-task-list", children: taskRuns.slice(0, 8).map((run) => (_jsxs("article", { className: cn(`is-${run.status}`), children: [_jsx("i", {}), _jsxs("div", { children: [_jsx("strong", { children: taskStatusLabel(run.status, locale) }), _jsx("code", { children: run.turnId.slice(0, 10) })] }), _jsxs("dl", { children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: run.durationMs === undefined ? sandboxText(locale, "进行中") : `${run.durationMs.toLocaleString(locale)} ms` })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: run.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: run.tokenCount.toLocaleString(locale) })] })] })] }, run.id))) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "运行任务后会在这里形成可回溯记录") })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-trace-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "最近执行") }), _jsx("small", { children: "2s sync" })] }), traceNotice && _jsxs("div", { className: "agent-playground-trace-notice", role: "alert", children: [_jsx(CircleAlert, { size: 16 }), _jsx("span", { children: traceNotice })] }), traceLoading && !trace ? (_jsxs("div", { className: "agent-playground-trace-loading", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : recentTraceEvents.length ? (_jsx("div", { className: "agent-playground-trace-list", children: recentTraceEvents.map((event) => {
|
|
888
958
|
const item = presentTraceEvent(event, locale);
|
|
889
959
|
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
960
|
}) })) : (_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 +974,10 @@ function taskStatusLabel(status, locale = 'zh-CN') {
|
|
|
904
974
|
}
|
|
905
975
|
function messageText(segments) {
|
|
906
976
|
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
|
-
}
|
|
977
|
+
const data = (segment.data ?? {});
|
|
911
978
|
if (segment.type === 'mention' || segment.type === 'at')
|
|
912
979
|
return `@${String(data.name ?? data.target ?? '')}`;
|
|
913
|
-
return
|
|
980
|
+
return segmentPreviewText(segment);
|
|
914
981
|
}).join(' ').trim();
|
|
915
982
|
}
|
|
916
983
|
function formatDuration(durationMs, locale = 'zh-CN') {
|