Documentation
¶
Overview ¶
Package server contains the REST API server, routers, and handlers.
Index ¶
- Constants
- Variables
- type Account
- type Claims
- type Game
- type HealthCheck
- type Prompt
- type Prompter
- type Prompts
- type Server
- func (s *Server) Cache(ctx context.Context) cache.Accessor
- func (s *Server) Close()
- func (s *Server) ConnectDB()
- func (s *Server) DB() *mongo.Database
- func (s *Server) Health() uint32
- func (s *Server) HealthHandler() http.Handler
- func (s *Server) Mux(w http.ResponseWriter, r *http.Request)
- func (s *Server) Serve() error
- func (s *Server) SetCache(cache cache.Accessor)
- func (s *Server) SetDB(db *mongo.Client)
- func (s *Server) SetHealth(code uint32)
- func (s *Server) SetPrompter(p Prompter)
- func (s *Server) SetRepoClient(cli repo.Client)
- func (s *Server) Shutdown(ctx context.Context)
- func (s *Server) UpdateAuthConfig()
- func (s *Server) UpdateGameImports()
- func (s *Server) UpdateGamePrompts()
- func (s *Server) UpdateMetrics(ctx context.Context) error
- type User
Constants ¶
const ( CtxKeyGameNoCount = "game_no_count" CtxKeyGameMinData = "game_min_data" CtxKeyGameAllowPreviousID = "game_allow_previous_id" CtxKeyGameAllowTags = "game_allow_tags" )
Context keys.
Variables ¶
var Version = ""
The server version.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { ID request.FieldString `bson:"id" json:"id" yaml:"id"` Name request.FieldString `bson:"name" json:"name" yaml:"name"` Status request.FieldString `bson:"status" json:"status" yaml:"status"` StatusData request.FieldJSON `bson:"status_data" json:"status_data" yaml:"status_data"` Repo request.FieldString `bson:"repo" json:"repo" yaml:"repo"` RepoStatus request.FieldString `bson:"repo_status" json:"repo_status" yaml:"repo_status"` RepoStatusData request.FieldJSON `bson:"repo_status_data" json:"repo_status_data" yaml:"repo_status_data"` GameCommitHash request.FieldString `bson:"game_commit_hash" json:"game_commit_hash" yaml:"game_commit_hash"` GameLimit request.FieldInt64 `bson:"game_limit" json:"game_limit" yaml:"game_limit"` Secret request.FieldString `bson:"secret" json:"secret" yaml:"secret"` AIAPIKey request.FieldString `bson:"ai_api_key" json:"ai_api_key" yaml:"ai_api_key"` AIMaxTokens request.FieldInt64 `bson:"ai_max_tokens" json:"ai_max_tokens" yaml:"ai_max_tokens"` AIThinkingBudget request.FieldInt64 `bson:"ai_thinking_budget" json:"ai_thinking_budget" yaml:"ai_thinking_budget"` Data request.FieldJSON `bson:"data" json:"data" yaml:"data"` CreatedAt request.FieldTime `bson:"created_at" json:"created_at" yaml:"created_at"` UpdatedAt request.FieldTime `bson:"updated_at" json:"updated_at" yaml:"updated_at"` }
Account values represent account data.
func (*Account) ValidateCreate ¶
ValidateCreate checks that the value contains valid data for creation.
type Claims ¶
type Claims struct { AccountID string `json:"account_id"` AccountName string `json:"account_name"` UserID string `json:"user_id"` Scopes string `json:"scopes"` }
Claims values contain token claims information.
type Game ¶
type Game struct { AccountID request.FieldString `bson:"account_id" json:"account_id" yaml:"account_id"` Debug request.FieldBool `bson:"debug" json:"debug" yaml:"debug"` Pause request.FieldBool `bson:"pause" json:"pause" yaml:"pause"` Public request.FieldBool `bson:"public" json:"public" yaml:"public"` W request.FieldInt64 `bson:"w" json:"w" yaml:"w"` H request.FieldInt64 `bson:"h" json:"h" yaml:"h"` ID request.FieldString `bson:"id" json:"id" yaml:"id"` PreviousID request.FieldString `bson:"previous_id" json:"previous_id" yaml:"previous_id"` Name request.FieldString `bson:"name" json:"name" yaml:"name"` Version request.FieldString `bson:"version" json:"version" yaml:"version"` Description request.FieldString `bson:"description" json:"description" yaml:"description"` Icon request.FieldString `bson:"icon" json:"icon" yaml:"icon"` Status request.FieldString `bson:"status" json:"status" yaml:"status"` StatusData request.FieldJSON `bson:"status_data" json:"status_data" yaml:"status_data"` Subject request.FieldJSON `bson:"subject" json:"subject" yaml:"subject"` Objects request.FieldJSON `bson:"objects" json:"objects" yaml:"objects"` Images request.FieldJSON `bson:"images" json:"images" yaml:"images"` Script request.FieldString `bson:"script" json:"script" yaml:"script"` Source request.FieldString `bson:"source" json:"source" yaml:"source"` CommitHash request.FieldString `bson:"commit_hash" json:"commit_hash" yaml:"commit_hash"` Tags request.FieldStringArray `bson:"tags" json:"tags" yaml:"tags"` Prompts request.FieldJSON `bson:"prompts" json:"prompts" yaml:"prompts"` CreatedAt request.FieldTime `bson:"created_at" json:"created_at" yaml:"created_at"` CreatedBy request.FieldString `bson:"created_by" json:"created_by" yaml:"created_by"` UpdatedAt request.FieldTime `bson:"updated_at" json:"updated_at" yaml:"updated_at"` UpdatedBy request.FieldString `bson:"updated_by" json:"updated_by" yaml:"updated_by"` }
Game values represent game state data.
func (*Game) ValidateCreate ¶
ValidateCreate checks that the value contains valid data for creation.
type HealthCheck ¶
type HealthCheck struct { Service string `json:"service,omitempty"` Version string `json:"version,omitempty"` CommitID string `json:"commit_id,omitempty"` BuildTime string `json:"build_time,omitempty"` Health uint32 `json:"health,omitempty"` }
HealthCheck values represent return information from health checks.
type Prompt ¶
type Prompt struct { Prompt request.FieldString `bson:"prompt" json:"prompt" yaml:"prompt"` Response request.FieldString `bson:"response" json:"response" yaml:"response"` Thinking request.FieldString `bson:"thinking" json:"thinking" yaml:"thinking"` }
Prompt values represent a single AI prompt and response.
type Prompter ¶
Prompter values are able to send prompts to AI services.
func NewAnthropicPrompter ¶
NewMockPrompter creates a new mock prompter with the given response, state and delay.
type Prompts ¶
type Prompts struct { Current Prompt `bson:"current" json:"current" yaml:"current"` History []Prompt `bson:"history" json:"history" yaml:"history"` Error request.FieldString `bson:"error" json:"error" yaml:"error"` GameID request.FieldString `bson:"game_id" json:"game_id" yaml:"game_id"` }
Prompts values contain the AI prompt data for a game.
type Server ¶
Server values implement HTTP server functionality.
func NewServer ¶
func NewServer(cfg *config.Config, log logger.Logger, metric metric.Recorder, tracer trace.Tracer, ) (*Server, error)
NewServer creates a new HTTP server.
func (*Server) HealthHandler ¶
HealthHandler returns a route handler for /health requests.
func (*Server) Mux ¶
func (s *Server) Mux(w http.ResponseWriter, r *http.Request)
Mux routes and serves a request.
func (*Server) SetPrompter ¶
SetPrompter sets the AI prompt sending interface client.
func (*Server) SetRepoClient ¶
SetRepoClient sets the git repository client to be used for imports.
func (*Server) UpdateAuthConfig ¶
func (s *Server) UpdateAuthConfig()
UpdateAuthConfig retrieves and begins periodic update of authentication configuration data, if configured to do so.
func (*Server) UpdateGameImports ¶
func (s *Server) UpdateGameImports()
UpdateGameImports periodically checks the import repository for game updates.
func (*Server) UpdateGamePrompts ¶
func (s *Server) UpdateGamePrompts()
UpdateGamePrompts periodically updates pending game prompts.
type User ¶
type User struct { AccountID request.FieldString `bson:"account_id" json:"account_id" yaml:"account_id"` ID request.FieldString `bson:"id" json:"id" yaml:"id"` Email request.FieldString `bson:"email" json:"email" yaml:"email"` LastName request.FieldString `bson:"last_name" json:"last_name" yaml:"last_name"` FirstName request.FieldString `bson:"first_name" json:"first_name" yaml:"first_name"` Status request.FieldString `bson:"status" json:"status" yaml:"status"` Scopes request.FieldString `bson:"scopes" json:"scopes" yaml:"scopes"` Data request.FieldJSON `bson:"data" json:"data" yaml:"data"` Password *string `bson:"password,omitempty" json:"password,omitempty" yaml:"password,omitempty"` CreatedAt request.FieldTime `bson:"created_at" json:"created_at" yaml:"created_at"` CreatedBy request.FieldString `bson:"created_by" json:"created_by" yaml:"created_by"` UpdatedAt request.FieldTime `bson:"updated_at" json:"updated_at" yaml:"updated_at"` UpdatedBy request.FieldString `bson:"updated_by" json:"updated_by" yaml:"updated_by"` }
User values represent user data.
func (*User) ValidateCreate ¶
ValidateCreate checks that the value contains valid data for creation.