orbitspace

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 22 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.

README

OrbitSpace Go SDK

Go 1.24+ REST/SSE client for application backends. Public module: github.com/orbitmesh-official/orbitspace-go-sdk.

This directory is the authoritative source in the OrbitSpace repository. Only allowlisted SDK source, examples, tests and API contracts are mirrored to the public distribution repository. A release uses a standard v0.x.y Go module tag there; do not install a private control-plane protobuf package or infer availability from this source version.

go get github.com/orbitmesh-official/orbitspace-go-sdk@v0.1.0

Use the install command after the public tag is available. The SDK does not require a generator, Buf, protobuf, gRPC or Connect at application runtime.

provider, err := orbitspace.NewClientCredentials(orbitspace.ClientCredentialsOptions{
    TokenURL: tokenEndpoint, ClientID: clientID, ClientSecret: secret,
    Scope: "tasks:read tasks:write artifacts:read",
})
if err != nil { return err }
client, err := orbitspace.New(orbitspace.Options{
    TokenProvider: provider, TenantID: tenantID, Retries: 2,
})
if err != nil { return err }
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
task, err := client.Tasks.Create(ctx, api.CreateTaskRequest{
    WorkspaceID: orbitspace.Ptr(workspaceID),
    WorkspaceAgentBindingID: orbitspace.Ptr(bindingID),
    Input: orbitspace.Ptr("Summarize the supplied document."),
    IdempotencyKey: orbitspace.Ptr(durableBusinessJobKey),
})
if err != nil { return err }
result, err := client.Tasks.Wait(ctx, *task.ID, orbitspace.ObserveOptions{})
if err != nil { return err }
// result.State may require input or approval. Completion is not assumed.

Imports:

import (
    "context"
    "time"
    orbitspace "github.com/orbitmesh-official/orbitspace-go-sdk"
    "github.com/orbitmesh-official/orbitspace-go-sdk/api"
)

Task interaction and recovery

Use Tasks.InputRequests / Tasks.GetInput to load the latest input request. Call Tasks.ReplyInput with its exact expected_state_version, response and one persistent idempotency_key per business reply. Load a fresh Task snapshot before Tasks.Resume, Pause, Retry or Cancel; do not invent a version or reuse a stale one. API Tokens and OAuth scopes do not replace project policy.

WatchTask, WatchInvocation, WatchGoal and Watch deliver raw SSE data to a synchronous callback. WatchOptions.After is an opaque string (including values above 2^53); reconnect uses Last-Event-ID. A received cursor is not a business acknowledgement: commit side effects and cursor atomically, then restart from that committed cursor. On missing history, use the documented event-page and snapshot recovery contract; the SDK surfaces the API error without pretending history is complete. REST snapshots are authoritative; Observe performs no periodic reads while idle. A cancellable context is mandatory for streams. Cancelling observation closes the connection but does not cancel the Task.

Authentication, errors and retries

Options.Token supports backend API Tokens. TokenProvider supports your own OIDC/PKCE token manager; never embed a confidential client secret in an app. NewClientCredentials defaults to client_secret_basic; it also supports client_secret_post and private_key_jwt with an assertion callback. Configure the issuer's actual token endpoint; HTTPS is required except for loopback tests. Issuance is single-flight per provider, cached with early renewal when expiry exists, and bounded by its own timeout. Cancelled waiters do not cancel other callers. On credential rotation, update the credential source and construct a new provider; Invalidate only clears the current provider's access-token cache. Providers are never shared implicitly across tenants or processes.

APIError exposes Status, Code, Message and RequestID; OAuthError never reflects provider error descriptions or credential-bearing response bodies. Inspect errors with errors.As; inspect cancellation with errors.Is.

REST defaults to a 30-second deadline. Configurable bounded retries cover only GET/HEAD and transient responses, with jitter and Retry-After. Writes are never replayed automatically, even with an idempotency key. For uncertain admission, reconcile using the same durable key; do not create another business job. API credentials are confined to the configured origin and base path; redirects are disabled. Pass HTTPClient to configure a transport/proxy, not to override these boundaries. Custom RoundTrippers must honor context and must not inject credentials into unrelated destinations.

Verified artifact downloads

Artifacts.DownloadFile(ctx, artifactID, destination, DownloadOptions{MaxBytes: ...}) obtains an authorized receipt, then fetches it without API authentication or tenant headers. The API origin's /api/v1/artifact-downloads/ prefix is the default allowlist; S3/CDN destinations require explicit Destinations entries with exact origins and slash-bounded prefixes. Redirects, expired receipts, size mismatches and SHA-256 mismatches fail. Private staging files are removed on failure; only a verified file atomically replaces the destination.

Complete typed API and boundaries

client.API.TaskServiceGetTaskWithResponse(ctx, id) illustrates the generated client. Package api includes all 330 admitted operations across the canonical nine API families, including Skill management through Registry operations. Decimal-string int64 fields and unknown string enum values are preserved. No Worker/Host registration, platform administration or secret leasing is exposed. The generated client's WithResponse methods return status-specific typed responses; check the HTTP status and problem response. Resource helpers normalize non-success results to APIError.

This is the REST/SSE application SDK, not an executor installation kit, A2A message binding or Webhook signature verifier. Those integration contracts remain separate. OAuth browser login, durable Inbox storage, approval policy, document retention and customer/device isolation remain application responsibilities.

Apache-2.0. See LICENSE.

Documentation

Overview

Package orbitspace provides the public OrbitSpace REST and SSE client. All calls accept a context. Cancelling observation never cancels a remote task.

Package orbitspace is the Go REST/SSE SDK for OrbitSpace application backends.

Create a Client with an API Token or a ClientCredentials provider. Tasks, Invocations and Goals expose event-driven Observe/Wait helpers; API contains all generated public operations. Wire int64 values remain decimal strings.

Observe/Wait stop at required input, approval, pause or a terminal state. They never automatically approve, reply, resume or cancel remote work. Persist stable idempotency keys and committed event cursors in your own store. Use DownloadFile for bounded, integrity-checked artifact transfers.

Index

Constants

View Source
const Version = "0.1.0"

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer for optional fields in the generated wire models.

Types

type APIError

type APIError struct {
	Status                   int
	Code, Message, RequestID string
}

func (*APIError) Error

func (e *APIError) Error() string

type ArtifactsService

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

func (*ArtifactsService) DownloadFile

func (s *ArtifactsService) DownloadFile(ctx context.Context, id, path string, opts DownloadOptions) (DownloadResult, error)

DownloadFile obtains a fresh receipt. The API origin's artifact-downloads path is the default destination; external S3/CDN locations require explicit review.

func (*ArtifactsService) Get

func (s *ArtifactsService) Get(ctx context.Context, id string) (*api.Artifact, error)

func (*ArtifactsService) GetDownload

func (s *ArtifactsService) GetDownload(ctx context.Context, id string) (*api.ArtifactDownload, error)

type Client

type Client struct {
	// API exposes all admitted typed operations. It shares the authenticated transport.
	API         *api.ClientWithResponses
	Tasks       *TasksService
	Invocations *InvocationsService
	Goals       *GoalsService
	Artifacts   *ArtifactsService
	// contains filtered or unexported fields
}

func New

func New(opts Options) (*Client, error)

func (*Client) DoJSON

func (c *Client) DoJSON(ctx context.Context, method, path string, body, out any) error

DoJSON calls a public API-relative path through the same guarded transport. Prefer API's generated typed methods or the resource helpers below.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, path string, opts WatchOptions, handle func(Event) error) error

Watch synchronously delivers events. Returning an error stops immediately. Persist a committed cursor only after your handler's business transaction succeeds. A finite or cancellable context is mandatory. No API timeout is applied to SSE.

func (*Client) WatchGoal

func (c *Client) WatchGoal(ctx context.Context, id string, opts WatchOptions, handle func(Event) error) error

func (*Client) WatchInvocation

func (c *Client) WatchInvocation(ctx context.Context, id string, opts WatchOptions, handle func(Event) error) error

func (*Client) WatchTask

func (c *Client) WatchTask(ctx context.Context, id string, opts WatchOptions, handle func(Event) error) error

type ClientCredentials

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

func NewClientCredentials

func NewClientCredentials(opts ClientCredentialsOptions) (*ClientCredentials, error)

func (*ClientCredentials) Invalidate

func (p *ClientCredentials) Invalidate()

Invalidate clears cached credentials. In-flight issuance cannot repopulate the cache.

func (*ClientCredentials) Token

func (p *ClientCredentials) Token(ctx context.Context) (string, error)

type ClientCredentialsOptions

type ClientCredentialsOptions struct {
	TokenURL, ClientID, ClientSecret, Scope, Resource string
	AuthMethod                                        string // client_secret_basic (default), client_secret_post, private_key_jwt.
	ClientAssertion                                   func(context.Context) (string, error)
	HTTPClient                                        *http.Client
	Timeout                                           time.Duration
}

type Destination

type Destination struct{ Origin, PathPrefix string }

Destination permits one exact origin and a slash-bounded path prefix.

type DownloadOptions

type DownloadOptions struct {
	MaxBytes     int64         // Mandatory upper bound, independent of declared size.
	Destinations []Destination // Mandatory reviewed capability destinations.
	HTTPClient   *http.Client  // No API credentials or tenant headers are supplied.
}

type DownloadResult

type DownloadResult struct {
	SizeBytes           int64
	SHA256, ContentType string
}

func DownloadFile

func DownloadFile(ctx context.Context, receipt api.ArtifactDownload, destination string, opts DownloadOptions) (DownloadResult, error)

DownloadFile verifies a private staging file before atomically replacing destination. Failure or cancellation removes staging and leaves an existing destination untouched.

type DownloadTransportError

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

DownloadTransportError redacts capability URLs from ordinary error logs. Unwrap preserves explicit transport diagnostics and errors.Is behavior.

func (*DownloadTransportError) Error

func (e *DownloadTransportError) Error() string

func (*DownloadTransportError) Unwrap

func (e *DownloadTransportError) Unwrap() error

type Event

type Event struct {
	ID, Type string
	Data     json.RawMessage
	Retry    time.Duration
}

Event.Data is retained verbatim; JSON decoding is a caller decision. ID is the observed cursor, not an acknowledgement of business side effects.

type ExecutionState

type ExecutionState string
const (
	StateQueued          ExecutionState = "queued"
	StateRunning         ExecutionState = "running"
	StateWaitingInput    ExecutionState = "waiting_input"
	StateWaitingApproval ExecutionState = "waiting_approval"
	StatePaused          ExecutionState = "paused"
	StateCompleted       ExecutionState = "completed"
	StateFailed          ExecutionState = "failed"
	StateCancelled       ExecutionState = "cancelled"
	StateUnknown         ExecutionState = "unknown"
)

func NormalizeState

func NormalizeState(status string) ExecutionState

func (ExecutionState) NeedsAttention

func (s ExecutionState) NeedsAttention() bool

type GoalsService

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

func (*GoalsService) Cancel

func (s *GoalsService) Cancel(ctx context.Context, id string, body api.CancelGoalRequest) (*api.Goal, error)

func (*GoalsService) Create

func (s *GoalsService) Create(ctx context.Context, body api.CreateGoalRequest) (*api.Goal, error)

func (*GoalsService) Get

func (s *GoalsService) Get(ctx context.Context, id string) (*api.Goal, error)

func (*GoalsService) Observe

func (s *GoalsService) Observe(ctx context.Context, id string, opts ObserveOptions, handle func(Observation[api.Goal]) error) error

func (*GoalsService) Pause

func (s *GoalsService) Pause(ctx context.Context, id string, body api.PauseGoalRequest) (*api.Goal, error)

func (*GoalsService) Resume

func (s *GoalsService) Resume(ctx context.Context, id string, body api.ResumeGoalRequest) (*api.Goal, error)

func (*GoalsService) Start

func (s *GoalsService) Start(ctx context.Context, id string, body api.StartGoalRequest) (*api.Goal, error)

func (*GoalsService) Wait

type InvocationsService

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

func (*InvocationsService) Cancel

func (*InvocationsService) Create

func (s *InvocationsService) Create(ctx context.Context, deploymentID string, body api.CreateInvocationRequest) (*api.Invocation, error)

func (*InvocationsService) Get

func (*InvocationsService) Observe

func (s *InvocationsService) Observe(ctx context.Context, id string, opts ObserveOptions, handle func(Observation[api.Invocation]) error) error

func (*InvocationsService) Retry

func (*InvocationsService) Wait

type OAuthError

type OAuthError struct {
	Status          int
	Code, RequestID string
}

func (*OAuthError) Error

func (e *OAuthError) Error() string

type Observation

type Observation[T any] struct {
	Resource *T
	State    ExecutionState
	Cursor   string
	Event    *Event
}

type ObserveOptions

type ObserveOptions struct {
	WatchOptions
	MinimumSnapshotInterval time.Duration /* Default 500ms; no idle polling. */
}

type Options

type Options struct {
	BaseURL       string
	Token         string
	TokenProvider TokenProvider
	TenantID      string
	HTTPClient    *http.Client
	Headers       http.Header
	Timeout       time.Duration // Defaults to 30s for REST; SSE uses its context lifetime.
	MaxErrorBytes int64         // Defaults to 64 KiB.
	Retries       int           // GET/HEAD only, 0..5; default 0.
	MaxRetryDelay time.Duration // Defaults to 10s; a longer Retry-After is not shortened.
}

Options never enables automatic retries of writes, including idempotent writes.

type TasksService

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

func (*TasksService) Cancel

func (s *TasksService) Cancel(ctx context.Context, id string, body api.CancelTaskRequest) (*api.Task, error)

func (*TasksService) Create

func (s *TasksService) Create(ctx context.Context, body api.CreateTaskRequest) (*api.Task, error)

func (*TasksService) Get

func (s *TasksService) Get(ctx context.Context, id string) (*api.Task, error)

func (*TasksService) GetInput

func (s *TasksService) GetInput(ctx context.Context, id string) (*api.RunInputRequest, error)

func (*TasksService) InputRequests

func (*TasksService) Observe

func (s *TasksService) Observe(ctx context.Context, id string, opts ObserveOptions, handle func(Observation[api.Task]) error) error

func (*TasksService) Pause

func (s *TasksService) Pause(ctx context.Context, id string, body api.PauseTaskRequest) (*api.Task, error)

func (*TasksService) ReplyInput

func (*TasksService) Resume

func (s *TasksService) Resume(ctx context.Context, id string, body api.ResumeTaskRequest) (*api.Task, error)

func (*TasksService) Retry

func (s *TasksService) Retry(ctx context.Context, id string, body api.RetryTaskRequest) (*api.Task, error)

func (*TasksService) Wait

type TokenProvider

type TokenProvider interface {
	Token(context.Context) (string, error)
}

type TokenProviderFunc

type TokenProviderFunc func(context.Context) (string, error)

func (TokenProviderFunc) Token

func (f TokenProviderFunc) Token(ctx context.Context) (string, error)

type WatchOptions

type WatchOptions struct {
	After          string
	MaxReconnects  int           // Default 5; -1 means unlimited until context cancellation.
	ReconnectDelay time.Duration // Default 500ms.
	MaxEventBytes  int           // Default 1 MiB, also bounds each line and pending ID.
}

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
examples
task command
A backend task observer.
A backend task observer.

Jump to

Keyboard shortcuts

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