tripops

package
v0.0.0-...-2adc0db Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 15 Imported by: 0 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 tripops is the shared itinerary agent surface used by HTTP/MCP and in-viewer chat. Business logic lives here; transports only bind auth and I/O.

Index

Constants

View Source
const (
	SummaryGetSchema        = "Itinerary schema and version"
	SummaryGetTrip          = "Compact trip card with day titles and per-day drive_dist/drive_min from bundle (use for drive-time questions; no YAML needed)"
	SummaryGetTripYAML      = "Get itinerary YAML"
	SummaryPatchTrip        = "Patch places info, day narrative, or structure"
	SummaryReplaceDayRoutes = "" /* 154-byte string literal not displayed */
	SummaryListVersions     = "List YAML versions"
	SummaryGetVersion       = "Get YAML for a prior version"
	SummaryRestoreVersion   = "Restore a prior YAML version"
)

OpenAPI operation summaries — single source for chat tool one-liners.

View Source
const SummaryEstimateDrive = "OSRM road distance/time between waypoints (use instead of web search for drive estimates)"

Variables

This section is empty.

Functions

func HTTPStatus

func HTTPStatus(err error) int

HTTPStatus maps tripops errors to HTTP codes for agent handlers.

func PrepareYAML

func PrepareYAML(b []byte) (itinerary.Trip, error)

PrepareYAML parses and validates itinerary YAML for create/put/restore.

func SchemaJSON

func SchemaJSON(context.Context) (json.RawMessage, error)

SchemaJSON returns the agent schema document.

Types

type Config

type Config struct {
	Store         store.Store
	PublicBaseURL string
	RouteMode     string // straight | osrm
	OSRMBaseURL   string // optional; empty uses the public OSRM demo server
}

Config wires store-backed trip ops.

type DayDriveStats

type DayDriveStats struct {
	Day       int     `json:"day"`
	DriveDist float64 `json:"drive_dist,omitempty"`
	DriveMin  int     `json:"drive_min,omitempty"`
}

DayDriveStats is precomputed OSRM drive totals for one day (from bundle trip.json).

type DriveEstimate

type DriveEstimate struct {
	Legs            []DriveLeg `json:"legs"`
	DistanceKm      float64    `json:"distance_km"`
	DurationMinutes float64    `json:"duration_minutes"`
	Provider        string     `json:"provider"` // osrm | mixed | straight
}

DriveEstimate is the OSRM (or straight-line fallback) summary.

type DriveLeg

type DriveLeg struct {
	From             string  `json:"from"`
	To               string  `json:"to"`
	DistanceKm       float64 `json:"distance_km"`
	DurationMinutes  float64 `json:"duration_minutes"`
	DistanceMeters   float64 `json:"distance_meters"`
	DurationSeconds  float64 `json:"duration_seconds"`
	FallbackStraight bool    `json:"fallback_straight,omitempty"`
}

DriveLeg is one OSRM leg between consecutive waypoints.

type DriveWaypoint

type DriveWaypoint struct {
	Place string  `json:"place,omitempty"` // place id from the trip catalog
	Lat   float64 `json:"lat,omitempty"`
	Lon   float64 `json:"lon,omitempty"`
	Title string  `json:"title,omitempty"` // optional label for the response
}

DriveWaypoint is one point on an estimateDrive request.

type MutateResult

type MutateResult struct {
	ID            string `json:"id"`
	VersionID     string `json:"version_id,omitempty"`
	SchemaVersion int    `json:"schema_version"`
	ViewerURL     string `json:"viewer_url,omitempty"`
	BundleOK      bool   `json:"bundle_ok"`
	BundleError   string `json:"bundle_error,omitempty"`
}

MutateResult matches OpenAPI MutateResult.

type Ops

type Ops interface {
	SchemaJSON(ctx context.Context) (json.RawMessage, error)
	Summary(ctx context.Context, tripID string) (TripSummary, error)
	GetYAML(ctx context.Context, tripID, scope string, day int) (YAMLResult, error)
	GetYAMLVersion(ctx context.Context, tripID, versionID string) (YAMLResult, error)
	Patch(ctx context.Context, tripID string, patchJSON []byte) (MutateResult, error)
	ReplaceDayRoutes(ctx context.Context, tripID string, bodyJSON []byte) (MutateResult, error)
	ListVersions(ctx context.Context, tripID string, limit int) ([]VersionEntry, error)
	RestoreVersion(ctx context.Context, tripID, versionID string) (MutateResult, error)
	EstimateDrive(ctx context.Context, tripID string, points []DriveWaypoint) (DriveEstimate, error)
}

Ops is the trip-scoped agent surface (no listTrips / createTrip).

type Service

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

Service implements Ops against a Store.

func New

func New(cfg Config) *Service

New builds a Service. Store must be non-nil.

func (*Service) ApplyPatch

func (s *Service) ApplyPatch(ctx context.Context, tripID string, p itinerary.Patch) (MutateResult, error)

ApplyPatch loads, patches, validates, and commits an itinerary.

func (*Service) ApplyPatchJSON

func (s *Service) ApplyPatchJSON(ctx context.Context, tripID string, patchJSON []byte) (MutateResult, error)

ApplyPatchJSON unmarshals a TripPatch and applies it.

func (*Service) ApplyReplaceDayRoutesJSON

func (s *Service) ApplyReplaceDayRoutesJSON(ctx context.Context, tripID string, bodyJSON []byte) (MutateResult, error)

ApplyReplaceDayRoutesJSON parses replaceDayRoutes body and applies it.

func (*Service) Commit

func (s *Service) Commit(ctx context.Context, id string, yamlBytes []byte, meta *store.Meta) (MutateResult, error)

Commit writes YAML + meta and regenerates the viewer bundle.

func (*Service) EstimateDrive

func (s *Service) EstimateDrive(ctx context.Context, tripID string, points []DriveWaypoint) (DriveEstimate, error)

EstimateDrive routes consecutive waypoints with OSRM (overview=false). Prefer place ids from getTripYAML; lat/lon may be used for candidates not yet in the trip.

func (*Service) GetYAML

func (s *Service) GetYAML(ctx context.Context, tripID, scope string, day int) (YAMLResult, error)

func (*Service) GetYAMLVersion

func (s *Service) GetYAMLVersion(ctx context.Context, tripID, versionID string) (YAMLResult, error)

func (*Service) ListVersions

func (s *Service) ListVersions(ctx context.Context, tripID string, limit int) ([]VersionEntry, error)

func (*Service) Patch

func (s *Service) Patch(ctx context.Context, tripID string, patchJSON []byte) (MutateResult, error)

func (*Service) ReplaceDayRoutes

func (s *Service) ReplaceDayRoutes(ctx context.Context, tripID string, bodyJSON []byte) (MutateResult, error)

func (*Service) RestoreVersion

func (s *Service) RestoreVersion(ctx context.Context, tripID, versionID string) (MutateResult, error)

RestoreVersion makes versionID the current YAML (Ops method).

func (*Service) SchemaJSON

func (s *Service) SchemaJSON(ctx context.Context) (json.RawMessage, error)

func (*Service) Summary

func (s *Service) Summary(ctx context.Context, tripID string) (TripSummary, error)

type TripSummary

type TripSummary struct {
	ID            string          `json:"id"`
	VersionID     string          `json:"version_id,omitempty"`
	SchemaVersion int             `json:"schema_version"`
	Trip          string          `json:"trip"`
	Description   string          `json:"description,omitempty"`
	Start         string          `json:"start,omitempty"`
	Days          int             `json:"days"`
	UpdatedAt     time.Time       `json:"updated_at,omitempty"`
	DayTitles     []string        `json:"day_titles,omitempty"`
	Units         string          `json:"units,omitempty"` // km | mi — bundle distance unit for drive_dist
	DayStats      []DayDriveStats `json:"day_stats,omitempty"`
}

TripSummary matches OpenAPI TripSummary (plus optional agent fields).

func BuildSummary

func BuildSummary(ctx context.Context, st store.Store, tripID string) (TripSummary, error)

BuildSummary loads YAML and builds a TripSummary.

type VersionEntry

type VersionEntry struct {
	VersionID    string `json:"version_id"`
	LastModified string `json:"last_modified,omitempty"` // RFC3339
	IsLatest     bool   `json:"is_latest,omitempty"`
}

VersionEntry is one YAML revision for agent tools.

func ListVersionEntries

func ListVersionEntries(ctx context.Context, st store.Store, tripID string, limit int) ([]VersionEntry, error)

ListVersionEntries lists versions; limit <= 0 means no cap.

type YAMLResult

type YAMLResult struct {
	Body      []byte
	VersionID string
}

YAMLResult is itinerary YAML plus version id.

func LoadYAML

func LoadYAML(ctx context.Context, st store.Store, tripID, scope string, day int) (YAMLResult, error)

LoadYAML returns full or day-scoped YAML. Empty scope means full (HTTP/MCP default). Callers that want day-default (viewer chat) must pass scope=day explicitly.

func LoadYAMLVersion

func LoadYAMLVersion(ctx context.Context, st store.Store, tripID, versionID string) (YAMLResult, error)

LoadYAMLVersion returns a prior revision's YAML.

Jump to

Keyboard shortcuts

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