Documentation
¶
Overview ¶
Package dataservice provides an agent-to-agent query service. A host agent runs the service, which listens for private chat DMs, parses them as data queries via a pluggable Handler registry, executes them against the shared knowledge base, and replies in the same format (plaintext or JSON) as the request.
Index ¶
Constants ¶
const MaxReplyChars = 500
MaxReplyChars is the server-enforced chat message content limit.
Variables ¶
This section is empty.
Functions ¶
func TruncateReply ¶
TruncateReply enforces the MaxReplyChars limit. If s is already within the limit it is returned unchanged. Otherwise it is cut so that s + truncateSuffix fits within MaxReplyChars.
Types ¶
type Config ¶
type Config struct {
AgentID string
Registry *Registry
Mbox *mbox.Store
Fetcher HistoryFetcher
Replier Replier
Logger *log.Logger
// PollInterval controls the ingest-loop cadence. Defaults to 5s.
PollInterval time.Duration
// ReplyPace is the enforced minimum between outgoing Chat calls so the
// server's 1-mutation-per-tick rule is respected. Defaults to 10s.
ReplyPace time.Duration
// HistoryLimit controls the max messages fetched per ingest call. Defaults to 50.
HistoryLimit int
// Verbose, when true, enables extra per-request diagnostic logging
// (full inbound content, dispatched reply preview). Off by default;
// callers wire it from a --debug flag.
Verbose bool
}
Config holds the runtime wiring for a Service.
type Deps ¶
type Deps struct {
KB knowledge.Base
Graph *galaxy.GalaxyGraph
// Tick returns the current game tick or 0 if no clock is available.
Tick func() int64
// Logger, if non-nil, opts handlers into verbose per-request debug
// logging (parsed kind/key, intermediate target counts, etc.). Leave
// nil for production use; set by --debug callers.
Logger *log.Logger
}
Deps bundles the runtime dependencies that concrete handlers may need. Passed to each handler's Execute method. Handlers must not mutate any field on Deps.
type ErrParse ¶
type ErrParse string
ErrParse is returned by handlers when user input is structurally wrong. The registry surfaces the error message directly to the requester.
type Format ¶
type Format int
Format is the reply format expected by a requester.
func DetectFormat ¶
DetectFormat inspects the trimmed request content. If it begins with '{' the request is treated as JSON; otherwise plaintext. Detection is purely lexical — malformed JSON that starts with '{' is still reported as JSON so the caller can produce a JSON error reply.
type Handler ¶
type Handler interface {
// Name returns the handler's query keyword (e.g. "nearest").
Name() string
// ShortHelp returns a one-line description shown in `help` output.
ShortHelp() string
// PlaintextUsages returns one or more grammar lines shown in `help`
// output, e.g. "nearest <poi_type> from <system_id>". A handler with
// multiple supported grammars should return one entry per form.
PlaintextUsages() []string
// JSONExamples returns one or more request examples for `help` output.
// Each example is a fully-formed JSON request body as a map.
JSONExamples() []map[string]any
// HandlePlaintext parses the tail of a plaintext request (tokens after
// the query keyword) and returns the styled reply.
HandlePlaintext(ctx context.Context, deps Deps, args []string) (string, error)
// HandleJSON parses a JSON `params` object and returns a JSON reply
// as a map the registry will marshal.
HandleJSON(ctx context.Context, deps Deps, params map[string]any) (map[string]any, error)
}
Handler is a single data-query handler registered with the service. Handlers must be concurrency-safe; the service may dispatch queries from multiple goroutines in the future.
type HistoryFetcher ¶
type HistoryFetcher interface {
Fetch(ctx context.Context, limit int) ([]serverapi.ChatMessage, error)
}
HistoryFetcher returns recent private-channel chat messages. A concrete implementation over game.GameClient lives in cmd/databot; this interface keeps Service testable without a live client.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the set of registered handlers. Safe for concurrent reads after all handlers are registered at construction time.
func NewRegistry ¶
NewRegistry creates an empty registry backed by the given deps.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the long-running query responder.
func NewService ¶
NewService validates the config and returns a Service.