@zhin.js/adapter-sandbox 1.1.24 → 1.1.26
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 +46 -0
- package/lib/endpoint.js +45 -7
- package/lib/protocol.d.ts +6 -0
- package/lib/protocol.js +15 -0
- package/package.json +19 -19
- package/pages/index/HtmlMessage.js +1 -1
- package/pages/index/HtmlMessage.tsx +1 -1
- package/pages/index/SandboxChat.js +131 -31
- package/pages/index/SandboxChat.tsx +334 -75
- package/pages/index/index.js +1 -1
- package/pages/index/index.tsx +1 -1
- package/pages/index/messages.js +2 -0
- package/pages/index/messages.ts +2 -0
- package/pages/index/styles.js +482 -181
- package/pages/index/styles.ts +482 -181
- package/src/endpoint.ts +42 -7
- package/src/protocol.ts +26 -0
|
@@ -2,14 +2,13 @@ import { sandboxText, type SandboxLocale } from './messages.js';
|
|
|
2
2
|
import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
|
3
3
|
import {
|
|
4
4
|
cn,
|
|
5
|
-
adapterConsoleStyles,
|
|
6
5
|
CodeBlock,
|
|
7
6
|
MarkdownContent,
|
|
8
7
|
resolveMediaSrc,
|
|
9
8
|
pickMediaRawUrl,
|
|
10
9
|
type MessageSegment,
|
|
11
10
|
} from '@zhin.js/client';
|
|
12
|
-
import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL, type SandboxRequestContext } from './sandboxTransport';
|
|
11
|
+
import { buildSandboxWebSocketUrl, captureSandboxRequestContext, createSandboxMessageId, submitSandboxFrame, SANDBOX_SCOPED_PROTOCOL, type SandboxRequestContext } from './sandboxTransport.js';
|
|
13
12
|
import { createWorkspaceDirectoryController, type DirectoryStatus } from './workspaceDirectoryState.js';
|
|
14
13
|
import type { SandboxWorkspaceScope } from './workspaceDirectory.js';
|
|
15
14
|
import {
|
|
@@ -21,7 +20,7 @@ import {
|
|
|
21
20
|
Square, RotateCcw, FileDiff, Terminal, FlaskConical, ChevronDown,
|
|
22
21
|
FileDown, ListChecks,
|
|
23
22
|
} from 'lucide-react';
|
|
24
|
-
import RichTextEditor, { type RichTextEditorRef } from './RichTextEditor';
|
|
23
|
+
import RichTextEditor, { type RichTextEditorRef } from './RichTextEditor.js';
|
|
25
24
|
import HtmlMessage from './HtmlMessage.js';
|
|
26
25
|
import { sandboxStyles } from './styles.js';
|
|
27
26
|
import ConversationRecoveryPanel from './ConversationRecoveryPanel.js';
|
|
@@ -107,6 +106,10 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
107
106
|
const [showConversationDetails, setShowConversationDetails] = useState(false)
|
|
108
107
|
const [pendingRefreshEpoch, setPendingRefreshEpoch] = useState(0)
|
|
109
108
|
const [showRunSettings, setShowRunSettings] = useState(false)
|
|
109
|
+
const [senderId, setSenderId] = useState('dev-user')
|
|
110
|
+
const [senderName, setSenderName] = useState('Developer')
|
|
111
|
+
const [senderRole, setSenderRole] = useState<'master' | 'admin' | 'member'>('master')
|
|
112
|
+
const [showSenderSettings, setShowSenderSettings] = useState(false)
|
|
110
113
|
const [showNewSession, setShowNewSession] = useState(false)
|
|
111
114
|
const [newSessionName, setNewSessionName] = useState('')
|
|
112
115
|
const [newSessionScope, setNewSessionScope] = useState<SandboxScope>('private')
|
|
@@ -221,9 +224,10 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
221
224
|
}) ? 'saved' : 'error')
|
|
222
225
|
}, [activeChannel.id, channels, messages, directoryStatus.mode])
|
|
223
226
|
|
|
227
|
+
const [inlineNotices, setInlineNotices] = useState<{ emoji: boolean; parse: boolean }>({ emoji: false, parse: false })
|
|
224
228
|
const fetchFaceList = async () => {
|
|
225
229
|
try { const res = await fetch('https://face.viki.moe/metadata.json'); setFaceList(await res.json()) }
|
|
226
|
-
catch (err) { console.error('[Sandbox] Failed to fetch face list:', err) }
|
|
230
|
+
catch (err) { console.error('[Sandbox] Failed to fetch face list:', err); setInlineNotices((n) => ({ ...n, emoji: true })) }
|
|
227
231
|
}
|
|
228
232
|
|
|
229
233
|
useEffect(() => { fetchFaceList() }, [])
|
|
@@ -240,6 +244,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
240
244
|
type: string; id: string; locale?: unknown; content?: unknown; endpoint?: string; workingDirectory?: string; canExecute?: boolean;
|
|
241
245
|
shellIsolation?: { available?: boolean; provider?: string; message?: string }; timestamp: number;
|
|
242
246
|
messageId?: string; bot?: string; protocol?: string; connectionId?: string; direction?: string; senderId?: string;
|
|
247
|
+
senderName?: string; senderRole?: 'master' | 'admin' | 'member';
|
|
243
248
|
revision?: number; streaming?: boolean;
|
|
244
249
|
conversation?: { type: Channel['type']; id: string };
|
|
245
250
|
}) => {
|
|
@@ -328,7 +333,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
328
333
|
id: data.messageId ?? createSandboxMessageId(), type: isInput ? 'sent' : 'received', channelType,
|
|
329
334
|
interactionReadOnly: false,
|
|
330
335
|
channelId: sceneId, channelName, senderId: isInput ? data.senderId || connectionRef.current.ownerId || 'owner' : 'endpoint',
|
|
331
|
-
senderName: isInput ? sandboxText(locale, "当前用户") : data.bot || endpointIdRef.current, content, timestamp: data.timestamp,
|
|
336
|
+
senderName: isInput ? (typeof data.senderName === 'string' && data.senderName.trim() ? data.senderName.trim() : sandboxText(locale, "当前用户")) : data.bot || endpointIdRef.current, content, timestamp: data.timestamp,
|
|
332
337
|
...(Number.isSafeInteger(data.revision) && data.revision! > 0 ? { revision: data.revision } : {}),
|
|
333
338
|
...(typeof data.streaming === 'boolean' ? { streaming: data.streaming } : {}),
|
|
334
339
|
}))
|
|
@@ -338,8 +343,11 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
338
343
|
if (!connectionRef.current.canExecute) return false
|
|
339
344
|
const scene = activeChannelRef.current
|
|
340
345
|
const segments: MessageSegment[] = [{ type: 'action', data: { id: payload, payload } }]
|
|
346
|
+
const resolvedSenderId = senderId.trim() || connectionRef.current.ownerId || 'dev-user'
|
|
347
|
+
const resolvedSenderName = senderName.trim() || sandboxText(localeRef.current, "测试用户")
|
|
341
348
|
if (!submitSandboxFrame(wsRef.current, {
|
|
342
349
|
type: scene.type, id: scene.id, messageId: createSandboxMessageId(), content: segments,
|
|
350
|
+
senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole,
|
|
343
351
|
agentRun: scene.runConfig, timestamp: Date.now(),
|
|
344
352
|
})) {
|
|
345
353
|
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,审批选择未发送。"))
|
|
@@ -408,7 +416,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
408
416
|
ws.onmessage = (event) => {
|
|
409
417
|
if (wsRef.current !== ws) return
|
|
410
418
|
try { handleInboundPayload(JSON.parse(String(event.data))) }
|
|
411
|
-
catch (err) { console.error('[Sandbox] Failed to parse message:', err) }
|
|
419
|
+
catch (err) { console.error('[Sandbox] Failed to parse message:', err); setInlineNotices((n) => ({ ...n, parse: true })) }
|
|
412
420
|
}
|
|
413
421
|
ws.onclose = () => {
|
|
414
422
|
if (wsRef.current !== ws) return
|
|
@@ -528,7 +536,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
528
536
|
|
|
529
537
|
const parseTextToSegments = (text: string): MessageSegment[] => {
|
|
530
538
|
const segments: MessageSegment[] = []
|
|
531
|
-
const regex = /\[@([^\]]+)\]|\[face:(\d+)\]|\[image:([^\]]+)\]|\[video:([^\]]+)\]|\[audio:([^\]]+)\]/g
|
|
539
|
+
const regex = /\[@([^\[\]]+)\]|\[face:(\d+)\]|\[image:([^\[\]]+)\]|\[video:([^\[\]]+)\]|\[audio:([^\[\]]+)\]/g
|
|
532
540
|
let lastIndex = 0
|
|
533
541
|
let match: RegExpExecArray | null
|
|
534
542
|
while ((match = regex.exec(text)) !== null) {
|
|
@@ -567,7 +575,6 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
567
575
|
onInteractionSubmitted?: () => void,
|
|
568
576
|
allowInteraction = true,
|
|
569
577
|
) => {
|
|
570
|
-
const ring = isSent ? 'ring-1 ring-primary-foreground/25' : 'ring-1 ring-border/60'
|
|
571
578
|
return segments.map((segment, index) => {
|
|
572
579
|
if (typeof segment === 'string') {
|
|
573
580
|
return <MarkdownContent key={index} text={segment} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
@@ -579,35 +586,35 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
579
586
|
case 'md':
|
|
580
587
|
return <MarkdownContent key={index} text={String(d.text ?? d.content ?? '')} className={isSent ? 'zhin-markdown--inverse' : undefined} />
|
|
581
588
|
case 'html':
|
|
582
|
-
return <HtmlMessage locale={locale} key={index} html={String(d.html ?? '')} />
|
|
589
|
+
return <HtmlMessage locale={locale} key={index} html={String(d.html ?? d.content ?? d.text ?? '')} />
|
|
583
590
|
case 'code':
|
|
584
591
|
return <CodeBlock key={index} code={String(d.code ?? d.text ?? d.content ?? '')} language={String(d.language ?? d.lang ?? '')} />
|
|
585
592
|
case 'mention':
|
|
586
593
|
case 'at':
|
|
587
|
-
return <span key={index} className="
|
|
594
|
+
return <span key={index} className="sandbox-chip is-mention">@{String(d.name ?? d.target ?? d.qq ?? '')}</span>
|
|
588
595
|
case 'face':
|
|
589
|
-
return <img key={index} src={`https://face.viki.moe/apng/${d.id}.png`} alt={String(d.name ?? '')} className="
|
|
596
|
+
return <img key={index} src={`https://face.viki.moe/apng/${d.id}.png`} alt={String(d.name ?? '')} className="sandbox-inline-face" title={String(d.name ?? d.id ?? '')} />
|
|
590
597
|
case 'dice':
|
|
591
|
-
return <span key={index} className="
|
|
598
|
+
return <span key={index} className="sandbox-chip">🎲 {d.result != null ? sandboxText(locale, "点数 {0}", [String(d.result)]) : sandboxText(locale, "骰子")}</span>
|
|
592
599
|
case 'rps':
|
|
593
|
-
return <span key={index} className="
|
|
600
|
+
return <span key={index} className="sandbox-chip">✊ {d.result != null ? sandboxText(locale, "结果 {0}", [String(d.result)]) : sandboxText(locale, "猜拳")}</span>
|
|
594
601
|
case 'image': {
|
|
595
602
|
const raw = pickMediaRawUrl(d)
|
|
596
603
|
const src = resolveMediaSrc(raw, 'image')
|
|
597
|
-
if (!src) return <span key={index} className="
|
|
604
|
+
if (!src) return <span key={index} className="sandbox-segment-note">{sandboxText(locale, "[图片]")}</span>
|
|
598
605
|
return (
|
|
599
606
|
// resolveMediaSrc allowlists non-executable URL schemes and image data MIME types.
|
|
600
607
|
// lgtm[js/xss,js/client-side-unvalidated-url-redirection]
|
|
601
|
-
<a key={index} href={src} target="_blank" rel="noreferrer" className="
|
|
608
|
+
<a key={index} href={src} target="_blank" rel="noreferrer" className="sandbox-media-link">
|
|
602
609
|
{/* lgtm[js/xss,js/client-side-unvalidated-url-redirection] */}
|
|
603
|
-
<img src={src} alt="" className=
|
|
610
|
+
<img src={src} alt="" className="sandbox-media-image" onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />
|
|
604
611
|
</a>
|
|
605
612
|
)
|
|
606
613
|
}
|
|
607
614
|
case 'video': {
|
|
608
615
|
const raw = pickMediaRawUrl(d)
|
|
609
616
|
const src = resolveMediaSrc(raw, 'video')
|
|
610
|
-
if (!src) return <span key={index} className="
|
|
617
|
+
if (!src) return <span key={index} className="sandbox-segment-note">{sandboxText(locale, "[视频无地址]")}</span>
|
|
611
618
|
return (
|
|
612
619
|
// resolveMediaSrc allowlists non-executable URL schemes and video data MIME types.
|
|
613
620
|
// lgtm[js/xss,js/client-side-unvalidated-url-redirection]
|
|
@@ -617,7 +624,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
617
624
|
controls
|
|
618
625
|
playsInline
|
|
619
626
|
preload="metadata"
|
|
620
|
-
className=
|
|
627
|
+
className="sandbox-media-video"
|
|
621
628
|
/>
|
|
622
629
|
)
|
|
623
630
|
}
|
|
@@ -625,7 +632,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
625
632
|
case 'record': {
|
|
626
633
|
const raw = pickMediaRawUrl(d)
|
|
627
634
|
const src = resolveMediaSrc(raw, 'audio')
|
|
628
|
-
if (!src) return <span key={index} className="
|
|
635
|
+
if (!src) return <span key={index} className="sandbox-segment-note">{sandboxText(locale, "[音频无地址]")}</span>
|
|
629
636
|
return (
|
|
630
637
|
// resolveMediaSrc allowlists non-executable URL schemes and audio data MIME types.
|
|
631
638
|
// lgtm[js/xss,js/client-side-unvalidated-url-redirection]
|
|
@@ -634,13 +641,13 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
634
641
|
src={src}
|
|
635
642
|
controls
|
|
636
643
|
preload="metadata"
|
|
637
|
-
className=
|
|
644
|
+
className="sandbox-media-audio"
|
|
638
645
|
/>
|
|
639
646
|
)
|
|
640
647
|
}
|
|
641
648
|
case 'reply':
|
|
642
649
|
return (
|
|
643
|
-
<div key={index} className="
|
|
650
|
+
<div key={index} className="sandbox-reply-quote">
|
|
644
651
|
{sandboxText(locale, "↩ 引用消息 #")}{String(d.message_id ?? d.id ?? '')}
|
|
645
652
|
</div>
|
|
646
653
|
)
|
|
@@ -648,12 +655,12 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
648
655
|
const messages = d.messages as Array<Array<{ type?: string; data?: Record<string, unknown> }>> | undefined
|
|
649
656
|
const title = String(d.title ?? sandboxText(locale, "聊天记录"))
|
|
650
657
|
return (
|
|
651
|
-
<div key={index} className="
|
|
652
|
-
<div className="
|
|
658
|
+
<div key={index} className="sandbox-forward">
|
|
659
|
+
<div className="sandbox-forward-title">📨 {title}</div>
|
|
653
660
|
{Array.isArray(messages) && messages.length > 0 ? (
|
|
654
|
-
<div className="
|
|
661
|
+
<div className="sandbox-forward-list">
|
|
655
662
|
{messages.slice(0, 3).map((batch, bi) => (
|
|
656
|
-
<div key={bi}
|
|
663
|
+
<div key={bi}>
|
|
657
664
|
{batch.map((s, si) => (
|
|
658
665
|
<span key={si}>
|
|
659
666
|
{s.type === 'text' ? String(s.data?.text ?? '') : `[${s.type ?? 'seg'}]`}
|
|
@@ -661,14 +668,142 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
661
668
|
))}
|
|
662
669
|
</div>
|
|
663
670
|
))}
|
|
664
|
-
{messages.length > 3 && <div className="
|
|
671
|
+
{messages.length > 3 && <div className="sandbox-forward-more">{sandboxText(locale, "…共")}{messages.length} {sandboxText(locale, "条")}</div>}
|
|
665
672
|
</div>
|
|
666
673
|
) : (
|
|
667
|
-
<div className="
|
|
674
|
+
<div className="sandbox-forward-empty">{sandboxText(locale, "[合并转发]")}</div>
|
|
668
675
|
)}
|
|
669
676
|
</div>
|
|
670
677
|
)
|
|
671
678
|
}
|
|
679
|
+
case 'card': {
|
|
680
|
+
const title = typeof d.title === 'string' ? d.title : ''
|
|
681
|
+
const subtitle = typeof d.subtitle === 'string' ? d.subtitle : ''
|
|
682
|
+
const description = typeof d.description === 'string'
|
|
683
|
+
? d.description
|
|
684
|
+
: typeof d.content === 'string'
|
|
685
|
+
? d.content
|
|
686
|
+
: typeof d.summary === 'string'
|
|
687
|
+
? d.summary
|
|
688
|
+
: ''
|
|
689
|
+
const rawImage = typeof d.image === 'string'
|
|
690
|
+
? d.image
|
|
691
|
+
: typeof d.thumbnail === 'string'
|
|
692
|
+
? d.thumbnail
|
|
693
|
+
: typeof d.imageUrl === 'string'
|
|
694
|
+
? d.imageUrl
|
|
695
|
+
: pickMediaRawUrl(d)
|
|
696
|
+
const imageSrc = rawImage ? resolveMediaSrc(rawImage, 'image') : undefined
|
|
697
|
+
const fields = Array.isArray(d.fields)
|
|
698
|
+
? (d.fields as Array<Record<string, unknown>>)
|
|
699
|
+
: []
|
|
700
|
+
const buttons = Array.isArray(d.buttons)
|
|
701
|
+
? (d.buttons as Array<Record<string, unknown>>)
|
|
702
|
+
: Array.isArray(d.actions)
|
|
703
|
+
? (d.actions as Array<Record<string, unknown>>)
|
|
704
|
+
: []
|
|
705
|
+
const resolved = Boolean(messageId && interactionResolved)
|
|
706
|
+
return (
|
|
707
|
+
<div key={index} className="sandbox-rich-card">
|
|
708
|
+
{imageSrc && (
|
|
709
|
+
/* lgtm[js/xss,js/client-side-unvalidated-url-redirection] */
|
|
710
|
+
<img src={imageSrc} alt={title} className="sandbox-rich-card-image" onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />
|
|
711
|
+
)}
|
|
712
|
+
<div className="sandbox-rich-card-body">
|
|
713
|
+
{title && <div className="sandbox-rich-card-title">{title}</div>}
|
|
714
|
+
{subtitle && <div className="sandbox-rich-card-subtitle">{subtitle}</div>}
|
|
715
|
+
{description && <div className="sandbox-rich-card-desc"><MarkdownContent text={description} /></div>}
|
|
716
|
+
{fields.length > 0 && (
|
|
717
|
+
<dl className="sandbox-rich-card-fields">
|
|
718
|
+
{fields.map((field, fi) => (
|
|
719
|
+
<div key={fi} className="sandbox-rich-card-field">
|
|
720
|
+
<dt>{String(field.label ?? field.name ?? field.key ?? '')}</dt>
|
|
721
|
+
<dd>{String(field.value ?? '')}</dd>
|
|
722
|
+
</div>
|
|
723
|
+
))}
|
|
724
|
+
</dl>
|
|
725
|
+
)}
|
|
726
|
+
{buttons.length > 0 && (
|
|
727
|
+
<div className="agent-playground-approval-actions sandbox-rich-card-actions">
|
|
728
|
+
<div>
|
|
729
|
+
{buttons.map((btn, bi) => {
|
|
730
|
+
const label = String(btn.label ?? btn.text ?? btn.title ?? btn.id ?? `Action ${bi + 1}`)
|
|
731
|
+
const payload = String(btn.payload ?? btn.value ?? btn.url ?? btn.id ?? label)
|
|
732
|
+
return (
|
|
733
|
+
<button
|
|
734
|
+
key={`${payload}-${bi}`}
|
|
735
|
+
type="button"
|
|
736
|
+
disabled={Boolean(btn.disabled) || isSent || resolved || !canExecute || !allowInteraction}
|
|
737
|
+
onClick={() => { if (sendInteractiveAction(payload, messageId)) onInteractionSubmitted?.() }}
|
|
738
|
+
className={cn(
|
|
739
|
+
btn.style === 'primary' && 'is-primary',
|
|
740
|
+
btn.style === 'danger' && 'is-danger',
|
|
741
|
+
)}
|
|
742
|
+
>
|
|
743
|
+
{label}
|
|
744
|
+
</button>
|
|
745
|
+
)
|
|
746
|
+
})}
|
|
747
|
+
</div>
|
|
748
|
+
</div>
|
|
749
|
+
)}
|
|
750
|
+
{!title && !subtitle && !description && fields.length === 0 && buttons.length === 0 && (
|
|
751
|
+
<CodeBlock code={JSON.stringify(d, null, 2)} language="json" />
|
|
752
|
+
)}
|
|
753
|
+
</div>
|
|
754
|
+
</div>
|
|
755
|
+
)
|
|
756
|
+
}
|
|
757
|
+
case 'share': {
|
|
758
|
+
const url = typeof d.url === 'string' ? d.url : ''
|
|
759
|
+
const title = String(d.title ?? (url || 'Share'))
|
|
760
|
+
const description = typeof d.description === 'string'
|
|
761
|
+
? d.description
|
|
762
|
+
: typeof d.content === 'string'
|
|
763
|
+
? d.content
|
|
764
|
+
: typeof d.artist === 'string'
|
|
765
|
+
? d.artist
|
|
766
|
+
: ''
|
|
767
|
+
const rawImage = typeof d.image === 'string' ? d.image : pickMediaRawUrl(d)
|
|
768
|
+
const imageSrc = rawImage ? resolveMediaSrc(rawImage, 'image') : undefined
|
|
769
|
+
return (
|
|
770
|
+
<div key={index} className="sandbox-share-card">
|
|
771
|
+
{imageSrc && (
|
|
772
|
+
/* lgtm[js/xss,js/client-side-unvalidated-url-redirection] */
|
|
773
|
+
<img src={imageSrc} alt={title} className="sandbox-share-card-thumb" onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }} />
|
|
774
|
+
)}
|
|
775
|
+
<div className="sandbox-share-card-main">
|
|
776
|
+
<div className="sandbox-share-card-title">
|
|
777
|
+
<span>{title} <ExternalLink size={12} /></span>
|
|
778
|
+
</div>
|
|
779
|
+
{description && <div className="sandbox-share-card-desc">{description}</div>}
|
|
780
|
+
{url && <div className="sandbox-share-card-url">{url}</div>}
|
|
781
|
+
</div>
|
|
782
|
+
</div>
|
|
783
|
+
)
|
|
784
|
+
}
|
|
785
|
+
case 'button': {
|
|
786
|
+
const label = String(d.label ?? d.text ?? d.id ?? 'Button')
|
|
787
|
+
const payload = String(d.payload ?? d.id ?? label)
|
|
788
|
+
const resolved = Boolean(messageId && interactionResolved)
|
|
789
|
+
return (
|
|
790
|
+
<div key={index} className="agent-playground-approval-actions">
|
|
791
|
+
<div>
|
|
792
|
+
<button
|
|
793
|
+
type="button"
|
|
794
|
+
disabled={Boolean(d.disabled) || isSent || resolved || !canExecute || !allowInteraction}
|
|
795
|
+
onClick={() => { if (sendInteractiveAction(payload, messageId)) onInteractionSubmitted?.() }}
|
|
796
|
+
className={cn(
|
|
797
|
+
d.style === 'primary' && 'is-primary',
|
|
798
|
+
d.style === 'danger' && 'is-danger',
|
|
799
|
+
)}
|
|
800
|
+
>
|
|
801
|
+
{label}
|
|
802
|
+
</button>
|
|
803
|
+
</div>
|
|
804
|
+
</div>
|
|
805
|
+
)
|
|
806
|
+
}
|
|
672
807
|
case 'keyboard': {
|
|
673
808
|
const rows = (d.rows as Array<Array<{ label: string; payload: string; disabled?: boolean; style?: string }>>) ?? []
|
|
674
809
|
const resolved = Boolean(messageId && interactionResolved)
|
|
@@ -697,7 +832,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
697
832
|
)
|
|
698
833
|
}
|
|
699
834
|
default:
|
|
700
|
-
return <span key={index} className="
|
|
835
|
+
return <span key={index} className="sandbox-segment-note">[{segment.type}]</span>
|
|
701
836
|
}
|
|
702
837
|
})
|
|
703
838
|
}
|
|
@@ -705,13 +840,16 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
705
840
|
const handleSendMessage = (_text: string, segments: MessageSegment[]) => {
|
|
706
841
|
if (!connectionRef.current.canExecute || directoryModeRef.current === 'loading' || !hasRenderableSegments(segments)) return
|
|
707
842
|
const scene = activeChannelRef.current
|
|
843
|
+
const resolvedSenderId = senderId.trim() || connectionRef.current.ownerId || 'dev-user'
|
|
844
|
+
const resolvedSenderName = senderName.trim() || sandboxText(localeRef.current, "测试用户")
|
|
708
845
|
const newMessage: Message = {
|
|
709
846
|
id: createSandboxMessageId(), type: 'sent', channelType: scene.type, channelId: scene.id,
|
|
710
|
-
channelName: scene.name, senderId:
|
|
711
|
-
senderName:
|
|
847
|
+
channelName: scene.name, senderId: resolvedSenderId,
|
|
848
|
+
senderName: resolvedSenderName, content: segments, timestamp: Date.now(),
|
|
712
849
|
}
|
|
713
850
|
if (!submitSandboxFrame(wsRef.current, {
|
|
714
851
|
type: scene.type, id: scene.id, messageId: newMessage.id, content: segments,
|
|
852
|
+
senderId: resolvedSenderId, senderName: resolvedSenderName, senderRole,
|
|
715
853
|
agentRun: scene.runConfig, timestamp: newMessage.timestamp,
|
|
716
854
|
})) {
|
|
717
855
|
setTransportNotice(sandboxText(localeRef.current, "Sandbox 连接尚未就绪,消息未发送。"))
|
|
@@ -891,8 +1029,41 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
891
1029
|
|
|
892
1030
|
const recoveryConnectionId = connectionRef.current.connectionId
|
|
893
1031
|
return (
|
|
894
|
-
<section className={cn("zhin-
|
|
895
|
-
<style>{
|
|
1032
|
+
<section className={cn("zhin-sandbox agent-playground-shell", showInspector && "has-inspector")}>
|
|
1033
|
+
<style>{`${sandboxStyles}
|
|
1034
|
+
.sandbox-sender-trigger { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 6px; }
|
|
1035
|
+
.sandbox-role-badge { font-style: normal; font-size: 10px; font-weight: 600; text-transform: uppercase; padding: 1px 6px; border-radius: 999px; background: rgba(148,163,184,0.18); color: inherit; }
|
|
1036
|
+
.sandbox-role-badge.is-master { background: rgba(245,158,11,0.18); color: #d97706; }
|
|
1037
|
+
.sandbox-role-badge.is-admin { background: rgba(59,130,246,0.18); color: #2563eb; }
|
|
1038
|
+
.sandbox-role-badge.is-member { background: rgba(16,185,129,0.16); color: #059669; }
|
|
1039
|
+
.sandbox-role-switcher { display: inline-flex; gap: 4px; }
|
|
1040
|
+
.sandbox-role-option { padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.3); font-size: 12px; cursor: pointer; background: transparent; color: inherit; text-transform: capitalize; }
|
|
1041
|
+
.sandbox-role-option.active { font-weight: 600; border-color: currentColor; background: rgba(59,130,246,0.12); }
|
|
1042
|
+
.sandbox-sender-presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
|
|
1043
|
+
.sandbox-sender-presets button { font-size: 11px; padding: 3px 8px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.28); background: transparent; color: inherit; cursor: pointer; }
|
|
1044
|
+
.sandbox-quick-commands { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-left: 6px; }
|
|
1045
|
+
.sandbox-command-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid rgba(148,163,184,0.28); background: transparent; color: inherit; cursor: pointer; }
|
|
1046
|
+
.sandbox-command-chip:hover:not(:disabled) { border-color: rgba(59,130,246,0.5); background: rgba(59,130,246,0.08); }
|
|
1047
|
+
.sandbox-command-chip:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
1048
|
+
.sandbox-rich-card { border: 1px solid rgba(148,163,184,0.28); border-radius: 10px; overflow: hidden; margin-top: 6px; max-width: 440px; background: rgba(148,163,184,0.06); }
|
|
1049
|
+
.sandbox-rich-card-image { width: 100%; max-height: 200px; object-fit: cover; display: block; }
|
|
1050
|
+
.sandbox-rich-card-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
|
|
1051
|
+
.sandbox-rich-card-title { font-weight: 600; font-size: 14px; }
|
|
1052
|
+
.sandbox-rich-card-subtitle { font-size: 12px; opacity: 0.75; }
|
|
1053
|
+
.sandbox-rich-card-desc { font-size: 13px; }
|
|
1054
|
+
.sandbox-rich-card-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin: 4px 0 0; }
|
|
1055
|
+
.sandbox-rich-card-field { background: rgba(148,163,184,0.08); padding: 4px 8px; border-radius: 6px; }
|
|
1056
|
+
.sandbox-rich-card-field dt { font-size: 11px; opacity: 0.7; }
|
|
1057
|
+
.sandbox-rich-card-field dd { margin: 0; font-size: 12px; font-weight: 500; }
|
|
1058
|
+
.sandbox-card-link-btn { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 4px 10px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.3); text-decoration: none; color: inherit; }
|
|
1059
|
+
.sandbox-share-card { display: flex; gap: 10px; align-items: center; border: 1px solid rgba(148,163,184,0.28); border-radius: 10px; padding: 8px 12px; margin-top: 6px; max-width: 440px; background: rgba(148,163,184,0.06); }
|
|
1060
|
+
.sandbox-share-card-thumb { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
|
|
1061
|
+
.sandbox-share-card-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
|
|
1062
|
+
.sandbox-share-card-title { font-weight: 600; font-size: 13px; }
|
|
1063
|
+
.sandbox-share-card-title a { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: underline; }
|
|
1064
|
+
.sandbox-share-card-desc { font-size: 12px; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }
|
|
1065
|
+
.sandbox-share-card-url { font-size: 11px; opacity: 0.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1066
|
+
`}</style>
|
|
896
1067
|
<div className="agent-playground-mobilebar">
|
|
897
1068
|
<button type="button" aria-expanded={showChannelList} onClick={() => setShowChannelList(!showChannelList)}><MessageSquare size={17} />{sandboxText(locale, "会话列表")}</button>
|
|
898
1069
|
<strong>{sandboxText(locale, "会话")}</strong>
|
|
@@ -901,8 +1072,8 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
901
1072
|
|
|
902
1073
|
<nav className={cn("channel-sidebar agent-playground-sessions", showChannelList && "show")} aria-label={sandboxText(locale, "会话列表")}>
|
|
903
1074
|
<div className="agent-playground-brand">
|
|
904
|
-
<div
|
|
905
|
-
<div
|
|
1075
|
+
<div>
|
|
1076
|
+
<div>
|
|
906
1077
|
<span className="agent-playground-mark"><Sparkles size={16} /></span>
|
|
907
1078
|
<div><h2>{sandboxText(locale, "会话")}</h2><small>Conversations</small></div>
|
|
908
1079
|
</div>
|
|
@@ -919,11 +1090,11 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
919
1090
|
return (
|
|
920
1091
|
<button type="button" key={`${channel.type}:${channel.id}`} disabled={directoryStatus.mode === 'loading'} aria-current={isActive ? 'page' : undefined} className={cn("agent-playground-session", isActive && "active")} onClick={() => switchChannel(channel)}>
|
|
921
1092
|
<span className="agent-playground-session-icon">{getChannelIcon(channel.type)}</span>
|
|
922
|
-
<div className="
|
|
923
|
-
<div className="
|
|
924
|
-
<div className="
|
|
1093
|
+
<div className="agent-playground-session-copy">
|
|
1094
|
+
<div className="agent-playground-session-title">{channel.name}</div>
|
|
1095
|
+
<div className="agent-playground-session-scope">{channel.type === 'private' ? sandboxText(locale, "单用户作用域") : channel.type === 'group' ? sandboxText(locale, "群组作用域") : sandboxText(locale, "频道作用域")}</div>
|
|
925
1096
|
</div>
|
|
926
|
-
{channel.unread > 0 && <span className="
|
|
1097
|
+
{channel.unread > 0 && <span className="agent-playground-unread">{channel.unread}</span>}
|
|
927
1098
|
</button>
|
|
928
1099
|
)
|
|
929
1100
|
})}
|
|
@@ -978,12 +1149,67 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
978
1149
|
{props.renderConversationDetails
|
|
979
1150
|
? <button type="button" disabled={!canExecute} aria-expanded={showConversationDetails} aria-controls="sandbox-conversation-details" onClick={() => setShowConversationDetails((visible) => !visible)}><ListChecks size={14} />{sandboxText(locale, "对话与轨迹")}</button>
|
|
980
1151
|
: <a href={agentSessionsPath(sessionKey)}><ExternalLink size={14} />{sandboxText(locale, "对话与轨迹")}</a>}
|
|
1152
|
+
<button
|
|
1153
|
+
type="button"
|
|
1154
|
+
className={cn("sandbox-sender-trigger", showSenderSettings && "active")}
|
|
1155
|
+
aria-expanded={showSenderSettings}
|
|
1156
|
+
onClick={() => setShowSenderSettings((visible) => !visible)}
|
|
1157
|
+
title={locale === 'en' ? 'Simulated sender identity & role' : '模拟发送者身份与角色'}
|
|
1158
|
+
>
|
|
1159
|
+
<User size={14} />
|
|
1160
|
+
<span>{senderName.trim() || senderId.trim() || 'dev-user'}</span>
|
|
1161
|
+
<em className={cn("sandbox-role-badge", `is-${senderRole}`)}>{senderRole}</em>
|
|
1162
|
+
</button>
|
|
981
1163
|
<button type="button" className={cn(showRunSettings && 'active')} aria-expanded={showRunSettings} onClick={() => setShowRunSettings((visible) => !visible)} aria-label={sandboxText(locale, "配置运行环境")}><SlidersHorizontal size={16} /></button>
|
|
982
1164
|
<button type="button" aria-expanded={showInspector} aria-controls="sandbox-run-inspector" onClick={() => setShowInspector(!showInspector)} aria-label={sandboxText(locale, "切换运行检查器")}><PanelRight size={16} /></button>
|
|
983
1165
|
<button type="button" onClick={() => setConfirmClear(true)} aria-label={sandboxText(locale, "清空当前会话")}><Trash2 size={15} /></button>
|
|
984
1166
|
</div>
|
|
985
1167
|
</header>
|
|
986
1168
|
|
|
1169
|
+
{showSenderSettings && (
|
|
1170
|
+
<section className="agent-playground-run-settings sandbox-sender-settings" aria-label={locale === 'en' ? 'Simulated sender' : '模拟发送者配置'}>
|
|
1171
|
+
<label>
|
|
1172
|
+
<span><User size={14} />{locale === 'en' ? 'Sender ID' : '发送者 ID'}</span>
|
|
1173
|
+
<input
|
|
1174
|
+
value={senderId}
|
|
1175
|
+
onChange={(event) => setSenderId(event.target.value)}
|
|
1176
|
+
placeholder="dev-user"
|
|
1177
|
+
spellCheck={false}
|
|
1178
|
+
/>
|
|
1179
|
+
</label>
|
|
1180
|
+
<label>
|
|
1181
|
+
<span>{locale === 'en' ? 'Sender Name' : '发送者昵称'}</span>
|
|
1182
|
+
<input
|
|
1183
|
+
value={senderName}
|
|
1184
|
+
onChange={(event) => setSenderName(event.target.value)}
|
|
1185
|
+
placeholder="Developer"
|
|
1186
|
+
spellCheck={false}
|
|
1187
|
+
/>
|
|
1188
|
+
</label>
|
|
1189
|
+
<label>
|
|
1190
|
+
<span><ShieldCheck size={14} />{locale === 'en' ? 'Sender Role' : '角色权限'}</span>
|
|
1191
|
+
<div className="sandbox-role-switcher" role="group" aria-label={locale === 'en' ? 'Sender role' : '角色权限'}>
|
|
1192
|
+
{(['member', 'admin', 'master'] as const).map((role) => (
|
|
1193
|
+
<button
|
|
1194
|
+
key={role}
|
|
1195
|
+
type="button"
|
|
1196
|
+
aria-pressed={senderRole === role}
|
|
1197
|
+
className={cn("sandbox-role-option", `is-${role}`, senderRole === role && "active")}
|
|
1198
|
+
onClick={() => setSenderRole(role)}
|
|
1199
|
+
>
|
|
1200
|
+
{role}
|
|
1201
|
+
</button>
|
|
1202
|
+
))}
|
|
1203
|
+
</div>
|
|
1204
|
+
</label>
|
|
1205
|
+
<div className="sandbox-sender-presets">
|
|
1206
|
+
<button type="button" onClick={() => { setSenderId('dev-user'); setSenderName('Developer'); setSenderRole('master') }}>Master (dev-user)</button>
|
|
1207
|
+
<button type="button" onClick={() => { setSenderId('admin-user'); setSenderName('Admin'); setSenderRole('admin') }}>Admin (admin-user)</button>
|
|
1208
|
+
<button type="button" onClick={() => { setSenderId('member-user'); setSenderName('Member'); setSenderRole('member') }}>Member (member-user)</button>
|
|
1209
|
+
</div>
|
|
1210
|
+
</section>
|
|
1211
|
+
)}
|
|
1212
|
+
|
|
987
1213
|
{cancellationFeedback && <div className="agent-playground-confirm" role={cancellationFeedback.kind === 'error' ? 'alert' : 'status'}>
|
|
988
1214
|
<div><span>{cancellationFeedback.message}</span></div>
|
|
989
1215
|
<button type="button" onClick={() => setCancellationFeedback(null)}>{sandboxText(locale, "知道了")}</button>
|
|
@@ -997,6 +1223,14 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
997
1223
|
</div>
|
|
998
1224
|
)}
|
|
999
1225
|
|
|
1226
|
+
{(['emoji', 'parse'] as const).filter((kind) => inlineNotices[kind]).map((kind) => (
|
|
1227
|
+
<div key={kind} className="sandbox-notice" role="status">
|
|
1228
|
+
<CircleAlert size={14} />
|
|
1229
|
+
<span>{kind === 'emoji' ? sandboxText(locale, "表情列表加载失败,表情选择器暂不可用。") : sandboxText(locale, "收到一条无法解析的消息,已忽略。")}</span>
|
|
1230
|
+
<button type="button" onClick={() => setInlineNotices((n) => ({ ...n, [kind]: false }))}>{sandboxText(locale, "知道了")}</button>
|
|
1231
|
+
</div>
|
|
1232
|
+
))}
|
|
1233
|
+
|
|
1000
1234
|
{transportNotice && (
|
|
1001
1235
|
<div className="agent-playground-confirm" role="status">
|
|
1002
1236
|
<div><strong>{sandboxText(locale, "运行暂不可用")}</strong><span>{transportNotice}</span></div>
|
|
@@ -1137,59 +1371,83 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1137
1371
|
{/* Input area */}
|
|
1138
1372
|
<section className="agent-playground-composer" hidden={showConversationDetails} aria-label={sandboxText(locale, "任务输入")}>
|
|
1139
1373
|
{/* Toolbar */}
|
|
1140
|
-
<div className="
|
|
1141
|
-
<button type="button" className={cn("
|
|
1374
|
+
<div className="sandbox-toolbar">
|
|
1375
|
+
<button type="button" className={cn("sandbox-tool-button", showFacePicker && "is-active")}
|
|
1142
1376
|
onClick={() => { setShowFacePicker(!showFacePicker); setMediaPanel(null) }} title={sandboxText(locale, "插入表情")}>
|
|
1143
1377
|
<Smile size={16} />
|
|
1144
1378
|
</button>
|
|
1145
|
-
<button type="button" className={cn("
|
|
1379
|
+
<button type="button" className={cn("sandbox-tool-button", mediaPanel === 'image' && "is-active")}
|
|
1146
1380
|
onClick={() => { setMediaPanel((p) => (p === 'image' ? null : 'image')); setShowFacePicker(false) }} title={sandboxText(locale, "插入图片 URL")}>
|
|
1147
1381
|
<Image size={16} />
|
|
1148
1382
|
</button>
|
|
1149
|
-
<button type="button" className={cn("
|
|
1383
|
+
<button type="button" className={cn("sandbox-tool-button", mediaPanel === 'video' && "is-active")}
|
|
1150
1384
|
onClick={() => { setMediaPanel((p) => (p === 'video' ? null : 'video')); setShowFacePicker(false) }} title={sandboxText(locale, "插入视频 URL")}>
|
|
1151
1385
|
<Video size={16} />
|
|
1152
1386
|
</button>
|
|
1153
|
-
<button type="button" className={cn("
|
|
1387
|
+
<button type="button" className={cn("sandbox-tool-button", mediaPanel === 'audio' && "is-active")}
|
|
1154
1388
|
onClick={() => { setMediaPanel((p) => (p === 'audio' ? null : 'audio')); setShowFacePicker(false) }} title={sandboxText(locale, "插入音频 URL")}>
|
|
1155
1389
|
<Music size={16} />
|
|
1156
1390
|
</button>
|
|
1157
|
-
<div className="
|
|
1391
|
+
<div className="sandbox-quick-commands" role="toolbar" aria-label={locale === 'en' ? 'Quick commands' : '快捷命令'}>
|
|
1392
|
+
{['/help', 'help', 'ping', '/status'].map((cmd) => (
|
|
1393
|
+
<button
|
|
1394
|
+
key={cmd}
|
|
1395
|
+
type="button"
|
|
1396
|
+
className="sandbox-command-chip"
|
|
1397
|
+
disabled={!canExecute || directoryStatus.mode === 'loading'}
|
|
1398
|
+
onClick={() => runPrompt(cmd)}
|
|
1399
|
+
>
|
|
1400
|
+
<Terminal size={11} />
|
|
1401
|
+
<span>{cmd}</span>
|
|
1402
|
+
</button>
|
|
1403
|
+
))}
|
|
1404
|
+
<button
|
|
1405
|
+
type="button"
|
|
1406
|
+
className="sandbox-command-chip is-clear"
|
|
1407
|
+
disabled={channelMessages.length === 0}
|
|
1408
|
+
onClick={clearMessages}
|
|
1409
|
+
title={sandboxText(locale, "清空当前会话")}
|
|
1410
|
+
>
|
|
1411
|
+
<Trash2 size={11} />
|
|
1412
|
+
<span>{locale === 'en' ? 'Clear' : '清屏'}</span>
|
|
1413
|
+
</button>
|
|
1414
|
+
</div>
|
|
1415
|
+
<div className="sandbox-toolbar-spacer" />
|
|
1158
1416
|
<div className="sandbox-composer-tabs" role="tablist" aria-label={sandboxText(locale, "消息编辑模式")}>
|
|
1159
1417
|
<button type="button" role="tab" aria-selected={composerMode === 'write'} className={cn(composerMode === 'write' && 'active')} onClick={() => setComposerMode('write')}>{sandboxText(locale, "编写")}</button>
|
|
1160
1418
|
<button type="button" role="tab" aria-selected={composerMode === 'preview'} className={cn(composerMode === 'preview' && 'active')} onClick={() => setComposerMode('preview')}>{sandboxText(locale, "预览")}</button>
|
|
1161
1419
|
</div>
|
|
1162
1420
|
{inputText && (
|
|
1163
|
-
<button className="
|
|
1421
|
+
<button type="button" className="sandbox-tool-button"
|
|
1164
1422
|
onClick={() => { editorRef.current?.clear(); setInputText(''); setPreviewSegments([]); setComposerMode('write') }} aria-label={sandboxText(locale, "清空输入")}><X size={16} /></button>
|
|
1165
1423
|
)}
|
|
1166
1424
|
</div>
|
|
1167
1425
|
|
|
1168
1426
|
{/* Face picker */}
|
|
1169
1427
|
{showFacePicker && (
|
|
1170
|
-
<div className="
|
|
1428
|
+
<div className="sandbox-panel">
|
|
1171
1429
|
<input value={faceSearchQuery} onChange={(e) => setFaceSearchQuery(e.target.value)}
|
|
1172
|
-
placeholder={sandboxText(locale, "搜索表情...")} className="
|
|
1173
|
-
<div className="
|
|
1430
|
+
placeholder={sandboxText(locale, "搜索表情...")} className="sandbox-input" />
|
|
1431
|
+
<div className="sandbox-face-grid">
|
|
1174
1432
|
{filteredFaces.slice(0, 80).map((face) => (
|
|
1175
1433
|
<button key={face.id} onClick={() => insertFace(face.id)} title={face.name}
|
|
1176
|
-
className="
|
|
1177
|
-
<img src={`https://face.viki.moe/apng/${face.id}.png`} alt={face.name} className="
|
|
1434
|
+
className="sandbox-face-button" type="button">
|
|
1435
|
+
<img src={`https://face.viki.moe/apng/${face.id}.png`} alt={face.name} className="sandbox-face-img" />
|
|
1178
1436
|
</button>
|
|
1179
1437
|
))}
|
|
1180
1438
|
</div>
|
|
1181
1439
|
{filteredFaces.length === 0 && (
|
|
1182
|
-
<div className="
|
|
1183
|
-
<Search size={
|
|
1184
|
-
<span
|
|
1440
|
+
<div className="sandbox-empty-hint">
|
|
1441
|
+
<Search size={28} />
|
|
1442
|
+
<span>{sandboxText(locale, "未找到匹配的表情")}</span>
|
|
1185
1443
|
</div>
|
|
1186
1444
|
)}
|
|
1187
1445
|
</div>
|
|
1188
1446
|
)}
|
|
1189
1447
|
|
|
1190
1448
|
{mediaPanel && (
|
|
1191
|
-
<div className="
|
|
1192
|
-
<p className="
|
|
1449
|
+
<div className="sandbox-panel">
|
|
1450
|
+
<p className="sandbox-panel-hint">
|
|
1193
1451
|
{mediaPanel === 'image' && sandboxText(locale, "支持 http(s) 图片链接或 data URL")}
|
|
1194
1452
|
{mediaPanel === 'video' && sandboxText(locale, "支持浏览器可解码的视频直链(如 .mp4、.webm)")}
|
|
1195
1453
|
{mediaPanel === 'audio' && sandboxText(locale, "支持 .mp3、.ogg、.wav 等音频直链")}
|
|
@@ -1198,12 +1456,12 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1198
1456
|
value={mediaUrl}
|
|
1199
1457
|
onChange={(e) => setMediaUrl(e.target.value)}
|
|
1200
1458
|
placeholder={mediaPanel === 'image' ? sandboxText(locale, "图片 URL…") : mediaPanel === 'video' ? sandboxText(locale, "视频 URL…") : sandboxText(locale, "音频 URL…")}
|
|
1201
|
-
className="
|
|
1459
|
+
className="sandbox-input"
|
|
1202
1460
|
onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault(); commitMediaUrl() } }}
|
|
1203
1461
|
/>
|
|
1204
1462
|
<button
|
|
1205
1463
|
type="button"
|
|
1206
|
-
className="
|
|
1464
|
+
className="sandbox-submit"
|
|
1207
1465
|
onClick={commitMediaUrl}
|
|
1208
1466
|
disabled={!mediaUrl.trim()}
|
|
1209
1467
|
>
|
|
@@ -1212,9 +1470,9 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1212
1470
|
)}
|
|
1213
1471
|
|
|
1214
1472
|
{/* Editor + send */}
|
|
1215
|
-
<div className="
|
|
1216
|
-
<div className="
|
|
1217
|
-
<div
|
|
1473
|
+
<div className="sandbox-editor-row">
|
|
1474
|
+
<div className="sandbox-editor-wrap">
|
|
1475
|
+
<div hidden={composerMode !== 'write'}>
|
|
1218
1476
|
<RichTextEditor
|
|
1219
1477
|
locale={locale}
|
|
1220
1478
|
ref={editorRef} placeholder={sandboxText(locale, "向 {0} 发送消息,支持 Markdown...", [activeChannel.name])}
|
|
@@ -1230,33 +1488,34 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1230
1488
|
</div>
|
|
1231
1489
|
)}
|
|
1232
1490
|
{atPopoverPosition && (
|
|
1233
|
-
<div className="
|
|
1491
|
+
<div className="sandbox-at-popover"
|
|
1234
1492
|
style={{ top: `${atPopoverPosition.top}px`, left: `${atPopoverPosition.left}px` }}>
|
|
1235
1493
|
{filteredAtSuggestions.length > 0 ? filteredAtSuggestions.map((user) => (
|
|
1236
|
-
<div key={user.id} className="
|
|
1237
|
-
<User size={16}
|
|
1238
|
-
<div
|
|
1494
|
+
<div key={user.id} className="sandbox-at-item" onClick={() => selectAtUser(user)}>
|
|
1495
|
+
<User size={16} />
|
|
1496
|
+
<div><div className="sandbox-at-name">{user.name}</div><div className="sandbox-at-id">ID: {user.id}</div></div>
|
|
1239
1497
|
</div>
|
|
1240
1498
|
)) : (
|
|
1241
|
-
<div className="
|
|
1242
|
-
<Search size={20}
|
|
1243
|
-
<span
|
|
1499
|
+
<div className="sandbox-empty-hint">
|
|
1500
|
+
<Search size={20} />
|
|
1501
|
+
<span>{sandboxText(locale, "未找到匹配的用户")}</span>
|
|
1244
1502
|
</div>
|
|
1245
1503
|
)}
|
|
1246
1504
|
</div>
|
|
1247
1505
|
)}
|
|
1248
1506
|
</div>
|
|
1249
1507
|
<button
|
|
1250
|
-
|
|
1508
|
+
type="button"
|
|
1509
|
+
className="sandbox-send"
|
|
1251
1510
|
onClick={() => { const c = editorRef.current?.getContent(); if (c) handleSendMessage(c.text, c.segments) }}
|
|
1252
1511
|
disabled={!canExecute || directoryStatus.mode === 'loading' || !hasRenderableSegments(previewSegments)}>
|
|
1253
1512
|
<Send size={16} /> {sandboxText(locale, "发送")}</button>
|
|
1254
1513
|
</div>
|
|
1255
1514
|
|
|
1256
1515
|
{/* Hints */}
|
|
1257
|
-
<div className="
|
|
1258
|
-
<Info size={12} /> {sandboxText(locale, "快捷操作:")}<span className="
|
|
1259
|
-
<span className="
|
|
1516
|
+
<div className="sandbox-hints">
|
|
1517
|
+
<Info size={12} /> {sandboxText(locale, "快捷操作:")}<span className="sandbox-hint-key">Enter</span> {sandboxText(locale, "发送")}<span className="sandbox-hint-key">Shift+Enter</span> {sandboxText(locale, "换行")}<span className="sandbox-hint-key">```ts</span> {sandboxText(locale, "代码块")}<span className="sandbox-hint-key">{sandboxText(locale, "**文本**")}</span> {sandboxText(locale, "加粗")}<span className="sandbox-hint-key">{sandboxText(locale, "[@名称]")}</span> {sandboxText(locale, "@某人")}<span className="sandbox-hint-key">[video:URL]</span>
|
|
1518
|
+
<span className="sandbox-hint-key">[audio:URL]</span>
|
|
1260
1519
|
</div>
|
|
1261
1520
|
</section>
|
|
1262
1521
|
</main>
|
|
@@ -1265,7 +1524,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1265
1524
|
<div className="agent-playground-inspector-head">
|
|
1266
1525
|
<div><span>Run inspector</span><h2>{sandboxText(locale, "运行检查器")}</h2></div>
|
|
1267
1526
|
<div>
|
|
1268
|
-
<button type="button" onClick={() => void loadTrace()} aria-label={sandboxText(locale, "刷新 Agent Trace")} disabled={traceLoading}><RefreshCw size={15} className={cn(traceLoading && '
|
|
1527
|
+
<button type="button" onClick={() => void loadTrace()} aria-label={sandboxText(locale, "刷新 Agent Trace")} disabled={traceLoading}><RefreshCw size={15} className={cn(traceLoading && 'is-spinning')} /></button>
|
|
1269
1528
|
<button type="button" className="agent-playground-inspector-close" onClick={() => setShowInspector(false)} aria-label={sandboxText(locale, "关闭运行检查器")}><X size={15} /></button>
|
|
1270
1529
|
</div>
|
|
1271
1530
|
</div>
|
|
@@ -1275,7 +1534,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1275
1534
|
<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>
|
|
1276
1535
|
</div>
|
|
1277
1536
|
|
|
1278
|
-
<div className={
|
|
1537
|
+
<div className={"agent-playground-inspector-view"} hidden={inspectorView !== 'runs'}>
|
|
1279
1538
|
|
|
1280
1539
|
<section className="agent-playground-inspector-section">
|
|
1281
1540
|
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "运行概览")}</span><small>{traceSummary.activeTurns > 0 ? 'live' : 'idle'}</small></div>
|
|
@@ -1345,7 +1604,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1345
1604
|
</section>
|
|
1346
1605
|
</div>
|
|
1347
1606
|
|
|
1348
|
-
<div className={
|
|
1607
|
+
<div className={"agent-playground-inspector-view"} hidden={inspectorView !== 'artifacts'}>
|
|
1349
1608
|
<section className="agent-playground-inspector-section agent-playground-artifact-section">
|
|
1350
1609
|
<div className="agent-playground-inspector-title"><span>{sandboxText(locale, "文件与命令产物")}</span><small>{workbenchArtifacts.length} items</small></div>
|
|
1351
1610
|
{workbenchArtifacts.length > 0 ? (
|
|
@@ -1365,7 +1624,7 @@ export default function Sandbox(props: SandboxPageProps = {}) {
|
|
|
1365
1624
|
<div className="agent-playground-artifact-detail">
|
|
1366
1625
|
{artifact.path && <code>{artifact.path}</code>}
|
|
1367
1626
|
{canExecute && artifact.projectFilePath && (
|
|
1368
|
-
<a href={`/files?${new URLSearchParams({ path: artifact.projectFilePath })}`} target="_blank" rel="noopener noreferrer" className="
|
|
1627
|
+
<a href={`/files?${new URLSearchParams({ path: artifact.projectFilePath })}`} target="_blank" rel="noopener noreferrer" className="sandbox-file-link">
|
|
1369
1628
|
<ExternalLink size={13} />{sandboxText(locale, "打开当前文件")}
|
|
1370
1629
|
</a>
|
|
1371
1630
|
)}
|