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
- Variables
- func ForgetBranding(dir string) error
- func KeptName(dir string) string
- func LayerDirs(dir string) (defaults, locked string)
- func Normalize(raw string) (string, error)
- func Register(c *Client)
- func ValidHandle(h string) bool
- type AppClient
- type Branding
- type Capabilities
- type CatalogFile
- type Client
- func (c *Client) AcceptTerms(ctx context.Context, version string) error
- func (c *Client) AccessToken(ctx context.Context) (string, error)
- func (c *Client) AnswerRun(ctx context.Context, run string, approve bool, note string) (ServiceRun, error)
- func (c *Client) CatalogReviews(ctx context.Context, state string) ([]Review, error)
- func (c *Client) Children(ctx context.Context, name string) ([]Resource, error)
- func (c *Client) CreateWorkspace(ctx context.Context, name, handle string, personal bool) (Workspace, error)
- func (c *Client) EndRun(ctx context.Context, end RunEnd) error
- func (c *Client) GoingRuns(ctx context.Context) ([]GoingRun, error)
- func (c *Client) Host() string
- func (c *Client) Invalidate()
- func (c *Client) JobRuns(ctx context.Context, job string) ([]ServiceRun, error)
- func (c *Client) Jobs(ctx context.Context) ([]ServiceJob, error)
- func (c *Client) KeepArtifact(ctx context.Context, path string, body io.Reader, mediaType string) error
- func (c *Client) Models(ctx context.Context) ([]Model, error)
- func (c *Client) Notices(ctx context.Context) (Notices, error)
- func (c *Client) OpenResource(ctx context.Context, name string) (io.ReadCloser, error)
- func (c *Client) PendingRuns(ctx context.Context) ([]GoingRun, error)
- func (c *Client) PublishCatalog(ctx context.Context, title string, files map[string][]byte) (Review, error)
- func (c *Client) Reachable() bool
- func (c *Client) ReadJobs(ctx context.Context, handle string) ([]ServiceJob, map[string]string, error)
- func (c *Client) RefreshBranding(ctx context.Context, dir string) (*Branding, error)
- func (c *Client) RefreshCatalog(ctx context.Context, dir string) (*Manifest, bool, error)
- func (c *Client) RunJobNow(ctx context.Context, job string) (ServiceRun, error)
- func (c *Client) RunMerged(ctx context.Context, job, run string) (ServiceRun, error)
- func (c *Client) SetJobEnabled(ctx context.Context, job string, on bool) error
- func (c *Client) SetNotices(ctx context.Context, n Notices) (Notices, error)
- func (c *Client) SignInBrowser(ctx context.Context, show func(Prompt), pasted <-chan string) error
- func (c *Client) SignInDevice(ctx context.Context, show func(Prompt)) error
- func (c *Client) SignOut(ctx context.Context) error
- func (c *Client) Status() Status
- func (c *Client) Terms(ctx context.Context) (Terms, error)
- func (c *Client) URL() string
- func (c *Client) Usage(ctx context.Context) (Usage, error)
- func (c *Client) WatchCatalog(ctx context.Context, on func()) error
- func (c *Client) WatchRuns(ctx context.Context, on func(RunChange)) error
- func (c *Client) WatchWorkspace(ctx context.Context, handle string, on func(ref, commit, by string)) error
- func (c *Client) Workspaces(ctx context.Context) ([]Workspace, error)
- type Document
- type GoingRun
- type Info
- type Limit
- type Manifest
- type Model
- type Notices
- type Options
- type Person
- type Policy
- type Price
- type Prompt
- type RateLimit
- type Refusal
- type Request
- type Resource
- type Review
- type RunChange
- type RunEnd
- type ServiceJob
- type ServiceRun
- type Status
- type Terms
- type Usage
- type Used
- type Workspace
Constants ¶
const ( APIMessages = "messages" // Anthropic's Messages API APIResponses = "responses" // OpenAI's Responses API )
The APIs a model speaks, as the service names them.
const (
PolicyFile = "policy.json"
)
The catalog's files in the organization's folder (EN-33, EN-54).
const RunPaused = "paused"
RunPaused is the status of a run that waits for its owner's answer (blitz-enterprise spec_009_jobs JB-13).
Variables ¶
var ErrNotSignedIn = errors.New("not signed in to the organization's service")
ErrNotSignedIn means no one is signed in to the service.
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.
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.
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.
Functions ¶
func ForgetBranding ¶
ForgetBranding removes dir, the service's folder: on disconnecting, the app is Blitz again (EN-54).
func KeptName ¶
KeptName is the organization's name from the branding kept in dir; "" for none (Blitz's own name).
func LayerDirs ¶
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 ¶
Normalize checks a service's address and gives it without a trailing slash: https, or http to this computer (for development).
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 ValidHandle ¶
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 ¶
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 ¶
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 ¶
New is the connection to the service at u (already normalized), keeping its sign-in in store.
func NewRun ¶
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 ¶
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 ¶
AcceptTerms records that the person accepted version of the terms.
func (*Client) AccessToken ¶
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) CatalogReviews ¶
CatalogReviews are the catalog's reviews, the newest first; state "" for all.
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) EndRun ¶
EndRun tells the service how the run ended; after it, the run's secret is good for nothing.
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) 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) Models ¶
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) OpenResource ¶
OpenResource reads a file's content by its name (RN-32): the caller closes it.
func (*Client) PendingRuns ¶
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) PublishCatalog ¶
func (c *Client) PublishCatalog(ctx context.Context, title string, files map[string][]byte) (Review, error)
PublishCatalog sends files (by their paths in the catalog) to the service as a review, for an Admin (its author too) to approve.
func (*Client) Reachable ¶
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) RefreshBranding ¶
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 ¶
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) RunMerged ¶
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) SetJobEnabled ¶
SetJobEnabled switches a service job on or off (an Editor of its workspace).
func (*Client) SetNotices ¶
SetNotices keeps the person's notice settings, answered as kept.
func (*Client) SignInBrowser ¶
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 ¶
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 ¶
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) WatchCatalog ¶
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 ¶
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).
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).
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 ¶
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 ¶
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 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 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 ¶
Prompt is what the person does to sign in: open URL in a browser, and, for the device code, enter Code there.
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 Refusal ¶
Refusal is the service's refusal: its status, its code (unauthenticated, forbidden, license_lapsed, terms_required…) and its message, written for the person.
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 Review ¶
type Review struct {
ID string `json:"id"`
Title string `json:"title"`
ByEmail string `json:"by_email"`
Branch string `json:"branch"`
Paths []string `json:"paths"`
Problems []string `json:"problems"`
State string `json:"state"` // open, approved or rejected
Note string `json:"note"`
Version *int `json:"version"`
Created time.Time `json:"created"`
}
Review is a change to the organization's catalog an Admin published, waiting for an Admin (its author too), or answered (spec_053 EN-36; the service's CA-03, CA-04).
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 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"`
}
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 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 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 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.
Source Files
¶
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. |