httpapi

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 30 Imported by: 0

README

The chat/marker file allows the agentapi binary to be built without populating the chat directory with real files. If the directory was empty, go build would fail.

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func FileServerWithIndexFallback added in v0.2.0

func FileServerWithIndexFallback(chatBasePath string) http.Handler

FileServerWithIndexFallback creates a file server that serves the given filesystem and falls back to index.html for any path that doesn't match a file

func FormatMessage

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

func SetupProcess

func SetupProcess(ctx context.Context, config SetupProcessConfig) (*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              `` /* 215-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              `` /* 193-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, config ServerConfig) (*Server, error)

NewServer creates a new server instance

func (*Server) GetOpenAPI

func (s *Server) GetOpenAPI() string

func (*Server) Handler added in v0.3.1

func (s *Server) Handler() http.Handler

Handler returns the underlying chi.Router for testing purposes.

func (*Server) NormalizeSchema added in v0.9.0

func (s *Server) NormalizeSchema(schema any) any

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server

func (*Server) StartSnapshotLoop added in v0.2.0

func (s *Server) StartSnapshotLoop(ctx context.Context)

func (*Server) Stop

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

Stop gracefully stops the HTTP server

type ServerConfig added in v0.3.3

type ServerConfig struct {
	AgentType      mf.AgentType
	Process        *termexec.Process
	Port           int
	ChatBasePath   string
	AllowedHosts   []string
	AllowedOrigins []string
	InitialPrompt  string
}

type SetupProcessConfig added in v0.2.2

type SetupProcessConfig struct {
	Program        string
	ProgramArgs    []string
	TerminalWidth  uint16
	TerminalHeight uint16
	AgentType      mf.AgentType
}

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