redactMessage 脱敏单个消息。
(ctx context.Context, msg types.Message, agentID string)
| 94 | |
| 95 | // redactMessage 脱敏单个消息。 |
| 96 | func (m *PIIRedactionMiddleware) redactMessage(ctx context.Context, msg types.Message, agentID string) (types.Message, error) { |
| 97 | // 处理简单文本内容 |
| 98 | if msg.Content != "" { |
| 99 | redacted, _, err := m.redactWithTracking(ctx, msg.Content, agentID) |
| 100 | if err != nil { |
| 101 | return msg, err |
| 102 | } |
| 103 | msg.Content = redacted |
| 104 | } |
| 105 | |
| 106 | // 处理复杂内容块 |
| 107 | if len(msg.ContentBlocks) > 0 { |
| 108 | for i, block := range msg.ContentBlocks { |
| 109 | redactedBlock, err := m.redactContentBlock(ctx, block, agentID) |
| 110 | if err != nil { |
| 111 | return msg, err |
| 112 | } |
| 113 | msg.ContentBlocks[i] = redactedBlock |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return msg, nil |
| 118 | } |
| 119 | |
| 120 | // redactContentBlock 脱敏内容块。 |
| 121 | func (m *PIIRedactionMiddleware) redactContentBlock(ctx context.Context, block types.ContentBlock, agentID string) (types.ContentBlock, error) { |
no test coverage detected