@zhin.js/adapter-sandbox 3.0.4 → 3.0.6
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 +101 -77
- package/README.md +21 -45
- package/client/Sandbox.tsx +9 -72
- package/client/index.tsx +1 -1
- package/client/sandboxTransport.ts +0 -49
- package/client/tsconfig.json +1 -1
- package/dist/index.js +8 -8
- package/lib/index.d.ts +2 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/sandbox-ws.d.ts +3 -18
- package/lib/sandbox-ws.d.ts.map +1 -1
- package/lib/sandbox-ws.js +2 -81
- package/lib/sandbox-ws.js.map +1 -1
- package/package.json +10 -16
- package/src/index.ts +3 -12
- package/src/sandbox-ws.ts +3 -103
- package/lib/fetch-sse.d.ts +0 -11
- package/lib/fetch-sse.d.ts.map +0 -1
- package/lib/fetch-sse.js +0 -76
- package/lib/fetch-sse.js.map +0 -1
- package/lib/fetch-ws.d.ts +0 -11
- package/lib/fetch-ws.d.ts.map +0 -1
- package/lib/fetch-ws.js +0 -13
- package/lib/fetch-ws.js.map +0 -1
- package/lib/sandbox-sse-hub.d.ts +0 -10
- package/lib/sandbox-sse-hub.d.ts.map +0 -1
- package/lib/sandbox-sse-hub.js +0 -101
- package/lib/sandbox-sse-hub.js.map +0 -1
- package/src/fetch-sse.ts +0 -87
- package/src/fetch-ws.ts +0 -23
- package/src/sandbox-sse-hub.ts +0 -118
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# @zhin.js/adapter-sandbox
|
|
2
2
|
|
|
3
|
-
Zhin.js Sandbox 适配器,基于 WebSocket
|
|
3
|
+
Zhin.js Sandbox 适配器,基于 WebSocket 的本地测试适配器;浏览器端聊天 UI 在 **[Remote Console](https://console.zhin.dev)**(Host 仅 Console API)中打开 Sandbox 窗口调试。
|
|
4
4
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
7
|
- **Node Host**:WebSocket `/sandbox`
|
|
8
|
-
- **Edge**(Vercel 等):`transport: http-sse` — `POST /sandbox/message` + `GET /sandbox/events`
|
|
9
8
|
- 浏览器端 React 聊天 UI
|
|
10
9
|
- 支持多客户端同时连接
|
|
11
10
|
- 无需第三方平台账号,即开即用
|
|
@@ -21,64 +20,41 @@ pnpm add @zhin.js/adapter-sandbox
|
|
|
21
20
|
|
|
22
21
|
Sandbox 适配器需要以下服务插件:
|
|
23
22
|
|
|
24
|
-
- `@zhin.js/
|
|
25
|
-
- `@zhin.js/
|
|
26
|
-
- `@zhin.js/client` —
|
|
23
|
+
- `@zhin.js/host-router` — HTTP 服务(提供 Router 和 WebSocket)
|
|
24
|
+
- `@zhin.js/host-api` — Host 侧 Console API(`addEntry` 注册 Sandbox 扩展)
|
|
25
|
+
- `@zhin.js/client` — Remote Console 客户端 SDK(UI 在 zhin-console 仓库)
|
|
27
26
|
|
|
28
27
|
## 配置
|
|
29
28
|
|
|
29
|
+
**推荐(与 [minimal-bot](../../../examples/minimal-bot/) 一致)**:`bots: []`,在 Remote Console 打开「沙盒」页时经 `/sandbox` WebSocket **自动创建** bot(如 `sandbox-xxxx`),无需在 yaml 里写 `context: sandbox`。
|
|
30
|
+
|
|
30
31
|
```yaml
|
|
31
32
|
# zhin.config.yml
|
|
32
|
-
bots:
|
|
33
|
-
- context: sandbox
|
|
34
|
-
name: sandbox-bot
|
|
35
|
-
# transport: http-sse # Edge / Vercel;Node 省略或 websocket
|
|
33
|
+
bots: []
|
|
36
34
|
|
|
37
35
|
plugins:
|
|
38
|
-
- adapter-sandbox
|
|
39
|
-
-
|
|
40
|
-
-
|
|
36
|
+
- "@zhin.js/adapter-sandbox"
|
|
37
|
+
- "@zhin.js/host-router"
|
|
38
|
+
- "@zhin.js/host-api"
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
bots: [
|
|
50
|
-
{
|
|
51
|
-
context: 'sandbox',
|
|
52
|
-
name: 'sandbox-bot',
|
|
53
|
-
}
|
|
54
|
-
],
|
|
55
|
-
plugins: [
|
|
56
|
-
'adapter-sandbox',
|
|
57
|
-
'http',
|
|
58
|
-
'console',
|
|
59
|
-
]
|
|
60
|
-
})
|
|
41
|
+
可选:若需在启动时即在 bot 列表显示**固定名称**的离线占位 bot,可显式配置:
|
|
42
|
+
|
|
43
|
+
```yaml
|
|
44
|
+
bots:
|
|
45
|
+
- context: sandbox
|
|
46
|
+
name: sandbox-bot
|
|
61
47
|
```
|
|
62
48
|
|
|
63
49
|
## 使用方式
|
|
64
50
|
|
|
65
|
-
1. 启动机器人:`pnpm dev`
|
|
66
|
-
2.
|
|
67
|
-
3.
|
|
68
|
-
|
|
69
|
-
每个浏览器客户端连接后创建 Sandbox Bot(无 yaml 固定名时为 `sandbox-xxxx`)。传输层在 `src/sandbox-ws.ts`(WS)与 `src/fetch-sse.ts`(SSE)。
|
|
70
|
-
|
|
71
|
-
**Node**(默认 `transport: websocket`):`Router.ws("/sandbox")`(插件 `useContext("router")` 自动挂载)。
|
|
51
|
+
1. 启动机器人:`pnpm dev`(终端会打印 Host 地址,一般为 `http://127.0.0.1:8086`)
|
|
52
|
+
2. 打开 **[Remote Console](https://console.zhin.dev)**,API Base 与 Host 地址一致,Token 与 `http.token` / `HTTP_TOKEN` 一致
|
|
53
|
+
3. 在 Console **沙盒** 页连接后发送消息进行测试
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
import { registerSandboxSseRoutes } from "@zhin.js/adapter-sandbox/edge";
|
|
77
|
-
|
|
78
|
-
registerSandboxSseRoutes(routeTable, () => plugin.inject("sandbox"));
|
|
79
|
-
```
|
|
55
|
+
每个浏览器客户端连接后创建 Sandbox Bot(无 yaml 固定名时为 `sandbox-xxxx`)。
|
|
80
56
|
|
|
81
|
-
|
|
57
|
+
通过 `Router.ws("/sandbox")`(插件 `useContext("router")` 自动挂载)建立连接。
|
|
82
58
|
|
|
83
59
|
## 消息格式
|
|
84
60
|
|
package/client/Sandbox.tsx
CHANGED
|
@@ -2,10 +2,6 @@ import React, { useState, useEffect, useRef } from 'react';
|
|
|
2
2
|
import { MessageSegment, cn, resolveMediaSrc, pickMediaRawUrl } from '@zhin.js/client';
|
|
3
3
|
import {
|
|
4
4
|
getSandboxApiBase,
|
|
5
|
-
getSandboxAuthHeaders,
|
|
6
|
-
getSandboxSessionId,
|
|
7
|
-
resolveSandboxTransport,
|
|
8
|
-
transportFromModuleUrl,
|
|
9
5
|
} from './sandboxTransport';
|
|
10
6
|
import { User, Users, Trash2, Send, Hash, MessageSquare, Wifi, WifiOff, Smile, Image, X, Check, Info, Search, Bot, UserPlus, Bell, Video, Music } from 'lucide-react';
|
|
11
7
|
import RichTextEditor, { RichTextEditorRef } from './RichTextEditor';
|
|
@@ -50,10 +46,6 @@ export default function Sandbox() {
|
|
|
50
46
|
const [viewMode, setViewMode] = useState<'chat' | 'requests' | 'notices'>('chat')
|
|
51
47
|
const messagesEndRef = useRef<HTMLDivElement>(null)
|
|
52
48
|
const wsRef = useRef<WebSocket | null>(null)
|
|
53
|
-
const esRef = useRef<EventSource | null>(null)
|
|
54
|
-
const transportRef = useRef<'websocket' | 'http-sse'>('websocket')
|
|
55
|
-
const apiBaseRef = useRef('')
|
|
56
|
-
const sessionIdRef = useRef('')
|
|
57
49
|
const editorRef = useRef<RichTextEditorRef>(null)
|
|
58
50
|
|
|
59
51
|
const fetchFaceList = async () => {
|
|
@@ -92,62 +84,20 @@ export default function Sandbox() {
|
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
useEffect(() => {
|
|
95
|
-
let cancelled = false
|
|
96
87
|
const base = getSandboxApiBase()
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const wsUrl = new URL('/sandbox', `${base}/`)
|
|
105
|
-
wsUrl.protocol = wsUrl.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
106
|
-
wsRef.current = new WebSocket(wsUrl.href)
|
|
107
|
-
wsRef.current.onopen = () => setConnected(true)
|
|
108
|
-
wsRef.current.onmessage = (event) => {
|
|
109
|
-
try { handleInboundPayload(JSON.parse(event.data)) }
|
|
110
|
-
catch (err) { console.error('[Sandbox] Failed to parse message:', err) }
|
|
111
|
-
}
|
|
112
|
-
wsRef.current.onclose = () => setConnected(false)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const connectSse = () => {
|
|
116
|
-
if (esRef.current) return
|
|
117
|
-
transportRef.current = 'http-sse'
|
|
118
|
-
const eventsUrl = new URL('/sandbox/events', `${base}/`)
|
|
119
|
-
eventsUrl.searchParams.set('session', sessionId)
|
|
120
|
-
const auth = getSandboxAuthHeaders().Authorization
|
|
121
|
-
if (auth?.startsWith('Bearer ')) {
|
|
122
|
-
eventsUrl.searchParams.set('access_token', auth.slice(7))
|
|
123
|
-
}
|
|
124
|
-
esRef.current = new EventSource(eventsUrl.href)
|
|
125
|
-
esRef.current.onopen = () => setConnected(true)
|
|
126
|
-
esRef.current.onmessage = (event) => {
|
|
127
|
-
try { handleInboundPayload(JSON.parse(event.data)) }
|
|
128
|
-
catch (err) { console.error('[Sandbox] Failed to parse SSE message:', err) }
|
|
129
|
-
}
|
|
130
|
-
esRef.current.onerror = () => setConnected(false)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const moduleMode = transportFromModuleUrl()
|
|
134
|
-
if (moduleMode === 'http-sse') {
|
|
135
|
-
connectSse()
|
|
136
|
-
} else {
|
|
137
|
-
void (async () => {
|
|
138
|
-
const mode = await resolveSandboxTransport(base)
|
|
139
|
-
if (cancelled) return
|
|
140
|
-
if (mode === 'http-sse') connectSse()
|
|
141
|
-
else connectWebSocket()
|
|
142
|
-
})()
|
|
88
|
+
const wsUrl = new URL('/sandbox', `${base}/`)
|
|
89
|
+
wsUrl.protocol = wsUrl.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
90
|
+
wsRef.current = new WebSocket(wsUrl.href)
|
|
91
|
+
wsRef.current.onopen = () => setConnected(true)
|
|
92
|
+
wsRef.current.onmessage = (event) => {
|
|
93
|
+
try { handleInboundPayload(JSON.parse(event.data)) }
|
|
94
|
+
catch (err) { console.error('[Sandbox] Failed to parse message:', err) }
|
|
143
95
|
}
|
|
96
|
+
wsRef.current.onclose = () => setConnected(false)
|
|
144
97
|
|
|
145
98
|
return () => {
|
|
146
|
-
cancelled = true
|
|
147
99
|
wsRef.current?.close()
|
|
148
100
|
wsRef.current = null
|
|
149
|
-
esRef.current?.close()
|
|
150
|
-
esRef.current = null
|
|
151
101
|
setConnected(false)
|
|
152
102
|
}
|
|
153
103
|
}, [])
|
|
@@ -255,20 +205,7 @@ export default function Sandbox() {
|
|
|
255
205
|
setMessages((prev) => [...prev, newMessage]); setInputText(''); setPreviewSegments([])
|
|
256
206
|
editorRef.current?.clear()
|
|
257
207
|
const payload = JSON.stringify({ type: activeChannel.type, id: activeChannel.id, content: segments, timestamp: Date.now() })
|
|
258
|
-
|
|
259
|
-
const url = new URL('/sandbox/message', `${apiBaseRef.current}/`)
|
|
260
|
-
void fetch(url.href, {
|
|
261
|
-
method: 'POST',
|
|
262
|
-
headers: {
|
|
263
|
-
'Content-Type': 'application/json',
|
|
264
|
-
'X-Sandbox-Session': sessionIdRef.current,
|
|
265
|
-
...getSandboxAuthHeaders(),
|
|
266
|
-
},
|
|
267
|
-
body: payload,
|
|
268
|
-
}).catch((err) => console.error('[Sandbox] POST message failed:', err))
|
|
269
|
-
} else {
|
|
270
|
-
wsRef.current?.send(payload)
|
|
271
|
-
}
|
|
208
|
+
wsRef.current?.send(payload)
|
|
272
209
|
}
|
|
273
210
|
|
|
274
211
|
const clearMessages = () => { if (confirm('确定清空所有消息记录?')) setMessages([]) }
|
package/client/index.tsx
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
export type SandboxTransportMode = "websocket" | "http-sse";
|
|
2
|
-
|
|
3
1
|
export function getSandboxApiBase(): string {
|
|
4
2
|
const stored = localStorage.getItem("zhin_api_base")?.trim();
|
|
5
3
|
return (stored ? stored.replace(/\/$/, "") : null) ?? window.location.origin;
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
export function getSandboxSessionId(): string {
|
|
9
|
-
const key = "zhin_sandbox_session";
|
|
10
|
-
let id = sessionStorage.getItem(key)?.trim();
|
|
11
|
-
if (!id) {
|
|
12
|
-
id = crypto.randomUUID();
|
|
13
|
-
sessionStorage.setItem(key, id);
|
|
14
|
-
}
|
|
15
|
-
return id;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
6
|
export function getSandboxAuthHeaders(): Record<string, string> {
|
|
19
7
|
const token =
|
|
20
8
|
localStorage.getItem("HTTP_TOKEN")?.trim() ||
|
|
@@ -22,40 +10,3 @@ export function getSandboxAuthHeaders(): Record<string, string> {
|
|
|
22
10
|
"";
|
|
23
11
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
24
12
|
}
|
|
25
|
-
|
|
26
|
-
/** Edge 构建的 sandbox.mjs 带 ?v=edge 或 ?transport=http-sse */
|
|
27
|
-
export function transportFromModuleUrl(): SandboxTransportMode | null {
|
|
28
|
-
try {
|
|
29
|
-
const u = new URL(import.meta.url);
|
|
30
|
-
if (u.searchParams.get("transport") === "http-sse") return "http-sse";
|
|
31
|
-
if (u.searchParams.get("v") === "edge") return "http-sse";
|
|
32
|
-
} catch {
|
|
33
|
-
/* 非 ESM 环境 */
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function fetchTransportHint(apiBase: string, path: string): Promise<SandboxTransportMode | null> {
|
|
39
|
-
const res = await fetch(new URL(path, `${apiBase.replace(/\/$/, "")}/`).href);
|
|
40
|
-
if (!res.ok) return null;
|
|
41
|
-
const data = (await res.json()) as { sandboxTransport?: string };
|
|
42
|
-
return data.sandboxTransport === "http-sse" ? "http-sse" : null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function resolveSandboxTransport(apiBase: string): Promise<SandboxTransportMode> {
|
|
46
|
-
const fromModule = transportFromModuleUrl();
|
|
47
|
-
if (fromModule) return fromModule;
|
|
48
|
-
|
|
49
|
-
const override = localStorage.getItem("zhin_sandbox_transport")?.trim();
|
|
50
|
-
if (override === "http-sse" || override === "websocket") return override;
|
|
51
|
-
|
|
52
|
-
for (const path of ["/entries", "/api/info"]) {
|
|
53
|
-
try {
|
|
54
|
-
const mode = await fetchTransportHint(apiBase, path);
|
|
55
|
-
if (mode) return mode;
|
|
56
|
-
} catch {
|
|
57
|
-
/* CORS / 离线 */
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return "websocket";
|
|
61
|
-
}
|
package/client/tsconfig.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
`)}return{text:d,segments:t}},
|
|
3
|
-
`)){
|
|
4
|
-
`).map((
|
|
5
|
-
`).length-1&&a("br",{})]},
|
|
6
|
-
`).map((
|
|
7
|
-
`).length-1&&a("br",{})]},S))},l);case"at":return o("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-accent text-accent-foreground text-xs mx-0.5",children:["@",String(g.name??g.qq??"")]},l);case"face":return a("img",{src:`https://face.viki.moe/apng/${g.id}.png`,alt:"",className:"w-6 h-6 inline-block align-middle mx-0.5"},l);case"image":{let h=De(g),S=Fe(h,"image");return S?a("a",{href:S,target:"_blank",rel:"noreferrer",className:"block my-1",children:a("img",{src:S,alt:"",className:M("max-w-[min(320px,88vw)] rounded-lg block",x,"ring-offset-0"),onError:te=>{te.target.style.display="none"}})},l):a("span",{className:"text-xs opacity-70",children:"[\u56FE\u7247]"},l)}case"video":{let h=De(g),S=Fe(h,"video");return S?a("video",{src:S,controls:!0,playsInline:!0,preload:"metadata",className:M("max-w-[min(360px,92vw)] max-h-72 rounded-lg my-1 bg-black/10",x)},l):a("span",{className:"text-xs opacity-70",children:"[\u89C6\u9891\u65E0\u5730\u5740]"},l)}case"audio":case"record":{let h=De(g),S=Fe(h,"audio");return S?a("audio",{src:S,controls:!0,preload:"metadata",className:M("w-full max-w-sm my-2 h-10",s&&"opacity-95")},l):a("span",{className:"text-xs opacity-70",children:"[\u97F3\u9891\u65E0\u5730\u5740]"},l)}case"file":return o("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:["\u{1F4CE} ",String(g.name||"\u6587\u4EF6")]},l);default:return o("span",{className:"text-xs opacity-70",children:["[",I.type,"]"]},l)}})},He=(e,s)=>{if(!Ue(s))return;let x={id:`msg_${Date.now()}`,type:"sent",channelType:w.type,channelId:w.id,channelName:w.name,senderId:"test_user",senderName:"\u6D4B\u8BD5\u7528\u6237",content:s,timestamp:Date.now()};c(l=>[...l,x]),F(""),q([]),H.current?.clear();let I=JSON.stringify({type:w.type,id:w.id,content:s,timestamp:Date.now()});if(we.current==="http-sse"){let l=new URL("/sandbox/message",`${ve.current}/`);fetch(l.href,{method:"POST",headers:{"Content-Type":"application/json","X-Sandbox-Session":Te.current,...Ae()},body:I}).catch(g=>console.error("[Sandbox] POST message failed:",g))}else E.current?.send(I)},oa=()=>{confirm("\u786E\u5B9A\u6E05\u7A7A\u6240\u6709\u6D88\u606F\u8BB0\u5F55\uFF1F")&&c([])},da=e=>{ke("chat"),m(e),L(s=>s.map(x=>x.id===e.id?{...x,unread:0}:x)),window.innerWidth<768&&U(!1)},ua=()=>{let e=["private","group","channel"],s=e[Math.floor(Math.random()*e.length)],x=prompt("\u8BF7\u8F93\u5165\u9891\u9053\u540D\u79F0\uFF1A");if(x){let I={id:`${s}_${Date.now()}`,name:x,type:s,unread:0};L(l=>[...l,I]),m(I)}},Oe=e=>{switch(e){case"private":return a(_,{size:16});case"group":return a(ne,{size:16});case"channel":return a(ue,{size:16});default:return a(G,{size:16})}},la=e=>{H.current?.insertFace(e),B(!1)},Ne=()=>{let e=ee.trim();!e||!y||(y==="image"?H.current?.insertImage(e):y==="video"?H.current?.insertVideo(e):H.current?.insertAudio(e),Ie(""),V(null))},Ga=()=>{f.trim()&&(H.current?.insertAt(f.trim()),p(""),Se(!1))},ra=e=>{H.current?.replaceAtTrigger(e.name,e.id),j(null),t("")},sa=(e,s,x)=>{if(w.type==="private"){j(null),t("");return}e&&x?(j(x),t(s)):(j(null),t(""))},Ee=A.filter(e=>{if(!d.trim())return!0;let s=d.toLowerCase();return e.name.toLowerCase().includes(s)||e.id.toLowerCase().includes(s)}),fa=(e,s)=>{F(e),q(s)},Ge=D.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())||e.describe.toLowerCase().includes(u.toLowerCase())),ye=r.filter(e=>e.channelId===w.id);return o("div",{className:"sandbox-container rounded-xl border border-border/70 bg-card/30 shadow-sm",children:[o("button",{className:"mobile-channel-toggle md:hidden",onClick:()=>U(!R),children:[a(G,{size:20})," \u9891\u9053\u5217\u8868"]}),o("div",{className:M("channel-sidebar rounded-lg border bg-card",R&&"show"),children:[a("div",{className:"p-3 border-b",children:o("div",{className:"flex justify-between items-center",children:[o("div",{className:"flex items-center gap-2",children:[a("div",{className:"p-1 rounded-md bg-secondary",children:a(G,{size:16,className:"text-muted-foreground"})}),a("h3",{className:"font-semibold",children:"\u9891\u9053\u5217\u8868"})]}),o("span",{className:M("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium border",W?"bg-emerald-100 text-emerald-800 border-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-400 dark:border-emerald-800":"bg-muted text-muted-foreground"),children:[W?a(Le,{size:12}):a(me,{size:12}),W?"\u5DF2\u8FDE\u63A5":"\u672A\u8FDE\u63A5"]})]})}),o("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:[C.map(e=>{let s=$==="chat"&&w.id===e.id;return o("div",{className:M("menu-item",s&&"active"),onClick:()=>da(e),children:[a("span",{className:"shrink-0",children:Oe(e.type)}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"text-sm font-medium truncate",children:e.name}),a("div",{className:"text-xs text-muted-foreground",children:e.type==="private"?"\u79C1\u804A":e.type==="group"?"\u7FA4\u804A":"\u9891\u9053"})]}),e.unread>0&&a("span",{className:"inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1",children:e.unread})]},e.id)}),o("div",{className:"pt-2 mt-2 border-t space-y-1",children:[o("div",{className:M("menu-item",$==="requests"&&"active"),onClick:()=>{ke("requests"),window.innerWidth<768&&U(!1)},children:[a(Z,{size:16,className:"shrink-0"}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"text-sm font-medium",children:"\u8BF7\u6C42"}),a("div",{className:"text-xs text-muted-foreground",children:"\u597D\u53CB/\u7FA4\u9080\u8BF7\u7B49"})]})]}),o("div",{className:M("menu-item",$==="notices"&&"active"),onClick:()=>{ke("notices"),window.innerWidth<768&&U(!1)},children:[a(K,{size:16,className:"shrink-0"}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"text-sm font-medium",children:"\u901A\u77E5"}),a("div",{className:"text-xs text-muted-foreground",children:"\u7FA4\u7BA1/\u64A4\u56DE\u7B49"})]})]})]})]}),a("div",{className:"p-2 border-t",children:a("button",{className:"w-full py-2 px-3 rounded-md border border-dashed text-sm text-muted-foreground hover:bg-accent transition-colors",onClick:ua,children:"+ \u6DFB\u52A0\u9891\u9053"})})]}),R&&a("div",{className:"channel-overlay md:hidden",onClick:()=>U(!1)}),o("div",{className:"chat-area",children:[$==="requests"&&o("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0 overflow-hidden",children:[a("div",{className:"p-3 border-b flex-shrink-0",children:o("h2",{className:"text-lg font-bold flex items-center gap-2",children:[a(Z,{size:20})," \u8BF7\u6C42"]})}),o("div",{className:"flex-1 overflow-y-auto p-4 flex flex-col items-center justify-center gap-3 text-muted-foreground text-center",children:[a(Z,{size:48,className:"opacity-30"}),a("span",{children:"\u6C99\u76D2\u4E3A\u6A21\u62DF\u73AF\u5883\uFF0C\u6682\u65E0\u8BF7\u6C42\u6570\u636E"}),o("span",{className:"text-sm",children:["\u5B9E\u9645\u597D\u53CB/\u7FA4\u9080\u8BF7\u7B49\u8BF7\u6C42\u8BF7\u5230\u4FA7\u8FB9\u680F ",a("strong",{children:"\u673A\u5668\u4EBA"})," \u9875\u9762\u8FDB\u5165\u5BF9\u5E94\u673A\u5668\u4EBA\u7BA1\u7406\u67E5\u770B"]})]})]}),$==="notices"&&o("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0 overflow-hidden",children:[a("div",{className:"p-3 border-b flex-shrink-0",children:o("h2",{className:"text-lg font-bold flex items-center gap-2",children:[a(K,{size:20})," \u901A\u77E5"]})}),o("div",{className:"flex-1 overflow-y-auto p-4 flex flex-col items-center justify-center gap-3 text-muted-foreground text-center",children:[a(K,{size:48,className:"opacity-30"}),a("span",{children:"\u6C99\u76D2\u4E3A\u6A21\u62DF\u73AF\u5883\uFF0C\u6682\u65E0\u901A\u77E5\u6570\u636E"}),o("span",{className:"text-sm",children:["\u5B9E\u9645\u7FA4\u7BA1\u3001\u64A4\u56DE\u7B49\u901A\u77E5\u8BF7\u5230\u4FA7\u8FB9\u680F ",a("strong",{children:"\u673A\u5668\u4EBA"})," \u9875\u9762\u8FDB\u5165\u5BF9\u5E94\u673A\u5668\u4EBA\u7BA1\u7406\u67E5\u770B"]})]})]}),$==="chat"&&o(Ea,{children:[a("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0",children:o("div",{className:"flex justify-between items-center flex-wrap gap-2",children:[o("div",{className:"flex items-center gap-3",children:[a("div",{className:"p-2 rounded-lg bg-secondary",children:Oe(w.type)}),o("div",{children:[a("h2",{className:"text-lg font-bold",children:w.name}),o("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[a("span",{children:w.id}),a("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-[10px]",children:ye.length}),a("span",{children:"\u6761\u6D88\u606F"})]})]}),a("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-secondary text-secondary-foreground",children:w.type==="private"?"\u79C1\u804A":w.type==="group"?"\u7FA4\u804A":"\u9891\u9053"})]}),o("div",{className:"flex items-center gap-2",children:[a("input",{value:O,onChange:e=>J(e.target.value),placeholder:"\u673A\u5668\u4EBA\u540D\u79F0",className:"h-8 w-28 rounded-md border bg-transparent px-2 text-sm"}),o("button",{className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-secondary text-secondary-foreground text-sm hover:bg-secondary/80",onClick:oa,children:[a(ce,{size:14})," \u6E05\u7A7A"]})]})]})}),a("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0",children:a("div",{className:"flex-1 overflow-y-auto p-4",children:ye.length===0?o("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[a(G,{size:64,className:"text-muted-foreground/20"}),a("span",{className:"text-muted-foreground",children:"\u6682\u65E0\u6D88\u606F\uFF0C\u5F00\u59CB\u5BF9\u8BDD\u5427\uFF01"})]}):o("div",{className:"space-y-2",children:[ye.map(e=>a("div",{className:M("flex",e.type==="sent"?"justify-end":"justify-start"),children:o("div",{className:M("max-w-[70%] p-3 rounded-2xl",e.type==="sent"?"bg-primary text-primary-foreground":"bg-muted"),children:[o("div",{className:"flex items-center gap-2 mb-1",children:[e.type==="received"&&a(oe,{size:14}),e.type==="sent"&&a(_,{size:14}),a("span",{className:"text-xs font-medium opacity-90",children:e.senderName}),a("span",{className:"text-xs opacity-70",children:new Date(e.timestamp).toLocaleTimeString()})]}),a("div",{className:"text-sm space-y-1",children:ta(e.content,e.type==="sent")})]})},e.id)),a("div",{ref:Re})]})})}),o("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0 space-y-3",children:[o("div",{className:"flex gap-2 items-center flex-wrap",children:[a("button",{type:"button",className:M("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",N?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{B(!N),V(null)},title:"\u63D2\u5165\u8868\u60C5",children:a(ie,{size:16})}),a("button",{type:"button",className:M("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",y==="image"?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{V(e=>e==="image"?null:"image"),B(!1)},title:"\u63D2\u5165\u56FE\u7247 URL",children:a(le,{size:16})}),a("button",{type:"button",className:M("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",y==="video"?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{V(e=>e==="video"?null:"video"),B(!1)},title:"\u63D2\u5165\u89C6\u9891 URL",children:a(pe,{size:16})}),a("button",{type:"button",className:M("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",y==="audio"?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{V(e=>e==="audio"?null:"audio"),B(!1)},title:"\u63D2\u5165\u97F3\u9891 URL",children:a(se,{size:16})}),a("div",{className:"flex-1 min-w-[1rem]"}),P&&a("button",{className:"h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors",onClick:()=>{F(""),q([])},children:a(xe,{size:16})})]}),N&&o("div",{className:"p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2",children:[a("input",{value:u,onChange:e=>n(e.target.value),placeholder:"\u641C\u7D22\u8868\u60C5...",className:"w-full h-8 rounded-md border bg-transparent px-2 text-sm"}),a("div",{className:"grid grid-cols-8 gap-1",children:Ge.slice(0,80).map(e=>a("button",{onClick:()=>la(e.id),title:e.name,className:"w-10 h-10 rounded-md border flex items-center justify-center hover:bg-accent transition-colors",children:a("img",{src:`https://face.viki.moe/apng/${e.id}.png`,alt:e.name,className:"w-8 h-8"})},e.id))}),Ge.length===0&&o("div",{className:"flex flex-col items-center gap-2 py-4",children:[a(Y,{size:32,className:"text-muted-foreground/30"}),a("span",{className:"text-sm text-muted-foreground",children:"\u672A\u627E\u5230\u5339\u914D\u7684\u8868\u60C5"})]})]}),y&&o("div",{className:"p-3 rounded-md border bg-muted/30 space-y-2",children:[o("p",{className:"text-xs text-muted-foreground",children:[y==="image"&&"\u652F\u6301 http(s) \u56FE\u7247\u94FE\u63A5\u6216 data URL",y==="video"&&"\u652F\u6301\u6D4F\u89C8\u5668\u53EF\u89E3\u7801\u7684\u89C6\u9891\u76F4\u94FE\uFF08\u5982 .mp4\u3001.webm\uFF09",y==="audio"&&"\u652F\u6301 .mp3\u3001.ogg\u3001.wav \u7B49\u97F3\u9891\u76F4\u94FE"]}),a("input",{value:ee,onChange:e=>Ie(e.target.value),placeholder:y==="image"?"\u56FE\u7247 URL\u2026":y==="video"?"\u89C6\u9891 URL\u2026":"\u97F3\u9891 URL\u2026",className:"w-full h-8 rounded-md border border-input bg-background px-2 text-sm",onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),Ne())}}),o("button",{type:"button",className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-primary text-primary-foreground text-sm disabled:opacity-50",onClick:Ne,disabled:!ee.trim(),children:[a(de,{size:14})," \u63D2\u5165\u5230\u8F93\u5165\u6846"]})]}),o("div",{className:"flex gap-2 items-start",children:[o("div",{className:"flex-1 relative",children:[a(Ye,{ref:H,placeholder:`\u5411 ${w.name} \u53D1\u9001\u6D88\u606F...`,onSend:He,onChange:fa,onAtTrigger:sa,minHeight:"44px",maxHeight:"200px"}),ae&&a("div",{className:"absolute z-50 rounded-lg border bg-popover shadow-md min-w-60 max-h-72 overflow-y-auto p-1",style:{top:`${ae.top}px`,left:`${ae.left}px`},children:Ee.length>0?Ee.map(e=>o("div",{className:"flex items-center gap-2 p-2 rounded-md cursor-pointer hover:bg-accent transition-colors",onClick:()=>ra(e),children:[a(_,{size:16,className:"text-muted-foreground"}),o("div",{className:"flex-1",children:[a("div",{className:"text-sm font-medium",children:e.name}),o("div",{className:"text-xs text-muted-foreground",children:["ID: ",e.id]})]})]},e.id)):o("div",{className:"flex flex-col items-center gap-2 p-4",children:[a(Y,{size:20,className:"text-muted-foreground/50"}),a("span",{className:"text-xs text-muted-foreground",children:"\u672A\u627E\u5230\u5339\u914D\u7684\u7528\u6237"})]})})]}),o("button",{className:"inline-flex items-center gap-1.5 h-10 px-4 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 transition-colors hover:bg-primary/90",onClick:()=>{let e=H.current?.getContent();e&&He(e.text,e.segments)},disabled:!Ue(z),children:[a(fe,{size:16})," \u53D1\u9001"]})]}),o("div",{className:"flex items-center gap-2 flex-wrap text-xs text-muted-foreground",children:[a(re,{size:12})," \u5FEB\u6377\u64CD\u4F5C:",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Enter"})," \u53D1\u9001",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Shift+Enter"})," \u6362\u884C",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[@\u540D\u79F0]"})," @\u67D0\u4EBA",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[video:URL]"}),a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[audio:URL]"})]})]})]})]})]})}function bo(r){r.addRoute({path:"/console/sandbox",name:"\u6C99\u76D2",element:r.React.createElement(be,{hostReact:r.React})}),r.addTool({id:"sandbox",name:"\u6C99\u76D2",path:"/console/sandbox"})}export{bo as register};
|
|
1
|
+
import ze,{useState as C,useEffect as Ie,useRef as we}from"react";import{cn as A,resolveMediaSrc as Pe,pickMediaRawUrl as ye}from"@zhin.js/client";function Te(){let i=localStorage.getItem("zhin_api_base")?.trim();return(i?i.replace(/\/$/,""):null)??window.location.origin}import{forwardRef as la,createElement as ra}from"react";var Le=(...i)=>i.filter((m,w,I)=>!!m&&m.trim()!==""&&I.indexOf(m)===w).join(" ").trim();var qe=i=>i.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var Ue=i=>i.replace(/^([A-Z])|[\s-_]+(\w)/g,(m,w,I)=>I?I.toUpperCase():w.toLowerCase());var ke=i=>{let m=Ue(i);return m.charAt(0).toUpperCase()+m.slice(1)};import{forwardRef as ua,createElement as Ne}from"react";var xe={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var He=i=>{for(let m in i)if(m.startsWith("aria-")||m==="role"||m==="title")return!0;return!1};import{createContext as ta,useContext as oa,useMemo as Ga,createElement as Wa}from"react";var da=ta({});var Oe=()=>oa(da);var Ee=ua(({color:i,size:m,strokeWidth:w,absoluteStrokeWidth:I,className:N="",children:D,iconNode:g,...p},S)=>{let{size:B=24,strokeWidth:U=2,absoluteStrokeWidth:_=!1,color:E="currentColor",className:G=""}=Oe()??{},H=I??_?Number(w??U)*24/Number(m??B):w??U;return Ne("svg",{ref:S,...xe,width:m??B??xe.width,height:m??B??xe.height,stroke:i??E,strokeWidth:H,className:Le("lucide",G,N),...!D&&!He(p)&&{"aria-hidden":"true"},...p},[...g.map(([M,k])=>Ne(M,k)),...Array.isArray(D)?D:[D]])});var s=(i,m)=>{let w=la(({className:I,...N},D)=>ra(Ee,{ref:D,iconNode:m,className:Le(`lucide-${qe(ke(i))}`,`lucide-${i}`,I),...N}));return w.displayName=ke(i),w};var sa=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],X=s("bell",sa);var fa=[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]],ee=s("bot",fa);var ia=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],ae=s("check",ia);var ca=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],te=s("hash",ca);var na=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],oe=s("image",na);var pa=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],de=s("info",pa);var ma=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],O=s("message-square",ma);var La=[["path",{d:"M9 18V5l12-2v13",key:"1jmyc2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["circle",{cx:"18",cy:"16",r:"3",key:"1hluhg"}]],ue=s("music",La);var xa=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],j=s("search",xa);var Ia=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],le=s("send",Ia);var Ca=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 14s1.5 2 4 2 4-2 4-2",key:"1y1vjs"}],["line",{x1:"9",x2:"9.01",y1:"9",y2:"9",key:"yxxnd0"}],["line",{x1:"15",x2:"15.01",y1:"9",y2:"9",key:"1p4y9e"}]],re=s("smile",Ca);var ga=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],se=s("trash-2",ga);var ha=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],K=s("user-plus",ha);var Sa=[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]],Z=s("user",Sa);var ka=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],fe=s("users",ka);var wa=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],ie=s("video",wa);var Pa=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],ce=s("wifi-off",Pa);var ya=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],ne=s("wifi",ya);var Aa=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],pe=s("x",Aa);import{useRef as Ge,forwardRef as Ma,useImperativeHandle as Ba}from"react";import{jsx as Fa}from"react/jsx-runtime";var We=Ma(({placeholder:i="\u8F93\u5165\u6D88\u606F...",onSend:m,onChange:w,onAtTrigger:I,minHeight:N="44px",maxHeight:D="200px"},g)=>{let p=Ge(null),S=Ge(null),B=()=>{if(!p.current)return{text:"",segments:[]};let d="",t=[],u=Array.from(p.current.childNodes);for(let c of u)if(c.nodeType===Node.TEXT_NODE){let l=c.textContent||"";l&&(d+=l,t.push({type:"text",data:{text:l}}))}else if(c.nodeType===Node.ELEMENT_NODE){let l=c;if(l.classList.contains("editor-face")){let n=l.dataset.id;d+=`[face:${n}]`,t.push({type:"face",data:{id:Number(n)}})}else if(l.classList.contains("editor-image")){let n=l.dataset.url;d+=`[image:${n}]`,t.push({type:"image",data:{url:n}})}else if(l.classList.contains("editor-video")){let n=l.dataset.url||"";d+=`[video:${n}]`,t.push({type:"video",data:{url:n}})}else if(l.classList.contains("editor-audio")){let n=l.dataset.url||"";d+=`[audio:${n}]`,t.push({type:"audio",data:{url:n}})}else if(l.classList.contains("editor-at")){let n=l.dataset.name,y=l.dataset.id;d+=`[@${n}]`,t.push({type:"at",data:{name:n,qq:y}})}else l.tagName==="BR"&&(d+=`
|
|
2
|
+
`)}return{text:d,segments:t}},U=d=>{if(!p.current)return;let t=document.createElement("img");t.src=`https://face.viki.moe/apng/${d}.png`,t.alt=`[face:${d}]`,t.dataset.type="face",t.dataset.id=String(d),t.className="editor-face",M(t),R()},_=d=>{if(!p.current||!d.trim())return;let t=document.createElement("img");t.src=d.trim(),t.alt=`[image:${d.trim()}]`,t.dataset.type="image",t.dataset.url=d.trim(),t.className="editor-image",M(t),R()},E=d=>{if(!p.current||!d.trim())return;let t=d.trim(),u=document.createElement("span");u.className="editor-video",u.dataset.url=t,u.contentEditable="false",u.textContent="\u{1F4F9} \u89C6\u9891",M(u),R()},G=d=>{if(!p.current||!d.trim())return;let t=d.trim(),u=document.createElement("span");u.className="editor-audio",u.dataset.url=t,u.contentEditable="false",u.textContent="\u{1F3B5} \u97F3\u9891",M(u),R()},H=(d,t)=>{if(!p.current||!d.trim())return;let u=document.createElement("span");u.dataset.type="at",u.dataset.name=d,t&&(u.dataset.id=t),u.className="editor-at",u.contentEditable="false";let c=document.createElement("span");c.textContent="@",c.className="editor-at-symbol";let l=document.createElement("span");l.textContent=d,l.className="editor-at-name",u.appendChild(c),u.appendChild(l),M(u),R()},M=d=>{if(!p.current)return;p.current.focus();let t=window.getSelection();if(t&&t.rangeCount>0){let u=t.getRangeAt(0);if(p.current.contains(u.commonAncestorContainer))u.deleteContents(),u.insertNode(d),u.collapse(!1),t.removeAllRanges(),t.addRange(u);else{p.current.appendChild(d);let l=document.createRange();l.setStartAfter(d),l.collapse(!0),t.removeAllRanges(),t.addRange(l)}}else{p.current.appendChild(d);let u=window.getSelection();if(u){let c=document.createRange();c.setStartAfter(d),c.collapse(!0),u.removeAllRanges(),u.addRange(c)}}},k=()=>{p.current&&(p.current.innerHTML="",R())},W=()=>{p.current?.focus()},$=()=>B(),me=()=>{if(!p.current||!I)return;let d=window.getSelection();if(!d||d.rangeCount===0){I(!1,""),S.current=null;return}let t=d.getRangeAt(0);if(!p.current.contains(t.commonAncestorContainer)){I(!1,""),S.current=null;return}let u=t.startContainer;if(u.nodeType!==Node.TEXT_NODE){I(!1,""),S.current=null;return}let c=u,l=c.textContent?.substring(0,t.startOffset)||"",n=l.lastIndexOf("@");if(n!==-1){let y=l.substring(n+1);if(y.includes(" ")||y.includes(`
|
|
3
|
+
`)){I(!1,""),S.current=null;return}S.current=c;let V=document.createRange();V.setStart(c,n),V.setEnd(c,n+1);let v=V.getBoundingClientRect(),b=p.current.getBoundingClientRect();I(!0,y,{top:v.bottom-b.top,left:v.left-b.left})}else I(!1,""),S.current=null},R=()=>{if(me(),w){let{text:d,segments:t}=B();w(d,t)}},Ce=(d,t)=>{if(!S.current)return;let u=S.current,c=u.textContent||"",l=c.lastIndexOf("@");if(l!==-1){let n=c.substring(l+1),y=l+1+n.split(/[\s\n]/)[0].length,V=c.substring(0,l),v=c.substring(y);u.textContent=V+v;let b=window.getSelection();if(b){let T=document.createRange();T.setStart(u,l),T.collapse(!0),b.removeAllRanges(),b.addRange(T)}}S.current=null,H(d,t)},Y=d=>{d.preventDefault();let t=d.clipboardData,c=Array.from(t.items).find(n=>n.type.startsWith("image/"));if(c){let n=c.getAsFile();if(n){let y=new FileReader;y.onload=()=>{typeof y.result=="string"&&_(y.result)},y.readAsDataURL(n)}return}let l=t.getData("text/plain");l&&(document.execCommand("insertText",!1,l),R())},Q=d=>{if(d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),m)){let{text:t,segments:u}=B();m(t,u)}};return Ba(g,()=>({focus:W,clear:k,insertFace:U,insertImage:_,insertVideo:E,insertAudio:G,insertAt:H,replaceAtTrigger:Ce,getContent:$})),Fa("div",{ref:p,contentEditable:!0,suppressContentEditableWarning:!0,onInput:R,onKeyDown:Q,onPaste:Y,"data-placeholder":i,className:"rich-text-editor",style:{width:"100%",minHeight:N,maxHeight:D,padding:"0.5rem 0.75rem",border:"1px solid var(--gray-6)",borderRadius:"6px",backgroundColor:"var(--gray-1)",fontSize:"var(--font-size-2)",outline:"none",overflowY:"auto",lineHeight:"1.5",wordWrap:"break-word",color:"var(--gray-12)"}})});We.displayName="RichTextEditor";var Ve=We;import{Fragment as Da,jsx as a,jsxs as o}from"react/jsx-runtime";function Ae(){let[i,m]=C([]),[w,I]=C([{id:"user_1001",name:"\u6D4B\u8BD5\u7528\u6237",type:"private",unread:0},{id:"group_2001",name:"\u6D4B\u8BD5\u7FA4\u7EC4",type:"group",unread:0},{id:"channel_3001",name:"\u6D4B\u8BD5\u9891\u9053",type:"channel",unread:0}]),[N,D]=C([]),[g,p]=C(w[0]),[S,B]=C(""),[U,_]=C("ProcessBot"),[E,G]=C(!1),[H,M]=C(!1),[k,W]=C(null),[$,me]=C(""),[R,Ce]=C(!1),[Y,Q]=C(null),[d,t]=C(""),[u,c]=C(""),[l,n]=C(""),[y]=C([{id:"10001",name:"\u5F20\u4E09"},{id:"10002",name:"\u674E\u56DB"},{id:"10003",name:"\u738B\u4E94"},{id:"10004",name:"\u8D75\u516D"},{id:"10005",name:"\u6D4B\u8BD5\u7528\u6237"},{id:"10086",name:"Admin"},{id:"10010",name:"Test User"}]),[V,v]=C([]),[b,T]=C(!1),[J,ge]=C("chat"),Me=we(null),z=we(null),q=we(null),Xe=async()=>{try{let e=await fetch("https://face.viki.moe/metadata.json");D(await e.json())}catch(e){console.error("[Sandbox] Failed to fetch face list:",e)}};Ie(()=>{Xe()},[]);let Ke=e=>{let r=typeof e.content=="string"?he(e.content):Array.isArray(e.content)?e.content:he(String(e.content??"")),L=e.type==="private"?`\u79C1\u804A-${e.bot||U}`:e.type==="group"?`\u7FA4\u7EC4-${e.id}`:`\u9891\u9053-${e.id}`,x=e.type;I(f=>{if(f.some(F=>F.id===e.id))return f;let h={id:e.id,name:L,type:x,unread:0};return p(h),[...f,h]}),m(f=>[...f,{id:`bot_${e.timestamp}`,type:"received",channelType:x,channelId:e.id,channelName:L,senderId:"bot",senderName:e.bot||U,content:r,timestamp:e.timestamp}])};Ie(()=>{let e=Te(),r=new URL("/sandbox",`${e}/`);return r.protocol=r.protocol==="https:"?"wss:":"ws:",z.current=new WebSocket(r.href),z.current.onopen=()=>G(!0),z.current.onmessage=L=>{try{Ke(JSON.parse(L.data))}catch(x){console.error("[Sandbox] Failed to parse message:",x)}},z.current.onclose=()=>G(!1),()=>{z.current?.close(),z.current=null,G(!1)}},[]),Ie(()=>{Me.current?.scrollIntoView({behavior:"smooth"})},[i]),Ie(()=>{v(S.trim()?he(S):[])},[S]);let he=e=>{let r=[],L=/\[@([^\]]+)\]|\[face:(\d+)\]|\[image:([^\]]+)\]|\[video:([^\]]+)\]|\[audio:([^\]]+)\]/g,x=0,f;for(;(f=L.exec(e))!==null;){if(f.index>x){let h=e.substring(x,f.index);h&&r.push({type:"text",data:{text:h}})}f[1]?r.push({type:"at",data:{qq:f[1],name:f[1]}}):f[2]?r.push({type:"face",data:{id:parseInt(f[2],10)}}):f[3]?r.push({type:"image",data:{url:f[3]}}):f[4]?r.push({type:"video",data:{url:f[4]}}):f[5]&&r.push({type:"audio",data:{url:f[5]}}),x=L.lastIndex}if(x<e.length){let h=e.substring(x);h&&r.push({type:"text",data:{text:h}})}return r.length>0?r:[{type:"text",data:{text:e}}]},Be=e=>e.length===0?!1:e.some(r=>r.type==="text"?!!String(r.data?.text??"").trim():!0),Ze=(e,r)=>{let L=r?"ring-1 ring-primary-foreground/25":"ring-1 ring-border/60";return e.map((x,f)=>{if(typeof x=="string")return a("span",{children:x.split(`
|
|
4
|
+
`).map((F,P)=>o(ze.Fragment,{children:[F,P<x.split(`
|
|
5
|
+
`).length-1&&a("br",{})]},P))},f);let h=x.data;switch(x.type){case"text":return a("span",{children:String(h.text??"").split(`
|
|
6
|
+
`).map((F,P)=>o(ze.Fragment,{children:[F,P<String(h.text??"").split(`
|
|
7
|
+
`).length-1&&a("br",{})]},P))},f);case"at":return o("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-accent text-accent-foreground text-xs mx-0.5",children:["@",String(h.name??h.qq??"")]},f);case"face":return a("img",{src:`https://face.viki.moe/apng/${h.id}.png`,alt:"",className:"w-6 h-6 inline-block align-middle mx-0.5"},f);case"image":{let F=ye(h),P=Pe(F,"image");return P?a("a",{href:P,target:"_blank",rel:"noreferrer",className:"block my-1",children:a("img",{src:P,alt:"",className:A("max-w-[min(320px,88vw)] rounded-lg block",L,"ring-offset-0"),onError:aa=>{aa.target.style.display="none"}})},f):a("span",{className:"text-xs opacity-70",children:"[\u56FE\u7247]"},f)}case"video":{let F=ye(h),P=Pe(F,"video");return P?a("video",{src:P,controls:!0,playsInline:!0,preload:"metadata",className:A("max-w-[min(360px,92vw)] max-h-72 rounded-lg my-1 bg-black/10",L)},f):a("span",{className:"text-xs opacity-70",children:"[\u89C6\u9891\u65E0\u5730\u5740]"},f)}case"audio":case"record":{let F=ye(h),P=Pe(F,"audio");return P?a("audio",{src:P,controls:!0,preload:"metadata",className:A("w-full max-w-sm my-2 h-10",r&&"opacity-95")},f):a("span",{className:"text-xs opacity-70",children:"[\u97F3\u9891\u65E0\u5730\u5740]"},f)}case"file":return o("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:["\u{1F4CE} ",String(h.name||"\u6587\u4EF6")]},f);default:return o("span",{className:"text-xs opacity-70",children:["[",x.type,"]"]},f)}})},Fe=(e,r)=>{if(!Be(r))return;let L={id:`msg_${Date.now()}`,type:"sent",channelType:g.type,channelId:g.id,channelName:g.name,senderId:"test_user",senderName:"\u6D4B\u8BD5\u7528\u6237",content:r,timestamp:Date.now()};m(f=>[...f,L]),B(""),v([]),q.current?.clear();let x=JSON.stringify({type:g.type,id:g.id,content:r,timestamp:Date.now()});z.current?.send(x)},_e=()=>{confirm("\u786E\u5B9A\u6E05\u7A7A\u6240\u6709\u6D88\u606F\u8BB0\u5F55\uFF1F")&&m([])},Qe=e=>{ge("chat"),p(e),I(r=>r.map(L=>L.id===e.id?{...L,unread:0}:L)),window.innerWidth<768&&T(!1)},Je=()=>{let e=["private","group","channel"],r=e[Math.floor(Math.random()*e.length)],L=prompt("\u8BF7\u8F93\u5165\u9891\u9053\u540D\u79F0\uFF1A");if(L){let x={id:`${r}_${Date.now()}`,name:L,type:r,unread:0};I(f=>[...f,x]),p(x)}},De=e=>{switch(e){case"private":return a(Z,{size:16});case"group":return a(fe,{size:16});case"channel":return a(te,{size:16});default:return a(O,{size:16})}},je=e=>{q.current?.insertFace(e),M(!1)},be=()=>{let e=$.trim();!e||!k||(k==="image"?q.current?.insertImage(e):k==="video"?q.current?.insertVideo(e):q.current?.insertAudio(e),me(""),W(null))},ba=()=>{l.trim()&&(q.current?.insertAt(l.trim()),n(""),Ce(!1))},$e=e=>{q.current?.replaceAtTrigger(e.name,e.id),Q(null),t("")},Ye=(e,r,L)=>{if(g.type==="private"){Q(null),t("");return}e&&L?(Q(L),t(r)):(Q(null),t(""))},Re=y.filter(e=>{if(!d.trim())return!0;let r=d.toLowerCase();return e.name.toLowerCase().includes(r)||e.id.toLowerCase().includes(r)}),ea=(e,r)=>{B(e),v(r)},ve=N.filter(e=>e.name.toLowerCase().includes(u.toLowerCase())||e.describe.toLowerCase().includes(u.toLowerCase())),Se=i.filter(e=>e.channelId===g.id);return o("div",{className:"sandbox-container rounded-xl border border-border/70 bg-card/30 shadow-sm",children:[o("button",{className:"mobile-channel-toggle md:hidden",onClick:()=>T(!b),children:[a(O,{size:20})," \u9891\u9053\u5217\u8868"]}),o("div",{className:A("channel-sidebar rounded-lg border bg-card",b&&"show"),children:[a("div",{className:"p-3 border-b",children:o("div",{className:"flex justify-between items-center",children:[o("div",{className:"flex items-center gap-2",children:[a("div",{className:"p-1 rounded-md bg-secondary",children:a(O,{size:16,className:"text-muted-foreground"})}),a("h3",{className:"font-semibold",children:"\u9891\u9053\u5217\u8868"})]}),o("span",{className:A("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium border",E?"bg-emerald-100 text-emerald-800 border-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-400 dark:border-emerald-800":"bg-muted text-muted-foreground"),children:[E?a(ne,{size:12}):a(ce,{size:12}),E?"\u5DF2\u8FDE\u63A5":"\u672A\u8FDE\u63A5"]})]})}),o("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:[w.map(e=>{let r=J==="chat"&&g.id===e.id;return o("div",{className:A("menu-item",r&&"active"),onClick:()=>Qe(e),children:[a("span",{className:"shrink-0",children:De(e.type)}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"text-sm font-medium truncate",children:e.name}),a("div",{className:"text-xs text-muted-foreground",children:e.type==="private"?"\u79C1\u804A":e.type==="group"?"\u7FA4\u804A":"\u9891\u9053"})]}),e.unread>0&&a("span",{className:"inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1",children:e.unread})]},e.id)}),o("div",{className:"pt-2 mt-2 border-t space-y-1",children:[o("div",{className:A("menu-item",J==="requests"&&"active"),onClick:()=>{ge("requests"),window.innerWidth<768&&T(!1)},children:[a(K,{size:16,className:"shrink-0"}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"text-sm font-medium",children:"\u8BF7\u6C42"}),a("div",{className:"text-xs text-muted-foreground",children:"\u597D\u53CB/\u7FA4\u9080\u8BF7\u7B49"})]})]}),o("div",{className:A("menu-item",J==="notices"&&"active"),onClick:()=>{ge("notices"),window.innerWidth<768&&T(!1)},children:[a(X,{size:16,className:"shrink-0"}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"text-sm font-medium",children:"\u901A\u77E5"}),a("div",{className:"text-xs text-muted-foreground",children:"\u7FA4\u7BA1/\u64A4\u56DE\u7B49"})]})]})]})]}),a("div",{className:"p-2 border-t",children:a("button",{className:"w-full py-2 px-3 rounded-md border border-dashed text-sm text-muted-foreground hover:bg-accent transition-colors",onClick:Je,children:"+ \u6DFB\u52A0\u9891\u9053"})})]}),b&&a("div",{className:"channel-overlay md:hidden",onClick:()=>T(!1)}),o("div",{className:"chat-area",children:[J==="requests"&&o("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0 overflow-hidden",children:[a("div",{className:"p-3 border-b flex-shrink-0",children:o("h2",{className:"text-lg font-bold flex items-center gap-2",children:[a(K,{size:20})," \u8BF7\u6C42"]})}),o("div",{className:"flex-1 overflow-y-auto p-4 flex flex-col items-center justify-center gap-3 text-muted-foreground text-center",children:[a(K,{size:48,className:"opacity-30"}),a("span",{children:"\u6C99\u76D2\u4E3A\u6A21\u62DF\u73AF\u5883\uFF0C\u6682\u65E0\u8BF7\u6C42\u6570\u636E"}),o("span",{className:"text-sm",children:["\u5B9E\u9645\u597D\u53CB/\u7FA4\u9080\u8BF7\u7B49\u8BF7\u6C42\u8BF7\u5230\u4FA7\u8FB9\u680F ",a("strong",{children:"\u673A\u5668\u4EBA"})," \u9875\u9762\u8FDB\u5165\u5BF9\u5E94\u673A\u5668\u4EBA\u7BA1\u7406\u67E5\u770B"]})]})]}),J==="notices"&&o("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0 overflow-hidden",children:[a("div",{className:"p-3 border-b flex-shrink-0",children:o("h2",{className:"text-lg font-bold flex items-center gap-2",children:[a(X,{size:20})," \u901A\u77E5"]})}),o("div",{className:"flex-1 overflow-y-auto p-4 flex flex-col items-center justify-center gap-3 text-muted-foreground text-center",children:[a(X,{size:48,className:"opacity-30"}),a("span",{children:"\u6C99\u76D2\u4E3A\u6A21\u62DF\u73AF\u5883\uFF0C\u6682\u65E0\u901A\u77E5\u6570\u636E"}),o("span",{className:"text-sm",children:["\u5B9E\u9645\u7FA4\u7BA1\u3001\u64A4\u56DE\u7B49\u901A\u77E5\u8BF7\u5230\u4FA7\u8FB9\u680F ",a("strong",{children:"\u673A\u5668\u4EBA"})," \u9875\u9762\u8FDB\u5165\u5BF9\u5E94\u673A\u5668\u4EBA\u7BA1\u7406\u67E5\u770B"]})]})]}),J==="chat"&&o(Da,{children:[a("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0",children:o("div",{className:"flex justify-between items-center flex-wrap gap-2",children:[o("div",{className:"flex items-center gap-3",children:[a("div",{className:"p-2 rounded-lg bg-secondary",children:De(g.type)}),o("div",{children:[a("h2",{className:"text-lg font-bold",children:g.name}),o("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[a("span",{children:g.id}),a("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-[10px]",children:Se.length}),a("span",{children:"\u6761\u6D88\u606F"})]})]}),a("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-secondary text-secondary-foreground",children:g.type==="private"?"\u79C1\u804A":g.type==="group"?"\u7FA4\u804A":"\u9891\u9053"})]}),o("div",{className:"flex items-center gap-2",children:[a("input",{value:U,onChange:e=>_(e.target.value),placeholder:"\u673A\u5668\u4EBA\u540D\u79F0",className:"h-8 w-28 rounded-md border bg-transparent px-2 text-sm"}),o("button",{className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-secondary text-secondary-foreground text-sm hover:bg-secondary/80",onClick:_e,children:[a(se,{size:14})," \u6E05\u7A7A"]})]})]})}),a("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0",children:a("div",{className:"flex-1 overflow-y-auto p-4",children:Se.length===0?o("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[a(O,{size:64,className:"text-muted-foreground/20"}),a("span",{className:"text-muted-foreground",children:"\u6682\u65E0\u6D88\u606F\uFF0C\u5F00\u59CB\u5BF9\u8BDD\u5427\uFF01"})]}):o("div",{className:"space-y-2",children:[Se.map(e=>a("div",{className:A("flex",e.type==="sent"?"justify-end":"justify-start"),children:o("div",{className:A("max-w-[70%] p-3 rounded-2xl",e.type==="sent"?"bg-primary text-primary-foreground":"bg-muted"),children:[o("div",{className:"flex items-center gap-2 mb-1",children:[e.type==="received"&&a(ee,{size:14}),e.type==="sent"&&a(Z,{size:14}),a("span",{className:"text-xs font-medium opacity-90",children:e.senderName}),a("span",{className:"text-xs opacity-70",children:new Date(e.timestamp).toLocaleTimeString()})]}),a("div",{className:"text-sm space-y-1",children:Ze(e.content,e.type==="sent")})]})},e.id)),a("div",{ref:Me})]})})}),o("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0 space-y-3",children:[o("div",{className:"flex gap-2 items-center flex-wrap",children:[a("button",{type:"button",className:A("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",H?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{M(!H),W(null)},title:"\u63D2\u5165\u8868\u60C5",children:a(re,{size:16})}),a("button",{type:"button",className:A("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",k==="image"?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{W(e=>e==="image"?null:"image"),M(!1)},title:"\u63D2\u5165\u56FE\u7247 URL",children:a(oe,{size:16})}),a("button",{type:"button",className:A("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",k==="video"?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{W(e=>e==="video"?null:"video"),M(!1)},title:"\u63D2\u5165\u89C6\u9891 URL",children:a(ie,{size:16})}),a("button",{type:"button",className:A("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",k==="audio"?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{W(e=>e==="audio"?null:"audio"),M(!1)},title:"\u63D2\u5165\u97F3\u9891 URL",children:a(ue,{size:16})}),a("div",{className:"flex-1 min-w-[1rem]"}),S&&a("button",{className:"h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors",onClick:()=>{B(""),v([])},children:a(pe,{size:16})})]}),H&&o("div",{className:"p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2",children:[a("input",{value:u,onChange:e=>c(e.target.value),placeholder:"\u641C\u7D22\u8868\u60C5...",className:"w-full h-8 rounded-md border bg-transparent px-2 text-sm"}),a("div",{className:"grid grid-cols-8 gap-1",children:ve.slice(0,80).map(e=>a("button",{onClick:()=>je(e.id),title:e.name,className:"w-10 h-10 rounded-md border flex items-center justify-center hover:bg-accent transition-colors",children:a("img",{src:`https://face.viki.moe/apng/${e.id}.png`,alt:e.name,className:"w-8 h-8"})},e.id))}),ve.length===0&&o("div",{className:"flex flex-col items-center gap-2 py-4",children:[a(j,{size:32,className:"text-muted-foreground/30"}),a("span",{className:"text-sm text-muted-foreground",children:"\u672A\u627E\u5230\u5339\u914D\u7684\u8868\u60C5"})]})]}),k&&o("div",{className:"p-3 rounded-md border bg-muted/30 space-y-2",children:[o("p",{className:"text-xs text-muted-foreground",children:[k==="image"&&"\u652F\u6301 http(s) \u56FE\u7247\u94FE\u63A5\u6216 data URL",k==="video"&&"\u652F\u6301\u6D4F\u89C8\u5668\u53EF\u89E3\u7801\u7684\u89C6\u9891\u76F4\u94FE\uFF08\u5982 .mp4\u3001.webm\uFF09",k==="audio"&&"\u652F\u6301 .mp3\u3001.ogg\u3001.wav \u7B49\u97F3\u9891\u76F4\u94FE"]}),a("input",{value:$,onChange:e=>me(e.target.value),placeholder:k==="image"?"\u56FE\u7247 URL\u2026":k==="video"?"\u89C6\u9891 URL\u2026":"\u97F3\u9891 URL\u2026",className:"w-full h-8 rounded-md border border-input bg-background px-2 text-sm",onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),be())}}),o("button",{type:"button",className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-primary text-primary-foreground text-sm disabled:opacity-50",onClick:be,disabled:!$.trim(),children:[a(ae,{size:14})," \u63D2\u5165\u5230\u8F93\u5165\u6846"]})]}),o("div",{className:"flex gap-2 items-start",children:[o("div",{className:"flex-1 relative",children:[a(Ve,{ref:q,placeholder:`\u5411 ${g.name} \u53D1\u9001\u6D88\u606F...`,onSend:Fe,onChange:ea,onAtTrigger:Ye,minHeight:"44px",maxHeight:"200px"}),Y&&a("div",{className:"absolute z-50 rounded-lg border bg-popover shadow-md min-w-60 max-h-72 overflow-y-auto p-1",style:{top:`${Y.top}px`,left:`${Y.left}px`},children:Re.length>0?Re.map(e=>o("div",{className:"flex items-center gap-2 p-2 rounded-md cursor-pointer hover:bg-accent transition-colors",onClick:()=>$e(e),children:[a(Z,{size:16,className:"text-muted-foreground"}),o("div",{className:"flex-1",children:[a("div",{className:"text-sm font-medium",children:e.name}),o("div",{className:"text-xs text-muted-foreground",children:["ID: ",e.id]})]})]},e.id)):o("div",{className:"flex flex-col items-center gap-2 p-4",children:[a(j,{size:20,className:"text-muted-foreground/50"}),a("span",{className:"text-xs text-muted-foreground",children:"\u672A\u627E\u5230\u5339\u914D\u7684\u7528\u6237"})]})})]}),o("button",{className:"inline-flex items-center gap-1.5 h-10 px-4 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 transition-colors hover:bg-primary/90",onClick:()=>{let e=q.current?.getContent();e&&Fe(e.text,e.segments)},disabled:!Be(V),children:[a(le,{size:16})," \u53D1\u9001"]})]}),o("div",{className:"flex items-center gap-2 flex-wrap text-xs text-muted-foreground",children:[a(de,{size:12})," \u5FEB\u6377\u64CD\u4F5C:",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Enter"})," \u53D1\u9001",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Shift+Enter"})," \u6362\u884C",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[@\u540D\u79F0]"})," @\u67D0\u4EBA",a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[video:URL]"}),a("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[audio:URL]"})]})]})]})]})]})}function So(i){i.addRoute({path:"/console/sandbox",name:"\u6C99\u76D2",element:i.React.createElement(Ae,{hostReact:i.React})}),i.addTool({id:"sandbox",name:"\u6C99\u76D2",path:"/console/sandbox"})}export{So as register};
|
|
8
8
|
/*! Bundled license information:
|
|
9
9
|
|
|
10
10
|
lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs:
|
|
@@ -37,7 +37,7 @@ lucide-react/dist/esm/icons/wifi.mjs:
|
|
|
37
37
|
lucide-react/dist/esm/icons/x.mjs:
|
|
38
38
|
lucide-react/dist/esm/lucide-react.mjs:
|
|
39
39
|
(**
|
|
40
|
-
* @license lucide-react v1.
|
|
40
|
+
* @license lucide-react v1.17.0 - ISC
|
|
41
41
|
*
|
|
42
42
|
* This source code is licensed under the ISC license.
|
|
43
43
|
* See the LICENSE file in the root directory of this source tree.
|
package/lib/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare module "zhin.js" {
|
|
|
8
8
|
sandbox: SandboxAdapter;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
/** Node:`Router.ws
|
|
11
|
+
/** Node:`Router.ws` */
|
|
12
12
|
export declare class SandboxAdapter extends SandboxWsHostAdapter {
|
|
13
13
|
wss?: {
|
|
14
14
|
on: (ev: string, fn: (...args: unknown[]) => void) => void;
|
|
@@ -18,7 +18,5 @@ export declare class SandboxAdapter extends SandboxWsHostAdapter {
|
|
|
18
18
|
start(): Promise<void>;
|
|
19
19
|
setupWebSocket(router: SandboxRouter): Promise<void>;
|
|
20
20
|
}
|
|
21
|
-
export {
|
|
22
|
-
export { registerSandboxSseRoutes, type RegisterSandboxSseOptions, } from "./fetch-sse.js";
|
|
23
|
-
export { SandboxWsBot, SandboxWsHostAdapter, resolveSandboxBot, bindSandboxWsSocket, parseSandboxWsPayload, type ResolvedSandboxBot, type SandboxTransport, type SandboxWsConfig, type SandboxWsSocket, } from "./sandbox-ws.js";
|
|
21
|
+
export { SandboxWsBot, SandboxWsHostAdapter, resolveSandboxBot, bindSandboxWsSocket, parseSandboxWsPayload, type ResolvedSandboxBot, type SandboxWsConfig, type SandboxWsSocket, } from "./sandbox-ws.js";
|
|
24
22
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,SAAS,CAAC;AAEjD,OAAO,EACL,oBAAoB,EAGrB,MAAM,iBAAiB,CAAC;AAGzB,KAAK,aAAa,GAAG;IACnB,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,QAAQ;QAChB,OAAO,EAAE,cAAc,CAAC;KACzB;CACF;AAKD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,SAAS,CAAC;AAEjD,OAAO,EACL,oBAAoB,EAGrB,MAAM,iBAAiB,CAAC;AAGzB,KAAK,aAAa,GAAG;IACnB,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,WAAW,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,QAAQ;QAChB,OAAO,EAAE,cAAc,CAAC;KACzB;CACF;AAKD,uBAAuB;AACvB,qBAAa,cAAe,SAAQ,oBAAoB;IACtD,GAAG,CAAC,EAAE;QAAE,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;gBAE5E,MAAM,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC;IAKjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ/B,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAsB3D;AAkCD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { usePlugin } from "zhin.js";
|
|
|
3
3
|
import { SandboxWsHostAdapter, resolveSandboxBot, } from "./sandbox-ws.js";
|
|
4
4
|
const plugin = usePlugin();
|
|
5
5
|
const logger = plugin.logger;
|
|
6
|
-
/** Node:`Router.ws
|
|
6
|
+
/** Node:`Router.ws` */
|
|
7
7
|
export class SandboxAdapter extends SandboxWsHostAdapter {
|
|
8
8
|
wss;
|
|
9
9
|
constructor(plugin) {
|
|
@@ -38,7 +38,7 @@ export class SandboxAdapter extends SandboxWsHostAdapter {
|
|
|
38
38
|
const { provide } = usePlugin();
|
|
39
39
|
provide({
|
|
40
40
|
name: "sandbox",
|
|
41
|
-
description: "Sandbox Adapter — Node Router.ws
|
|
41
|
+
description: "Sandbox Adapter — Node Router.ws",
|
|
42
42
|
mounted: async (p) => {
|
|
43
43
|
const adapter = new SandboxAdapter(p);
|
|
44
44
|
await adapter.start();
|
|
@@ -63,7 +63,5 @@ plugin.useContext("web", (pageManager) => {
|
|
|
63
63
|
meta: { name: "Sandbox" },
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
-
export { registerSandboxWebSocketRoutes, } from "./fetch-ws.js";
|
|
67
|
-
export { registerSandboxSseRoutes, } from "./fetch-sse.js";
|
|
68
66
|
export { SandboxWsBot, SandboxWsHostAdapter, resolveSandboxBot, bindSandboxWsSocket, parseSandboxWsPayload, } from "./sandbox-ws.js";
|
|
69
67
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAe,MAAM,SAAS,CAAC;AAEjD,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAElB,MAAM,iBAAiB,CAAC;AAazB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAE7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAe,MAAM,SAAS,CAAC;AAEjD,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAElB,MAAM,iBAAiB,CAAC;AAazB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAE7B,uBAAuB;AACvB,MAAM,OAAO,cAAe,SAAQ,oBAAoB;IACtD,GAAG,CAAqF;IAExF,YAAY,MAAoC;QAC9C,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAA4B,CAAC;QAC3F,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;IAC9C,CAAC;IAEQ,KAAK,CAAC,KAAK;QAClB,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,6BAA6B,EAAE,CAAC;QACrC,MAAM,CAAC,KAAK,CACV,wBAAwB,IAAI,CAAC,QAAQ,CAAC,IAAI,8BAA8B,CACzE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,MAAqB;QACxC,IAAI,IAAI,CAAC,GAAG;YAAE,OAAO;QACrB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;QAEjC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE;YAC/C,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAc,CAAC;YAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAA4C,CAAC;YAC/D,MAAM,CAAC,KAAK,CACV,+BAA+B,GAAG,CAAC,MAAM,EAAE,aAAa,IAAI,SAAS,EAAE,CACxE,CAAC;YACF,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,EAAqB,CAAC,CAAC;YACxD,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBAClB,MAAM,CAAC,KAAK,CAAC,8BAA8B,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC/D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvB,MAAM,CAAC,KAAK,CAAC,+BAA+B,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAC;IAChF,CAAC;CACF;AAED,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,EAAE,CAAC;AAEhC,OAAO,CAAC;IACN,IAAI,EAAE,SAAS;IACf,WAAW,EAAE,kCAAkC;IAC/C,OAAO,EAAE,KAAK,EAAE,CAAS,EAAE,EAAE;QAC3B,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE;QACzC,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC;QAC1B,CAAC;QACD,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC;QACrB,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;CACO,CAAC,CAAC;AAEZ,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAC,SAAS,EAAE,KAAK,EAAE,MAAqB,EAAC,OAAuB,EAAE,EAAE;IAC5F,MAAM,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,EAAE;IACvC,WAAW,CAAC,QAAQ,CAAC;QACnB,EAAE,EAAE,SAAS;QACb,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,qBAAqB,CAAC;QACrE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC;QACjE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;KAC1B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,GAItB,MAAM,iBAAiB,CAAC"}
|