feedback

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package feedback 提供 Message Feedback 接缝(Storage Domain sidecar + 稳定 fail 分类)。

对齐上游:packages/feedback/feedback(S09)

设计要点:

  • 每个 (sessionId, messageId) 一条 Feedback 记录:rating/note/version(CAS)/createdAt/updatedAt;
  • 复用 M45 storage.Domain[T] 的 CAS 版本(Put 带 expectedVersion,冲突报 VERSION_CONFLICT);
  • 稳定错误分类:VERSION_CONFLICT / SESSION_NOT_FOUND / NOT_FOUND;
  • list/put/delete。

validate.go 复刻官方 message-feedback 的值约束:评分只接受 thumbs up/down 两值 (0 表示未评分,不作为有效反馈落库);note 若提供则必须含非空白字符。

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyNote = errors.New("feedback: note must contain a non-whitespace character")

ErrEmptyNote note 提供了但全为空白。

View Source
var ErrInvalidRating = errors.New("feedback: rating must be thumbs up or down")

ErrInvalidRating 评分不是有效两值之一。

Functions

func ValidateNote

func ValidateNote(note string) error

ValidateNote note 非空时要求含非空白字符;空串视为"不提供 note",合法。

func ValidateRating

func ValidateRating(r Rating) error

ValidateRating 校验评分只取 ThumbsUp/ThumbsDown。

Types

type FailCode

type FailCode string

FailCode 是稳定失败分类码。

const (
	CodeVersionConflict FailCode = "VERSION_CONFLICT"
	CodeSessionNotFound FailCode = "SESSION_NOT_FOUND"
	CodeNotFound        FailCode = "NOT_FOUND"
)

func CodeOf

func CodeOf(err error) FailCode

CodeOf 提取稳定码。

type FailError

type FailError struct {
	Code FailCode
	Msg  string
}

FailError 是携带稳定码的反馈错误。

func (*FailError) Error

func (e *FailError) Error() string

type Feedback

type Feedback struct {
	// SessionID 所属会话 id。
	SessionID brand.SessionID `json:"sessionId"`
	// MessageID 消息标识。
	MessageID string `json:"messageId"`
	// Rating 评分(-1/0/1)。
	Rating Rating `json:"rating"`
	// Note 备注。
	Note string `json:"note,omitempty"`
	// Version CAS 版本(写时自增)。
	Version uint64 `json:"version"`
	// CreatedAt 创建时间。
	CreatedAt time.Time `json:"createdAt"`
	// UpdatedAt 最后更新时间。
	UpdatedAt time.Time `json:"updatedAt"`
}

Feedback 是一条消息反馈。

type Rating

type Rating int

Rating 是反馈评分。

const (
	RatingThumbsDown Rating = -1
	RatingNone       Rating = 0
	RatingThumbsUp   Rating = 1
)

评分枚举。

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store 是 Message Feedback 存储。

func New

func New(backend storage.Backend) *Store

New 创建反馈存储(backend 传 M45 storage backend)。

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, session brand.SessionID, messageID string) error

Delete 删除一条反馈。

func (*Store) Get

func (s *Store) Get(ctx context.Context, session brand.SessionID, messageID string) (*Feedback, error)

Get 读取一条反馈;不存在 → NOT_FOUND。

func (*Store) List

func (s *Store) List(ctx context.Context, session brand.SessionID) ([]Feedback, error)

List 列出某会话下全部反馈(按 key 排序)。

func (*Store) Put

func (s *Store) Put(ctx context.Context, session brand.SessionID, messageID string, rating Rating, note string, expectedVersion *uint64) (uint64, error)

Put 写入(或创建)一条反馈。Sign 若提供 expectedVersion,则做 CAS:版本不符 → VERSION_CONFLICT。 返回新版本号。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL