httpapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageTypeValues = []MessageType{
	MessageTypeUser,
	MessageTypeRaw,
}

Functions

func FormatMessage

func FormatMessage(agentType mf.AgentType, message string) []st.MessagePart

func SetupProcess

func SetupProcess(ctx context.Context, program string, programArgs ...string) (*termexec.Process, error)

Types

type AgentStatus

type AgentStatus string
const (
	AgentStatusRunning AgentStatus = "running"
	AgentStatusStable  AgentStatus = "stable"
)

func (AgentStatus) Schema

func (a AgentStatus) Schema(r huma.Registry) *huma.Schema

type Event

type Event struct {
	Type    EventType
	Payload any
}

type EventEmitter

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

func NewEventEmitter

func NewEventEmitter(subscriptionBufSize int) *EventEmitter

subscriptionBufSize is the size of the buffer for each subscription. Once the buffer is full, the channel will be closed. Listeners must actively drain the channel, so it's important to set this to a value that is large enough to handle the expected number of events.

func (*EventEmitter) Subscribe

func (e *EventEmitter) Subscribe() (int, <-chan Event, []Event)

Subscribe returns: - a subscription ID that can be used to unsubscribe. - a channel for receiving events. - a list of events that allow to recreate the state of the conversation right before the subscription was created.

func (*EventEmitter) Unsubscribe

func (e *EventEmitter) Unsubscribe(chanId int)

func (*EventEmitter) UpdateMessagesAndEmitChanges

func (e *EventEmitter) UpdateMessagesAndEmitChanges(newMessages []st.ConversationMessage)

Assumes that only the last message can change or new messages can be added. If a new message is injected between existing messages (identified by Id), the behavior is undefined.

func (*EventEmitter) UpdateScreenAndEmitChanges

func (e *EventEmitter) UpdateScreenAndEmitChanges(newScreen string)

func (*EventEmitter) UpdateStatusAndEmitChanges

func (e *EventEmitter) UpdateStatusAndEmitChanges(newStatus st.ConversationStatus)

type EventType

type EventType string
const (
	EventTypeMessageUpdate EventType = "message_update"
	EventTypeStatusChange  EventType = "status_change"
	EventTypeScreenUpdate  EventType = "screen_update"
)

type Message

type Message struct {
	Id      int                 `` /* 136-byte string literal not displayed */
	Content string              `` /* 197-byte string literal not displayed */
	Role    st.ConversationRole `json:"role" doc:"Role of the message author"`
	Time    time.Time           `json:"time" doc:"Timestamp of the message"`
}

Message represents a message

type MessageRequest

type MessageRequest struct {
	Body MessageRequestBody `json:"body" doc:"Message content and type"`
}

MessageRequest represents a request to create a new message

type MessageRequestBody

type MessageRequestBody struct {
	Content string      `json:"content" example:"Hello, agent!" doc:"Message content"`
	Type    MessageType `` /* 451-byte string literal not displayed */
}

type MessageResponse

type MessageResponse struct {
	Body struct {
		Ok bool `` /* 256-byte string literal not displayed */
	}
}

MessageResponse represents a newly created message

type MessageType

type MessageType string
const (
	MessageTypeUser MessageType = "user"
	MessageTypeRaw  MessageType = "raw"
)

func (MessageType) Schema

func (m MessageType) Schema(r huma.Registry) *huma.Schema

type MessageUpdateBody

type MessageUpdateBody struct {
	Id      int                 `` /* 136-byte string literal not displayed */
	Role    st.ConversationRole `json:"role" doc:"Role of the message author"`
	Message string              `` /* 175-byte string literal not displayed */
	Time    time.Time           `json:"time" doc:"Timestamp of the message"`
}

type MessagesResponse

type MessagesResponse struct {
	Body struct {
		Messages []Message `json:"messages" nullable:"false" doc:"List of messages"`
	}
}

MessagesResponse represents the list of messages

type ScreenUpdateBody

type ScreenUpdateBody struct {
	Screen string `json:"screen"`
}

type Server

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

Server represents the HTTP server

func NewServer

func NewServer(ctx context.Context, agentType mf.AgentType, process *termexec.Process, port int) *Server

NewServer creates a new server instance

func (*Server) GetOpenAPI

func (s *Server) GetOpenAPI() string

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully stops the HTTP server

type StatusChangeBody

type StatusChangeBody struct {
	Status AgentStatus `json:"status" doc:"Agent status"`
}

type StatusResponse

type StatusResponse struct {
	Body struct {
		Status AgentStatus `` /* 158-byte string literal not displayed */
	}
}

StatusResponse represents the server status

Jump to

Keyboard shortcuts

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