enterprise

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 36 Imported by: 1 module, 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 enterprise connects Blitz to an organization's service (spec_053_enterprise §3): it finds out what the service offers (EN-11), signs the person in with the organization's identity provider and exchanges the provider's ID token for the service's own tokens (EN-12), and keeps those renewed. The refresh token is kept in the secret store (the OS keychain); the access token only in memory. The calls are JSON over HTTPS, as the spec gives them: nothing here needs the service's code.

Index

Constants

View Source
const (
	APIMessages  = "messages"  // Anthropic's Messages API
	APIResponses = "responses" // OpenAI's Responses API
)

The APIs a model speaks, as the service names them.

View Source
const CatalogRemoved = "catalog_removed"

layOut builds the layers for m from the kept files beside the old ones, then swaps them in. CatalogRemoved is the code a service whose catalog is retired answers /api/v1/catalog with.

View Source
const ConflictsDir = "conflicts"

ConflictsDir is where a sync keeps another computer's version of an asset changed on both, under ~/.blitz.

View Source
const (
	PolicyFile = "policy.json"
)

The catalog's files in the organization's folder (EN-33, EN-54).

View Source
const PolicySchema = 2

PolicySchema is the newest policy envelope this client reads. A newer one may hold restrictions it doesn't know, so it isn't taken: the policy kept stays, and with none, the strictest applies (EN-33b; security review enterprise#6). 0 is an envelope from before the field.

View Source
const RegistryTokenEnv = "BLITZ_REGISTRY_TOKEN"

RegistryTokenEnv names the environment variable a registry token is in.

View Source
const RenewWithin = 24 * time.Hour

RenewWithin is how near its expiry a kept policy or catalog is fetched whole, without If-None-Match, so it comes renewed (EN-33d).

View Source
const RunPaused = "paused"

RunPaused is the status of a run that waits for its owner's answer (blitz-enterprise spec_009_jobs JB-13).

View Source
const SharedAsPerson = "person"

SharedAsPerson is a shared connector's auth when it queries as each person.

View Source
const SharedMCP = "mcp"

SharedMCP is a shared connector's kind when it's a remote MCP server.

Variables

View Source
var ErrChangedElsewhere = errors.New("changed on another computer first")

ErrChangedElsewhere is a change to a personal asset another computer changed first (the service's 409 conflict).

View Source
var ErrNoConsent = errors.New("your organization's service can't query as each person")

ErrNoConsent is a service that can't query as each person (another sign-in provider, or one before it).

View Source
var ErrNoPolicyAPI = errors.New("the organization's service doesn't serve a policy of its own")

ErrNoPolicyAPI means the service predates /api/v1/policy: the policy the catalog's manifest carries stands (EN-38).

View Source
var ErrNotSignedIn = errors.New("not signed in to the organization's service")

ErrNotSignedIn means no one is signed in to the service.

View Source
var ErrPolicySchema = errors.New("your organization's policy is newer than this version of Blitz reads: update Blitz")

ErrPolicySchema is a policy envelope newer than this client reads.

View Source
var ErrSignature = errors.New("this didn't come signed by the organization's service")

ErrSignature means what the service sent (its branding, its catalog) doesn't check against the keys it published.

View Source
var ErrUnreachable = errors.New("your organization's service isn't answering")

ErrUnreachable is the organization's service not answering lately: Blitz works on as if offline (spec_053_enterprise EN-37), its files and folders as ever, the organization's models and the rest waiting until the service answers again.

View Source
var HTTPClient = sync.OnceValue(func() *http.Client {
	return &http.Client{Transport: transport()}
})

HTTPClient is the client calls to an organization's service go through unless Options says: one that gives up on a service that doesn't answer, where Go's default client would wait for good.

View Source
var PersonalKinds = map[string]string{"agent": "agents", "skill": "skills", "workflow": "workflows", "rule": "rules", "guardrail": "guardrails"}

PersonalKinds are the kinds of the person's own assets that sync, each with its folder under ~/.blitz.

Functions

func ForgetBranding

func ForgetBranding(dir string) error

ForgetBranding removes dir, the service's folder: on disconnecting, the app is Blitz again (EN-54).

func KeptName

func KeptName(dir string) string

KeptName is the organization's name from the branding kept in dir; "" for none (Blitz's own name).

func LayerDirs

func LayerDirs(dir string) (defaults, locked string)

LayerDirs are the catalog's layers in dir: its default items, which a workspace or the person may override, and its locked ones, which apply over theirs (EN-31). Both are laid out as a workspace's .agents folder.

func Normalize

func Normalize(raw string) (string, error)

Normalize checks a service's address and gives it without a trailing slash: https, or http to this computer (for development).

func PersonalFiles added in v1.1.0

func PersonalFiles(root string) (map[string]map[string]string, map[string]string)

PersonalFiles are the person's own assets under root (~/.blitz), by "kind/name", each its files by path under root; skipped are those that can't sync, and why (agentpkg.ReadAssets).

func PersonalSecrets added in v1.2.0

func PersonalSecrets(files map[string]string) []secretscan.Finding

PersonalSecrets are what look like secrets in one of the person's own assets, by file and line, before it leaves the computer (shared or synced): what's published is read for secrets first, as a shared folder is (spec_053 EN-36a, EN-66). A line marked secretscan.AllowMarker is a false alarm.

func Register

func Register(c *Client)

Register makes c the process's Client for its service: blitzd's, with the store and the name it signs in with.

func SecretsSummary added in v1.2.0

func SecretsSummary(found []secretscan.Finding) string

SecretsSummary names what a secret scan found, each by file and line, the first ten.

func ValidHandle

func ValidHandle(h string) bool

ValidHandle is whether h can be a workspace's handle.

Types

type AppClient

type AppClient struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret,omitempty"`
}

AppClient is an OAuth client an app signs in with. The secret, when the provider gives one to apps, isn't confidential.

type Branding

type Branding struct {
	Name       string            `json:"name"`
	ShortName  string            `json:"short_name"`
	Accent     string            `json:"accent"`
	AccentDark string            `json:"accent_dark"`
	Support    string            `json:"support"`
	About      string            `json:"about"`
	Images     map[string]string `json:"images"`
	Terms      []Document        `json:"terms"`
}

Branding is how the organization's Blitz looks (spec_053_enterprise EN-50): its name, accents for the light and dark themes, images as data URLs (logo.svg, logo-dark.svg, icon.png, by file name), a support link, an about text, and its documents.

func LoadBranding

func LoadBranding(dir string) *Branding

LoadBranding is the branding kept in dir, checked again against the keys kept with it; nil when there's none, or it doesn't check (Blitz's own look until the service answers).

type Capabilities

type Capabilities struct {
	Tools, Images, Thinking bool
	Context                 int
}

Capabilities are what a model can do, as the organization says (EN-21): whether it uses tools, reads images and thinks before answering, and its context window in tokens (0 when unknown).

type CatalogFile

type CatalogFile struct {
	Kind   string   `json:"kind"`
	Name   string   `json:"name"`
	Path   string   `json:"path"`
	Lock   string   `json:"lock"`
	Groups []string `json:"groups,omitempty"`
	SHA256 string   `json:"sha256"`
	Size   int      `json:"size"`
}

CatalogFile is one of the catalog's files for this person: what it is (an agent, rule, skill or skill's file, guardrail, command, MCP server or connector), its name, its path in the catalog, how it applies (locked or default) and its contents' SHA-256.

type Client

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

Client is the connection to one service, for one person on this computer. It's safe to use at once from many goroutines; renewals go one at a time, since each refresh token is good once.

func New

func New(u string, store secrets.Store, o Options) *Client

New is the connection to the service at u (already normalized), keeping its sign-in in store.

func NewRun

func NewRun(u, run, secret string, o Options) *Client

NewRun is a run's connection to the organization's service, for a job that runs on it (spec_009_jobs JB-10, JB-11): its access tokens, as the job's owner, come for the run's secret instead of a person's sign-in.

func Shared

func Shared(u string, store func() secrets.Store, o Options) *Client

Shared is the process's Client for the service at u (normalized), made with store and o when none is registered yet.

func (*Client) AcceptTerms

func (c *Client) AcceptTerms(ctx context.Context, version string) error

AcceptTerms records that the person accepted version of the terms.

func (*Client) AccessToken

func (c *Client) AccessToken(ctx context.Context) (string, error)

AccessToken is a current access token for the service's calls, renewed when it's near its end. A renewal the service refuses (the session was ended, the person deactivated) signs out here too: the error is the service's refusal, and ErrNotSignedIn after it.

func (*Client) AnswerRun

func (c *Client) AnswerRun(ctx context.Context, run string, approve bool, note string) (ServiceRun, error)

AnswerRun approves or denies what a paused run asks for, with a note; the run goes on.

func (*Client) CachedModels added in v0.9.2

func (c *Client) CachedModels() []Model

CachedModels are the models the last Models call returned, without asking the service: none before the first.

func (*Client) CallAPI added in v1.1.0

func (c *Client) CallAPI(ctx context.Context, connector, method, path, query string, body []byte, header http.Header) (*http.Response, error)

CallAPI calls one of the organization's API connectors through its service, as the signed-in person (spec_053 EN-91; the service's spec_013 CN-71): method on path under the connector, with query and body; header's Content-Type and Accept go along. The service adds the organization's token and logs the call. Its answer is the server's, as it gave it; the caller closes its body.

func (*Client) Children

func (c *Client) Children(ctx context.Context, name string) ([]Resource, error)

Children are what's under a resource name, all of them (RN-31).

func (*Client) ConnectorConsent added in v1.1.0

func (c *Client) ConnectorConsent(ctx context.Context) (string, bool, error)

ConnectorConsent is where the person lets connectors query as them, with their Google account, and whether they have (EN-76).

func (*Client) CreateWorkspace

func (c *Client) CreateWorkspace(ctx context.Context, name, handle string, personal bool) (Workspace, error)

CreateWorkspace makes a workspace of the organization's, the person its owner; handle "" lets the service make one from the name. A personal one's handle is ~<the person>/<handle> (blitz-enterprise WS-01).

func (*Client) DeletePersonal added in v1.1.0

func (c *Client) DeletePersonal(ctx context.Context, kind, name string, base int) error

DeletePersonal removes the person's asset, a change from revision base.

func (*Client) EndRun

func (c *Client) EndRun(ctx context.Context, end RunEnd) error

EndRun tells the service how the run ended; after it, the run's secret is good for nothing.

func (*Client) GoingRuns

func (c *Client) GoingRuns(ctx context.Context) ([]GoingRun, error)

GoingRuns are the runs going now in the person's workspaces.

func (*Client) Host

func (c *Client) Host() string

Host is the service's host, as Git names it when it asks for a credential.

func (*Client) Invalidate

func (c *Client) Invalidate()

Invalidate drops the access token, so the next call renews it: after the service refused it as expired.

func (*Client) JobRuns

func (c *Client) JobRuns(ctx context.Context, job string) ([]ServiceRun, error)

JobRuns are a service job's latest runs, newest first.

func (*Client) Jobs

func (c *Client) Jobs(ctx context.Context) ([]ServiceJob, error)

Jobs are the service's jobs in the person's workspaces.

func (*Client) KeepArtifact

func (c *Client) KeepArtifact(ctx context.Context, path string, body io.Reader, mediaType string) error

KeepArtifact keeps one of the run's files at path (out/report.csv) as its artifact, urn:blitz:artifacts:<workspace>:<job>:<run>/<path> (spec_009_jobs JB-30): while the run goes, with its secret.

func (*Client) MCPEndpoint added in v1.1.0

func (c *Client) MCPEndpoint(name string) string

MCPEndpoint is the service's endpoint for the shared connector name when it's a remote MCP server: MCP's streamable HTTP, through the service, which adds the organization's token (the service's CN-51).

func (*Client) Models

func (c *Client) Models(ctx context.Context) ([]Model, error)

Models are the organization's models the person may use: the service filters them by role. The list is kept and asked for again with its ETag, so an unchanged one costs the service nothing.

func (*Client) Notices

func (c *Client) Notices(ctx context.Context) (Notices, error)

Notices are the person's notice settings.

func (*Client) OpenResource

func (c *Client) OpenResource(ctx context.Context, name string) (io.ReadCloser, error)

OpenResource reads a file's content by its name (RN-32): the caller closes it.

func (*Client) PendingRuns

func (c *Client) PendingRuns(ctx context.Context) ([]GoingRun, error)

PendingRuns are the runs paused for the person's answer (theirs, or in workspaces they're an Owner of; spec_053 EN-43).

func (*Client) PersonalItem added in v1.1.0

func (c *Client) PersonalItem(ctx context.Context, kind, name string) (PersonalItem, error)

PersonalItem is one of them, with its files.

func (*Client) PersonalItems added in v1.1.0

func (c *Client) PersonalItems(ctx context.Context) ([]PersonalItem, map[string]bool, error)

PersonalItems are the person's own assets the service keeps (no files) and which kinds it keeps, by kind.

func (*Client) PutPersonal added in v1.1.0

func (c *Client) PutPersonal(ctx context.Context, kind, name string, files map[string]string, base int) (PersonalItem, error)

PutPersonal keeps files as the person's asset, a change from revision base (0: a new one); ErrChangedElsewhere when another came first.

func (*Client) Reachable

func (c *Client) Reachable() bool

Reachable is false while the service hasn't answered lately (the last call failed to reach it within downFor).

func (*Client) ReadJobs

func (c *Client) ReadJobs(ctx context.Context, handle string) ([]ServiceJob, map[string]string, error)

ReadJobs has the service read a workspace's main now, not at its next scan, and gives its jobs there, and the jobs main defines that the service doesn't run, each with why (a Viewer of it may).

func (*Client) Receipt added in v1.1.0

func (c *Client) Receipt(ctx context.Context, r Receipt) error

Receipt tells the service what a git hook's workflow found (the service's spec_014 LB-40).

func (*Client) RefreshBranding

func (c *Client) RefreshBranding(ctx context.Context, dir string) (*Branding, error)

RefreshBranding asks the service for its branding (with the ETag of the copy kept) and keeps a new one in dir, after checking its signature. It needs no sign-in. It returns what's in dir after: the service's branding, or nil when it has none (the folder's copy is then removed). A copy that doesn't check is refused and the last one kept.

func (*Client) RefreshCatalog

func (c *Client) RefreshCatalog(ctx context.Context, dir string) (*Manifest, bool, error)

RefreshCatalog asks the service for the person's catalog (with the ETag of the one kept), checks its signature and each file's SHA-256, and lays it out in dir: the default and locked layers, built beside the old ones and swapped in whole, and the policy. It returns the catalog in dir after, and whether it changed; nil when the service has none. A catalog that doesn't check is refused and the last one kept, as it is when the service answers 404 (unsigned) with one kept.

func (*Client) RefreshPolicy added in v1.1.0

func (c *Client) RefreshPolicy(ctx context.Context, dir string) (bool, error)

RefreshPolicy asks the service for the person's effective policy (with the ETag of the one kept), checks its signature, and writes it to dir: policy.json with why each setting is what it is, and the rules and guardrails it switches on, built beside the old ones and swapped in whole. It reports whether it changed. A service before /api/v1/policy answers 404: ErrNoPolicyAPI, and the catalog's policy stands.

func (*Client) RegistrySearch added in v1.1.0

func (c *Client) RegistrySearch(ctx context.Context, q, kind string) ([]RegistryAsset, error)

RegistrySearch searches the organization's registry as the person (EN-96): the published assets their policy offers them whose name or description holds q, of kind ("" for any).

func (*Client) ReportRun added in v1.1.0

func (c *Client) ReportRun(ctx context.Context, r RunReport) error

ReportRun tells the service of a run.

func (*Client) RevokeConnectorConsent added in v1.1.0

func (c *Client) RevokeConnectorConsent(ctx context.Context) error

RevokeConnectorConsent forgets the person's consent: those connectors ask again.

func (*Client) RunJobNow

func (c *Client) RunJobNow(ctx context.Context, job string) (ServiceRun, error)

RunJobNow starts a run of a service job (a Runner of its workspace).

func (*Client) RunMerged

func (c *Client) RunMerged(ctx context.Context, job, run string) (ServiceRun, error)

RunMerged tells the service that a run's changes, on its branch, are on main now (an Editor of its workspace added them).

func (*Client) SetItem added in v1.1.0

func (c *Client) SetItem(ctx context.Context, kind, name string, on bool) (config.OrgAsset, error)

SetItem switches one of the library's available assets on or off for the person (EN-83; the service's spec_014_library LB-22): kind is agent, skill, workflow, rule or guardrail. A required one can't be switched off (a Refusal, required).

func (*Client) SetJobEnabled

func (c *Client) SetJobEnabled(ctx context.Context, job string, on bool) error

SetJobEnabled switches a service job on or off (an Editor of its workspace).

func (*Client) SetNotices

func (c *Client) SetNotices(ctx context.Context, n Notices) (Notices, error)

SetNotices keeps the person's notice settings, answered as kept.

func (*Client) Share added in v1.1.0

func (c *Client) Share(ctx context.Context, kind, name string, files map[string]string, note string) (Submission, error)

Share submits files as the person's kind/name to share with the organization, judged by its evaluator: a Refusal (contribute_off, no_evaluator, name_taken, submission_open, invalid) when it isn't taken.

func (*Client) SharedConnectors added in v1.1.0

func (c *Client) SharedConnectors(ctx context.Context) ([]SharedConnector, error)

SharedConnectors are the shared connectors the person may use; none from a service before them.

func (*Client) SharedQuery added in v1.1.0

func (c *Client) SharedQuery(ctx context.Context, name, statement string, maxRows int) (json.RawMessage, error)

SharedQuery runs statement through the shared connector named name, as the person, at most maxRows rows (0: as many as their policy allows); the result is the service's table, as Blitz's data tables are in JSON. A refusal says why and who decided it (a *Refusal, 403).

func (*Client) SharedSchema added in v1.1.0

func (c *Client) SharedSchema(ctx context.Context, name string) ([]SharedTable, error)

SharedSchema are the tables of the shared connector named name the person may use.

func (*Client) SignInBrowser

func (c *Client) SignInBrowser(ctx context.Context, show func(Prompt), pasted <-chan string) error

SignInBrowser signs in through a browser, for the desktop app and the tray: the authorization code with PKCE, received on a redirect to this computer (EN-12). show gets the address to open; pasted takes the address the browser ended on when it's on another computer (an SSH session).

func (*Client) SignInDevice

func (c *Client) SignInDevice(ctx context.Context, show func(Prompt)) error

SignInDevice signs in with a code entered in a browser anywhere, for the CLI (EN-12): show gets the address and the code.

func (*Client) SignOut

func (c *Client) SignOut(ctx context.Context) error

SignOut ends the session at the service, then here. Here it always ends: a service that can't be reached ends it when its refresh token expires.

func (*Client) SignedHTTP added in v1.1.0

func (c *Client) SignedHTTP() *http.Client

SignedHTTP is an HTTP client whose requests carry the person's access token, renewed as it needs to be.

func (*Client) Status

func (c *Client) Status() Status

Status is the sign-in's state, from what's kept: it calls nothing.

func (*Client) Submissions added in v1.1.0

func (c *Client) Submissions(ctx context.Context) ([]Submission, error)

Submissions are the person's submissions, the newest first.

func (*Client) Terms

func (c *Client) Terms(ctx context.Context) (Terms, error)

Terms asks the service for its terms in force.

func (*Client) URL

func (c *Client) URL() string

URL is the service's address.

func (*Client) Usage

func (c *Client) Usage(ctx context.Context) (Usage, error)

Usage asks the service for the person's usage.

func (*Client) WatchCatalog

func (c *Client) WatchCatalog(ctx context.Context, on func()) error

WatchCatalog follows the service's stream of catalog versions, calling on for each one published, until ctx ends or the stream does (the error says why).

func (*Client) WatchRuns

func (c *Client) WatchRuns(ctx context.Context, on func(RunChange)) error

WatchRuns follows the changes of runs in the person's workspaces (blitz-enterprise spec_009_jobs JB-60), calling on with each, until ctx ends or the stream does (an error either way).

func (*Client) WatchWorkspace

func (c *Client) WatchWorkspace(ctx context.Context, handle string, on func(ref, commit, by string)) error

WatchWorkspace follows a workspace's stream of pushes (the enterprise service's WS-06), calling on with each pushed ref's new commit, until ctx ends or the stream does (the error says why).

func (*Client) Workspaces

func (c *Client) Workspaces(ctx context.Context) ([]Workspace, error)

Workspaces are the organization's workspaces the person has a role in.

type Document

type Document struct {
	Document  string    `json:"document"`
	Version   string    `json:"version"`
	Text      string    `json:"text,omitempty"`
	URL       string    `json:"url,omitempty"`
	Effective time.Time `json:"effective,omitzero"`
}

Document is one of the organization's documents: its terms of service (terms) or privacy notice (privacy), as text or a link, with a version.

type GoingRun

type GoingRun struct {
	ServiceRun
	JobName   string `json:"job_name"`
	Workspace string `json:"workspace"`
}

GoingRun is a run going now, with its job's name and workspace's handle.

type Info

type Info struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	OIDC    struct {
		Issuer   string    `json:"issuer"`
		ClientID string    `json:"client_id"`
		Desktop  AppClient `json:"desktop"`
		Device   AppClient `json:"device"`
	} `json:"oidc"`
	Capabilities []string `json:"capabilities"`
	// CatalogKeys check what the service signs (its branding, its
	// catalog), by key ID: Ed25519 public keys, base64.
	CatalogKeys map[string]string `json:"catalog_keys"`
}

Info is what the service says about itself (EN-11).

func Discover

func Discover(ctx context.Context, hc *http.Client, u string) (Info, error)

Discover asks the service at u what it offers.

func (Info) Has

func (i Info) Has(capability string) bool

Has is whether the service offers a capability (gateway, catalog, jobs, sharing, workspaces, branding).

type Limit

type Limit struct {
	// ScopeKind is person, group or org: whose it is.
	ScopeKind string `json:"scope_kind"`
	Period    string `json:"period"` // day or month
	Unit      string `json:"unit"`   // usd or tokens
	// Model is the model it limits ("" for every model together).
	Model        string    `json:"model"`
	AmountUSD    float64   `json:"amount_usd"`
	Tokens       int64     `json:"tokens"`
	InputTokens  int64     `json:"input_tokens"`
	OutputTokens int64     `json:"output_tokens"`
	Used         Used      `json:"used"`
	Resets       time.Time `json:"resets"`
}

Limit is a budget (dollars) or a quota (tokens) that applies to the person, what they used of it, and when it starts again.

type Manifest

type Manifest struct {
	Version int           `json:"version"`
	Commit  string        `json:"commit"`
	Built   time.Time     `json:"built"`
	Files   []CatalogFile `json:"files"`
	Policy  Policy        `json:"policy"`
	// Expires is when Blitz stops working under it unrenewed (EN-33).
	Expires time.Time `json:"expires"`
}

Manifest is a version of the catalog for this person.

func LoadCatalog

func LoadCatalog(dir string) *Manifest

LoadCatalog is the manifest kept in dir, checked again against the keys kept with it; nil when there's none or it doesn't check.

type Model

type Model struct {
	ID              string         `json:"id"`
	DisplayName     string         `json:"display_name"`
	Vendor          string         `json:"vendor"`
	API             string         `json:"api"`
	Capabilities    map[string]any `json:"capabilities"`
	Price           *Price         `json:"price"`
	Default         bool           `json:"default"`
	MaxOutputTokens int            `json:"max_output_tokens"`
}

Model is one of the organization's models the person may use (EN-21).

func Find

func Find(list []Model, id string) (m Model, ok bool)

Find is the model id in list, else the default one, else the first: a model the settings name that the organization doesn't offer gives way to one it does. ok is false only for an empty list.

func (Model) Caps

func (m Model) Caps() (c Capabilities, ok bool)

Caps are m's capabilities; ok is false when the service says none.

type Notices

type Notices struct {
	Email    bool   `json:"email"`
	Webhook  string `json:"webhook"`
	EveryRun bool   `json:"every_run"`
	// EmailAvailable says the service sends email at all.
	EmailAvailable bool `json:"email_available,omitempty"`
}

Notices are how the person hears of their jobs' runs on the service (the enterprise spec's JB-31): by email, by a webhook (https), and for every run or only failures and runs waiting for their answer.

type Options

type Options struct {
	// HTTP is the client the calls go through (http.DefaultClient).
	HTTP *http.Client
	// Now is the clock (time.Now).
	Now func() time.Time
	// Client names the app and its version for the service's sessions,
	// such as "blitz 0.9.0 (desktop)".
	Client string
	// BrandingDir is the folder the service's branding is kept in
	// (RefreshBranding's): the browser sign-in's page shows it.
	BrandingDir string
}

Options are a Client's.

type Person

type Person struct {
	ID    string   `json:"id"`
	Email string   `json:"email"`
	Name  string   `json:"name"`
	Roles []string `json:"roles"`
}

Person is who's signed in, as the service knows them.

type PersonalItem added in v1.1.0

type PersonalItem struct {
	Kind      string            `json:"kind"`
	Name      string            `json:"name"`
	Revision  int               `json:"revision"`
	SHA256    string            `json:"sha256"`
	ChangedAt time.Time         `json:"changed_at"`
	Files     map[string]string `json:"files,omitempty"`
}

PersonalItem is one of the person's own assets as the organization's service keeps it (spec_053 EN-93; the service's spec_014 LB-50): its files are paths under ~/.blitz ("skills/tone/SKILL.md").

type Policy

type Policy struct {
	// Refresh is how often to fetch the catalog when its stream isn't up,
	// as a Go duration ("15m" when unset).
	Refresh string `json:"refresh"`
	config.OrgPolicy
}

Policy is the organization's policy (spec_053_enterprise EN-35), as far as Blitz applies it: how often to fetch the catalog, and the rules pkg/config applies from policy.json, one type for both so neither drops what the other reads.

type PolicyEntry added in v1.1.0

type PolicyEntry struct {
	Kind   string `json:"kind"` // rule or guardrail
	Name   string `json:"name"`
	Body   string `json:"body"`
	SHA256 string `json:"sha256"`
}

PolicyEntry is one of the organization's rules or guardrails the person's policy switches on, with its text.

type PolicyEnvelope added in v1.1.0

type PolicyEnvelope struct {
	Schema     int                              `json:"schema"`
	Policy     Policy                           `json:"policy"`
	Explain    map[string]config.PolicyDecision `json:"explain"`
	Rules      []PolicyEntry                    `json:"rules"`
	Guardrails []PolicyEntry                    `json:"guardrails"`
	// Items are the library's assets it offers them (EN-80); none from a
	// service before the library.
	Items   []PolicyItem `json:"items"`
	Expires time.Time    `json:"expires"`
}

PolicyEnvelope is what the service signs at /api/v1/policy (its spec_012_policy PO-20): the person's effective policy, why each setting is what it is, their rules and guardrails, and until when it holds.

type PolicyItem added in v1.1.0

type PolicyItem struct {
	config.OrgAsset
	Files map[string]string `json:"files,omitempty"`
}

PolicyItem is one of the library's assets as the service delivers it (its spec_014_library LB-21): what the person's Blitz lays out (EN-80), its files when they have it.

type Price

type Price struct {
	InputPerMTok  float64 `json:"input_per_mtok"`
	OutputPerMTok float64 `json:"output_per_mtok"`
}

Price is a model's, in dollars per million tokens.

type Prompt

type Prompt struct {
	URL  string
	Code string
}

Prompt is what the person does to sign in: open URL in a browser, and, for the device code, enter Code there.

type Published added in v1.1.0

type Published struct {
	Version    string `json:"version"`
	URI        string `json:"uri"`
	Evaluating any    `json:"evaluating,omitempty"`
}

Published is what a publish to the registry did: the version it published, or, while its evals run, that it's being evaluated.

type RateLimit

type RateLimit struct {
	Model     string `json:"model"`
	PersonRPM int    `json:"person_rpm"`
	PersonTPM int    `json:"person_tpm"`
	RPM       int    `json:"rpm"`
	TPM       int    `json:"tpm"`
}

RateLimit is how many requests and tokens a minute one of the models takes: everyone's together, and each person's.

type Receipt added in v1.1.0

type Receipt struct {
	Workflow  string    `json:"workflow"`
	Version   string    `json:"version,omitempty"`
	Event     string    `json:"event"`
	Repo      string    `json:"repo,omitempty"`
	Tree      string    `json:"tree"`
	Passed    bool      `json:"passed"`
	Message   string    `json:"message,omitempty"`
	Workspace string    `json:"workspace,omitempty"`
	At        time.Time `json:"at"`
}

Receipt is what a workflow a git hook ran found (EN-92): which workflow, its version (the organization's, "" for the workspace's own), the event, the tree it ran on, and whether it passed.

type Refusal

type Refusal struct {
	Status  int
	Code    string
	Message string
}

Refusal is the service's refusal: its status, its code (unauthenticated, forbidden, license_lapsed, terms_required…) and its message, written for the person.

func (*Refusal) Error

func (r *Refusal) Error() string

Error is the message, else the status and code.

type Registry added in v1.1.0

type Registry struct {
	Client *Client
	URL    string
	Token  string
	HTTP   *http.Client
}

Registry is an organization's registry for `blitz pkg` (spec_065 PK-16; the service's spec_016): through the person's sign-in (Client), or, for CI and builders outside Blitz, a registry token (URL and Token, BLITZ_REGISTRY_TOKEN).

func (*Registry) Fetch added in v1.1.0

func (r *Registry) Fetch(ctx context.Context, host, kind, name, rng string) (string, map[string]string, error)

Fetch is the version rng resolves to of kind/name, and its files (packages.Registry): host must be this registry's.

func (*Registry) Publish added in v1.1.0

func (r *Registry) Publish(ctx context.Context, kind, name string, files map[string]string, bump, note string) (Published, error)

Publish publishes files as kind/name's next version (bump: patch, minor or major), through the library's evals.

func (*Registry) Search added in v1.1.0

func (r *Registry) Search(ctx context.Context, q, kind string) ([]RegistryAsset, error)

Search lists the published assets whose name or description holds q.

type RegistryAsset added in v1.1.0

type RegistryAsset struct {
	Kind        string `json:"kind"`
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`
	State       string `json:"state,omitempty"`
	On          bool   `json:"on,omitempty"`
	URI         string `json:"uri"`
	// Tags are its own; Lifecycle is deprecated or obsolete, with why
	// (Note); Snippet its words around what matched (the service's RG-14).
	Tags      []string `json:"tags,omitempty"`
	Lifecycle string   `json:"lifecycle,omitempty"`
	Note      string   `json:"lifecycle_note,omitempty"`
	Snippet   string   `json:"snippet,omitempty"`
}

RegistryAsset is one of the organization's published assets as its registry lists it (the service's spec_016 RG-10): for a person, its state for them (available or required) and whether they have it.

func (RegistryAsset) Label added in v1.1.0

func (a RegistryAsset) Label() string

Label is how a's life and tags read beside its name: "(deprecated: why) #tag", "" for none.

type Request

type Request struct {
	Tool   string `json:"tool"`
	Kind   string `json:"kind"`
	Detail string `json:"detail"`
}

Request is what a paused run asks for: a tool, its kind, and what exactly.

type Resource

type Resource struct {
	URN       string     `json:"urn"`
	Kind      string     `json:"kind"`
	Title     string     `json:"title"`
	Parent    string     `json:"parent"`
	Created   *time.Time `json:"created"`
	MediaType string     `json:"media_type"`
	Size      int64      `json:"size"`
}

Resource is what the service says a resource name is (spec_055_urns RN-30).

type RunChange

type RunChange struct {
	Run, Job string
	// Workspace is its handle.
	Workspace, Status string
}

RunChange is one run's change: queued, started, ended, or its branch pushed.

type RunEnd

type RunEnd struct {
	// Status is succeeded, failed or stopped.
	Status string `json:"status"`
	// Note says why it failed or stopped.
	Note string `json:"note,omitempty"`
	// Output is the run's last message.
	Output string `json:"output,omitempty"`
	// Branch is where its changes went ("" for none).
	Branch string `json:"branch,omitempty"`
	// Merged is whether its changes are on main too; MergeNote why not,
	// when they're on its branch only (JB-10).
	Merged    bool    `json:"merged,omitempty"`
	MergeNote string  `json:"merge_note,omitempty"`
	CostUSD   float64 `json:"cost_usd"`
	// A paused run's (RunPaused): what it asks for, and its session.
	Pending *Request `json:"pending,omitempty"`
	Session string   `json:"session,omitempty"`
}

RunEnd is how a run ended, for the service.

type RunReport added in v1.1.0

type RunReport struct {
	Kind      string     `json:"kind"` // workflow or eval
	Name      string     `json:"name"`
	Status    string     `json:"status"`
	Workspace string     `json:"workspace,omitempty"`
	StartedAt time.Time  `json:"started_at"`
	EndedAt   *time.Time `json:"ended_at,omitempty"`
	CostUSD   float64    `json:"cost_usd"`
	Summary   string     `json:"summary,omitempty"`
}

RunReport is one of the person's workflow or eval runs, as the service keeps it (EN-94; the service's LB-54).

type ServiceJob

type ServiceJob struct {
	ID        string     `json:"id"`
	URN       string     `json:"urn"`
	Workspace string     `json:"workspace"` // its handle
	Name      string     `json:"name"`
	Schedule  string     `json:"schedule"`
	Timezone  string     `json:"timezone"`
	Enabled   bool       `json:"enabled"`
	NextRun   *time.Time `json:"next_run"`
	LastRun   *time.Time `json:"last_run"`
	// Description says what it does.
	Description string `json:"description"`
	// Organization: one of the organization's own jobs, which its admins
	// write and its policy lets the person see, run or answer (the
	// service's spec_009_jobs JB-72), in no workspace of theirs.
	Organization bool `json:"organization"`
}

ServiceJob is a job the organization's service runs (spec_053_enterprise EN-42; blitz-enterprise spec_009_jobs JB-60), as the person may see it.

type ServiceRun

type ServiceRun struct {
	ID      string `json:"id"`
	URN     string `json:"urn"`
	Job     string `json:"job"`     // its ID
	Trigger string `json:"trigger"` // schedule, catch_up or now
	// Status is queued, running, succeeded, failed, skipped or stopped.
	Status  string     `json:"status"`
	Note    string     `json:"note"`
	Output  string     `json:"output"`
	CostUSD float64    `json:"cost_usd"`
	Created time.Time  `json:"created"`
	Started *time.Time `json:"started"`
	Ended   *time.Time `json:"ended"`
	// Branch is where its changes went ("" for none); Artifacts the name
	// of what it left (spec_055_urns); As the person it acted as.
	Branch    string `json:"branch"`
	Artifacts string `json:"artifacts"`
	As        string `json:"as"`
	// Merged is whether its changes are on main too; MergeNote why not,
	// when they're on its branch only.
	Merged    bool   `json:"merged"`
	MergeNote string `json:"merge_note"`
	// A paused run's request (status paused), and how it was answered.
	Pending    *Request `json:"pending"`
	Answer     string   `json:"answer"`
	AnswerNote string   `json:"answer_note"`
}

ServiceRun is one of a service job's runs.

type SharedConnector added in v1.1.0

type SharedConnector struct {
	Name        string `json:"name"`
	Kind        string `json:"kind"`
	Description string `json:"description"`
	// ReadOnly: their queries can't change data (the connector's, or
	// their policy's doing).
	ReadOnly bool `json:"read_only"`
	// Tables are the patterns of the tables they may use; every one when
	// none.
	Tables  []string `json:"tables,omitempty"`
	MaxRows int      `json:"max_rows"`
	// Auth is person when it queries as them, with their Google consent
	// (EN-76; the service's CN-60).
	Auth string `json:"auth,omitempty"`
}

SharedConnector is one of the organization's shared connectors the person's policy lets them use (spec_053 EN-70; the service's spec_013_connectors CN-20): the service holds the connection and its secrets, and runs their queries.

type SharedTable added in v1.1.0

type SharedTable struct {
	Name    string `json:"name"`
	About   string `json:"about,omitempty"`
	Columns []struct {
		Name  string `json:"name"`
		Type  string `json:"type,omitempty"`
		About string `json:"about,omitempty"`
	} `json:"columns"`
}

SharedTable is one of a shared connector's tables they may use.

type Status

type Status struct {
	URL      string
	SignedIn bool
	Person   Person
	Info     Info
	// Renews is when the access token is next renewed; zero until one is
	// asked for.
	Renews time.Time
	// Terms is a version of the organization's terms to accept, if the
	// service said so at the last sign-in or renewal (EN-53).
	Terms string
}

Status is who's signed in, and until when their access token lasts.

type Submission added in v1.1.0

type Submission struct {
	ID        int64      `json:"id"`
	Kind      string     `json:"kind"`
	Name      string     `json:"name"`
	Note      string     `json:"note"`
	State     string     `json:"state"`
	Verdicts  []Verdict  `json:"verdicts"`
	Reason    string     `json:"reason"`
	Published string     `json:"published_version,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	DecidedAt *time.Time `json:"decided_at,omitempty"`
}

Submission is one of the person's assets submitted to share with the organization (EN-95; the service's LB-60): judging, rejected, held for an admin, accepted (then its published version) or error.

type SyncReport added in v1.1.0

type SyncReport struct {
	Sent, Received, Removed []string
	// Conflicts were changed on this computer and another: this one's
	// kept and sent, the other's saved under ~/.blitz/conflicts.
	Conflicts []string
	// Skipped can't sync, and why: a kind the policy doesn't keep, a
	// name or file the service doesn't take.
	Skipped map[string]string
}

SyncReport is what a sync of the person's own assets did (EN-93), by "kind/name".

func SyncPersonal added in v1.1.0

func SyncPersonal(ctx context.Context, c *Client, root, state string) (SyncReport, error)

SyncPersonal syncs the person's own assets under root (~/.blitz) with the organization's service, both ways (EN-93), remembering what it synced in state (a file): what changed here is sent, what changed on another computer is fetched, what was removed on one side is removed on the other; changed on both, this computer's wins and the other's is kept under root/conflicts. Kinds the policy doesn't keep are left alone.

type Terms

type Terms struct {
	Version   string    `json:"version"`
	Accepted  bool      `json:"accepted"`
	Text      string    `json:"text"`
	URL       string    `json:"url"`
	Effective time.Time `json:"effective"`
}

Terms is the version of the organization's terms in force and whether the person has accepted it (EN-53), with the text to read or its link.

type Usage

type Usage struct {
	Today      map[string]Used `json:"today"`
	Month      map[string]Used `json:"month"`
	Limits     []Limit         `json:"limits"`
	RateLimits []RateLimit     `json:"rate_limits"`
	PromptLogs bool            `json:"prompt_logs"`
}

Usage is the person's own use of the organization's models (spec_053 EN-24; the gateway's GW-27): today's and this month's by model, the limits that apply with what's left, and whether full prompt logs keep their requests.

type Used

type Used struct {
	Requests     int64   `json:"requests"`
	InputTokens  int64   `json:"input_tokens"`
	Cached       int64   `json:"cached_input_tokens"`
	OutputTokens int64   `json:"output_tokens"`
	CostUSD      float64 `json:"cost_usd"`
}

Used is what was used of the organization's models: requests, tokens and cost.

type Verdict added in v1.1.0

type Verdict struct {
	Check    string   `json:"check"`
	Score    float64  `json:"score"`
	Passed   bool     `json:"passed"`
	Reason   string   `json:"reason"`
	Findings []string `json:"findings,omitempty"`
}

Verdict is one of an evaluator's checks' on a submission.

type Workspace

type Workspace struct {
	// ID is the service's, which never changes (the Blitz-Workspace header,
	// EN-22).
	ID       string
	Handle   string
	Name     string
	Role     string // owner, editor, runner or viewer
	Sync     bool   // saved and shared as it changes (EN-62)
	CloneURL string
	Archived bool
}

Workspace is one of the organization's workspaces the person has a role in (spec_053_enterprise EN-60): a Git repository the service keeps, cloned through it at CloneURL.

Directories

Path Synopsis
Package enterprisetest has an identity provider and an organization's service for tests, as strict as the real ones (spec_053_enterprise EN-12): the provider checks PKCE, the client and its redirect, and keeps the device code pending once; the service rotates refresh tokens, ends a session whose spent one comes back, and serves the person's models with an ETag.
Package enterprisetest has an identity provider and an organization's service for tests, as strict as the real ones (spec_053_enterprise EN-12): the provider checks PKCE, the client and its redirect, and keeps the device code pending once; the service rotates refresh tokens, ends a session whose spent one comes back, and serves the person's models with an ETag.

Jump to

Keyboard shortcuts

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