chatluna-plugin-onebot-sandbox 1.1.0 → 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.
- package/client/chat/composer.tsx +4 -1
- package/client/chat/message-list.tsx +6 -0
- package/client/environment/avatar-picker.tsx +2 -5
- package/client/environment/entity-dialog.css +5 -0
- package/client/environment/entity-dialog.tsx +41 -3
- package/client/locales/en.yml +7 -0
- package/client/locales/zh.yml +7 -0
- package/client/settings/localize.ts +2 -2
- package/client/settings/page.tsx +2 -2
- package/client/workspace/media-cache.ts +1 -1
- package/client/workspace/store.ts +29 -12
- package/dist/.vite/manifest.json +1 -1
- package/dist/app-CpJLSY0S.js +85 -0
- package/dist/client.css +1 -1
- package/dist/client.js +1 -1
- package/lib/builtin-avatar-options.d.ts.map +1 -1
- package/lib/builtin-avatar-png.d.ts +15 -0
- package/lib/builtin-avatar-png.d.ts.map +1 -0
- package/lib/builtin-avatars.d.ts +1 -1
- package/lib/builtin-avatars.d.ts.map +1 -1
- package/lib/chatluna/user-permissions.d.ts +15 -0
- package/lib/chatluna/user-permissions.d.ts.map +1 -0
- package/lib/control-service.d.ts +6 -6
- package/lib/control-service.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +390 -88
- package/lib/index.js.map +1 -1
- package/lib/mcp/service.d.ts +3 -0
- package/lib/mcp/service.d.ts.map +1 -1
- package/lib/mcp/tool-registry.d.ts +1 -0
- package/lib/mcp/tool-registry.d.ts.map +1 -1
- package/lib/types.d.ts +7 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/user-authority.d.ts +6 -0
- package/lib/user-authority.d.ts.map +1 -0
- package/package.json +6 -2
- package/dist/app-SGdVOART.js +0 -85
package/client/chat/composer.tsx
CHANGED
|
@@ -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,
|
|
@@ -517,6 +517,9 @@ export const Composer = React.forwardRef<ComposerHandle, {
|
|
|
517
517
|
<SandboxAvatar kind={sender.kind} name={sender.name} src={sender.avatar} badge={false} className="sandbox-composer-user-avatar" />
|
|
518
518
|
</ContextMenuTrigger>
|
|
519
519
|
<ContextMenuContent className="sandbox-glass">
|
|
520
|
+
<ContextMenuItem onClick={() => dialogs.openProfile(sender.id)}>
|
|
521
|
+
<IdCardIcon />{t('sandbox.menu.profile')}
|
|
522
|
+
</ContextMenuItem>
|
|
520
523
|
<ContextMenuItem onClick={() => dialogs.openEntity('edit', { type: sender.kind, id: sender.id })}>
|
|
521
524
|
<PencilIcon />{t('sandbox.menu.editEntity', { kind: t(`sandbox.kind.${sender.kind}`) })}<ExtensionMark />
|
|
522
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-
|
|
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
|
-
|
|
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 交回,服务端负责导入成受控媒体。用于浮层内原地切换的二级视图。 */
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
type SandboxAccountSex,
|
|
30
30
|
type SandboxGroupMember,
|
|
31
31
|
type SandboxImplementationProfile,
|
|
32
|
+
type SandboxUserAuthority,
|
|
32
33
|
} from '../../src/types'
|
|
33
34
|
import { useT } from '../i18n'
|
|
34
35
|
import { SandboxAvatar } from '../shared/avatar'
|
|
@@ -51,6 +52,7 @@ interface Draft {
|
|
|
51
52
|
avatar: string
|
|
52
53
|
personalNote: string
|
|
53
54
|
sex: 'unset' | SandboxAccountSex
|
|
55
|
+
authority: 'inherit' | SandboxUserAuthority
|
|
54
56
|
implementation: SandboxImplementationProfile
|
|
55
57
|
enabled: boolean
|
|
56
58
|
disabledCapabilities: string[]
|
|
@@ -59,6 +61,7 @@ interface Draft {
|
|
|
59
61
|
|
|
60
62
|
/** 「跟随路由规则」的选项值;预设 ID 由 v2 按文件名生成,不含冒号,不会与它撞上。 */
|
|
61
63
|
const FOLLOW_ROUTE = 'onebot-sandbox:follow-route'
|
|
64
|
+
const AUTHORITY_LEVELS = [0, 1, 2, 3, 4, 5] as const
|
|
62
65
|
|
|
63
66
|
/** 机器人的预设选项:未读取、服务未加载、读取失败或读到的目录。 */
|
|
64
67
|
type PresetState =
|
|
@@ -67,7 +70,7 @@ type PresetState =
|
|
|
67
70
|
| { status: 'ready'; catalog: SandboxBotPresetCatalog }
|
|
68
71
|
|
|
69
72
|
const EMPTY_DRAFT: Draft = {
|
|
70
|
-
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: [],
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
/** 编辑或删除一个用户、机器人或群组。ID 创建后不可修改;删除会连带清理相关会话与关系。 */
|
|
@@ -131,6 +134,7 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
|
|
|
131
134
|
avatar: participant.avatar ?? '',
|
|
132
135
|
personalNote: participant.profile?.personalNote ?? '',
|
|
133
136
|
sex: participant.profile?.sex ?? 'unset',
|
|
137
|
+
authority: participant.kind === 'user' ? participant.authority ?? 'inherit' : 'inherit',
|
|
134
138
|
...(participant.kind === 'bot' ? {
|
|
135
139
|
implementation: participant.implementation,
|
|
136
140
|
enabled: participant.enabled,
|
|
@@ -187,7 +191,13 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
|
|
|
187
191
|
const submitEdit = (event: React.FormEvent) => {
|
|
188
192
|
event.preventDefault()
|
|
189
193
|
if (target?.type === 'user') {
|
|
190
|
-
void runAction({
|
|
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
|
+
})
|
|
191
201
|
} else if (target?.type === 'bot') {
|
|
192
202
|
void runAction({
|
|
193
203
|
action: 'update-bot',
|
|
@@ -266,6 +276,13 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
|
|
|
266
276
|
: presetState.status === 'failed'
|
|
267
277
|
? t('sandbox.entity.presetFailed', { error: presetState.error })
|
|
268
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
|
+
]
|
|
269
286
|
const roleItems = [
|
|
270
287
|
{ value: 'owner', label: t('sandbox.role.owner') },
|
|
271
288
|
{ value: 'admin', label: t('sandbox.role.admin') },
|
|
@@ -274,7 +291,7 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
|
|
|
274
291
|
|
|
275
292
|
return (
|
|
276
293
|
<Dialog open={open} onOpenChange={(next) => next ? onOpenChange(true) : requestClose()}>
|
|
277
|
-
<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')}>
|
|
278
295
|
<DialogHeader>
|
|
279
296
|
<DialogTitle>{t(mode === 'edit' ? 'sandbox.entity.editTitle' : 'sandbox.entity.deleteTitle', { kind: entityLabel })}</DialogTitle>
|
|
280
297
|
<DialogDescription>{t(mode === 'edit' ? 'sandbox.entity.editHint' : 'sandbox.entity.deleteHint')}</DialogDescription>
|
|
@@ -342,6 +359,27 @@ export function EntityDialog({ open, mode, target, onOpenChange }: {
|
|
|
342
359
|
)}
|
|
343
360
|
</div>
|
|
344
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
|
+
)}
|
|
345
383
|
{type === 'bot' && (
|
|
346
384
|
<section className="sandbox-entity-section">
|
|
347
385
|
<h3 className="sandbox-entity-section-title">{t('sandbox.entity.section.runtime')}</h3>
|
package/client/locales/en.yml
CHANGED
|
@@ -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"
|
|
@@ -469,6 +474,8 @@ sandbox.settings.discard: "Discard changes"
|
|
|
469
474
|
sandbox.settings.invalid: "Some fields have invalid values"
|
|
470
475
|
sandbox.settings.saveFailed: "Failed to save settings"
|
|
471
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"
|
|
472
479
|
sandbox.settings.schema.botTools.description: "Tool calling"
|
|
473
480
|
sandbox.settings.schema.botTools.enabled.description: "Register the test endpoint tools in ChatLuna with the `sandbox_` prefix"
|
|
474
481
|
sandbox.settings.schema.botTools.enabled.label: "Enabled"
|
package/client/locales/zh.yml
CHANGED
|
@@ -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、别名或作用"
|
|
@@ -469,6 +474,8 @@ sandbox.settings.discard: "撤销更改"
|
|
|
469
474
|
sandbox.settings.invalid: "部分字段的值无效"
|
|
470
475
|
sandbox.settings.saveFailed: "设置保存失败"
|
|
471
476
|
sandbox.settings.saved: "设置已保存,插件按新设置重启"
|
|
477
|
+
sandbox.settings.schema.allowToolPermissionEditing.description: "允许 MCP、HTTP 和机器人工具分配沙盒用户权限等级,包括批量修改、场景导入与重置;开启后 AI 可以提高工具执行权限,关闭时仅 WebUI 可修改"
|
|
478
|
+
sandbox.settings.schema.allowToolPermissionEditing.label: "允许工具修改权限等级"
|
|
472
479
|
sandbox.settings.schema.botTools.description: "工具调用"
|
|
473
480
|
sandbox.settings.schema.botTools.enabled.description: "把测试端点的工具以`sandbox_`前缀注册到 ChatLuna"
|
|
474
481
|
sandbox.settings.schema.botTools.enabled.label: "启用"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Translate } from '@chatluna/ui-client/client'
|
|
2
|
-
import type { SchemaDocument
|
|
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:
|
|
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 }
|
package/client/settings/page.tsx
CHANGED
|
@@ -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
|
|
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:
|
|
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,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 先闪名字首字再出图片。媒体 ID 是内容的 sha256(`src/media-storage.ts`),同一个 ID 的内容不变,
|
|
6
6
|
* 所以缓存不会过期,插件重启、切换空间与操作者都照用。只在内存里,刷新页面后重新拉取。
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* 内置头像是预生成的 PNG,数量有限,长期保留;消息里的图片可能有几 MB,只保留最近用到的
|
|
9
9
|
* {@link MESSAGE_MEDIA_LIMIT} 张,按最近使用淘汰。
|
|
10
10
|
*/
|
|
11
11
|
|
|
@@ -85,6 +85,7 @@ export interface WorkspaceView {
|
|
|
85
85
|
export class WorkspaceStore {
|
|
86
86
|
private view: WorkspaceView = { media: {}, mediaFailures: {} }
|
|
87
87
|
private listeners = new Set<() => void>()
|
|
88
|
+
private loadTask: Promise<void> | undefined
|
|
88
89
|
private refreshTask: Promise<void> | undefined
|
|
89
90
|
private pendingRefresh = false
|
|
90
91
|
private mediaLoading = new Set<string>()
|
|
@@ -137,6 +138,7 @@ export class WorkspaceStore {
|
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
private replaceWorkspace(workspace: SandboxWorkspaceState, preferred: SandboxWorkspaceSelection = {}, persist = true) {
|
|
141
|
+
if (this.disposed) return
|
|
140
142
|
const selection = resolveWorkspaceSelection(workspace.snapshot, {
|
|
141
143
|
currentOperatorId: preferred.currentOperatorId ?? this.view.currentOperatorId,
|
|
142
144
|
activeConversationId: preferred.activeConversationId ?? this.view.activeConversationId,
|
|
@@ -166,20 +168,28 @@ export class WorkspaceStore {
|
|
|
166
168
|
this.replaceWorkspace(workspace, readSelection(this.spaceId), false)
|
|
167
169
|
}
|
|
168
170
|
|
|
169
|
-
|
|
171
|
+
load() {
|
|
172
|
+
if (this.loadTask) return this.loadTask
|
|
170
173
|
const stored = readSelection(this.spaceId)
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
const operatorId = this.view.currentOperatorId
|
|
175
|
+
this.loadTask = (async () => {
|
|
173
176
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
let workspace: SandboxWorkspaceState
|
|
178
|
+
try {
|
|
179
|
+
workspace = await invoke('onebot-sandbox.workspace', this.scoped(stored.currentOperatorId ? { operatorId: stored.currentOperatorId } : {}))
|
|
180
|
+
} catch {
|
|
181
|
+
// 本地记住的操作者可能已被删除;退回默认视角再解析一次选择。
|
|
182
|
+
workspace = await invoke('onebot-sandbox.workspace', this.scoped({}))
|
|
183
|
+
}
|
|
184
|
+
if (operatorId !== this.view.currentOperatorId) return
|
|
185
|
+
this.replaceWorkspace(workspace, stored)
|
|
186
|
+
} catch (error) {
|
|
187
|
+
this.set({ loadError: errorText(error, translate('sandbox.error.loadWorkspace')) })
|
|
188
|
+
} finally {
|
|
189
|
+
this.loadTask = undefined
|
|
178
190
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.set({ loadError: errorText(error, translate('sandbox.error.loadWorkspace')) })
|
|
182
|
-
}
|
|
191
|
+
})()
|
|
192
|
+
return this.loadTask
|
|
183
193
|
}
|
|
184
194
|
|
|
185
195
|
/** 场景变更广播只是失效信号;多次信号合并成串行的若干次读取,不会并发打满。 */
|
|
@@ -189,10 +199,18 @@ export class WorkspaceStore {
|
|
|
189
199
|
this.refreshTask = (async () => {
|
|
190
200
|
try {
|
|
191
201
|
while (this.pendingRefresh && !this.disposed) {
|
|
202
|
+
// 初次加载会恢复本地操作者;提前请求会按默认用户裁剪,随后覆盖掉当前用户的私聊。
|
|
203
|
+
await this.loadTask
|
|
204
|
+
if (this.disposed) break
|
|
192
205
|
this.pendingRefresh = false
|
|
206
|
+
if (!this.view.workspace) continue
|
|
193
207
|
const operatorId = this.view.currentOperatorId
|
|
194
208
|
try {
|
|
195
209
|
const workspace = await invoke('onebot-sandbox.workspace', this.scoped(operatorId ? { operatorId } : {}))
|
|
210
|
+
if (operatorId !== this.view.currentOperatorId) {
|
|
211
|
+
this.pendingRefresh = true
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
196
214
|
if (workspace.snapshot.revision >= (this.snapshot?.revision ?? 0)) this.replaceWorkspace(workspace)
|
|
197
215
|
} catch {
|
|
198
216
|
// 刷新失败保留当前画面,下一次信号会再试。
|
|
@@ -211,7 +229,6 @@ export class WorkspaceStore {
|
|
|
211
229
|
|
|
212
230
|
async selectOperator(participantId: string) {
|
|
213
231
|
const workspace = await invoke('onebot-sandbox.workspace', this.scoped({ operatorId: participantId }))
|
|
214
|
-
this.set({ currentOperatorId: participantId })
|
|
215
232
|
this.replaceWorkspace(workspace, { currentOperatorId: participantId })
|
|
216
233
|
}
|
|
217
234
|
|