Documentation
¶
Overview ¶
Package attachadapter bridges a mast serve-daemon session into pkg/attach's Registrant contract, so operator frontends (mast-web) can list, tail, and inject into sessions over the attach protocol.
One Adapter represents one ADK session triple. All adapters in a daemon share the daemon's eventlog handle — attach's broadcaster filters the stream per session. Construction is explicit (attachadapter.New with a Config); the daemon registers the result on an attach.SessionRegistry.
Index ¶
- type Adapter
- func (ad *Adapter) AppName() string
- func (ad *Adapter) AttachInterrupt() bool
- func (ad *Adapter) AttachStatus() attach.StatusInfo
- func (ad *Adapter) AttachTools() []attach.ToolInfo
- func (ad *Adapter) AttachUsage() attach.UsageInfo
- func (ad *Adapter) AuditsInterrupts()
- func (ad *Adapter) Description() string
- func (ad *Adapter) EventLog() *eventlog.Handle
- func (ad *Adapter) Inject(message string) error
- func (ad *Adapter) InjectAs(message string, caller auth.Caller) error
- func (ad *Adapter) RequestWake()
- func (ad *Adapter) SessionID() string
- func (ad *Adapter) SetOperatorEventEmitter(f func(eventType string, payload any))
- func (ad *Adapter) UserID() string
- type Config
- type TurnResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements attach.Registrant plus the optional capability interfaces mast's daemon can honestly serve: StatusProvider, UsageProvider, ToolsProvider, InterruptProvider, DescriptionProvider, and OperatorEventTarget.
func (*Adapter) AttachInterrupt ¶
AttachInterrupt implements attach.InterruptProvider: cancel the in-flight turn's context. Returns false when no turn is running. Queued messages are NOT discarded — the next one still runs, same as core-agent's interrupt (which stops the turn, not the agent).
func (*Adapter) AttachStatus ¶
func (ad *Adapter) AttachStatus() attach.StatusInfo
AttachStatus implements attach.StatusProvider.
func (*Adapter) AttachTools ¶
AttachTools implements attach.ToolsProvider. Empty when no ToolsFn is wired.
func (*Adapter) AttachUsage ¶
AttachUsage implements attach.UsageProvider. Zero UsageInfo when no UsageFn is wired.
func (*Adapter) AuditsInterrupts ¶ added in v0.1.2
func (ad *Adapter) AuditsInterrupts()
AuditsInterrupts implements attach.InterruptSelfAuditor (a capability marker, never called for effect): this adapter records the operator-interrupt audit event from its own turn loop, so the protocol layer's fallback append — which would stale the unwinding turn's session handle — is suppressed.
func (*Adapter) Description ¶
Description implements attach.DescriptionProvider.
func (*Adapter) Inject ¶
Inject implements attach.Registrant: queue a message and run it as its own turn once earlier queued messages finish. Unlike core-agent's inbox (whose agent loop drains the whole batch into one turn), mast maps one injected message to one turn — the daemon has no long-lived loop to batch for.
func (*Adapter) InjectAs ¶
InjectAs implements attach.Registrant. The caller rides the turn context (auth.WithCaller) so the eventlog metadata extractor and any caller-aware substrate see who triggered the turn.
func (*Adapter) RequestWake ¶
func (ad *Adapter) RequestWake()
RequestWake implements attach.Registrant. Core-agent's wake signal re-checks an idle agent loop's inbox; mast's daemon runs turns on demand, so wake only kicks the drainer in case a message is queued with no drainer running (a state that shouldn't occur — this is belt-and-braces, not a scheduler).
func (*Adapter) SetOperatorEventEmitter ¶
SetOperatorEventEmitter implements attach.OperatorEventTarget: the broadcaster installs the typed-event callback at first-subscriber time and clears it (f == nil) when the last subscriber disconnects.
type Config ¶
type Config struct {
// AppName / UserID / SessionID form the ADK session key —
// attach uses (AppName, SessionID) for URL lookup and the
// broadcaster uses all three to filter the eventlog stream.
AppName string
UserID string
SessionID string
// EventLog is the daemon-wide eventlog handle. Attach requires
// it for live-tail (the broadcaster pumps from Stream.Watch).
EventLog *eventlog.Handle
// RunTurn executes one turn for this session: append message as
// user content, drive the runner until the turn completes, and
// return what is known about the turn's token usage. The
// adapter guarantees calls are serialized per session. ctx is
// canceled when an operator interrupts the turn (POST
// /interrupt) or the daemon shuts down.
RunTurn func(ctx context.Context, message string) (TurnResult, error)
// BaseContext bounds every turn this adapter runs; defaults to
// context.Background(). Pass the daemon's serve context so
// in-flight turns die with the process's graceful shutdown.
BaseContext context.Context
// ModelName, when set, is reported on status frames.
ModelName string
// Description, when set, feeds the agent card + session list.
Description string
// UsageFn, when set, supplies the GET /sessions/.../usage
// snapshot (typically from the session's budget meter). Nil
// reports zero usage rather than 501 — same behavior as a
// core-agent registrant with an empty tracker.
UsageFn func() attach.UsageInfo
// ToolsFn, when set, supplies GET /sessions/.../tools (typically
// the workload bundle's tool catalog). Nil reports an empty list.
ToolsFn func() []attach.ToolInfo
}
Config wires an Adapter to one session's turn machinery. AppName, UserID, SessionID, EventLog, and RunTurn are required.
type TurnResult ¶
TurnResult carries what the daemon's turn runner knows about a finished turn. Zero values are honest "unknown" — the terminal turn-complete event reports them as-is and authoritative cost arrives via the usage snapshot (UsageFn), matching the attach spec's "cost deferred" wire semantics.