@zhin.js/adapter-sandbox 1.1.34 → 1.1.35
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 +51 -0
- package/README.md +5 -1
- package/lib/adapter.js +12 -1
- package/lib/console.d.ts +23 -0
- package/lib/console.js +46 -0
- package/lib/endpoint.d.ts +24 -2
- package/lib/endpoint.js +80 -4
- package/lib/protocol.d.ts +12 -0
- package/lib/protocol.js +10 -0
- package/package.json +13 -13
- package/pages/index/SandboxChat.js +34 -4
- package/pages/index/SandboxChat.tsx +69 -9
- package/pages/index/chatIdentity.js +47 -0
- package/pages/index/chatIdentity.ts +66 -0
- package/pages/index/messages.js +12 -0
- package/pages/index/messages.ts +12 -0
- package/pages/index/styles.js +7 -0
- package/pages/index/styles.ts +7 -0
- package/plugin.js +7 -0
- package/src/adapter.ts +7 -1
- package/src/console.ts +50 -0
- package/src/endpoint.ts +77 -5
- package/src/protocol.ts +18 -0
package/src/protocol.ts
CHANGED
|
@@ -178,6 +178,11 @@ export interface SandboxParsedMessage {
|
|
|
178
178
|
senderId?: string;
|
|
179
179
|
senderName?: string;
|
|
180
180
|
senderRole?: SandboxSenderRole;
|
|
181
|
+
/**
|
|
182
|
+
* ADR 0060 §5.4: speak as the chat identity linked to the authenticated Console user instead of
|
|
183
|
+
* `senderId`. The server decides; without such an identity the message is simulated.
|
|
184
|
+
*/
|
|
185
|
+
asMe?: boolean;
|
|
181
186
|
}
|
|
182
187
|
|
|
183
188
|
export type SandboxInboundEnvelope = SandboxParsedMessage;
|
|
@@ -193,6 +198,7 @@ interface SandboxWirePayload {
|
|
|
193
198
|
senderId?: unknown;
|
|
194
199
|
senderName?: unknown;
|
|
195
200
|
senderRole?: unknown;
|
|
201
|
+
asMe?: unknown;
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
function readSandboxWirePayload(raw: string): SandboxWirePayload & { op?: unknown; conversation?: unknown } {
|
|
@@ -361,9 +367,21 @@ function normalizeSandboxWsPayload(payload: SandboxWirePayload, raw: string, sel
|
|
|
361
367
|
...(senderId ? { senderId } : {}),
|
|
362
368
|
...(senderName ? { senderName } : {}),
|
|
363
369
|
...(senderRole ? { senderRole } : {}),
|
|
370
|
+
...(payload.asMe === true ? { asMe: true } : {}),
|
|
364
371
|
};
|
|
365
372
|
}
|
|
366
373
|
|
|
374
|
+
/**
|
|
375
|
+
* ADR 0060 §5.4: a client-chosen sender id becomes a reserved simulated id (`~sim:<id>`). Ids
|
|
376
|
+
* starting with `~` are never chat identities (`isChatIdentity`), so a simulated sender holds no
|
|
377
|
+
* zhin role whatever id it types — including the id of an owner.
|
|
378
|
+
*/
|
|
379
|
+
export const SANDBOX_SIMULATED_PREFIX = '~sim:';
|
|
380
|
+
|
|
381
|
+
export function sandboxSimulatedSenderId(clientId: string): string {
|
|
382
|
+
return clientId.startsWith(SANDBOX_SIMULATED_PREFIX) ? clientId : `${SANDBOX_SIMULATED_PREFIX}${clientId}`;
|
|
383
|
+
}
|
|
384
|
+
|
|
367
385
|
/**
|
|
368
386
|
* 入站归一化 → ConversationRef。sandbox 无平台社交图谱:
|
|
369
387
|
* `private`/`group`/`channel` 直映射;`direct`(私聊)归 'private';
|