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,442 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { CheckIcon, PencilIcon, PlusIcon, SearchIcon, XIcon } from 'lucide-react'
|
|
3
|
+
import {
|
|
4
|
+
Badge,
|
|
5
|
+
Button,
|
|
6
|
+
Checkbox,
|
|
7
|
+
cn,
|
|
8
|
+
Dialog,
|
|
9
|
+
DialogContent,
|
|
10
|
+
DialogDescription,
|
|
11
|
+
DialogFooter,
|
|
12
|
+
DialogHeader,
|
|
13
|
+
DialogTitle,
|
|
14
|
+
Input,
|
|
15
|
+
Label,
|
|
16
|
+
Select,
|
|
17
|
+
SelectContent,
|
|
18
|
+
SelectItem,
|
|
19
|
+
SelectTrigger,
|
|
20
|
+
SelectValue,
|
|
21
|
+
Switch,
|
|
22
|
+
} from '@chatluna/ui-kit'
|
|
23
|
+
import { getOneBotProfileBaseline } from '../../src/onebot-profiles'
|
|
24
|
+
import {
|
|
25
|
+
getSandboxBots,
|
|
26
|
+
getSandboxUsers,
|
|
27
|
+
type ManageSandboxEnvironmentInput,
|
|
28
|
+
type SandboxAccountSex,
|
|
29
|
+
type SandboxGroupMember,
|
|
30
|
+
type SandboxImplementationProfile,
|
|
31
|
+
} from '../../src/types'
|
|
32
|
+
import { useT } from '../i18n'
|
|
33
|
+
import { SandboxAvatar } from '../shared/avatar'
|
|
34
|
+
import { useDiscardConfirm } from '../shared/discard-confirm'
|
|
35
|
+
import { OverlayScrollbar } from '../shared/overlay-scrollbar'
|
|
36
|
+
import { useSandbox, useWorkspace } from '../workspace/context'
|
|
37
|
+
import { errorText } from '../workspace/store'
|
|
38
|
+
import { AvatarChoices } from './avatar-picker'
|
|
39
|
+
import { ImplementationSelect } from './create-popover'
|
|
40
|
+
import './entity-dialog.css'
|
|
41
|
+
|
|
42
|
+
export interface EntityDialogTarget {
|
|
43
|
+
type: 'user' | 'bot' | 'group'
|
|
44
|
+
id: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Draft {
|
|
48
|
+
id: string
|
|
49
|
+
name: string
|
|
50
|
+
avatar: string
|
|
51
|
+
personalNote: string
|
|
52
|
+
sex: 'unset' | SandboxAccountSex
|
|
53
|
+
implementation: SandboxImplementationProfile
|
|
54
|
+
enabled: boolean
|
|
55
|
+
disabledCapabilities: string[]
|
|
56
|
+
members: SandboxGroupMember[]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const EMPTY_DRAFT: Draft = {
|
|
60
|
+
id: '', name: '', avatar: '', personalNote: '', sex: 'unset', implementation: 'napcat', enabled: true, disabledCapabilities: [], members: [],
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 编辑或删除一个用户、机器人或群组。ID 创建后不可修改;删除会连带清理相关会话与关系。 */
|
|
64
|
+
export function EntityDialog({ open, mode, target, onOpenChange }: {
|
|
65
|
+
open: boolean
|
|
66
|
+
mode: 'edit' | 'delete'
|
|
67
|
+
target?: EntityDialogTarget
|
|
68
|
+
onOpenChange(open: boolean): void
|
|
69
|
+
}) {
|
|
70
|
+
const t = useT()
|
|
71
|
+
const { store } = useSandbox()
|
|
72
|
+
const { snapshot, resolveAvatar } = useWorkspace()
|
|
73
|
+
const [draft, setDraft] = React.useState<Draft>(EMPTY_DRAFT)
|
|
74
|
+
// 打开时的草稿,与当前草稿比较得出是否有未保存修改。
|
|
75
|
+
const [initial, setInitial] = React.useState<Draft>(EMPTY_DRAFT)
|
|
76
|
+
const [busy, setBusy] = React.useState(false)
|
|
77
|
+
const [error, setError] = React.useState('')
|
|
78
|
+
const [picking, setPicking] = React.useState(false)
|
|
79
|
+
const [capabilitySearch, setCapabilitySearch] = React.useState('')
|
|
80
|
+
const [editingMemberId, setEditingMemberId] = React.useState('')
|
|
81
|
+
const scroller = React.useRef<HTMLDivElement>(null)
|
|
82
|
+
const capabilityScroller = React.useRef<HTMLDivElement>(null)
|
|
83
|
+
const users = getSandboxUsers(snapshot)
|
|
84
|
+
const bots = getSandboxBots(snapshot)
|
|
85
|
+
const participants = [
|
|
86
|
+
...users.map((user) => ({ ...user, type: 'user' as const })),
|
|
87
|
+
...bots.map((bot) => ({ ...bot, type: 'bot' as const })),
|
|
88
|
+
]
|
|
89
|
+
const entity = target?.type === 'group'
|
|
90
|
+
? snapshot.groups.find(({ id }) => id === target.id)
|
|
91
|
+
: snapshot.participants.find(({ id }) => id === target?.id)
|
|
92
|
+
|
|
93
|
+
const reset = (next: Draft) => {
|
|
94
|
+
setDraft(next)
|
|
95
|
+
setInitial(next)
|
|
96
|
+
}
|
|
97
|
+
const dirty = mode === 'edit' && JSON.stringify(draft) !== JSON.stringify(initial)
|
|
98
|
+
const { requestClose, confirm } = useDiscardConfirm(dirty, () => onOpenChange(false))
|
|
99
|
+
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
if (!open || !target) return
|
|
102
|
+
setError('')
|
|
103
|
+
setPicking(false)
|
|
104
|
+
setCapabilitySearch('')
|
|
105
|
+
setEditingMemberId('')
|
|
106
|
+
if (target.type === 'group') {
|
|
107
|
+
const group = snapshot.groups.find(({ id }) => id === target.id)
|
|
108
|
+
if (group) reset({ ...EMPTY_DRAFT, id: group.id, name: group.name, avatar: group.avatar ?? '', members: group.members.map((member) => ({ ...member })) })
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
const participant = snapshot.participants.find(({ id }) => id === target.id)
|
|
112
|
+
if (!participant) return
|
|
113
|
+
reset({
|
|
114
|
+
...EMPTY_DRAFT,
|
|
115
|
+
id: participant.id,
|
|
116
|
+
name: participant.name,
|
|
117
|
+
avatar: participant.avatar ?? '',
|
|
118
|
+
personalNote: participant.profile?.personalNote ?? '',
|
|
119
|
+
sex: participant.profile?.sex ?? 'unset',
|
|
120
|
+
...(participant.kind === 'bot' ? {
|
|
121
|
+
implementation: participant.implementation,
|
|
122
|
+
enabled: participant.enabled,
|
|
123
|
+
disabledCapabilities: participant.disabledCapabilities ?? [],
|
|
124
|
+
} : {}),
|
|
125
|
+
})
|
|
126
|
+
// 打开时取一次快照作为草稿;编辑期间的场景刷新不覆盖用户正在输入的内容。
|
|
127
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
128
|
+
}, [open, target?.type, target?.id])
|
|
129
|
+
|
|
130
|
+
const runAction = async (input: ManageSandboxEnvironmentInput) => {
|
|
131
|
+
if (busy) return
|
|
132
|
+
setBusy(true)
|
|
133
|
+
setError('')
|
|
134
|
+
try {
|
|
135
|
+
await store.manageEnvironment(input)
|
|
136
|
+
onOpenChange(false)
|
|
137
|
+
} catch (failure) {
|
|
138
|
+
setError(errorText(failure, t('sandbox.entity.failed')))
|
|
139
|
+
} finally {
|
|
140
|
+
setBusy(false)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const accountProfile = () => {
|
|
145
|
+
const profile = {
|
|
146
|
+
...(draft.personalNote.trim() ? { personalNote: draft.personalNote.trim() } : {}),
|
|
147
|
+
...(draft.sex !== 'unset' ? { sex: draft.sex } : {}),
|
|
148
|
+
}
|
|
149
|
+
return Object.keys(profile).length ? profile : undefined
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const submitEdit = (event: React.FormEvent) => {
|
|
153
|
+
event.preventDefault()
|
|
154
|
+
if (target?.type === 'user') {
|
|
155
|
+
void runAction({ action: 'update-user', data: { id: draft.id, name: draft.name, avatar: draft.avatar, profile: accountProfile() } })
|
|
156
|
+
} else if (target?.type === 'bot') {
|
|
157
|
+
void runAction({
|
|
158
|
+
action: 'update-bot',
|
|
159
|
+
data: {
|
|
160
|
+
id: draft.id,
|
|
161
|
+
name: draft.name,
|
|
162
|
+
implementation: draft.implementation,
|
|
163
|
+
enabled: draft.enabled,
|
|
164
|
+
disabledCapabilities: [...draft.disabledCapabilities],
|
|
165
|
+
avatar: draft.avatar,
|
|
166
|
+
profile: accountProfile(),
|
|
167
|
+
},
|
|
168
|
+
})
|
|
169
|
+
} else if (target?.type === 'group') {
|
|
170
|
+
void runAction({ action: 'update-group', data: { id: draft.id, name: draft.name, avatar: draft.avatar, members: draft.members.map((member) => ({ ...member })) } })
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const submitDelete = () => {
|
|
175
|
+
if (!target) return
|
|
176
|
+
void runAction({ action: `delete-${target.type}`, data: { id: target.id } } as ManageSandboxEnvironmentInput)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const memberOf = (participantId: string) => draft.members.find((member) => member.participantId === participantId)
|
|
180
|
+
const toggleMember = (participantId: string) => {
|
|
181
|
+
if (memberOf(participantId)) {
|
|
182
|
+
setDraft((value) => ({ ...value, members: value.members.filter((member) => member.participantId !== participantId) }))
|
|
183
|
+
if (editingMemberId === participantId) setEditingMemberId('')
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
const participant = participants.find(({ id }) => id === participantId)
|
|
187
|
+
if (!participant) return
|
|
188
|
+
setDraft((value) => ({
|
|
189
|
+
...value,
|
|
190
|
+
members: [...value.members, { participantId, card: participant.name, role: value.members.some(({ role }) => role === 'owner') ? 'member' : 'owner' }],
|
|
191
|
+
}))
|
|
192
|
+
}
|
|
193
|
+
const patchMember = (participantId: string, patch: Partial<SandboxGroupMember>) => setDraft((value) => ({
|
|
194
|
+
...value,
|
|
195
|
+
members: value.members.map((member) => member.participantId === participantId ? { ...member, ...patch } : member),
|
|
196
|
+
}))
|
|
197
|
+
|
|
198
|
+
const baseline = getOneBotProfileBaseline(draft.implementation)
|
|
199
|
+
const query = capabilitySearch.trim().toLowerCase()
|
|
200
|
+
const capabilities = query
|
|
201
|
+
? baseline.capabilities.filter((capability) => [capability.id, capability.action, capability.description, capability.reason, ...(capability.aliases ?? [])]
|
|
202
|
+
.some((value) => value?.toLowerCase().includes(query)))
|
|
203
|
+
: baseline.capabilities
|
|
204
|
+
const supportedCapabilityCount = baseline.capabilities.filter(({ supported }) => supported).length
|
|
205
|
+
const enabledCapabilityCount = baseline.capabilities.filter(({ id, supported }) => supported && !draft.disabledCapabilities.includes(id)).length
|
|
206
|
+
const type = target?.type ?? 'user'
|
|
207
|
+
const entityLabel = t(`sandbox.kind.${type}`)
|
|
208
|
+
const editingParticipant = participants.find(({ id }) => id === editingMemberId)
|
|
209
|
+
const editingMember = memberOf(editingMemberId)
|
|
210
|
+
const roleItems = [
|
|
211
|
+
{ value: 'owner', label: t('sandbox.role.owner') },
|
|
212
|
+
{ value: 'admin', label: t('sandbox.role.admin') },
|
|
213
|
+
{ value: 'member', label: t('sandbox.role.member') },
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<Dialog open={open} onOpenChange={(next) => next ? onOpenChange(true) : requestClose()}>
|
|
218
|
+
<DialogContent className={cn('flex flex-col overflow-hidden', mode === 'edit' && 'sm:max-w-lg')}>
|
|
219
|
+
<DialogHeader>
|
|
220
|
+
<DialogTitle>{t(mode === 'edit' ? 'sandbox.entity.editTitle' : 'sandbox.entity.deleteTitle', { kind: entityLabel })}</DialogTitle>
|
|
221
|
+
<DialogDescription>{t(mode === 'edit' ? 'sandbox.entity.editHint' : 'sandbox.entity.deleteHint')}</DialogDescription>
|
|
222
|
+
</DialogHeader>
|
|
223
|
+
{mode === 'delete' ? (
|
|
224
|
+
<>
|
|
225
|
+
<div className="flex flex-col gap-4">
|
|
226
|
+
<p className="text-[13px] leading-6">
|
|
227
|
+
{t(target?.type === 'user' ? 'sandbox.entity.deleteUser' : 'sandbox.entity.deleteOther', { kind: entityLabel, name: entity?.name ?? target?.id ?? '' })}
|
|
228
|
+
</p>
|
|
229
|
+
{error && <p role="alert" className="text-xs text-destructive">{error}</p>}
|
|
230
|
+
</div>
|
|
231
|
+
<DialogFooter>
|
|
232
|
+
<Button variant="outline" onClick={() => onOpenChange(false)}>{t('sandbox.common.cancel')}</Button>
|
|
233
|
+
<Button variant="destructive" disabled={busy} onClick={submitDelete}>{busy ? t('sandbox.entity.deleting') : t('sandbox.entity.confirmDelete')}</Button>
|
|
234
|
+
</DialogFooter>
|
|
235
|
+
</>
|
|
236
|
+
) : (
|
|
237
|
+
// 三段式:页头与页脚固定,只有正文滚动;视口很矮时正文先收缩,不会滚到透明的毛玻璃页头下面。
|
|
238
|
+
<form className="flex min-h-0 flex-col gap-4" onSubmit={submitEdit}>
|
|
239
|
+
<div className="sandbox-entity-body">
|
|
240
|
+
<div ref={scroller} className="sandbox-entity-scroller">
|
|
241
|
+
<div className="sandbox-entity-hero">
|
|
242
|
+
<button type="button" className="sandbox-entity-avatar" aria-label={t('sandbox.avatar.change')} onClick={() => setPicking(true)}>
|
|
243
|
+
<SandboxAvatar kind={type} name={draft.name} src={resolveAvatar(draft.avatar)} className="sandbox-entity-avatar-image" badge={false} />
|
|
244
|
+
<span className="sandbox-entity-avatar-edit" aria-hidden><PencilIcon /></span>
|
|
245
|
+
</button>
|
|
246
|
+
<div className="sandbox-entity-identity">
|
|
247
|
+
<strong className={cn('sandbox-entity-name', !draft.name.trim() && 'is-empty')}>{draft.name.trim() || t(`sandbox.field.name.${type}`)}</strong>
|
|
248
|
+
<span className="sandbox-entity-id">{type === 'group' ? t('sandbox.field.groupId') : t('sandbox.field.qqId')} {draft.id}</span>
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
<section className="sandbox-entity-section">
|
|
252
|
+
<h3 className="sandbox-entity-section-title">{t('sandbox.entity.section.basic')}</h3>
|
|
253
|
+
<div className="sandbox-entity-grid">
|
|
254
|
+
<div className={cn('sandbox-entity-field', type === 'group' && 'is-wide')}>
|
|
255
|
+
<Label htmlFor="sandbox-entity-name">{t(`sandbox.field.name.${type}`)}</Label>
|
|
256
|
+
<Input id="sandbox-entity-name" required value={draft.name} onChange={(event) => setDraft((value) => ({ ...value, name: event.target.value }))} />
|
|
257
|
+
</div>
|
|
258
|
+
{type !== 'group' && (
|
|
259
|
+
<>
|
|
260
|
+
<div className="sandbox-entity-field">
|
|
261
|
+
<Label>{t('sandbox.field.sex')}</Label>
|
|
262
|
+
<Select
|
|
263
|
+
value={draft.sex}
|
|
264
|
+
onValueChange={(value) => value && setDraft((current) => ({ ...current, sex: value === 'unset' ? 'unset' : value === 'male' ? 'male' : value === 'female' ? 'female' : 'unknown' }))}
|
|
265
|
+
items={['unset', 'unknown', 'male', 'female'].map((value) => ({ value, label: t(`sandbox.sex.${value}`) }))}
|
|
266
|
+
>
|
|
267
|
+
<SelectTrigger className="w-full"><SelectValue /></SelectTrigger>
|
|
268
|
+
<SelectContent className="sandbox-glass">
|
|
269
|
+
{['unset', 'unknown', 'male', 'female'].map((value) => <SelectItem key={value} value={value}>{t(`sandbox.sex.${value}`)}</SelectItem>)}
|
|
270
|
+
</SelectContent>
|
|
271
|
+
</Select>
|
|
272
|
+
</div>
|
|
273
|
+
<div className="sandbox-entity-field is-wide">
|
|
274
|
+
<Label htmlFor="sandbox-entity-note">{t('sandbox.field.personalNote')}</Label>
|
|
275
|
+
<Input
|
|
276
|
+
id="sandbox-entity-note"
|
|
277
|
+
placeholder={t('sandbox.field.personalNotePlaceholder')}
|
|
278
|
+
value={draft.personalNote}
|
|
279
|
+
onChange={(event) => setDraft((value) => ({ ...value, personalNote: event.target.value }))}
|
|
280
|
+
/>
|
|
281
|
+
</div>
|
|
282
|
+
</>
|
|
283
|
+
)}
|
|
284
|
+
</div>
|
|
285
|
+
</section>
|
|
286
|
+
{type === 'bot' && (
|
|
287
|
+
<section className="sandbox-entity-section">
|
|
288
|
+
<h3 className="sandbox-entity-section-title">{t('sandbox.entity.section.runtime')}</h3>
|
|
289
|
+
<label className="sandbox-entity-toggle">
|
|
290
|
+
<span>{t('sandbox.field.botEnabled')}</span>
|
|
291
|
+
<Switch checked={draft.enabled} onCheckedChange={(value) => setDraft((current) => ({ ...current, enabled: value === true }))} />
|
|
292
|
+
</label>
|
|
293
|
+
<ImplementationSelect value={draft.implementation} onChange={(implementation) => setDraft((value) => ({ ...value, implementation }))} />
|
|
294
|
+
<div className="sandbox-entity-field">
|
|
295
|
+
<div className="sandbox-entity-section-title">
|
|
296
|
+
<Label>{t('sandbox.entity.capabilities')}</Label>
|
|
297
|
+
<span className="sandbox-entity-section-meta">{t('sandbox.entity.capabilityCount', { enabled: enabledCapabilityCount, total: supportedCapabilityCount })}</span>
|
|
298
|
+
</div>
|
|
299
|
+
<div className="relative">
|
|
300
|
+
<SearchIcon className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
|
301
|
+
<Input type="search" className="sandbox-search-input pl-8!" value={capabilitySearch} placeholder={t('sandbox.entity.capabilitySearch')} aria-label={t('sandbox.entity.capabilitySearch')} onChange={(event) => setCapabilitySearch(event.target.value)} />
|
|
302
|
+
</div>
|
|
303
|
+
<div className="sandbox-entity-capabilities">
|
|
304
|
+
<div ref={capabilityScroller} className="sandbox-entity-capability-list">
|
|
305
|
+
{capabilities.map((capability) => (
|
|
306
|
+
<label key={capability.id} className={cn('sandbox-entity-capability', !capability.supported && 'is-unsupported')}>
|
|
307
|
+
<Checkbox
|
|
308
|
+
className="mt-0.5"
|
|
309
|
+
checked={capability.supported && !draft.disabledCapabilities.includes(capability.id)}
|
|
310
|
+
disabled={!capability.supported}
|
|
311
|
+
onCheckedChange={(checked) => setDraft((value) => ({
|
|
312
|
+
...value,
|
|
313
|
+
disabledCapabilities: checked === true
|
|
314
|
+
? value.disabledCapabilities.filter((id) => id !== capability.id)
|
|
315
|
+
: [...new Set([...value.disabledCapabilities, capability.id])],
|
|
316
|
+
}))}
|
|
317
|
+
/>
|
|
318
|
+
<span className="sandbox-entity-capability-text">
|
|
319
|
+
<span className="sandbox-entity-capability-action">
|
|
320
|
+
{capability.action}
|
|
321
|
+
<Badge variant="secondary" className="text-[10px]">{t(capability.surface === 'standard' ? 'sandbox.entity.standard' : 'sandbox.entity.native')}</Badge>
|
|
322
|
+
</span>
|
|
323
|
+
<span className="sandbox-entity-capability-description">{capability.description}</span>
|
|
324
|
+
{(capability.aliases?.length || !capability.supported) && (
|
|
325
|
+
<small className="sandbox-entity-capability-note">
|
|
326
|
+
{capability.aliases?.length ? t('sandbox.entity.aliases', { aliases: capability.aliases.join('、') }) : ''}
|
|
327
|
+
{capability.aliases?.length && !capability.supported ? ' · ' : ''}
|
|
328
|
+
{!capability.supported ? capability.reason : ''}
|
|
329
|
+
</small>
|
|
330
|
+
)}
|
|
331
|
+
</span>
|
|
332
|
+
</label>
|
|
333
|
+
))}
|
|
334
|
+
{!capabilities.length && <p className="sandbox-entity-empty">{t('sandbox.entity.noCapability')}</p>}
|
|
335
|
+
</div>
|
|
336
|
+
<OverlayScrollbar target={capabilityScroller} className="sandbox-entity-capability-scrollbar" />
|
|
337
|
+
</div>
|
|
338
|
+
</div>
|
|
339
|
+
</section>
|
|
340
|
+
)}
|
|
341
|
+
{type === 'group' && (
|
|
342
|
+
<section className="sandbox-entity-section">
|
|
343
|
+
<h3 className="sandbox-entity-section-title">
|
|
344
|
+
<span>{t('sandbox.entity.members')}</span>
|
|
345
|
+
<span className="sandbox-entity-section-meta">{draft.members.length} / {participants.length}</span>
|
|
346
|
+
</h3>
|
|
347
|
+
<p className="sandbox-entity-hint">{t('sandbox.entity.membersHint')}</p>
|
|
348
|
+
<div className="sandbox-entity-members">
|
|
349
|
+
{participants.map((participant) => {
|
|
350
|
+
const member = memberOf(participant.id)
|
|
351
|
+
return (
|
|
352
|
+
<article key={participant.id} className={cn('sandbox-entity-member', member && 'is-member', editingMemberId === participant.id && 'is-editing')}>
|
|
353
|
+
<button
|
|
354
|
+
type="button"
|
|
355
|
+
className="sandbox-entity-member-toggle"
|
|
356
|
+
aria-pressed={!!member}
|
|
357
|
+
aria-label={t(member ? 'sandbox.entity.removeMember' : 'sandbox.entity.addMember', { name: participant.name, id: participant.id })}
|
|
358
|
+
onClick={() => toggleMember(participant.id)}
|
|
359
|
+
>
|
|
360
|
+
<span className="sandbox-entity-member-avatar">
|
|
361
|
+
<SandboxAvatar kind={participant.type} name={participant.name} src={resolveAvatar(participant.avatar)} className="size-8" />
|
|
362
|
+
<span className="sandbox-entity-member-marker" aria-hidden>{member ? <CheckIcon /> : <PlusIcon />}</span>
|
|
363
|
+
</span>
|
|
364
|
+
<span className="sandbox-entity-member-text">
|
|
365
|
+
<strong>{participant.name}</strong>
|
|
366
|
+
<small>{member ? `${member.card || t('sandbox.entity.noCard')} · ${t(`sandbox.role.${member.role}`)}` : participant.id}</small>
|
|
367
|
+
</span>
|
|
368
|
+
</button>
|
|
369
|
+
{member && (
|
|
370
|
+
<Button type="button" variant="ghost" size="icon-xs" aria-label={t('sandbox.entity.editMember', { name: participant.name })} onClick={() => setEditingMemberId(participant.id)}>
|
|
371
|
+
<PencilIcon />
|
|
372
|
+
</Button>
|
|
373
|
+
)}
|
|
374
|
+
</article>
|
|
375
|
+
)
|
|
376
|
+
})}
|
|
377
|
+
</div>
|
|
378
|
+
{editingParticipant && editingMember && (
|
|
379
|
+
<div className="sandbox-entity-member-editor">
|
|
380
|
+
<div className="sandbox-entity-member-editor-head">
|
|
381
|
+
<SandboxAvatar kind={editingParticipant.type} name={editingParticipant.name} src={resolveAvatar(editingParticipant.avatar)} className="size-7" />
|
|
382
|
+
<span className="sandbox-entity-member-text flex-1">
|
|
383
|
+
<strong>{editingParticipant.name}</strong>
|
|
384
|
+
<small>{editingParticipant.id}</small>
|
|
385
|
+
</span>
|
|
386
|
+
<Button type="button" variant="ghost" size="icon-xs" aria-label={t('sandbox.common.close')} onClick={() => setEditingMemberId('')}><XIcon /></Button>
|
|
387
|
+
</div>
|
|
388
|
+
<div className="sandbox-entity-grid">
|
|
389
|
+
<div className="sandbox-entity-field">
|
|
390
|
+
<Label>{t('sandbox.entity.card')}</Label>
|
|
391
|
+
<Input value={editingMember.card ?? ''} onChange={(event) => patchMember(editingParticipant.id, { card: event.target.value })} />
|
|
392
|
+
</div>
|
|
393
|
+
<div className="sandbox-entity-field">
|
|
394
|
+
<Label>{t('sandbox.entity.role')}</Label>
|
|
395
|
+
<Select
|
|
396
|
+
value={editingMember.role}
|
|
397
|
+
onValueChange={(value) => value && patchMember(editingParticipant.id, { role: value === 'owner' ? 'owner' : value === 'admin' ? 'admin' : 'member' })}
|
|
398
|
+
items={roleItems}
|
|
399
|
+
>
|
|
400
|
+
<SelectTrigger className="w-full"><SelectValue /></SelectTrigger>
|
|
401
|
+
<SelectContent className="sandbox-glass">
|
|
402
|
+
{roleItems.map(({ value, label }) => <SelectItem key={value} value={value}>{label}</SelectItem>)}
|
|
403
|
+
</SelectContent>
|
|
404
|
+
</Select>
|
|
405
|
+
</div>
|
|
406
|
+
</div>
|
|
407
|
+
</div>
|
|
408
|
+
)}
|
|
409
|
+
{!draft.members.length && <p className="text-xs text-destructive">{t('sandbox.entity.needOwner')}</p>}
|
|
410
|
+
</section>
|
|
411
|
+
)}
|
|
412
|
+
{error && <p role="alert" className="text-xs text-destructive">{error}</p>}
|
|
413
|
+
</div>
|
|
414
|
+
<OverlayScrollbar target={scroller} className="sandbox-entity-scrollbar" />
|
|
415
|
+
</div>
|
|
416
|
+
<DialogFooter>
|
|
417
|
+
<Button type="button" variant="outline" onClick={requestClose}>{t('sandbox.common.cancel')}</Button>
|
|
418
|
+
<Button type="submit" disabled={busy}>{busy ? t('sandbox.common.saving') : t('sandbox.common.save')}</Button>
|
|
419
|
+
</DialogFooter>
|
|
420
|
+
</form>
|
|
421
|
+
)}
|
|
422
|
+
{target && (
|
|
423
|
+
<Dialog open={picking} onOpenChange={setPicking}>
|
|
424
|
+
<DialogContent className="flex flex-col overflow-hidden sm:max-w-md">
|
|
425
|
+
<DialogHeader>
|
|
426
|
+
<DialogTitle>{t('sandbox.avatar.title')}</DialogTitle>
|
|
427
|
+
<DialogDescription>{t('sandbox.avatar.description')}</DialogDescription>
|
|
428
|
+
</DialogHeader>
|
|
429
|
+
<div className="-mx-5 min-h-0 overflow-y-auto px-5">
|
|
430
|
+
<AvatarChoices kind={target.type} onSelect={(avatar) => {
|
|
431
|
+
setDraft((value) => ({ ...value, avatar }))
|
|
432
|
+
setPicking(false)
|
|
433
|
+
}} />
|
|
434
|
+
</div>
|
|
435
|
+
</DialogContent>
|
|
436
|
+
</Dialog>
|
|
437
|
+
)}
|
|
438
|
+
{confirm}
|
|
439
|
+
</DialogContent>
|
|
440
|
+
</Dialog>
|
|
441
|
+
)
|
|
442
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 环境管理页(environment/page.tsx)。只按 sandbox-env- 类名选择;本文件不分层。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* 原生滚动条隐藏,由 .sandbox-env-scrollbar 自绘(SCROLLBAR.md)。 */
|
|
6
|
+
.sandbox-env-scroller {
|
|
7
|
+
scrollbar-width: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* 轨道上端紧贴面板标题栏下方,下端让出面板的 12px 圆角。 */
|
|
11
|
+
.sandbox-env-scrollbar {
|
|
12
|
+
top: 4px;
|
|
13
|
+
bottom: 12px;
|
|
14
|
+
}
|