chatluna-plugin-onebot-sandbox 1.1.5 → 1.2.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/client/chat/chat-pane.tsx +19 -7
- package/client/chat/composer.tsx +4 -4
- package/client/chat/forward.tsx +11 -12
- package/client/chat/media-attachments.tsx +236 -0
- package/client/chat/message-list.tsx +54 -37
- package/client/chat/messages.css +203 -19
- package/client/environment/avatar-picker.tsx +4 -0
- package/client/locales/en.yml +10 -3
- package/client/locales/zh.yml +10 -3
- package/client/mcp/credential-manager.tsx +5 -9
- package/client/test-space/spaces.css +2 -0
- package/client/webqq/composer-draft.ts +0 -1
- package/client/webqq/forward-dialog-stack.ts +11 -3
- package/client/webqq/media-attachment.ts +72 -0
- package/client/webqq/message-cluster.ts +9 -29
- package/client/workspace/context.tsx +1 -1
- package/client/workspace/overlay-host.tsx +26 -17
- package/client/workspace/store.ts +75 -39
- package/dist/.vite/manifest.json +1 -1
- package/dist/app-Cubeh6IM.js +85 -0
- package/dist/client.css +2 -2
- package/dist/client.js +1 -1
- package/lib/base64.d.ts +3 -0
- package/lib/base64.d.ts.map +1 -0
- package/lib/bot.d.ts.map +1 -1
- package/lib/builtin-avatar-png.d.ts +0 -1
- package/lib/builtin-avatar-png.d.ts.map +1 -1
- package/lib/builtin-avatars.d.ts +0 -1
- package/lib/builtin-avatars.d.ts.map +1 -1
- package/lib/chatluna/state.d.ts.map +1 -1
- package/lib/chatluna/thinking.d.ts.map +1 -1
- package/lib/console-contract.d.ts +5 -5
- package/lib/console-contract.d.ts.map +1 -1
- package/lib/console.d.ts +1 -3
- package/lib/console.d.ts.map +1 -1
- package/lib/control-service.d.ts +4 -3
- package/lib/control-service.d.ts.map +1 -1
- package/lib/conversation-resolution.d.ts +0 -2
- package/lib/conversation-resolution.d.ts.map +1 -1
- package/lib/inbound-delivery.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +529 -549
- package/lib/index.js.map +1 -1
- package/lib/mcp/call-records.d.ts.map +1 -1
- package/lib/mcp/http-api.d.ts +3 -4
- package/lib/mcp/http-api.d.ts.map +1 -1
- package/lib/mcp/server.d.ts.map +1 -1
- package/lib/mcp/service.d.ts +8 -7
- package/lib/mcp/service.d.ts.map +1 -1
- package/lib/mcp/types.d.ts +1 -4
- package/lib/mcp/types.d.ts.map +1 -1
- package/lib/media-download.d.ts +3 -0
- package/lib/media-download.d.ts.map +1 -0
- package/lib/media-limits.d.ts +6 -0
- package/lib/media-limits.d.ts.map +1 -0
- package/lib/media-preview.d.ts +4 -0
- package/lib/media-preview.d.ts.map +1 -0
- package/lib/media-storage.d.ts +2 -3
- package/lib/media-storage.d.ts.map +1 -1
- package/lib/onebot-debug.d.ts.map +1 -1
- package/lib/record-store.d.ts +0 -2
- package/lib/record-store.d.ts.map +1 -1
- package/lib/test-spaces.d.ts +1 -0
- package/lib/test-spaces.d.ts.map +1 -1
- package/lib/types.d.ts +16 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/user-authority.d.ts +1 -1
- package/lib/user-authority.d.ts.map +1 -1
- package/package.json +5 -2
- package/dist/app-CpJLSY0S.js +0 -85
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
Input,
|
|
13
13
|
} from '@chatluna/ui-kit'
|
|
14
14
|
import { toast } from '@chatluna/ui-client/client'
|
|
15
|
+
import { resolveConversation } from '../../src/conversation-resolution'
|
|
15
16
|
import { useT } from '../i18n'
|
|
16
17
|
import { EntityDialog, type EntityDialogTarget } from '../environment/entity-dialog'
|
|
17
18
|
import { SandboxAvatar } from '../shared/avatar'
|
|
@@ -27,7 +28,7 @@ import { useSandbox, useWorkspace } from './context'
|
|
|
27
28
|
|
|
28
29
|
type TextDialog =
|
|
29
30
|
| { kind: 'remark', targetId: string, value: string }
|
|
30
|
-
| { kind: 'card' | 'name' | 'title', targetId: string, groupId: string, value: string }
|
|
31
|
+
| { kind: 'card' | 'sandbox-card' | 'name' | 'title', targetId: string, groupId: string, value: string }
|
|
31
32
|
| { kind: 'rename', conversationId: string, value: string }
|
|
32
33
|
|
|
33
34
|
export interface OverlayState {
|
|
@@ -58,15 +59,15 @@ export function useOverlayState(store: WorkspaceStore) {
|
|
|
58
59
|
setState((current) => ({ ...current, text: { kind, targetId, groupId: group.id, value } }))
|
|
59
60
|
},
|
|
60
61
|
openConversationRename: (conversationId) => {
|
|
61
|
-
const instance = store.snapshot?.conversationInstances
|
|
62
|
+
const instance = store.snapshot?.conversationInstances.find(({ id }) => id === conversationId)
|
|
62
63
|
if (instance) setState((value) => ({ ...value, text: { kind: 'rename', conversationId, value: instance.title ?? '' } }))
|
|
63
64
|
},
|
|
64
65
|
openProfile: (participantId, anchor) => {
|
|
65
66
|
const snapshot = store.snapshot
|
|
66
67
|
if (!snapshot) return
|
|
67
68
|
const view = store.getView()
|
|
68
|
-
const conversation =
|
|
69
|
-
const groupId = conversation
|
|
69
|
+
const conversation = view.activeConversationId ? resolveConversation(snapshot, view.activeConversationId) : undefined
|
|
70
|
+
const groupId = conversation?.groupId
|
|
70
71
|
const card = buildProfileCardModel(t, { snapshot, participantId, viewerId: view.currentOperatorId, groupId })
|
|
71
72
|
if (card) setState((value) => ({ ...value, profile: { card, ...anchorOf(anchor) } }))
|
|
72
73
|
},
|
|
@@ -106,6 +107,7 @@ function TextActionDialog({ dialog, onClose }: { dialog?: TextDialog, onClose():
|
|
|
106
107
|
const [busy, setBusy] = React.useState(false)
|
|
107
108
|
const [error, setError] = React.useState('')
|
|
108
109
|
const shown = useRetained(dialog)
|
|
110
|
+
const scroller = React.useRef<HTMLDivElement>(null)
|
|
109
111
|
const { requestClose, confirm } = useDiscardConfirm(!!dialog && value !== dialog.value, onClose)
|
|
110
112
|
|
|
111
113
|
// 布局阶段回填:打开的首帧就是本次的值,不闪出上一次输入的内容。
|
|
@@ -124,6 +126,7 @@ function TextActionDialog({ dialog, onClose }: { dialog?: TextDialog, onClose():
|
|
|
124
126
|
else if (dialog.kind === 'rename') await store.renameConversationInstance({ conversationId: dialog.conversationId, title: value })
|
|
125
127
|
else if (dialog.kind === 'name') await store.performGroupAction({ action: 'set-name', groupId: dialog.groupId, name: value })
|
|
126
128
|
else if (dialog.kind === 'title') await store.performGroupAction({ action: 'set-title', groupId: dialog.groupId, targetId: dialog.targetId, title: value })
|
|
129
|
+
else if (dialog.kind === 'sandbox-card') await store.manageEnvironment({ action: 'set-group-card', data: { groupId: dialog.groupId, targetId: dialog.targetId, card: value } })
|
|
127
130
|
else await store.performGroupAction({ action: 'set-card', groupId: dialog.groupId, targetId: dialog.targetId, card: value })
|
|
128
131
|
onClose()
|
|
129
132
|
} catch (failure) {
|
|
@@ -133,24 +136,30 @@ function TextActionDialog({ dialog, onClose }: { dialog?: TextDialog, onClose():
|
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
|
|
136
|
-
const kind = shown?.kind ?? 'remark'
|
|
139
|
+
const kind = shown?.kind === 'sandbox-card' ? 'card' : shown?.kind ?? 'remark'
|
|
137
140
|
return (
|
|
138
141
|
<Dialog open={!!dialog} onOpenChange={(open) => !open && requestClose()}>
|
|
139
|
-
<DialogContent>
|
|
142
|
+
<DialogContent className="flex flex-col overflow-hidden text-sm leading-6">
|
|
140
143
|
<DialogHeader>
|
|
141
144
|
<DialogTitle>{t(`sandbox.text.${kind}.title`)}</DialogTitle>
|
|
142
|
-
<DialogDescription>{t(`sandbox.text.${kind}.description`)}</DialogDescription>
|
|
145
|
+
<DialogDescription>{t(shown?.kind === 'sandbox-card' ? 'sandbox.text.card.sandboxDescription' : `sandbox.text.${kind}.description`)}</DialogDescription>
|
|
143
146
|
</DialogHeader>
|
|
144
|
-
<
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
<div className="relative -mx-5 flex min-h-0 flex-col">
|
|
148
|
+
<div ref={scroller} className="min-h-0 space-y-2 overflow-y-auto px-5 py-0.5" style={{ scrollbarWidth: 'none' }}>
|
|
149
|
+
<Input
|
|
150
|
+
autoFocus
|
|
151
|
+
value={value}
|
|
152
|
+
aria-label={t(`sandbox.text.${kind}.placeholder`)}
|
|
153
|
+
placeholder={t(`sandbox.text.${kind}.placeholder`)}
|
|
154
|
+
onChange={(event) => setValue(event.target.value)}
|
|
155
|
+
onKeyDown={(event) => {
|
|
156
|
+
if (event.key === 'Enter' && !event.nativeEvent.isComposing) void submit()
|
|
157
|
+
}}
|
|
158
|
+
/>
|
|
159
|
+
{error && <p role="alert" className="text-xs text-destructive">{error}</p>}
|
|
160
|
+
</div>
|
|
161
|
+
<OverlayScrollbar target={scroller} className="inset-y-0" />
|
|
162
|
+
</div>
|
|
154
163
|
<DialogFooter>
|
|
155
164
|
<Button variant="outline" onClick={requestClose}>{t('sandbox.common.cancel')}</Button>
|
|
156
165
|
<Button disabled={busy} onClick={submit}>{busy ? t('sandbox.common.saving') : t('sandbox.common.save')}</Button>
|
|
@@ -89,6 +89,8 @@ export class WorkspaceStore {
|
|
|
89
89
|
private refreshTask: Promise<void> | undefined
|
|
90
90
|
private pendingRefresh = false
|
|
91
91
|
private mediaLoading = new Set<string>()
|
|
92
|
+
private readEpoch = 0
|
|
93
|
+
private historyTasks = new Map<string, Promise<void>>()
|
|
92
94
|
private disposed = false
|
|
93
95
|
|
|
94
96
|
constructor(readonly spaceId: string | undefined) {}
|
|
@@ -108,10 +110,21 @@ export class WorkspaceStore {
|
|
|
108
110
|
/** 只停止写入视图;监听器由 `useSyncExternalStore` 自行退订,清空会误删重挂载后的订阅。 */
|
|
109
111
|
dispose() {
|
|
110
112
|
this.disposed = true
|
|
113
|
+
this.invalidateReads()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private invalidateReads() {
|
|
117
|
+
this.readEpoch++
|
|
118
|
+
this.historyTasks.clear()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private isCurrentRead(epoch: number, operatorId: string) {
|
|
122
|
+
return !this.disposed && epoch === this.readEpoch && operatorId === this.view.currentOperatorId
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
private set(patch: Partial<WorkspaceView>) {
|
|
114
126
|
if (this.disposed) return
|
|
127
|
+
if ('currentOperatorId' in patch && patch.currentOperatorId !== this.view.currentOperatorId) this.invalidateReads()
|
|
115
128
|
this.view = { ...this.view, ...patch }
|
|
116
129
|
for (const listener of this.listeners) listener()
|
|
117
130
|
}
|
|
@@ -321,50 +334,72 @@ export class WorkspaceStore {
|
|
|
321
334
|
return invoke('onebot-sandbox.search-conversation-messages', this.scoped({ ...input, operatorId: this.requireOperatorId() }))
|
|
322
335
|
}
|
|
323
336
|
|
|
337
|
+
/** 视角切换或卸载后的结果返回 undefined,调用方不能继续展示旧转发内容。 */
|
|
324
338
|
async getForwardMessage(input: { forwardId?: string, messageId?: string }) {
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
339
|
+
if (this.disposed) return
|
|
340
|
+
const operatorId = this.requireOperatorId()
|
|
341
|
+
const epoch = this.readEpoch
|
|
342
|
+
try {
|
|
343
|
+
const forward = await invoke('onebot-sandbox.get-forward-message', this.scoped({ ...input, operatorId }))
|
|
344
|
+
if (!this.isCurrentRead(epoch, operatorId)) return
|
|
345
|
+
const workspace = this.view.workspace
|
|
346
|
+
if (!workspace) return
|
|
347
|
+
if (!workspace.snapshot.forwards.some(({ id }) => id === forward.id)) {
|
|
348
|
+
this.set({ workspace: { ...workspace, snapshot: { ...workspace.snapshot, forwards: [...workspace.snapshot.forwards, forward] } } })
|
|
349
|
+
void this.loadVisibleMedia()
|
|
350
|
+
}
|
|
351
|
+
return forward
|
|
352
|
+
} catch (error) {
|
|
353
|
+
if (this.isCurrentRead(epoch, operatorId)) throw error
|
|
330
354
|
}
|
|
331
|
-
return forward
|
|
332
355
|
}
|
|
333
356
|
|
|
334
|
-
/**
|
|
335
|
-
|
|
357
|
+
/** 同一视角、同一会话复用在途分页;切换视角或卸载会使旧请求失效。 */
|
|
358
|
+
loadEarlierMessages(conversationId: string): Promise<void> {
|
|
336
359
|
const workspace = this.view.workspace
|
|
337
|
-
if (!workspace) return
|
|
360
|
+
if (this.disposed || !workspace) return Promise.resolve()
|
|
361
|
+
const pending = this.historyTasks.get(conversationId)
|
|
362
|
+
if (pending) return pending
|
|
338
363
|
const beforeMessageId = readConversationMessageIds(workspace.snapshot, conversationId)[0]
|
|
339
|
-
if (!beforeMessageId) return
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
if (!beforeMessageId) return Promise.resolve()
|
|
365
|
+
const operatorId = this.requireOperatorId()
|
|
366
|
+
const epoch = this.readEpoch
|
|
367
|
+
const task = (async () => {
|
|
368
|
+
try {
|
|
369
|
+
const history = await invoke('onebot-sandbox.message-history', this.scoped({ operatorId, conversationId, beforeMessageId, limit: 50 }))
|
|
370
|
+
if (!this.isCurrentRead(epoch, operatorId)) return
|
|
371
|
+
const current = this.view.workspace
|
|
372
|
+
// 会话可能已被清空、删除或重新裁剪,不把旧分页接到另一条边界上。
|
|
373
|
+
if (!current || readConversationMessageIds(current.snapshot, conversationId)[0] !== beforeMessageId) return
|
|
374
|
+
const snapshot = current.snapshot
|
|
375
|
+
const knownIds = new Set(snapshot.messages.map(({ id }) => id))
|
|
376
|
+
const knownForwardIds = new Set(snapshot.forwards.map(({ id }) => id))
|
|
377
|
+
const prepend = <T extends { id: string, messageIds: string[] }>(rows: T[]) => rows.map((row) => row.id === conversationId ? {
|
|
378
|
+
...row,
|
|
379
|
+
messageIds: [...new Set([...history.messages.map(({ id }) => id), ...row.messageIds])],
|
|
380
|
+
hasMoreMessages: !!history.nextBeforeMessageId,
|
|
381
|
+
} : row)
|
|
382
|
+
this.set({
|
|
383
|
+
workspace: {
|
|
384
|
+
...current,
|
|
385
|
+
snapshot: {
|
|
386
|
+
...snapshot,
|
|
387
|
+
conversations: prepend(snapshot.conversations),
|
|
388
|
+
conversationInstances: prepend(snapshot.conversationInstances),
|
|
389
|
+
messages: [...history.messages.filter(({ id }) => !knownIds.has(id)), ...snapshot.messages],
|
|
390
|
+
forwards: [...snapshot.forwards, ...(history.forwards ?? []).filter(({ id }) => !knownForwardIds.has(id))],
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
})
|
|
394
|
+
void this.loadVisibleMedia()
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (this.isCurrentRead(epoch, operatorId)) throw error
|
|
397
|
+
}
|
|
398
|
+
})().finally(() => {
|
|
399
|
+
if (this.historyTasks.get(conversationId) === task) this.historyTasks.delete(conversationId)
|
|
366
400
|
})
|
|
367
|
-
|
|
401
|
+
this.historyTasks.set(conversationId, task)
|
|
402
|
+
return task
|
|
368
403
|
}
|
|
369
404
|
|
|
370
405
|
resolveAvatar(reference: string | undefined) {
|
|
@@ -386,7 +421,8 @@ export class WorkspaceStore {
|
|
|
386
421
|
this.mediaLoading.add(mediaId)
|
|
387
422
|
try {
|
|
388
423
|
const content = await invoke('onebot-sandbox.media-content', this.scoped({ operatorId, mediaId }))
|
|
389
|
-
const
|
|
424
|
+
const playable = content.preview ?? content
|
|
425
|
+
const url = `data:${playable.mimeType};base64,${playable.dataBase64}`
|
|
390
426
|
rememberMedia(mediaId, url, avatarIds.has(mediaId))
|
|
391
427
|
const { [mediaId]: _, ...failures } = this.view.mediaFailures
|
|
392
428
|
this.set({ media: { ...this.view.media, [mediaId]: url }, mediaFailures: failures })
|
|
@@ -405,7 +441,7 @@ function visibleMediaIdsOf(snapshot: SandboxSnapshot) {
|
|
|
405
441
|
.flatMap((reference) => mediaIdOf(reference) ?? []))
|
|
406
442
|
const messageMediaIds = new Set([
|
|
407
443
|
...snapshot.messages.flatMap(({ media }) => media?.map(({ id }) => id) ?? []),
|
|
408
|
-
...
|
|
444
|
+
...snapshot.forwards.flatMap(({ nodes }) => nodes.flatMap(({ media }) => media?.map(({ id }) => id) ?? [])),
|
|
409
445
|
])
|
|
410
446
|
return { avatarIds, messageMediaIds }
|
|
411
447
|
}
|