18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
54 lines
2.0 KiB
Go
54 lines
2.0 KiB
Go
package contract
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// CustomerAccessProof is a host-verified, short-lived customer request proof.
|
|
// It intentionally contains no password, bearer token, card number, or device
|
|
// number. The opaque SessionID can only be issued and validated by the host.
|
|
type CustomerAccessProof struct {
|
|
SessionID string
|
|
TargetType string
|
|
TargetID int64
|
|
ConversationID int64
|
|
MessageID int64
|
|
RequestID string
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
type customerAccessProofContextKey struct{}
|
|
|
|
// WithCustomerAccessProof attaches a copy of a host-verified proof to the
|
|
// current request. Agent Desk propagates only these claims into async runs.
|
|
func WithCustomerAccessProof(ctx context.Context, proof CustomerAccessProof) context.Context {
|
|
return context.WithValue(ctx, customerAccessProofContextKey{}, proof)
|
|
}
|
|
|
|
// CustomerAccessProofFromContext returns only a structurally valid, live
|
|
// proof. The host must still verify SessionID against its server-side store.
|
|
func CustomerAccessProofFromContext(ctx context.Context) (CustomerAccessProof, bool) {
|
|
proof, ok := ctx.Value(customerAccessProofContextKey{}).(CustomerAccessProof)
|
|
if !ok || strings.TrimSpace(proof.SessionID) == "" || proof.TargetID <= 0 ||
|
|
(strings.TrimSpace(proof.TargetType) != "card" && strings.TrimSpace(proof.TargetType) != "device") ||
|
|
proof.ExpiresAt.IsZero() || !proof.ExpiresAt.After(time.Now()) {
|
|
return CustomerAccessProof{}, false
|
|
}
|
|
return proof, true
|
|
}
|
|
|
|
// BindCustomerAccessProofToMessage binds the current request proof to the
|
|
// exact persisted customer message that triggered an async Agent run.
|
|
func BindCustomerAccessProofToMessage(ctx context.Context, conversationID, messageID int64, requestID string) context.Context {
|
|
proof, ok := CustomerAccessProofFromContext(ctx)
|
|
if !ok {
|
|
return ctx
|
|
}
|
|
proof.ConversationID = conversationID
|
|
proof.MessageID = messageID
|
|
proof.RequestID = strings.TrimSpace(requestID)
|
|
return WithCustomerAccessProof(ctx, proof)
|
|
}
|