Documentation
¶
Overview ¶
Package proxy implements the Comfy API v2 surface over one ComfyUI.
GET /api/v2/jobs/{id} is authoritative and reads ComfyUI's /history and /queue on every call. The proxy itself only keeps what ComfyUI cannot tell it: the job records it minted (created_at, metadata, priority, the resolved workflow), Idempotency-Key claims, the asset index, and the secret that signs output asset ids. With --state-dir those write through to SQLite.
Index ¶
- type AssetRecord
- type AssetStore
- func (s *AssetStore) Add(rec AssetRecord) (AssetRecord, error)
- func (s *AssetStore) Delete(id string) (bool, error)
- func (s *AssetStore) DeleteExpired(cutoff time.Time) ([]string, error)
- func (s *AssetStore) Get(id string) (AssetRecord, bool)
- func (s *AssetStore) GetByHash(hash string) (AssetRecord, bool)
- type ComfyRef
- type JobRecord
- type Persist
- type Proxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssetRecord ¶
type AssetRecord struct {
ID string
Hash string // "blake3:<hex>", empty for unhashed
SizeBytes int64
ContentType string
FilePath *string
CreatedAt string
ExpiresAt *string
ComfyRef *ComfyRef
DiskPath *string
Tags []string
}
AssetRecord is one asset: its v2 fields plus how to fetch the bytes. Exactly one of ComfyRef and DiskPath is set.
type AssetStore ¶
type AssetStore struct {
// contains filtered or unexported fields
}
AssetStore is the asset index plus its content-hash lookup. A self-hosted ComfyUI is single-user, so there is one namespace, but the v2 shape holds: UUID-identified records over blake3-addressed bytes.
func NewAssetStore ¶
func NewAssetStore(persist Persist) *AssetStore
NewAssetStore returns an empty store that writes through to persist when it is non-nil.
func (*AssetStore) Add ¶
func (s *AssetStore) Add(rec AssetRecord) (AssetRecord, error)
Add stores a new record. The first record with a given hash owns its dedup slot, so a later identical upload resolves to the same record.
func (*AssetStore) Delete ¶
func (s *AssetStore) Delete(id string) (bool, error)
Delete removes a record. It reports whether the record existed.
func (*AssetStore) DeleteExpired ¶
func (s *AssetStore) DeleteExpired(cutoff time.Time) ([]string, error)
DeleteExpired removes every record whose expires_at is at or before cutoff and returns their ids. A record with an unparseable expires_at is kept.
func (*AssetStore) Get ¶
func (s *AssetStore) Get(id string) (AssetRecord, bool)
Get returns a copy of the record, so callers cannot race on it.
func (*AssetStore) GetByHash ¶
func (s *AssetStore) GetByHash(hash string) (AssetRecord, bool)
GetByHash returns the record that owns hash's dedup slot.
type ComfyRef ¶
type ComfyRef struct {
Filename string `json:"filename"`
Subfolder string `json:"subfolder"`
Type string `json:"type"`
}
ComfyRef locates a file through ComfyUI's /view.
type JobRecord ¶
type JobRecord struct {
ID string
CreatedAt time.Time
ClientID string
Metadata *string
Priority *int64
// Workflow is the resolved graph that ran. Nil on records reloaded from
// the store, which skip the column to keep startup cheap.
Workflow json.RawMessage
}
JobRecord is what the proxy remembers about a job it submitted.
type Persist ¶
type Persist interface {
GetMeta(key string) (string, bool, error)
SetMeta(key, value string) error
UpsertJob(rec JobRecord) error
// LoadJobs returns the newest limit records, oldest first, without their
// workflow graphs.
LoadJobs(limit int) ([]JobRecord, error)
GetJob(id string) (*JobRecord, error)
GetJobWorkflow(id string) (json.RawMessage, error)
// ClaimIdempotency reports false when the key is already claimed.
ClaimIdempotency(key string, claimedAt time.Time) (bool, error)
ReleaseIdempotency(key string) error
// LoadIdempotencyKeys returns claimed keys oldest first.
LoadIdempotencyKeys() ([]string, error)
TrimIdempotency(max int) error
UpsertAsset(rec AssetRecord) error
// LoadAssets returns every asset and the hash index (hash to asset id).
LoadAssets() ([]AssetRecord, map[string]string, error)
DeleteAsset(id string) error
}
Persist is the --state-dir write-through store. The in-memory indexes stay the source of truth while the process runs; Persist makes them survive a restart. Implemented by internal/state over SQLite.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy holds the v2 handlers and the proxy-layer state.
func New ¶
New builds a Proxy. store is nil for in-memory mode. log receives operational lines such as expired-asset cleanup counts.
func (*Proxy) RunCleanup ¶
RunCleanup removes expired assets on an interval until ctx ends. Unlike the reference it also runs with --state-dir, where expires_at now persists.
func (*Proxy) StopStreams ¶
func (p *Proxy) StopStreams()
StopStreams ends every open SSE stream. Register it as a server shutdown hook so a graceful stop does not wait on streams that never go idle.