Documentation
¶
Overview ¶
Package endpoint provides centralized SageOx endpoint URL management.
Index ¶
Constants ¶
const ( // Default is the default SageOx API endpoint. // All requests route through the main domain which proxies to internal services. Default = "https://sageox.ai" // EnvVar is the environment variable for the endpoint. EnvVar = "SAGEOX_ENDPOINT" // Production is an alias for Default, used in path functions to explicitly // indicate production endpoint paths should be used (e.g., ~/.sageox/data/teams/). // Using this constant makes code intent clearer than passing an empty string. Production = Default )
Variables ¶
var LoggedInEndpointsGetter func() []string
LoggedInEndpointsGetter returns endpoints the user is logged into. This is set by the auth package to avoid circular imports.
var ProjectEndpointGetter func(projectRoot string) string
ProjectEndpointGetter is a function that loads endpoint from project config. This is set by the config package to avoid circular imports.
Functions ¶
func Get ¶
func Get() string
Get returns the SageOx endpoint URL without trailing slash. Checks SAGEOX_ENDPOINT env var first, then falls back to default (production).
⚠️ WARNING: This function ignores project configuration!
Using Get() when a project context exists will cause bugs where operations target production instead of the project's configured endpoint.
✅ CORRECT: Use GetForProject(projectRoot) for:
- All API calls within a repo context
- Path functions (paths.TeamsDataDir, paths.LedgersDataDir, etc.)
- Auth checks within a repo context
- Any operation where .sageox/config.json might exist
Get returns the endpoint from SAGEOX_ENDPOINT env var or the default.
⚠️ WARNING: DO NOT USE THIS FUNCTION FOR PROJECT-SCOPED OPERATIONS ⚠️
This function ignores project config and returns the global/env endpoint. Using this in project-scoped code causes endpoint mismatches where resources end up in wrong directories (e.g., localhost auth but sageox.ai/ directories).
✅ ALLOWED uses (require human review for each new call):
- ox login (before any project config exists)
- ox init (initial project setup, before config is saved)
- Operations explicitly outside any repo context
❌ FORBIDDEN uses:
- Any code that has access to gitRoot or projectRoot
- Doctor checks, agent operations, sync, status
- Anywhere ProjectContext or endpoint.GetForProject() could be used
Before adding a call to Get(), you MUST:
- Confirm no projectRoot is available in the call chain
- Get explicit human approval in code review
- Add a comment explaining why GetForProject() cannot be used
If you have a projectRoot, use GetForProject(projectRoot) instead.
func GetForProject ¶
GetForProject returns the endpoint for a specific project. Precedence: SAGEOX_ENDPOINT env var > project config > default
Use this for repo-bound operations (doctor, init, agent, sync). Use Get() for global operations (login without --endpoint, status without repo).
func IsProduction ¶
IsProduction returns true if the endpoint is a production SageOx endpoint. Production endpoints share the same data directory structure, while non-production endpoints (dev, staging, localhost) are namespaced by their hostname.
func NormalizeEndpoint ¶
NormalizeEndpoint strips common subdomain prefixes (api., www., app., git.) from the host portion of an endpoint URL. Preserves scheme, path, port, and removes trailing slashes.
This is the canonical normalization function for endpoint URLs before they are stored, compared, or displayed. NormalizeSlug() calls this internally.
Examples:
https://www.test.sageox.ai → https://test.sageox.ai https://api.sageox.ai/v1 → https://sageox.ai/v1 https://app.sageox.ai → https://sageox.ai https://git.test.sageox.ai → https://test.sageox.ai www.test.sageox.ai → test.sageox.ai http://localhost:8080 → http://localhost:8080 (no prefix to strip)
func NormalizeSlug ¶
NormalizeSlug returns a normalized endpoint slug for use in filesystem paths. Calls NormalizeEndpoint() first, then extracts the host and removes port numbers. Normalizes 127.0.0.1 to localhost for consistency.
Examples:
api.sageox.ai → sageox.ai localhost:8080 → localhost 127.0.0.1:3000 → localhost staging.sageox.ai:443 → staging.sageox.ai https://app.sageox.ai/v1 → sageox.ai https://git.test.sageox.ai → test.sageox.ai
func SanitizeForPath ¶
SanitizeForPath returns a filesystem-safe version of the endpoint for use in paths. Uses NormalizeSlug() to strip common prefixes and remove port numbers.
Types ¶
This section is empty.