chatluna-plugin-onebot-sandbox 1.0.2 → 1.1.5

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.
Files changed (68) hide show
  1. package/README.md +1 -0
  2. package/client/chat/composer.tsx +8 -3
  3. package/client/chat/message-list.tsx +6 -0
  4. package/client/environment/avatar-picker.tsx +2 -5
  5. package/client/environment/entity-dialog.css +9 -0
  6. package/client/environment/entity-dialog.tsx +113 -6
  7. package/client/locales/en.yml +18 -0
  8. package/client/locales/zh.yml +18 -0
  9. package/client/settings/localize.ts +2 -2
  10. package/client/settings/page.tsx +2 -2
  11. package/client/workspace/media-cache.ts +38 -0
  12. package/client/workspace/store.ts +57 -21
  13. package/dist/.vite/manifest.json +1 -1
  14. package/dist/app-CpJLSY0S.js +85 -0
  15. package/dist/client.css +1 -1
  16. package/dist/client.js +1 -1
  17. package/lib/bot.d.ts +4 -1
  18. package/lib/bot.d.ts.map +1 -1
  19. package/lib/builtin-avatar-options.d.ts.map +1 -1
  20. package/lib/builtin-avatar-png.d.ts +15 -0
  21. package/lib/builtin-avatar-png.d.ts.map +1 -0
  22. package/lib/builtin-avatars.d.ts +1 -1
  23. package/lib/builtin-avatars.d.ts.map +1 -1
  24. package/lib/channel-assignee.d.ts +4 -3
  25. package/lib/channel-assignee.d.ts.map +1 -1
  26. package/lib/chatluna/conversation-lines.d.ts +41 -27
  27. package/lib/chatluna/conversation-lines.d.ts.map +1 -1
  28. package/lib/chatluna/model-calls.d.ts +68 -0
  29. package/lib/chatluna/model-calls.d.ts.map +1 -0
  30. package/lib/chatluna/presets.d.ts +142 -0
  31. package/lib/chatluna/presets.d.ts.map +1 -0
  32. package/lib/chatluna/runtime.d.ts +14 -0
  33. package/lib/chatluna/runtime.d.ts.map +1 -1
  34. package/lib/chatluna/state.d.ts +13 -4
  35. package/lib/chatluna/state.d.ts.map +1 -1
  36. package/lib/chatluna/user-permissions.d.ts +15 -0
  37. package/lib/chatluna/user-permissions.d.ts.map +1 -0
  38. package/lib/chatluna/wakeup.d.ts +2 -2
  39. package/lib/chatluna/wakeup.d.ts.map +1 -1
  40. package/lib/console-contract.d.ts +21 -1
  41. package/lib/console-contract.d.ts.map +1 -1
  42. package/lib/console.d.ts +2 -1
  43. package/lib/console.d.ts.map +1 -1
  44. package/lib/control-service.d.ts +16 -6
  45. package/lib/control-service.d.ts.map +1 -1
  46. package/lib/conversation-resolution.d.ts +17 -0
  47. package/lib/conversation-resolution.d.ts.map +1 -1
  48. package/lib/inbound-delivery.d.ts +17 -8
  49. package/lib/inbound-delivery.d.ts.map +1 -1
  50. package/lib/index.d.ts +5 -0
  51. package/lib/index.d.ts.map +1 -1
  52. package/lib/index.js +1628 -294
  53. package/lib/index.js.map +1 -1
  54. package/lib/mcp/http-api.d.ts.map +1 -1
  55. package/lib/mcp/service.d.ts +14 -1
  56. package/lib/mcp/service.d.ts.map +1 -1
  57. package/lib/mcp/tool-registry.d.ts +7 -0
  58. package/lib/mcp/tool-registry.d.ts.map +1 -1
  59. package/lib/onebot-profiles.d.ts +8 -0
  60. package/lib/onebot-profiles.d.ts.map +1 -1
  61. package/lib/test-spaces.d.ts.map +1 -1
  62. package/lib/types.d.ts +7 -1
  63. package/lib/types.d.ts.map +1 -1
  64. package/lib/user-authority.d.ts +6 -0
  65. package/lib/user-authority.d.ts.map +1 -0
  66. package/lib/webui.d.ts.map +1 -1
  67. package/package.json +10 -2
  68. package/dist/app-bHKIhF6g.js +0 -85
package/README.md CHANGED
@@ -12,6 +12,7 @@ ChatLuna v2 插件:在 WebUI 中模拟 QQ(OneBot v11)环境,不接入真
12
12
  - **AI 测试空间**:相互隔离的独立场景,可供 AI 通过 MCP 自行操作与观察。
13
13
  - **测试端点**:提供 MCP 与 HTTP 两种接口,带凭证与调用配额,供自动化脚本驱动沙盒;默认关闭。
14
14
  - **回复出处**:机器人的回复可跳转到 ChatLuna 的 trace 页,查看对应的模型请求。
15
+ - **模型调用与测试预设**:测试端点可读取机器人每一步模型调用的请求与响应,新建与修改测试用预设,并把沙盒机器人切换到指定预设;已有预设只有在设置中列为可编辑的才能修改。
15
16
 
16
17
  ## 安装
17
18
 
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react'
2
2
  import { createLayout, type AutoLayout } from 'animejs'
3
- import { FileIcon, PaperclipIcon, PencilIcon, PlusIcon, SendIcon, Trash2Icon, XIcon } from 'lucide-react'
3
+ import { FileIcon, IdCardIcon, PaperclipIcon, PencilIcon, PlusIcon, SendIcon, Trash2Icon, XIcon } from 'lucide-react'
4
4
  import {
5
5
  cn,
6
6
  ContextMenu,
@@ -386,8 +386,10 @@ export const Composer = React.forwardRef<ComposerHandle, {
386
386
  setCompactStack(element.clientWidth < fullWidth + COMPOSER_FIXED_WIDTH + COMPOSER_MIN_INPUT_WIDTH)
387
387
  // 回复与附件共用一个浮动包络,消息区底部留白按包络真实高度计算。28 = 胶囊距底 20px + 置底时
388
388
  // 末条消息与输入区的可视间隙 8px;包络与胶囊之间的 8px 已计入包络高度。
389
- const formHeight = Math.ceil(element.getBoundingClientRect().height)
390
- const overlay = context.current ? Math.ceil(context.current.getBoundingClientRect().height) + 8 : 0
389
+ // 量布局高度(offsetHeight)而不是 getBoundingClientRect:进出测试空间的缩放动画期间工作区带 scale,
390
+ // 量到的是缩小后的高度,动画结束时布局尺寸不变、ResizeObserver 不再触发,留白就一直偏小。
391
+ const formHeight = element.offsetHeight
392
+ const overlay = context.current ? context.current.offsetHeight + 8 : 0
391
393
  onSpaceChange?.(formHeight + overlay + 28)
392
394
  }
393
395
  const observer = new ResizeObserver(update)
@@ -515,6 +517,9 @@ export const Composer = React.forwardRef<ComposerHandle, {
515
517
  <SandboxAvatar kind={sender.kind} name={sender.name} src={sender.avatar} badge={false} className="sandbox-composer-user-avatar" />
516
518
  </ContextMenuTrigger>
517
519
  <ContextMenuContent className="sandbox-glass">
520
+ <ContextMenuItem onClick={() => dialogs.openProfile(sender.id)}>
521
+ <IdCardIcon />{t('sandbox.menu.profile')}
522
+ </ContextMenuItem>
518
523
  <ContextMenuItem onClick={() => dialogs.openEntity('edit', { type: sender.kind, id: sender.id })}>
519
524
  <PencilIcon />{t('sandbox.menu.editEntity', { kind: t(`sandbox.kind.${sender.kind}`) })}<ExtensionMark />
520
525
  </ContextMenuItem>
@@ -14,6 +14,7 @@ import {
14
14
  IdCardIcon,
15
15
  ListChecksIcon,
16
16
  PaperclipIcon,
17
+ PencilIcon,
17
18
  ReplyIcon,
18
19
  SmilePlusIcon,
19
20
  TagIcon,
@@ -357,6 +358,11 @@ export const MessageList = React.forwardRef<MessageListHandle, MessageListProps>
357
358
  </ContextMenuTrigger>
358
359
  <ContextMenuContent className="sandbox-glass">
359
360
  <ContextMenuItem onClick={() => dialogs.openProfile(message.authorId)}><IdCardIcon />{t('sandbox.menu.profile')}</ContextMenuItem>
361
+ {participants[message.authorId] && (
362
+ <ContextMenuItem onClick={() => dialogs.openEntity('edit', { type: isBot ? 'bot' : 'user', id: message.authorId })}>
363
+ <PencilIcon />{t('sandbox.menu.editEntity', { kind: t(isBot ? 'sandbox.kind.bot' : 'sandbox.kind.user') })}<ExtensionMark />
364
+ </ContextMenuItem>
365
+ )}
360
366
  {!outgoing && (
361
367
  <>
362
368
  {getMessageGroupMemberActions(message.authorId, presentation).includes('mention') && (
@@ -1,14 +1,11 @@
1
1
  import * as React from 'react'
2
2
  import { ArrowLeftIcon, ChevronRightIcon, UploadIcon } from 'lucide-react'
3
3
  import { Button } from '@chatluna/ui-kit'
4
- import { BUILTIN_AVATARS, type BuiltinAvatar, type BuiltinAvatarKind } from '../../src/builtin-avatar-options'
4
+ import { BUILTIN_AVATARS, type BuiltinAvatar, type BuiltinAvatarKind } from '../../src/builtin-avatar-png'
5
5
  import { useT } from '../i18n'
6
6
 
7
7
  function avatarDataUrl(avatar: BuiltinAvatar) {
8
- const bytes = new TextEncoder().encode(avatar.svg)
9
- let binary = ''
10
- for (const byte of bytes) binary += String.fromCharCode(byte)
11
- return `data:image/svg+xml;base64,${btoa(binary)}`
8
+ return `data:image/png;base64,${avatar.png}`
12
9
  }
13
10
 
14
11
  /** 头像选择:内置头像或本地图片,选定后以 Data URL 交回,服务端负责导入成受控媒体。用于浮层内原地切换的二级视图。 */
@@ -3,6 +3,11 @@
3
3
  * 本文件不分层,压过 ui-kit 在宿主 utilities 层里的工具类。
4
4
  */
5
5
 
6
+ .sandbox-entity-dialog {
7
+ font-size: 13px;
8
+ line-height: 20px;
9
+ }
10
+
6
11
  /* 正文:外层负边距贴到弹窗两侧,自绘滚动条画在弹窗内缘;上下留 2px,输入框的焦点环不被裁掉。 */
7
12
  .sandbox-entity-body {
8
13
  position: relative;
@@ -148,6 +153,10 @@
148
153
  line-height: 18px;
149
154
  }
150
155
 
156
+ .sandbox-entity-hint.is-error {
157
+ color: var(--destructive);
158
+ }
159
+
151
160
  .sandbox-entity-grid {
152
161
  display: grid;
153
162
  grid-template-columns: minmax(0, 1fr) 140px;
@@ -20,6 +20,7 @@ import {
20
20
  SelectValue,
21
21
  Switch,
22
22
  } from '@chatluna/ui-kit'
23
+ import type { SandboxBotPresetCatalog } from '../../src/console-contract'
23
24
  import { getOneBotProfileBaseline } from '../../src/onebot-profiles'
24
25
  import {
25
26
  getSandboxBots,
@@ -28,13 +29,14 @@ import {
28
29
  type SandboxAccountSex,
29
30
  type SandboxGroupMember,
30
31
  type SandboxImplementationProfile,
32
+ type SandboxUserAuthority,
31
33
  } from '../../src/types'
32
34
  import { useT } from '../i18n'
33
35
  import { SandboxAvatar } from '../shared/avatar'
34
36
  import { useDiscardConfirm } from '../shared/discard-confirm'
35
37
  import { OverlayScrollbar } from '../shared/overlay-scrollbar'
36
38
  import { useSandbox, useWorkspace } from '../workspace/context'
37
- import { errorText } from '../workspace/store'
39
+ import { errorText, invoke } from '../workspace/store'
38
40
  import { AvatarChoices } from './avatar-picker'
39
41
  import { ImplementationSelect } from './create-popover'
40
42
  import './entity-dialog.css'
@@ -50,14 +52,25 @@ interface Draft {
50
52
  avatar: string
51
53
  personalNote: string
52
54
  sex: 'unset' | SandboxAccountSex
55
+ authority: 'inherit' | SandboxUserAuthority
53
56
  implementation: SandboxImplementationProfile
54
57
  enabled: boolean
55
58
  disabledCapabilities: string[]
56
59
  members: SandboxGroupMember[]
57
60
  }
58
61
 
62
+ /** 「跟随路由规则」的选项值;预设 ID 由 v2 按文件名生成,不含冒号,不会与它撞上。 */
63
+ const FOLLOW_ROUTE = 'onebot-sandbox:follow-route'
64
+ const AUTHORITY_LEVELS = [0, 1, 2, 3, 4, 5] as const
65
+
66
+ /** 机器人的预设选项:未读取、服务未加载、读取失败或读到的目录。 */
67
+ type PresetState =
68
+ | { status: 'loading' }
69
+ | { status: 'failed'; error: string }
70
+ | { status: 'ready'; catalog: SandboxBotPresetCatalog }
71
+
59
72
  const EMPTY_DRAFT: Draft = {
60
- id: '', name: '', avatar: '', personalNote: '', sex: 'unset', implementation: 'napcat', enabled: true, disabledCapabilities: [], members: [],
73
+ id: '', name: '', avatar: '', personalNote: '', sex: 'unset', authority: 'inherit', implementation: 'napcat', enabled: true, disabledCapabilities: [], members: [],
61
74
  }
62
75
 
63
76
  /** 编辑或删除一个用户、机器人或群组。ID 创建后不可修改;删除会连带清理相关会话与关系。 */
@@ -78,6 +91,10 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
78
91
  const [picking, setPicking] = React.useState(false)
79
92
  const [capabilitySearch, setCapabilitySearch] = React.useState('')
80
93
  const [editingMemberId, setEditingMemberId] = React.useState('')
94
+ // 预设不在场景快照里,打开时另外读取,所以不进 Draft:读到之前两份都是 FOLLOW_ROUTE,选单禁用。
95
+ const [presetState, setPresetState] = React.useState<PresetState>({ status: 'loading' })
96
+ const [preset, setPreset] = React.useState(FOLLOW_ROUTE)
97
+ const [initialPreset, setInitialPreset] = React.useState(FOLLOW_ROUTE)
81
98
  const scroller = React.useRef<HTMLDivElement>(null)
82
99
  const capabilityScroller = React.useRef<HTMLDivElement>(null)
83
100
  const users = getSandboxUsers(snapshot)
@@ -94,7 +111,7 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
94
111
  setDraft(next)
95
112
  setInitial(next)
96
113
  }
97
- const dirty = mode === 'edit' && JSON.stringify(draft) !== JSON.stringify(initial)
114
+ const dirty = mode === 'edit' && (JSON.stringify(draft) !== JSON.stringify(initial) || preset !== initialPreset)
98
115
  const { requestClose, confirm } = useDiscardConfirm(dirty, () => onOpenChange(false))
99
116
 
100
117
  React.useEffect(() => {
@@ -117,6 +134,7 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
117
134
  avatar: participant.avatar ?? '',
118
135
  personalNote: participant.profile?.personalNote ?? '',
119
136
  sex: participant.profile?.sex ?? 'unset',
137
+ authority: participant.kind === 'user' ? participant.authority ?? 'inherit' : 'inherit',
120
138
  ...(participant.kind === 'bot' ? {
121
139
  implementation: participant.implementation,
122
140
  enabled: participant.enabled,
@@ -127,11 +145,32 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
127
145
  // eslint-disable-next-line react-hooks/exhaustive-deps
128
146
  }, [open, target?.type, target?.id])
129
147
 
130
- const runAction = async (input: ManageSandboxEnvironmentInput) => {
148
+ React.useEffect(() => {
149
+ setPreset(FOLLOW_ROUTE)
150
+ setInitialPreset(FOLLOW_ROUTE)
151
+ if (!open || mode !== 'edit' || target?.type !== 'bot') return
152
+ const botId = target.id
153
+ let active = true
154
+ setPresetState({ status: 'loading' })
155
+ invoke('onebot-sandbox.bot-presets', undefined).then((catalog) => {
156
+ if (!active) return
157
+ const assigned = catalog.assignments.find((assignment) => assignment.botId === botId)?.presetId ?? FOLLOW_ROUTE
158
+ setPresetState({ status: 'ready', catalog })
159
+ setPreset(assigned)
160
+ setInitialPreset(assigned)
161
+ }, (failure) => {
162
+ if (active) setPresetState({ status: 'failed', error: errorText(failure) })
163
+ })
164
+ return () => { active = false }
165
+ }, [open, mode, target?.type, target?.id])
166
+
167
+ /** `prepare` 先于环境变更执行:预设依赖外部服务,更容易失败,失败时整次保存都不落地。 */
168
+ const runAction = async (input: ManageSandboxEnvironmentInput, prepare?: () => Promise<unknown>) => {
131
169
  if (busy) return
132
170
  setBusy(true)
133
171
  setError('')
134
172
  try {
173
+ await prepare?.()
135
174
  await store.manageEnvironment(input)
136
175
  onOpenChange(false)
137
176
  } catch (failure) {
@@ -152,7 +191,13 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
152
191
  const submitEdit = (event: React.FormEvent) => {
153
192
  event.preventDefault()
154
193
  if (target?.type === 'user') {
155
- void runAction({ action: 'update-user', data: { id: draft.id, name: draft.name, avatar: draft.avatar, profile: accountProfile() } })
194
+ void runAction({
195
+ action: 'update-user',
196
+ data: {
197
+ id: draft.id, name: draft.name, avatar: draft.avatar, profile: accountProfile(),
198
+ authority: draft.authority === 'inherit' ? null : draft.authority,
199
+ },
200
+ })
156
201
  } else if (target?.type === 'bot') {
157
202
  void runAction({
158
203
  action: 'update-bot',
@@ -165,6 +210,13 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
165
210
  avatar: draft.avatar,
166
211
  profile: accountProfile(),
167
212
  },
213
+ }, preset === initialPreset ? undefined : async () => {
214
+ await invoke('onebot-sandbox.set-bot-preset', {
215
+ botId: draft.id,
216
+ presetId: preset === FOLLOW_ROUTE ? null : preset,
217
+ ...(store.spaceId ? { spaceId: store.spaceId } : {}),
218
+ })
219
+ setInitialPreset(preset)
168
220
  })
169
221
  } else if (target?.type === 'group') {
170
222
  void runAction({ action: 'update-group', data: { id: draft.id, name: draft.name, avatar: draft.avatar, members: draft.members.map((member) => ({ ...member })) } })
@@ -207,6 +259,30 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
207
259
  const entityLabel = t(`sandbox.kind.${type}`)
208
260
  const editingParticipant = participants.find(({ id }) => id === editingMemberId)
209
261
  const editingMember = memberOf(editingMemberId)
262
+ const presetItems = presetState.status === 'ready' ? [
263
+ { value: FOLLOW_ROUTE, label: t('sandbox.entity.presetFollowRoute') },
264
+ ...presetState.catalog.presets.map(({ id, name, status }) => {
265
+ const label = name === id ? id : `${name}(${id})`
266
+ return { value: id, label: status === 'error' ? t('sandbox.entity.presetError', { name: label }) : label }
267
+ }),
268
+ // 规则指向的预设已被删掉时仍列出并标明,否则选单显示空白,也无从看出该恢复默认。
269
+ ...(preset !== FOLLOW_ROUTE && !presetState.catalog.presets.some(({ id }) => id === preset)
270
+ ? [{ value: preset, label: t('sandbox.entity.presetMissing', { id: preset }) }]
271
+ : []),
272
+ ] : [{ value: FOLLOW_ROUTE, label: t('sandbox.entity.presetFollowRoute') }]
273
+ const presetReady = presetState.status === 'ready' && presetState.catalog.available
274
+ const presetHint = presetState.status === 'loading'
275
+ ? t('sandbox.entity.presetLoading')
276
+ : presetState.status === 'failed'
277
+ ? t('sandbox.entity.presetFailed', { error: presetState.error })
278
+ : presetState.catalog.available ? t('sandbox.entity.presetHint') : t('sandbox.entity.presetUnavailable')
279
+ const authorityItems = [
280
+ { value: 'inherit', label: t('sandbox.entity.authorityInherit') },
281
+ ...AUTHORITY_LEVELS.map((level) => ({
282
+ value: String(level),
283
+ label: level === 0 ? t('sandbox.entity.authorityDisabled') : t('sandbox.entity.authorityLevel', { level }),
284
+ })),
285
+ ]
210
286
  const roleItems = [
211
287
  { value: 'owner', label: t('sandbox.role.owner') },
212
288
  { value: 'admin', label: t('sandbox.role.admin') },
@@ -215,7 +291,7 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
215
291
 
216
292
  return (
217
293
  <Dialog open={open} onOpenChange={(next) => next ? onOpenChange(true) : requestClose()}>
218
- <DialogContent className={cn('flex flex-col overflow-hidden', mode === 'edit' && 'sm:max-w-lg')}>
294
+ <DialogContent className={cn('sandbox-entity-dialog flex flex-col overflow-hidden', mode === 'edit' && 'sm:max-w-lg')}>
219
295
  <DialogHeader>
220
296
  <DialogTitle>{t(mode === 'edit' ? 'sandbox.entity.editTitle' : 'sandbox.entity.deleteTitle', { kind: entityLabel })}</DialogTitle>
221
297
  <DialogDescription>{t(mode === 'edit' ? 'sandbox.entity.editHint' : 'sandbox.entity.deleteHint')}</DialogDescription>
@@ -283,6 +359,27 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
283
359
  )}
284
360
  </div>
285
361
  </section>
362
+ {type === 'user' && (
363
+ <section className="sandbox-entity-section">
364
+ <h3 className="sandbox-entity-section-title">{t('sandbox.entity.section.runtime')}</h3>
365
+ <div className="sandbox-entity-field">
366
+ <Label htmlFor="sandbox-entity-authority">{t('sandbox.entity.authority')}</Label>
367
+ <Select
368
+ value={String(draft.authority)}
369
+ items={authorityItems}
370
+ onValueChange={(value) => value && setDraft((current) => ({
371
+ ...current, authority: AUTHORITY_LEVELS.find((level) => String(level) === value) ?? 'inherit',
372
+ }))}
373
+ >
374
+ <SelectTrigger id="sandbox-entity-authority" className="w-full" aria-describedby="sandbox-entity-authority-hint"><SelectValue /></SelectTrigger>
375
+ <SelectContent className="sandbox-glass">
376
+ {authorityItems.map(({ value, label }) => <SelectItem key={value} value={value}>{label}</SelectItem>)}
377
+ </SelectContent>
378
+ </Select>
379
+ <p id="sandbox-entity-authority-hint" className="sandbox-entity-hint">{t('sandbox.entity.authorityHint')}</p>
380
+ </div>
381
+ </section>
382
+ )}
286
383
  {type === 'bot' && (
287
384
  <section className="sandbox-entity-section">
288
385
  <h3 className="sandbox-entity-section-title">{t('sandbox.entity.section.runtime')}</h3>
@@ -291,6 +388,16 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
291
388
  <Switch checked={draft.enabled} onCheckedChange={(value) => setDraft((current) => ({ ...current, enabled: value === true }))} />
292
389
  </label>
293
390
  <ImplementationSelect value={draft.implementation} onChange={(implementation) => setDraft((value) => ({ ...value, implementation }))} />
391
+ <div className="sandbox-entity-field">
392
+ <Label>{t('sandbox.entity.preset')}</Label>
393
+ <Select value={preset} disabled={!presetReady} onValueChange={(value) => value && setPreset(value)} items={presetItems}>
394
+ <SelectTrigger className="w-full"><SelectValue /></SelectTrigger>
395
+ <SelectContent className="sandbox-glass">
396
+ {presetItems.map(({ value, label }) => <SelectItem key={value} value={value}>{label}</SelectItem>)}
397
+ </SelectContent>
398
+ </Select>
399
+ <p className={cn('sandbox-entity-hint', presetState.status === 'failed' && 'is-error')}>{presetHint}</p>
400
+ </div>
294
401
  <div className="sandbox-entity-field">
295
402
  <div className="sandbox-entity-section-title">
296
403
  <Label>{t('sandbox.entity.capabilities')}</Label>
@@ -166,6 +166,11 @@ sandbox.emoji.search: "Search by name, pinyin or ID"
166
166
  sandbox.emoji.title: "React"
167
167
  sandbox.entity.addMember: "Add {name} ({id})"
168
168
  sandbox.entity.aliases: "Aliases {aliases}"
169
+ sandbox.entity.authority: "Permission level"
170
+ sandbox.entity.authorityDisabled: "Level 0 (disabled)"
171
+ sandbox.entity.authorityHint: "Applies only to active sandbox bots in this scene. Saved changes affect subsequent tool authorization. Independent of QQ levels and group roles; explicit denial and approval rules still apply."
172
+ sandbox.entity.authorityInherit: "Use host permissions"
173
+ sandbox.entity.authorityLevel: "Level {level}"
169
174
  sandbox.entity.capabilities: "Capability overrides"
170
175
  sandbox.entity.capabilityCount: "{enabled} / {total} enabled"
171
176
  sandbox.entity.capabilitySearch: "Search action, alias or purpose"
@@ -186,6 +191,14 @@ sandbox.entity.native: "Native"
186
191
  sandbox.entity.needOwner: "A group needs at least one member as owner."
187
192
  sandbox.entity.noCapability: "No matching capability"
188
193
  sandbox.entity.noCard: "No card"
194
+ sandbox.entity.preset: "ChatLuna preset"
195
+ sandbox.entity.presetError: "{name} (failed to load)"
196
+ sandbox.entity.presetFailed: "Failed to read presets: {error}"
197
+ sandbox.entity.presetFollowRoute: "Follow routing rules"
198
+ sandbox.entity.presetHint: "Saved as a ChatLuna routing rule that matches only this QQ ID, shared by bots with the same ID in the main environment and every test space; more specific routing rules (per channel, for example) still take precedence. The switch applies from the next message and keeps the conversation history."
199
+ sandbox.entity.presetLoading: "Reading presets…"
200
+ sandbox.entity.presetMissing: "{id} (preset no longer exists)"
201
+ sandbox.entity.presetUnavailable: "The ChatLuna preset service is not loaded; the preset cannot be switched."
189
202
  sandbox.entity.removeMember: "Remove {name} ({id})"
190
203
  sandbox.entity.role: "Role"
191
204
  sandbox.entity.section.basic: "Basic info"
@@ -461,6 +474,8 @@ sandbox.settings.discard: "Discard changes"
461
474
  sandbox.settings.invalid: "Some fields have invalid values"
462
475
  sandbox.settings.saveFailed: "Failed to save settings"
463
476
  sandbox.settings.saved: "Settings saved. The plugin restarts with the new settings"
477
+ sandbox.settings.schema.allowToolPermissionEditing.description: "Allows MCP, HTTP and bot tools to assign sandbox user permission levels, including batch edits, scene imports and resets. Enabling this lets AI raise tool execution privileges; when disabled, only the WebUI can make these changes"
478
+ sandbox.settings.schema.allowToolPermissionEditing.label: "Allow tools to change permission levels"
464
479
  sandbox.settings.schema.botTools.description: "Tool calling"
465
480
  sandbox.settings.schema.botTools.enabled.description: "Register the test endpoint tools in ChatLuna with the `sandbox_` prefix"
466
481
  sandbox.settings.schema.botTools.enabled.label: "Enabled"
@@ -483,6 +498,9 @@ sandbox.settings.schema.persistenceMode.description: "Database mode persists acr
483
498
  sandbox.settings.schema.persistenceMode.label: "Storage mode"
484
499
  sandbox.settings.schema.persistenceMode.option.database.description: "Database"
485
500
  sandbox.settings.schema.persistenceMode.option.memory.description: "Server memory"
501
+ sandbox.settings.schema.presetEditing.description: "Preset editing"
502
+ sandbox.settings.schema.presetEditing.editablePresets.description: "Besides test presets with the `sandbox-test-` prefix, test tools may modify these presets; they can be modified but not deleted"
503
+ sandbox.settings.schema.presetEditing.editablePresets.label: "Editable presets"
486
504
  sandbox.settings.schema.sandboxAccentColor.description: "Color of own bubbles, the composer and selected states. Does not follow the ChatLuna theme color"
487
505
  sandbox.settings.schema.sandboxAccentColor.label: "Accent color"
488
506
  sandbox.settings.schema.sandboxIncomingBubbleStyle.description: "Shadow uses a translucent white background with a drop shadow; outline uses a white background with a thin border. Applies only to the light theme"
@@ -166,6 +166,11 @@ sandbox.emoji.search: "搜索表情名称、拼音或 ID"
166
166
  sandbox.emoji.title: "贴表情"
167
167
  sandbox.entity.addMember: "添加 {name}({id})"
168
168
  sandbox.entity.aliases: "别名 {aliases}"
169
+ sandbox.entity.authority: "权限等级"
170
+ sandbox.entity.authorityDisabled: "0 级(禁用)"
171
+ sandbox.entity.authorityHint: "仅作用于当前场景的活动沙盒机器人,保存后影响后续工具权限判定。与 QQ 等级、群身份无关;工具的显式拒绝和审批规则仍然生效。"
172
+ sandbox.entity.authorityInherit: "沿用宿主权限"
173
+ sandbox.entity.authorityLevel: "{level} 级"
169
174
  sandbox.entity.capabilities: "能力覆盖"
170
175
  sandbox.entity.capabilityCount: "已启用 {enabled} / {total}"
171
176
  sandbox.entity.capabilitySearch: "搜索 action、别名或作用"
@@ -186,6 +191,14 @@ sandbox.entity.native: "原生扩展"
186
191
  sandbox.entity.needOwner: "群组至少需要一位成员作为群主。"
187
192
  sandbox.entity.noCapability: "无匹配能力"
188
193
  sandbox.entity.noCard: "未设置群昵称"
194
+ sandbox.entity.preset: "ChatLuna 预设"
195
+ sandbox.entity.presetError: "{name}(加载出错)"
196
+ sandbox.entity.presetFailed: "预设列表读取失败:{error}"
197
+ sandbox.entity.presetFollowRoute: "跟随路由规则"
198
+ sandbox.entity.presetHint: "写成只命中这个 QQ 号的 ChatLuna 路由规则,主环境与各测试空间里同号的机器人共用;按频道等写得更具体的路由规则仍会盖过它。切换后从下一条消息起生效,会话历史保留。"
199
+ sandbox.entity.presetLoading: "正在读取预设列表…"
200
+ sandbox.entity.presetMissing: "{id}(预设已不存在)"
201
+ sandbox.entity.presetUnavailable: "ChatLuna 的预设服务没有加载,预设不可切换。"
189
202
  sandbox.entity.removeMember: "移除 {name}({id})"
190
203
  sandbox.entity.role: "群身份"
191
204
  sandbox.entity.section.basic: "基本资料"
@@ -461,6 +474,8 @@ sandbox.settings.discard: "撤销更改"
461
474
  sandbox.settings.invalid: "部分字段的值无效"
462
475
  sandbox.settings.saveFailed: "设置保存失败"
463
476
  sandbox.settings.saved: "设置已保存,插件按新设置重启"
477
+ sandbox.settings.schema.allowToolPermissionEditing.description: "允许 MCP、HTTP 和机器人工具分配沙盒用户权限等级,包括批量修改、场景导入与重置;开启后 AI 可以提高工具执行权限,关闭时仅 WebUI 可修改"
478
+ sandbox.settings.schema.allowToolPermissionEditing.label: "允许工具修改权限等级"
464
479
  sandbox.settings.schema.botTools.description: "工具调用"
465
480
  sandbox.settings.schema.botTools.enabled.description: "把测试端点的工具以`sandbox_`前缀注册到 ChatLuna"
466
481
  sandbox.settings.schema.botTools.enabled.label: "启用"
@@ -483,6 +498,9 @@ sandbox.settings.schema.persistenceMode.description: "数据库模式在重启
483
498
  sandbox.settings.schema.persistenceMode.label: "存储方式"
484
499
  sandbox.settings.schema.persistenceMode.option.database.description: "数据库"
485
500
  sandbox.settings.schema.persistenceMode.option.memory.description: "服务端内存"
501
+ sandbox.settings.schema.presetEditing.description: "预设编辑"
502
+ sandbox.settings.schema.presetEditing.editablePresets.description: "测试工具除了`sandbox-test-`前缀的测试预设,还可以修改这些预设;只能修改,不能删除"
503
+ sandbox.settings.schema.presetEditing.editablePresets.label: "可编辑预设"
486
504
  sandbox.settings.schema.sandboxAccentColor.description: "己方气泡、发送框与选中态使用的颜色,不跟随 ChatLuna 主题色"
487
505
  sandbox.settings.schema.sandboxAccentColor.label: "强调色"
488
506
  sandbox.settings.schema.sandboxIncomingBubbleStyle.description: "投影为半透明白底加阴影,描边为白底加细边框;仅在亮色主题下生效"
@@ -1,5 +1,5 @@
1
1
  import type { Translate } from '@chatluna/ui-client/client'
2
- import type { SchemaDocument, SchemaDocumentNode } from '@chatluna/schema'
2
+ import type { SchemaDocument } from '@chatluna/schema'
3
3
 
4
4
  /** schema 文案的键前缀,后接节点的文案 ID 与 `label`/`description`。 */
5
5
  export const SCHEMA_LOCALE_PREFIX = 'sandbox.settings.schema.'
@@ -60,7 +60,7 @@ export function schemaTexts(document: SchemaDocument): SchemaText[] {
60
60
  * 语言文件里缺的键原样保留服务端的中文,新增字段忘了补译文时不会显示成键名。
61
61
  */
62
62
  export function localizeSchema(document: SchemaDocument, t: Translate): SchemaDocument {
63
- const refs: Record<string, SchemaDocumentNode> = { ...document.refs }
63
+ const refs: SchemaDocument['refs'] = { ...document.refs }
64
64
  visit(document, document.uid, undefined, '', (id, textId) => {
65
65
  const node = refs[id]!
66
66
  const meta = { ...node.meta }
@@ -3,7 +3,7 @@ import { DatabaseIcon, InfoIcon, PaletteIcon, SaveIcon, ServerCogIcon, SlidersHo
3
3
  import { Alert, AlertDescription, Button, cn, Spinner } from '@chatluna/ui-kit'
4
4
  import { apiErrorMessage, callAction, toast, useLive } from '@chatluna/ui-client/client'
5
5
  import { SchemaForm, useFormValidation } from '@chatluna/ui-schema-form/client'
6
- import type { SchemaDocument, SchemaDocumentNode } from '@chatluna/schema'
6
+ import type { SchemaDocument } from '@chatluna/schema'
7
7
  import { useT } from '../i18n'
8
8
  import { OverlayScrollbar } from '../shared/overlay-scrollbar'
9
9
  import { AboutPanel } from './about'
@@ -49,7 +49,7 @@ function sectionsOf(document: SchemaDocument, fallbackTitle: string): SettingsSe
49
49
  return ids.map((id) => {
50
50
  const node = document.refs[id]!
51
51
  const { label, description, ...meta } = node.meta ?? {}
52
- const stripped: SchemaDocumentNode = { ...node, meta }
52
+ const stripped: SchemaDocument['refs'][string] = { ...node, meta }
53
53
  return {
54
54
  title: textOf(label) ?? textOf(description) ?? fallbackTitle,
55
55
  description: textOf(label) ? textOf(description) : undefined,
@@ -0,0 +1,38 @@
1
+ /**
2
+ * 媒体 Data URL 的页面级缓存,各空间的 `WorkspaceStore` 与每次挂载共用。
3
+ *
4
+ * store 跟着沙盒页面挂载、卸载,缓存放在 store 里时,从别的页面回来每个头像都要重新请求一遍,
5
+ * 先闪名字首字再出图片。媒体 ID 是内容的 sha256(`src/media-storage.ts`),同一个 ID 的内容不变,
6
+ * 所以缓存不会过期,插件重启、切换空间与操作者都照用。只在内存里,刷新页面后重新拉取。
7
+ *
8
+ * 内置头像是预生成的 PNG,数量有限,长期保留;消息里的图片可能有几 MB,只保留最近用到的
9
+ * {@link MESSAGE_MEDIA_LIMIT} 张,按最近使用淘汰。
10
+ */
11
+
12
+ const MESSAGE_MEDIA_LIMIT = 64
13
+
14
+ const avatars = new Map<string, string>()
15
+ /** Map 的插入顺序即使用顺序:命中时删掉重插,淘汰时取第一项。 */
16
+ const messageMedia = new Map<string, string>()
17
+
18
+ export function readCachedMedia(id: string): string | undefined {
19
+ const avatar = avatars.get(id)
20
+ if (avatar !== undefined) return avatar
21
+ const url = messageMedia.get(id)
22
+ if (url === undefined) return undefined
23
+ messageMedia.delete(id)
24
+ messageMedia.set(id, url)
25
+ return url
26
+ }
27
+
28
+ export function rememberMedia(id: string, url: string, avatar: boolean) {
29
+ if (avatar) {
30
+ avatars.set(id, url)
31
+ messageMedia.delete(id)
32
+ return
33
+ }
34
+ if (avatars.has(id)) return
35
+ messageMedia.delete(id)
36
+ messageMedia.set(id, url)
37
+ while (messageMedia.size > MESSAGE_MEDIA_LIMIT) messageMedia.delete(messageMedia.keys().next().value!)
38
+ }