httpapi

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 41 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 httpapi exposes the local device service without opening USB handles.

Index

Constants

View Source
const FlashTicketHeader = "X-NB1-Flash-Ticket"
View Source
const MaxBodyBytes = control.MaxRequestBytes
View Source
const PatternLibraryContract = "nb1-pattern-library/v1"
View Source
const PatternLibraryV2Contract = "nb1-pattern-library/experimental-v2"
View Source
const PatternRefPreviewContract = "nb1-pattern-ref-preview/experimental-v1"

Variables

This section is empty.

Functions

func New

func New(service control.Service, options ...Option) http.Handler

func NewWithRemote added in v0.1.3

func NewWithRemote(service control.Service, protect func(http.Handler) http.Handler, options ...Option) (http.Handler, http.Handler)

NewWithRemote shares one API instance (including its library lock) between the loopback listener and a distinct listener with its own access checks. protect authenticates and restricts the network request before API dispatch.

Types

type ErrorBody

type ErrorBody struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type ErrorResponse

type ErrorResponse struct {
	Error ErrorBody `json:"error"`
}

type FlashResetFailure added in v0.1.4

type FlashResetFailure struct {
	Error  ErrorBody         `json:"error"`
	Result flashreset.Result `json:"result"`
}

FlashResetFailure retains the hardware progress alongside the normal API error.

type FlashResetTicket added in v0.1.4

type FlashResetTicket struct {
	Ticket string `json:"ticket"`
}

type Option

type Option func(*handler)

func WithLibraryDirectory

func WithLibraryDirectory(dir string) Option

WithLibraryDirectory selects a local v1 library without accessing its files. An empty directory leaves library operations unavailable.

func WithLocalProtection added in v0.1.3

func WithLocalProtection(protect func(http.Handler) http.Handler) Option

WithLocalProtection runs protection after the existing loopback Host and Origin checks. Requests from the separate HTTPS listener use its own gate.

func WithPatternDirectory

func WithPatternDirectory(dir string) Option

WithPatternDirectory selects a library without opening or creating it. An invalid configuration disables only Pattern features, never ordinary lights. Empty selects the current service account's UserConfigDir()/nb1/patterns.

func WithPatternDirectoryV2

func WithPatternDirectoryV2(dir string) Option

WithPatternDirectoryV2 selects an independent v2 library without filesystem I/O. Empty selects UserConfigDir()/nb1/patterns-v2. Only a valid save or import entering its write transaction may create the directory; failed publication does not promise to remove that directory. Invalid configuration disables this library while pure preview and ordinary device operations remain available.

func WithPatternStore

func WithPatternStore(store PatternStore) Option

WithPatternStore opts in to the library without changing existing New calls.

func WithPatternStoreV2

func WithPatternStoreV2(store PatternStoreV2) Option

WithPatternStoreV2 opts in to one explicitly selected v2 store. It performs no store calls, path selection, default-directory lookup or v1 fallback. In particular, a pure preview never calls even Path on this store.

func WithSequenceAPI

func WithSequenceAPI() Option

WithSequenceAPI selects the new runtime's route table.

func WithSequenceRouting added in v0.1.3

func WithSequenceRouting(defaultSerial string, useSingleOnline bool, libraryDir string) Option

WithSequenceRouting enables server-side default targets and local triggers.

type PatternLibraryInfo

type PatternLibraryInfo struct {
	Path            string `json:"path"`
	State           string `json:"state"`
	CreateOnly      bool   `json:"create_only"`
	MaxRecords      int    `json:"max_records"`
	MaxPackageBytes int    `json:"max_package_bytes"`
	RecordContract  string `json:"record_contract"`
	CompileContract string `json:"compile_contract"`
	SnapshotKind    string `json:"snapshot_kind"`
}

type PatternList

type PatternList struct {
	SchemaVersion int                `json:"schema_version"`
	Contract      string             `json:"contract"`
	Library       PatternLibraryInfo `json:"library"`
	Patterns      []PatternSummary   `json:"patterns"`
}

type PatternPreview

type PatternPreview struct {
	PatternRef PatternRef            `json:"pattern_ref"`
	Preview    control.PreviewResult `json:"preview"`
}

type PatternRef

type PatternRef struct {
	ID       string `json:"id"`
	Revision string `json:"revision"`
}

type PatternStore

type PatternStore interface {
	Path() string
	List() ([]patterns.Record, error)
	Get(string) (patterns.Record, error)
	Resolve(string, string) (patterns.Record, error)
	Export() ([]byte, error)
	Import([]byte) (patternstore.ImportResult, error)
}

PatternStore owns only the bounded library. It never admits device work.

type PatternStoreV2

type PatternStoreV2 interface {
	Path() string
	List() ([]patternsv2.Inspection, error)
	Get(string) (patternsv2.Inspection, error)
	Resolve(string, string) (patternsv2.Record, error)
	Export() ([]byte, error)
	Import([]byte) (patternstore.ImportResultV2, error)
}

PatternStoreV2 is explicitly independent of the v1 library. P3 authoring and inspection never call Resolve or any service method; the separate execution adapter uses exact Resolve only after a new receipt miss.

type PatternSummary

type PatternSummary struct {
	ID                   string   `json:"id"`
	Title                string   `json:"title"`
	Revision             string   `json:"revision"`
	CompileContract      string   `json:"compile_contract"`
	TotalSteps           int      `json:"total_steps"`
	NominalDurationMS    int64    `json:"nominal_duration_ms"`
	OnFinish             string   `json:"on_finish"`
	RequiredCapabilities []string `json:"required_capabilities"`
}

type PreviewRequest

type PreviewRequest struct {
	PatternRef *PatternRef      `json:"pattern_ref,omitempty"`
	Program    *control.Program `json:"program,omitempty"`
	Effect     *control.Effect  `json:"effect,omitempty"`
	Serial     *string          `json:"serial,omitempty"`
}

PreviewRequest is compilation only. Serial optionally checks one configured cached snapshot; policy and receipts are not accepted. A fixed Pattern reference is mutually exclusive with Program and Effect.

type SubmitRequest

type SubmitRequest struct {
	Program                  *control.Program `json:"program,omitempty"`
	Effect                   *control.Effect  `json:"effect,omitempty"`
	PatternRef               *PatternRef      `json:"pattern_ref,omitempty"`
	Policy                   string           `json:"policy"`
	RequestID                *string          `json:"request_id,omitempty"`
	ExpectedDaemonInstanceID *string          `json:"expected_daemon_instance_id,omitempty"`
}

Jump to

Keyboard shortcuts

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