chatluna-plugin-onebot-sandbox 1.0.0
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/LICENSE +21 -0
- package/README.md +20 -0
- package/client/app.tsx +306 -0
- package/client/chat/chat-pane.tsx +303 -0
- package/client/chat/composer.css +635 -0
- package/client/chat/composer.tsx +646 -0
- package/client/chat/details-panel.tsx +196 -0
- package/client/chat/emoji-picker.tsx +70 -0
- package/client/chat/extension-mark.tsx +16 -0
- package/client/chat/forward.tsx +257 -0
- package/client/chat/image-preview.tsx +93 -0
- package/client/chat/member-menu.tsx +64 -0
- package/client/chat/message-list.tsx +617 -0
- package/client/chat/messages.css +1018 -0
- package/client/chat/notifications.tsx +83 -0
- package/client/chat/reactions.tsx +52 -0
- package/client/chat/search-panel.tsx +231 -0
- package/client/chat/sidebar.tsx +424 -0
- package/client/chat/webqq-view.tsx +71 -0
- package/client/environment/avatar-picker.tsx +92 -0
- package/client/environment/create-popover.tsx +228 -0
- package/client/environment/directory-model.ts +63 -0
- package/client/environment/entity-dialog.css +383 -0
- package/client/environment/entity-dialog.tsx +442 -0
- package/client/environment/page.css +14 -0
- package/client/environment/page.tsx +280 -0
- package/client/i18n.ts +19 -0
- package/client/index.ts +17 -0
- package/client/locales/en.yml +617 -0
- package/client/locales/zh.yml +617 -0
- package/client/mcp/capability-catalog.tsx +277 -0
- package/client/mcp/credential-manager.tsx +257 -0
- package/client/onebot-debug/page.tsx +329 -0
- package/client/records/record-layout.tsx +429 -0
- package/client/records/records.css +259 -0
- package/client/settings/about.tsx +43 -0
- package/client/settings/draft.ts +47 -0
- package/client/settings/localize.ts +76 -0
- package/client/settings/page.tsx +210 -0
- package/client/settings/settings.css +47 -0
- package/client/shared/avatar.tsx +35 -0
- package/client/shared/confirm-dialog.tsx +44 -0
- package/client/shared/controls.css +17 -0
- package/client/shared/discard-confirm.tsx +45 -0
- package/client/shared/floating-panel.ts +40 -0
- package/client/shared/format-duration.ts +22 -0
- package/client/shared/format-time.ts +49 -0
- package/client/shared/glass.css +150 -0
- package/client/shared/implementation.ts +12 -0
- package/client/shared/overlay-scrollbar.css +45 -0
- package/client/shared/overlay-scrollbar.tsx +123 -0
- package/client/shared/use-element-width.ts +19 -0
- package/client/shared/use-retained.ts +12 -0
- package/client/test-call/page.tsx +260 -0
- package/client/test-space/agent-visuals.tsx +121 -0
- package/client/test-space/observe-overlay.tsx +42 -0
- package/client/test-space/overview.tsx +267 -0
- package/client/test-space/spaces.css +201 -0
- package/client/test-space/thumbnail-capture.ts +63 -0
- package/client/test-space/thumbnail-scale.ts +21 -0
- package/client/test-space/use-space-list.ts +35 -0
- package/client/test-space/zoom.ts +197 -0
- package/client/webqq/composer-draft-host.ts +578 -0
- package/client/webqq/composer-draft.ts +81 -0
- package/client/webqq/conversation-tree.ts +155 -0
- package/client/webqq/emoji-catalog.ts +78 -0
- package/client/webqq/fork-boundary.ts +28 -0
- package/client/webqq/forward-cluster.ts +20 -0
- package/client/webqq/forward-dialog-stack.ts +74 -0
- package/client/webqq/forward-preview.ts +40 -0
- package/client/webqq/friend-menu.ts +17 -0
- package/client/webqq/group-display.ts +18 -0
- package/client/webqq/group-menu.ts +25 -0
- package/client/webqq/mention.ts +4 -0
- package/client/webqq/message-capabilities.ts +37 -0
- package/client/webqq/message-cluster.ts +68 -0
- package/client/webqq/message-presentation.ts +197 -0
- package/client/webqq/message-reveal.ts +31 -0
- package/client/webqq/message-search-date.ts +40 -0
- package/client/webqq/message-selection.ts +85 -0
- package/client/webqq/notification-requests.ts +20 -0
- package/client/webqq/participant-presentation.ts +128 -0
- package/client/webqq/profile-card.ts +199 -0
- package/client/webqq/relationship-directory.ts +62 -0
- package/client/webqq/thinking-panel.ts +7 -0
- package/client/webqq/user-stack.ts +53 -0
- package/client/workspace/agent-overlay-effect.ts +238 -0
- package/client/workspace/context.tsx +117 -0
- package/client/workspace/overlay-host.tsx +299 -0
- package/client/workspace/profile-card.css +164 -0
- package/client/workspace/state.ts +28 -0
- package/client/workspace/store.ts +388 -0
- package/client/workspace/use-test-spaces.ts +21 -0
- package/dist/.vite/manifest.json +21 -0
- package/dist/app-63rfTh6w.js +85 -0
- package/dist/client.css +4 -0
- package/dist/client.js +1 -0
- package/lib/account-profile.d.ts +17 -0
- package/lib/account-profile.d.ts.map +1 -0
- package/lib/base-dir.d.ts +4 -0
- package/lib/base-dir.d.ts.map +1 -0
- package/lib/bot.d.ts +185 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/builtin-avatar-options.d.ts +11 -0
- package/lib/builtin-avatar-options.d.ts.map +1 -0
- package/lib/builtin-avatars.d.ts +6 -0
- package/lib/builtin-avatars.d.ts.map +1 -0
- package/lib/channel-assignee.d.ts +52 -0
- package/lib/channel-assignee.d.ts.map +1 -0
- package/lib/chatluna/conversation-lines.d.ts +46 -0
- package/lib/chatluna/conversation-lines.d.ts.map +1 -0
- package/lib/chatluna/runtime.d.ts +26 -0
- package/lib/chatluna/runtime.d.ts.map +1 -0
- package/lib/chatluna/state.d.ts +67 -0
- package/lib/chatluna/state.d.ts.map +1 -0
- package/lib/chatluna/thinking.d.ts +10 -0
- package/lib/chatluna/thinking.d.ts.map +1 -0
- package/lib/chatluna/tools.d.ts +36 -0
- package/lib/chatluna/tools.d.ts.map +1 -0
- package/lib/chatluna/wakeup.d.ts +143 -0
- package/lib/chatluna/wakeup.d.ts.map +1 -0
- package/lib/console-contract.d.ts +131 -0
- package/lib/console-contract.d.ts.map +1 -0
- package/lib/console.d.ts +31 -0
- package/lib/console.d.ts.map +1 -0
- package/lib/control-service.d.ts +425 -0
- package/lib/control-service.d.ts.map +1 -0
- package/lib/conversation-resolution.d.ts +157 -0
- package/lib/conversation-resolution.d.ts.map +1 -0
- package/lib/error-detail.d.ts +3 -0
- package/lib/error-detail.d.ts.map +1 -0
- package/lib/inbound-delivery.d.ts +156 -0
- package/lib/inbound-delivery.d.ts.map +1 -0
- package/lib/index.d.ts +76 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12834 -0
- package/lib/index.js.map +1 -0
- package/lib/lifecycle.d.ts +8 -0
- package/lib/lifecycle.d.ts.map +1 -0
- package/lib/mcp/arguments.d.ts +71 -0
- package/lib/mcp/arguments.d.ts.map +1 -0
- package/lib/mcp/call-records.d.ts +32 -0
- package/lib/mcp/call-records.d.ts.map +1 -0
- package/lib/mcp/http-api.d.ts +147 -0
- package/lib/mcp/http-api.d.ts.map +1 -0
- package/lib/mcp/page-cursor.d.ts +37 -0
- package/lib/mcp/page-cursor.d.ts.map +1 -0
- package/lib/mcp/server.d.ts +60 -0
- package/lib/mcp/server.d.ts.map +1 -0
- package/lib/mcp/service.d.ts +219 -0
- package/lib/mcp/service.d.ts.map +1 -0
- package/lib/mcp/tool-registry.d.ts +113 -0
- package/lib/mcp/tool-registry.d.ts.map +1 -0
- package/lib/mcp/types.d.ts +144 -0
- package/lib/mcp/types.d.ts.map +1 -0
- package/lib/media-storage.d.ts +33 -0
- package/lib/media-storage.d.ts.map +1 -0
- package/lib/message-capabilities.d.ts +78 -0
- package/lib/message-capabilities.d.ts.map +1 -0
- package/lib/onebot-debug.d.ts +115 -0
- package/lib/onebot-debug.d.ts.map +1 -0
- package/lib/onebot-message.d.ts +23 -0
- package/lib/onebot-message.d.ts.map +1 -0
- package/lib/onebot-profiles.d.ts +45 -0
- package/lib/onebot-profiles.d.ts.map +1 -0
- package/lib/persistence.d.ts +148 -0
- package/lib/persistence.d.ts.map +1 -0
- package/lib/random.d.ts +5 -0
- package/lib/random.d.ts.map +1 -0
- package/lib/record-store.d.ts +80 -0
- package/lib/record-store.d.ts.map +1 -0
- package/lib/relationship-actions.d.ts +157 -0
- package/lib/relationship-actions.d.ts.map +1 -0
- package/lib/scope-directory.d.ts +105 -0
- package/lib/scope-directory.d.ts.map +1 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.d.ts.map +1 -0
- package/lib/test-spaces.d.ts +69 -0
- package/lib/test-spaces.d.ts.map +1 -0
- package/lib/types.d.ts +739 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/webui.d.ts +26 -0
- package/lib/webui.d.ts.map +1 -0
- package/package.json +112 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { BotIcon, KeyRoundIcon, PencilIcon, PlusIcon, ServerCogIcon, Trash2Icon, UserIcon, UsersIcon, WebhookIcon, type LucideIcon } from 'lucide-react'
|
|
3
|
+
import { Badge, Button, cn, ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@chatluna/ui-kit'
|
|
4
|
+
import { getSandboxBots } from '../../src/types'
|
|
5
|
+
import { sourceName, useT } from '../i18n'
|
|
6
|
+
import { HttpCapabilityCatalog, McpCapabilityCatalog, useCatalog } from '../mcp/capability-catalog'
|
|
7
|
+
import { TestCredentialManager } from '../mcp/credential-manager'
|
|
8
|
+
import { SandboxAvatar } from '../shared/avatar'
|
|
9
|
+
import { OverlayScrollbar } from '../shared/overlay-scrollbar'
|
|
10
|
+
import { useSandbox, useWorkspace } from '../workspace/context'
|
|
11
|
+
import { invoke } from '../workspace/store'
|
|
12
|
+
import { useTestSpaces } from '../workspace/use-test-spaces'
|
|
13
|
+
import { CreateEntityPopover } from './create-popover'
|
|
14
|
+
import { buildEnvironmentDirectoryModel } from './directory-model'
|
|
15
|
+
import { implementationLabel } from '../shared/implementation'
|
|
16
|
+
import './page.css'
|
|
17
|
+
|
|
18
|
+
type Section = 'users' | 'bots' | 'groups' | 'credentials' | 'mcp' | 'http'
|
|
19
|
+
|
|
20
|
+
type EntityTarget = { type: 'user' | 'bot' | 'group', id: string }
|
|
21
|
+
|
|
22
|
+
/** 三份目录对应的创建类型;能力目录与测试凭证没有实体可建。 */
|
|
23
|
+
const CREATE_TYPES: Partial<Record<Section, EntityTarget['type']>> = { users: 'user', bots: 'bot', groups: 'group' }
|
|
24
|
+
|
|
25
|
+
interface SectionItem {
|
|
26
|
+
id: Section
|
|
27
|
+
icon: LucideIcon
|
|
28
|
+
count?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 环境管理:模拟 QQ 环境的三份目录,加上测试控制端点的凭证与两种协议表述的能力目录。 */
|
|
32
|
+
export function EnvironmentPage() {
|
|
33
|
+
const t = useT()
|
|
34
|
+
const { snapshot, resolveAvatar, operator } = useWorkspace()
|
|
35
|
+
const { spaces } = useTestSpaces()
|
|
36
|
+
const directory = React.useMemo(() => buildEnvironmentDirectoryModel(snapshot, spaces, resolveAvatar), [snapshot, spaces, resolveAvatar])
|
|
37
|
+
const [section, setSection] = React.useState<Section>('users')
|
|
38
|
+
const scroller = React.useRef<HTMLDivElement>(null)
|
|
39
|
+
const mcp = useCatalog(() => invoke('onebot-sandbox.mcp-capabilities', undefined), t('sandbox.env.mcpFailed'))
|
|
40
|
+
const http = useCatalog(() => invoke('onebot-sandbox.http-capabilities', undefined), t('sandbox.env.httpFailed'))
|
|
41
|
+
const loadMcp = mcp.load
|
|
42
|
+
const loadHttp = http.load
|
|
43
|
+
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
void loadMcp()
|
|
46
|
+
void loadHttp()
|
|
47
|
+
}, [loadMcp, loadHttp])
|
|
48
|
+
|
|
49
|
+
// 导航分两组:模拟出来的 QQ 环境,与给测试脚本用的控制端点。
|
|
50
|
+
const groups: Array<{ id: 'directory' | 'endpoint', items: SectionItem[] }> = [
|
|
51
|
+
{
|
|
52
|
+
id: 'directory',
|
|
53
|
+
items: [
|
|
54
|
+
{ id: 'users', icon: UserIcon, count: directory.users.length },
|
|
55
|
+
{ id: 'bots', icon: BotIcon, count: directory.bots.length },
|
|
56
|
+
{ id: 'groups', icon: UsersIcon, count: directory.groups.length },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'endpoint',
|
|
61
|
+
items: [
|
|
62
|
+
{ id: 'mcp', icon: ServerCogIcon, count: mcp.catalog?.tools.length },
|
|
63
|
+
{ id: 'http', icon: WebhookIcon, count: http.catalog?.routes.length },
|
|
64
|
+
{ id: 'credentials', icon: KeyRoundIcon },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
const createType = CREATE_TYPES[section]
|
|
70
|
+
|
|
71
|
+
const select = (id: Section) => {
|
|
72
|
+
setSection(id)
|
|
73
|
+
scroller.current?.scrollTo({ top: 0 })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-hidden px-6 pt-3 pb-6 text-sm leading-5">
|
|
78
|
+
<p className="text-xs text-muted-foreground">{t('sandbox.env.description')}</p>
|
|
79
|
+
<div className="grid min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)] gap-4 md:grid-cols-[14rem_minmax(0,1fr)] md:grid-rows-1">
|
|
80
|
+
<nav aria-label={t('sandbox.env.sections')} className="sandbox-scroll-strip flex gap-0.5 self-start overflow-x-auto rounded-xl p-1.5 ring-1 ring-border md:flex-col md:overflow-x-visible">
|
|
81
|
+
{groups.map((group, index) => (
|
|
82
|
+
<React.Fragment key={group.id}>
|
|
83
|
+
{index > 0 && <div role="separator" className="mx-1 w-px shrink-0 bg-border md:hidden" />}
|
|
84
|
+
<p className={cn('hidden px-2.5 pt-1.5 pb-1 text-[11px] leading-4 font-medium text-muted-foreground md:block', index > 0 && 'md:mt-2')}>
|
|
85
|
+
{t(`sandbox.env.nav.${group.id}`)}
|
|
86
|
+
</p>
|
|
87
|
+
{group.items.map(({ id, icon: Icon, count }) => (
|
|
88
|
+
<Button
|
|
89
|
+
key={id}
|
|
90
|
+
variant="ghost"
|
|
91
|
+
className={cn('shrink-0 justify-start md:w-full', section === id && 'bg-accent text-accent-foreground')}
|
|
92
|
+
aria-current={section === id ? 'page' : undefined}
|
|
93
|
+
onClick={() => select(id)}
|
|
94
|
+
>
|
|
95
|
+
<Icon />
|
|
96
|
+
<span>{t(`sandbox.env.section.${id}.label`)}</span>
|
|
97
|
+
{count !== undefined && (
|
|
98
|
+
<span className={cn('ml-auto pl-2 text-xs tabular-nums', section === id ? 'text-foreground/70' : 'text-muted-foreground')}>{count}</span>
|
|
99
|
+
)}
|
|
100
|
+
</Button>
|
|
101
|
+
))}
|
|
102
|
+
</React.Fragment>
|
|
103
|
+
))}
|
|
104
|
+
</nav>
|
|
105
|
+
<section aria-label={t(`sandbox.env.section.${section}.label`)} className="flex min-h-0 flex-col overflow-hidden rounded-xl ring-1 ring-border">
|
|
106
|
+
<header className="flex shrink-0 items-center gap-3 border-b border-border px-5 py-3.5">
|
|
107
|
+
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
108
|
+
<h2 className="text-sm leading-5 font-semibold">{t(`sandbox.env.section.${section}.label`)}</h2>
|
|
109
|
+
<p className="text-xs leading-4 text-muted-foreground">{t(`sandbox.env.section.${section}.description`)}</p>
|
|
110
|
+
</div>
|
|
111
|
+
{createType && (
|
|
112
|
+
<CreateEntityPopover
|
|
113
|
+
key={createType}
|
|
114
|
+
type={createType}
|
|
115
|
+
operator={operator}
|
|
116
|
+
bots={getSandboxBots(snapshot)}
|
|
117
|
+
side="bottom"
|
|
118
|
+
trigger={<Button size="sm" variant="outline" className="shrink-0"><PlusIcon />{t(`sandbox.create.${createType}`)}</Button>}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</header>
|
|
122
|
+
<div className="relative flex min-h-0 flex-1 flex-col">
|
|
123
|
+
<div ref={scroller} className="sandbox-env-scroller min-h-0 flex-1 overflow-y-auto">
|
|
124
|
+
{section === 'users' && (
|
|
125
|
+
<DirectoryGrid icon={UserIcon} empty={t('sandbox.env.noUser')}>
|
|
126
|
+
{directory.users.map((user) => (
|
|
127
|
+
<EditableCard key={user.id} target={{ type: 'user', id: user.id }} avatar={<SandboxAvatar kind="user" name={user.name} src={user.avatar} className="size-10" />} title={user.name} subtitle={user.id} />
|
|
128
|
+
))}
|
|
129
|
+
</DirectoryGrid>
|
|
130
|
+
)}
|
|
131
|
+
{section === 'bots' && (
|
|
132
|
+
<DirectoryGrid icon={BotIcon} empty={t('sandbox.env.noBot')}>
|
|
133
|
+
{directory.bots.map((bot) => {
|
|
134
|
+
const card = {
|
|
135
|
+
avatar: <SandboxAvatar kind="bot" name={bot.name} src={bot.avatar} className="size-10" />,
|
|
136
|
+
title: bot.name,
|
|
137
|
+
subtitle: bot.id,
|
|
138
|
+
meta: (
|
|
139
|
+
<>
|
|
140
|
+
<Badge variant="secondary">{implementationLabel(bot.implementation)}</Badge>
|
|
141
|
+
<Badge variant="outline" className="max-w-40"><span className="truncate">{sourceName(t, bot.source)}</span></Badge>
|
|
142
|
+
<EnabledStatus enabled={bot.enabled} />
|
|
143
|
+
</>
|
|
144
|
+
),
|
|
145
|
+
}
|
|
146
|
+
// 测试空间的机器人属于各自的空间快照,实体弹窗只编辑主环境,这里只读展示。
|
|
147
|
+
return bot.source.type === 'main'
|
|
148
|
+
? <EditableCard key={`main:${bot.id}`} target={{ type: 'bot', id: bot.id }} {...card} />
|
|
149
|
+
: <DirectoryCard key={`space:${bot.source.spaceId}:${bot.id}`} {...card} />
|
|
150
|
+
})}
|
|
151
|
+
</DirectoryGrid>
|
|
152
|
+
)}
|
|
153
|
+
{section === 'groups' && (
|
|
154
|
+
<DirectoryGrid icon={UsersIcon} empty={t('sandbox.env.noGroup')}>
|
|
155
|
+
{directory.groups.map((group) => (
|
|
156
|
+
<EditableCard
|
|
157
|
+
key={group.id}
|
|
158
|
+
target={{ type: 'group', id: group.id }}
|
|
159
|
+
avatar={<SandboxAvatar kind="group" name={group.name} src={group.avatar} className="size-10" />}
|
|
160
|
+
title={group.name}
|
|
161
|
+
subtitle={t('sandbox.env.groupSubtitle', { id: group.id, count: group.members.length })}
|
|
162
|
+
/>
|
|
163
|
+
))}
|
|
164
|
+
</DirectoryGrid>
|
|
165
|
+
)}
|
|
166
|
+
{section === 'credentials' && <TestCredentialManager />}
|
|
167
|
+
{section === 'mcp' && <McpCapabilityCatalog catalog={mcp.catalog} loading={mcp.loading} error={mcp.error} onRetry={() => void mcp.load()} />}
|
|
168
|
+
{section === 'http' && <HttpCapabilityCatalog catalog={http.catalog} loading={http.loading} error={http.error} onRetry={() => void http.load()} />}
|
|
169
|
+
</div>
|
|
170
|
+
<OverlayScrollbar target={scroller} className="sandbox-env-scrollbar" />
|
|
171
|
+
</div>
|
|
172
|
+
</section>
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** 目录卡片按面板宽度自动排列,宽屏下多列铺开,不在右侧留下大片空白。 */
|
|
179
|
+
function DirectoryGrid({ icon: Icon, empty, children }: { icon: LucideIcon, empty: string, children: React.ReactNode[] }) {
|
|
180
|
+
if (!children.length) {
|
|
181
|
+
return (
|
|
182
|
+
<div className="flex flex-col items-center gap-3 px-6 py-16 text-center">
|
|
183
|
+
<span className="flex size-10 items-center justify-center rounded-full bg-muted text-muted-foreground"><Icon className="size-5" /></span>
|
|
184
|
+
<p className="text-xs text-muted-foreground">{empty}</p>
|
|
185
|
+
</div>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
return <div className="grid grid-cols-[repeat(auto-fill,minmax(15rem,1fr))] gap-3 p-4">{children}</div>
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface DirectoryCardContent {
|
|
192
|
+
avatar: React.ReactNode
|
|
193
|
+
title: string
|
|
194
|
+
subtitle: string
|
|
195
|
+
meta?: React.ReactNode
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** 主环境的实体卡片:点卡片打开编辑,悬停或聚焦时露出编辑与删除,右键菜单提供同样两项。 */
|
|
199
|
+
function EditableCard({ target, ...card }: DirectoryCardContent & { target: EntityTarget }) {
|
|
200
|
+
const t = useT()
|
|
201
|
+
const { dialogs } = useSandbox()
|
|
202
|
+
const kind = t(`sandbox.kind.${target.type}`)
|
|
203
|
+
const editLabel = t('sandbox.menu.editEntity', { kind })
|
|
204
|
+
const deleteLabel = t('sandbox.menu.deleteEntity', { kind })
|
|
205
|
+
const edit = () => dialogs.openEntity('edit', target)
|
|
206
|
+
const remove = () => dialogs.openEntity('delete', target)
|
|
207
|
+
return (
|
|
208
|
+
<ContextMenu>
|
|
209
|
+
<ContextMenuTrigger render={(
|
|
210
|
+
<DirectoryCard
|
|
211
|
+
{...card}
|
|
212
|
+
onEdit={edit}
|
|
213
|
+
actions={(
|
|
214
|
+
<>
|
|
215
|
+
<Button size="icon-sm" variant="ghost" aria-label={editLabel} onClick={edit}><PencilIcon /></Button>
|
|
216
|
+
<Button size="icon-sm" variant="ghost" aria-label={deleteLabel} className="hover:text-destructive" onClick={remove}><Trash2Icon /></Button>
|
|
217
|
+
</>
|
|
218
|
+
)}
|
|
219
|
+
/>
|
|
220
|
+
)} />
|
|
221
|
+
<ContextMenuContent className="sandbox-glass">
|
|
222
|
+
<ContextMenuItem onClick={edit}><PencilIcon />{editLabel}</ContextMenuItem>
|
|
223
|
+
<ContextMenuItem variant="destructive" onClick={remove}><Trash2Icon />{deleteLabel}</ContextMenuItem>
|
|
224
|
+
</ContextMenuContent>
|
|
225
|
+
</ContextMenu>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 目录卡片。可编辑时标题是撑满整张卡片的按钮(`::after` 铺满),操作按钮叠在它上面,
|
|
231
|
+
* 避免按钮嵌套按钮;焦点环也画在铺满层上,键盘聚焦时整张卡片高亮。
|
|
232
|
+
*/
|
|
233
|
+
const DirectoryCard = React.forwardRef<HTMLElement, DirectoryCardContent & Omit<React.ComponentProps<'article'>, 'title'> & {
|
|
234
|
+
onEdit?(): void
|
|
235
|
+
actions?: React.ReactNode
|
|
236
|
+
}>(function DirectoryCard({ avatar, title, subtitle, meta, onEdit, actions, className, ...props }, ref) {
|
|
237
|
+
return (
|
|
238
|
+
<article
|
|
239
|
+
ref={ref}
|
|
240
|
+
className={cn(
|
|
241
|
+
'relative flex flex-col gap-3 rounded-xl bg-muted/30 p-3.5 ring-1 ring-border/70',
|
|
242
|
+
onEdit && 'group transition-[background-color,box-shadow] duration-150 hover:bg-muted/60 hover:ring-border',
|
|
243
|
+
className,
|
|
244
|
+
)}
|
|
245
|
+
{...props}
|
|
246
|
+
>
|
|
247
|
+
<div className="flex items-center gap-3">
|
|
248
|
+
{avatar}
|
|
249
|
+
<span className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
250
|
+
{onEdit ? (
|
|
251
|
+
<button
|
|
252
|
+
type="button"
|
|
253
|
+
className="block w-full truncate text-left text-[13px] leading-5 font-medium outline-none after:absolute after:inset-0 after:rounded-xl focus-visible:after:ring-2 focus-visible:after:ring-ring/50"
|
|
254
|
+
onClick={onEdit}
|
|
255
|
+
>
|
|
256
|
+
{title}
|
|
257
|
+
</button>
|
|
258
|
+
) : <strong className="truncate text-[13px] leading-5 font-medium">{title}</strong>}
|
|
259
|
+
<small className="truncate text-xs leading-4 text-muted-foreground tabular-nums">{subtitle}</small>
|
|
260
|
+
</span>
|
|
261
|
+
{actions && (
|
|
262
|
+
<span className="relative z-10 -my-1 -mr-1.5 flex shrink-0 items-center gap-0.5 self-start text-muted-foreground opacity-0 transition-opacity duration-150 group-focus-within:opacity-100 group-hover:opacity-100">
|
|
263
|
+
{actions}
|
|
264
|
+
</span>
|
|
265
|
+
)}
|
|
266
|
+
</div>
|
|
267
|
+
{meta && <div className="flex flex-wrap items-center gap-1.5">{meta}</div>}
|
|
268
|
+
</article>
|
|
269
|
+
)
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
function EnabledStatus({ enabled }: { enabled: boolean }) {
|
|
273
|
+
const t = useT()
|
|
274
|
+
return (
|
|
275
|
+
<span className="ml-auto flex shrink-0 items-center gap-1.5 text-[11px] leading-5 text-muted-foreground">
|
|
276
|
+
<span aria-hidden className={cn('size-1.5 rounded-full', enabled ? 'bg-emerald-500' : 'bg-muted-foreground/40')} />
|
|
277
|
+
{t(enabled ? 'sandbox.env.enabled' : 'sandbox.env.disabled')}
|
|
278
|
+
</span>
|
|
279
|
+
)
|
|
280
|
+
}
|
package/client/i18n.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { useLocale, useTranslate, type Translate } from '@chatluna/ui-client/client'
|
|
3
|
+
|
|
4
|
+
export const LOCALE_NS = 'onebot-sandbox'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 宿主按命名空间缓存 `t`,切换语言后引用不变,依赖它的 `useMemo`/`useCallback` 不会重算,
|
|
8
|
+
* 缓存下来的文案停在旧语言。这里按语言快照换一个新引用,把 `t` 写进依赖即可跟随切换。
|
|
9
|
+
*/
|
|
10
|
+
export function useT(): Translate {
|
|
11
|
+
const locale = useLocale()
|
|
12
|
+
const translate = useTranslate(LOCALE_NS)
|
|
13
|
+
return React.useMemo<Translate>(() => (key, params) => translate(key, params), [translate, locale])
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 记录来源的显示名:主环境的名字由服务端写成中文,按当前语言替换;测试空间用用户起的名字。 */
|
|
17
|
+
export function sourceName(t: Translate, source: { type: string, name: string }): string {
|
|
18
|
+
return source.type === 'main' ? t('sandbox.source.main') : source.name
|
|
19
|
+
}
|
package/client/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context } from 'cordis'
|
|
2
|
+
import zh from './locales/zh.yml'
|
|
3
|
+
import en from './locales/en.yml'
|
|
4
|
+
|
|
5
|
+
export default function apply(ctx: Context) {
|
|
6
|
+
ctx.locale.register('onebot-sandbox', { zh, en })
|
|
7
|
+
const t = ctx.locale.bind('onebot-sandbox')
|
|
8
|
+
ctx.slots.route({
|
|
9
|
+
path: '/onebot-sandbox/:view?',
|
|
10
|
+
page: async () => (await import('./app')).SandboxApp,
|
|
11
|
+
title: () => t('onebot-sandbox.title'),
|
|
12
|
+
icon: 'flask-conical',
|
|
13
|
+
order: 60,
|
|
14
|
+
group: 'chat',
|
|
15
|
+
groupOrder: 20,
|
|
16
|
+
})
|
|
17
|
+
}
|