Documentation
¶
Overview ¶
Package adapter translates pi runtime (ADK) events into ACP session updates.
The adapter is the single place where ACP protocol concerns touch the pi runtime, so the runtime can stay acp-agnostic. Stream owns per-turn state: text accumulation, tool-call tracking, and sub-agent nesting.
This file ships the text and thought paths; tool-call lifecycle lives in toolcall.go. The runtime rewrite in Zed-08 wires these together.
Index ¶
- func BuildAvailableCommands(skills []extension.Skill, subagents []subagent.AgentConfig) []acp.AvailableCommand
- type SessionUpdater
- type Stream
- func (s *Stream) Final() string
- func (s *Stream) OnEvent(ctx context.Context, ev *adksession.Event) error
- func (s *Stream) OnToolEnd(ctx context.Context, callID string, args map[string]any, result any, ...) error
- func (s *Stream) OnToolStart(ctx context.Context, name string, args map[string]any) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAvailableCommands ¶
func BuildAvailableCommands(skills []extension.Skill, subagents []subagent.AgentConfig) []acp.AvailableCommand
BuildAvailableCommands assembles the slash-command list advertised in InitializeResponse.AvailableCommands. The result is the concatenation of meta commands, one entry per discovered skill, and one per discovered sub-agent — in that order. Input order within each group is preserved because discovery is already deterministic (project > user > bundled).
Wiring into Initialize is Zed-09's responsibility; this function is pure so it can be unit-tested without spinning up an ACP server.
Types ¶
type SessionUpdater ¶
type SessionUpdater interface {
Update(ctx context.Context, update acp.SessionUpdate) error
}
SessionUpdater streams session updates back to the ACP peer. A nil Updater silently discards updates so the adapter is usable in tests without a live connection.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream holds per-turn state for a single ACP prompt turn. mu guards all state mutations (toolCalls map, nextCallSeq, subagentID, finalText).
The ADK invokes BeforeToolCallbacks from concurrent goroutines (one per parallel tool call). Top-level tool start/end Updates are sent after mu is released so concurrent tool calls do not serialize on the protocol write; nested (sub-agent child) Updates intentionally hold mu to preserve content line-ordering on the parent card.
func New ¶
func New(u SessionUpdater) *Stream
New constructs a Stream that emits updates through u. A nil updater is accepted and results in updates being discarded — useful for tests that only care about Final().
func (*Stream) Final ¶
Final returns the accumulated assistant text with surrounding whitespace trimmed. Safe to call multiple times; always reflects the latest state.
func (*Stream) OnEvent ¶
OnEvent consumes one ADK event and forwards its parts to the peer.
Rules:
- Nil event or nil content: no-op.
- User-role events are ignored; the ACP peer already knows the prompt.
- Thought parts (part.Thought == true) emit agent_thought_chunk and are kept out of the assistant message accumulator.
- Function-call and function-response parts are skipped — Zed-04 emits them via Before/AfterToolCallbacks.
- Plain text parts are streamed as agent_message_chunk and accumulated into finalText.
Text accumulation happens under mu; Update() calls are made after releasing mu so a concurrent tool callback does not block on event emission.
func (*Stream) OnToolEnd ¶
func (s *Stream) OnToolEnd(ctx context.Context, callID string, args map[string]any, result any, runErr error) error
OnToolEnd emits the terminal SessionUpdate for callID. Unknown ids are a no-op so the adapter tolerates a dropped/filtered start without surfacing a protocol error; the call simply never materializes in Zed.
Like OnToolStart, the lock is released before network I/O for top-level calls and held through the write for nested calls.
func (*Stream) OnToolStart ¶
OnToolStart records a new tool invocation and emits the initial SessionUpdate for it. The returned call id pairs this start with its later OnToolEnd — the runtime bridge (Zed-08) threads it through the ADK Before/After tool callbacks.
When the tool is a sub-agent dispatch, the call is marked as the active parent: subsequent tool starts fold their progress into the parent's content instead of creating new top-level cards. Nesting is single-level — a sub-agent spawned inside another sub-agent is treated as a plain nested call.
The mutex is held only for state mutations. Top-level tool updates are sent after unlock so concurrent parallel tool calls do not serialize on the protocol write. Nested (sub-agent child) updates keep the lock during the write to preserve content line-ordering on the parent card.