@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,3 +1,4 @@
|
|
|
1
|
+
import { sandboxText, type SandboxLocale } from './messages.js';
|
|
1
2
|
import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
|
2
3
|
import {
|
|
3
4
|
cn,
|
|
@@ -50,6 +51,8 @@ type Channel = PlaygroundSession
|
|
|
50
51
|
interface Face { id: number; emojiId: number; stickerId: number; emojiType: string; name: string; describe: string; png: boolean; apng: boolean; lottie: boolean; }
|
|
51
52
|
|
|
52
53
|
export default function Sandbox() {
|
|
54
|
+
const [locale, setLocale] = useState<SandboxLocale>('zh-CN')
|
|
55
|
+
const localeRef = useRef<SandboxLocale>('zh-CN')
|
|
53
56
|
const [initialState] = useState(() => loadPlaygroundState())
|
|
54
57
|
const [messages, setMessages] = useState<Message[]>(() => [...initialState.messages])
|
|
55
58
|
const [channels, setChannels] = useState<Channel[]>(() => [...initialState.sessions])
|
|
@@ -79,10 +82,10 @@ export default function Sandbox() {
|
|
|
79
82
|
const [atPopoverPosition, setAtPopoverPosition] = useState<{ top: number; left: number } | null>(null)
|
|
80
83
|
const [atSearchQuery, setAtSearchQuery] = useState('')
|
|
81
84
|
const [faceSearchQuery, setFaceSearchQuery] = useState('')
|
|
82
|
-
const
|
|
83
|
-
{ id: 'actor-owner', name:
|
|
84
|
-
{ id: 'actor-operator', name:
|
|
85
|
-
]
|
|
85
|
+
const atSuggestions = [
|
|
86
|
+
{ id: 'actor-owner', name: sandboxText(locale, "当前用户") }, { id: 'actor-reviewer', name: sandboxText(locale, "审阅者") },
|
|
87
|
+
{ id: 'actor-operator', name: sandboxText(locale, "协作者") }, { id: 'actor-bot', name: 'Sandbox Agent' }
|
|
88
|
+
]
|
|
86
89
|
const [previewSegments, setPreviewSegments] = useState<MessageSegment[]>([])
|
|
87
90
|
const [composerMode, setComposerMode] = useState<'write' | 'preview'>('write')
|
|
88
91
|
const [showChannelList, setShowChannelList] = useState(false)
|
|
@@ -107,9 +110,9 @@ export default function Sandbox() {
|
|
|
107
110
|
)
|
|
108
111
|
const traceSummary = useMemo(() => summarizeTrace(trace), [trace])
|
|
109
112
|
const taskRuns = useMemo(() => deriveTaskRuns(trace), [trace])
|
|
110
|
-
const workbenchArtifacts = useMemo(() => deriveWorkbenchArtifacts(trace), [trace])
|
|
113
|
+
const workbenchArtifacts = useMemo(() => deriveWorkbenchArtifacts(trace, locale), [trace, locale])
|
|
111
114
|
const currentTask = taskRuns.find((run) => run.status === 'running') ?? taskRuns[0]
|
|
112
|
-
const currentRunSteps = useMemo(() => deriveAgentRunSteps(trace, currentTask), [currentTask, trace])
|
|
115
|
+
const currentRunSteps = useMemo(() => deriveAgentRunSteps(trace, currentTask, locale), [currentTask, trace, locale])
|
|
113
116
|
const currentRunArtifacts = useMemo(
|
|
114
117
|
() => workbenchArtifacts.filter((artifact) => (
|
|
115
118
|
artifact.turnId === currentTask?.turnId && artifact.runtimeId === currentTask?.runtimeId
|
|
@@ -138,19 +141,22 @@ export default function Sandbox() {
|
|
|
138
141
|
useEffect(() => { fetchFaceList() }, [])
|
|
139
142
|
|
|
140
143
|
const handleInboundPayload = (data: {
|
|
141
|
-
type: string; id: string; content?: unknown; endpoint?: string; workingDirectory?: string; canExecute?: boolean;
|
|
144
|
+
type: string; id: string; locale?: unknown; content?: unknown; endpoint?: string; workingDirectory?: string; canExecute?: boolean;
|
|
142
145
|
shellIsolation?: { available?: boolean; provider?: string; message?: string }; timestamp: number;
|
|
143
146
|
messageId?: string; bot?: string;
|
|
144
147
|
}) => {
|
|
148
|
+
const locale = data.type === 'ready' && data.locale === 'en' ? 'en' : data.type === 'ready' ? 'zh-CN' : localeRef.current
|
|
145
149
|
if (data.type === 'ready') {
|
|
150
|
+
localeRef.current = locale
|
|
151
|
+
setLocale(locale)
|
|
146
152
|
setBotName(data.endpoint || data.bot || 'sandbox-bot')
|
|
147
153
|
setCanExecute(data.canExecute !== false)
|
|
148
|
-
setTransportNotice(data.canExecute === false ?
|
|
154
|
+
setTransportNotice(data.canExecute === false ? sandboxText(locale, "当前 Token 只有演示权限,任务运行已禁用。") : null)
|
|
149
155
|
if (data.shellIsolation) {
|
|
150
156
|
setShellIsolation({
|
|
151
157
|
available: data.shellIsolation.available === true,
|
|
152
158
|
provider: data.shellIsolation.provider || 'docker',
|
|
153
|
-
message: data.shellIsolation.message ||
|
|
159
|
+
message: data.shellIsolation.message || sandboxText(locale, "未检测到隔离执行环境"),
|
|
154
160
|
})
|
|
155
161
|
}
|
|
156
162
|
if (data.workingDirectory?.trim()) {
|
|
@@ -166,8 +172,8 @@ export default function Sandbox() {
|
|
|
166
172
|
}
|
|
167
173
|
if (data.type === 'error') {
|
|
168
174
|
const notice = Array.isArray(data.content)
|
|
169
|
-
? String((data.content[0] as { data?: { text?: unknown } } | undefined)?.data?.text ??
|
|
170
|
-
: String(data.content ??
|
|
175
|
+
? String((data.content[0] as { data?: { text?: unknown } } | undefined)?.data?.text ?? sandboxText(locale, "Sandbox 拒绝了本次操作"))
|
|
176
|
+
: String(data.content ?? sandboxText(locale, "Sandbox 拒绝了本次操作"))
|
|
171
177
|
setTransportNotice(notice)
|
|
172
178
|
return
|
|
173
179
|
}
|
|
@@ -185,10 +191,10 @@ export default function Sandbox() {
|
|
|
185
191
|
|
|
186
192
|
const channelType: Channel['type'] = data.type === 'group' || data.type === 'channel' ? data.type : 'private'
|
|
187
193
|
const channelName = channelType === 'private'
|
|
188
|
-
?
|
|
194
|
+
? sandboxText(locale, "会话 {0}", [data.id])
|
|
189
195
|
: channelType === 'group'
|
|
190
|
-
?
|
|
191
|
-
:
|
|
196
|
+
? sandboxText(locale, "群组场景 {0}", [data.id])
|
|
197
|
+
: sandboxText(locale, "频道场景 {0}", [data.id])
|
|
192
198
|
|
|
193
199
|
setChannels((prev) => {
|
|
194
200
|
if (prev.some((c) => c.id === data.id && c.type === channelType)) return prev
|
|
@@ -210,7 +216,7 @@ export default function Sandbox() {
|
|
|
210
216
|
const sendInteractiveAction = (payload: string, messageId?: string) => {
|
|
211
217
|
const ws = wsRef.current
|
|
212
218
|
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
213
|
-
setTransportNotice(
|
|
219
|
+
setTransportNotice(sandboxText(locale, "Sandbox 连接尚未就绪,审批选择未发送。"))
|
|
214
220
|
return
|
|
215
221
|
}
|
|
216
222
|
const segments: MessageSegment[] = [{ type: 'action', data: { id: payload, payload } }]
|
|
@@ -229,7 +235,7 @@ export default function Sandbox() {
|
|
|
229
235
|
: message))
|
|
230
236
|
}
|
|
231
237
|
} catch {
|
|
232
|
-
setTransportNotice(
|
|
238
|
+
setTransportNotice(sandboxText(locale, "审批选择发送失败,请等待连接恢复后重试。"))
|
|
233
239
|
}
|
|
234
240
|
}
|
|
235
241
|
|
|
@@ -329,12 +335,13 @@ export default function Sandbox() {
|
|
|
329
335
|
useEffect(() => { setPreviewSegments(inputText.trim() ? parseTextToSegments(inputText) : []) }, [inputText])
|
|
330
336
|
|
|
331
337
|
const loadTrace = useCallback(async (quiet = false) => {
|
|
338
|
+
const locale = localeRef.current
|
|
332
339
|
if (!quiet) setTraceLoading(true)
|
|
333
340
|
try {
|
|
334
341
|
const current = traceRef.current?.sessionKey === sessionKey ? traceRef.current : null
|
|
335
|
-
let incoming = await fetchAgentTrace(sessionKey, quiet ? current?.latestSequence ?? 0 : 0)
|
|
342
|
+
let incoming = await fetchAgentTrace(sessionKey, quiet ? current?.latestSequence ?? 0 : 0, locale)
|
|
336
343
|
if (quiet && current?.runtimeId && incoming.runtimeId && current.runtimeId !== incoming.runtimeId) {
|
|
337
|
-
incoming = await fetchAgentTrace(sessionKey, 0)
|
|
344
|
+
incoming = await fetchAgentTrace(sessionKey, 0, locale)
|
|
338
345
|
}
|
|
339
346
|
const merged = mergeTraceSnapshot(current, incoming)
|
|
340
347
|
traceRef.current = merged
|
|
@@ -342,7 +349,7 @@ export default function Sandbox() {
|
|
|
342
349
|
saveCachedAgentTrace(merged)
|
|
343
350
|
setTraceNotice(null)
|
|
344
351
|
} catch (error) {
|
|
345
|
-
setTraceNotice(error instanceof Error ? error.message :
|
|
352
|
+
setTraceNotice(error instanceof Error ? error.message : sandboxText(locale, "Agent Trace 暂不可用"))
|
|
346
353
|
} finally {
|
|
347
354
|
if (!quiet) setTraceLoading(false)
|
|
348
355
|
}
|
|
@@ -411,7 +418,7 @@ export default function Sandbox() {
|
|
|
411
418
|
case 'md':
|
|
412
419
|
return <MarkdownContent key={index} text={String(d.text ?? d.content ?? '')} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
413
420
|
case 'html':
|
|
414
|
-
return <HtmlMessage key={index} html={String(d.html ?? '')} />
|
|
421
|
+
return <HtmlMessage locale={locale} key={index} html={String(d.html ?? '')} />
|
|
415
422
|
case 'code':
|
|
416
423
|
return <CodeBlock key={index} code={String(d.code ?? d.text ?? d.content ?? '')} language={String(d.language ?? d.lang ?? '')} />
|
|
417
424
|
case 'mention':
|
|
@@ -420,13 +427,13 @@ export default function Sandbox() {
|
|
|
420
427
|
case 'face':
|
|
421
428
|
return <img key={index} 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 ?? '')} />
|
|
422
429
|
case 'dice':
|
|
423
|
-
return <span key={index} className="inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5">🎲 {d.result != null ?
|
|
430
|
+
return <span key={index} className="inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5">🎲 {d.result != null ? sandboxText(locale, "点数 {0}", [String(d.result)]) : sandboxText(locale, "骰子")}</span>
|
|
424
431
|
case 'rps':
|
|
425
|
-
return <span key={index} className="inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5">✊ {d.result != null ?
|
|
432
|
+
return <span key={index} className="inline-flex items-center px-1.5 py-0.5 rounded bg-secondary text-xs mx-0.5">✊ {d.result != null ? sandboxText(locale, "结果 {0}", [String(d.result)]) : sandboxText(locale, "猜拳")}</span>
|
|
426
433
|
case 'image': {
|
|
427
434
|
const raw = pickMediaRawUrl(d)
|
|
428
435
|
const src = resolveMediaSrc(raw, 'image')
|
|
429
|
-
if (!src) return <span key={index} className="text-xs opacity-70">[图片]</span>
|
|
436
|
+
if (!src) return <span key={index} className="text-xs opacity-70">{sandboxText(locale, "[图片]")}</span>
|
|
430
437
|
return (
|
|
431
438
|
// resolveMediaSrc allowlists non-executable URL schemes and image data MIME types.
|
|
432
439
|
// lgtm[js/xss,js/client-side-unvalidated-url-redirection]
|
|
@@ -439,7 +446,7 @@ export default function Sandbox() {
|
|
|
439
446
|
case 'video': {
|
|
440
447
|
const raw = pickMediaRawUrl(d)
|
|
441
448
|
const src = resolveMediaSrc(raw, 'video')
|
|
442
|
-
if (!src) return <span key={index} className="text-xs opacity-70">[视频无地址]</span>
|
|
449
|
+
if (!src) return <span key={index} className="text-xs opacity-70">{sandboxText(locale, "[视频无地址]")}</span>
|
|
443
450
|
return (
|
|
444
451
|
// resolveMediaSrc allowlists non-executable URL schemes and video data MIME types.
|
|
445
452
|
// lgtm[js/xss,js/client-side-unvalidated-url-redirection]
|
|
@@ -457,7 +464,7 @@ export default function Sandbox() {
|
|
|
457
464
|
case 'record': {
|
|
458
465
|
const raw = pickMediaRawUrl(d)
|
|
459
466
|
const src = resolveMediaSrc(raw, 'audio')
|
|
460
|
-
if (!src) return <span key={index} className="text-xs opacity-70">[音频无地址]</span>
|
|
467
|
+
if (!src) return <span key={index} className="text-xs opacity-70">{sandboxText(locale, "[音频无地址]")}</span>
|
|
461
468
|
return (
|
|
462
469
|
// resolveMediaSrc allowlists non-executable URL schemes and audio data MIME types.
|
|
463
470
|
// lgtm[js/xss,js/client-side-unvalidated-url-redirection]
|
|
@@ -473,12 +480,12 @@ export default function Sandbox() {
|
|
|
473
480
|
case 'reply':
|
|
474
481
|
return (
|
|
475
482
|
<div key={index} className="mb-1 rounded-md border border-dashed px-2 py-1 text-xs opacity-90">
|
|
476
|
-
↩ 引用消息 #{String(d.message_id ?? d.id ?? '')}
|
|
483
|
+
{sandboxText(locale, "↩ 引用消息 #")}{String(d.message_id ?? d.id ?? '')}
|
|
477
484
|
</div>
|
|
478
485
|
)
|
|
479
486
|
case 'forward': {
|
|
480
487
|
const messages = d.messages as Array<Array<{ type?: string; data?: Record<string, unknown> }>> | undefined
|
|
481
|
-
const title = String(d.title ??
|
|
488
|
+
const title = String(d.title ?? sandboxText(locale, "聊天记录"))
|
|
482
489
|
return (
|
|
483
490
|
<div key={index} className="my-1 rounded-md border bg-background/40 px-2 py-2 text-xs space-y-1">
|
|
484
491
|
<div className="font-medium">📨 {title}</div>
|
|
@@ -493,10 +500,10 @@ export default function Sandbox() {
|
|
|
493
500
|
))}
|
|
494
501
|
</div>
|
|
495
502
|
))}
|
|
496
|
-
{messages.length > 3 && <div className="opacity-60"
|
|
503
|
+
{messages.length > 3 && <div className="opacity-60">{sandboxText(locale, "…共")}{messages.length} {sandboxText(locale, "条")}</div>}
|
|
497
504
|
</div>
|
|
498
505
|
) : (
|
|
499
|
-
<div className="opacity-70">[合并转发]</div>
|
|
506
|
+
<div className="opacity-70">{sandboxText(locale, "[合并转发]")}</div>
|
|
500
507
|
)}
|
|
501
508
|
</div>
|
|
502
509
|
)
|
|
@@ -524,7 +531,7 @@ export default function Sandbox() {
|
|
|
524
531
|
))}
|
|
525
532
|
</div>
|
|
526
533
|
))}
|
|
527
|
-
{resolved && <small><Check size={12}
|
|
534
|
+
{resolved && <small><Check size={12} />{sandboxText(locale, "已提交本次选择")}</small>}
|
|
528
535
|
</div>
|
|
529
536
|
)
|
|
530
537
|
}
|
|
@@ -536,7 +543,7 @@ export default function Sandbox() {
|
|
|
536
543
|
|
|
537
544
|
const handleSendMessage = (text: string, segments: MessageSegment[]) => {
|
|
538
545
|
if (!canExecute || !hasRenderableSegments(segments)) return
|
|
539
|
-
const newMessage: Message = { id: `msg_${Date.now()}`, type: 'sent', channelType: activeChannel.type, channelId: activeChannel.id, channelName: activeChannel.name, senderId: 'test_user', senderName:
|
|
546
|
+
const newMessage: Message = { 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() }
|
|
540
547
|
setMessages((prev) => [...prev, newMessage]); setInputText(''); setPreviewSegments([]); setComposerMode('write')
|
|
541
548
|
editorRef.current?.clear()
|
|
542
549
|
// Stamp type+id so Host sandbox endpoint preserves channel context for outbound replies.
|
|
@@ -565,7 +572,7 @@ export default function Sandbox() {
|
|
|
565
572
|
setChannels((sessions) => sessions.map((session) => session.id === activeChannel.id && session.type === activeChannel.type ? next : session))
|
|
566
573
|
}
|
|
567
574
|
const addSession = () => {
|
|
568
|
-
const label = newSessionName.trim() ||
|
|
575
|
+
const label = newSessionName.trim() || sandboxText(locale, "未命名试验")
|
|
569
576
|
const id = `${newSessionScope}-${Date.now().toString(36)}`
|
|
570
577
|
const session: Channel = {
|
|
571
578
|
id, name: label, type: newSessionScope, unread: 0,
|
|
@@ -600,17 +607,17 @@ export default function Sandbox() {
|
|
|
600
607
|
const currentTaskMessage = currentTask?.sourceMessageId
|
|
601
608
|
? channelMessages.find((message) => message.id === currentTask.sourceMessageId && message.type === 'sent')
|
|
602
609
|
: undefined
|
|
603
|
-
const scopeLabel = activeChannel.type === 'private' ?
|
|
610
|
+
const scopeLabel = activeChannel.type === 'private' ? sandboxText(locale, "单用户") : activeChannel.type === 'group' ? sandboxText(locale, "群组上下文") : sandboxText(locale, "频道上下文")
|
|
604
611
|
const runPrompt = (prompt: string) => handleSendMessage(prompt, [{ type: 'text', data: { text: prompt } }])
|
|
605
612
|
const recentTraceEvents = trace?.events.slice(-8).reverse() ?? []
|
|
606
613
|
const stopActiveTask = async () => {
|
|
607
614
|
setStoppingTask(true)
|
|
608
615
|
try {
|
|
609
|
-
const cancelled = await cancelAgentTask(sessionKey)
|
|
610
|
-
setTraceNotice(cancelled ?
|
|
616
|
+
const cancelled = await cancelAgentTask(sessionKey, locale)
|
|
617
|
+
setTraceNotice(cancelled ? sandboxText(locale, "已发送停止请求,正在等待任务结束。") : sandboxText(locale, "当前会话没有运行中的任务。"))
|
|
611
618
|
window.setTimeout(() => void loadTrace(true), 240)
|
|
612
619
|
} catch (error) {
|
|
613
|
-
setTraceNotice(error instanceof Error ? error.message :
|
|
620
|
+
setTraceNotice(error instanceof Error ? error.message : sandboxText(locale, "无法停止任务"))
|
|
614
621
|
setShowInspector(true)
|
|
615
622
|
} finally {
|
|
616
623
|
setStoppingTask(false)
|
|
@@ -634,7 +641,7 @@ export default function Sandbox() {
|
|
|
634
641
|
safetyMode: activeChannel.runConfig.safetyMode,
|
|
635
642
|
approvalMode: activeChannel.runConfig.approvalMode,
|
|
636
643
|
networkAccess: activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess,
|
|
637
|
-
})
|
|
644
|
+
}, locale)
|
|
638
645
|
const url = URL.createObjectURL(new Blob([report], { type: 'text/markdown;charset=utf-8' }))
|
|
639
646
|
const link = document.createElement('a')
|
|
640
647
|
link.href = url
|
|
@@ -651,24 +658,24 @@ export default function Sandbox() {
|
|
|
651
658
|
<span className="agent-playground-inline-run-icon"><ListChecks size={17} /></span>
|
|
652
659
|
<div className="agent-playground-inline-run-copy">
|
|
653
660
|
<span>{currentTask.status === 'running' ? 'Live agent run' : 'Agent run summary'}</span>
|
|
654
|
-
<h3>{taskStatusLabel(currentTask.status)}</h3>
|
|
661
|
+
<h3>{taskStatusLabel(currentTask.status, locale)}</h3>
|
|
655
662
|
{currentTaskMessage && <p>{messageText(currentTaskMessage.content)}</p>}
|
|
656
663
|
</div>
|
|
657
664
|
<div className="agent-playground-inline-run-actions">
|
|
658
665
|
{currentTask.status === 'running' ? (
|
|
659
|
-
<button type="button" className="is-stop" onClick={() => void stopActiveTask()} disabled={stoppingTask}><Square size={12} />{stoppingTask ?
|
|
666
|
+
<button type="button" className="is-stop" onClick={() => void stopActiveTask()} disabled={stoppingTask}><Square size={12} />{stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")}</button>
|
|
660
667
|
) : currentTaskMessage ? (
|
|
661
|
-
<button type="button" onClick={retryCurrentTask}><RotateCcw size={13}
|
|
668
|
+
<button type="button" onClick={retryCurrentTask}><RotateCcw size={13} />{sandboxText(locale, "重试")}</button>
|
|
662
669
|
) : null}
|
|
663
|
-
<button type="button" onClick={exportCurrentRun} title="导出 Markdown 运行报告"><FileDown size={13}
|
|
670
|
+
<button type="button" onClick={exportCurrentRun} title={sandboxText(locale, "导出 Markdown 运行报告")}><FileDown size={13} />{sandboxText(locale, "导出")}</button>
|
|
664
671
|
</div>
|
|
665
672
|
</div>
|
|
666
673
|
<dl className="agent-playground-inline-run-metrics">
|
|
667
|
-
<div><dt
|
|
668
|
-
<div><dt
|
|
669
|
-
<div><dt
|
|
670
|
-
<div><dt>Token</dt><dd>{currentTask.tokenCount.toLocaleString()}</dd></div>
|
|
671
|
-
<div className={cn(currentTask.problemCount > 0 && 'has-problem')}><dt
|
|
674
|
+
<div><dt>{sandboxText(locale, "耗时")}</dt><dd>{currentTask.durationMs === undefined ? sandboxText(locale, "进行中") : formatDuration(currentTask.durationMs, locale)}</dd></div>
|
|
675
|
+
<div><dt>{sandboxText(locale, "步骤")}</dt><dd>{currentRunSteps.length}</dd></div>
|
|
676
|
+
<div><dt>{sandboxText(locale, "工具")}</dt><dd>{currentTask.toolCount}</dd></div>
|
|
677
|
+
<div><dt>Token</dt><dd>{currentTask.tokenCount.toLocaleString(locale)}</dd></div>
|
|
678
|
+
<div className={cn(currentTask.problemCount > 0 && 'has-problem')}><dt>{sandboxText(locale, "异常")}</dt><dd>{currentTask.problemCount}</dd></div>
|
|
672
679
|
</dl>
|
|
673
680
|
{inlineRunExpanded && (
|
|
674
681
|
currentRunSteps.length > 0 ? (
|
|
@@ -677,18 +684,18 @@ export default function Sandbox() {
|
|
|
677
684
|
<li key={step.id} className={cn(`is-${step.status}`)}>
|
|
678
685
|
<i aria-hidden="true" />
|
|
679
686
|
<div><strong>{step.title}</strong>{step.detail && <small>{step.detail}</small>}</div>
|
|
680
|
-
<span>{step.durationMs === undefined ? runStepStatusLabel(step.status) : formatDuration(step.durationMs)}</span>
|
|
687
|
+
<span>{step.durationMs === undefined ? runStepStatusLabel(step.status, locale) : formatDuration(step.durationMs, locale)}</span>
|
|
681
688
|
</li>
|
|
682
689
|
))}
|
|
683
690
|
</ol>
|
|
684
|
-
) : <div className="agent-playground-inline-run-empty"
|
|
691
|
+
) : <div className="agent-playground-inline-run-empty">{sandboxText(locale, "正在等待第一条运行事件…")}</div>
|
|
685
692
|
)}
|
|
686
693
|
<footer>
|
|
687
694
|
<button type="button" aria-expanded={inlineRunExpanded} onClick={() => setInlineRunExpanded((expanded) => !expanded)}>
|
|
688
|
-
<ChevronDown size={13} />{inlineRunExpanded ?
|
|
695
|
+
<ChevronDown size={13} />{inlineRunExpanded ? sandboxText(locale, "收起步骤") : sandboxText(locale, "查看 {0} 个步骤", [currentRunSteps.length])}
|
|
689
696
|
</button>
|
|
690
697
|
<button type="button" onClick={() => { setInspectorView(currentRunArtifacts.length > 0 ? 'artifacts' : 'runs'); setShowInspector(true) }}>
|
|
691
|
-
{currentRunArtifacts.length > 0 ?
|
|
698
|
+
{currentRunArtifacts.length > 0 ? sandboxText(locale, "{0} 个变更与产物", [currentRunArtifacts.length]) : sandboxText(locale, "打开运行检查器")}<PanelRight size={13} />
|
|
692
699
|
</button>
|
|
693
700
|
</footer>
|
|
694
701
|
</article>
|
|
@@ -697,25 +704,25 @@ export default function Sandbox() {
|
|
|
697
704
|
return (
|
|
698
705
|
<section className="agent-playground-shell">
|
|
699
706
|
<div className="agent-playground-mobilebar">
|
|
700
|
-
<button type="button" aria-expanded={showChannelList} onClick={() => setShowChannelList(!showChannelList)}><MessageSquare size={17}
|
|
701
|
-
<strong>
|
|
702
|
-
<button type="button" aria-expanded={showInspector} onClick={() => setShowInspector(!showInspector)}><PanelRight size={17}
|
|
707
|
+
<button type="button" aria-expanded={showChannelList} onClick={() => setShowChannelList(!showChannelList)}><MessageSquare size={17} />{sandboxText(locale, "测试会话")}</button>
|
|
708
|
+
<strong>{sandboxText(locale, "试聊一下")}</strong>
|
|
709
|
+
<button type="button" aria-expanded={showInspector} onClick={() => setShowInspector(!showInspector)}><PanelRight size={17} />{sandboxText(locale, "检查器")}</button>
|
|
703
710
|
</div>
|
|
704
711
|
|
|
705
|
-
<nav className={cn("channel-sidebar agent-playground-sessions", showChannelList && "show")} aria-label="测试会话">
|
|
712
|
+
<nav className={cn("channel-sidebar agent-playground-sessions", showChannelList && "show")} aria-label={sandboxText(locale, "测试会话")}>
|
|
706
713
|
<div className="agent-playground-brand">
|
|
707
714
|
<div className="flex justify-between items-center">
|
|
708
715
|
<div className="flex items-center gap-2">
|
|
709
716
|
<span className="agent-playground-mark"><Sparkles size={16} /></span>
|
|
710
|
-
<div><h2>
|
|
717
|
+
<div><h2>{sandboxText(locale, "试聊一下")}</h2><small>Try a chat</small></div>
|
|
711
718
|
</div>
|
|
712
|
-
<span className={cn("agent-playground-connection", connected && "is-online")} title={connected ?
|
|
719
|
+
<span className={cn("agent-playground-connection", connected && "is-online")} title={connected ? sandboxText(locale, "Sandbox WebSocket 已连接") : sandboxText(locale, "正在重连 Sandbox WebSocket")}>
|
|
713
720
|
{connected ? <Wifi size={12} /> : <WifiOff size={12} />}
|
|
714
721
|
</span>
|
|
715
722
|
</div>
|
|
716
723
|
</div>
|
|
717
724
|
|
|
718
|
-
<div className="agent-playground-section-label"><span
|
|
725
|
+
<div className="agent-playground-section-label"><span>{sandboxText(locale, "测试会话")}</span><span>{channels.length}</span></div>
|
|
719
726
|
<div className="agent-playground-session-list">
|
|
720
727
|
{channels.map((channel) => {
|
|
721
728
|
const isActive = activeChannel.id === channel.id && activeChannel.type === channel.type
|
|
@@ -724,7 +731,7 @@ export default function Sandbox() {
|
|
|
724
731
|
<span className="agent-playground-session-icon">{getChannelIcon(channel.type)}</span>
|
|
725
732
|
<div className="flex-1 min-w-0">
|
|
726
733
|
<div className="text-sm font-medium truncate">{channel.name}</div>
|
|
727
|
-
<div className="text-xs text-muted-foreground">{channel.type === 'private' ?
|
|
734
|
+
<div className="text-xs text-muted-foreground">{channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域")}</div>
|
|
728
735
|
</div>
|
|
729
736
|
{channel.unread > 0 && <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">{channel.unread}</span>}
|
|
730
737
|
</button>
|
|
@@ -735,25 +742,25 @@ export default function Sandbox() {
|
|
|
735
742
|
<div className="agent-playground-new-session">
|
|
736
743
|
{showNewSession ? (
|
|
737
744
|
<div className="agent-playground-new-form">
|
|
738
|
-
<input value={newSessionName} onChange={(event) => setNewSessionName(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter') addSession() }} placeholder="会话名称" autoFocus />
|
|
739
|
-
<div className="agent-playground-scope-picker" role="group" aria-label="消息作用域">
|
|
745
|
+
<input value={newSessionName} onChange={(event) => setNewSessionName(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter') addSession() }} placeholder={sandboxText(locale, "会话名称")} autoFocus />
|
|
746
|
+
<div className="agent-playground-scope-picker" role="group" aria-label={sandboxText(locale, "消息作用域")}>
|
|
740
747
|
{(['private', 'group', 'channel'] as SandboxScope[]).map((scope) => (
|
|
741
748
|
<button type="button" key={scope} aria-pressed={newSessionScope === scope} className={cn(newSessionScope === scope && 'active')} onClick={() => setNewSessionScope(scope)}>
|
|
742
|
-
{scope === 'private' ?
|
|
749
|
+
{scope === 'private' ? sandboxText(locale, "单用户") : scope === 'group' ? sandboxText(locale, "群组") : sandboxText(locale, "频道")}
|
|
743
750
|
</button>
|
|
744
751
|
))}
|
|
745
752
|
</div>
|
|
746
753
|
<div className="agent-playground-new-actions">
|
|
747
|
-
<button type="button" onClick={() => setShowNewSession(false)}
|
|
748
|
-
<button type="button" className="primary" onClick={addSession}
|
|
754
|
+
<button type="button" onClick={() => setShowNewSession(false)}>{sandboxText(locale, "取消")}</button>
|
|
755
|
+
<button type="button" className="primary" onClick={addSession}>{sandboxText(locale, "创建")}</button>
|
|
749
756
|
</div>
|
|
750
757
|
</div>
|
|
751
758
|
) : (
|
|
752
|
-
<button type="button" className="agent-playground-add" onClick={() => setShowNewSession(true)}><Plus size={15}
|
|
759
|
+
<button type="button" className="agent-playground-add" onClick={() => setShowNewSession(true)}><Plus size={15} />{sandboxText(locale, "新建测试会话")}</button>
|
|
753
760
|
)}
|
|
754
761
|
</div>
|
|
755
762
|
<div className="agent-playground-endpoint">
|
|
756
|
-
<span>{persistenceStatus === 'saved' ?
|
|
763
|
+
<span>{persistenceStatus === 'saved' ? sandboxText(locale, "会话已持久化") : sandboxText(locale, "会话保存失败")}</span>
|
|
757
764
|
<strong>{endpointId}</strong>
|
|
758
765
|
</div>
|
|
759
766
|
</nav>
|
|
@@ -772,71 +779,71 @@ export default function Sandbox() {
|
|
|
772
779
|
<div className="agent-playground-run-actions">
|
|
773
780
|
<span className={cn("agent-playground-run-state", currentTask?.status === 'running' && "is-running", currentTask?.status === 'failed' && 'has-problem')}>
|
|
774
781
|
{currentTask?.status === 'running' ? <Activity size={14} /> : <Gauge size={14} />}
|
|
775
|
-
{currentTask ? taskStatusLabel(currentTask.status) :
|
|
782
|
+
{currentTask ? taskStatusLabel(currentTask.status, locale) : sandboxText(locale, "{0} 条消息", [channelMessages.length])}
|
|
776
783
|
</span>
|
|
777
784
|
{currentTask?.status === 'running' ? (
|
|
778
|
-
<button type="button" className="agent-playground-stop" onClick={() => void stopActiveTask()} disabled={stoppingTask} aria-label="停止当前任务"><Square size={13} />{stoppingTask ?
|
|
785
|
+
<button type="button" className="agent-playground-stop" onClick={() => void stopActiveTask()} disabled={stoppingTask} aria-label={sandboxText(locale, "停止当前任务")}><Square size={13} />{stoppingTask ? sandboxText(locale, "停止中") : sandboxText(locale, "停止")}</button>
|
|
779
786
|
) : lastUserMessage ? (
|
|
780
|
-
<button type="button" onClick={retryLastTask} aria-label="重新运行上一个任务"><RotateCcw size={14}
|
|
787
|
+
<button type="button" onClick={retryLastTask} aria-label={sandboxText(locale, "重新运行上一个任务")}><RotateCcw size={14} />{sandboxText(locale, "重试")}</button>
|
|
781
788
|
) : null}
|
|
782
789
|
<a href={agentStudioPath(sessionKey)}><ExternalLink size={14} />Agent Studio</a>
|
|
783
|
-
<button type="button" className={cn(showRunSettings && 'active')} aria-expanded={showRunSettings} onClick={() => setShowRunSettings((visible) => !visible)} aria-label="配置运行环境"><SlidersHorizontal size={16} /></button>
|
|
784
|
-
<button type="button" aria-expanded={showInspector} onClick={() => setShowInspector(!showInspector)} aria-label="切换运行检查器"><PanelRight size={16} /></button>
|
|
785
|
-
<button type="button" onClick={() => setConfirmClear(true)} aria-label="清空当前会话"><Trash2 size={15} /></button>
|
|
790
|
+
<button type="button" className={cn(showRunSettings && 'active')} aria-expanded={showRunSettings} onClick={() => setShowRunSettings((visible) => !visible)} aria-label={sandboxText(locale, "配置运行环境")}><SlidersHorizontal size={16} /></button>
|
|
791
|
+
<button type="button" aria-expanded={showInspector} onClick={() => setShowInspector(!showInspector)} aria-label={sandboxText(locale, "切换运行检查器")}><PanelRight size={16} /></button>
|
|
792
|
+
<button type="button" onClick={() => setConfirmClear(true)} aria-label={sandboxText(locale, "清空当前会话")}><Trash2 size={15} /></button>
|
|
786
793
|
</div>
|
|
787
794
|
</header>
|
|
788
795
|
|
|
789
796
|
{confirmClear && (
|
|
790
797
|
<div className="agent-playground-confirm" role="alert">
|
|
791
|
-
<div><strong
|
|
792
|
-
<button type="button" onClick={() => setConfirmClear(false)}
|
|
793
|
-
<button type="button" className="danger" onClick={clearMessages}
|
|
798
|
+
<div><strong>{sandboxText(locale, "清空当前测试记录?")}</strong><span>{sandboxText(locale, "只移除“")}{activeChannel.name}{sandboxText(locale, "”在浏览器中的消息,不影响 Agent 会话存储。")}</span></div>
|
|
799
|
+
<button type="button" onClick={() => setConfirmClear(false)}>{sandboxText(locale, "取消")}</button>
|
|
800
|
+
<button type="button" className="danger" onClick={clearMessages}>{sandboxText(locale, "确认清空")}</button>
|
|
794
801
|
</div>
|
|
795
802
|
)}
|
|
796
803
|
|
|
797
804
|
{transportNotice && (
|
|
798
805
|
<div className="agent-playground-confirm" role="status">
|
|
799
|
-
<div><strong
|
|
800
|
-
<button type="button" onClick={() => setTransportNotice(null)}
|
|
806
|
+
<div><strong>{sandboxText(locale, "运行暂不可用")}</strong><span>{transportNotice}</span></div>
|
|
807
|
+
<button type="button" onClick={() => setTransportNotice(null)}>{sandboxText(locale, "知道了")}</button>
|
|
801
808
|
</div>
|
|
802
809
|
)}
|
|
803
810
|
|
|
804
811
|
{showRunSettings && (
|
|
805
|
-
<section className="agent-playground-run-settings" aria-label="运行配置">
|
|
812
|
+
<section className="agent-playground-run-settings" aria-label={sandboxText(locale, "运行配置")}>
|
|
806
813
|
<label className="agent-playground-directory-field">
|
|
807
|
-
<span><FolderOpen size={14}
|
|
814
|
+
<span><FolderOpen size={14} />{sandboxText(locale, "工作目录")}</span>
|
|
808
815
|
<input
|
|
809
816
|
value={activeChannel.runConfig.workingDirectory}
|
|
810
817
|
onChange={(event) => updateRunConfig({ workingDirectory: event.target.value })}
|
|
811
|
-
placeholder="使用 Host 项目目录"
|
|
818
|
+
placeholder={sandboxText(locale, "使用 Host 项目目录")}
|
|
812
819
|
spellCheck={false}
|
|
813
820
|
/>
|
|
814
821
|
</label>
|
|
815
822
|
<label>
|
|
816
|
-
<span><ShieldCheck size={14}
|
|
823
|
+
<span><ShieldCheck size={14} />{sandboxText(locale, "安全策略")}</span>
|
|
817
824
|
<select value={activeChannel.runConfig.safetyMode} onChange={(event) => {
|
|
818
825
|
const safetyMode = event.target.value as SandboxAgentRunConfig['safetyMode']
|
|
819
826
|
updateRunConfig({ safetyMode, ...(safetyMode === 'danger-full-access' ? { networkAccess: true } : {}) })
|
|
820
827
|
}}>
|
|
821
|
-
<option value="read-only"
|
|
822
|
-
<option value="workspace-write"
|
|
823
|
-
<option value="danger-full-access"
|
|
828
|
+
<option value="read-only">{sandboxText(locale, "只读")}</option>
|
|
829
|
+
<option value="workspace-write">{sandboxText(locale, "工作区写入")}</option>
|
|
830
|
+
<option value="danger-full-access">{sandboxText(locale, "完全访问")}</option>
|
|
824
831
|
</select>
|
|
825
832
|
</label>
|
|
826
833
|
<label>
|
|
827
|
-
<span
|
|
834
|
+
<span>{sandboxText(locale, "审批策略")}</span>
|
|
828
835
|
<select
|
|
829
836
|
value={activeChannel.runConfig.safetyMode === 'read-only' ? 'auto' : activeChannel.runConfig.safetyMode === 'danger-full-access' ? 'bypass' : activeChannel.runConfig.approvalMode}
|
|
830
837
|
disabled={activeChannel.runConfig.safetyMode !== 'workspace-write'}
|
|
831
838
|
onChange={(event) => updateRunConfig({ approvalMode: event.target.value as SandboxAgentRunConfig['approvalMode'] })}
|
|
832
839
|
>
|
|
833
|
-
<option value="ask"
|
|
834
|
-
<option value="auto"
|
|
835
|
-
<option value="bypass"
|
|
840
|
+
<option value="ask">{sandboxText(locale, "按需确认")}</option>
|
|
841
|
+
<option value="auto">{sandboxText(locale, "审核 Agent 自动判断")}</option>
|
|
842
|
+
<option value="bypass">{sandboxText(locale, "绕过审批")}</option>
|
|
836
843
|
</select>
|
|
837
844
|
</label>
|
|
838
845
|
<label className="agent-playground-network-toggle">
|
|
839
|
-
<span><Network size={14}
|
|
846
|
+
<span><Network size={14} />{sandboxText(locale, "网络访问")}</span>
|
|
840
847
|
<input
|
|
841
848
|
type="checkbox"
|
|
842
849
|
checked={activeChannel.runConfig.safetyMode === 'danger-full-access' || activeChannel.runConfig.networkAccess}
|
|
@@ -846,25 +853,25 @@ export default function Sandbox() {
|
|
|
846
853
|
<i aria-hidden="true" />
|
|
847
854
|
</label>
|
|
848
855
|
{activeChannel.runConfig.safetyMode === 'danger-full-access' && (
|
|
849
|
-
<p><CircleAlert size={14}
|
|
856
|
+
<p><CircleAlert size={14} />{sandboxText(locale, "完全访问允许 Agent 操作工作目录之外的文件并访问网络,请仅用于可信任务。")}</p>
|
|
850
857
|
)}
|
|
851
858
|
{activeChannel.runConfig.safetyMode !== 'danger-full-access' && shellIsolation?.available === false && (
|
|
852
|
-
<p><CircleAlert size={14}
|
|
859
|
+
<p><CircleAlert size={14} />{sandboxText(locale, "安全 Shell 需要可用的 Docker daemon;当前仅文件工具可运行。")}{shellIsolation.message}</p>
|
|
853
860
|
)}
|
|
854
861
|
</section>
|
|
855
862
|
)}
|
|
856
863
|
|
|
857
864
|
{/* Messages */}
|
|
858
|
-
<section className="agent-playground-conversation" aria-label="Agent 对话">
|
|
865
|
+
<section className="agent-playground-conversation" aria-label={sandboxText(locale, "Agent 对话")}>
|
|
859
866
|
<div className="agent-playground-message-scroll">
|
|
860
867
|
{channelMessages.length === 0 ? (
|
|
861
868
|
<div className="agent-playground-empty">
|
|
862
869
|
<span className="agent-playground-empty-mark"><Sparkles size={24} /></span>
|
|
863
|
-
<div><h2
|
|
870
|
+
<div><h2>{sandboxText(locale, "开始一次可观察的 Agent 运行")}</h2><p>{sandboxText(locale, "发送任务后,回复、工具调用、Token 与异常会在同一会话上下文中关联。")}</p></div>
|
|
864
871
|
<div className="agent-playground-prompts">
|
|
865
|
-
<button type="button" onClick={() => runPrompt(
|
|
866
|
-
<button type="button" onClick={() => runPrompt(
|
|
867
|
-
<button type="button" onClick={() => runPrompt(
|
|
872
|
+
<button type="button" onClick={() => runPrompt(sandboxText(locale, "介绍当前 Agent 可以使用的能力,并给出三个具体示例。"))}>{sandboxText(locale, "探索可用能力")}</button>
|
|
873
|
+
<button type="button" onClick={() => runPrompt(sandboxText(locale, "用 Markdown 表格总结当前运行环境,并附上一段 TypeScript 示例代码。"))}>{sandboxText(locale, "测试富文本输出")}</button>
|
|
874
|
+
<button type="button" onClick={() => runPrompt(sandboxText(locale, "分析一个任务从推理、工具调用到最终回复的完整执行路径。"))}>{sandboxText(locale, "观察执行路径")}</button>
|
|
868
875
|
</div>
|
|
869
876
|
</div>
|
|
870
877
|
) : (
|
|
@@ -877,9 +884,9 @@ export default function Sandbox() {
|
|
|
877
884
|
<span className="agent-playground-message-avatar">{msg.type === 'received' ? <Bot size={16} /> : <User size={16} />}</span>
|
|
878
885
|
<div className="agent-playground-message-main">
|
|
879
886
|
<div className="agent-playground-message-meta">
|
|
880
|
-
<strong>{isApproval ?
|
|
887
|
+
<strong>{isApproval ? sandboxText(locale, "需要你的确认") : msg.type === 'received' ? endpointId : sandboxText(locale, "你")}</strong>
|
|
881
888
|
{isApproval && <span>approval required</span>}
|
|
882
|
-
<time>{new Date(msg.timestamp).toLocaleTimeString(
|
|
889
|
+
<time>{new Date(msg.timestamp).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' })}</time>
|
|
883
890
|
</div>
|
|
884
891
|
<div className="agent-playground-message-content">{renderMessageSegments(msg.content, msg.type === 'sent', msg.id, msg.interactionResolved === true)}</div>
|
|
885
892
|
</div>
|
|
@@ -896,33 +903,33 @@ export default function Sandbox() {
|
|
|
896
903
|
</section>
|
|
897
904
|
|
|
898
905
|
{/* Input area */}
|
|
899
|
-
<section className="agent-playground-composer" aria-label="任务输入">
|
|
906
|
+
<section className="agent-playground-composer" aria-label={sandboxText(locale, "任务输入")}>
|
|
900
907
|
{/* Toolbar */}
|
|
901
908
|
<div className="flex gap-2 items-center flex-wrap">
|
|
902
909
|
<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")}
|
|
903
|
-
onClick={() => { setShowFacePicker(!showFacePicker); setMediaPanel(null) }} title="插入表情">
|
|
910
|
+
onClick={() => { setShowFacePicker(!showFacePicker); setMediaPanel(null) }} title={sandboxText(locale, "插入表情")}>
|
|
904
911
|
<Smile size={16} />
|
|
905
912
|
</button>
|
|
906
913
|
<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")}
|
|
907
|
-
onClick={() => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false) }} title="插入图片 URL">
|
|
914
|
+
onClick={() => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false) }} title={sandboxText(locale, "插入图片 URL")}>
|
|
908
915
|
<Image size={16} />
|
|
909
916
|
</button>
|
|
910
917
|
<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")}
|
|
911
|
-
onClick={() => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false) }} title="插入视频 URL">
|
|
918
|
+
onClick={() => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false) }} title={sandboxText(locale, "插入视频 URL")}>
|
|
912
919
|
<Video size={16} />
|
|
913
920
|
</button>
|
|
914
921
|
<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")}
|
|
915
|
-
onClick={() => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false) }} title="插入音频 URL">
|
|
922
|
+
onClick={() => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false) }} title={sandboxText(locale, "插入音频 URL")}>
|
|
916
923
|
<Music size={16} />
|
|
917
924
|
</button>
|
|
918
925
|
<div className="flex-1 min-w-[1rem]" />
|
|
919
|
-
<div className="sandbox-composer-tabs" role="tablist" aria-label="消息编辑模式">
|
|
920
|
-
<button type="button" role="tab" aria-selected={composerMode === 'write'} className={cn(composerMode === 'write' && 'active')} onClick={() => setComposerMode('write')}
|
|
921
|
-
<button type="button" role="tab" aria-selected={composerMode === 'preview'} className={cn(composerMode === 'preview' && 'active')} onClick={() => setComposerMode('preview')}
|
|
926
|
+
<div className="sandbox-composer-tabs" role="tablist" aria-label={sandboxText(locale, "消息编辑模式")}>
|
|
927
|
+
<button type="button" role="tab" aria-selected={composerMode === 'write'} className={cn(composerMode === 'write' && 'active')} onClick={() => setComposerMode('write')}>{sandboxText(locale, "编写")}</button>
|
|
928
|
+
<button type="button" role="tab" aria-selected={composerMode === 'preview'} className={cn(composerMode === 'preview' && 'active')} onClick={() => setComposerMode('preview')}>{sandboxText(locale, "预览")}</button>
|
|
922
929
|
</div>
|
|
923
930
|
{inputText && (
|
|
924
931
|
<button className="h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors"
|
|
925
|
-
onClick={() => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write') }} aria-label="清空输入"><X size={16} /></button>
|
|
932
|
+
onClick={() => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write') }} aria-label={sandboxText(locale, "清空输入")}><X size={16} /></button>
|
|
926
933
|
)}
|
|
927
934
|
</div>
|
|
928
935
|
|
|
@@ -930,7 +937,7 @@ export default function Sandbox() {
|
|
|
930
937
|
{showFacePicker && (
|
|
931
938
|
<div className="p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2">
|
|
932
939
|
<input value={faceSearchQuery} onChange={(e) => setFaceSearchQuery(e.target.value)}
|
|
933
|
-
placeholder="搜索表情..." className="w-full h-8 rounded-md border bg-transparent px-2 text-sm" />
|
|
940
|
+
placeholder={sandboxText(locale, "搜索表情...")} className="w-full h-8 rounded-md border bg-transparent px-2 text-sm" />
|
|
934
941
|
<div className="grid grid-cols-8 gap-1">
|
|
935
942
|
{filteredFaces.slice(0, 80).map((face) => (
|
|
936
943
|
<button key={face.id} onClick={() => insertFace(face.id)} title={face.name}
|
|
@@ -942,7 +949,7 @@ export default function Sandbox() {
|
|
|
942
949
|
{filteredFaces.length === 0 && (
|
|
943
950
|
<div className="flex flex-col items-center gap-2 py-4">
|
|
944
951
|
<Search size={32} className="text-muted-foreground/30" />
|
|
945
|
-
<span className="text-sm text-muted-foreground"
|
|
952
|
+
<span className="text-sm text-muted-foreground">{sandboxText(locale, "未找到匹配的表情")}</span>
|
|
946
953
|
</div>
|
|
947
954
|
)}
|
|
948
955
|
</div>
|
|
@@ -951,14 +958,14 @@ export default function Sandbox() {
|
|
|
951
958
|
{mediaPanel && (
|
|
952
959
|
<div className="p-3 rounded-md border bg-muted/30 space-y-2">
|
|
953
960
|
<p className="text-xs text-muted-foreground">
|
|
954
|
-
{mediaPanel === 'image' &&
|
|
955
|
-
{mediaPanel === 'video' &&
|
|
956
|
-
{mediaPanel === 'audio' &&
|
|
961
|
+
{mediaPanel === 'image' && sandboxText(locale, "支持 http(s) 图片链接或 data URL")}
|
|
962
|
+
{mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)")}
|
|
963
|
+
{mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")}
|
|
957
964
|
</p>
|
|
958
965
|
<input
|
|
959
966
|
value={mediaUrl}
|
|
960
967
|
onChange={(e) => setMediaUrl(e.target.value)}
|
|
961
|
-
placeholder={mediaPanel === 'image' ?
|
|
968
|
+
placeholder={mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…")}
|
|
962
969
|
className="w-full h-8 rounded-md border border-input bg-background px-2 text-sm"
|
|
963
970
|
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); commitMediaUrl() } }}
|
|
964
971
|
/>
|
|
@@ -968,8 +975,7 @@ export default function Sandbox() {
|
|
|
968
975
|
onClick={commitMediaUrl}
|
|
969
976
|
disabled={!mediaUrl.trim()}
|
|
970
977
|
>
|
|
971
|
-
<Check size={14} /> 插入到输入框
|
|
972
|
-
</button>
|
|
978
|
+
<Check size={14} /> {sandboxText(locale, "插入到输入框")}</button>
|
|
973
979
|
</div>
|
|
974
980
|
)}
|
|
975
981
|
|
|
@@ -978,7 +984,8 @@ export default function Sandbox() {
|
|
|
978
984
|
<div className="flex-1 relative">
|
|
979
985
|
<div className={composerMode === 'write' ? 'block' : 'hidden'}>
|
|
980
986
|
<RichTextEditor
|
|
981
|
-
|
|
987
|
+
locale={locale}
|
|
988
|
+
ref={editorRef} placeholder={sandboxText(locale, "向 {0} 发送消息,支持 Markdown...", [activeChannel.name])}
|
|
982
989
|
onSend={handleSendMessage} onChange={handleEditorChange} onAtTrigger={handleAtTrigger}
|
|
983
990
|
minHeight="44px" maxHeight="200px"
|
|
984
991
|
/>
|
|
@@ -987,7 +994,7 @@ export default function Sandbox() {
|
|
|
987
994
|
<div className="sandbox-markdown-preview" role="tabpanel">
|
|
988
995
|
{inputText.trim()
|
|
989
996
|
? <MarkdownContent text={inputText} />
|
|
990
|
-
: <span className="sandbox-markdown-preview-empty"
|
|
997
|
+
: <span className="sandbox-markdown-preview-empty">{sandboxText(locale, "输入 Markdown 后可在这里检查最终效果")}</span>}
|
|
991
998
|
</div>
|
|
992
999
|
)}
|
|
993
1000
|
{atPopoverPosition && (
|
|
@@ -1001,7 +1008,7 @@ export default function Sandbox() {
|
|
|
1001
1008
|
)) : (
|
|
1002
1009
|
<div className="flex flex-col items-center gap-2 p-4">
|
|
1003
1010
|
<Search size={20} className="text-muted-foreground/50" />
|
|
1004
|
-
<span className="text-xs text-muted-foreground"
|
|
1011
|
+
<span className="text-xs text-muted-foreground">{sandboxText(locale, "未找到匹配的用户")}</span>
|
|
1005
1012
|
</div>
|
|
1006
1013
|
)}
|
|
1007
1014
|
</div>
|
|
@@ -1011,52 +1018,45 @@ export default function Sandbox() {
|
|
|
1011
1018
|
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"
|
|
1012
1019
|
onClick={() => { const c = editorRef.current?.getContent(); if (c) handleSendMessage(c.text, c.segments) }}
|
|
1013
1020
|
disabled={!canExecute || !hasRenderableSegments(previewSegments)}>
|
|
1014
|
-
<Send size={16} /> 发送
|
|
1015
|
-
</button>
|
|
1021
|
+
<Send size={16} /> {sandboxText(locale, "发送")}</button>
|
|
1016
1022
|
</div>
|
|
1017
1023
|
|
|
1018
1024
|
{/* Hints */}
|
|
1019
1025
|
<div className="flex items-center gap-2 flex-wrap text-xs text-muted-foreground">
|
|
1020
|
-
<Info size={12} /> 快捷操作:
|
|
1021
|
-
<span className="px-1 py-0.5 rounded border text-[10px]">Enter</span> 发送
|
|
1022
|
-
<span className="px-1 py-0.5 rounded border text-[10px]">Shift+Enter</span> 换行
|
|
1023
|
-
<span className="px-1 py-0.5 rounded border text-[10px]">```ts</span> 代码块
|
|
1024
|
-
<span className="px-1 py-0.5 rounded border text-[10px]">**文本**</span> 加粗
|
|
1025
|
-
<span className="px-1 py-0.5 rounded border text-[10px]">[@名称]</span> @某人
|
|
1026
|
-
<span className="px-1 py-0.5 rounded border text-[10px]">[video:URL]</span>
|
|
1026
|
+
<Info size={12} /> {sandboxText(locale, "快捷操作:")}<span className="px-1 py-0.5 rounded border text-[10px]">Enter</span> {sandboxText(locale, "发送")}<span className="px-1 py-0.5 rounded border text-[10px]">Shift+Enter</span> {sandboxText(locale, "换行")}<span className="px-1 py-0.5 rounded border text-[10px]">```ts</span> {sandboxText(locale, "代码块")}<span className="px-1 py-0.5 rounded border text-[10px]">{sandboxText(locale, "**文本**")}</span> {sandboxText(locale, "加粗")}<span className="px-1 py-0.5 rounded border text-[10px]">{sandboxText(locale, "[@名称]")}</span> {sandboxText(locale, "@某人")}<span className="px-1 py-0.5 rounded border text-[10px]">[video:URL]</span>
|
|
1027
1027
|
<span className="px-1 py-0.5 rounded border text-[10px]">[audio:URL]</span>
|
|
1028
1028
|
</div>
|
|
1029
1029
|
</section>
|
|
1030
1030
|
</main>
|
|
1031
1031
|
|
|
1032
|
-
<aside className={cn("agent-playground-inspector", showInspector && "show")} aria-label="运行检查器">
|
|
1032
|
+
<aside className={cn("agent-playground-inspector", showInspector && "show")} aria-label={sandboxText(locale, "运行检查器")}>
|
|
1033
1033
|
<div className="agent-playground-inspector-head">
|
|
1034
|
-
<div><span>Run inspector</span><h2
|
|
1034
|
+
<div><span>Run inspector</span><h2>{sandboxText(locale, "运行检查器")}</h2></div>
|
|
1035
1035
|
<div>
|
|
1036
|
-
<button type="button" onClick={() => void loadTrace()} aria-label="刷新 Agent Trace" disabled={traceLoading}><RefreshCw size={15} className={cn(traceLoading && 'animate-spin')} /></button>
|
|
1037
|
-
<button type="button" className="agent-playground-inspector-close" onClick={() => setShowInspector(false)} aria-label="关闭运行检查器"><X size={15} /></button>
|
|
1036
|
+
<button type="button" onClick={() => void loadTrace()} aria-label={sandboxText(locale, "刷新 Agent Trace")} disabled={traceLoading}><RefreshCw size={15} className={cn(traceLoading && 'animate-spin')} /></button>
|
|
1037
|
+
<button type="button" className="agent-playground-inspector-close" onClick={() => setShowInspector(false)} aria-label={sandboxText(locale, "关闭运行检查器")}><X size={15} /></button>
|
|
1038
1038
|
</div>
|
|
1039
1039
|
</div>
|
|
1040
1040
|
|
|
1041
|
-
<div className="agent-playground-inspector-tabs" role="tablist" aria-label="检查器视图">
|
|
1042
|
-
<button type="button" role="tab" aria-selected={inspectorView === 'runs'} className={cn(inspectorView === 'runs' && 'active')} onClick={() => setInspectorView('runs')}><Activity size={13}
|
|
1043
|
-
<button type="button" role="tab" aria-selected={inspectorView === 'artifacts'} className={cn(inspectorView === 'artifacts' && 'active')} onClick={() => setInspectorView('artifacts')}><FileDiff size={13}
|
|
1041
|
+
<div className="agent-playground-inspector-tabs" role="tablist" aria-label={sandboxText(locale, "检查器视图")}>
|
|
1042
|
+
<button type="button" role="tab" aria-selected={inspectorView === 'runs'} className={cn(inspectorView === 'runs' && 'active')} onClick={() => setInspectorView('runs')}><Activity size={13} />{sandboxText(locale, "任务")}</button>
|
|
1043
|
+
<button type="button" role="tab" aria-selected={inspectorView === 'artifacts'} className={cn(inspectorView === 'artifacts' && 'active')} onClick={() => setInspectorView('artifacts')}><FileDiff size={13} />{sandboxText(locale, "变更与产物")}<span>{workbenchArtifacts.length}</span></button>
|
|
1044
1044
|
</div>
|
|
1045
1045
|
|
|
1046
1046
|
<div className={cn("agent-playground-inspector-view", inspectorView !== 'runs' && 'hidden')}>
|
|
1047
1047
|
|
|
1048
1048
|
<section className="agent-playground-inspector-section">
|
|
1049
|
-
<div className="agent-playground-inspector-title"><span
|
|
1049
|
+
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "运行概览")}</span><small>{traceSummary.activeTurns > 0 ? 'live' : 'idle'}</small></div>
|
|
1050
1050
|
<div className="agent-playground-metrics">
|
|
1051
|
-
<div><Activity /><strong>{traceSummary.eventCount.toLocaleString()}</strong><span
|
|
1052
|
-
<div><Wrench /><strong>{traceSummary.toolCount.toLocaleString()}</strong><span
|
|
1053
|
-
<div><Coins /><strong>{traceSummary.tokenCount.toLocaleString()}</strong><span>Token</span></div>
|
|
1054
|
-
<div className={cn(traceSummary.problemCount > 0 && 'has-problem')}><CircleAlert /><strong>{traceSummary.problemCount}</strong><span
|
|
1051
|
+
<div><Activity /><strong>{traceSummary.eventCount.toLocaleString(locale)}</strong><span>{sandboxText(locale, "事件")}</span></div>
|
|
1052
|
+
<div><Wrench /><strong>{traceSummary.toolCount.toLocaleString(locale)}</strong><span>{sandboxText(locale, "工具")}</span></div>
|
|
1053
|
+
<div><Coins /><strong>{traceSummary.tokenCount.toLocaleString(locale)}</strong><span>Token</span></div>
|
|
1054
|
+
<div className={cn(traceSummary.problemCount > 0 && 'has-problem')}><CircleAlert /><strong>{traceSummary.problemCount}</strong><span>{sandboxText(locale, "异常")}</span></div>
|
|
1055
1055
|
</div>
|
|
1056
1056
|
</section>
|
|
1057
1057
|
|
|
1058
1058
|
<section className="agent-playground-inspector-section">
|
|
1059
|
-
<div className="agent-playground-inspector-title"><span
|
|
1059
|
+
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "上下文")}</span></div>
|
|
1060
1060
|
<dl className="agent-playground-context-list">
|
|
1061
1061
|
<div><dt>Endpoint</dt><dd>{endpointId}</dd></div>
|
|
1062
1062
|
<div><dt>Scope</dt><dd>{activeChannel.type}</dd></div>
|
|
@@ -1071,26 +1071,26 @@ export default function Sandbox() {
|
|
|
1071
1071
|
</section>
|
|
1072
1072
|
|
|
1073
1073
|
<section className="agent-playground-inspector-section agent-playground-task-section">
|
|
1074
|
-
<div className="agent-playground-inspector-title"><span
|
|
1074
|
+
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "任务历史")}</span><small>{taskRuns.length} runs</small></div>
|
|
1075
1075
|
{taskRuns.length > 0 ? (
|
|
1076
1076
|
<div className="agent-playground-task-list">
|
|
1077
1077
|
{taskRuns.slice(0, 8).map((run) => (
|
|
1078
1078
|
<article key={run.id} className={cn(`is-${run.status}`)}>
|
|
1079
1079
|
<i />
|
|
1080
|
-
<div><strong>{taskStatusLabel(run.status)}</strong><code>{run.turnId.slice(0, 10)}</code></div>
|
|
1080
|
+
<div><strong>{taskStatusLabel(run.status, locale)}</strong><code>{run.turnId.slice(0, 10)}</code></div>
|
|
1081
1081
|
<dl>
|
|
1082
|
-
<div><dt
|
|
1083
|
-
<div><dt
|
|
1084
|
-
<div><dt>Token</dt><dd>{run.tokenCount.toLocaleString()}</dd></div>
|
|
1082
|
+
<div><dt>{sandboxText(locale, "耗时")}</dt><dd>{run.durationMs === undefined ? sandboxText(locale, "进行中") : `${run.durationMs.toLocaleString(locale)} ms`}</dd></div>
|
|
1083
|
+
<div><dt>{sandboxText(locale, "工具")}</dt><dd>{run.toolCount}</dd></div>
|
|
1084
|
+
<div><dt>Token</dt><dd>{run.tokenCount.toLocaleString(locale)}</dd></div>
|
|
1085
1085
|
</dl>
|
|
1086
1086
|
</article>
|
|
1087
1087
|
))}
|
|
1088
1088
|
</div>
|
|
1089
|
-
) : <div className="agent-playground-artifact-empty"><Activity size={18} /><span
|
|
1089
|
+
) : <div className="agent-playground-artifact-empty"><Activity size={18} /><span>{sandboxText(locale, "运行任务后会在这里形成可回溯记录")}</span></div>}
|
|
1090
1090
|
</section>
|
|
1091
1091
|
|
|
1092
1092
|
<section className="agent-playground-inspector-section agent-playground-trace-section">
|
|
1093
|
-
<div className="agent-playground-inspector-title"><span
|
|
1093
|
+
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "最近执行")}</span><small>2s sync</small></div>
|
|
1094
1094
|
{traceLoading && !trace ? (
|
|
1095
1095
|
<div className="agent-playground-trace-loading"><i /><i /><i /></div>
|
|
1096
1096
|
) : traceNotice && !trace?.events.length ? (
|
|
@@ -1098,25 +1098,25 @@ export default function Sandbox() {
|
|
|
1098
1098
|
) : recentTraceEvents.length ? (
|
|
1099
1099
|
<div className="agent-playground-trace-list">
|
|
1100
1100
|
{recentTraceEvents.map((event) => {
|
|
1101
|
-
const item = presentTraceEvent(event)
|
|
1101
|
+
const item = presentTraceEvent(event, locale)
|
|
1102
1102
|
return (
|
|
1103
1103
|
<div key={event.sequence} className={cn("agent-playground-trace-item", `is-${item.tone}`)}>
|
|
1104
1104
|
<span className="agent-playground-trace-dot" />
|
|
1105
1105
|
<div><strong>{item.title}</strong>{item.detail ? <small>{item.detail}</small> : null}</div>
|
|
1106
|
-
<time>{new Date(event.recordedAt).toLocaleTimeString(
|
|
1106
|
+
<time>{new Date(event.recordedAt).toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit' })}</time>
|
|
1107
1107
|
</div>
|
|
1108
1108
|
)
|
|
1109
1109
|
})}
|
|
1110
1110
|
</div>
|
|
1111
1111
|
) : (
|
|
1112
|
-
<div className="agent-playground-trace-empty"><Activity size={18} /><span
|
|
1112
|
+
<div className="agent-playground-trace-empty"><Activity size={18} /><span>{sandboxText(locale, "发送任务后显示推理与工具轨迹")}</span></div>
|
|
1113
1113
|
)}
|
|
1114
1114
|
</section>
|
|
1115
1115
|
</div>
|
|
1116
1116
|
|
|
1117
1117
|
<div className={cn("agent-playground-inspector-view", inspectorView !== 'artifacts' && 'hidden')}>
|
|
1118
1118
|
<section className="agent-playground-inspector-section agent-playground-artifact-section">
|
|
1119
|
-
<div className="agent-playground-inspector-title"><span
|
|
1119
|
+
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "文件与命令产物")}</span><small>{workbenchArtifacts.length} items</small></div>
|
|
1120
1120
|
{workbenchArtifacts.length > 0 ? (
|
|
1121
1121
|
<div className="agent-playground-artifact-list">
|
|
1122
1122
|
{workbenchArtifacts.map((artifact) => {
|
|
@@ -1133,30 +1133,30 @@ export default function Sandbox() {
|
|
|
1133
1133
|
{expanded && (
|
|
1134
1134
|
<div className="agent-playground-artifact-detail">
|
|
1135
1135
|
{artifact.path && <code>{artifact.path}</code>}
|
|
1136
|
-
{artifact.diff ? <pre>{artifact.diff}</pre> : <pre>{artifact.detail ||
|
|
1137
|
-
<footer><span>{artifact.durationMs === undefined ?
|
|
1136
|
+
{artifact.diff ? <pre>{artifact.diff}</pre> : <pre>{artifact.detail || sandboxText(locale, "暂无输出")}</pre>}
|
|
1137
|
+
<footer><span>{artifact.durationMs === undefined ? sandboxText(locale, "等待结果") : `${artifact.durationMs.toLocaleString(locale)} ms`}</span><code>{artifact.turnId.slice(0, 12)}</code></footer>
|
|
1138
1138
|
</div>
|
|
1139
1139
|
)}
|
|
1140
1140
|
</article>
|
|
1141
1141
|
)
|
|
1142
1142
|
})}
|
|
1143
1143
|
</div>
|
|
1144
|
-
) : <div className="agent-playground-artifact-empty"><FileDiff size={18} /><span>Agent
|
|
1144
|
+
) : <div className="agent-playground-artifact-empty"><FileDiff size={18} /><span>{sandboxText(locale, "Agent 修改文件、执行命令或测试后,产物会集中出现在这里")}</span></div>}
|
|
1145
1145
|
</section>
|
|
1146
1146
|
</div>
|
|
1147
1147
|
|
|
1148
|
-
<a className="agent-playground-studio-link" href={agentStudioPath(sessionKey)}><span><ExternalLink size={15}
|
|
1148
|
+
<a className="agent-playground-studio-link" href={agentStudioPath(sessionKey)}><span><ExternalLink size={15} />{sandboxText(locale, "在 Agent Studio 中完整诊断")}</span><code>{sessionKey}</code></a>
|
|
1149
1149
|
</aside>
|
|
1150
1150
|
{showInspector && <div className="agent-playground-inspector-overlay" onClick={() => setShowInspector(false)} />}
|
|
1151
1151
|
</section>
|
|
1152
1152
|
)
|
|
1153
1153
|
}
|
|
1154
1154
|
|
|
1155
|
-
function taskStatusLabel(status: 'running' | 'completed' | 'failed' | 'cancelled'): string {
|
|
1156
|
-
if (status === 'running') return
|
|
1157
|
-
if (status === 'completed') return
|
|
1158
|
-
if (status === 'failed') return
|
|
1159
|
-
return
|
|
1155
|
+
function taskStatusLabel(status: 'running' | 'completed' | 'failed' | 'cancelled', locale: SandboxLocale = 'zh-CN'): string {
|
|
1156
|
+
if (status === 'running') return sandboxText(locale, "Agent 运行中")
|
|
1157
|
+
if (status === 'completed') return sandboxText(locale, "最近任务已完成")
|
|
1158
|
+
if (status === 'failed') return sandboxText(locale, "最近任务失败")
|
|
1159
|
+
return sandboxText(locale, "最近任务已取消")
|
|
1160
1160
|
}
|
|
1161
1161
|
|
|
1162
1162
|
function messageText(segments: readonly MessageSegment[]): string {
|
|
@@ -1170,18 +1170,18 @@ function messageText(segments: readonly MessageSegment[]): string {
|
|
|
1170
1170
|
}).join(' ').trim()
|
|
1171
1171
|
}
|
|
1172
1172
|
|
|
1173
|
-
function formatDuration(durationMs: number): string {
|
|
1174
|
-
if (durationMs < 1_000) return `${durationMs.toLocaleString()} ms`
|
|
1173
|
+
function formatDuration(durationMs: number, locale: SandboxLocale = 'zh-CN'): string {
|
|
1174
|
+
if (durationMs < 1_000) return `${durationMs.toLocaleString(locale)} ms`
|
|
1175
1175
|
if (durationMs < 60_000) return `${(durationMs / 1_000).toFixed(durationMs < 10_000 ? 1 : 0)} s`
|
|
1176
1176
|
return `${Math.floor(durationMs / 60_000)}m ${Math.round((durationMs % 60_000) / 1_000)}s`
|
|
1177
1177
|
}
|
|
1178
1178
|
|
|
1179
|
-
function runStepStatusLabel(status: 'running' | 'completed' | 'failed' | 'denied' | 'cancelled'): string {
|
|
1180
|
-
if (status === 'running') return
|
|
1181
|
-
if (status === 'completed') return
|
|
1182
|
-
if (status === 'denied') return
|
|
1183
|
-
if (status === 'cancelled') return
|
|
1184
|
-
return
|
|
1179
|
+
function runStepStatusLabel(status: 'running' | 'completed' | 'failed' | 'denied' | 'cancelled', locale: SandboxLocale = 'zh-CN'): string {
|
|
1180
|
+
if (status === 'running') return sandboxText(locale, "进行中")
|
|
1181
|
+
if (status === 'completed') return sandboxText(locale, "完成")
|
|
1182
|
+
if (status === 'denied') return sandboxText(locale, "已拒绝")
|
|
1183
|
+
if (status === 'cancelled') return sandboxText(locale, "已取消")
|
|
1184
|
+
return sandboxText(locale, "失败")
|
|
1185
1185
|
}
|
|
1186
1186
|
|
|
1187
1187
|
function safeFileName(value: string): string {
|