server

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, opts Options) error

Run starts the HTTP server synchronously and returns when it shuts down. Cancelling ctx triggers a graceful shutdown; when ctx is nil the server runs until the process is killed.

Types

type AiContextDTO added in v0.0.10

type AiContextDTO struct {
	Cluster         string `json:"cluster"`
	Database        string `json:"database"`
	Content         string `json:"content"`
	UpdatedAt       string `json:"updatedAt,omitempty"`
	MaxContentBytes int    `json:"maxContentBytes"`
}

AiContextDTO is the response shape for GET /api/aictx. Content is the user-authored prompt context for the active (cluster, database). When no context is configured the field is empty and updatedAt is omitted. MaxContentBytes echoes the server-side byte cap so the SPA can show an accurate counter and pre-validate without hard-coding the limit.

type AnalyzeRequest added in v0.0.2

type AnalyzeRequest struct {
	SQL        string `json:"sql"`
	ResultBlob string `json:"resultBlob"`
	Focus      string `json:"focus,omitempty"`
	// contains filtered or unexported fields
}

AnalyzeRequest is the JSON body of POST /api/ai/analyze. ResultBlob is a CSV rendering of the last result produced by the SPA — we send it verbatim rather than re-running the query.

type AskRequest added in v0.0.2

type AskRequest struct {
	Messages []MessageDTO `json:"messages"`
	// contains filtered or unexported fields
}

AskRequest is the JSON body of POST /api/ai/ask. Messages is the full multi-turn history (SPA-managed); the server does not keep conversation state.

type AskResponse added in v0.0.2

type AskResponse struct {
	SQL          string `json:"sql"`
	IsReadOnly   bool   `json:"isReadOnly"`
	AutoRunnable bool   `json:"autoRunnable"`
}

AskResponse is the JSON body of POST /api/ai/ask. The SQL has already been stripped of Markdown code fences by bedrock.Ask. IsReadOnly is the runner.IsReadOnlySQL classification of the same SQL; AutoRunnable is the stricter server-side gate the SPA uses for immediate execution.

type ClusterInfoDTO added in v0.0.2

type ClusterInfoDTO struct {
	Identifier          string `json:"identifier"`
	ARN                 string `json:"arn"`
	Engine              string `json:"engine"`
	Endpoint            string `json:"endpoint"`
	MasterUserSecretArn string `json:"masterUserSecretArn,omitempty"`
}

ClusterInfoDTO is the JSON shape of a single Aurora cluster returned by /api/clusters. Engine lets the SPA pick MySQL vs PostgreSQL when configuring CodeMirror's SQL dialect.

type ClustersDTO added in v0.0.2

type ClustersDTO struct {
	Clusters []ClusterInfoDTO `json:"clusters"`
}

ClustersDTO wraps the /api/clusters list.

type DatabasesDTO added in v0.0.2

type DatabasesDTO struct {
	History []string `json:"history"`
}

DatabasesDTO wraps the /api/databases response. History is the list of DB names previously used for this profile (most recent first), as tracked in state.json.

type ErrorDTO added in v0.0.2

type ErrorDTO struct {
	Error ErrorDetail `json:"error"`
}

ErrorDTO is the uniform shape for error responses. Code is a short, stable string enum for programmatic handling; Message is free-form text for display.

type ErrorDetail added in v0.0.2

type ErrorDetail struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorDetail is the nested object inside ErrorDTO.

type ExecuteRequest added in v0.0.2

type ExecuteRequest struct {
	Profile   string `json:"profile"`
	Cluster   string `json:"cluster"`
	Secret    string `json:"secret"`
	Database  string `json:"database"`
	SQL       string `json:"sql"`
	Confirmed bool   `json:"confirmed,omitempty"`
}

ExecuteRequest is the JSON body of POST /api/execute. All four connection fields are required because the server is stateless — it does not assume the session store has the right values at the moment the request arrives. See ExecuteResponse.NeedsConfirmation for the Confirmed handshake.

type ExecuteResponse added in v0.0.2

type ExecuteResponse struct {
	Columns    []string `json:"columns"`
	Rows       [][]any  `json:"rows"`
	Updated    int64    `json:"updated"`
	DurationMS int64    `json:"durationMs"`

	NeedsConfirmation bool   `json:"needsConfirmation,omitempty"`
	ConfirmReason     string `json:"confirmReason,omitempty"`
}

ExecuteResponse is the JSON body returned by POST /api/execute. Rows is a [][]any so SELECT output preserves native Go types (int64/float64/bool/ []byte-as-base64/null) through JSON marshaling.

NeedsConfirmation signals that the statement is destructive (DELETE / UPDATE without WHERE, TRUNCATE) and the client must re-send with Confirmed=true. It travels on a 200 response rather than a 4xx so access logs and error metrics stay clean for a normal user flow; Columns / Rows / Updated / DurationMS are zero values in that branch and must be ignored — no execution happened.

type ExplainRequest added in v0.0.2

type ExplainRequest struct {
	SQL      string `json:"sql"`
	ErrorMsg string `json:"errorMsg"`
	// contains filtered or unexported fields
}

ExplainRequest is the JSON body of POST /api/ai/explain.

type FavoriteRequest added in v0.0.2

type FavoriteRequest struct {
	At       string `json:"at"`
	Favorite bool   `json:"favorite"`
}

FavoriteRequest is the JSON body of POST /api/history/favorite. At identifies the entry (history is keyed by execution timestamp).

type HealthDTO added in v0.0.2

type HealthDTO struct {
	Status string `json:"status"`
}

HealthDTO is the JSON body of /api/health.

type HistoryDTO added in v0.0.2

type HistoryDTO struct {
	Entries []HistoryEntryDTO `json:"entries"`
}

HistoryDTO wraps the /api/history list (most recent first).

type HistoryEntryDTO added in v0.0.2

type HistoryEntryDTO struct {
	Profile    string `json:"profile"`
	Database   string `json:"database"`
	SQL        string `json:"sql"`
	At         string `json:"at"`
	Ok         bool   `json:"ok"`
	DurationMS int64  `json:"durationMs"`
	Error      string `json:"error,omitempty"`
	Favorite   bool   `json:"favorite,omitempty"`
}

HistoryEntryDTO is the JSON shape of a /api/history entry. Times are rendered as RFC3339Nano strings so the SPA can round-trip them through POST /api/history/favorite.

type MessageDTO added in v0.0.2

type MessageDTO struct {
	Role string `json:"role"`
	Text string `json:"text"`
}

MessageDTO is one turn in a multi-turn conversation sent to /api/ai/ask. Role is "user" or "assistant".

type ModelInfoDTO added in v0.0.2

type ModelInfoDTO struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

ModelInfoDTO is a single Bedrock model / inference profile entry.

type ModelsDTO added in v0.0.2

type ModelsDTO struct {
	Models []ModelInfoDTO `json:"models"`
}

ModelsDTO wraps the /api/ai/models list.

type Options added in v0.0.2

type Options struct {
	// Port is the TCP port to bind on 127.0.0.1. 0 means "pick a free
	// port" which is primarily useful from tests.
	Port int

	// NoOpen disables the automatic browser launch on startup.
	NoOpen bool

	// Dev adds http://localhost:5173 / http://127.0.0.1:5173 (the Vite
	// dev server) to the allowed-origin list so frontend hot-reload works
	// without having to run the Go binary through Vite's proxy in reverse.
	Dev bool

	// Initial* seed the session store before the first GET /api/session.
	InitialProfile         string
	InitialCluster         string
	InitialSecret          string
	InitialDatabase        string
	InitialBedrockModel    string
	InitialBedrockLanguage string
}

Options configures a `rdq gui` run. Values are propagated from command-line flags + the per-profile state.json into the session so the SPA can reload without losing its context.

type ProfilesDTO added in v0.0.2

type ProfilesDTO struct {
	Profiles []string `json:"profiles"`
}

ProfilesDTO is the JSON body of /api/profiles.

type PutAiContextRequest added in v0.0.10

type PutAiContextRequest struct {
	Cluster  string `json:"cluster"`
	Database string `json:"database"`
	Content  string `json:"content"`
}

PutAiContextRequest is the JSON body of PUT /api/aictx. Content is the new prompt context to persist; an empty string is rejected (use DELETE to clear the entry instead).

type ReviewRequest added in v0.0.2

type ReviewRequest struct {
	SQL   string `json:"sql"`
	Focus string `json:"focus,omitempty"`
	// contains filtered or unexported fields
}

ReviewRequest is the JSON body of POST /api/ai/review.

type SchemaColumnDTO added in v0.0.2

type SchemaColumnDTO struct {
	Schema string `json:"schema"`
	Table  string `json:"table"`
	Name   string `json:"name"`
	Type   string `json:"type"`
}

SchemaColumnDTO is one row from information_schema.columns.

type SchemaDTO added in v0.0.2

type SchemaDTO struct {
	Cluster   string            `json:"cluster"`
	Database  string            `json:"database"`
	FetchedAt string            `json:"fetchedAt"`
	Columns   []SchemaColumnDTO `json:"columns"`
	FromCache bool              `json:"fromCache"`
}

SchemaDTO is the JSON body of /api/schema. FromCache=true means the snapshot was served from the on-disk cache without an AWS round trip.

type SchemaRefreshRequest added in v0.0.2

type SchemaRefreshRequest struct {
	Profile  string `json:"profile"`
	Cluster  string `json:"cluster"`
	Secret   string `json:"secret"`
	Database string `json:"database"`
}

SchemaRefreshRequest is the JSON body of POST /api/schema/refresh.

type SecretInfoDTO added in v0.0.2

type SecretInfoDTO struct {
	Name        string `json:"name"`
	ARN         string `json:"arn"`
	Description string `json:"description,omitempty"`
}

SecretInfoDTO is the JSON shape of a Secrets Manager secret.

type SecretsDTO added in v0.0.2

type SecretsDTO struct {
	Secrets   []SecretInfoDTO `json:"secrets"`
	Suggested bool            `json:"suggested"`
}

SecretsDTO wraps the /api/secrets list. Suggested=true means the list is scoped to the given cluster (MasterUserSecret + tag filters); false means the SPA is looking at the full region listing as a fallback.

type SessionDTO added in v0.0.2

type SessionDTO struct {
	Profile         string `json:"profile"`
	Cluster         string `json:"cluster"`
	Secret          string `json:"secret"`
	Database        string `json:"database"`
	BedrockModel    string `json:"bedrockModel"`
	BedrockLanguage string `json:"bedrockLanguage"`
	IsProduction    *bool  `json:"isProduction,omitempty"`
	IsReadOnly      *bool  `json:"isReadOnly,omitempty"`
	// AutoRunReadOnly mirrors state.ProfileState.AutoRunReadOnly: when
	// true, the SPA fires the freshly generated AI SQL into /api/execute
	// the moment Bedrock returns it, provided the runner classifies the
	// statement as read-only. nil / false leaves the existing review-then-
	// run flow intact.
	AutoRunReadOnly *bool `json:"autoRunReadOnly,omitempty"`
}

SessionDTO is the JSON representation of the server's "current connection" pointer. It is returned by GET /api/session and accepted by PUT /api/session. All fields may be empty — the GUI is responsible for nudging the user into filling them in (via ConnectionDialog) before calling an endpoint that actually needs them.

IsProduction is a tri-state pointer that mirrors state.ProfileState: nil = the user has not answered, true / false = explicit choice. The SPA paints the ConnectionBar with a warning colour when it is true.

IsReadOnly mirrors state.ProfileState.IsReadOnly. The execute handler treats a nil value as read-only enabled so fresh / unanswered profiles default to the safe side; destructive statements are rejected with a "read_only" error code. Users toggle it off in Settings.

func LoadFromState added in v0.0.2

func LoadFromState(seed SessionDTO) SessionDTO

LoadFromState enriches a session seed with values persisted under the profile's state.json entry. Explicit seed values take priority; the state fills only the blanks. This is how startup works: CLI flags (seed) win over cached state (seed fallback).

type TextResponse added in v0.0.2

type TextResponse struct {
	Text string `json:"text"`
}

TextResponse is the JSON body returned by /api/ai/explain, /api/ai/review, and /api/ai/analyze. The text is raw Markdown from Bedrock.

Jump to

Keyboard shortcuts

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