Documentation
¶
Overview ¶
Question lifecycle service
Question payload types and their JSON acceptance checks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = NewService(nil, nil)
Default is the package-level service backed by bus.Default.
var Event = struct { Asked bus.Definition Replied bus.Definition Rejected bus.Definition }{ Asked: bus.Define("question.asked", "QuestionRequest"), Replied: bus.Define("question.replied", "QuestionReplied"), Rejected: bus.Define("question.rejected", "QuestionRejected"), }
Event contains the three question bus definitions.
Functions ¶
func SchemaAccepts ¶
func SchemaAccepts(kind, mode string, raw json.RawMessage) bool
SchemaAccepts reports whether raw is a valid JSON encoding of the named question type. Mode "strict" additionally requires branded ID strings to carry their prefix; mode "basic" checks structure only.
Types ¶
type IDGenerator ¶
type IDGenerator func() (QuestionID, error)
IDGenerator creates a new ascending question identifier.
type Info ¶
type Info struct {
Question string `json:"question"`
Header string `json:"header"`
Options []Option `json:"options"`
Multiple *bool `json:"multiple,omitempty"`
Custom *bool `json:"custom,omitempty"`
}
Info describes a question presented to a user.
type Prompt ¶
type Prompt struct {
Question string `json:"question"`
Header string `json:"header"`
Options []Option `json:"options"`
Multiple *bool `json:"multiple,omitempty"`
}
Prompt is the tool-facing question shape before the custom-answer flag is added.
type Publisher ¶
type Publisher interface {
Publish(bus.Definition, any, ...bus.PublishOptions)
}
Publisher is the narrow bus surface used by Service.
type QuestionID ¶
type QuestionID string
QuestionID is the branded string used to identify a pending question.
func AscendingQuestionID ¶
func AscendingQuestionID(given ...string) (QuestionID, error)
AscendingQuestionID returns a new ascending question ID, or validates and returns given.
type Rejected ¶
type Rejected struct {
SessionID string `json:"sessionID"`
RequestID QuestionID `json:"requestID"`
}
Rejected is the payload of question.rejected.
type RejectedError ¶
type RejectedError struct{}
RejectedError is returned when a question is dismissed or the service is finalized.
func (*RejectedError) Error ¶
func (*RejectedError) Error() string
Error is the model-visible dismissal message.
type Replied ¶
type Replied struct {
SessionID string `json:"sessionID"`
RequestID QuestionID `json:"requestID"`
Answers []Answer `json:"answers"`
}
Replied is the payload of question.replied.
type Reply ¶
type Reply struct {
Answers []Answer `json:"answers"`
}
Reply is the HTTP/tool reply body.
type ReplyInput ¶
type ReplyInput struct {
RequestID QuestionID
Answers []Answer
}
ReplyInput is the input accepted by Service.Reply.
type Request ¶
type Request struct {
ID QuestionID `json:"id"`
SessionID string `json:"sessionID"`
Questions []Info `json:"questions"`
Tool *Tool `json:"tool,omitempty"`
}
Request is the payload of question.asked.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the insertion-ordered pending-question map.
func NewService ¶
func NewService(publisher Publisher, createID IDGenerator) *Service
NewService constructs a question service. Nil dependencies use the package-level bus and QuestionID generator.
func (*Service) Ask ¶
Ask registers and publishes a request, then waits for a reply, rejection, or context cancellation. The pending entry is removed on every exit path.
func (*Service) Close ¶
func (s *Service) Close()
Close rejects every waiter, clears the pending map, and makes subsequent asks fail as dismissed.
func (*Service) Reject ¶
func (s *Service) Reject(requestID QuestionID)
Reject publishes the rejection and fails its pending Ask. Unknown request IDs are ignored.
func (*Service) Reply ¶
func (s *Service) Reply(input ReplyInput)
Reply publishes the reply and resolves its pending Ask. Unknown request IDs are ignored.