@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/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';