@zhin.js/adapter-sandbox 1.1.17 → 1.1.19
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 +50 -0
- package/README.md +1 -1
- package/adapters/sandbox/index.js +2 -0
- package/adapters/sandbox/index.ts +2 -0
- package/lib/endpoint.d.ts +3 -0
- package/lib/endpoint.js +14 -4
- package/package.json +19 -19
- package/pages/index/HtmlMessage.js +3 -2
- package/pages/index/HtmlMessage.tsx +3 -2
- package/pages/index/RichTextEditor.js +4 -3
- package/pages/index/RichTextEditor.tsx +5 -3
- package/pages/index/SandboxChat.js +70 -63
- package/pages/index/SandboxChat.tsx +167 -167
- package/pages/index/agentTrace.js +74 -73
- package/pages/index/agentTrace.ts +74 -73
- package/pages/index/index.js +2 -1
- package/pages/index/index.tsx +2 -1
- package/pages/index/messages.js +227 -0
- package/pages/index/messages.ts +229 -0
- package/schema.json +35 -5
- package/src/endpoint.ts +17 -4
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { sandboxText } from './messages.js';
|
|
3
4
|
import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
|
4
5
|
import { cn, CodeBlock, MarkdownContent, resolveMediaSrc, pickMediaRawUrl, } from '@zhin.js/client';
|
|
5
6
|
import { buildSandboxWebSocketUrl } from './sandboxTransport';
|
|
@@ -9,6 +10,8 @@ import HtmlMessage from './HtmlMessage.js';
|
|
|
9
10
|
import { agentStudioPath, buildAgentRunReport, buildSandboxSessionKey, cancelAgentTask, deriveAgentRunSteps, deriveTaskRuns, deriveWorkbenchArtifacts, fetchAgentTrace, loadCachedAgentTrace, mergeTraceSnapshot, presentTraceEvent, summarizeTrace, saveCachedAgentTrace, } from './agentTrace.js';
|
|
10
11
|
import { createDefaultPlaygroundState, loadPlaygroundState, savePlaygroundState, } from './playgroundState.js';
|
|
11
12
|
export default function Sandbox() {
|
|
13
|
+
const [locale, setLocale] = useState('zh-CN');
|
|
14
|
+
const localeRef = useRef('zh-CN');
|
|
12
15
|
const [initialState] = useState(() => loadPlaygroundState());
|
|
13
16
|
const [messages, setMessages] = useState(() => [...initialState.messages]);
|
|
14
17
|
const [channels, setChannels] = useState(() => [...initialState.sessions]);
|
|
@@ -34,10 +37,10 @@ export default function Sandbox() {
|
|
|
34
37
|
const [atPopoverPosition, setAtPopoverPosition] = useState(null);
|
|
35
38
|
const [atSearchQuery, setAtSearchQuery] = useState('');
|
|
36
39
|
const [faceSearchQuery, setFaceSearchQuery] = useState('');
|
|
37
|
-
const
|
|
38
|
-
{ id: 'actor-owner', name:
|
|
39
|
-
{ id: 'actor-operator', name:
|
|
40
|
-
]
|
|
40
|
+
const atSuggestions = [
|
|
41
|
+
{ id: 'actor-owner', name: sandboxText(locale, "当前用户") }, { id: 'actor-reviewer', name: sandboxText(locale, "审阅者") },
|
|
42
|
+
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id: 'actor-bot', name: 'Sandbox Agent' }
|
|
43
|
+
];
|
|
41
44
|
const [previewSegments, setPreviewSegments] = useState([]);
|
|
42
45
|
const [composerMode, setComposerMode] = useState('write');
|
|
43
46
|
const [showChannelList, setShowChannelList] = useState(false);
|
|
@@ -59,9 +62,9 @@ export default function Sandbox() {
|
|
|
59
62
|
const sessionKey = useMemo(() => buildSandboxSessionKey(endpointId, activeChannel.type, activeChannel.id), [activeChannel.id, activeChannel.type, endpointId]);
|
|
60
63
|
const traceSummary = useMemo(() => summarizeTrace(trace), [trace]);
|
|
61
64
|
const taskRuns = useMemo(() => deriveTaskRuns(trace), [trace]);
|
|
62
|
-
const workbenchArtifacts = useMemo(() => deriveWorkbenchArtifacts(trace), [trace]);
|
|
65
|
+
const workbenchArtifacts = useMemo(() => deriveWorkbenchArtifacts(trace, locale), [trace, locale]);
|
|
63
66
|
const currentTask = taskRuns.find((run) => run.status === 'running') ?? taskRuns[0];
|
|
64
|
-
const currentRunSteps = useMemo(() => deriveAgentRunSteps(trace, currentTask), [currentTask, trace]);
|
|
67
|
+
const currentRunSteps = useMemo(() => deriveAgentRunSteps(trace, currentTask, locale), [currentTask, trace, locale]);
|
|
65
68
|
const currentRunArtifacts = useMemo(() => workbenchArtifacts.filter((artifact) => (artifact.turnId === currentTask?.turnId && artifact.runtimeId === currentTask?.runtimeId)), [currentTask?.runtimeId, currentTask?.turnId, workbenchArtifacts]);
|
|
66
69
|
useEffect(() => { activeChannelRef.current = activeChannel; }, [activeChannel]);
|
|
67
70
|
useEffect(() => { endpointIdRef.current = endpointId; }, [endpointId]);
|
|
@@ -86,15 +89,18 @@ export default function Sandbox() {
|
|
|
86
89
|
};
|
|
87
90
|
useEffect(() => { fetchFaceList(); }, []);
|
|
88
91
|
const handleInboundPayload = (data) => {
|
|
92
|
+
const locale = data.type === 'ready' && data.locale === 'en' ? 'en' : data.type === 'ready' ? 'zh-CN' : localeRef.current;
|
|
89
93
|
if (data.type === 'ready') {
|
|
94
|
+
localeRef.current = locale;
|
|
95
|
+
setLocale(locale);
|
|
90
96
|
setBotName(data.endpoint || data.bot || 'sandbox-bot');
|
|
91
97
|
setCanExecute(data.canExecute !== false);
|
|
92
|
-
setTransportNotice(data.canExecute === false ?
|
|
98
|
+
setTransportNotice(data.canExecute === false ? sandboxText(locale, "当前 Token 只有演示权限,任务运行已禁用。") : null);
|
|
93
99
|
if (data.shellIsolation) {
|
|
94
100
|
setShellIsolation({
|
|
95
101
|
available: data.shellIsolation.available === true,
|
|
96
102
|
provider: data.shellIsolation.provider || 'docker',
|
|
97
|
-
message: data.shellIsolation.message ||
|
|
103
|
+
message: data.shellIsolation.message || sandboxText(locale, "未检测到隔离执行环境"),
|
|
98
104
|
});
|
|
99
105
|
}
|
|
100
106
|
if (data.workingDirectory?.trim()) {
|
|
@@ -110,8 +116,8 @@ export default function Sandbox() {
|
|
|
110
116
|
}
|
|
111
117
|
if (data.type === 'error') {
|
|
112
118
|
const notice = Array.isArray(data.content)
|
|
113
|
-
? String(data.content[0]?.data?.text ??
|
|
114
|
-
: String(data.content ??
|
|
119
|
+
? String(data.content[0]?.data?.text ?? sandboxText(locale, "Sandbox 拒绝了本次操作"))
|
|
120
|
+
: String(data.content ?? sandboxText(locale, "Sandbox 拒绝了本次操作"));
|
|
115
121
|
setTransportNotice(notice);
|
|
116
122
|
return;
|
|
117
123
|
}
|
|
@@ -127,10 +133,10 @@ export default function Sandbox() {
|
|
|
127
133
|
: Array.isArray(data.content) ? data.content : parseTextToSegments(String(data.content ?? ''));
|
|
128
134
|
const channelType = data.type === 'group' || data.type === 'channel' ? data.type : 'private';
|
|
129
135
|
const channelName = channelType === 'private'
|
|
130
|
-
?
|
|
136
|
+
? sandboxText(locale, "会话 {0}", [data.id])
|
|
131
137
|
: channelType === 'group'
|
|
132
|
-
?
|
|
133
|
-
:
|
|
138
|
+
? sandboxText(locale, "群组场景 {0}", [data.id])
|
|
139
|
+
: sandboxText(locale, "频道场景 {0}", [data.id]);
|
|
134
140
|
setChannels((prev) => {
|
|
135
141
|
if (prev.some((c) => c.id === data.id && c.type === channelType))
|
|
136
142
|
return prev;
|
|
@@ -150,7 +156,7 @@ export default function Sandbox() {
|
|
|
150
156
|
const sendInteractiveAction = (payload, messageId) => {
|
|
151
157
|
const ws = wsRef.current;
|
|
152
158
|
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
153
|
-
setTransportNotice(
|
|
159
|
+
setTransportNotice(sandboxText(locale, "Sandbox 连接尚未就绪,审批选择未发送。"));
|
|
154
160
|
return;
|
|
155
161
|
}
|
|
156
162
|
const segments = [{ type: 'action', data: { id: payload, payload } }];
|
|
@@ -170,7 +176,7 @@ export default function Sandbox() {
|
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
catch {
|
|
173
|
-
setTransportNotice(
|
|
179
|
+
setTransportNotice(sandboxText(locale, "审批选择发送失败,请等待连接恢复后重试。"));
|
|
174
180
|
}
|
|
175
181
|
};
|
|
176
182
|
useEffect(() => {
|
|
@@ -273,13 +279,14 @@ export default function Sandbox() {
|
|
|
273
279
|
useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]);
|
|
274
280
|
useEffect(() => { setPreviewSegments(inputText.trim() ? parseTextToSegments(inputText) : []); }, [inputText]);
|
|
275
281
|
const loadTrace = useCallback(async (quiet = false) => {
|
|
282
|
+
const locale = localeRef.current;
|
|
276
283
|
if (!quiet)
|
|
277
284
|
setTraceLoading(true);
|
|
278
285
|
try {
|
|
279
286
|
const current = traceRef.current?.sessionKey === sessionKey ? traceRef.current : null;
|
|
280
|
-
let incoming = await fetchAgentTrace(sessionKey, quiet ? current?.latestSequence ?? 0 : 0);
|
|
287
|
+
let incoming = await fetchAgentTrace(sessionKey, quiet ? current?.latestSequence ?? 0 : 0, locale);
|
|
281
288
|
if (quiet && current?.runtimeId && incoming.runtimeId && current.runtimeId !== incoming.runtimeId) {
|
|
282
|
-
incoming = await fetchAgentTrace(sessionKey, 0);
|
|
289
|
+
incoming = await fetchAgentTrace(sessionKey, 0, locale);
|
|
283
290
|
}
|
|
284
291
|
const merged = mergeTraceSnapshot(current, incoming);
|
|
285
292
|
traceRef.current = merged;
|
|
@@ -288,7 +295,7 @@ export default function Sandbox() {
|
|
|
288
295
|
setTraceNotice(null);
|
|
289
296
|
}
|
|
290
297
|
catch (error) {
|
|
291
|
-
setTraceNotice(error instanceof Error ? error.message :
|
|
298
|
+
setTraceNotice(error instanceof Error ? error.message : sandboxText(locale, "Agent Trace 暂不可用"));
|
|
292
299
|
}
|
|
293
300
|
finally {
|
|
294
301
|
if (!quiet)
|
|
@@ -361,7 +368,7 @@ export default function Sandbox() {
|
|
|
361
368
|
case 'md':
|
|
362
369
|
return _jsx(MarkdownContent, { text: String(d.text ?? d.content ?? ''), className: isSent ? 'zhin-markdown--inverse' : undefined }, index);
|
|
363
370
|
case 'html':
|
|
364
|
-
return _jsx(HtmlMessage, { html: String(d.html ?? '') }, index);
|
|
371
|
+
return _jsx(HtmlMessage, { locale: locale, html: String(d.html ?? '') }, index);
|
|
365
372
|
case 'code':
|
|
366
373
|
return _jsx(CodeBlock, { code: String(d.code ?? d.text ?? d.content ?? ''), language: String(d.language ?? d.lang ?? '') }, index);
|
|
367
374
|
case 'mention':
|
|
@@ -370,21 +377,21 @@ export default function Sandbox() {
|
|
|
370
377
|
case 'face':
|
|
371
378
|
return _jsx("img", { src: `https://face.viki.moe/apng/${d.id}.png`, alt: String(d.name ?? ''), className: "w-6 h-6 inline-block align-middle mx-0.5", title: String(d.name ?? d.id ?? '') }, index);
|
|
372
379
|
case 'dice':
|
|
373
|
-
return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5", children: ["\uD83C\uDFB2 ", d.result != null ?
|
|
380
|
+
return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5", children: ["\uD83C\uDFB2 ", d.result != null ? sandboxText(locale, "点数 {0}", [String(d.result)]) : sandboxText(locale, "骰子")] }, index);
|
|
374
381
|
case 'rps':
|
|
375
|
-
return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5", children: ["\u270A ", d.result != null ?
|
|
382
|
+
return _jsxs("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5", children: ["\u270A ", d.result != null ? sandboxText(locale, "结果 {0}", [String(d.result)]) : sandboxText(locale, "猜拳")] }, index);
|
|
376
383
|
case 'image': {
|
|
377
384
|
const raw = pickMediaRawUrl(d);
|
|
378
385
|
const src = resolveMediaSrc(raw, 'image');
|
|
379
386
|
if (!src)
|
|
380
|
-
return _jsx("span", { className: "text-xs opacity-70", children: "[
|
|
387
|
+
return _jsx("span", { className: "text-xs opacity-70", children: sandboxText(locale, "[图片]") }, index);
|
|
381
388
|
return (_jsx("a", { href: src, target: "_blank", rel: "noreferrer", className: "block my-1", children: _jsx("img", { src: src, alt: "", className: cn('max-w-[min(320px,88vw)] rounded-lg block', ring, 'ring-offset-0'), onError: (e) => { e.target.style.display = 'none'; } }) }, index));
|
|
382
389
|
}
|
|
383
390
|
case 'video': {
|
|
384
391
|
const raw = pickMediaRawUrl(d);
|
|
385
392
|
const src = resolveMediaSrc(raw, 'video');
|
|
386
393
|
if (!src)
|
|
387
|
-
return _jsx("span", { className: "text-xs opacity-70", children: "[
|
|
394
|
+
return _jsx("span", { className: "text-xs opacity-70", children: sandboxText(locale, "[视频无地址]") }, index);
|
|
388
395
|
return (_jsx("video", { src: src, controls: true, playsInline: true, preload: "metadata", className: cn('max-w-[min(360px,92vw)] max-h-72 rounded-lg my-1 bg-black/10', ring) }, index));
|
|
389
396
|
}
|
|
390
397
|
case 'audio':
|
|
@@ -392,20 +399,20 @@ export default function Sandbox() {
|
|
|
392
399
|
const raw = pickMediaRawUrl(d);
|
|
393
400
|
const src = resolveMediaSrc(raw, 'audio');
|
|
394
401
|
if (!src)
|
|
395
|
-
return _jsx("span", { className: "text-xs opacity-70", children: "[
|
|
402
|
+
return _jsx("span", { className: "text-xs opacity-70", children: sandboxText(locale, "[音频无地址]") }, index);
|
|
396
403
|
return (_jsx("audio", { src: src, controls: true, preload: "metadata", className: cn('w-full max-w-sm my-2 h-10', isSent && 'opacity-95') }, index));
|
|
397
404
|
}
|
|
398
405
|
case 'reply':
|
|
399
|
-
return (_jsxs("div", { className: "mb-1 rounded-md border border-dashed px-2 py-1 text-xs opacity-90", children: ["
|
|
406
|
+
return (_jsxs("div", { className: "mb-1 rounded-md border border-dashed px-2 py-1 text-xs opacity-90", children: [sandboxText(locale, "↩ 引用消息 #"), String(d.message_id ?? d.id ?? '')] }, index));
|
|
400
407
|
case 'forward': {
|
|
401
408
|
const messages = d.messages;
|
|
402
|
-
const title = String(d.title ??
|
|
403
|
-
return (_jsxs("div", { className: "my-1 rounded-md border bg-background/40 px-2 py-2 text-xs space-y-1", children: [_jsxs("div", { className: "font-medium", children: ["\uD83D\uDCE8 ", title] }), Array.isArray(messages) && messages.length > 0 ? (_jsxs("div", { className: "space-y-1 pl-2 border-l-2 border-muted", children: [messages.slice(0, 3).map((batch, bi) => (_jsx("div", { className: "opacity-90", children: batch.map((s, si) => (_jsx("span", { children: s.type === 'text' ? String(s.data?.text ?? '') : `[${s.type ?? 'seg'}]` }, si))) }, bi))), messages.length > 3 && _jsxs("div", { className: "opacity-60", children: [
|
|
409
|
+
const title = String(d.title ?? sandboxText(locale, "聊天记录"));
|
|
410
|
+
return (_jsxs("div", { className: "my-1 rounded-md border bg-background/40 px-2 py-2 text-xs space-y-1", children: [_jsxs("div", { className: "font-medium", children: ["\uD83D\uDCE8 ", title] }), Array.isArray(messages) && messages.length > 0 ? (_jsxs("div", { className: "space-y-1 pl-2 border-l-2 border-muted", children: [messages.slice(0, 3).map((batch, bi) => (_jsx("div", { className: "opacity-90", children: batch.map((s, si) => (_jsx("span", { children: s.type === 'text' ? String(s.data?.text ?? '') : `[${s.type ?? 'seg'}]` }, si))) }, bi))), messages.length > 3 && _jsxs("div", { className: "opacity-60", children: [sandboxText(locale, "…共"), messages.length, " ", sandboxText(locale, "条")] })] })) : (_jsx("div", { className: "opacity-70", children: sandboxText(locale, "[合并转发]") }))] }, index));
|
|
404
411
|
}
|
|
405
412
|
case 'keyboard': {
|
|
406
413
|
const rows = d.rows ?? [];
|
|
407
414
|
const resolved = Boolean(messageId && interactionResolved);
|
|
408
|
-
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, onClick: () => sendInteractiveAction(btn.payload, messageId), 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 }), "
|
|
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, onClick: () => sendInteractiveAction(btn.payload, messageId), 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));
|
|
409
416
|
}
|
|
410
417
|
default:
|
|
411
418
|
return _jsxs("span", { className: "text-xs opacity-70", children: ["[", segment.type, "]"] }, index);
|
|
@@ -415,7 +422,7 @@ export default function Sandbox() {
|
|
|
415
422
|
const handleSendMessage = (text, segments) => {
|
|
416
423
|
if (!canExecute || !hasRenderableSegments(segments))
|
|
417
424
|
return;
|
|
418
|
-
const newMessage = { id: `msg_${Date.now()}`, type: 'sent', channelType: activeChannel.type, channelId: activeChannel.id, channelName: activeChannel.name, senderId: 'test_user', senderName:
|
|
425
|
+
const newMessage = { id: `msg_${Date.now()}`, type: 'sent', channelType: activeChannel.type, channelId: activeChannel.id, channelName: activeChannel.name, senderId: 'test_user', senderName: sandboxText(locale, "测试用户"), content: segments, timestamp: Date.now() };
|
|
419
426
|
setMessages((prev) => [...prev, newMessage]);
|
|
420
427
|
setInputText('');
|
|
421
428
|
setPreviewSegments([]);
|
|
@@ -444,7 +451,7 @@ export default function Sandbox() {
|
|
|
444
451
|
setChannels((sessions) => sessions.map((session) => session.id === activeChannel.id && session.type === activeChannel.type ? next : session));
|
|
445
452
|
};
|
|
446
453
|
const addSession = () => {
|
|
447
|
-
const label = newSessionName.trim() ||
|
|
454
|
+
const label = newSessionName.trim() || sandboxText(locale, "未命名试验");
|
|
448
455
|
const id = `${newSessionScope}-${Date.now().toString(36)}`;
|
|
449
456
|
const session = {
|
|
450
457
|
id, name: label, type: newSessionScope, unread: 0,
|
|
@@ -500,18 +507,18 @@ export default function Sandbox() {
|
|
|
500
507
|
const currentTaskMessage = currentTask?.sourceMessageId
|
|
501
508
|
? channelMessages.find((message) => message.id === currentTask.sourceMessageId && message.type === 'sent')
|
|
502
509
|
: undefined;
|
|
503
|
-
const scopeLabel = activeChannel.type === 'private' ?
|
|
510
|
+
const scopeLabel = activeChannel.type === 'private' ? sandboxText(locale, "单用户") : activeChannel.type === 'group' ? sandboxText(locale, "群组上下文") : sandboxText(locale, "频道上下文");
|
|
504
511
|
const runPrompt = (prompt) => handleSendMessage(prompt, [{ type: 'text', data: { text: prompt } }]);
|
|
505
512
|
const recentTraceEvents = trace?.events.slice(-8).reverse() ?? [];
|
|
506
513
|
const stopActiveTask = async () => {
|
|
507
514
|
setStoppingTask(true);
|
|
508
515
|
try {
|
|
509
|
-
const cancelled = await cancelAgentTask(sessionKey);
|
|
510
|
-
setTraceNotice(cancelled ?
|
|
516
|
+
const cancelled = await cancelAgentTask(sessionKey, locale);
|
|
517
|
+
setTraceNotice(cancelled ? sandboxText(locale, "已发送停止请求,正在等待任务结束。") : sandboxText(locale, "当前会话没有运行中的任务。"));
|
|
511
518
|
window.setTimeout(() => void loadTrace(true), 240);
|
|
512
519
|
}
|
|
513
520
|
catch (error) {
|
|
514
|
-
setTraceNotice(error instanceof Error ? error.message :
|
|
521
|
+
setTraceNotice(error instanceof Error ? error.message : sandboxText(locale, "无法停止任务"));
|
|
515
522
|
setShowInspector(true);
|
|
516
523
|
}
|
|
517
524
|
finally {
|
|
@@ -539,7 +546,7 @@ export default function Sandbox() {
|
|
|
539
546
|
safetyMode: activeChannel.runConfig.safetyMode,
|
|
540
547
|
approvalMode: activeChannel.runConfig.approvalMode,
|
|
541
548
|
networkAccess: activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess,
|
|
542
|
-
});
|
|
549
|
+
}, locale);
|
|
543
550
|
const url = URL.createObjectURL(new Blob([report], { type: 'text/markdown;charset=utf-8' }));
|
|
544
551
|
const link = document.createElement('a');
|
|
545
552
|
link.href = url;
|
|
@@ -549,40 +556,40 @@ export default function Sandbox() {
|
|
|
549
556
|
link.remove();
|
|
550
557
|
window.setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
551
558
|
};
|
|
552
|
-
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) }), 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 ?
|
|
553
|
-
return (_jsxs("section", { className: "agent-playground-shell", children: [_jsxs("div", { className: "agent-playground-mobilebar", children: [_jsxs("button", { type: "button", "aria-expanded": showChannelList, onClick: () => setShowChannelList(!showChannelList), children: [_jsx(MessageSquare, { size: 17 }), "
|
|
559
|
+
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
|
+
return (_jsxs("section", { className: "agent-playground-shell", 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, 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: "Try a chat" })] })] }), _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("div", { className: "agent-playground-session-list", children: channels.map((channel) => {
|
|
554
561
|
const isActive = activeChannel.id === channel.id && activeChannel.type === channel.type;
|
|
555
|
-
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' ?
|
|
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}`));
|
|
556
563
|
}) }), _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')
|
|
557
|
-
addSession(); }, placeholder: "
|
|
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, "新建测试会话")] })) }), _jsxs("div", { className: "agent-playground-endpoint", children: [_jsx("span", { children: 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) }), _jsxs("div", { children: [_jsxs("div", { className: "agent-playground-run-title", children: [_jsx("h1", { children: activeChannel.name }), _jsx("span", { children: scopeLabel })] }), _jsx("code", { children: sessionKey })] })] }), _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, _jsxs("a", { href: agentStudioPath(sessionKey), children: [_jsx(ExternalLink, { size: 14 }), "Agent Studio"] }), _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, 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 }) })] })] }), 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, "知道了") })] })), 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", { 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", { value: activeChannel.runConfig.safetyMode, onChange: (event) => {
|
|
558
565
|
const safetyMode = event.target.value;
|
|
559
566
|
updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) });
|
|
560
|
-
}, children: [_jsx("option", { value: "read-only", children: "
|
|
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] }))] })), _jsx("section", { className: "agent-playground-conversation", "aria-label": sandboxText(locale, "Agent 对话"), children: _jsx("div", { className: "agent-playground-message-scroll", children: 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) => {
|
|
561
568
|
const isApproval = msg.type === 'received' && msg.content.some((segment) => segment.type === 'keyboard');
|
|
562
|
-
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 ?
|
|
563
|
-
}), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] })) }) }), _jsxs("section", { className: "agent-playground-composer", "aria-label": "
|
|
569
|
+
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 : sandboxText(locale, "你") }), isApproval && _jsx("span", { children: "approval required" }), _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) })] })] }), currentTaskMessage?.id === msg.id && inlineRunCard] }, msg.id));
|
|
570
|
+
}), !currentTaskMessage && inlineRunCard, _jsx("div", { ref: messagesEndRef })] })) }) }), _jsxs("section", { className: "agent-playground-composer", "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') {
|
|
564
571
|
e.preventDefault();
|
|
565
572
|
commitMediaUrl();
|
|
566
|
-
} } }), _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 }), "
|
|
573
|
+
} } }), _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()
|
|
567
574
|
? _jsx(MarkdownContent, { text: inputText })
|
|
568
|
-
: _jsx("span", { className: "sandbox-markdown-preview-empty", children: "
|
|
569
|
-
handleSendMessage(c.text, c.segments); }, disabled: !canExecute || !hasRenderableSegments(previewSegments), children: [_jsx(Send, { size: 16 }), "
|
|
570
|
-
const item = presentTraceEvent(event);
|
|
571
|
-
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(
|
|
572
|
-
}) })) : (_jsxs("div", { className: "agent-playground-trace-empty", children: [_jsx(Activity, { size: 18 }), _jsx("span", { children: "
|
|
575
|
+
: _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" })] }), traceLoading && !trace ? (_jsxs("div", { className: "agent-playground-trace-loading", children: [_jsx("i", {}), _jsx("i", {}), _jsx("i", {})] })) : traceNotice && !trace?.events.length ? (_jsxs("div", { className: "agent-playground-trace-notice", children: [_jsx(CircleAlert, { size: 16 }), _jsx("span", { children: traceNotice })] })) : recentTraceEvents.length ? (_jsx("div", { className: "agent-playground-trace-list", children: recentTraceEvents.map((event) => {
|
|
577
|
+
const item = presentTraceEvent(event, locale);
|
|
578
|
+
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
|
+
}) })) : (_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) => {
|
|
573
580
|
const ArtifactIcon = artifact.kind === 'file-change' ? FileDiff : artifact.kind === 'test' ? FlaskConical : Terminal;
|
|
574
581
|
const expanded = expandedArtifact === artifact.id;
|
|
575
|
-
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 ||
|
|
576
|
-
}) })) : _jsxs("div", { className: "agent-playground-artifact-empty", children: [_jsx(FileDiff, { size: 18 }), _jsx("span", { children: "Agent
|
|
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: agentStudioPath(sessionKey), children: [_jsxs("span", { children: [_jsx(ExternalLink, { size: 15 }), sandboxText(locale, "在 Agent Studio 中完整诊断")] }), _jsx("code", { children: sessionKey })] })] }), showInspector && _jsx("div", { className: "agent-playground-inspector-overlay", onClick: () => setShowInspector(false) })] }));
|
|
577
584
|
}
|
|
578
|
-
function taskStatusLabel(status) {
|
|
585
|
+
function taskStatusLabel(status, locale = 'zh-CN') {
|
|
579
586
|
if (status === 'running')
|
|
580
|
-
return
|
|
587
|
+
return sandboxText(locale, "Agent 运行中");
|
|
581
588
|
if (status === 'completed')
|
|
582
|
-
return
|
|
589
|
+
return sandboxText(locale, "最近任务已完成");
|
|
583
590
|
if (status === 'failed')
|
|
584
|
-
return
|
|
585
|
-
return
|
|
591
|
+
return sandboxText(locale, "最近任务失败");
|
|
592
|
+
return sandboxText(locale, "最近任务已取消");
|
|
586
593
|
}
|
|
587
594
|
function messageText(segments) {
|
|
588
595
|
return segments.map((segment) => {
|
|
@@ -595,23 +602,23 @@ function messageText(segments) {
|
|
|
595
602
|
return `[${segment.type}]`;
|
|
596
603
|
}).join(' ').trim();
|
|
597
604
|
}
|
|
598
|
-
function formatDuration(durationMs) {
|
|
605
|
+
function formatDuration(durationMs, locale = 'zh-CN') {
|
|
599
606
|
if (durationMs < 1_000)
|
|
600
|
-
return `${durationMs.toLocaleString()} ms`;
|
|
607
|
+
return `${durationMs.toLocaleString(locale)} ms`;
|
|
601
608
|
if (durationMs < 60_000)
|
|
602
609
|
return `${(durationMs / 1_000).toFixed(durationMs < 10_000 ? 1 : 0)} s`;
|
|
603
610
|
return `${Math.floor(durationMs / 60_000)}m ${Math.round((durationMs % 60_000) / 1_000)}s`;
|
|
604
611
|
}
|
|
605
|
-
function runStepStatusLabel(status) {
|
|
612
|
+
function runStepStatusLabel(status, locale = 'zh-CN') {
|
|
606
613
|
if (status === 'running')
|
|
607
|
-
return
|
|
614
|
+
return sandboxText(locale, "进行中");
|
|
608
615
|
if (status === 'completed')
|
|
609
|
-
return
|
|
616
|
+
return sandboxText(locale, "完成");
|
|
610
617
|
if (status === 'denied')
|
|
611
|
-
return
|
|
618
|
+
return sandboxText(locale, "已拒绝");
|
|
612
619
|
if (status === 'cancelled')
|
|
613
|
-
return
|
|
614
|
-
return
|
|
620
|
+
return sandboxText(locale, "已取消");
|
|
621
|
+
return sandboxText(locale, "失败");
|
|
615
622
|
}
|
|
616
623
|
function safeFileName(value) {
|
|
617
624
|
return value.trim().replace(/[^\p{L}\p{N}._-]+/gu, '-').replace(/^-+|-+$/gu, '').slice(0, 48) || 'session';
|