Documentation
¶
Overview ¶
Package settingsctl lets an agent change harnessly's settings when a person asks it to. It has three parts:
- the catalog: every setting an agent may read and propose a change of, with a title, a description, its kind, the values it takes and the value it has now;
- the proposals: an agent of the Settings window's own chat changes a setting at once; an agent of any other chat only proposes, and the change is made when the person says yes on the card the chat shows;
- the journal: every change (by a person or by an agent) with the old and the new value, who made it and when, so that the Settings window can show what changed.
A value is a string everywhere: an enum's value, "on"/"off" for a switch, digits for a number. The catalog holds no secret: a key of a provider is no setting.
Index ¶
- Constants
- func CleanWhy(why string) string
- type Actor
- type Change
- type Item
- type Journal
- type Kind
- type Option
- type Outcome
- type Proposal
- type Refusal
- type Said
- type Service
- func (s *Service) Apply(key, value string, by Actor, via, why string) (Change, error)
- func (s *Service) Approve(id string) (Outcome, error)
- func (s *Service) Decline(id string) (Outcome, error)
- func (s *Service) Get(key string) (Setting, error)
- func (s *Service) List() []Setting
- func (s *Service) Pending() []Proposal
- func (s *Service) Propose(key, value, why string, by Actor) (Outcome, error)
- func (s *Service) Record(key, old, value string, by Actor, via string)
- func (s *Service) Rev() uint64
- func (s *Service) Touch()
- func (s *Service) Wait(ctx context.Context, id string, d time.Duration) Outcome
- func (s *Service) WaitRev(ctx context.Context, after uint64, d time.Duration) uint64
- type Setting
Constants ¶
const ( On = "on" Off = "off" )
The values of a switch.
const ( ReasonUnknownKey = "unknown-setting" // no setting of that key ReasonBadValue = "bad-value" // the setting does not take the value ReasonSame = "same" // the setting already has the value ReasonNotFound = "not-found" // no proposal of that id ReasonClosed = "closed" // the proposal is answered already ReasonTooMany = "too-many" // too many proposals wait for an answer ReasonRateLimited = "rate-limited" // too many proposals from one chat ReasonFailed = "failed" )
Reasons of a refusal.
const ( ByPerson = "person" ByAgent = "agent" )
Who made a change.
const ( // ViaPage: the person changed it on the Settings screen. ViaPage = "page" // ViaSettingsChat: the agent of the Settings window's chat changed it at once. ViaSettingsChat = "settings-chat" // ViaConfirmed: an agent of another chat proposed it and the person said yes. ViaConfirmed = "confirmed" )
How a change was made.
const ( StateWaiting = "waiting" StateApplied = "applied" StateDeclined = "declined" StateExpired = "expired" )
The states of a proposal.
const JournalKept = 500
JournalKept is how many changes the journal keeps; the oldest go first.
const (
// MaxWhy is the longest reason an agent gives.
MaxWhy = 300
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Actor ¶
type Actor struct {
Kind string `json:"kind"`
// Conv and Title are the agent's chat (its title as it was then); empty for a person.
Conv string `json:"conv,omitempty"`
Title string `json:"title,omitempty"`
}
Actor is who made a change: a person, or the agent of a chat.
type Change ¶
type Change struct {
ID string `json:"id"`
At int64 `json:"at"`
Key string `json:"key"`
Title string `json:"title"`
// Old and New are the values; OldLabel and NewLabel the same in words.
Old string `json:"old"`
New string `json:"new"`
OldLabel string `json:"oldLabel"`
NewLabel string `json:"newLabel"`
By Actor `json:"by"`
Via string `json:"via"`
// Why is the agent's one line of why it changed the setting.
Why string `json:"why,omitempty"`
// Note, when not empty, says that the value was not set here but passed on, and what it waits for.
Note string `json:"note,omitempty"`
}
Change is one line of the journal.
type Item ¶
type Item struct {
Key, Section, Title, Description string
Kind Kind
// Options are the values of an enum, asked each time (the providers and their models change).
Options func() []Option
Min, Max int
Get func() (string, error)
// Set is given a value that passed the check of its kind.
Set func(value string) error
// SetBy, when set, is called in place of Set and is also told who asks (a change that is made elsewhere, in the
// hub, says the chat it comes from). Its note, when not empty, says what became of the value in place of a
// change made here: it was passed on and waits for someone else's yes.
SetBy func(value string, by Actor) (note string, err error)
// Free lets an enum take a value that is none of Options when it says so (a model the provider does not list);
// for a text it is the whole check.
Free func(value string) bool
// Why says in words why a value was not taken, when the setting can tell; nil or "": the common words.
Why func(value string) string
// Label says a text's value in words for the person (the card of a change, the journal); nil: the value itself.
Label func(value string) string
// Replaces says what a value that changes a part of a text takes the place of, in words ("" when it only adds);
// part is false when the value is the whole text. nil: every value is the whole.
Replaces func(value string) (label string, part bool)
}
Item is a setting with the way to read and to change it.
type Journal ¶
type Journal struct {
Path string
// contains filtered or unexported fields
}
Journal is the changes of the settings in a file, a JSON line each, the newest last.
type Outcome ¶
type Outcome struct {
// State: applied (the setting is changed), waiting (the person has not answered yet), declined, expired.
State string `json:"status"`
// Change is the journal line of an applied change.
Change *Change `json:"change,omitempty"`
// Proposal is the card the person answers; absent for a change of the Settings window's chat, made at once.
Proposal *Proposal `json:"proposal,omitempty"`
}
Outcome is what an agent's proposal came to.
type Proposal ¶
type Proposal struct {
ID string `json:"id"`
At int64 `json:"at"`
Key string `json:"key"`
Title string `json:"title"`
Old string `json:"old"`
New string `json:"new"`
OldLabel string `json:"oldLabel"`
NewLabel string `json:"newLabel"`
Why string `json:"why,omitempty"`
// Conv and ConvTitle are the chat whose agent asks; the card is shown there.
Conv string `json:"conv"`
ConvTitle string `json:"convTitle"`
State string `json:"state"`
// Failed says why a change the person agreed to was not made, in the setting's words; "" for one that was not
// tried or was made. Such a proposal is declined: nothing changed.
Failed string `json:"failed,omitempty"`
}
Proposal is a change an agent asks the person to confirm: the card of the chat.
type Refusal ¶
type Refusal struct {
Reason string
Setting *Setting
Err error
// Message is the setting's own words for the refusal, when it has some.
Message string
}
Refusal is a reason the caller is told; Setting is the setting it is about when there is one, so that the caller can be shown what values it takes.
type Said ¶
type Said struct{ Message string }
Said is an error of a setting's Set whose words are for the person and the agent: a change that was refused where it is made (the hub said the person has no right to it).
type Service ¶
type Service struct {
// Items are the settings, in the order the catalog lists them.
Items []Item
Journal *Journal
// SettingsChat says whether a chat is the Settings window's own: its agent changes a setting at once.
SettingsChat func(conv string) bool
Now func() time.Time
// contains filtered or unexported fields
}
Service is the catalog with its proposals and its journal.
func (*Service) Approve ¶
Approve is the person's yes: the setting is changed as the agent of the proposal's chat, and the proposal is applied. A change the setting no longer takes (it has the value already, the value is gone) closes the proposal as declined and is told.
func (*Service) List ¶
List is the catalog with the values of now. A setting that cannot be read is left out.
func (*Service) Propose ¶
Propose is an agent's change of a setting. The agent of the Settings window's chat changes it at once. Any other agent leaves a proposal for the person: the one that waits already for the same change of the same chat, else a new one.
func (*Service) Record ¶
Record writes into the journal a change that was made past the catalog (a person saved the Settings screen): the values are told, nothing is set.
func (*Service) Rev ¶
Rev is the revision of the journal and the proposals: it moves with every change of either.
func (*Service) Touch ¶
func (s *Service) Touch()
Touch moves the revision without a change of a setting: a page that watches reads what else it watches (the agents' looks, cmd/runtime routes_looks.go).
type Setting ¶
type Setting struct {
Key string `json:"key"`
// Section is the part of Settings it belongs to, in words.
Section string `json:"section"`
Title string `json:"title"`
Description string `json:"description"`
Kind Kind `json:"kind"`
Options []Option `json:"options,omitempty"`
Min *int `json:"min,omitempty"`
Max *int `json:"max,omitempty"`
// Value is what the setting is now; ValueLabel the same in words.
Value string `json:"value"`
ValueLabel string `json:"valueLabel"`
}
Setting is a setting as the catalog lists it.