@zhin.js/adapter-sandbox 1.1.19 → 1.1.21
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/CHANGELOG.md +69 -0
- package/README.md +55 -7
- package/adapters/sandbox/index.js +3 -12
- package/adapters/sandbox/index.ts +2 -12
- package/lib/adapter.d.ts +17 -0
- package/lib/adapter.js +17 -0
- package/lib/client.d.ts +7 -14
- package/lib/client.js +12 -11
- package/lib/endpoint.d.ts +16 -13
- package/lib/endpoint.js +171 -138
- package/lib/index.d.ts +2 -1
- package/lib/index.js +2 -1
- package/lib/protocol.d.ts +22 -1
- package/lib/protocol.js +34 -4
- package/package.json +18 -18
- package/pages/index/ConversationRecoveryPanel.js +131 -0
- package/pages/index/ConversationRecoveryPanel.tsx +134 -0
- package/pages/index/SandboxChat.js +319 -111
- package/pages/index/SandboxChat.tsx +356 -126
- package/pages/index/agentTrace.js +21 -10
- package/pages/index/agentTrace.ts +24 -10
- package/pages/index/conversationRecovery.js +40 -0
- package/pages/index/conversationRecovery.ts +68 -0
- package/pages/index/index.js +5 -5
- package/pages/index/index.tsx +5 -5
- package/pages/index/messages.js +24 -6
- package/pages/index/messages.ts +24 -6
- package/pages/index/playgroundState.js +51 -1
- package/pages/index/playgroundState.ts +61 -1
- package/pages/index/sandboxTransport.js +25 -0
- package/pages/index/sandboxTransport.ts +35 -0
- package/pages/index/useSandboxHistory.js +161 -0
- package/pages/index/useSandboxHistory.ts +164 -0
- package/pages/index/workspaceDirectory.js +49 -0
- package/pages/index/workspaceDirectory.ts +74 -0
- package/pages/index/workspaceDirectoryState.js +120 -0
- package/pages/index/workspaceDirectoryState.ts +124 -0
- package/src/adapter.ts +22 -0
- package/src/client.ts +16 -18
- package/src/endpoint.ts +179 -140
- package/src/index.ts +1 -1
- package/src/protocol.ts +59 -13
|
@@ -28,7 +28,13 @@ export interface PlaygroundMessage {
|
|
|
28
28
|
readonly senderName: string;
|
|
29
29
|
readonly content: MessageSegment[];
|
|
30
30
|
readonly timestamp: number;
|
|
31
|
+
/** Legacy field name: the choice was submitted; this never reports policy acceptance. */
|
|
31
32
|
readonly interactionResolved?: boolean;
|
|
33
|
+
/** Stored controls are display data; only the live pending authority may accept their answers. */
|
|
34
|
+
readonly interactionReadOnly?: boolean;
|
|
35
|
+
readonly historySequence?: number;
|
|
36
|
+
readonly recalled?: boolean;
|
|
37
|
+
readonly recalledMessageId?: string;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export interface PlaygroundState {
|
|
@@ -81,7 +87,7 @@ export function loadPlaygroundState(
|
|
|
81
87
|
const sessionKeys = new Set(sessions.map(sessionIdentity));
|
|
82
88
|
const messages = Array.isArray(parsed.messages)
|
|
83
89
|
? parsed.messages.map(parseMessage).filter((item): item is PlaygroundMessage => (
|
|
84
|
-
|
|
90
|
+
item !== undefined && sessionKeys.has(sessionIdentity({ id: item.channelId, type: item.channelType }))
|
|
85
91
|
))
|
|
86
92
|
: [];
|
|
87
93
|
const requestedActive = typeof parsed.activeSessionId === 'string'
|
|
@@ -160,9 +166,51 @@ function parseMessage(value: unknown): PlaygroundMessage | undefined {
|
|
|
160
166
|
content: item.content as MessageSegment[],
|
|
161
167
|
timestamp: Number.isFinite(item.timestamp) ? Number(item.timestamp) : Date.now(),
|
|
162
168
|
...(item.interactionResolved === true ? { interactionResolved: true } : {}),
|
|
169
|
+
...(hasPlaygroundKeyboard(item.content as MessageSegment[]) ? { interactionReadOnly: true } : {}),
|
|
170
|
+
...(Number.isSafeInteger(item.historySequence) && Number(item.historySequence) > 0 ? { historySequence: Number(item.historySequence) } : {}),
|
|
171
|
+
...(item.recalled === true ? { recalled: true } : {}),
|
|
172
|
+
...(typeof item.recalledMessageId === 'string' ? { recalledMessageId: item.recalledMessageId } : {}),
|
|
163
173
|
};
|
|
164
174
|
}
|
|
165
175
|
|
|
176
|
+
export function hasPlaygroundKeyboard(content: readonly MessageSegment[]): boolean {
|
|
177
|
+
return content.some(segment => segment?.type === 'keyboard' || (segment?.type === 'forward'
|
|
178
|
+
&& Array.isArray(segment.data?.entries) && segment.data.entries.some((entry: { segments?: MessageSegment[] }) =>
|
|
179
|
+
Array.isArray(entry?.segments) && hasPlaygroundKeyboard(entry.segments))));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Retire only controls previously issued by the current authoritative prompt reader. */
|
|
183
|
+
export function retirePlaygroundInteractions(
|
|
184
|
+
current: readonly PlaygroundMessage[],
|
|
185
|
+
scene: Pick<PlaygroundSession, 'id' | 'type'>,
|
|
186
|
+
retiredSegments: readonly MessageSegment[],
|
|
187
|
+
): PlaygroundMessage[] {
|
|
188
|
+
const retired = new Set(keyboardPayloads(retiredSegments));
|
|
189
|
+
return current.map(message => message.type === 'received' && message.channelType === scene.type && message.channelId === scene.id
|
|
190
|
+
&& message.interactionReadOnly !== true && keyboardPayloads(message.content).some(payload => retired.has(payload))
|
|
191
|
+
? { ...message, interactionReadOnly: true } : message);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function keyboardPayloads(segments: readonly MessageSegment[]): string[] {
|
|
195
|
+
const payloads: string[] = [];
|
|
196
|
+
for (const segment of segments) {
|
|
197
|
+
if (segment?.type === 'keyboard' && Array.isArray(segment.data?.rows)) {
|
|
198
|
+
for (const row of segment.data.rows) {
|
|
199
|
+
if (!Array.isArray(row)) continue;
|
|
200
|
+
for (const button of row) if (typeof button?.payload === 'string') payloads.push(button.payload);
|
|
201
|
+
}
|
|
202
|
+
} else if (segment?.type === 'forward') {
|
|
203
|
+
if (Array.isArray(segment.data?.entries)) {
|
|
204
|
+
for (const entry of segment.data.entries) if (Array.isArray(entry?.segments)) payloads.push(...keyboardPayloads(entry.segments));
|
|
205
|
+
}
|
|
206
|
+
if (Array.isArray(segment.data?.messages)) {
|
|
207
|
+
for (const batch of segment.data.messages) if (Array.isArray(batch)) payloads.push(...keyboardPayloads(batch));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return payloads;
|
|
212
|
+
}
|
|
213
|
+
|
|
166
214
|
function browserStorage(): PlaygroundStorage | undefined {
|
|
167
215
|
return typeof window === 'undefined' ? undefined : window.localStorage;
|
|
168
216
|
}
|
|
@@ -170,3 +218,15 @@ function browserStorage(): PlaygroundStorage | undefined {
|
|
|
170
218
|
function sessionIdentity(value: Pick<PlaygroundSession, 'id' | 'type'>): string {
|
|
171
219
|
return `${value.type}\0${value.id}`;
|
|
172
220
|
}
|
|
221
|
+
|
|
222
|
+
/** Socket echoes replace their local optimistic row, without crossing scenes or authors. */
|
|
223
|
+
export function mergePlaygroundMessage(
|
|
224
|
+
messages: readonly PlaygroundMessage[],
|
|
225
|
+
incoming: PlaygroundMessage,
|
|
226
|
+
): PlaygroundMessage[] {
|
|
227
|
+
const index = messages.findIndex(message => message.id === incoming.id
|
|
228
|
+
&& message.channelType === incoming.channelType && message.channelId === incoming.channelId
|
|
229
|
+
&& message.type === incoming.type);
|
|
230
|
+
return index < 0 ? [...messages, incoming]
|
|
231
|
+
: messages.map((message, offset) => offset === index ? { ...message, ...incoming } : message);
|
|
232
|
+
}
|
|
@@ -29,6 +29,10 @@ export function getSandboxAuthHeaders() {
|
|
|
29
29
|
const token = getSandboxBearerToken();
|
|
30
30
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
31
31
|
}
|
|
32
|
+
/** Capture once for a request owner; credentials stay in its closure, never UI state or storage. */
|
|
33
|
+
export function captureSandboxRequestContext() {
|
|
34
|
+
return Object.freeze({ apiBase: getSandboxApiBase(), headers: Object.freeze(getSandboxAuthHeaders()) });
|
|
35
|
+
}
|
|
32
36
|
/**
|
|
33
37
|
* Browser WebSocket cannot set Authorization reliably; pass token in query when needed.
|
|
34
38
|
* Uses stored Console API base so Remote Console (different origin) still hits the bot Host.
|
|
@@ -43,3 +47,24 @@ export function buildSandboxWebSocketUrl(base) {
|
|
|
43
47
|
wsUrl.searchParams.set('token', token);
|
|
44
48
|
return wsUrl.href;
|
|
45
49
|
}
|
|
50
|
+
export const SANDBOX_SCOPED_PROTOCOL = 'scoped-conversations-v1';
|
|
51
|
+
/** A successful send means queued on this socket, never accepted by the Agent or an approval policy. */
|
|
52
|
+
export function submitSandboxFrame(socket, frame) {
|
|
53
|
+
if (!socket || socket.readyState !== 1)
|
|
54
|
+
return false;
|
|
55
|
+
try {
|
|
56
|
+
socket.send(JSON.stringify(frame));
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** UUID v4 using Web Crypto, including ordinary HTTP LAN pages without randomUUID(). */
|
|
64
|
+
export function createSandboxMessageId() {
|
|
65
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
66
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
67
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
68
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
69
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
70
|
+
}
|
|
@@ -30,6 +30,16 @@ export function getSandboxAuthHeaders(): Record<string, string> {
|
|
|
30
30
|
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export interface SandboxRequestContext {
|
|
34
|
+
readonly apiBase: string;
|
|
35
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Capture once for a request owner; credentials stay in its closure, never UI state or storage. */
|
|
39
|
+
export function captureSandboxRequestContext(): SandboxRequestContext {
|
|
40
|
+
return Object.freeze({ apiBase: getSandboxApiBase(), headers: Object.freeze(getSandboxAuthHeaders()) });
|
|
41
|
+
}
|
|
42
|
+
|
|
33
43
|
/**
|
|
34
44
|
* Browser WebSocket cannot set Authorization reliably; pass token in query when needed.
|
|
35
45
|
* Uses stored Console API base so Remote Console (different origin) still hits the bot Host.
|
|
@@ -43,3 +53,28 @@ export function buildSandboxWebSocketUrl(base?: string): string {
|
|
|
43
53
|
if (token) wsUrl.searchParams.set('token', token);
|
|
44
54
|
return wsUrl.href;
|
|
45
55
|
}
|
|
56
|
+
|
|
57
|
+
export const SANDBOX_SCOPED_PROTOCOL = 'scoped-conversations-v1';
|
|
58
|
+
|
|
59
|
+
/** A successful send means queued on this socket, never accepted by the Agent or an approval policy. */
|
|
60
|
+
export function submitSandboxFrame(
|
|
61
|
+
socket: Pick<WebSocket, 'readyState' | 'send'> | null,
|
|
62
|
+
frame: Readonly<Record<string, unknown>>,
|
|
63
|
+
): boolean {
|
|
64
|
+
if (!socket || socket.readyState !== 1) return false;
|
|
65
|
+
try {
|
|
66
|
+
socket.send(JSON.stringify(frame));
|
|
67
|
+
return true;
|
|
68
|
+
} catch {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** UUID v4 using Web Crypto, including ordinary HTTP LAN pages without randomUUID(). */
|
|
74
|
+
export function createSandboxMessageId(): string {
|
|
75
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
76
|
+
bytes[6] = (bytes[6]! & 0x0f) | 0x40;
|
|
77
|
+
bytes[8] = (bytes[8]! & 0x3f) | 0x80;
|
|
78
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
79
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
80
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { hasPlaygroundKeyboard } from './playgroundState.js';
|
|
4
|
+
import { captureSandboxRequestContext } from './sandboxTransport.js';
|
|
5
|
+
import { sandboxText } from './messages.js';
|
|
6
|
+
/** Real message events only. A page applies to the latest live rows rather than replacing them. */
|
|
7
|
+
export function useSandboxHistory(binding, onHistory, locale = 'zh-CN') {
|
|
8
|
+
const key = binding ? JSON.stringify([captureSandboxRequestContext().apiBase, binding.connectionId, binding.sessionKey,
|
|
9
|
+
binding.scope.adapter, binding.scope.id, binding.scene.type, binding.scene.id, binding.ownerId]) : '';
|
|
10
|
+
const current = useRef(key);
|
|
11
|
+
current.current = key;
|
|
12
|
+
const receiver = useRef(onHistory);
|
|
13
|
+
receiver.current = onHistory;
|
|
14
|
+
const owner = useRef(undefined);
|
|
15
|
+
const [state, setState] = useState({ key, loading: false, hasMore: false, error: null });
|
|
16
|
+
const active = (read) => owner.current === read && current.current === read.key
|
|
17
|
+
&& !read.controller.signal.aborted && requestContextCurrent(read.context);
|
|
18
|
+
const load = useCallback((read, earlier) => {
|
|
19
|
+
if (!active(read) || earlier && !read.hasMore)
|
|
20
|
+
return Promise.resolve();
|
|
21
|
+
if (read.pending)
|
|
22
|
+
return read.pending;
|
|
23
|
+
const before = earlier ? read.before : undefined;
|
|
24
|
+
setState({ key: read.key, loading: true, hasMore: read.hasMore, error: null });
|
|
25
|
+
read.pending = (async () => {
|
|
26
|
+
try {
|
|
27
|
+
const url = new URL('/api/conversations/history', `${read.context.apiBase}/`);
|
|
28
|
+
url.searchParams.set('connectionId', read.binding.connectionId);
|
|
29
|
+
url.searchParams.set('sessionKey', read.binding.sessionKey);
|
|
30
|
+
if (before !== undefined)
|
|
31
|
+
url.searchParams.set('beforeSequence', String(before));
|
|
32
|
+
const response = await fetch(url, { headers: read.context.headers, signal: read.controller.signal, cache: 'no-store' });
|
|
33
|
+
if (!active(read))
|
|
34
|
+
return;
|
|
35
|
+
const body = await response.json();
|
|
36
|
+
if (!active(read))
|
|
37
|
+
return;
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
if (response.status === 404 && record(body)?.code === 'history_not_recorded') {
|
|
40
|
+
read.hasMore = false;
|
|
41
|
+
read.before = undefined;
|
|
42
|
+
setState({ key: read.key, loading: false, hasMore: false, error: null });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
throw Error(typeof record(body)?.error === 'string' ? String(record(body).error) : `History request failed (${response.status})`);
|
|
46
|
+
}
|
|
47
|
+
const page = readSandboxHistoryPage(body, read.binding, before, locale);
|
|
48
|
+
// React may defer a functional update; retire it at execution time too.
|
|
49
|
+
receiver.current(previous => active(read) ? mergeSandboxHistory(previous, page.messages) : [...previous]);
|
|
50
|
+
read.hasMore = page.hasMore;
|
|
51
|
+
read.before = page.nextBeforeSequence ?? undefined;
|
|
52
|
+
setState({ key: read.key, loading: false, hasMore: read.hasMore, error: null });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (active(read))
|
|
56
|
+
setState({ key: read.key, loading: false, hasMore: read.hasMore,
|
|
57
|
+
error: error instanceof Error ? error.message : 'History read failed' });
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
read.pending = undefined;
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
return read.pending;
|
|
64
|
+
}, [locale]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!binding) {
|
|
67
|
+
owner.current = undefined;
|
|
68
|
+
setState({ key, loading: false, hasMore: false, error: null });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const read = { key, binding: { ...binding, scope: { ...binding.scope }, scene: { ...binding.scene } },
|
|
72
|
+
context: binding.requestContext ?? captureSandboxRequestContext(), controller: new AbortController(), hasMore: false };
|
|
73
|
+
owner.current = read;
|
|
74
|
+
setState({ key, loading: false, hasMore: false, error: null });
|
|
75
|
+
void load(read, false);
|
|
76
|
+
return () => { read.controller.abort(); if (owner.current === read)
|
|
77
|
+
owner.current = undefined; };
|
|
78
|
+
}, [key, binding?.requestContext]);
|
|
79
|
+
const visible = state.key === key && (owner.current ? active(owner.current) : !binding);
|
|
80
|
+
return {
|
|
81
|
+
loading: visible && state.loading,
|
|
82
|
+
error: visible ? state.error : null,
|
|
83
|
+
hasMore: visible && state.hasMore,
|
|
84
|
+
loadEarlier: () => owner.current ? load(owner.current, true) : Promise.resolve(),
|
|
85
|
+
refresh: () => owner.current ? load(owner.current, false) : Promise.resolve(),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function requestContextCurrent(context) {
|
|
89
|
+
const current = captureSandboxRequestContext();
|
|
90
|
+
return current.apiBase === context.apiBase && current.headers.Authorization === context.headers.Authorization;
|
|
91
|
+
}
|
|
92
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
93
|
+
? value : undefined;
|
|
94
|
+
const text = (value) => typeof value === 'string' && value.length > 0;
|
|
95
|
+
const validTime = (value) => typeof value === 'number' && Number.isFinite(value) && Number.isFinite(new Date(value).getTime());
|
|
96
|
+
/** Validate the server address before projecting any message into the active scene. */
|
|
97
|
+
export function readSandboxHistoryPage(body, binding, before, locale = 'zh-CN') {
|
|
98
|
+
function fail() { throw Error('History response does not match the current conversation'); }
|
|
99
|
+
const data = record(record(body)?.data);
|
|
100
|
+
const matches = (value) => {
|
|
101
|
+
const conversation = record(value), endpoint = record(conversation?.endpoint);
|
|
102
|
+
return endpoint?.adapter === binding.scope.adapter && endpoint.id === binding.scope.id
|
|
103
|
+
&& conversation?.kind === binding.scene.type && conversation.id === binding.scene.id
|
|
104
|
+
&& conversation.parent === undefined && conversation.threadId === undefined;
|
|
105
|
+
};
|
|
106
|
+
if (record(body)?.success !== true || !data || !matches(data.conversation) || !Array.isArray(data.items)
|
|
107
|
+
|| data.items.length > 50 || typeof data.hasMore !== 'boolean')
|
|
108
|
+
fail();
|
|
109
|
+
const items = data.items;
|
|
110
|
+
let previous = 0;
|
|
111
|
+
const messages = [];
|
|
112
|
+
for (const value of items) {
|
|
113
|
+
const item = record(value);
|
|
114
|
+
if (!item || !Number.isSafeInteger(item.sequence) || Number(item.sequence) <= previous || !text(item.type)
|
|
115
|
+
|| !validTime(item.timestamp) || before !== undefined && Number(item.sequence) >= before)
|
|
116
|
+
fail();
|
|
117
|
+
previous = Number(item.sequence);
|
|
118
|
+
if (item.type === 'message.created') {
|
|
119
|
+
const message = record(item.message), ref = record(message?.ref), actor = record(message?.actor);
|
|
120
|
+
if (!message || !ref || !text(ref.id) || !matches(ref.conversation) || !validTime(message.timestamp)
|
|
121
|
+
|| !Array.isArray(message.segments) || !message.segments.every(segment => text(record(segment)?.type) && record(record(segment)?.data))
|
|
122
|
+
|| message.actor !== undefined && (!actor || !text(actor.id) || actor.displayName !== undefined && typeof actor.displayName !== 'string')
|
|
123
|
+
|| message.contentStatus !== undefined && message.contentStatus !== 'unavailable')
|
|
124
|
+
fail();
|
|
125
|
+
const content = message.contentStatus === 'unavailable'
|
|
126
|
+
? [{ type: 'text', data: { text: sandboxText(locale, '消息正文未保存') } }] : message.segments;
|
|
127
|
+
messages.push({ id: ref.id, type: actor ? 'sent' : 'received', channelType: binding.scene.type, channelId: binding.scene.id,
|
|
128
|
+
channelName: binding.scene.name, senderId: actor ? String(actor.id) : 'endpoint',
|
|
129
|
+
senderName: actor ? String(actor.displayName || actor.id) : binding.scope.id, content, timestamp: message.timestamp,
|
|
130
|
+
historySequence: previous, ...(hasPlaygroundKeyboard(content) ? { interactionReadOnly: true } : {}) });
|
|
131
|
+
}
|
|
132
|
+
else if (item.type === 'message.recalled') {
|
|
133
|
+
const ref = record(item.messageRef);
|
|
134
|
+
if (item.messageRef !== undefined && (!ref || !text(ref.id) || !matches(ref.conversation)))
|
|
135
|
+
fail();
|
|
136
|
+
messages.push({ id: `history:recall:${previous}`, type: 'received', channelType: binding.scene.type, channelId: binding.scene.id,
|
|
137
|
+
channelName: binding.scene.name, senderId: 'endpoint', senderName: binding.scope.id, timestamp: item.timestamp,
|
|
138
|
+
content: [{ type: 'text', data: { text: sandboxText(locale, '消息已撤回') } }], historySequence: previous,
|
|
139
|
+
...(ref ? { recalledMessageId: String(ref.id) } : {}) });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (data.hasMore ? !items.length || data.nextBeforeSequence !== record(items[0])?.sequence
|
|
143
|
+
: data.nextBeforeSequence !== null)
|
|
144
|
+
fail();
|
|
145
|
+
return { messages, hasMore: data.hasMore, nextBeforeSequence: data.hasMore ? Number(data.nextBeforeSequence) : null };
|
|
146
|
+
}
|
|
147
|
+
/** Stable message identity joins canonical events, optimistic inputs and native wire receipts. */
|
|
148
|
+
export function mergeSandboxHistory(current, history) {
|
|
149
|
+
const key = (row) => JSON.stringify([row.channelType, row.channelId, row.type, row.id]);
|
|
150
|
+
const rows = new Map(current.map(row => [key(row), row]));
|
|
151
|
+
for (const row of history) {
|
|
152
|
+
const existing = rows.get(key(row));
|
|
153
|
+
rows.set(key(row), existing ? { ...row, ...existing, historySequence: row.historySequence,
|
|
154
|
+
...(existing.interactionReadOnly === false ? { interactionReadOnly: false } : row.interactionReadOnly ? { interactionReadOnly: true } : {}) } : row);
|
|
155
|
+
}
|
|
156
|
+
const recalled = new Set([...rows.values()].filter(row => row.recalledMessageId).map(row => JSON.stringify([row.channelType, row.channelId, row.recalledMessageId])));
|
|
157
|
+
return [...rows.values()].map(row => recalled.has(JSON.stringify([row.channelType, row.channelId, row.id]))
|
|
158
|
+
? { ...row, recalled: true, ...(hasPlaygroundKeyboard(row.content) ? { interactionReadOnly: true } : {}) } : row)
|
|
159
|
+
.sort((a, b) => a.timestamp - b.timestamp || (a.channelType === b.channelType && a.channelId === b.channelId
|
|
160
|
+
? (a.historySequence ?? Number.MAX_SAFE_INTEGER) - (b.historySequence ?? Number.MAX_SAFE_INTEGER) : 0));
|
|
161
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { MessageSegment } from '@zhin.js/client';
|
|
3
|
+
import { hasPlaygroundKeyboard, type PlaygroundMessage, type PlaygroundScope } from './playgroundState.js';
|
|
4
|
+
import { captureSandboxRequestContext, type SandboxRequestContext } from './sandboxTransport.js';
|
|
5
|
+
import { sandboxText, type SandboxLocale } from './messages.js';
|
|
6
|
+
|
|
7
|
+
export interface SandboxHistoryBinding {
|
|
8
|
+
readonly connectionId: string;
|
|
9
|
+
readonly sessionKey: string;
|
|
10
|
+
readonly scope: Readonly<{ adapter: string; id: string }>;
|
|
11
|
+
readonly scene: Readonly<{ id: string; type: PlaygroundScope; name: string }>;
|
|
12
|
+
readonly ownerId: string;
|
|
13
|
+
readonly requestContext?: SandboxRequestContext;
|
|
14
|
+
}
|
|
15
|
+
type HistoryUpdate = (current: readonly PlaygroundMessage[]) => PlaygroundMessage[];
|
|
16
|
+
interface HistoryPage { messages: PlaygroundMessage[]; hasMore: boolean; nextBeforeSequence: number | null }
|
|
17
|
+
interface HistoryOwner {
|
|
18
|
+
key: string;
|
|
19
|
+
binding: SandboxHistoryBinding;
|
|
20
|
+
context: SandboxRequestContext;
|
|
21
|
+
controller: AbortController;
|
|
22
|
+
before?: number;
|
|
23
|
+
hasMore: boolean;
|
|
24
|
+
pending?: Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Real message events only. A page applies to the latest live rows rather than replacing them. */
|
|
28
|
+
export function useSandboxHistory(
|
|
29
|
+
binding: SandboxHistoryBinding | undefined,
|
|
30
|
+
onHistory: (update: HistoryUpdate) => void,
|
|
31
|
+
locale: SandboxLocale = 'zh-CN',
|
|
32
|
+
) {
|
|
33
|
+
const key = binding ? JSON.stringify([captureSandboxRequestContext().apiBase, binding.connectionId, binding.sessionKey,
|
|
34
|
+
binding.scope.adapter, binding.scope.id, binding.scene.type, binding.scene.id, binding.ownerId]) : '';
|
|
35
|
+
const current = useRef(key); current.current = key;
|
|
36
|
+
const receiver = useRef(onHistory); receiver.current = onHistory;
|
|
37
|
+
const owner = useRef<HistoryOwner | undefined>(undefined);
|
|
38
|
+
const [state, setState] = useState({ key, loading: false, hasMore: false, error: null as string | null });
|
|
39
|
+
const active = (read: HistoryOwner) => owner.current === read && current.current === read.key
|
|
40
|
+
&& !read.controller.signal.aborted && requestContextCurrent(read.context);
|
|
41
|
+
const load = useCallback((read: HistoryOwner, earlier: boolean): Promise<void> => {
|
|
42
|
+
if (!active(read) || earlier && !read.hasMore) return Promise.resolve();
|
|
43
|
+
if (read.pending) return read.pending;
|
|
44
|
+
const before = earlier ? read.before : undefined;
|
|
45
|
+
setState({ key: read.key, loading: true, hasMore: read.hasMore, error: null });
|
|
46
|
+
read.pending = (async () => {
|
|
47
|
+
try {
|
|
48
|
+
const url = new URL('/api/conversations/history', `${read.context.apiBase}/`);
|
|
49
|
+
url.searchParams.set('connectionId', read.binding.connectionId);
|
|
50
|
+
url.searchParams.set('sessionKey', read.binding.sessionKey);
|
|
51
|
+
if (before !== undefined) url.searchParams.set('beforeSequence', String(before));
|
|
52
|
+
const response = await fetch(url, { headers: read.context.headers, signal: read.controller.signal, cache: 'no-store' });
|
|
53
|
+
if (!active(read)) return;
|
|
54
|
+
const body: unknown = await response.json();
|
|
55
|
+
if (!active(read)) return;
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
if (response.status === 404 && record(body)?.code === 'history_not_recorded') {
|
|
58
|
+
read.hasMore = false; read.before = undefined;
|
|
59
|
+
setState({ key: read.key, loading: false, hasMore: false, error: null });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
throw Error(typeof record(body)?.error === 'string' ? String(record(body)!.error) : `History request failed (${response.status})`);
|
|
63
|
+
}
|
|
64
|
+
const page = readSandboxHistoryPage(body, read.binding, before, locale);
|
|
65
|
+
// React may defer a functional update; retire it at execution time too.
|
|
66
|
+
receiver.current(previous => active(read) ? mergeSandboxHistory(previous, page.messages) : [...previous]);
|
|
67
|
+
read.hasMore = page.hasMore; read.before = page.nextBeforeSequence ?? undefined;
|
|
68
|
+
setState({ key: read.key, loading: false, hasMore: read.hasMore, error: null });
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (active(read)) setState({ key: read.key, loading: false, hasMore: read.hasMore,
|
|
71
|
+
error: error instanceof Error ? error.message : 'History read failed' });
|
|
72
|
+
} finally { read.pending = undefined; }
|
|
73
|
+
})();
|
|
74
|
+
return read.pending;
|
|
75
|
+
}, [locale]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!binding) { owner.current = undefined; setState({ key, loading: false, hasMore: false, error: null }); return; }
|
|
78
|
+
const read: HistoryOwner = { key, binding: { ...binding, scope: { ...binding.scope }, scene: { ...binding.scene } },
|
|
79
|
+
context: binding.requestContext ?? captureSandboxRequestContext(), controller: new AbortController(), hasMore: false };
|
|
80
|
+
owner.current = read;
|
|
81
|
+
setState({ key, loading: false, hasMore: false, error: null });
|
|
82
|
+
void load(read, false);
|
|
83
|
+
return () => { read.controller.abort(); if (owner.current === read) owner.current = undefined; };
|
|
84
|
+
}, [key, binding?.requestContext]);
|
|
85
|
+
const visible = state.key === key && (owner.current ? active(owner.current) : !binding);
|
|
86
|
+
return {
|
|
87
|
+
loading: visible && state.loading,
|
|
88
|
+
error: visible ? state.error : null,
|
|
89
|
+
hasMore: visible && state.hasMore,
|
|
90
|
+
loadEarlier: () => owner.current ? load(owner.current, true) : Promise.resolve(),
|
|
91
|
+
refresh: () => owner.current ? load(owner.current, false) : Promise.resolve(),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function requestContextCurrent(context: SandboxRequestContext): boolean {
|
|
96
|
+
const current = captureSandboxRequestContext();
|
|
97
|
+
return current.apiBase === context.apiBase && current.headers.Authorization === context.headers.Authorization;
|
|
98
|
+
}
|
|
99
|
+
const record = (value: unknown): Record<string, unknown> | undefined => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
100
|
+
? value as Record<string, unknown> : undefined;
|
|
101
|
+
const text = (value: unknown): value is string => typeof value === 'string' && value.length > 0;
|
|
102
|
+
const validTime = (value: unknown): value is number => typeof value === 'number' && Number.isFinite(value) && Number.isFinite(new Date(value).getTime());
|
|
103
|
+
|
|
104
|
+
/** Validate the server address before projecting any message into the active scene. */
|
|
105
|
+
export function readSandboxHistoryPage(body: unknown, binding: SandboxHistoryBinding, before?: number, locale: SandboxLocale = 'zh-CN'): HistoryPage {
|
|
106
|
+
function fail(): never { throw Error('History response does not match the current conversation'); }
|
|
107
|
+
const data = record(record(body)?.data);
|
|
108
|
+
const matches = (value: unknown) => {
|
|
109
|
+
const conversation = record(value), endpoint = record(conversation?.endpoint);
|
|
110
|
+
return endpoint?.adapter === binding.scope.adapter && endpoint.id === binding.scope.id
|
|
111
|
+
&& conversation?.kind === binding.scene.type && conversation.id === binding.scene.id
|
|
112
|
+
&& conversation.parent === undefined && conversation.threadId === undefined;
|
|
113
|
+
};
|
|
114
|
+
if (record(body)?.success !== true || !data || !matches(data.conversation) || !Array.isArray(data.items)
|
|
115
|
+
|| data.items.length > 50 || typeof data.hasMore !== 'boolean') fail();
|
|
116
|
+
const items = data.items as unknown[];
|
|
117
|
+
let previous = 0;
|
|
118
|
+
const messages: PlaygroundMessage[] = [];
|
|
119
|
+
for (const value of items) {
|
|
120
|
+
const item = record(value);
|
|
121
|
+
if (!item || !Number.isSafeInteger(item.sequence) || Number(item.sequence) <= previous || !text(item.type)
|
|
122
|
+
|| !validTime(item.timestamp) || before !== undefined && Number(item.sequence) >= before) fail();
|
|
123
|
+
previous = Number(item.sequence);
|
|
124
|
+
if (item.type === 'message.created') {
|
|
125
|
+
const message = record(item.message), ref = record(message?.ref), actor = record(message?.actor);
|
|
126
|
+
if (!message || !ref || !text(ref.id) || !matches(ref.conversation) || !validTime(message.timestamp)
|
|
127
|
+
|| !Array.isArray(message.segments) || !message.segments.every(segment => text(record(segment)?.type) && record(record(segment)?.data))
|
|
128
|
+
|| message.actor !== undefined && (!actor || !text(actor.id) || actor.displayName !== undefined && typeof actor.displayName !== 'string')
|
|
129
|
+
|| message.contentStatus !== undefined && message.contentStatus !== 'unavailable') fail();
|
|
130
|
+
const content: MessageSegment[] = message.contentStatus === 'unavailable'
|
|
131
|
+
? [{ type: 'text', data: { text: sandboxText(locale, '消息正文未保存') } }] : message.segments as MessageSegment[];
|
|
132
|
+
messages.push({ id: ref.id, type: actor ? 'sent' : 'received', channelType: binding.scene.type, channelId: binding.scene.id,
|
|
133
|
+
channelName: binding.scene.name, senderId: actor ? String(actor.id) : 'endpoint',
|
|
134
|
+
senderName: actor ? String(actor.displayName || actor.id) : binding.scope.id, content, timestamp: message.timestamp,
|
|
135
|
+
historySequence: previous, ...(hasPlaygroundKeyboard(content) ? { interactionReadOnly: true } : {}) });
|
|
136
|
+
} else if (item.type === 'message.recalled') {
|
|
137
|
+
const ref = record(item.messageRef);
|
|
138
|
+
if (item.messageRef !== undefined && (!ref || !text(ref.id) || !matches(ref.conversation))) fail();
|
|
139
|
+
messages.push({ id: `history:recall:${previous}`, type: 'received', channelType: binding.scene.type, channelId: binding.scene.id,
|
|
140
|
+
channelName: binding.scene.name, senderId: 'endpoint', senderName: binding.scope.id, timestamp: item.timestamp,
|
|
141
|
+
content: [{ type: 'text', data: { text: sandboxText(locale, '消息已撤回') } }], historySequence: previous,
|
|
142
|
+
...(ref ? { recalledMessageId: String(ref.id) } : {}) });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (data.hasMore ? !items.length || data.nextBeforeSequence !== record(items[0])?.sequence
|
|
146
|
+
: data.nextBeforeSequence !== null) fail();
|
|
147
|
+
return { messages, hasMore: data.hasMore, nextBeforeSequence: data.hasMore ? Number(data.nextBeforeSequence) : null };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Stable message identity joins canonical events, optimistic inputs and native wire receipts. */
|
|
151
|
+
export function mergeSandboxHistory(current: readonly PlaygroundMessage[], history: readonly PlaygroundMessage[]): PlaygroundMessage[] {
|
|
152
|
+
const key = (row: PlaygroundMessage) => JSON.stringify([row.channelType, row.channelId, row.type, row.id]);
|
|
153
|
+
const rows = new Map(current.map(row => [key(row), row]));
|
|
154
|
+
for (const row of history) {
|
|
155
|
+
const existing = rows.get(key(row));
|
|
156
|
+
rows.set(key(row), existing ? { ...row, ...existing, historySequence: row.historySequence,
|
|
157
|
+
...(existing.interactionReadOnly === false ? { interactionReadOnly: false } : row.interactionReadOnly ? { interactionReadOnly: true } : {}) } : row);
|
|
158
|
+
}
|
|
159
|
+
const recalled = new Set([...rows.values()].filter(row => row.recalledMessageId).map(row => JSON.stringify([row.channelType, row.channelId, row.recalledMessageId])));
|
|
160
|
+
return [...rows.values()].map(row => recalled.has(JSON.stringify([row.channelType, row.channelId, row.id]))
|
|
161
|
+
? { ...row, recalled: true, ...(hasPlaygroundKeyboard(row.content) ? { interactionReadOnly: true } : {}) } : row)
|
|
162
|
+
.sort((a, b) => a.timestamp - b.timestamp || (a.channelType === b.channelType && a.channelId === b.channelId
|
|
163
|
+
? (a.historySequence ?? Number.MAX_SAFE_INTEGER) - (b.historySequence ?? Number.MAX_SAFE_INTEGER) : 0));
|
|
164
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { getSandboxApiBase, getSandboxAuthHeaders } from './sandboxTransport.js';
|
|
3
|
+
export class WorkspaceRequestError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
code;
|
|
6
|
+
constructor(message, status, code) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function directoryUrl(connectionId, context) {
|
|
13
|
+
const url = new URL('/api/conversations/workspaces', `${(context ? context.apiBase : getSandboxApiBase()) || window.location.origin}/`);
|
|
14
|
+
url.searchParams.set('connectionId', connectionId);
|
|
15
|
+
return url;
|
|
16
|
+
}
|
|
17
|
+
/** Only an absent endpoint or explicitly unavailable store permits the agreed browser fallback. */
|
|
18
|
+
export async function readWorkspaceDirectory(connectionId, signal, context) {
|
|
19
|
+
const response = await fetch(directoryUrl(connectionId, context), { headers: context?.headers ?? getSandboxAuthHeaders(), signal });
|
|
20
|
+
if (response.status === 404 || response.status === 405)
|
|
21
|
+
return null;
|
|
22
|
+
const body = await response.json();
|
|
23
|
+
if (response.status === 503 && body.code === 'workspace_store_unavailable')
|
|
24
|
+
return null;
|
|
25
|
+
if (!response.ok || !body.success || !body.data) {
|
|
26
|
+
throw new WorkspaceRequestError(body.error || `Conversation directory request failed (${response.status})`, response.status, body.code);
|
|
27
|
+
}
|
|
28
|
+
if (body.data.scope.connectionId !== connectionId || !Array.isArray(body.data.items)) {
|
|
29
|
+
throw new WorkspaceRequestError('Conversation directory returned a different connection or invalid catalog', response.status);
|
|
30
|
+
}
|
|
31
|
+
return body.data;
|
|
32
|
+
}
|
|
33
|
+
/** One revision-checked mutation. An unknown outcome or conflict must never cause a blind retry. */
|
|
34
|
+
export async function saveWorkspaceConversation(connectionId, conversation, expectedRevision, context) {
|
|
35
|
+
const response = await fetch(directoryUrl(connectionId, context), {
|
|
36
|
+
method: 'PUT', headers: { ...(context?.headers ?? getSandboxAuthHeaders()), 'content-type': 'application/json' },
|
|
37
|
+
body: JSON.stringify({ connectionId, conversation: {
|
|
38
|
+
id: conversation.id, type: conversation.type, name: conversation.name, runConfig: conversation.runConfig,
|
|
39
|
+
}, expectedRevision }),
|
|
40
|
+
});
|
|
41
|
+
const body = await response.json();
|
|
42
|
+
if (!response.ok || !body.success || !body.data) {
|
|
43
|
+
throw new WorkspaceRequestError(body.error || `Conversation save failed (${response.status})`, response.status, body.code);
|
|
44
|
+
}
|
|
45
|
+
if (body.data.scope.connectionId !== connectionId || body.data.item.id !== conversation.id || body.data.item.type !== conversation.type) {
|
|
46
|
+
throw new WorkspaceRequestError('Conversation save returned a different connection or scene', response.status);
|
|
47
|
+
}
|
|
48
|
+
return body.data;
|
|
49
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { PlaygroundSession } from './playgroundState.js';
|
|
2
|
+
import { getSandboxApiBase, getSandboxAuthHeaders, type SandboxRequestContext } from './sandboxTransport.js';
|
|
3
|
+
|
|
4
|
+
export interface SandboxWorkspaceScope {
|
|
5
|
+
readonly endpoint: Readonly<{ adapter: string; id: string }>;
|
|
6
|
+
readonly endpointKey: string;
|
|
7
|
+
readonly ownerId: string;
|
|
8
|
+
readonly connectionId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WorkspaceConversation extends Pick<PlaygroundSession, 'id' | 'type' | 'name' | 'runConfig'> {
|
|
12
|
+
readonly revision: string;
|
|
13
|
+
readonly updatedAt: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface WorkspaceDirectory {
|
|
17
|
+
readonly scope: SandboxWorkspaceScope;
|
|
18
|
+
readonly items: readonly WorkspaceConversation[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class WorkspaceRequestError extends Error {
|
|
22
|
+
constructor(message: string, readonly status: number, readonly code?: string) { super(message); }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface WorkspaceResponse<T> {
|
|
26
|
+
readonly success?: boolean;
|
|
27
|
+
readonly data?: T;
|
|
28
|
+
readonly error?: string;
|
|
29
|
+
readonly code?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function directoryUrl(connectionId: string, context?: SandboxRequestContext): URL {
|
|
33
|
+
const url = new URL('/api/conversations/workspaces', `${(context ? context.apiBase : getSandboxApiBase()) || window.location.origin}/`);
|
|
34
|
+
url.searchParams.set('connectionId', connectionId);
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Only an absent endpoint or explicitly unavailable store permits the agreed browser fallback. */
|
|
39
|
+
export async function readWorkspaceDirectory(connectionId: string, signal?: AbortSignal, context?: SandboxRequestContext): Promise<WorkspaceDirectory | null> {
|
|
40
|
+
const response = await fetch(directoryUrl(connectionId, context), { headers: context?.headers ?? getSandboxAuthHeaders(), signal });
|
|
41
|
+
if (response.status === 404 || response.status === 405) return null;
|
|
42
|
+
const body = await response.json() as WorkspaceResponse<WorkspaceDirectory>;
|
|
43
|
+
if (response.status === 503 && body.code === 'workspace_store_unavailable') return null;
|
|
44
|
+
if (!response.ok || !body.success || !body.data) {
|
|
45
|
+
throw new WorkspaceRequestError(body.error || `Conversation directory request failed (${response.status})`, response.status, body.code);
|
|
46
|
+
}
|
|
47
|
+
if (body.data.scope.connectionId !== connectionId || !Array.isArray(body.data.items)) {
|
|
48
|
+
throw new WorkspaceRequestError('Conversation directory returned a different connection or invalid catalog', response.status);
|
|
49
|
+
}
|
|
50
|
+
return body.data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** One revision-checked mutation. An unknown outcome or conflict must never cause a blind retry. */
|
|
54
|
+
export async function saveWorkspaceConversation(
|
|
55
|
+
connectionId: string,
|
|
56
|
+
conversation: Pick<PlaygroundSession, 'id' | 'type' | 'name' | 'runConfig'>,
|
|
57
|
+
expectedRevision: string | null,
|
|
58
|
+
context?: SandboxRequestContext,
|
|
59
|
+
): Promise<Readonly<{ scope: SandboxWorkspaceScope; item: WorkspaceConversation }>> {
|
|
60
|
+
const response = await fetch(directoryUrl(connectionId, context), {
|
|
61
|
+
method: 'PUT', headers: { ...(context?.headers ?? getSandboxAuthHeaders()), 'content-type': 'application/json' },
|
|
62
|
+
body: JSON.stringify({ connectionId, conversation: {
|
|
63
|
+
id: conversation.id, type: conversation.type, name: conversation.name, runConfig: conversation.runConfig,
|
|
64
|
+
}, expectedRevision }),
|
|
65
|
+
});
|
|
66
|
+
const body = await response.json() as WorkspaceResponse<{ scope: SandboxWorkspaceScope; item: WorkspaceConversation }>;
|
|
67
|
+
if (!response.ok || !body.success || !body.data) {
|
|
68
|
+
throw new WorkspaceRequestError(body.error || `Conversation save failed (${response.status})`, response.status, body.code);
|
|
69
|
+
}
|
|
70
|
+
if (body.data.scope.connectionId !== connectionId || body.data.item.id !== conversation.id || body.data.item.type !== conversation.type) {
|
|
71
|
+
throw new WorkspaceRequestError('Conversation save returned a different connection or scene', response.status);
|
|
72
|
+
}
|
|
73
|
+
return body.data;
|
|
74
|
+
}
|