communicate

package
v0.1.148 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 6 Imported by: 4

README

How does communication between the CLI and the Agent work?

Disclaimer: Looked briefly at bidirectional communication with Hashicorp plugin model but tabled that for now https://github.com/hashicorp/go-plugin/tree/main/examples/bidirectional

Goal here is to make the API somewhat clean to that we can move to this model later if needed.

Terminology

Since the CLI is the one that initiates the communication, we will call it the client and the agent the server.

Flows
  • Client asks server if communication is required for a given channel
  • If no, client proceeds with the command
  • If yes, client start a communication session with the server until the server is satisfied
Communication session
  • Client sends an initial Information request to the server
  • Server sends back an InformationRequest
  • Client processes the InformationRequest with a handler (CLI prompt) and returns an Answer
  • The Answer is sent back to the server
  • If satisfied, the server communicates back that it is done
  • Otherwise, we repeat the process until the server is satisfied

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Channel added in v0.0.51

func Channel[T any]() *agentv0.Channel

func Display added in v0.0.51

func Display(msg *agentv0.Message, data map[string]string) *agentv0.Question

func Do added in v0.0.51

func Do[T any](ctx context.Context, agent Communicate, handler AnswerProvider) error

func GetDefaultConfirm added in v0.1.89

func GetDefaultConfirm(options []*agentv0.Question, name string) (bool, error)

func GetDefaultStringInput added in v0.1.89

func GetDefaultStringInput(options []*agentv0.Question, name string) (string, error)

func NewChoice added in v0.0.51

func NewChoice(msg *agentv0.Message, options ...*agentv0.Message) *agentv0.Question

func NewConfirm added in v0.0.51

func NewConfirm(msg *agentv0.Message, defaultConfirm bool) *agentv0.Question

func NewIntInput added in v0.1.33

func NewIntInput(msg *agentv0.Message, defaultValue int) *agentv0.Question

func NewSelection added in v0.0.51

func NewSelection(msg *agentv0.Message, options ...*agentv0.Message) *agentv0.Question

func NewStringInput added in v0.0.51

func NewStringInput(msg *agentv0.Message, defaultValue string) *agentv0.Question

func StateAsString

func StateAsString(s *agentv0.Answer) string

Types

type AnswerProvider added in v0.0.51

type AnswerProvider interface {
	Answer(ctx context.Context, question *agentv0.Question) (*agentv0.Answer, error)
}

type ClientSession added in v0.0.51

type ClientSession struct {
	// contains filtered or unexported fields
}

func NewClientSession added in v0.0.51

func NewClientSession(channel *agentv0.Channel, handler AnswerProvider) *ClientSession

func (*ClientSession) Engage added in v0.0.51

type Communicate added in v0.0.51

type Communicate interface {
	Communicate(ctx context.Context, req *agentv0.Engage) (*agentv0.InformationRequest, error)
}

type Generator added in v0.0.51

type Generator struct {
	Kind              string
	QuestionGenerator QuestionGenerator
}

func New added in v0.0.51

func New[T any](gen QuestionGenerator) *Generator

type QuestionGenerator added in v0.0.51

type QuestionGenerator interface {
	Ready() bool
	Process(ctx context.Context, req *agentv0.Engage) (*agentv0.InformationRequest, error)
}

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

func NewSequence

func NewSequence(qs ...*agentv0.Question) *Sequence

func (*Sequence) Process

func (*Sequence) Ready

func (s *Sequence) Ready() bool

type Server added in v0.0.51

type Server struct {
	// contains filtered or unexported fields
}

Server is the Agent

func NewServer added in v0.0.51

func NewServer(_ context.Context) *Server

func (*Server) Channels added in v0.0.91

func (server *Server) Channels() []string

func (*Server) Communicate added in v0.0.51

func (server *Server) Communicate(ctx context.Context, req *agentv0.Engage) (*agentv0.InformationRequest, error)

Communicate from the generator and sends back information request required

func (*Server) Done added in v0.0.51

func (server *Server) Done(ctx context.Context, channel *agentv0.Channel) (*ServerSession, error)

func (*Server) Log added in v0.0.91

func (server *Server) Log(ctx context.Context)

func (*Server) Ready added in v0.0.51

func (server *Server) Ready(s string) bool

func (*Server) Register added in v0.0.51

func (server *Server) Register(ctx context.Context, generator *Generator) error

func (*Server) RequiresCommunication added in v0.0.51

func (server *Server) RequiresCommunication(channel *agentv0.Channel) (*ServerContext, bool)

type ServerContext

type ServerContext struct {
	// contains filtered or unexported fields
}

func NewServerContext

func NewServerContext(_ context.Context, gen QuestionGenerator) *ServerContext

func (*ServerContext) Communicate

func (*ServerContext) Done

func (c *ServerContext) Done() bool

type ServerSession added in v0.0.51

type ServerSession struct {
	// contains filtered or unexported fields
}

func NewServerSession added in v0.0.51

func NewServerSession(generator QuestionGenerator) *ServerSession

func (*ServerSession) Choice added in v0.1.31

func (session *ServerSession) Choice(stage string) (*agentv0.ChoiceAnswer, error)

func (*ServerSession) Confirm added in v0.0.51

func (session *ServerSession) Confirm(stage string) (bool, error)

func (*ServerSession) GetInputString added in v0.0.51

func (session *ServerSession) GetInputString(stage string) (string, error)

func (*ServerSession) GetIntString added in v0.1.33

func (session *ServerSession) GetIntString(stage string) (int, error)

func (*ServerSession) GetState added in v0.0.91

func (session *ServerSession) GetState() map[string]*agentv0.Answer

func (*ServerSession) Input added in v0.0.51

func (session *ServerSession) Input(stage string) (*agentv0.InputAnswer, error)

func (*ServerSession) Process added in v0.0.51

func (session *ServerSession) Process(ctx context.Context, eng *agentv0.Engage) (*agentv0.InformationRequest, error)

func (*ServerSession) Ready added in v0.0.51

func (session *ServerSession) Ready() bool

func (*ServerSession) Selection added in v0.0.51

func (session *ServerSession) Selection(stage string) (*agentv0.SelectionAnswer, error)

func (*ServerSession) String added in v0.0.51

func (session *ServerSession) String() string

Jump to

Keyboard shortcuts

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