httpapi

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 37 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,
}
View Source
var TransportValues = []Transport{
	TransportPTY,
	TransportACP,
}

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 ErrorBody added in v0.12.0

type ErrorBody struct {
	Message string        `json:"message" doc:"Error message"`
	Level   st.ErrorLevel `json:"level" doc:"Error level"`
	Time    time.Time     `json:"time" doc:"Timestamp when the error occurred"`
}

type Event

type Event struct {
	Type    EventType
	Payload any
}

type EventEmitter

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

func NewEventEmitter

func NewEventEmitter(opts ...EventEmitterOption) *EventEmitter

func (*EventEmitter) EmitError added in v0.12.0

func (e *EventEmitter) EmitError(message string, level st.ErrorLevel)

func (*EventEmitter) EmitMessages added in v0.12.0

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

EmitMessages 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) EmitScreen added in v0.12.0

func (e *EventEmitter) EmitScreen(newScreen string)

func (*EventEmitter) EmitStatus added in v0.12.0

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

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)

type EventEmitterOption added in v0.12.0

type EventEmitterOption func(*EventEmitter)

func WithAgentType added in v0.12.0

func WithAgentType(agentType mf.AgentType) EventEmitterOption

func WithClock added in v0.12.0

func WithClock(clock quartz.Clock) EventEmitterOption

func WithSubscriptionBufSize added in v0.12.0

func WithSubscriptionBufSize(size uint) EventEmitterOption

type EventType

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

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.8.0

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

func (*Server) SaveState added in v0.12.0

func (s *Server) SaveState(source string) error

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. It is safe to call multiple times.

type ServerConfig added in v0.3.3

type ServerConfig struct {
	AgentType              mf.AgentType
	AgentIO                st.AgentIO
	Transport              Transport
	Port                   int
	ChatBasePath           string
	AllowedHosts           []string
	AllowedOrigins         []string
	InitialPrompt          string
	Clock                  quartz.Clock
	StatePersistenceConfig st.StatePersistenceConfig
}

type SetupACPConfig added in v0.12.0

type SetupACPConfig struct {
	Program     string
	ProgramArgs []string
	Clock       quartz.Clock
}

type SetupACPResult added in v0.12.0

type SetupACPResult struct {
	AgentIO *acpio.ACPAgentIO
	Wait    func() error  // Calls cmd.Wait() and returns exit error
	Done    chan struct{} // Close this when Wait() returns to clean up goroutine
}

SetupACPResult contains the result of setting up an ACP process.

func SetupACP added in v0.12.0

func SetupACP(ctx context.Context, config SetupACPConfig) (*SetupACPResult, error)

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"`
	AgentType mf.AgentType `json:"agent_type" doc:"Type of the agent being used by the server."`
}

type StatusResponse

type StatusResponse struct {
	Body struct {
		Status    AgentStatus  `` /* 158-byte string literal not displayed */
		AgentType mf.AgentType `json:"agent_type" doc:"Type of the agent being used by the server."`
		Transport Transport    `json:"transport" doc:"Backend transport being used ('acp' or 'pty')."`
	}
}

StatusResponse represents the server status

type Transport added in v0.12.0

type Transport string
const (
	TransportPTY Transport = "pty"
	TransportACP Transport = "acp"
)

func (Transport) Schema added in v0.12.0

func (tr Transport) Schema(r huma.Registry) *huma.Schema

type UploadRequest added in v0.10.0

type UploadRequest struct {
	File huma.FormFile `form:"file" required:"true" doc:"file that needs to be uploaded"`
}

type UploadResponse added in v0.10.0

type UploadResponse struct {
	Body struct {
		Ok       bool   `json:"ok" doc:"Indicates whether the files were uploaded successfully."`
		FilePath string `json:"filePath" doc:"Path of the file"`
	}
}

Jump to

Keyboard shortcuts

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