MCPcopy Create free account
hub / github.com/astercloud/aster / WrapModelCall

Method WrapModelCall

pkg/security/pii_middleware.go:276–295  ·  view source on GitHub ↗

WrapModelCall 包装模型调用。

(ctx context.Context, req *middleware.ModelRequest, handler middleware.ModelCallHandler)

Source from the content-addressed store, hash-verified

274
275// WrapModelCall 包装模型调用。
276func (m *ConditionalPIIMiddleware) WrapModelCall(ctx context.Context, req *middleware.ModelRequest, handler middleware.ModelCallHandler) (*middleware.ModelResponse, error) {
277 // 检查是否需要脱敏
278 if m.condition != nil && !m.condition(ctx, req) {
279 return handler(ctx, req)
280 }
281
282 // 脱敏逻辑(简化版,不追踪)
283 for i, msg := range req.Messages {
284 if msg.Content != "" {
285 redacted, err := m.redactor.Redact(ctx, msg.Content)
286 if err != nil {
287 return nil, err
288 }
289 msg.Content = redacted
290 }
291 req.Messages[i] = msg
292 }
293
294 return handler(ctx, req)
295}
296
297// TODO: PII Redaction Tool 可以作为独立工具实现,供 Agent 主动调用
298// 需要实现 tools.Tool 接口

Callers

nothing calls this directly

Calls 2

handlerFunction · 0.85
RedactMethod · 0.65

Tested by

no test coverage detected