Skip to content

imProxyAgentMessage

IM 智能体代理相关的消息正文、附件、会话路由与 aborted 回复查找纯函数。

函数签名

typescript
function imPersistedIdsEqual(a: unknown, b: unknown): boolean

function imMessageTypeTriggersProxy(
  t: ImMessage['type'],
): t is 'text' | 'markdown'

function extractAtUidMentions(content: string): string[]

interface ImProxyConversationSnap {
  mode: 'direct' | 'multi'
  members: string[]
}

function collectUserIdsForProxyAccountLookup(
  message: Pick<ImMessage, 'sender_id' | 'content'>,
  snap: ImProxyConversationSnap,
  projectLeadUserId?: string | null,
): string[]

function pickLlmProxyRecipientUserId(
  message: Pick<ImMessage, 'sender_id' | 'content'>,
  snap: ImProxyConversationSnap,
  kinds: Map<string, 'person' | 'ai_agent'>,
  options?: { projectLeadUserId?: string | null },
): string | null

function normalizeImMessagePlainContent(content: string): string

function imMessageUserTextPlain(m: ImMessage): string

function imMessageUserTextPlainForAgent(m: ImMessage, recipientUserId: string): string

function imInlineAttachmentsForAgent(m: ImMessage): Array<{
  url: string
  mimeType: string
  filename?: string
}>

function imMessageHasAgentPayload(m: ImMessage): boolean

function isAbortedModelAgentReplyForTrigger(
  message: ImMessage,
  triggerMessageId: string | number,
  triggerSenderId: string,
): boolean

function findAbortedModelAgentRepliesForTrigger(
  sortedAsc: ImMessage[],
  triggerMessageId: string | number,
  triggerSenderId: string,
): ImMessage[]

工作原理

  1. 代理触发:仅 text / markdown 类型消息可触发 ImProxy。
  2. 接收方路由:双人会话取对端智能体;多人会话优先 @ 智能体,否则回落项目负责人。
  3. 正文规范化:去零宽字符 \u200b 并 trim,不修改 wire HTML。
  4. aborted 查找:在正序消息列表中,取触发消息之后、下一条同发送者消息之前的 model aborted 助手回复。

使用场景

  • ImProxyService 门禁与接收方解析
  • ImProxyAgentPipeline 拼 user content
  • ImService 代理重试时查找 aborted 回复

依赖 Nest HttpException 的重试分类、LLM AgentInputContentPart 转换等仍留在 API im-proxy.pure.ts