Documentation
¶
Overview ¶
Package noticeslot is the smart notice's open slot: an app (through its SDK) or an agent (through the `harnessly notice` command or the notice_ask MCP tool) shows the person a ready element in the black plate — a status, a progress, a choice, a confirmation, a short field, code cells or a view of its own — and gets the answer back. One description serves the three ways in. The page lists what is open and answers it.
What the slot never does: ask for a password, a key or a sign-in. There is no password field in any kind, a view of its own that brings one is refused, a field worded as a password or key is refused, and a typed answer that looks like a key is turned back with a pointer to the safe. Secrets go through the safe and the site sign-in.
It lives in memory: a notice is a question of the moment, and the call that waits for it is gone with a restart too. Only the sources the person turned off are kept (Muted), by the caller.
Index ¶
- Constants
- Variables
- func AsksForSecret(parts ...string) bool
- func Check(sp *Spec) error
- func HasPasswordField(html string) bool
- func LooksSecret(s string) bool
- func Refusal(err error) string
- func ViewIsActive(html string) bool
- type Kind
- type Mutes
- type Notice
- type Result
- type Slot
- func (s *Slot) Answer(id string, value json.RawMessage) error
- func (s *Slot) Ask(ctx context.Context, src Source, conv string, sp Spec) (Result, error)
- func (s *Slot) Close(src Source, id string) error
- func (s *Slot) Dismiss(id string) error
- func (s *Slot) MuteSource(src Source)
- func (s *Slot) Open(src Source, conv string, sp Spec) (Notice, error)
- func (s *Slot) Pending() []Notice
- func (s *Slot) SourceOf(id string) (Source, bool)
- func (s *Slot) Update(src Source, id string, progress *float64, text *string, title *string) error
- func (s *Slot) Wait(ctx context.Context, id string) (Result, bool)
- type Source
- type Spec
- type Tools
Constants ¶
const ( SourceApp = "app" SourceAgent = "agent" )
const ( StatusAnswered = "answered" StatusDismissed = "dismissed" StatusTimeout = "timeout" StatusMuted = "muted" )
const ( DefaultTTL = 10 * time.Minute MaxTTL = 24 * time.Hour StatusTTL = 8 * time.Second MaxShownPerSrc = 3 // waiting notices of one source shown at once on the machine MaxOpenPerSrc = 12 // all open notices of one source, queued ones too RatePerMinute = 5 // new notices of one source a minute MaxTitle = 120 MaxText = 600 MaxOption = 80 MinOptions = 2 MaxOptions = 6 MaxView = 16 << 10 MaxAnswer = 2000 )
Limits.
const ( ToolAsk = "notice_ask" ToolShow = "notice_show" ToolUpdate = "notice_update" ToolClose = "notice_close" )
The agent's MCP tools of the slot: the same description as `harnessly notice` and the SDK's hl.notice.
const AgentCodeRefusal = "refused: an agent does not get one-time codes through the notice. Run the command that needs the code " +
"with `harnessly secret run --code VAR --why \"…\" -- COMMAND`: the person types it in the chat's panel and it goes " +
"straight into the command's environment."
AgentCodeRefusal: an agent never sees a one-time code; the safe hands it to the command that needs it.
Variables ¶
var ( ErrArgs = errors.New("noticeslot: bad notice") ErrSecret = errors.New("noticeslot: the slot does not take passwords, keys or sign-ins; use the safe") ErrBusy = errors.New("noticeslot: this source has too many open notices") ErrRate = errors.New("noticeslot: this source shows notices too often") ErrMuted = errors.New("noticeslot: the person turned this source off") ErrGone = errors.New("noticeslot: no such notice") ErrAnswer = errors.New("noticeslot: the answer does not fit the notice") // ErrAnswerSecret: the person typed something that looks like a key; the page points them to the safe. ErrAnswerSecret = errors.New("noticeslot: the answer looks like a key") )
Functions ¶
func AsksForSecret ¶
AsksForSecret tells a field or code whose wording asks for a password, a key or a sign-in.
func HasPasswordField ¶
HasPasswordField tells a custom view that brings a password input of its own.
func LooksSecret ¶
LooksSecret tells a text that is, or holds, a key, a token or a private key: a known prefix, a JWT, a bot token, or one long random word (at least 24 characters of letters and digits with no spaces, mixed and high in entropy).
func ViewIsActive ¶
ViewIsActive tells a custom view that holds code, a field, a form, a frame or a link: a view is plain layout and buttons that answer with data-answer, and the page draws nothing else.
Types ¶
type Mutes ¶
type Mutes struct {
Path string
// contains filtered or unexported fields
}
Mutes are the sources the person turned off from the plate's menu («Не показывать от …»), kept in a file so they stay off after a restart. Path "" keeps them in memory only (tests).
type Notice ¶
type Notice struct {
ID string `json:"id"`
Spec
Source Source `json:"source"`
Conversation string `json:"conversation,omitempty"`
CreatedAt int64 `json:"createdAt"`
ExpiresAt int64 `json:"expiresAt"`
// Queued: another notice of the same source waits in the same chat before it; the page shows it after that one.
Queued bool `json:"queued,omitempty"`
}
Notice is one open notice as the page lists it.
type Result ¶
type Result struct {
// Status: answered, dismissed (the person said no or closed it), timeout, or muted (the person turned the source off).
Status string `json:"status"`
// Value is the answer: a choice's index ({"choice": n}) or own words ({"text": s}), a confirmation's true/false, a
// field's or code's text, a view's own JSON.
Value json.RawMessage `json:"value,omitempty"`
}
Result is what the caller gets back.
type Slot ¶
type Slot struct {
Now func() time.Time
// Muted tells a source the person turned off; nil for none.
Muted func(Source) bool
// FirstOption answers every choice notice with its first option at once (an eval stand has no person; HRN-1561).
FirstOption bool
// Changed is told when the list changes (the page refreshes); nil for none.
Changed func()
// Journal is told when a notice opens ("open") and when it ends ("end", with its status), for the store to keep
// nil for none. It is called with the slot's lock held, so it must only queue the news.
Journal func(event string, n Notice, status string)
// contains filtered or unexported fields
}
Slot is the machine's open notices.
func (*Slot) Answer ¶
func (s *Slot) Answer(id string, value json.RawMessage) error
Answer is the person's answer; it is checked against the notice's kind. A typed text that looks like a key is refused with ErrAnswerSecret and the notice stays open.
func (*Slot) Ask ¶
Ask shows a notice and waits for its result (a telling kind returns answered at once).
func (*Slot) Close ¶
Close takes a notice away for its source (a progress that ended, a question no longer needed).
func (*Slot) MuteSource ¶
MuteSource ends every open notice of a source the person just turned off.
func (*Slot) Open ¶
Open shows a notice and returns it at once; Wait gets its result. The same question from the same source in the same chat while the first is open joins it (its id comes back), so a caller that repeats itself shows one plate.
func (*Slot) Pending ¶
Pending is what the page shows: the open notices, oldest first; of one source in one chat only the first is shown, the rest are Queued behind it, and at most MaxShownPerSrc waiting ones of a source are shown on the machine.
type Source ¶
Source is who asks: an app (ID is its id, Name its name from the manifest) or the agent of a chat (ID is the chat). The page draws it as the label over the plate, which the caller cannot change.
type Spec ¶
type Spec struct {
Kind Kind `json:"kind"`
Title string `json:"title"`
Text string `json:"text,omitempty"`
// Icon is a harnessly icon name for the plate; empty for the kind's own.
Icon string `json:"icon,omitempty"`
// Options are a choice's 2…6 answers; Own adds a line for the person's own words.
Options []string `json:"options,omitempty"`
Own bool `json:"own,omitempty"`
// Yes and No name a confirmation's buttons; Danger marks an action that cannot be undone.
Yes string `json:"yes,omitempty"`
No string `json:"no,omitempty"`
Danger bool `json:"danger,omitempty"`
// Placeholder is a field's hint while it is empty (a field is one line).
Placeholder string `json:"placeholder,omitempty"`
// Digits is a code's length, 4…8.
Digits int `json:"digits,omitempty"`
// Progress is a progress's share done, 0…1; nil while it is not known.
Progress *float64 `json:"progress,omitempty"`
// View is a view of its own: an HTML fragment of layout and buttons (data-answer), drawn with the plate's tokens and kit.
View string `json:"view,omitempty"`
// TimeoutSec is how long it waits; 0 for the default, at most a day.
TimeoutSec int `json:"timeoutSec,omitempty"`
}
Spec is what a caller asks to show.