dataservice

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxReplyChars = 500

MaxReplyChars is the server-enforced chat message content limit.

Variables

This section is empty.

Functions

func TruncateReply

func TruncateReply(s string) string

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.

func (ErrParse) Error

func (e ErrParse) Error() string

Error implements the error interface.

type Format

type Format int

Format is the reply format expected by a requester.

const (
	// FormatPlaintext produces styled human-readable replies.
	FormatPlaintext Format = iota
	// FormatJSON produces machine-readable JSON replies.
	FormatJSON
)

func DetectFormat

func DetectFormat(content string) Format

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

func NewRegistry(deps Deps) *Registry

NewRegistry creates an empty registry backed by the given deps.

func (*Registry) Dispatch

func (r *Registry) Dispatch(ctx context.Context, content string) (string, error)

Dispatch parses the content, routes to a handler, and returns the rendered reply. Errors returned are from the Dispatch mechanism itself; handler-level failures are rendered into the reply.

func (*Registry) Register

func (r *Registry) Register(h Handler)

Register adds a handler. Panics on duplicate names to catch wiring mistakes at startup.

type Replier

type Replier interface {
	Reply(ctx context.Context, targetID, content string) error
}

Replier sends a chat reply. Abstracted for the same reason as HistoryFetcher.

type Service

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

Service is the long-running query responder.

func NewService

func NewService(cfg Config) (*Service, error)

NewService validates the config and returns a Service.

func (*Service) Run

func (s *Service) Run(ctx context.Context) error

Run drives the ingest and dispatch loops until ctx is cancelled.

Directories

Path Synopsis
Package handlers provides concrete Handler implementations for the dataservice query registry.
Package handlers provides concrete Handler implementations for the dataservice query registry.

Jump to

Keyboard shortcuts

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