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,388 @@
|
|
|
1
|
+
import { callAction, type Translate } from '@chatluna/ui-client/client'
|
|
2
|
+
import { readStored, writeStored } from '@chatluna/ui-storage'
|
|
3
|
+
import {
|
|
4
|
+
includesConversationParticipant,
|
|
5
|
+
listConversations,
|
|
6
|
+
readConversationMessageIds,
|
|
7
|
+
type ResolvedConversation,
|
|
8
|
+
} from '../../src/conversation-resolution'
|
|
9
|
+
import type { SandboxConsoleEvents } from '../../src/console-contract'
|
|
10
|
+
import type {
|
|
11
|
+
ManageSandboxEnvironmentInput,
|
|
12
|
+
SandboxFriendAction,
|
|
13
|
+
SandboxGroupAction,
|
|
14
|
+
SandboxMessage,
|
|
15
|
+
SandboxSnapshot,
|
|
16
|
+
SandboxWorkspaceState,
|
|
17
|
+
} from '../../src/types'
|
|
18
|
+
import { resolveWorkspaceSelection, type SandboxWorkspaceSelection } from './state'
|
|
19
|
+
|
|
20
|
+
type Endpoint = keyof SandboxConsoleEvents
|
|
21
|
+
type InputOf<K extends Endpoint> = Parameters<SandboxConsoleEvents[K]>[0]
|
|
22
|
+
type OutputOf<K extends Endpoint> = Awaited<ReturnType<SandboxConsoleEvents[K]>>
|
|
23
|
+
|
|
24
|
+
/** 控制台契约的统一调用口:错误只保留服务端给出的第一行说明,不带错误码前缀。 */
|
|
25
|
+
export async function invoke<K extends Endpoint>(name: K, input: InputOf<K>): Promise<OutputOf<K>> {
|
|
26
|
+
try {
|
|
27
|
+
// 无参端点的入参类型是 undefined,action 请求体仍需一个对象。
|
|
28
|
+
return await callAction(name, (input ?? {}) as never) as OutputOf<K>
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(errorText(error))
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 错误兜底文案的翻译:store 与 `invoke` 不在 React 树里,拿不到 `useT`。沙盒根组件每次渲染登记当前语言的
|
|
36
|
+
* `t`(`app.tsx`),这里的兜底与 store 自己抛出的错误据此按界面语言显示。
|
|
37
|
+
*/
|
|
38
|
+
let translate: Translate = (key) => key
|
|
39
|
+
|
|
40
|
+
export function bindStoreTranslator(t: Translate) {
|
|
41
|
+
translate = t
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function errorText(error: unknown, fallback = translate('sandbox.common.failed')) {
|
|
45
|
+
const message = error instanceof Error ? error.message : typeof error === 'string' ? error : ''
|
|
46
|
+
return message.trim().split(/\r?\n/, 1)[0]?.replace(/^Error:\s*/, '') || fallback
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const MEDIA_REFERENCE = /^sandbox-media:\/\/([a-f0-9]{32})$/
|
|
50
|
+
|
|
51
|
+
export function mediaIdOf(reference: string | undefined) {
|
|
52
|
+
return reference?.match(MEDIA_REFERENCE)?.[1]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function selectionKey(spaceId: string | undefined) {
|
|
56
|
+
return `chatluna.onebot-sandbox.selection.${spaceId ?? 'main'}`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readSelection(spaceId: string | undefined): SandboxWorkspaceSelection {
|
|
60
|
+
const value = readStored(selectionKey(spaceId))
|
|
61
|
+
if (!value || typeof value !== 'object') return {}
|
|
62
|
+
const record = value as Record<string, unknown>
|
|
63
|
+
return {
|
|
64
|
+
currentOperatorId: typeof record['currentOperatorId'] === 'string' ? record['currentOperatorId'] : undefined,
|
|
65
|
+
activeConversationId: typeof record['activeConversationId'] === 'string' ? record['activeConversationId'] : undefined,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface WorkspaceView {
|
|
70
|
+
workspace?: SandboxWorkspaceState
|
|
71
|
+
currentOperatorId?: string
|
|
72
|
+
activeConversationId?: string
|
|
73
|
+
loadError?: string
|
|
74
|
+
media: Readonly<Record<string, string>>
|
|
75
|
+
mediaFailures: Readonly<Record<string, true>>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 一个沙盒空间的工作区状态:权威快照来自服务端,当前操作者与选中会话只存在浏览器本地。
|
|
80
|
+
*
|
|
81
|
+
* 每次变更端点都返回完整工作区,因此这里只做整份替换;选中按新快照重新解析,删除了正选中的
|
|
82
|
+
* 会话或操作者时自然回退到第一个可见项。
|
|
83
|
+
*/
|
|
84
|
+
export class WorkspaceStore {
|
|
85
|
+
private view: WorkspaceView = { media: {}, mediaFailures: {} }
|
|
86
|
+
private listeners = new Set<() => void>()
|
|
87
|
+
private refreshTask: Promise<void> | undefined
|
|
88
|
+
private pendingRefresh = false
|
|
89
|
+
private mediaLoading = new Set<string>()
|
|
90
|
+
private disposed = false
|
|
91
|
+
|
|
92
|
+
constructor(readonly spaceId: string | undefined) {}
|
|
93
|
+
|
|
94
|
+
subscribe = (listener: () => void) => {
|
|
95
|
+
this.listeners.add(listener)
|
|
96
|
+
return () => this.listeners.delete(listener)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getView = () => this.view
|
|
100
|
+
|
|
101
|
+
/** StrictMode 会卸载再挂载同一个 store,挂载时要撤销上一次 {@link dispose}。 */
|
|
102
|
+
activate() {
|
|
103
|
+
this.disposed = false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 只停止写入视图;监听器由 `useSyncExternalStore` 自行退订,清空会误删重挂载后的订阅。 */
|
|
107
|
+
dispose() {
|
|
108
|
+
this.disposed = true
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private set(patch: Partial<WorkspaceView>) {
|
|
112
|
+
if (this.disposed) return
|
|
113
|
+
this.view = { ...this.view, ...patch }
|
|
114
|
+
for (const listener of this.listeners) listener()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private scoped<T extends object>(input: T): T & { spaceId?: string } {
|
|
118
|
+
return this.spaceId ? { ...input, spaceId: this.spaceId } : input
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get snapshot(): SandboxSnapshot | undefined {
|
|
122
|
+
return this.view.workspace?.snapshot
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
requireOperatorId() {
|
|
126
|
+
const operatorId = this.view.currentOperatorId
|
|
127
|
+
if (!operatorId) throw new Error(translate('sandbox.error.noOperator'))
|
|
128
|
+
return operatorId
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private saveSelection() {
|
|
132
|
+
writeStored(selectionKey(this.spaceId), {
|
|
133
|
+
currentOperatorId: this.view.currentOperatorId,
|
|
134
|
+
activeConversationId: this.view.activeConversationId,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private replaceWorkspace(workspace: SandboxWorkspaceState, preferred: SandboxWorkspaceSelection = {}, persist = true) {
|
|
139
|
+
const selection = resolveWorkspaceSelection(workspace.snapshot, {
|
|
140
|
+
currentOperatorId: preferred.currentOperatorId ?? this.view.currentOperatorId,
|
|
141
|
+
activeConversationId: preferred.activeConversationId ?? this.view.activeConversationId,
|
|
142
|
+
})
|
|
143
|
+
this.set({
|
|
144
|
+
workspace,
|
|
145
|
+
currentOperatorId: selection.currentOperatorId,
|
|
146
|
+
activeConversationId: selection.activeConversationId,
|
|
147
|
+
loadError: undefined,
|
|
148
|
+
})
|
|
149
|
+
if (persist) this.saveSelection()
|
|
150
|
+
void this.loadVisibleMedia()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 用现成的工作区数据直接填充视图,供 AI 测试空间总览的缩略图使用:沿用该空间上次记住的选择,
|
|
155
|
+
* 但不回写,缩略图不能改动用户真正进入空间时看到的会话。
|
|
156
|
+
*/
|
|
157
|
+
seed(workspace: SandboxWorkspaceState) {
|
|
158
|
+
this.replaceWorkspace(workspace, readSelection(this.spaceId), false)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async load() {
|
|
162
|
+
const stored = readSelection(this.spaceId)
|
|
163
|
+
try {
|
|
164
|
+
let workspace: SandboxWorkspaceState
|
|
165
|
+
try {
|
|
166
|
+
workspace = await invoke('onebot-sandbox.workspace', this.scoped(stored.currentOperatorId ? { operatorId: stored.currentOperatorId } : {}))
|
|
167
|
+
} catch {
|
|
168
|
+
// 本地记住的操作者可能已被删除;退回默认视角再解析一次选择。
|
|
169
|
+
workspace = await invoke('onebot-sandbox.workspace', this.scoped({}))
|
|
170
|
+
}
|
|
171
|
+
this.replaceWorkspace(workspace, stored)
|
|
172
|
+
} catch (error) {
|
|
173
|
+
this.set({ loadError: errorText(error, translate('sandbox.error.loadWorkspace')) })
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 场景变更广播只是失效信号;多次信号合并成串行的若干次读取,不会并发打满。 */
|
|
178
|
+
notifySceneChanged() {
|
|
179
|
+
this.pendingRefresh = true
|
|
180
|
+
if (this.refreshTask) return
|
|
181
|
+
this.refreshTask = (async () => {
|
|
182
|
+
try {
|
|
183
|
+
while (this.pendingRefresh && !this.disposed) {
|
|
184
|
+
this.pendingRefresh = false
|
|
185
|
+
const operatorId = this.view.currentOperatorId
|
|
186
|
+
try {
|
|
187
|
+
const workspace = await invoke('onebot-sandbox.workspace', this.scoped(operatorId ? { operatorId } : {}))
|
|
188
|
+
if (workspace.snapshot.revision >= (this.snapshot?.revision ?? 0)) this.replaceWorkspace(workspace)
|
|
189
|
+
} catch {
|
|
190
|
+
// 刷新失败保留当前画面,下一次信号会再试。
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} finally {
|
|
194
|
+
this.refreshTask = undefined
|
|
195
|
+
}
|
|
196
|
+
})()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
selectConversation(conversationId: string) {
|
|
200
|
+
this.set({ activeConversationId: conversationId })
|
|
201
|
+
this.saveSelection()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async selectOperator(participantId: string) {
|
|
205
|
+
const workspace = await invoke('onebot-sandbox.workspace', this.scoped({ operatorId: participantId }))
|
|
206
|
+
this.set({ currentOperatorId: participantId })
|
|
207
|
+
this.replaceWorkspace(workspace, { currentOperatorId: participantId })
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 统一形态的变更:注入当前操作者与空间定域,用返回的完整工作区整份替换。 */
|
|
211
|
+
private async mutate<K extends Endpoint>(name: K, input: object): Promise<OutputOf<K>> {
|
|
212
|
+
const result = await invoke(name, this.scoped({ ...input, operatorId: this.requireOperatorId() }) as InputOf<K>)
|
|
213
|
+
if (result && typeof result === 'object' && 'snapshot' in result) this.replaceWorkspace(result as SandboxWorkspaceState)
|
|
214
|
+
return result
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
sendMessage(input: { conversationId: string, content: string, replyToMessageId?: string }) {
|
|
218
|
+
return this.mutate('onebot-sandbox.send-message', input)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
sendMediaMessage(input: { conversationId: string, content?: string, replyToMessageId?: string, media: InputOf<'onebot-sandbox.send-media-message'>['media'] }) {
|
|
222
|
+
return this.mutate('onebot-sandbox.send-media-message', input)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
sendForwardMessage(input: { conversationId: string, messageIds: string[] }) {
|
|
226
|
+
return this.mutate('onebot-sandbox.send-forward-message', input)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
recallMessage(input: { conversationId: string, messageId: string }) {
|
|
230
|
+
return this.mutate('onebot-sandbox.recall-message', input)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
clearConversationMessages(input: { conversationId: string }) {
|
|
234
|
+
return this.mutate('onebot-sandbox.clear-conversation-messages', input)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
setMessageReaction(input: { conversationId: string, messageId: string, emojiId: string, enabled: boolean }) {
|
|
238
|
+
return this.mutate('onebot-sandbox.set-message-reaction', input)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async createConversationInstance(rootConversationId: string) {
|
|
242
|
+
const { conversationId } = await this.mutate('onebot-sandbox.create-conversation-instance', { rootConversationId })
|
|
243
|
+
this.selectConversation(conversationId)
|
|
244
|
+
return conversationId
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async branchConversationInstance(input: { conversationId: string, messageId: string }) {
|
|
248
|
+
const { conversationId } = await this.mutate('onebot-sandbox.branch-conversation-instance', input)
|
|
249
|
+
this.selectConversation(conversationId)
|
|
250
|
+
return conversationId
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
renameConversationInstance(input: { conversationId: string, title: string }) {
|
|
254
|
+
return this.mutate('onebot-sandbox.rename-conversation-instance', input)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
deleteConversationInstance(conversationId: string) {
|
|
258
|
+
return this.mutate('onebot-sandbox.delete-conversation-instance', { conversationId })
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
performFriendAction(input: SandboxFriendAction) {
|
|
262
|
+
return this.mutate('onebot-sandbox.friend-action', input)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
performGroupAction(input: SandboxGroupAction) {
|
|
266
|
+
return this.mutate('onebot-sandbox.group-action', input)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
handleRelationshipRequest(requestId: string, approve: boolean) {
|
|
270
|
+
const request = this.snapshot?.requests.find(({ id }) => id === requestId)
|
|
271
|
+
if (!request) throw new Error(translate('sandbox.error.requestMissing'))
|
|
272
|
+
return request.type === 'group'
|
|
273
|
+
? this.performGroupAction({ action: 'handle-request', requestId, approve })
|
|
274
|
+
: this.performFriendAction({ action: 'handle-request', requestId, approve })
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
setGroupAnnouncement(input: { groupId: string, content: string }) {
|
|
278
|
+
return this.mutate('onebot-sandbox.set-group-announcement', input)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
deleteGroupAnnouncement(input: { groupId: string, announcementId: string }) {
|
|
282
|
+
return this.mutate('onebot-sandbox.delete-group-announcement', input)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** 环境管理不带操作者;删除的不是当前操作者时,再按当前视角取一次,保持可见性口径一致。 */
|
|
286
|
+
async manageEnvironment(input: ManageSandboxEnvironmentInput) {
|
|
287
|
+
const operatorId = this.view.currentOperatorId
|
|
288
|
+
const managed = await invoke('onebot-sandbox.manage-environment', this.scoped(input))
|
|
289
|
+
const deletesOperator = (input.action === 'delete-user' || input.action === 'delete-bot') && input.data.id === operatorId
|
|
290
|
+
this.replaceWorkspace(operatorId && !deletesOperator
|
|
291
|
+
? await invoke('onebot-sandbox.workspace', this.scoped({ operatorId }))
|
|
292
|
+
: managed)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
searchConversationMessages(input: Omit<InputOf<'onebot-sandbox.search-conversation-messages'>, 'operatorId'>) {
|
|
296
|
+
return invoke('onebot-sandbox.search-conversation-messages', this.scoped({ ...input, operatorId: this.requireOperatorId() }))
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async getForwardMessage(input: { forwardId?: string, messageId?: string }) {
|
|
300
|
+
const forward = await invoke('onebot-sandbox.get-forward-message', this.scoped({ ...input, operatorId: this.requireOperatorId() }))
|
|
301
|
+
const workspace = this.view.workspace
|
|
302
|
+
if (workspace && !(workspace.snapshot.forwards ?? []).some(({ id }) => id === forward.id)) {
|
|
303
|
+
this.set({ workspace: { ...workspace, snapshot: { ...workspace.snapshot, forwards: [...(workspace.snapshot.forwards ?? []), forward] } } })
|
|
304
|
+
void this.loadVisibleMedia()
|
|
305
|
+
}
|
|
306
|
+
return forward
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** 向前翻历史:服务端只给最近一段,旧消息按最早一条的 ID 继续取,拼到会话头部。 */
|
|
310
|
+
async loadEarlierMessages(conversationId: string) {
|
|
311
|
+
const workspace = this.view.workspace
|
|
312
|
+
if (!workspace) return
|
|
313
|
+
const beforeMessageId = readConversationMessageIds(workspace.snapshot, conversationId)[0]
|
|
314
|
+
if (!beforeMessageId) return
|
|
315
|
+
const history = await invoke('onebot-sandbox.message-history', this.scoped({
|
|
316
|
+
operatorId: this.requireOperatorId(),
|
|
317
|
+
conversationId,
|
|
318
|
+
beforeMessageId,
|
|
319
|
+
limit: 50,
|
|
320
|
+
}))
|
|
321
|
+
const current = this.view.workspace ?? workspace
|
|
322
|
+
const snapshot = current.snapshot
|
|
323
|
+
const knownIds = new Set(snapshot.messages.map(({ id }) => id))
|
|
324
|
+
const knownForwardIds = new Set((snapshot.forwards ?? []).map(({ id }) => id))
|
|
325
|
+
const prepend = <T extends { id: string, messageIds: string[] }>(rows: T[]) => rows.map((row) => row.id === conversationId ? {
|
|
326
|
+
...row,
|
|
327
|
+
messageIds: [...history.messages.map(({ id }) => id), ...row.messageIds],
|
|
328
|
+
hasMoreMessages: !!history.nextBeforeMessageId,
|
|
329
|
+
} : row)
|
|
330
|
+
this.set({
|
|
331
|
+
workspace: {
|
|
332
|
+
...current,
|
|
333
|
+
snapshot: {
|
|
334
|
+
...snapshot,
|
|
335
|
+
conversations: prepend(snapshot.conversations),
|
|
336
|
+
conversationInstances: prepend(snapshot.conversationInstances ?? []),
|
|
337
|
+
messages: [...history.messages.filter(({ id }) => !knownIds.has(id)), ...snapshot.messages],
|
|
338
|
+
forwards: [...(snapshot.forwards ?? []), ...(history.forwards ?? []).filter(({ id }) => !knownForwardIds.has(id))],
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
})
|
|
342
|
+
void this.loadVisibleMedia()
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
resolveAvatar(reference: string | undefined) {
|
|
346
|
+
const id = mediaIdOf(reference)
|
|
347
|
+
return id ? this.view.media[id] ?? '' : reference ?? ''
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** 头像与消息媒体都是受控引用;按需拉取 Base64 并缓存为 Data URL,失败只标记不重试风暴。 */
|
|
351
|
+
async loadVisibleMedia() {
|
|
352
|
+
const snapshot = this.snapshot
|
|
353
|
+
const operatorId = this.view.currentOperatorId
|
|
354
|
+
if (!snapshot || !operatorId) return
|
|
355
|
+
const ids = [
|
|
356
|
+
...snapshot.messages.flatMap(({ media }) => media?.map(({ id }) => id) ?? []),
|
|
357
|
+
...(snapshot.forwards ?? []).flatMap(({ nodes }) => nodes.flatMap(({ media }) => media?.map(({ id }) => id) ?? [])),
|
|
358
|
+
...[...snapshot.participants.map(({ avatar }) => avatar), ...snapshot.groups.map(({ avatar }) => avatar)]
|
|
359
|
+
.flatMap((reference) => mediaIdOf(reference) ?? []),
|
|
360
|
+
]
|
|
361
|
+
const missing = [...new Set(ids)].filter((id) => !this.view.media[id] && !this.mediaLoading.has(id))
|
|
362
|
+
await Promise.all(missing.map(async (mediaId) => {
|
|
363
|
+
this.mediaLoading.add(mediaId)
|
|
364
|
+
try {
|
|
365
|
+
const content = await invoke('onebot-sandbox.media-content', this.scoped({ operatorId, mediaId }))
|
|
366
|
+
const { [mediaId]: _, ...failures } = this.view.mediaFailures
|
|
367
|
+
this.set({ media: { ...this.view.media, [mediaId]: `data:${content.mimeType};base64,${content.dataBase64}` }, mediaFailures: failures })
|
|
368
|
+
} catch {
|
|
369
|
+
this.set({ mediaFailures: { ...this.view.mediaFailures, [mediaId]: true } })
|
|
370
|
+
} finally {
|
|
371
|
+
this.mediaLoading.delete(mediaId)
|
|
372
|
+
}
|
|
373
|
+
}))
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** 当前操作者可见的全部会话(根会话与实例),与侧栏、选择恢复同一口径。 */
|
|
378
|
+
export function visibleConversationsOf(snapshot: SandboxSnapshot, operatorId: string | undefined): ResolvedConversation[] {
|
|
379
|
+
if (!operatorId) return []
|
|
380
|
+
return listConversations(snapshot).filter((conversation) => includesConversationParticipant(snapshot, conversation, operatorId))
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function conversationMessagesOf(snapshot: SandboxSnapshot, conversationId: string | undefined): SandboxMessage[] {
|
|
384
|
+
if (!conversationId) return []
|
|
385
|
+
const ids = readConversationMessageIds(snapshot, conversationId)
|
|
386
|
+
const byId = new Map(snapshot.messages.map((message) => [message.id, message]))
|
|
387
|
+
return ids.flatMap((id) => byId.get(id) ?? [])
|
|
388
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { errorText, invoke } from './store'
|
|
3
|
+
import type { SandboxTestSpaceSummary } from '../../src/test-spaces'
|
|
4
|
+
|
|
5
|
+
/** AI 测试空间列表(含各自快照);环境管理与 OneBot 调试按它合成跨空间的机器人目录。 */
|
|
6
|
+
export function useTestSpaces() {
|
|
7
|
+
const [spaces, setSpaces] = React.useState<SandboxTestSpaceSummary[]>([])
|
|
8
|
+
const [error, setError] = React.useState('')
|
|
9
|
+
const reload = React.useCallback(async () => {
|
|
10
|
+
try {
|
|
11
|
+
setSpaces(await invoke('onebot-sandbox.test-spaces', undefined))
|
|
12
|
+
setError('')
|
|
13
|
+
} catch (failure) {
|
|
14
|
+
setError(errorText(failure))
|
|
15
|
+
}
|
|
16
|
+
}, [])
|
|
17
|
+
React.useEffect(() => {
|
|
18
|
+
void reload()
|
|
19
|
+
}, [reload])
|
|
20
|
+
return { spaces, error, reload }
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"client/app.tsx": {
|
|
3
|
+
"file": "app-63rfTh6w.js",
|
|
4
|
+
"name": "app",
|
|
5
|
+
"src": "client/app.tsx",
|
|
6
|
+
"isDynamicEntry": true
|
|
7
|
+
},
|
|
8
|
+
"client/index.ts": {
|
|
9
|
+
"file": "client.js",
|
|
10
|
+
"name": "index",
|
|
11
|
+
"src": "client/index.ts",
|
|
12
|
+
"isEntry": true,
|
|
13
|
+
"dynamicImports": [
|
|
14
|
+
"client/app.tsx"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"style.css": {
|
|
18
|
+
"file": "client.css",
|
|
19
|
+
"src": "style.css"
|
|
20
|
+
}
|
|
21
|
+
}
|