question

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 6 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

Question lifecycle service

Question payload types and their JSON acceptance checks.

Index

Constants

This section is empty.

Variables

View Source
var Default = NewService(nil, nil)

Default is the package-level service backed by bus.Default.

View Source
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 Answer

type Answer []string

Answer contains the selected labels for one question.

type AskInput

type AskInput struct {
	SessionID string
	Questions []Info
	Tool      *Tool
}

AskInput is the input accepted by Service.Ask.

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 Option

type Option struct {
	Label       string `json:"label"`
	Description string `json:"description"`
}

Option is one selectable response.

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

func (s *Service) Ask(ctx context.Context, input AskInput) ([]Answer, error)

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) List

func (s *Service) List() []Request

List returns pending requests in insertion order.

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.

type Tool

type Tool struct {
	MessageID string `json:"messageID"`
	CallID    string `json:"callID"`
}

Tool links a question request to its originating tool call.

Jump to

Keyboard shortcuts

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