userinput

package
v0.502.7 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package userinput provides a blocking question/answer service that lets the agent ask the user structured, selectable questions mid-task and wait for the response. It mirrors the architecture of internal/permission: a tool blocks on a channel, a pubsub event is published, a frontend renders an overlay and responds, unblocking the tool. The difference is that userinput returns structured data (selected options) instead of a boolean.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	QuestionID string   `json:"question_id"`
	Selected   []string `json:"selected"`
	OtherText  string   `json:"other_text,omitempty"`
}

Answer holds the user's response to a single question.

type AskResponse

type AskResponse struct {
	Answers   []Answer `json:"answers"`
	Cancelled bool     `json:"cancelled"`
}

AskResponse is the result returned to the blocking caller.

type CreateAskRequest

type CreateAskRequest struct {
	SessionID string     `json:"session_id"`
	Questions []Question `json:"questions"`
}

CreateAskRequest is the input to Ask.

type Option

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

Option is a single selectable choice within a Question.

type Question

type Question struct {
	ID          string   `json:"id"`
	Header      string   `json:"header"`
	Question    string   `json:"question"`
	MultiSelect bool     `json:"multi_select"`
	Options     []Option `json:"options"`
}

Question is a single question presented to the user, with selectable options.

type QuestionRequest

type QuestionRequest struct {
	ID        string     `json:"id"`
	SessionID string     `json:"session_id"`
	Questions []Question `json:"questions"`
}

QuestionRequest is the pubsub event payload broadcast to frontends.

type Service

type Service interface {
	pubsub.Suscriber[QuestionRequest]
	// Ask publishes a question request and blocks until the user responds or
	// the request is cancelled.
	Ask(req CreateAskRequest) AskResponse
	// Respond delivers a response to a blocked Ask call.
	Respond(id string, resp AskResponse)
	// Cancel cancels a pending request, unblocking Ask with Cancelled=true.
	Cancel(id string)
	// PendingRequests returns the published requests for a session that are
	// still awaiting a response. Used to replay prompts to reconnecting clients.
	PendingRequests(sessionID string) []QuestionRequest
}

Service is the userinput service interface, parallel to permission.Service.

func NewService

func NewService() Service

NewService creates a new userinput service.

Jump to

Keyboard shortcuts

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