Documentation
¶
Overview ¶
Package element defines language-neutral contracts for computations that can participate in an OpenRealtime graph.
Index ¶
- Constants
- func ValidateIdentity(identity Identity) error
- type CapabilityResolution
- type Cardinality
- type ConfigValidator
- type DeliveryResult
- type Dependency
- type Descriptor
- func (descriptor Descriptor) Canonical() (Descriptor, error)
- func (descriptor Descriptor) Clone() Descriptor
- func (descriptor Descriptor) Digest() (string, error)
- func (descriptor Descriptor) Identity() (Identity, error)
- func (descriptor Descriptor) Port(name string) (Port, bool)
- func (descriptor Descriptor) Validate() error
- type Direction
- type Effect
- type Envelope
- type Factory
- type Identity
- type InputPort
- type InspectionCauseKind
- type InspectionCauseProvider
- type InspectionDecision
- type InspectionDecisionKind
- type InspectionDecisionOperation
- type InspectionDecisionProvider
- type Lifecycle
- type MountContext
- type OutputPort
- type Port
- type Ports
- type Reaction
- type Receiver
- type ResolutionReporter
- type Runnable
- type RunnableFunc
- type SendResult
- type Sender
- type Services
- type StateLifecycle
- type StateQuiescer
- type StateResumer
- type StateSnapshotter
- type StateTransferCapabilities
- type Type
- func Event(payload Type) Type
- func Interrupt(key Type) Type
- func Named(name string, arguments ...Type) Type
- func Reply(payload, key Type) Type
- func Request(payload, key Type) Type
- func Revisions(payload, key Type) Type
- func Segmented(payload, key Type) Type
- func State(payload Type) Type
- func Stream(payload Type) Type
- func Trigger(payload Type) Type
- func Var(name string) Type
- func (value Type) Clone() Type
- func (value Type) ContainsVariable() bool
- func (value Type) Equal(other Type) bool
- func (value Type) IsProtocol() bool
- func (value Type) IsVariable() bool
- func (value Type) String() string
- func (value Type) Validate(generics map[string]struct{}) error
- func (value Type) ValidateConcretePort() error
- func (value Type) ValidatePort(generics map[string]struct{}) error
Constants ¶
const DescriptorFormatVersion = 1
Variables ¶
This section is empty.
Functions ¶
func ValidateIdentity ¶
ValidateIdentity checks the immutable fields supplied by a lockfile.
Types ¶
type CapabilityResolution ¶
type CapabilityResolution struct {
Name string
Contract string
ProviderID string
ProviderRevision string
ProviderDigest string
AdapterID string
AdapterRevision string
AdapterDigest string
}
CapabilityResolution is intentionally independent of provider packages. Provider and adapter identities remain separate so operational evidence can distinguish a model change from a transport/adapter change.
type Cardinality ¶
type Cardinality string
Cardinality says whether a port is singular or is a homogeneous variadic group whose lanes are materialized from graph edges.
const ( One Cardinality = "one" Variadic Cardinality = "variadic" )
type ConfigValidator ¶
type ConfigValidator interface {
ValidateConfig(json.RawMessage) error
}
ConfigValidator proves one resolved node value before any factory in the graph is mounted. A factory whose descriptor declares ConfigSchema must implement this interface; an implementation without a config schema may accept only the empty object.
type DeliveryResult ¶
type DeliveryResult string
DeliveryResult distinguishes accepted items from legal best-effort drops.
const ( Delivered DeliveryResult = "delivered" Dropped DeliveryResult = "dropped" )
type Dependency ¶
type Dependency struct {
Name string `json:"name" yaml:"name"`
Optional bool `json:"optional,omitempty" yaml:"optional,omitempty"`
}
Dependency is a service or coeffect required while an element is mounted.
type Descriptor ¶
type Descriptor struct {
FormatVersion uint64 `json:"format_version" yaml:"format_version"`
Name string `json:"name" yaml:"name"`
Revision uint64 `json:"revision" yaml:"revision"`
Generics []string `json:"generics,omitempty" yaml:"generics,omitempty"`
Ports []Port `json:"ports" yaml:"ports"`
Reaction Reaction `json:"reaction,omitempty" yaml:"reaction,omitempty"`
StateSchema string `json:"state_schema,omitempty" yaml:"state_schema,omitempty"`
// StateTransfer is nil for schema-only state. Its optional representation
// keeps descriptors authored before this contract byte-for-byte and
// digest-compatible while making transfer support an explicit opt-in.
StateTransfer *StateTransferCapabilities `json:"state_transfer,omitempty" yaml:"state_transfer,omitempty"`
ConfigSchema string `json:"config_schema,omitempty" yaml:"config_schema,omitempty"`
Dependencies []Dependency `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
Effects []Effect `json:"effects,omitempty" yaml:"effects,omitempty"`
// CompositeFingerprint is set only for a subgraph descriptor. It binds the
// exported contract identity to the exact frozen child Graph IR rather than
// allowing a body change behind an unchanged boundary signature.
CompositeFingerprint string `json:"composite_fingerprint,omitempty" yaml:"composite_fingerprint,omitempty"`
}
Descriptor is the immutable, language-neutral composition contract of an element implementation. Human graph source refers to Name only; a generated lockfile and Graph IR retain Revision and Digest.
func (Descriptor) Canonical ¶
func (descriptor Descriptor) Canonical() (Descriptor, error)
Canonical returns a validated, recursively independent descriptor with all declaration-order-insensitive collections sorted. It is useful when a runtime verifies that Graph IR did not alter the contract behind a digest.
func (Descriptor) Clone ¶
func (descriptor Descriptor) Clone() Descriptor
Clone returns a recursively independent descriptor. Catalogs use this to preserve the immutability promised by descriptor identities even when a caller later reuses or mutates its construction slices.
func (Descriptor) Digest ¶
func (descriptor Descriptor) Digest() (string, error)
Digest returns a deterministic content digest for a valid descriptor.
func (Descriptor) Identity ¶
func (descriptor Descriptor) Identity() (Identity, error)
Identity returns the exact, content-addressed descriptor identity.
func (Descriptor) Port ¶
func (descriptor Descriptor) Port(name string) (Port, bool)
Port returns the named port.
func (Descriptor) Validate ¶
func (descriptor Descriptor) Validate() error
Validate checks a complete descriptor without consulting a registry.
type Direction ¶
type Direction string
Direction is the direction of a port relative to its element.
type Effect ¶
type Effect struct {
Name string `json:"name" yaml:"name"`
External bool `json:"external,omitempty" yaml:"external,omitempty"`
Authority string `json:"authority,omitempty" yaml:"authority,omitempty"`
Reversible bool `json:"reversible,omitempty" yaml:"reversible,omitempty"`
}
Effect is a lifecycle-owned registration/resource or an external authority the element may request. External effects are not claimed to be reversible.
type Envelope ¶
type Envelope struct {
Type Type `json:"type"`
ItemID string `json:"item_id"`
SessionID string `json:"session_id,omitempty"`
SourceID string `json:"source_id,omitempty"`
OpportunityID string `json:"opportunity_id,omitempty"`
RunID string `json:"run_id,omitempty"`
Sequence uint64 `json:"sequence,omitempty"`
CaptureNS uint64 `json:"capture_ns,omitempty"`
ReceiveNS uint64 `json:"receive_ns,omitempty"`
TraceID string `json:"trace_id,omitempty"`
CancellationScope string `json:"cancellation_scope,omitempty"`
CausalParents []string `json:"causal_parents,omitempty"`
Payload any `json:"-"`
}
Envelope is the common immutable runtime wrapper for typed graph items. Large payloads should be immutable handles or reference-counted media rather than mutable buffers copied through every edge.
func (Envelope) Clone ¶
Clone copies envelope metadata. Payload remains shared by design and must obey the immutable payload contract.
func (Envelope) ValidateFor ¶
ValidateFor verifies the identity and concrete edge type before enqueue.
type Factory ¶
type Factory interface {
Descriptor() Descriptor
Mount(context.Context, MountContext) (Runnable, error)
}
Factory mounts one implementation of an immutable descriptor. Mount must not start unsupervised work; long-lived activity belongs in Runnable.Run.
type Identity ¶
type Identity struct {
Name string `json:"name" yaml:"name"`
Revision uint64 `json:"revision" yaml:"revision"`
Digest string `json:"digest" yaml:"digest"`
}
Identity is the exact descriptor selected by resolution.
type InputPort ¶
type InputPort interface {
Name() string
Type() Type
Lanes() []Receiver
Receive(context.Context) (Envelope, error)
ReceiveAny(context.Context) (Envelope, string, error)
}
InputPort owns zero or more input lanes. Receive is valid for a singular connected port; ReceiveAny performs fair arbitration over a variadic group.
type InspectionCauseKind ¶
type InspectionCauseKind string
InspectionCauseKind is the closed semantic vocabulary that a typed payload may contribute to payload-free causal inspection. Queue traversal, trigger timing, and authority decisions are already retained independently; these four values identify the semantic work that happened between those runtime boundaries without exposing request, provider, or model content.
const ( CauseObservation InspectionCauseKind = "observation" CauseStateRevision InspectionCauseKind = "state_revision" CausePolicy InspectionCauseKind = "policy" CauseModelRun InspectionCauseKind = "model_run" )
func SupportedInspectionCauseKinds ¶
func SupportedInspectionCauseKinds() []InspectionCauseKind
SupportedInspectionCauseKinds returns an independent copy of the exact semantic-causality vocabulary used by runtime and presentation validators.
func (InspectionCauseKind) Validate ¶
func (kind InspectionCauseKind) Validate() error
Validate rejects free-form classifications that could smuggle payload or provider data into an inspection snapshot.
type InspectionCauseProvider ¶
type InspectionCauseProvider interface {
InspectionCause() InspectionCauseKind
}
InspectionCauseProvider is implemented only by typed payloads that can project one closed semantic classification. A payload that has no such projection remains unclassified; the runtime rejects invalid projections.
type InspectionDecision ¶
type InspectionDecision struct {
Kind InspectionDecisionKind
Operation InspectionDecisionOperation
Crossed bool
}
InspectionDecision is the complete authority-decision projection that an element may offer to the runtime. Crossed states whether an irreversible effect boundary had already been crossed when the outcome was produced.
func (InspectionDecision) Validate ¶
func (decision InspectionDecision) Validate() error
type InspectionDecisionKind ¶
type InspectionDecisionKind string
InspectionDecisionKind is a closed, payload-free authority outcome class. It intentionally carries no call, run, session, provider, or message value.
const ( DecisionSucceeded InspectionDecisionKind = "succeeded" DecisionRejected InspectionDecisionKind = "rejected" DecisionDenied InspectionDecisionKind = "denied" DecisionCanceled InspectionDecisionKind = "canceled" DecisionTimedOut InspectionDecisionKind = "timed_out" DecisionFailed InspectionDecisionKind = "failed" DecisionIgnored InspectionDecisionKind = "ignored" )
func SupportedInspectionDecisionKinds ¶
func SupportedInspectionDecisionKinds() []InspectionDecisionKind
SupportedInspectionDecisionKinds returns an independent copy of the exact closed outcome vocabulary used by runtime and presentation validators.
type InspectionDecisionOperation ¶
type InspectionDecisionOperation string
InspectionDecisionOperation is the closed action-policy operation vocabulary admitted to live inspection and trace artifacts. Keeping this vocabulary closed prevents an element from smuggling request content into evidence.
const ( DecisionAccepted InspectionDecisionOperation = "accepted" DecisionAction InspectionDecisionOperation = "action" DecisionAdmit InspectionDecisionOperation = "admit" DecisionAlreadyCommitted InspectionDecisionOperation = "already_committed" DecisionAttest InspectionDecisionOperation = "attest" DecisionAuthorize InspectionDecisionOperation = "authorize" DecisionCancel InspectionDecisionOperation = "cancel" DecisionCandidate InspectionDecisionOperation = "candidate" DecisionCommit InspectionDecisionOperation = "commit" DecisionCommitted InspectionDecisionOperation = "committed" DecisionComplete InspectionDecisionOperation = "complete" DecisionConfirm InspectionDecisionOperation = "confirm" DecisionContext InspectionDecisionOperation = "context" DecisionExecute InspectionDecisionOperation = "execute" DecisionFence InspectionDecisionOperation = "fence" DecisionJoin InspectionDecisionOperation = "join" DecisionLookup InspectionDecisionOperation = "lookup" DecisionNormalize InspectionDecisionOperation = "normalize" DecisionPrepare InspectionDecisionOperation = "prepare" DecisionPromote InspectionDecisionOperation = "promote" DecisionProposal InspectionDecisionOperation = "proposal" DecisionProvenance InspectionDecisionOperation = "provenance" DecisionQueue InspectionDecisionOperation = "queue" DecisionResult InspectionDecisionOperation = "result" DecisionRejection InspectionDecisionOperation = "rejected" DecisionRetry InspectionDecisionOperation = "retry" DecisionSelect InspectionDecisionOperation = "select" DecisionTimeout InspectionDecisionOperation = "timeout" )
func SupportedInspectionDecisionOperations ¶
func SupportedInspectionDecisionOperations() []InspectionDecisionOperation
SupportedInspectionDecisionOperations returns an independent copy of the exact closed action-policy operation vocabulary.
type InspectionDecisionProvider ¶
type InspectionDecisionProvider interface {
InspectionDecision() InspectionDecision
}
InspectionDecisionProvider is implemented only by typed payloads that can project a closed, payload-free authority outcome. The runtime validates the returned value and ignores invalid or arbitrary payloads.
type Lifecycle ¶
type Lifecycle interface {
Defer(name string, dispose func(context.Context) error) error
Do(name string, work func(context.Context) error) error
Go(name string, worker func(context.Context) error) error
}
Lifecycle owns mount-time registrations, caller-blocking work, and background workers. Defer registers a bounded disposer that runs in reverse order on unmount. Do runs work in the caller while making it visible to lifecycle cancellation and join; Go starts the same kind of owned work in a supervised goroutine. Worker names are unique within one mount lifecycle.
type MountContext ¶
type MountContext struct {
InstanceID string
Identity Identity
Config json.RawMessage
Ports Ports
Services Services
Lifecycle Lifecycle
State StateLifecycle
Resolution ResolutionReporter
}
MountContext is the complete, scoped environment of one element instance.
type OutputPort ¶
type OutputPort interface {
Name() string
Type() Type
Lanes() []Sender
Broadcast(context.Context, Envelope) (SendResult, error)
}
OutputPort owns zero or more output lanes. Broadcast is atomic across all lossless lanes with respect to bounded-capacity admission; best-effort lanes may independently drop when full.
type Port ¶
type Port struct {
Name string `json:"name" yaml:"name"`
Direction Direction `json:"direction" yaml:"direction"`
Type Type `json:"type" yaml:"type"`
Cardinality Cardinality `json:"cardinality" yaml:"cardinality"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
MinConnections int `json:"min_connections,omitempty" yaml:"min_connections,omitempty"`
LossAllowed bool `json:"loss_allowed,omitempty" yaml:"loss_allowed,omitempty"`
DefaultDepth int `json:"default_depth,omitempty" yaml:"default_depth,omitempty"`
}
Port is one typed observation or action boundary of an element.
type Ports ¶
type Ports interface {
Input(name string) (InputPort, error)
Output(name string) (OutputPort, error)
}
Ports exposes only the connections declared for one instance.
type Reaction ¶
type Reaction struct {
Triggers []string `json:"triggers,omitempty" yaml:"triggers,omitempty"`
SampledState []string `json:"sampled_state,omitempty" yaml:"sampled_state,omitempty"`
Interrupts []string `json:"interrupts,omitempty" yaml:"interrupts,omitempty"`
Outcomes []string `json:"outcomes,omitempty" yaml:"outcomes,omitempty"`
MaxConcurrency int `json:"max_concurrency,omitempty" yaml:"max_concurrency,omitempty"`
// BreaksCycles declares that this reaction provides an explicit causal
// break (for example a seeded State or Delay) and can therefore make
// progress without first consuming the graph cycle it participates in.
BreaksCycles bool `json:"breaks_cycles,omitempty" yaml:"breaks_cycles,omitempty"`
}
Reaction describes activation independently of payload type. Context/state ports can update without appearing in Triggers; an interrupt is visible and addressed rather than a hidden method call.
type ResolutionReporter ¶
type ResolutionReporter interface {
Runtime(artifactID, revision, digest string) error
Capabilities([]CapabilityResolution) error
}
ResolutionReporter publishes immutable live runtime/provider selection to the management plane. Elements call it only after a real startup handshake or provider construction; deployment declarations are not live evidence. An empty capability list is a complete, attested statement that the node selected no provider capabilities.
type Runnable ¶
Runnable owns the long-lived reaction loop of one mounted element. It must return promptly after ctx is cancelled and must not retain port handles after unmount.
type RunnableFunc ¶
type SendResult ¶
SendResult summarizes one fan-out operation.
type Sender ¶
type Sender interface {
ID() string
Type() Type
Send(context.Context, Envelope) (DeliveryResult, error)
}
Sender is one concrete output lane.
type Services ¶
Services resolves lifecycle coeffects without conflating them with data or control ports.
type StateLifecycle ¶
type StateLifecycle interface {
Restored() (snapshot json.RawMessage, available bool, err error)
Quiesce(StateQuiescer) error
Snapshot(StateSnapshotter) error
}
StateLifecycle is present only when the immutable descriptor explicitly declares StateTransfer capabilities. Restored may be consumed once while mounting when restore is declared. Snapshot and Quiesce register at most one callback each before Factory.Mount returns and only when their corresponding capabilities are declared. A StateSchema alone does not grant or imply any live-transfer operation.
type StateQuiescer ¶
type StateQuiescer func(context.Context) (StateResumer, error)
StateQuiescer closes mutation admission and drains already-admitted mutations before a snapshot. A successful reconciliation retires the quiesced lifecycle; refusal invokes the returned resumer.
type StateResumer ¶
StateResumer reopens mutation admission after a state capture is refused before lifecycle teardown. It must be idempotent and honor its context.
type StateSnapshotter ¶
type StateSnapshotter func(context.Context) (json.RawMessage, error)
StateSnapshotter returns one bounded strict-JSON object representing the complete restorable state of an element instance. Snapshot payloads remain private to graph reconciliation and are never inspection-plane evidence.
type StateTransferCapabilities ¶
type StateTransferCapabilities struct {
Snapshot bool `json:"snapshot,omitempty" yaml:"snapshot,omitempty"`
Restore bool `json:"restore,omitempty" yaml:"restore,omitempty"`
Quiesce bool `json:"quiesce,omitempty" yaml:"quiesce,omitempty"`
}
StateTransferCapabilities declares which state-transfer lifecycle operations an element implementation supports. It is intentionally separate from StateSchema: a schema describes state bytes, but does not imply that an implementation can safely capture, restore, or quiesce that state.
Snapshot and Restore are independent because a predecessor and candidate may have asymmetric roles in an explicitly migrated transition. Quiesce requires Snapshot because stopping mutation without capturing state is not a state transfer capability.
func (*StateTransferCapabilities) Clone ¶
func (capabilities *StateTransferCapabilities) Clone() *StateTransferCapabilities
Clone returns an independently owned optional capability contract.
func (StateTransferCapabilities) Validate ¶
func (capabilities StateTransferCapabilities) Validate() error
Validate rejects an empty or internally contradictory capability contract. The owning descriptor or Graph IR node separately verifies StateSchema.
type Type ¶
type Type struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Arguments []Type `json:"arguments,omitempty" yaml:"arguments,omitempty"`
Variable string `json:"variable,omitempty" yaml:"variable,omitempty"`
}
Type is a structural graph-port type.
A concrete type has a Name and optional Arguments. A type variable has only Variable set. Variables are scoped to one element instance by the graph elaborator, so two instances that both declare T do not accidentally share an inference variable.
Examples:
Type{Name: "Event", Arguments: []Type{{Name: "interaction.TurnEnd"}}}
Type{Name: "Segmented", Arguments: []Type{{Name: "text.Delta"}, {Name: "flow.RunID"}}}
Type{Variable: "T"}
func State ¶
State is latest-value state sampled by reactions. Updating it does not, by itself, create a reaction.
func Stream ¶
Stream is the protocol type for an ordered sequence of independently meaningful items.
func (Type) ContainsVariable ¶
ContainsVariable reports whether this expression still needs inference.
func (Type) IsProtocol ¶
IsProtocol reports whether the outer type is one of the temporal protocol families understood by the graph kernel.
func (Type) IsVariable ¶
IsVariable reports whether the type is a generic variable.
func (Type) Validate ¶
Validate checks that the expression is well formed and that every variable is declared by the surrounding descriptor.
func (Type) ValidateConcretePort ¶
ValidateConcretePort checks a fully elaborated port type.
func (Type) ValidatePort ¶
ValidatePort checks that a descriptor port has one temporal protocol at its root. A generic connector may use a root variable and infer the complete protocol from its neighbors; ordinary concrete ports may not omit temporal semantics.