platformfeedback

package
v1.171.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package platformfeedback is what agents report the platform could not do for them (#2820), delivered to whoever runs the platform.

The audit records that a call failed, not what the agent wanted. An agent knows at the moment it is blocked what it needed, and that knowledge was lost with the session; the only record of intent in three production deployments was a handful of tool-finding queries. A post here keeps it: what the agent was trying to do, what blocked it, the tool, a suggestion, and the calls involved by reference.

Every text field passes the content secret check (internal/secretscan) before anything is written, posts are bounded per session and per persona, a repeat of an open post is counted on it, and nothing is sent until an administrator turns the feature on and names the channels.

Index

Constants

View Source
const (
	DefaultSessionLimit      = 5
	DefaultPersonaDailyLimit = 50
)

Defaults for the limits.

View Source
const (
	CodeOff     = "platform_feedback_off"
	CodePersona = "platform_feedback_persona"
	CodeLimit   = "platform_feedback_limit"
	CodeSecret  = "platform_feedback_secret"
	CodeInvalid = "platform_feedback_invalid"
)

Codes a post is refused with.

View Source
const (
	StatusOpen     = "open"
	StatusPlanned  = "planned"
	StatusDone     = "done"
	StatusDeclined = "declined"
)

Statuses a post moves through.

View Source
const DefaultEmbedTimeout = 5 * time.Second

DefaultEmbedTimeout is how long a post waits for its embedding (#2829). The embedding only folds a near-duplicate onto an open post, so a busy embedding service, as right after an upgrade re-embeds the platform's knowledge, costs a missed fold and never the report.

View Source
const SectionName = "platform_feedback"

SectionName is the platform_settings section the settings are kept in.

Variables

View Source
var ErrNotFound = errors.New("platform feedback post not found")

ErrNotFound is a post that does not exist.

Functions

func Register

func Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler, svc *Service, author func(*http.Request) string)

Register mounts the admin routes behind wrap: the settings, the list, one post, its status, and a resend.

Types

type Caller

type Caller struct {
	UserID    string
	Persona   string
	SessionID string
}

Caller is who posts.

type ChannelSender

type ChannelSender interface {
	NotifyChannel(ctx context.Context, s notification.ChannelSend) (notification.ChannelResult, error)
}

ChannelSender queues a document for one channel; notification.Enqueuer is one.

type Delivery

type Delivery struct {
	Channel   string     `json:"channel"`
	Status    string     `json:"status"`
	Attempts  int        `json:"attempts"`
	LastError string     `json:"last_error,omitempty"`
	SentAt    *time.Time `json:"sent_at,omitempty"`
}

Delivery is a post's send to one channel, as the notification queue holds it.

type Deps

type Deps struct {
	// DB holds the posts and the notification queue rows their sends wrote.
	DB *sql.DB
	// Section holds the settings; nil is "off".
	Section *settingsjson.Section[Settings]
	// Detector checks every text field for a credential before anything is
	// written.
	Detector secretscan.Detector
	// Embed turns a post's words into a vector for folding a repeat; nil
	// folds only an exact repeat.
	Embed func(ctx context.Context, text string) ([]float32, error)
	// EmbedTimeout bounds Embed; zero is DefaultEmbedTimeout. A post whose
	// embedding does not come back in time is stored and sent unfolded, but
	// for a repeat of its exact words (#2829).
	EmbedTimeout time.Duration
	// Channels resolves a channel name; Sender queues a send to it.
	Channels notification.ChannelStore
	Sender   ChannelSender
	// ServiceAccount reports a persona whose calls are machinery: it may not
	// post when the settings name no personas.
	ServiceAccount func(persona string) bool
	// KnownPersona checks a persona a settings save names.
	KnownPersona func(persona string) bool
	// PortalURL is the portal's public address, for the link a send carries.
	PortalURL string
	// Now is the clock; nil is time.Now.
	Now func() time.Time
}

Deps is what the service reads.

type Detail

type Detail struct {
	Item
	Reports    []Report   `json:"reports"`
	Deliveries []Delivery `json:"deliveries"`
}

Detail is one post with its reports and deliveries.

type InvalidError

type InvalidError struct{ Msg string }

InvalidError is a settings save refused for what it holds.

func (*InvalidError) Error

func (e *InvalidError) Error() string

type Item

type Item struct {
	ID             string    `json:"id"`
	TryingTo       string    `json:"trying_to"`
	BlockedBy      string    `json:"blocked_by"`
	Tool           string    `json:"tool"`
	Suggestion     string    `json:"suggestion"`
	Status         string    `json:"status"`
	ReportCount    int       `json:"report_count"`
	CreatedAt      time.Time `json:"created_at"`
	LastReportedAt time.Time `json:"last_reported_at"`
}

Item is one post as the list shows it.

type ListFilter

type ListFilter struct {
	Status string
	Tool   string
	Query  string
	Limit  int
	Offset int
}

ListFilter narrows the list.

type ListResponse

type ListResponse struct {
	Posts []Item `json:"posts"`
	Total int    `json:"total"`
	Stats Stats  `json:"stats"`
}

ListResponse is a page of posts and the page's counts.

type Post

type Post struct {
	TryingTo   string   `json:"trying_to"`
	BlockedBy  string   `json:"blocked_by"`
	Tool       string   `json:"tool,omitempty"`
	Suggestion string   `json:"suggestion,omitempty"`
	Calls      []string `json:"calls,omitempty"`
}

Post is one report as an agent writes it.

type RefusedError

type RefusedError struct {
	Code string
	Msg  string
}

RefusedError is a post refused, with the code a caller branches on. Its message never repeats a field's content.

func (*RefusedError) Error

func (e *RefusedError) Error() string

type Report

type Report struct {
	Persona    string    `json:"persona"`
	UserID     string    `json:"-"`
	SessionID  string    `json:"-"`
	Calls      []string  `json:"calls"`
	ReportedAt time.Time `json:"reported_at"`
}

Report is one report of a post: who and in which session, and the calls it names.

type ResendRequest

type ResendRequest struct {
	Channel string `json:"channel" example:"ops-webhook"`
}

ResendRequest names the channel a post is sent to again.

type Result

type Result struct {
	ID          string `json:"id"`
	ReportCount int    `json:"report_count"`
	// Folded is true when the post repeated an open one and was counted on it
	// rather than stored and sent again.
	Folded bool `json:"folded"`
	// Channels is how many channels the new post was queued for.
	Channels int    `json:"channels"`
	Message  string `json:"message"`
}

Result is what a post did.

type Service

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

Service is platform feedback.

func New

func New(d Deps) *Service

New builds the service.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (Detail, error)

Get is one post in full.

func (*Service) List

func (s *Service) List(ctx context.Context, f ListFilter) (ListResponse, error)

List is the posts a filter selects, with the page's counts.

func (*Service) Resend

func (s *Service) Resend(ctx context.Context, id, channel string) error

Resend queues a post again for one channel the settings name, as a delivery that failed is retried by hand.

func (*Service) SaveSettings

func (s *Service) SaveSettings(ctx context.Context, in Settings, author string) (settingsjson.Stored[Settings], error)

SaveSettings validates and stores the settings.

func (*Service) SetStatus

func (s *Service) SetStatus(ctx context.Context, id, status, by string) error

SetStatus moves a post to a status.

func (*Service) Settings

func (s *Service) Settings(ctx context.Context) settingsjson.Stored[Settings]

Settings is the settings in force, with who saved them.

func (*Service) Submit

func (s *Service) Submit(ctx context.Context, c Caller, p Post) (Result, error)

Submit checks, stores and sends one post.

type Settings

type Settings struct {
	// Enabled lets agents post. Off by default.
	Enabled bool `json:"enabled"`
	// Channels are the notification channels a new post is sent to.
	Channels []string `json:"channels"`
	// Personas may post; empty is every persona except service accounts.
	Personas []string `json:"personas"`
	// SessionLimit is the most posts one session may make.
	SessionLimit int `json:"session_limit"`
	// PersonaDailyLimit is the most posts one persona may make in a day.
	PersonaDailyLimit int `json:"persona_daily_limit"`
}

Settings is how platform feedback is configured in Admin > Settings.

type SettingsView

type SettingsView struct {
	Settings
	UpdatedBy string     `json:"updated_by,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

SettingsView is the settings with who saved them.

type Stats

type Stats struct {
	Open             int `json:"open"`
	ReportsThisWeek  int `json:"reports_this_week"`
	RefusedThisWeek  int `json:"refused_this_week"`
	DeliveryFailures int `json:"delivery_failures"`
}

Stats are the list page's counts.

type StatusRequest

type StatusRequest struct {
	Status string `json:"status" example:"planned"`
}

StatusRequest moves a post to a status.

Jump to

Keyboard shortcuts

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