attachadapter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

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 New

func New(cfg Config) (*Adapter, error)

New validates cfg and returns an Adapter ready to Register on an attach.SessionRegistry.

func (*Adapter) AppName

func (ad *Adapter) AppName() string

AppName implements attach.Registrant.

func (*Adapter) AttachInterrupt

func (ad *Adapter) AttachInterrupt() bool

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

func (ad *Adapter) AttachTools() []attach.ToolInfo

AttachTools implements attach.ToolsProvider. Empty when no ToolsFn is wired.

func (*Adapter) AttachUsage

func (ad *Adapter) AttachUsage() attach.UsageInfo

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

func (ad *Adapter) Description() string

Description implements attach.DescriptionProvider.

func (*Adapter) EventLog

func (ad *Adapter) EventLog() *eventlog.Handle

EventLog implements attach.Registrant.

func (*Adapter) Inject

func (ad *Adapter) Inject(message string) error

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

func (ad *Adapter) InjectAs(message string, caller auth.Caller) error

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) SessionID

func (ad *Adapter) SessionID() string

SessionID implements attach.Registrant.

func (*Adapter) SetOperatorEventEmitter

func (ad *Adapter) SetOperatorEventEmitter(f func(eventType string, payload any))

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.

func (*Adapter) UserID

func (ad *Adapter) UserID() string

UserID implements attach.Registrant.

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

type TurnResult struct {
	TokensIn  int
	TokensOut int
}

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.

Jump to

Keyboard shortcuts

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