@zhin.js/adapter-sandbox 1.1.19 → 1.1.21
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 +69 -0
- package/README.md +55 -7
- package/adapters/sandbox/index.js +3 -12
- package/adapters/sandbox/index.ts +2 -12
- package/lib/adapter.d.ts +17 -0
- package/lib/adapter.js +17 -0
- package/lib/client.d.ts +7 -14
- package/lib/client.js +12 -11
- package/lib/endpoint.d.ts +16 -13
- package/lib/endpoint.js +171 -138
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/protocol.d.ts +22 -1
- package/lib/protocol.js +34 -4
- package/package.json +18 -18
- package/pages/index/ConversationRecoveryPanel.js +131 -0
- package/pages/index/ConversationRecoveryPanel.tsx +134 -0
- package/pages/index/SandboxChat.js +319 -111
- package/pages/index/SandboxChat.tsx +356 -126
- package/pages/index/agentTrace.js +21 -10
- package/pages/index/agentTrace.ts +24 -10
- package/pages/index/conversationRecovery.js +40 -0
- package/pages/index/conversationRecovery.ts +68 -0
- package/pages/index/index.js +5 -5
- package/pages/index/index.tsx +5 -5
- package/pages/index/messages.js +24 -6
- package/pages/index/messages.ts +24 -6
- package/pages/index/playgroundState.js +51 -1
- package/pages/index/playgroundState.ts +61 -1
- package/pages/index/sandboxTransport.js +25 -0
- package/pages/index/sandboxTransport.ts +35 -0
- package/pages/index/useSandboxHistory.js +161 -0
- package/pages/index/useSandboxHistory.ts +164 -0
- package/pages/index/workspaceDirectory.js +49 -0
- package/pages/index/workspaceDirectory.ts +74 -0
- package/pages/index/workspaceDirectoryState.js +120 -0
- package/pages/index/workspaceDirectoryState.ts +124 -0
- package/src/adapter.ts +22 -0
- package/src/client.ts +16 -18
- package/src/endpoint.ts +179 -140
- package/src/index.ts +1 -1
- package/src/protocol.ts +59 -13
|
@@ -3,16 +3,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { sandboxText } from './messages.js';
|
|
4
4
|
import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
|
5
5
|
import { cn, CodeBlock, MarkdownContent, resolveMediaSrc, pickMediaRawUrl, } from '@zhin.js/client';
|
|
6
|
-
import { buildSandboxWebSocketUrl } from './sandboxTransport';
|
|
6
|
+
import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL } from './sandboxTransport';
|
|
7
|
+
import { createWorkspaceDirectoryController } from './workspaceDirectoryState.js';
|
|
7
8
|
import { User, Bot, Users, Trash2, Send, Hash, MessageSquare, Wifi, WifiOff, Smile, Image, X, Check, Info, Search, Video, Music, Plus, PanelRight, ExternalLink, RefreshCw, Sparkles, Activity, Wrench, Coins, CircleAlert, Gauge, SlidersHorizontal, FolderOpen, ShieldCheck, Network, Square, RotateCcw, FileDiff, Terminal, FlaskConical, ChevronDown, FileDown, ListChecks, } from 'lucide-react';
|
|
8
9
|
import RichTextEditor, {} from './RichTextEditor';
|
|
9
10
|
import HtmlMessage from './HtmlMessage.js';
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import ConversationRecoveryPanel from './ConversationRecoveryPanel.js';
|
|
12
|
+
import { useSandboxHistory } from './useSandboxHistory.js';
|
|
13
|
+
import { agentSessionsPath, buildAgentRunReport, buildSandboxSessionKey, cancelAgentTask, deriveAgentRunSteps, deriveTaskRuns, deriveWorkbenchArtifacts, fetchAgentTrace, loadCachedAgentTrace, mergeTraceSnapshot, presentTraceEvent, summarizeTrace, saveCachedAgentTrace, } from './agentTrace.js';
|
|
14
|
+
import { createDefaultPlaygroundState, loadPlaygroundState, savePlaygroundState, mergePlaygroundMessage, retirePlaygroundInteractions, } from './playgroundState.js';
|
|
15
|
+
export default function Sandbox(props = {}) {
|
|
13
16
|
const [locale, setLocale] = useState('zh-CN');
|
|
14
17
|
const localeRef = useRef('zh-CN');
|
|
15
|
-
const [initialState] = useState(() =>
|
|
18
|
+
const [initialState] = useState(() => createDefaultPlaygroundState());
|
|
16
19
|
const [messages, setMessages] = useState(() => [...initialState.messages]);
|
|
17
20
|
const [channels, setChannels] = useState(() => [...initialState.sessions]);
|
|
18
21
|
const [faceList, setFaceList] = useState([]);
|
|
@@ -22,8 +25,10 @@ export default function Sandbox() {
|
|
|
22
25
|
const [inputText, setInputText] = useState('');
|
|
23
26
|
const [endpointId, setBotName] = useState('sandbox-bot');
|
|
24
27
|
const [connected, setConnected] = useState(false);
|
|
25
|
-
const [canExecute, setCanExecute] = useState(
|
|
28
|
+
const [canExecute, setCanExecute] = useState(false);
|
|
26
29
|
const [persistenceStatus, setPersistenceStatus] = useState('saved');
|
|
30
|
+
const [directoryStatus, setDirectoryStatus] = useState({ mode: 'loading', error: null });
|
|
31
|
+
const [workspaceScope, setWorkspaceScope] = useState(null);
|
|
27
32
|
const [transportNotice, setTransportNotice] = useState(null);
|
|
28
33
|
const [shellIsolation, setShellIsolation] = useState(null);
|
|
29
34
|
const [inspectorView, setInspectorView] = useState('runs');
|
|
@@ -45,6 +50,8 @@ export default function Sandbox() {
|
|
|
45
50
|
const [composerMode, setComposerMode] = useState('write');
|
|
46
51
|
const [showChannelList, setShowChannelList] = useState(false);
|
|
47
52
|
const [showInspector, setShowInspector] = useState(false);
|
|
53
|
+
const [showConversationDetails, setShowConversationDetails] = useState(false);
|
|
54
|
+
const [pendingRefreshEpoch, setPendingRefreshEpoch] = useState(0);
|
|
48
55
|
const [showRunSettings, setShowRunSettings] = useState(false);
|
|
49
56
|
const [showNewSession, setShowNewSession] = useState(false);
|
|
50
57
|
const [newSessionName, setNewSessionName] = useState('');
|
|
@@ -53,13 +60,87 @@ export default function Sandbox() {
|
|
|
53
60
|
const [trace, setTrace] = useState(null);
|
|
54
61
|
const [traceLoading, setTraceLoading] = useState(true);
|
|
55
62
|
const [traceNotice, setTraceNotice] = useState(null);
|
|
63
|
+
const [cancellationFeedback, setCancellationFeedback] = useState(null);
|
|
56
64
|
const messagesEndRef = useRef(null);
|
|
57
65
|
const wsRef = useRef(null);
|
|
66
|
+
const connectionRef = useRef({ canExecute: false });
|
|
58
67
|
const editorRef = useRef(null);
|
|
59
68
|
const traceRef = useRef(null);
|
|
69
|
+
const traceReadOwnerRef = useRef(null);
|
|
60
70
|
const activeChannelRef = useRef(activeChannel);
|
|
61
71
|
const endpointIdRef = useRef(endpointId);
|
|
72
|
+
const directoryModeRef = useRef(directoryStatus.mode);
|
|
73
|
+
const directoryHostRef = useRef(null);
|
|
74
|
+
const readyWorkingDirectoryRef = useRef('');
|
|
75
|
+
const readyIdentityRef = useRef(null);
|
|
76
|
+
const socketRequestContextRef = useRef(null);
|
|
77
|
+
const directoryControllerRef = useRef(null);
|
|
78
|
+
if (!directoryControllerRef.current)
|
|
79
|
+
directoryControllerRef.current = createWorkspaceDirectoryController({
|
|
80
|
+
loaded: (directory, sameScope) => {
|
|
81
|
+
const fallback = directory ? createDefaultPlaygroundState(readyWorkingDirectoryRef.current) : loadPlaygroundState();
|
|
82
|
+
const sessions = directory?.items.length
|
|
83
|
+
? directory.items.map((item) => ({ id: item.id, type: item.type, name: item.name, runConfig: item.runConfig, unread: 0 }))
|
|
84
|
+
: [...fallback.sessions];
|
|
85
|
+
const previous = activeChannelRef.current;
|
|
86
|
+
if (sameScope && !sessions.some((session) => session.id === previous.id && session.type === previous.type))
|
|
87
|
+
sessions.push(previous);
|
|
88
|
+
const selected = sameScope
|
|
89
|
+
? sessions.find((session) => session.id === previous.id && session.type === previous.type)
|
|
90
|
+
: sessions.find((session) => session.id === fallback.activeSessionId && session.type === fallback.activeSessionType) ?? sessions[0];
|
|
91
|
+
activeChannelRef.current = selected;
|
|
92
|
+
setActiveChannel(selected);
|
|
93
|
+
if (!sameScope)
|
|
94
|
+
setMessages(directory ? [] : [...fallback.messages]);
|
|
95
|
+
setChannels(sessions);
|
|
96
|
+
setWorkspaceScope(directory?.scope ?? null);
|
|
97
|
+
subscribeToScene(selected);
|
|
98
|
+
},
|
|
99
|
+
status: (status) => {
|
|
100
|
+
directoryModeRef.current = status.mode;
|
|
101
|
+
setDirectoryStatus(status);
|
|
102
|
+
if (status.error)
|
|
103
|
+
setPersistenceStatus('error');
|
|
104
|
+
else if (status.mode === 'server')
|
|
105
|
+
setPersistenceStatus('saved');
|
|
106
|
+
},
|
|
107
|
+
});
|
|
62
108
|
const sessionKey = useMemo(() => buildSandboxSessionKey(endpointId, activeChannel.type, activeChannel.id), [activeChannel.id, activeChannel.type, endpointId]);
|
|
109
|
+
const history = useSandboxHistory(canExecute && directoryStatus.mode === 'server' && workspaceScope
|
|
110
|
+
&& workspaceScope.connectionId === connectionRef.current.connectionId ? {
|
|
111
|
+
connectionId: workspaceScope.connectionId, sessionKey, scope: workspaceScope.endpoint,
|
|
112
|
+
scene: { id: activeChannel.id, type: activeChannel.type, name: activeChannel.name },
|
|
113
|
+
ownerId: workspaceScope.ownerId, requestContext: socketRequestContextRef.current ?? undefined,
|
|
114
|
+
} : undefined, setMessages, locale);
|
|
115
|
+
const retireTraceReads = () => {
|
|
116
|
+
const owner = traceReadOwnerRef.current;
|
|
117
|
+
traceReadOwnerRef.current = null;
|
|
118
|
+
owner?.controller.abort();
|
|
119
|
+
if (owner?.cancelRefresh !== undefined)
|
|
120
|
+
window.clearTimeout(owner.cancelRefresh);
|
|
121
|
+
traceRef.current = null;
|
|
122
|
+
};
|
|
123
|
+
const currentTraceOwner = () => {
|
|
124
|
+
const scene = activeChannelRef.current;
|
|
125
|
+
const key = buildSandboxSessionKey(endpointIdRef.current, scene.type, scene.id);
|
|
126
|
+
let owner = traceReadOwnerRef.current;
|
|
127
|
+
if (!owner || owner.sessionKey !== key || owner.socket !== wsRef.current) {
|
|
128
|
+
retireTraceReads();
|
|
129
|
+
owner = { sessionKey: key, socket: wsRef.current, controller: new AbortController() };
|
|
130
|
+
traceReadOwnerRef.current = owner;
|
|
131
|
+
setTrace(null);
|
|
132
|
+
setTraceNotice(null);
|
|
133
|
+
setCancellationFeedback(null);
|
|
134
|
+
setStoppingTask(false);
|
|
135
|
+
}
|
|
136
|
+
return owner;
|
|
137
|
+
};
|
|
138
|
+
const ownsCurrentTrace = (owner) => {
|
|
139
|
+
const scene = activeChannelRef.current;
|
|
140
|
+
return traceReadOwnerRef.current === owner && !owner.controller.signal.aborted
|
|
141
|
+
&& owner.socket === wsRef.current
|
|
142
|
+
&& owner.sessionKey === buildSandboxSessionKey(endpointIdRef.current, scene.type, scene.id);
|
|
143
|
+
};
|
|
63
144
|
const traceSummary = useMemo(() => summarizeTrace(trace), [trace]);
|
|
64
145
|
const taskRuns = useMemo(() => deriveTaskRuns(trace), [trace]);
|
|
65
146
|
const workbenchArtifacts = useMemo(() => deriveWorkbenchArtifacts(trace, locale), [trace, locale]);
|
|
@@ -71,13 +152,15 @@ export default function Sandbox() {
|
|
|
71
152
|
useEffect(() => { setInlineRunExpanded(currentTask?.status === 'running'); }, [currentTask?.id]);
|
|
72
153
|
useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [currentTask?.id]);
|
|
73
154
|
useEffect(() => {
|
|
155
|
+
if (directoryModeRef.current !== 'browser')
|
|
156
|
+
return;
|
|
74
157
|
setPersistenceStatus(savePlaygroundState({
|
|
75
158
|
activeSessionId: activeChannel.id,
|
|
76
159
|
activeSessionType: activeChannel.type,
|
|
77
160
|
sessions: channels,
|
|
78
161
|
messages,
|
|
79
162
|
}) ? 'saved' : 'error');
|
|
80
|
-
}, [activeChannel.id, channels, messages]);
|
|
163
|
+
}, [activeChannel.id, channels, messages, directoryStatus.mode]);
|
|
81
164
|
const fetchFaceList = async () => {
|
|
82
165
|
try {
|
|
83
166
|
const res = await fetch('https://face.viki.moe/metadata.json');
|
|
@@ -88,12 +171,33 @@ export default function Sandbox() {
|
|
|
88
171
|
}
|
|
89
172
|
};
|
|
90
173
|
useEffect(() => { fetchFaceList(); }, []);
|
|
174
|
+
const subscribeToScene = (scene) => {
|
|
175
|
+
// Old Hosts parse unknown JSON as chat, so control frames require this explicit handshake.
|
|
176
|
+
if (connectionRef.current.protocol !== SANDBOX_SCOPED_PROTOCOL || !connectionRef.current.canExecute)
|
|
177
|
+
return;
|
|
178
|
+
if (!submitSandboxFrame(wsRef.current, { op: 'subscribe', conversation: { type: scene.type, id: scene.id } })) {
|
|
179
|
+
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,会话切换未发送。"));
|
|
180
|
+
}
|
|
181
|
+
};
|
|
91
182
|
const handleInboundPayload = (data) => {
|
|
92
183
|
const locale = data.type === 'ready' && data.locale === 'en' ? 'en' : data.type === 'ready' ? 'zh-CN' : localeRef.current;
|
|
93
184
|
if (data.type === 'ready') {
|
|
94
185
|
localeRef.current = locale;
|
|
95
186
|
setLocale(locale);
|
|
96
|
-
|
|
187
|
+
const requestContext = socketRequestContextRef.current ?? captureSandboxRequestContext();
|
|
188
|
+
const host = requestContext.apiBase || window.location.origin;
|
|
189
|
+
const previousIdentity = readyIdentityRef.current;
|
|
190
|
+
if (previousIdentity && (previousIdentity.host !== host || previousIdentity.ownerId !== data.id)) {
|
|
191
|
+
const fresh = createDefaultPlaygroundState(data.workingDirectory?.trim());
|
|
192
|
+
activeChannelRef.current = fresh.sessions[0];
|
|
193
|
+
setActiveChannel(fresh.sessions[0]);
|
|
194
|
+
setChannels([...fresh.sessions]);
|
|
195
|
+
setMessages([]);
|
|
196
|
+
}
|
|
197
|
+
readyIdentityRef.current = { host, ownerId: data.id };
|
|
198
|
+
endpointIdRef.current = data.endpoint || data.bot || 'sandbox-bot';
|
|
199
|
+
setBotName(endpointIdRef.current);
|
|
200
|
+
connectionRef.current = { protocol: data.protocol, connectionId: data.connectionId, ownerId: data.id, canExecute: data.canExecute !== false };
|
|
97
201
|
setCanExecute(data.canExecute !== false);
|
|
98
202
|
setTransportNotice(data.canExecute === false ? sandboxText(locale, "当前 Token 只有演示权限,任务运行已禁用。") : null);
|
|
99
203
|
if (data.shellIsolation) {
|
|
@@ -103,18 +207,15 @@ export default function Sandbox() {
|
|
|
103
207
|
message: data.shellIsolation.message || sandboxText(locale, "未检测到隔离执行环境"),
|
|
104
208
|
});
|
|
105
209
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
? session
|
|
110
|
-
: { ...session, runConfig: { ...session.runConfig, workingDirectory } }));
|
|
111
|
-
setActiveChannel((current) => current.runConfig.workingDirectory
|
|
112
|
-
? current
|
|
113
|
-
: { ...current, runConfig: { ...current.runConfig, workingDirectory } });
|
|
114
|
-
}
|
|
210
|
+
readyWorkingDirectoryRef.current = data.workingDirectory?.trim() ?? '';
|
|
211
|
+
void directoryControllerRef.current.begin({ host,
|
|
212
|
+
connectionId: data.connectionId, canExecute: data.canExecute !== false, requestContext });
|
|
115
213
|
return;
|
|
116
214
|
}
|
|
215
|
+
if (data.type === 'subscribed')
|
|
216
|
+
return;
|
|
117
217
|
if (data.type === 'error') {
|
|
218
|
+
setPendingRefreshEpoch((epoch) => epoch + 1);
|
|
118
219
|
const notice = Array.isArray(data.content)
|
|
119
220
|
? String(data.content[0]?.data?.text ?? sandboxText(locale, "Sandbox 拒绝了本次操作"))
|
|
120
221
|
: String(data.content ?? sandboxText(locale, "Sandbox 拒绝了本次操作"));
|
|
@@ -125,59 +226,66 @@ export default function Sandbox() {
|
|
|
125
226
|
const content = Array.isArray(data.content)
|
|
126
227
|
? data.content
|
|
127
228
|
: parseTextToSegments(String(data.content ?? ''));
|
|
128
|
-
|
|
229
|
+
const scene = data.conversation ?? activeChannelRef.current;
|
|
230
|
+
if (!data.conversation && data.id && data.id !== scene.id)
|
|
231
|
+
return;
|
|
232
|
+
setMessages((prev) => prev.map((message) => message.id === data.messageId
|
|
233
|
+
&& message.channelType === scene.type && message.channelId === scene.id && message.type === 'received'
|
|
234
|
+
? { ...message, content } : message));
|
|
129
235
|
return;
|
|
130
236
|
}
|
|
237
|
+
// A received message invalidates the projection; only Core decides whether a claim remains live.
|
|
238
|
+
setPendingRefreshEpoch((epoch) => epoch + 1);
|
|
131
239
|
const content = typeof data.content === 'string'
|
|
132
240
|
? parseTextToSegments(data.content)
|
|
133
241
|
: Array.isArray(data.content) ? data.content : parseTextToSegments(String(data.content ?? ''));
|
|
134
|
-
const channelType = data.type === 'group' || data.type === 'channel' ? data.type : 'private';
|
|
242
|
+
const channelType = data.conversation?.type ?? (data.type === 'group' || data.type === 'channel' ? data.type : 'private');
|
|
243
|
+
const sceneId = data.conversation?.id ?? data.id;
|
|
244
|
+
const isInput = data.direction === 'inbound';
|
|
245
|
+
// Interactive choices are transport inputs, not another chat turn or an approval result.
|
|
246
|
+
if (isInput && content.every((segment) => segment.type === 'action'))
|
|
247
|
+
return;
|
|
135
248
|
const channelName = channelType === 'private'
|
|
136
|
-
? sandboxText(locale, "会话 {0}", [
|
|
249
|
+
? sandboxText(locale, "会话 {0}", [sceneId])
|
|
137
250
|
: channelType === 'group'
|
|
138
|
-
? sandboxText(locale, "群组场景 {0}", [
|
|
139
|
-
: sandboxText(locale, "频道场景 {0}", [
|
|
251
|
+
? sandboxText(locale, "群组场景 {0}", [sceneId])
|
|
252
|
+
: sandboxText(locale, "频道场景 {0}", [sceneId]);
|
|
140
253
|
setChannels((prev) => {
|
|
141
|
-
if (prev.some((c) => c.id ===
|
|
254
|
+
if (prev.some((c) => c.id === sceneId && c.type === channelType))
|
|
142
255
|
return prev;
|
|
143
256
|
const created = {
|
|
144
|
-
id:
|
|
257
|
+
id: sceneId, name: channelName, type: channelType, unread: 0,
|
|
145
258
|
runConfig: { ...activeChannelRef.current.runConfig },
|
|
146
259
|
};
|
|
260
|
+
activeChannelRef.current = created;
|
|
147
261
|
setActiveChannel(created);
|
|
148
262
|
return [...prev, created];
|
|
149
263
|
});
|
|
150
|
-
setMessages((prev) =>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
264
|
+
setMessages((prev) => mergePlaygroundMessage(prev, {
|
|
265
|
+
id: data.messageId ?? createSandboxMessageId(), type: isInput ? 'sent' : 'received', channelType,
|
|
266
|
+
interactionReadOnly: false,
|
|
267
|
+
channelId: sceneId, channelName, senderId: isInput ? data.senderId || connectionRef.current.ownerId || 'owner' : 'endpoint',
|
|
268
|
+
senderName: isInput ? sandboxText(locale, "当前用户") : data.bot || endpointIdRef.current, content, timestamp: data.timestamp,
|
|
269
|
+
}));
|
|
155
270
|
};
|
|
156
271
|
const sendInteractiveAction = (payload, messageId) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
272
|
+
if (!connectionRef.current.canExecute)
|
|
273
|
+
return false;
|
|
274
|
+
const scene = activeChannelRef.current;
|
|
162
275
|
const segments = [{ type: 'action', data: { id: payload, payload } }];
|
|
163
|
-
|
|
164
|
-
type:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
170
|
-
try {
|
|
171
|
-
ws.send(payloadJson);
|
|
172
|
-
if (messageId) {
|
|
173
|
-
setMessages((current) => current.map((message) => message.id === messageId
|
|
174
|
-
? { ...message, interactionResolved: true }
|
|
175
|
-
: message));
|
|
176
|
-
}
|
|
276
|
+
if (!submitSandboxFrame(wsRef.current, {
|
|
277
|
+
type: scene.type, id: scene.id, messageId: createSandboxMessageId(), content: segments,
|
|
278
|
+
agentRun: scene.runConfig, timestamp: Date.now(),
|
|
279
|
+
})) {
|
|
280
|
+
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,审批选择未发送。"));
|
|
281
|
+
return false;
|
|
177
282
|
}
|
|
178
|
-
|
|
179
|
-
|
|
283
|
+
if (messageId) {
|
|
284
|
+
setMessages((current) => current.map((message) => message.id === messageId
|
|
285
|
+
&& message.channelType === scene.type && message.channelId === scene.id && message.type === 'received'
|
|
286
|
+
? { ...message, interactionResolved: true } : message));
|
|
180
287
|
}
|
|
288
|
+
return true;
|
|
181
289
|
};
|
|
182
290
|
useEffect(() => {
|
|
183
291
|
let closed = false;
|
|
@@ -188,13 +296,30 @@ export default function Sandbox() {
|
|
|
188
296
|
const connect = () => {
|
|
189
297
|
if (closed)
|
|
190
298
|
return;
|
|
299
|
+
retireTraceReads();
|
|
300
|
+
directoryControllerRef.current?.retire();
|
|
301
|
+
directoryModeRef.current = 'loading';
|
|
302
|
+
setDirectoryStatus({ mode: 'loading', error: null });
|
|
303
|
+
setWorkspaceScope(null);
|
|
304
|
+
const requestContext = captureSandboxRequestContext();
|
|
305
|
+
const nextHost = requestContext.apiBase || window.location.origin;
|
|
306
|
+
if (directoryHostRef.current !== nextHost) {
|
|
307
|
+
const fresh = createDefaultPlaygroundState();
|
|
308
|
+
activeChannelRef.current = fresh.sessions[0];
|
|
309
|
+
setActiveChannel(fresh.sessions[0]);
|
|
310
|
+
setChannels([...fresh.sessions]);
|
|
311
|
+
setMessages([]);
|
|
312
|
+
}
|
|
313
|
+
directoryHostRef.current = nextHost;
|
|
191
314
|
if (retryTimer) {
|
|
192
315
|
clearTimeout(retryTimer);
|
|
193
316
|
retryTimer = undefined;
|
|
194
317
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
318
|
+
connectionRef.current = { canExecute: false };
|
|
319
|
+
setCanExecute(false);
|
|
320
|
+
setConnected(false);
|
|
321
|
+
const wsUrl = buildSandboxWebSocketUrl(nextHost);
|
|
322
|
+
// This page owns one connection; replacing its credentials must retire only that socket.
|
|
198
323
|
const previous = wsRef.current;
|
|
199
324
|
if (previous) {
|
|
200
325
|
replaceInFlight = true;
|
|
@@ -209,12 +334,18 @@ export default function Sandbox() {
|
|
|
209
334
|
replaceInFlight = false;
|
|
210
335
|
}
|
|
211
336
|
const ws = new WebSocket(wsUrl);
|
|
337
|
+
socketRequestContextRef.current = requestContext;
|
|
212
338
|
wsRef.current = ws;
|
|
339
|
+
void loadTrace();
|
|
213
340
|
ws.onopen = () => {
|
|
341
|
+
if (wsRef.current !== ws)
|
|
342
|
+
return;
|
|
214
343
|
attempt = 0;
|
|
215
344
|
setConnected(true);
|
|
216
345
|
};
|
|
217
346
|
ws.onmessage = (event) => {
|
|
347
|
+
if (wsRef.current !== ws)
|
|
348
|
+
return;
|
|
218
349
|
try {
|
|
219
350
|
handleInboundPayload(JSON.parse(String(event.data)));
|
|
220
351
|
}
|
|
@@ -225,7 +356,14 @@ export default function Sandbox() {
|
|
|
225
356
|
ws.onclose = () => {
|
|
226
357
|
if (wsRef.current !== ws)
|
|
227
358
|
return;
|
|
359
|
+
retireTraceReads();
|
|
360
|
+
directoryControllerRef.current?.retire();
|
|
361
|
+
directoryModeRef.current = 'loading';
|
|
362
|
+
setDirectoryStatus({ mode: 'loading', error: null });
|
|
363
|
+
setWorkspaceScope(null);
|
|
228
364
|
setConnected(false);
|
|
365
|
+
setCanExecute(false);
|
|
366
|
+
connectionRef.current = { canExecute: false };
|
|
229
367
|
wsRef.current = null;
|
|
230
368
|
if (closed || replaceInFlight)
|
|
231
369
|
return;
|
|
@@ -263,6 +401,8 @@ export default function Sandbox() {
|
|
|
263
401
|
}
|
|
264
402
|
return () => {
|
|
265
403
|
closed = true;
|
|
404
|
+
retireTraceReads();
|
|
405
|
+
directoryControllerRef.current?.retire();
|
|
266
406
|
if (retryTimer)
|
|
267
407
|
clearTimeout(retryTimer);
|
|
268
408
|
if (typeof window !== 'undefined') {
|
|
@@ -273,38 +413,54 @@ export default function Sandbox() {
|
|
|
273
413
|
}
|
|
274
414
|
wsRef.current?.close();
|
|
275
415
|
wsRef.current = null;
|
|
416
|
+
connectionRef.current = { canExecute: false };
|
|
417
|
+
setCanExecute(false);
|
|
276
418
|
setConnected(false);
|
|
277
419
|
};
|
|
278
420
|
}, []);
|
|
279
421
|
useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]);
|
|
280
422
|
useEffect(() => { setPreviewSegments(inputText.trim() ? parseTextToSegments(inputText) : []); }, [inputText]);
|
|
281
423
|
const loadTrace = useCallback(async (quiet = false) => {
|
|
424
|
+
const owner = currentTraceOwner();
|
|
282
425
|
const locale = localeRef.current;
|
|
283
426
|
if (!quiet)
|
|
284
427
|
setTraceLoading(true);
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
428
|
+
if (owner.pending)
|
|
429
|
+
return owner.pending;
|
|
430
|
+
owner.pending = (async () => {
|
|
431
|
+
try {
|
|
432
|
+
const current = traceRef.current?.sessionKey === owner.sessionKey ? traceRef.current : null;
|
|
433
|
+
let incoming = await fetchAgentTrace(owner.sessionKey, quiet ? current?.latestSequence ?? 0 : 0, locale, owner.controller.signal);
|
|
434
|
+
if (!ownsCurrentTrace(owner))
|
|
435
|
+
return;
|
|
436
|
+
if (quiet && current?.runtimeId && incoming.runtimeId && current.runtimeId !== incoming.runtimeId) {
|
|
437
|
+
incoming = await fetchAgentTrace(owner.sessionKey, 0, locale, owner.controller.signal);
|
|
438
|
+
if (!ownsCurrentTrace(owner))
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const baseline = traceRef.current?.sessionKey === owner.sessionKey ? traceRef.current : null;
|
|
442
|
+
const merged = mergeTraceSnapshot(baseline, incoming);
|
|
443
|
+
traceRef.current = merged;
|
|
444
|
+
setTrace(merged);
|
|
445
|
+
saveCachedAgentTrace(merged);
|
|
446
|
+
setTraceNotice(null);
|
|
290
447
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
}, [sessionKey]);
|
|
448
|
+
catch (error) {
|
|
449
|
+
if (ownsCurrentTrace(owner))
|
|
450
|
+
setTraceNotice(error instanceof Error ? error.message : sandboxText(locale, "Agent Trace 暂不可用"));
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
owner.pending = undefined;
|
|
454
|
+
if (ownsCurrentTrace(owner))
|
|
455
|
+
setTraceLoading(false);
|
|
456
|
+
}
|
|
457
|
+
})();
|
|
458
|
+
return owner.pending;
|
|
459
|
+
}, []);
|
|
305
460
|
useEffect(() => {
|
|
461
|
+
const owner = currentTraceOwner();
|
|
306
462
|
const cached = loadCachedAgentTrace(sessionKey);
|
|
307
|
-
|
|
463
|
+
// Cached display is not an incremental baseline for this connection.
|
|
308
464
|
setTrace(cached);
|
|
309
465
|
setTraceNotice(null);
|
|
310
466
|
void loadTrace();
|
|
@@ -312,8 +468,12 @@ export default function Sandbox() {
|
|
|
312
468
|
if (document.visibilityState === 'visible')
|
|
313
469
|
void loadTrace(true);
|
|
314
470
|
}, 2_000);
|
|
315
|
-
return () =>
|
|
316
|
-
|
|
471
|
+
return () => {
|
|
472
|
+
window.clearInterval(timer);
|
|
473
|
+
if (traceReadOwnerRef.current === owner)
|
|
474
|
+
retireTraceReads();
|
|
475
|
+
};
|
|
476
|
+
}, [sessionKey, loadTrace]);
|
|
317
477
|
const parseTextToSegments = (text) => {
|
|
318
478
|
const segments = [];
|
|
319
479
|
const regex = /\[@([^\]]+)\]|\[face:(\d+)\]|\[image:([^\]]+)\]|\[video:([^\]]+)\]|\[audio:([^\]]+)\]/g;
|
|
@@ -355,7 +515,7 @@ export default function Sandbox() {
|
|
|
355
515
|
return true;
|
|
356
516
|
});
|
|
357
517
|
};
|
|
358
|
-
const renderMessageSegments = (segments, isSent, messageId, interactionResolved = false) => {
|
|
518
|
+
const renderMessageSegments = (segments, isSent, messageId, interactionResolved = false, onInteractionSubmitted, allowInteraction = true) => {
|
|
359
519
|
const ring = isSent ? 'ring-1 ring-primary-foreground/25' : 'ring-1 ring-border/60';
|
|
360
520
|
return segments.map((segment, index) => {
|
|
361
521
|
if (typeof segment === 'string') {
|
|
@@ -412,53 +572,74 @@ export default function Sandbox() {
|
|
|
412
572
|
case 'keyboard': {
|
|
413
573
|
const rows = d.rows ?? [];
|
|
414
574
|
const resolved = Boolean(messageId && interactionResolved);
|
|
415
|
-
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
|
|
575
|
+
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))
|
|
576
|
+
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));
|
|
416
577
|
}
|
|
417
578
|
default:
|
|
418
579
|
return _jsxs("span", { className: "text-xs opacity-70", children: ["[", segment.type, "]"] }, index);
|
|
419
580
|
}
|
|
420
581
|
});
|
|
421
582
|
};
|
|
422
|
-
const handleSendMessage = (
|
|
423
|
-
if (!canExecute || !hasRenderableSegments(segments))
|
|
583
|
+
const handleSendMessage = (_text, segments) => {
|
|
584
|
+
if (!connectionRef.current.canExecute || directoryModeRef.current === 'loading' || !hasRenderableSegments(segments))
|
|
424
585
|
return;
|
|
425
|
-
const
|
|
426
|
-
|
|
586
|
+
const scene = activeChannelRef.current;
|
|
587
|
+
const newMessage = {
|
|
588
|
+
id: createSandboxMessageId(), type: 'sent', channelType: scene.type, channelId: scene.id,
|
|
589
|
+
channelName: scene.name, senderId: connectionRef.current.ownerId || 'test_user',
|
|
590
|
+
senderName: sandboxText(localeRef.current, "测试用户"), content: segments, timestamp: Date.now(),
|
|
591
|
+
};
|
|
592
|
+
if (!submitSandboxFrame(wsRef.current, {
|
|
593
|
+
type: scene.type, id: scene.id, messageId: newMessage.id, content: segments,
|
|
594
|
+
agentRun: scene.runConfig, timestamp: newMessage.timestamp,
|
|
595
|
+
})) {
|
|
596
|
+
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,消息未发送。"));
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
void directoryControllerRef.current?.save(scene, true);
|
|
600
|
+
setPendingRefreshEpoch((epoch) => epoch + 1);
|
|
601
|
+
setMessages((prev) => mergePlaygroundMessage(prev, newMessage));
|
|
427
602
|
setInputText('');
|
|
428
603
|
setPreviewSegments([]);
|
|
429
604
|
setComposerMode('write');
|
|
430
605
|
editorRef.current?.clear();
|
|
431
|
-
// Stamp type+id so Host sandbox endpoint preserves channel context for outbound replies.
|
|
432
|
-
const payload = JSON.stringify({
|
|
433
|
-
type: activeChannel.type,
|
|
434
|
-
id: activeChannel.id,
|
|
435
|
-
messageId: newMessage.id,
|
|
436
|
-
content: segments,
|
|
437
|
-
agentRun: activeChannel.runConfig,
|
|
438
|
-
timestamp: Date.now(),
|
|
439
|
-
});
|
|
440
|
-
wsRef.current?.send(payload);
|
|
441
606
|
};
|
|
442
607
|
const clearMessages = () => {
|
|
443
608
|
setMessages((current) => current.filter((message) => !(message.channelId === activeChannel.id && message.channelType === activeChannel.type)));
|
|
444
609
|
setConfirmClear(false);
|
|
445
610
|
};
|
|
446
|
-
const switchChannel = (channel) => {
|
|
447
|
-
|
|
611
|
+
const switchChannel = (channel) => {
|
|
612
|
+
activeChannelRef.current = channel;
|
|
613
|
+
subscribeToScene(channel);
|
|
614
|
+
setActiveChannel(channel);
|
|
615
|
+
setChannels((prev) => prev.map((c) => c.id === channel.id && c.type === channel.type ? { ...c, unread: 0 } : c));
|
|
616
|
+
if (window.innerWidth < 900)
|
|
617
|
+
setShowChannelList(false);
|
|
618
|
+
};
|
|
448
619
|
const updateRunConfig = (patch) => {
|
|
449
|
-
|
|
620
|
+
if (directoryModeRef.current === 'loading')
|
|
621
|
+
return;
|
|
622
|
+
const current = activeChannelRef.current;
|
|
623
|
+
const next = { ...current, runConfig: { ...current.runConfig, ...patch } };
|
|
624
|
+
activeChannelRef.current = next;
|
|
450
625
|
setActiveChannel(next);
|
|
451
|
-
setChannels((sessions) => sessions.map((session) => session.id ===
|
|
626
|
+
setChannels((sessions) => sessions.map((session) => session.id === current.id && session.type === current.type ? next : session));
|
|
627
|
+
void directoryControllerRef.current?.save(next);
|
|
452
628
|
};
|
|
453
629
|
const addSession = () => {
|
|
630
|
+
if (directoryModeRef.current === 'loading')
|
|
631
|
+
return;
|
|
454
632
|
const label = newSessionName.trim() || sandboxText(locale, "未命名试验");
|
|
455
|
-
const id = `${newSessionScope}-${
|
|
633
|
+
const id = `${newSessionScope}-${createSandboxMessageId()}`;
|
|
456
634
|
const session = {
|
|
457
635
|
id, name: label, type: newSessionScope, unread: 0,
|
|
458
636
|
runConfig: { ...activeChannel.runConfig },
|
|
459
637
|
};
|
|
460
638
|
setChannels((current) => [...current, session]);
|
|
639
|
+
activeChannelRef.current = session;
|
|
640
|
+
subscribeToScene(session);
|
|
461
641
|
setActiveChannel(session);
|
|
642
|
+
void directoryControllerRef.current?.save(session);
|
|
462
643
|
setNewSessionName('');
|
|
463
644
|
setShowNewSession(false);
|
|
464
645
|
};
|
|
@@ -511,18 +692,31 @@ export default function Sandbox() {
|
|
|
511
692
|
const runPrompt = (prompt) => handleSendMessage(prompt, [{ type: 'text', data: { text: prompt } }]);
|
|
512
693
|
const recentTraceEvents = trace?.events.slice(-8).reverse() ?? [];
|
|
513
694
|
const stopActiveTask = async () => {
|
|
695
|
+
const owner = currentTraceOwner();
|
|
696
|
+
setCancellationFeedback(null);
|
|
514
697
|
setStoppingTask(true);
|
|
515
698
|
try {
|
|
516
|
-
const cancelled = await cancelAgentTask(sessionKey, locale);
|
|
517
|
-
|
|
518
|
-
|
|
699
|
+
const cancelled = await cancelAgentTask(owner.sessionKey, locale);
|
|
700
|
+
if (!ownsCurrentTrace(owner))
|
|
701
|
+
return;
|
|
702
|
+
setCancellationFeedback({ kind: 'status', message: cancelled ? sandboxText(locale, "停止请求已提交。") : sandboxText(locale, "当前会话没有运行中的任务。") });
|
|
703
|
+
if (owner.cancelRefresh !== undefined)
|
|
704
|
+
window.clearTimeout(owner.cancelRefresh);
|
|
705
|
+
owner.cancelRefresh = window.setTimeout(() => {
|
|
706
|
+
owner.cancelRefresh = undefined;
|
|
707
|
+
if (ownsCurrentTrace(owner))
|
|
708
|
+
void loadTrace(true);
|
|
709
|
+
}, 240);
|
|
519
710
|
}
|
|
520
711
|
catch (error) {
|
|
521
|
-
|
|
712
|
+
if (!ownsCurrentTrace(owner))
|
|
713
|
+
return;
|
|
714
|
+
setCancellationFeedback({ kind: 'error', message: error instanceof Error ? error.message : sandboxText(locale, "无法停止任务") });
|
|
522
715
|
setShowInspector(true);
|
|
523
716
|
}
|
|
524
717
|
finally {
|
|
525
|
-
|
|
718
|
+
if (ownsCurrentTrace(owner))
|
|
719
|
+
setStoppingTask(false);
|
|
526
720
|
}
|
|
527
721
|
};
|
|
528
722
|
const retryLastTask = () => {
|
|
@@ -557,30 +751,44 @@ export default function Sandbox() {
|
|
|
557
751
|
window.setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
558
752
|
};
|
|
559
753
|
const inlineRunCard = currentTask ? (_jsxs("article", { className: cn('agent-playground-inline-run', `is-${currentTask.status}`), "aria-live": currentTask.status === 'running' ? 'polite' : undefined, children: [_jsx("span", { className: "agent-playground-inline-run-rail", "aria-hidden": "true" }), _jsxs("div", { className: "agent-playground-inline-run-head", children: [_jsx("span", { className: "agent-playground-inline-run-icon", children: _jsx(ListChecks, { size: 17 }) }), _jsxs("div", { className: "agent-playground-inline-run-copy", children: [_jsx("span", { children: currentTask.status === 'running' ? 'Live agent run' : 'Agent run summary' }), _jsx("h3", { children: taskStatusLabel(currentTask.status, locale) }), currentTaskMessage && _jsx("p", { children: messageText(currentTaskMessage.content) })] }), _jsxs("div", { className: "agent-playground-inline-run-actions", children: [currentTask.status === 'running' ? (_jsxs("button", { type: "button", className: "is-stop", onClick: () => void stopActiveTask(), disabled: stoppingTask, children: [_jsx(Square, { size: 12 }), stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")] })) : currentTaskMessage ? (_jsxs("button", { type: "button", onClick: retryCurrentTask, children: [_jsx(RotateCcw, { size: 13 }), sandboxText(locale, "重试")] })) : null, _jsxs("button", { type: "button", onClick: exportCurrentRun, title: sandboxText(locale, "导出 Markdown 运行报告"), children: [_jsx(FileDown, { size: 13 }), sandboxText(locale, "导出")] })] })] }), _jsxs("dl", { className: "agent-playground-inline-run-metrics", children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: currentTask.durationMs === undefined ? sandboxText(locale, "进行中") : formatDuration(currentTask.durationMs, locale) })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "步骤") }), _jsx("dd", { children: currentRunSteps.length })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: currentTask.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: currentTask.tokenCount.toLocaleString(locale) })] }), _jsxs("div", { className: cn(currentTask.problemCount > 0 && 'has-problem'), children: [_jsx("dt", { children: sandboxText(locale, "异常") }), _jsx("dd", { children: currentTask.problemCount })] })] }), inlineRunExpanded && (currentRunSteps.length > 0 ? (_jsx("ol", { className: "agent-playground-inline-run-steps", children: currentRunSteps.map((step) => (_jsxs("li", { className: cn(`is-${step.status}`), children: [_jsx("i", { "aria-hidden": "true" }), _jsxs("div", { children: [_jsx("strong", { children: step.title }), step.detail && _jsx("small", { children: step.detail })] }), _jsx("span", { children: step.durationMs === undefined ? runStepStatusLabel(step.status, locale) : formatDuration(step.durationMs, locale) })] }, step.id))) })) : _jsx("div", { className: "agent-playground-inline-run-empty", children: sandboxText(locale, "正在等待第一条运行事件…") })), _jsxs("footer", { children: [_jsxs("button", { type: "button", "aria-expanded": inlineRunExpanded, onClick: () => setInlineRunExpanded((expanded) => !expanded), children: [_jsx(ChevronDown, { size: 13 }), inlineRunExpanded ? sandboxText(locale, "收起步骤") : sandboxText(locale, "查看 {0} 个步骤", [currentRunSteps.length])] }), _jsxs("button", { type: "button", onClick: () => { setInspectorView(currentRunArtifacts.length > 0 ? 'artifacts' : 'runs'); setShowInspector(true); }, children: [currentRunArtifacts.length > 0 ? sandboxText(locale, "{0} 个变更与产物", [currentRunArtifacts.length]) : sandboxText(locale, "打开运行检查器"), _jsx(PanelRight, { size: 13 })] })] })] })) : null;
|
|
560
|
-
|
|
754
|
+
const recoveryConnectionId = connectionRef.current.connectionId;
|
|
755
|
+
return (_jsxs("section", { className: cn("agent-playground-shell", showInspector && "has-inspector"), children: [_jsxs("div", { className: "agent-playground-mobilebar", children: [_jsxs("button", { type: "button", "aria-expanded": showChannelList, onClick: () => setShowChannelList(!showChannelList), children: [_jsx(MessageSquare, { size: 17 }), sandboxText(locale, "会话列表")] }), _jsx("strong", { children: sandboxText(locale, "会话") }), _jsxs("button", { type: "button", "aria-expanded": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => setShowInspector(!showInspector), children: [_jsx(PanelRight, { size: 17 }), sandboxText(locale, "检查器")] })] }), _jsxs("nav", { className: cn("channel-sidebar agent-playground-sessions", showChannelList && "show"), "aria-label": sandboxText(locale, "会话列表"), children: [_jsx("div", { className: "agent-playground-brand", children: _jsxs("div", { className: "flex justify-between items-center", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "agent-playground-mark", children: _jsx(Sparkles, { size: 16 }) }), _jsxs("div", { children: [_jsx("h2", { children: sandboxText(locale, "会话") }), _jsx("small", { children: "Conversations" })] })] }), _jsx("span", { className: cn("agent-playground-connection", connected && "is-online"), title: connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket"), children: connected ? _jsx(Wifi, { size: 12 }) : _jsx(WifiOff, { size: 12 }) })] }) }), _jsxs("div", { className: "agent-playground-section-label", children: [_jsx("span", { children: sandboxText(locale, "会话列表") }), _jsx("span", { children: channels.length }), _jsx("button", { type: "button", disabled: directoryStatus.mode === 'loading', "aria-label": sandboxText(locale, "刷新会话目录"), onClick: () => void directoryControllerRef.current?.refresh(), children: _jsx(RefreshCw, { size: 13 }) })] }), _jsx("div", { className: "agent-playground-session-list", children: channels.map((channel) => {
|
|
561
756
|
const isActive = activeChannel.id === channel.id && activeChannel.type === channel.type;
|
|
562
|
-
return (_jsxs("button", { type: "button", "aria-current": isActive ? 'page' : undefined, className: cn("agent-playground-session", isActive && "active"), onClick: () => switchChannel(channel), children: [_jsx("span", { className: "agent-playground-session-icon", children: getChannelIcon(channel.type) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("div", { className: "text-sm font-medium truncate", children: channel.name }), _jsx("div", { className: "text-xs text-muted-foreground", children: channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域") })] }), channel.unread > 0 && _jsx("span", { className: "inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1", children: channel.unread })] }, `${channel.type}:${channel.id}`));
|
|
757
|
+
return (_jsxs("button", { type: "button", disabled: directoryStatus.mode === 'loading', "aria-current": isActive ? 'page' : undefined, className: cn("agent-playground-session", isActive && "active"), onClick: () => switchChannel(channel), children: [_jsx("span", { className: "agent-playground-session-icon", children: getChannelIcon(channel.type) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("div", { className: "text-sm font-medium truncate", children: channel.name }), _jsx("div", { className: "text-xs text-muted-foreground", children: channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域") })] }), channel.unread > 0 && _jsx("span", { className: "inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1", children: channel.unread })] }, `${channel.type}:${channel.id}`));
|
|
563
758
|
}) }), _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')
|
|
564
|
-
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", className: "agent-playground-add", onClick: () => setShowNewSession(true), children: [_jsx(Plus, { size: 15 }), sandboxText(locale, "
|
|
759
|
+
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
|
|
760
|
+
? _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, "对话与轨迹")] })
|
|
761
|
+
: _jsxs("a", { href: agentSessionsPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), sandboxText(locale, "对话与轨迹")] }), _jsx("button", { type: "button", className: cn(showRunSettings && 'active'), "aria-expanded": showRunSettings, onClick: () => setShowRunSettings((visible) => !visible), "aria-label": sandboxText(locale, "配置运行环境"), children: _jsx(SlidersHorizontal, { size: 16 }) }), _jsx("button", { type: "button", "aria-expanded": showInspector, "aria-controls": "sandbox-run-inspector", onClick: () => setShowInspector(!showInspector), "aria-label": sandboxText(locale, "切换运行检查器"), children: _jsx(PanelRight, { size: 16 }) }), _jsx("button", { type: "button", onClick: () => setConfirmClear(true), "aria-label": sandboxText(locale, "清空当前会话"), children: _jsx(Trash2, { size: 15 }) })] })] }), cancellationFeedback && _jsxs("div", { className: "agent-playground-confirm", role: cancellationFeedback.kind === 'error' ? 'alert' : 'status', children: [_jsx("div", { children: _jsx("span", { children: cancellationFeedback.message }) }), _jsx("button", { type: "button", onClick: () => setCancellationFeedback(null), children: sandboxText(locale, "知道了") })] }), confirmClear && (_jsxs("div", { className: "agent-playground-confirm", role: "alert", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "清空当前测试记录?") }), _jsxs("span", { children: [sandboxText(locale, "只移除“"), activeChannel.name, sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")] })] }), _jsx("button", { type: "button", onClick: () => setConfirmClear(false), children: sandboxText(locale, "取消") }), _jsx("button", { type: "button", className: "danger", onClick: clearMessages, children: sandboxText(locale, "确认清空") })] })), transportNotice && (_jsxs("div", { className: "agent-playground-confirm", role: "status", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "运行暂不可用") }), _jsx("span", { children: transportNotice })] }), _jsx("button", { type: "button", onClick: () => setTransportNotice(null), children: sandboxText(locale, "知道了") })] })), directoryStatus.error && _jsxs("div", { className: "agent-playground-confirm", role: "alert", children: [_jsxs("div", { children: [_jsx("strong", { children: sandboxText(locale, "会话目录") }), _jsx("span", { children: directoryStatus.error })] }), _jsx("button", { type: "button", onClick: () => void directoryControllerRef.current?.refresh(), children: sandboxText(locale, "重新读取") })] }), showRunSettings && (_jsxs("section", { className: "agent-playground-run-settings", "aria-label": sandboxText(locale, "运行配置"), children: [_jsxs("label", { className: "agent-playground-directory-field", children: [_jsxs("span", { children: [_jsx(FolderOpen, { size: 14 }), sandboxText(locale, "工作目录")] }), _jsx("input", { disabled: directoryStatus.mode === 'loading', value: activeChannel.runConfig.workingDirectory, onChange: (event) => updateRunConfig({ workingDirectory: event.target.value }), placeholder: sandboxText(locale, "使用 Host 项目目录"), spellCheck: false })] }), _jsxs("label", { children: [_jsxs("span", { children: [_jsx(ShieldCheck, { size: 14 }), sandboxText(locale, "安全策略")] }), _jsxs("select", { disabled: directoryStatus.mode === 'loading', value: activeChannel.runConfig.safetyMode, onChange: (event) => {
|
|
565
762
|
const safetyMode = event.target.value;
|
|
566
763
|
updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) });
|
|
567
|
-
}, 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] }))] })),
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
764
|
+
}, 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) => {
|
|
765
|
+
const segments = retired.flatMap(interaction => interaction.segments);
|
|
766
|
+
setMessages(previous => {
|
|
767
|
+
const current = activeChannelRef.current;
|
|
768
|
+
if (connectionRef.current.connectionId !== recoveryConnectionId
|
|
769
|
+
|| buildSandboxSessionKey(endpointIdRef.current, current.type, current.id) !== sessionKey)
|
|
770
|
+
return previous;
|
|
771
|
+
return retirePlaygroundInteractions(previous, activeChannel, segments);
|
|
772
|
+
});
|
|
773
|
+
}, 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) => {
|
|
774
|
+
if (msg.recalledMessageId)
|
|
775
|
+
return _jsx("p", { className: "agent-playground-history-notice", children: sandboxText(locale, '消息已撤回') }, msg.id);
|
|
776
|
+
const isApproval = msg.type === 'received' && msg.interactionReadOnly !== true && msg.content.some((segment) => segment.type === 'keyboard');
|
|
777
|
+
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])));
|
|
778
|
+
}), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] }))] }) }), _jsxs("section", { className: "agent-playground-composer", hidden: showConversationDetails, "aria-label": sandboxText(locale, "任务输入"), children: [_jsxs("div", { className: "flex gap-2 items-center flex-wrap", children: [_jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", showFacePicker ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setShowFacePicker(!showFacePicker); setMediaPanel(null); }, title: sandboxText(locale, "插入表情"), children: _jsx(Smile, { size: 16 }) }), _jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", mediaPanel === 'image' ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false); }, title: sandboxText(locale, "插入图片 URL"), children: _jsx(Image, { size: 16 }) }), _jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", mediaPanel === 'video' ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false); }, title: sandboxText(locale, "插入视频 URL"), children: _jsx(Video, { size: 16 }) }), _jsx("button", { type: "button", className: cn("h-8 w-8 rounded-md flex items-center justify-center border transition-colors", mediaPanel === 'audio' ? "bg-primary text-primary-foreground" : "hover:bg-accent"), onClick: () => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false); }, title: sandboxText(locale, "插入音频 URL"), children: _jsx(Music, { size: 16 }) }), _jsx("div", { className: "flex-1 min-w-[1rem]" }), _jsxs("div", { className: "sandbox-composer-tabs", role: "tablist", "aria-label": sandboxText(locale, "消息编辑模式"), children: [_jsx("button", { type: "button", role: "tab", "aria-selected": composerMode === 'write', className: cn(composerMode === 'write' && 'active'), onClick: () => setComposerMode('write'), children: sandboxText(locale, "编写") }), _jsx("button", { type: "button", role: "tab", "aria-selected": composerMode === 'preview', className: cn(composerMode === 'preview' && 'active'), onClick: () => setComposerMode('preview'), children: sandboxText(locale, "预览") })] }), inputText && (_jsx("button", { className: "h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors", onClick: () => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write'); }, "aria-label": sandboxText(locale, "清空输入"), children: _jsx(X, { size: 16 }) }))] }), showFacePicker && (_jsxs("div", { className: "p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2", children: [_jsx("input", { value: faceSearchQuery, onChange: (e) => setFaceSearchQuery(e.target.value), placeholder: sandboxText(locale, "搜索表情..."), className: "w-full h-8 rounded-md border bg-transparent px-2 text-sm" }), _jsx("div", { className: "grid grid-cols-8 gap-1", children: filteredFaces.slice(0, 80).map((face) => (_jsx("button", { onClick: () => insertFace(face.id), title: face.name, className: "w-10 h-10 rounded-md border flex items-center justify-center hover:bg-accent transition-colors", children: _jsx("img", { src: `https://face.viki.moe/apng/${face.id}.png`, alt: face.name, className: "w-8 h-8" }) }, face.id))) }), filteredFaces.length === 0 && (_jsxs("div", { className: "flex flex-col items-center gap-2 py-4", children: [_jsx(Search, { size: 32, className: "text-muted-foreground/30" }), _jsx("span", { className: "text-sm text-muted-foreground", children: sandboxText(locale, "未找到匹配的表情") })] }))] })), mediaPanel && (_jsxs("div", { className: "p-3 rounded-md border bg-muted/30 space-y-2", children: [_jsxs("p", { className: "text-xs text-muted-foreground", children: [mediaPanel === 'image' && sandboxText(locale, "支持 http(s) 图片链接或 data URL"), mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)"), mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")] }), _jsx("input", { value: mediaUrl, onChange: (e) => setMediaUrl(e.target.value), placeholder: mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…"), className: "w-full h-8 rounded-md border border-input bg-background px-2 text-sm", onKeyDown: (e) => { if (e.key === 'Enter') {
|
|
571
779
|
e.preventDefault();
|
|
572
780
|
commitMediaUrl();
|
|
573
781
|
} } }), _jsxs("button", { type: "button", className: "inline-flex items-center gap-1 h-8 px-3 rounded-md bg-primary text-primary-foreground text-sm disabled:opacity-50", onClick: commitMediaUrl, disabled: !mediaUrl.trim(), children: [_jsx(Check, { size: 14 }), " ", sandboxText(locale, "插入到输入框")] })] })), _jsxs("div", { className: "flex gap-2 items-start", children: [_jsxs("div", { className: "flex-1 relative", children: [_jsx("div", { className: composerMode === 'write' ? 'block' : 'hidden', children: _jsx(RichTextEditor, { locale: locale, ref: editorRef, placeholder: sandboxText(locale, "向 {0} 发送消息,支持 Markdown...", [activeChannel.name]), onSend: handleSendMessage, onChange: handleEditorChange, onAtTrigger: handleAtTrigger, minHeight: "44px", maxHeight: "200px" }) }), composerMode === 'preview' && (_jsx("div", { className: "sandbox-markdown-preview", role: "tabpanel", children: inputText.trim()
|
|
574
782
|
? _jsx(MarkdownContent, { text: inputText })
|
|
575
783
|
: _jsx("span", { className: "sandbox-markdown-preview-empty", children: sandboxText(locale, "输入 Markdown 后可在这里检查最终效果") }) })), atPopoverPosition && (_jsx("div", { className: "absolute z-50 rounded-lg border bg-popover shadow-md min-w-60 max-h-72 overflow-y-auto p-1", style: { top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }, children: filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (_jsxs("div", { className: "flex items-center gap-2 p-2 rounded-md cursor-pointer hover:bg-accent transition-colors", onClick: () => selectAtUser(user), children: [_jsx(User, { size: 16, className: "text-muted-foreground" }), _jsxs("div", { className: "flex-1", children: [_jsx("div", { className: "text-sm font-medium", children: user.name }), _jsxs("div", { className: "text-xs text-muted-foreground", children: ["ID: ", user.id] })] })] }, user.id))) : (_jsxs("div", { className: "flex flex-col items-center gap-2 p-4", children: [_jsx(Search, { size: 20, className: "text-muted-foreground/50" }), _jsx("span", { className: "text-xs text-muted-foreground", children: sandboxText(locale, "未找到匹配的用户") })] })) }))] }), _jsxs("button", { className: "inline-flex items-center gap-1.5 h-10 px-4 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 transition-colors hover:bg-primary/90", onClick: () => { const c = editorRef.current?.getContent(); if (c)
|
|
576
|
-
handleSendMessage(c.text, c.segments); }, disabled: !canExecute || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("div", { className: "flex items-center gap-2 flex-wrap text-xs text-muted-foreground", children: [_jsx(Info, { size: 12 }), " ", sandboxText(locale, "快捷操作:"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "Enter" }), " ", sandboxText(locale, "发送"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "Shift+Enter" }), " ", sandboxText(locale, "换行"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "```ts" }), " ", sandboxText(locale, "代码块"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "[video:URL]" }), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "[audio:URL]" })] })] })] }), _jsxs("aside", { className: cn("agent-playground-inspector", showInspector && "show"), "aria-label": sandboxText(locale, "运行检查器"), children: [_jsxs("div", { className: "agent-playground-inspector-head", children: [_jsxs("div", { children: [_jsx("span", { children: "Run inspector" }), _jsx("h2", { children: sandboxText(locale, "运行检查器") })] }), _jsxs("div", { children: [_jsx("button", { type: "button", onClick: () => void loadTrace(), "aria-label": sandboxText(locale, "刷新 Agent Trace"), disabled: traceLoading, children: _jsx(RefreshCw, { size: 15, className: cn(traceLoading && 'animate-spin') }) }), _jsx("button", { type: "button", className: "agent-playground-inspector-close", onClick: () => setShowInspector(false), "aria-label": sandboxText(locale, "关闭运行检查器"), children: _jsx(X, { size: 15 }) })] })] }), _jsxs("div", { className: "agent-playground-inspector-tabs", role: "tablist", "aria-label": sandboxText(locale, "检查器视图"), children: [_jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'runs', className: cn(inspectorView === 'runs' && 'active'), onClick: () => setInspectorView('runs'), children: [_jsx(Activity, { size: 13 }), sandboxText(locale, "任务")] }), _jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'artifacts', className: cn(inspectorView === 'artifacts' && 'active'), onClick: () => setInspectorView('artifacts'), children: [_jsx(FileDiff, { size: 13 }), sandboxText(locale, "变更与产物"), _jsx("span", { children: workbenchArtifacts.length })] })] }), _jsxs("div", { className: cn("agent-playground-inspector-view", inspectorView !== 'runs' && 'hidden'), children: [_jsxs("section", { className: "agent-playground-inspector-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "运行概览") }), _jsx("small", { children: traceSummary.activeTurns > 0 ? 'live' : 'idle' })] }), _jsxs("div", { className: "agent-playground-metrics", children: [_jsxs("div", { children: [_jsx(Activity, {}), _jsx("strong", { children: traceSummary.eventCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "事件") })] }), _jsxs("div", { children: [_jsx(Wrench, {}), _jsx("strong", { children: traceSummary.toolCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "工具") })] }), _jsxs("div", { children: [_jsx(Coins, {}), _jsx("strong", { children: traceSummary.tokenCount.toLocaleString(locale) }), _jsx("span", { children: "Token" })] }), _jsxs("div", { className: cn(traceSummary.problemCount > 0 && 'has-problem'), children: [_jsx(CircleAlert, {}), _jsx("strong", { children: traceSummary.problemCount }), _jsx("span", { children: sandboxText(locale, "异常") })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section", children: [_jsx("div", { className: "agent-playground-inspector-title", children: _jsx("span", { children: sandboxText(locale, "上下文") }) }), _jsxs("dl", { className: "agent-playground-context-list", children: [_jsxs("div", { children: [_jsx("dt", { children: "Endpoint" }), _jsx("dd", { children: endpointId })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scope" }), _jsx("dd", { children: activeChannel.type })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scene" }), _jsx("dd", { children: activeChannel.id })] }), _jsxs("div", { children: [_jsx("dt", { children: "Workdir" }), _jsx("dd", { title: activeChannel.runConfig.workingDirectory, children: activeChannel.runConfig.workingDirectory || 'Host project root' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Security" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Approval" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Network" }), _jsx("dd", { children: activeChannel.runConfig.networkAccess ? 'enabled' : 'disabled' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Isolation" }), _jsx("dd", { className: cn(shellIsolation?.available && 'is-online'), children: shellIsolation ? `${shellIsolation.provider}: ${shellIsolation.available ? 'ready' : 'unavailable'}` : 'checking' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Transport" }), _jsx("dd", { className: cn(connected && 'is-online'), children: connected ? 'WebSocket online' : 'reconnecting' })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-task-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "任务历史") }), _jsxs("small", { children: [taskRuns.length, " runs"] })] }), taskRuns.length > 0 ? (_jsx("div", { className: "agent-playground-task-list", children: taskRuns.slice(0, 8).map((run) => (_jsxs("article", { className: cn(`is-${run.status}`), children: [_jsx("i", {}), _jsxs("div", { children: [_jsx("strong", { children: taskStatusLabel(run.status, locale) }), _jsx("code", { children: run.turnId.slice(0, 10) })] }), _jsxs("dl", { children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: run.durationMs === undefined ? sandboxText(locale, "进行中") : `${run.durationMs.toLocaleString(locale)} ms` })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: run.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: run.tokenCount.toLocaleString(locale) })] })] })] }, run.id))) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "运行任务后会在这里形成可回溯记录") })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-trace-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "最近执行") }), _jsx("small", { children: "2s sync" })] }),
|
|
784
|
+
handleSendMessage(c.text, c.segments); }, disabled: !canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), " ", sandboxText(locale, "发送")] })] }), _jsxs("div", { className: "flex items-center gap-2 flex-wrap text-xs text-muted-foreground", children: [_jsx(Info, { size: 12 }), " ", sandboxText(locale, "快捷操作:"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "Enter" }), " ", sandboxText(locale, "发送"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "Shift+Enter" }), " ", sandboxText(locale, "换行"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "```ts" }), " ", sandboxText(locale, "代码块"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: sandboxText(locale, "**文本**") }), " ", sandboxText(locale, "加粗"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: sandboxText(locale, "[@名称]") }), " ", sandboxText(locale, "@某人"), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "[video:URL]" }), _jsx("span", { className: "px-1 py-0.5 rounded border text-[10px]", children: "[audio:URL]" })] })] })] }), _jsxs("aside", { id: "sandbox-run-inspector", className: cn("agent-playground-inspector", showInspector && "show"), hidden: !showInspector, "aria-hidden": !showInspector, "aria-label": sandboxText(locale, "运行检查器"), children: [_jsxs("div", { className: "agent-playground-inspector-head", children: [_jsxs("div", { children: [_jsx("span", { children: "Run inspector" }), _jsx("h2", { children: sandboxText(locale, "运行检查器") })] }), _jsxs("div", { children: [_jsx("button", { type: "button", onClick: () => void loadTrace(), "aria-label": sandboxText(locale, "刷新 Agent Trace"), disabled: traceLoading, children: _jsx(RefreshCw, { size: 15, className: cn(traceLoading && 'animate-spin') }) }), _jsx("button", { type: "button", className: "agent-playground-inspector-close", onClick: () => setShowInspector(false), "aria-label": sandboxText(locale, "关闭运行检查器"), children: _jsx(X, { size: 15 }) })] })] }), _jsxs("div", { className: "agent-playground-inspector-tabs", role: "tablist", "aria-label": sandboxText(locale, "检查器视图"), children: [_jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'runs', className: cn(inspectorView === 'runs' && 'active'), onClick: () => setInspectorView('runs'), children: [_jsx(Activity, { size: 13 }), sandboxText(locale, "任务")] }), _jsxs("button", { type: "button", role: "tab", "aria-selected": inspectorView === 'artifacts', className: cn(inspectorView === 'artifacts' && 'active'), onClick: () => setInspectorView('artifacts'), children: [_jsx(FileDiff, { size: 13 }), sandboxText(locale, "变更与产物"), _jsx("span", { children: workbenchArtifacts.length })] })] }), _jsxs("div", { className: cn("agent-playground-inspector-view", inspectorView !== 'runs' && 'hidden'), children: [_jsxs("section", { className: "agent-playground-inspector-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "运行概览") }), _jsx("small", { children: traceSummary.activeTurns > 0 ? 'live' : 'idle' })] }), _jsxs("div", { className: "agent-playground-metrics", children: [_jsxs("div", { children: [_jsx(Activity, {}), _jsx("strong", { children: traceSummary.eventCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "事件") })] }), _jsxs("div", { children: [_jsx(Wrench, {}), _jsx("strong", { children: traceSummary.toolCount.toLocaleString(locale) }), _jsx("span", { children: sandboxText(locale, "工具") })] }), _jsxs("div", { children: [_jsx(Coins, {}), _jsx("strong", { children: traceSummary.tokenCount.toLocaleString(locale) }), _jsx("span", { children: "Token" })] }), _jsxs("div", { className: cn(traceSummary.problemCount > 0 && 'has-problem'), children: [_jsx(CircleAlert, {}), _jsx("strong", { children: traceSummary.problemCount }), _jsx("span", { children: sandboxText(locale, "异常") })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section", children: [_jsx("div", { className: "agent-playground-inspector-title", children: _jsx("span", { children: sandboxText(locale, "上下文") }) }), _jsxs("dl", { className: "agent-playground-context-list", children: [_jsxs("div", { children: [_jsx("dt", { children: "Endpoint" }), _jsx("dd", { children: endpointId })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scope" }), _jsx("dd", { children: activeChannel.type })] }), _jsxs("div", { children: [_jsx("dt", { children: "Scene" }), _jsx("dd", { children: activeChannel.id })] }), _jsxs("div", { children: [_jsx("dt", { children: "Workdir" }), _jsx("dd", { title: activeChannel.runConfig.workingDirectory, children: activeChannel.runConfig.workingDirectory || 'Host project root' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Security" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Approval" }), _jsx("dd", { children: activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode })] }), _jsxs("div", { children: [_jsx("dt", { children: "Network" }), _jsx("dd", { children: activeChannel.runConfig.networkAccess ? 'enabled' : 'disabled' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Isolation" }), _jsx("dd", { className: cn(shellIsolation?.available && 'is-online'), children: shellIsolation ? `${shellIsolation.provider}: ${shellIsolation.available ? 'ready' : 'unavailable'}` : 'checking' })] }), _jsxs("div", { children: [_jsx("dt", { children: "Transport" }), _jsx("dd", { className: cn(connected && 'is-online'), children: connected ? 'WebSocket online' : 'reconnecting' })] })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-task-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "任务历史") }), _jsxs("small", { children: [taskRuns.length, " runs"] })] }), taskRuns.length > 0 ? (_jsx("div", { className: "agent-playground-task-list", children: taskRuns.slice(0, 8).map((run) => (_jsxs("article", { className: cn(`is-${run.status}`), children: [_jsx("i", {}), _jsxs("div", { children: [_jsx("strong", { children: taskStatusLabel(run.status, locale) }), _jsx("code", { children: run.turnId.slice(0, 10) })] }), _jsxs("dl", { children: [_jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "耗时") }), _jsx("dd", { children: run.durationMs === undefined ? sandboxText(locale, "进行中") : `${run.durationMs.toLocaleString(locale)} ms` })] }), _jsxs("div", { children: [_jsx("dt", { children: sandboxText(locale, "工具") }), _jsx("dd", { children: run.toolCount })] }), _jsxs("div", { children: [_jsx("dt", { children: "Token" }), _jsx("dd", { children: run.tokenCount.toLocaleString(locale) })] })] })] }, run.id))) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "运行任务后会在这里形成可回溯记录") })] })] }), _jsxs("section", { className: "agent-playground-inspector-section agent-playground-trace-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "最近执行") }), _jsx("small", { children: "2s sync" })] }), traceNotice && _jsxs("div", { className: "agent-playground-trace-notice", role: "alert", children: [_jsx(CircleAlert, { size: 16 }), _jsx("span", { children: traceNotice })] }), traceLoading && !trace ? (_jsxs("div", { className: "agent-playground-trace-loading", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : recentTraceEvents.length ? (_jsx("div", { className: "agent-playground-trace-list", children: recentTraceEvents.map((event) => {
|
|
577
785
|
const item = presentTraceEvent(event, locale);
|
|
578
786
|
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));
|
|
579
787
|
}) })) : (_jsxs("div", { className: "agent-playground-trace-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: sandboxText(locale, "发送任务后显示推理与工具轨迹") })] }))] })] }), _jsx("div", { className: cn("agent-playground-inspector-view", inspectorView !== 'artifacts' && 'hidden'), children: _jsxs("section", { className: "agent-playground-inspector-section agent-playground-artifact-section", children: [_jsxs("div", { className: "agent-playground-inspector-title", children: [_jsx("span", { children: sandboxText(locale, "文件与命令产物") }), _jsxs("small", { children: [workbenchArtifacts.length, " items"] })] }), workbenchArtifacts.length > 0 ? (_jsx("div", { className: "agent-playground-artifact-list", children: workbenchArtifacts.map((artifact) => {
|
|
580
788
|
const ArtifactIcon = artifact.kind === 'file-change' ? FileDiff : artifact.kind === 'test' ? FlaskConical : Terminal;
|
|
581
789
|
const expanded = expandedArtifact === artifact.id;
|
|
582
|
-
return (_jsxs("article", { className: cn(`is-${artifact.status}`, expanded && 'is-expanded'), children: [_jsxs("button", { type: "button", onClick: () => setExpandedArtifact(expanded ? null : artifact.id), "aria-expanded": expanded, children: [_jsx("span", { className: "agent-playground-artifact-icon", children: _jsx(ArtifactIcon, { size: 14 }) }), _jsxs("span", { children: [_jsx("strong", { children: artifact.title }), _jsx("small", { children: artifact.path ?? artifact.detail ?? artifact.kind })] }), _jsx("em", { children: artifact.status }), _jsx(ChevronDown, { size: 14 })] }), expanded && (_jsxs("div", { className: "agent-playground-artifact-detail", children: [artifact.path && _jsx("code", { children: artifact.path }), artifact.diff ? _jsx("pre", { children: artifact.diff }) : _jsx("pre", { children: artifact.detail || sandboxText(locale, "暂无输出") }), _jsxs("footer", { children: [_jsx("span", { children: artifact.durationMs === undefined ? sandboxText(locale, "等待结果") : `${artifact.durationMs.toLocaleString(locale)} ms` }), _jsx("code", { children: artifact.turnId.slice(0, 12) })] })] }))] }, artifact.id));
|
|
583
|
-
}) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(FileDiff, { size: 18 }), _jsx("span", { children: sandboxText(locale, "Agent 修改文件、执行命令或测试后,产物会集中出现在这里") })] })] }) }), _jsxs("a", { className: "agent-playground-studio-link", href:
|
|
790
|
+
return (_jsxs("article", { className: cn(`is-${artifact.status}`, expanded && 'is-expanded'), children: [_jsxs("button", { type: "button", onClick: () => setExpandedArtifact(expanded ? null : artifact.id), "aria-expanded": expanded, children: [_jsx("span", { className: "agent-playground-artifact-icon", children: _jsx(ArtifactIcon, { size: 14 }) }), _jsxs("span", { children: [_jsx("strong", { children: artifact.title }), _jsx("small", { children: artifact.path ?? artifact.detail ?? artifact.kind })] }), _jsx("em", { children: artifact.status }), _jsx(ChevronDown, { size: 14 })] }), expanded && (_jsxs("div", { className: "agent-playground-artifact-detail", children: [artifact.path && _jsx("code", { children: artifact.path }), canExecute && artifact.projectFilePath && (_jsxs("a", { href: `/files?${new URLSearchParams({ path: artifact.projectFilePath })}`, target: "_blank", rel: "noopener noreferrer", className: "inline-flex items-center gap-1 text-primary hover:underline", children: [_jsx(ExternalLink, { size: 13 }), sandboxText(locale, "打开当前文件")] })), artifact.diff ? _jsx("pre", { children: artifact.diff }) : _jsx("pre", { children: artifact.detail || sandboxText(locale, "暂无输出") }), _jsxs("footer", { children: [_jsx("span", { children: artifact.durationMs === undefined ? sandboxText(locale, "等待结果") : `${artifact.durationMs.toLocaleString(locale)} ms` }), _jsx("code", { children: artifact.turnId.slice(0, 12) })] })] }))] }, artifact.id));
|
|
791
|
+
}) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(FileDiff, { size: 18 }), _jsx("span", { children: sandboxText(locale, "Agent 修改文件、执行命令或测试后,产物会集中出现在这里") })] })] }) }), _jsxs("a", { className: "agent-playground-studio-link", href: agentSessionsPath(sessionKey), children: [_jsxs("span", { children: [_jsx(ExternalLink, { size: 15 }), sandboxText(locale, "对话与轨迹")] }), _jsx("code", { children: sessionKey })] })] }), showInspector && _jsx("div", { className: "agent-playground-inspector-overlay", onClick: () => setShowInspector(false) })] }));
|
|
584
792
|
}
|
|
585
793
|
function taskStatusLabel(status, locale = 'zh-CN') {
|
|
586
794
|
if (status === 'running')
|