pkg/ezagentapi/server_outbound.go

package ezagentapi

import (
	"context"

	"git.cafe/ezterry/ez-agent/pkg/protocol"
)

func (c *Conn) SendCwdUpdated(ctx context.Context, cwd, leafID, requestID string) error {
	return c.sendFrame(ctx, protocol.CwdUpdated{Type: "cwd_updated", Cwd: cwd, LeafID: leafID, RequestID: requestID})
}

func (c *Conn) SendCwdList(ctx context.Context, cwds []string, requestID string) error {
	return c.sendFrame(ctx, protocol.CwdList{Type: "cwd_list", Cwds: cwds, RequestID: requestID})
}

// SendCwdListWithInfos includes activity summaries aligned with cwds.
func (c *Conn) SendCwdListWithInfos(ctx context.Context, cwds []string, infos []protocol.CwdInfo, requestID string) error {
	return c.sendFrame(ctx, protocol.CwdList{Type: "cwd_list", Cwds: cwds, CwdInfos: infos, RequestID: requestID})
}

func (c *Conn) SendLeafCreated(ctx context.Context, rootID, leafID, model string, isTemp bool, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafCreated{Type: "leaf_created", RootID: rootID, LeafID: leafID, Model: model, IsTemp: isTemp, RequestID: requestID})
}

func (c *Conn) SendLeafConfigValue(ctx context.Context, key, value, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafConfigValue{Type: "leaf_config_value", Key: key, Value: value, RequestID: requestID})
}

func (c *Conn) SendLeafConfigSet(ctx context.Context, key, value, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafConfigSet{Type: "leaf_config_set", Key: key, Value: value, RequestID: requestID})
}

func (c *Conn) SendLeafConfigDeleted(ctx context.Context, key, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafConfigDeleted{Type: "leaf_config_deleted", Key: key, RequestID: requestID})
}

func (c *Conn) SendLeafConfigList(ctx context.Context, entries []protocol.LeafConfigListEntry, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafConfigList{Type: "leaf_config_list", Configs: entries, RequestID: requestID})
}

func (c *Conn) SendLeafDeleted(ctx context.Context, leafID, turnID, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafDeleted{Type: "leaf_deleted", LeafID: leafID, TurnID: turnID, RequestID: requestID})
}

func (c *Conn) SendLeafRewound(ctx context.Context, leafID, oldTipTurnID, newTipTurnID string, replay bool, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafRewound{
		Type: "leaf_rewound", LeafID: leafID, OldTipTurnID: oldTipTurnID,
		NewTipTurnID: newTipTurnID, Replay: replay, RequestID: requestID,
	})
}

func (c *Conn) SendLeafRenamed(ctx context.Context, leafID, name, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafRenamed{Type: "leaf_renamed", LeafID: leafID, Name: name, RequestID: requestID})
}

func (c *Conn) SendLeafSwitched(ctx context.Context, leafID, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafSwitched{Type: "leaf_switched", LeafID: leafID, RequestID: requestID})
}

func (c *Conn) SendLeafList(ctx context.Context, leaves []protocol.LeafInfo, requestID string) error {
	return c.sendFrame(ctx, protocol.LeafList{Type: "leaf_list", Leaves: leaves, RequestID: requestID})
}

func (c *Conn) SendLeafStats(ctx context.Context, stats protocol.LeafStatsResponse, requestID string) error {
	stats.Type = "leaf_stats_response"
	stats.RequestID = requestID
	return c.sendFrame(ctx, stats)
}

func (c *Conn) SendHistoryList(ctx context.Context, leafID, tipTurnID string, turns []protocol.TurnSummary, requestID string) error {
	return c.sendFrame(ctx, protocol.HistoryList{Type: "history_list", LeafID: leafID, TipTurnID: tipTurnID, Turns: turns, RequestID: requestID})
}

func (c *Conn) SendTurnTreeList(ctx context.Context, rootID string, turns []protocol.TurnTreeNode, requestID string) error {
	return c.sendFrame(ctx, protocol.TurnTreeList{Type: "turn_tree_list", RootID: rootID, Turns: turns, RequestID: requestID})
}

func (c *Conn) SendToolList(ctx context.Context, tools []string, requestID string) error {
	return c.sendFrame(ctx, protocol.ToolList{Type: "tool_list", Tools: tools, RequestID: requestID})
}

func (c *Conn) SendToolInfoValue(ctx context.Context, tools []protocol.ToolInfo, requestID string) error {
	return c.sendFrame(ctx, protocol.ToolInfoValue{Type: "tool_info", Tools: tools, RequestID: requestID})
}

func (c *Conn) SendToolAdded(ctx context.Context, leafID, toolName, requestID string) error {
	return c.sendFrame(ctx, protocol.ToolAdded{Type: "tool_added", LeafID: leafID, ToolName: toolName, RequestID: requestID})
}

func (c *Conn) SendToolRemoved(ctx context.Context, leafID, toolName, requestID string) error {
	return c.sendFrame(ctx, protocol.ToolRemoved{Type: "tool_removed", LeafID: leafID, ToolName: toolName, RequestID: requestID})
}

func (c *Conn) SendPluginList(ctx context.Context, plugins []string, requestID string) error {
	return c.sendFrame(ctx, protocol.PluginList{Type: "plugin_list", Plugins: plugins, RequestID: requestID})
}

func (c *Conn) SendMacroList(ctx context.Context, macros []protocol.MacroInfo, requestID string) error {
	return c.sendFrame(ctx, protocol.MacroList{Type: "macro_list", Macros: macros, RequestID: requestID})
}

func (c *Conn) SendMacroCallResult(ctx context.Context, result protocol.MacroResult, requestID string) error {
	result.Type = "macro_result"
	result.RequestID = requestID
	return c.sendFrame(ctx, result)
}

func (c *Conn) SendModelList(ctx context.Context, models []protocol.ModelEntry, requestID string) error {
	return c.sendFrame(ctx, protocol.ModelList{Type: "model_list", Models: models, RequestID: requestID})
}

func (c *Conn) SendModelSet(ctx context.Context, leafID, model, thinkingLevel, requestID string) error {
	return c.sendFrame(ctx, protocol.ModelSet{Type: "model_set", LeafID: leafID, Model: model, ThinkingLevel: thinkingLevel, RequestID: requestID})
}

func (c *Conn) SendThinkingLevelSet(ctx context.Context, leafID, level, requestID string) error {
	return c.sendFrame(ctx, protocol.ThinkingLevelSet{Type: "thinking_level_set", LeafID: leafID, Level: level, RequestID: requestID})
}

func (c *Conn) SendProviderList(ctx context.Context, providers []protocol.ProviderListEntry, requestID string) error {
	return c.sendFrame(ctx, protocol.ProviderList{Type: "provider_list", Providers: providers, RequestID: requestID})
}

func (c *Conn) SendResolvedModels(ctx context.Context, models protocol.ResolvedModels, requestID string) error {
	models.Type = "resolved_models"
	models.RequestID = requestID
	return c.sendFrame(ctx, models)
}

func (c *Conn) SendEffectiveConfig(ctx context.Context, config protocol.EffectiveConfig, requestID string) error {
	config.Type = "effective_config"
	config.RequestID = requestID
	return c.sendFrame(ctx, config)
}

func (c *Conn) SendPromptAccepted(ctx context.Context, rootID, leafID string, turnIDs []string, tipTurnID, requestID string) error {
	return c.sendFrame(ctx, protocol.PromptAccepted{Type: "prompt_accepted", RootID: rootID, LeafID: leafID, TurnIDs: turnIDs, TipTurnID: tipTurnID, RequestID: requestID})
}

func (c *Conn) SendPromptCompleted(ctx context.Context, leafID, rootID, reason, message, requestID string) error {
	return c.sendFrame(ctx, protocol.PromptCompleted{Type: "prompt_completed", LeafID: leafID, RootID: rootID, Reason: reason, Message: message, RequestID: requestID})
}

func (c *Conn) SendVirtualRootCreated(ctx context.Context, rootID, leafID, model, requestID string) error {
	return c.sendFrame(ctx, protocol.VirtualRootCreated{Type: "virtual_root_created", RootID: rootID, LeafID: leafID, Model: model, RequestID: requestID})
}

func (c *Conn) SendVacuumResult(ctx context.Context, result protocol.VacuumResult, requestID string) error {
	result.Type = "vacuum_result"
	result.RequestID = requestID
	return c.sendFrame(ctx, result)
}

func (c *Conn) SendRootList(ctx context.Context, roots []protocol.RootInfo, requestID string) error {
	return c.sendFrame(ctx, protocol.RootList{Type: "root_list", Roots: roots, RequestID: requestID})
}

func (c *Conn) SendQueuedList(ctx context.Context, messages []protocol.QueuedMessage, requestID string) error {
	return c.sendFrame(ctx, protocol.QueuedList{Type: "queued_list", Messages: messages, RequestID: requestID})
}

func (c *Conn) SendConnectionList(ctx context.Context, conns []protocol.ConnectionListEntry, requestID string) error {
	return c.sendFrame(ctx, protocol.ConnectionList{Type: "connection_list", Connections: conns, RequestID: requestID})
}

func (c *Conn) SendSupportedFiletypes(ctx context.Context, requestID string) error {
	return c.sendFrame(ctx, protocol.SupportedFiletypesResponse{Type: "supported_filetypes_response", Filetypes: protocol.SupportedFiletypeGroups, RequestID: requestID})
}

func (c *Conn) SendFeedDropped(ctx context.Context, leafID, requestID string) error {
	return c.sendFrame(ctx, protocol.FeedDropped{Type: "feed_dropped", LeafID: leafID, RequestID: requestID})
}

func (c *Conn) SendLeafMetaUpdated(ctx context.Context, updated protocol.LeafMetaUpdated, requestID string) error {
	updated.Type = "leaf_meta_updated"
	updated.RequestID = requestID
	return c.sendFrame(ctx, updated)
}

func (c *Conn) SendAbortReceived(ctx context.Context, leafID, requestID string) error {
	return c.sendFrame(ctx, protocol.AbortReceived{Type: "abort_received", LeafID: leafID, RequestID: requestID})
}

func (c *Conn) SendSteerAccepted(ctx context.Context, leafID string, turnIDs []string, tipTurnID, requestID string) error {
	return c.sendFrame(ctx, protocol.SteerAccepted{Type: "steer_accepted", LeafID: leafID, TurnIDs: turnIDs, TipTurnID: tipTurnID, RequestID: requestID})
}

func (c *Conn) SendAgentStart(ctx context.Context, leafID string) error {
	return c.sendFrame(ctx, protocol.AgentStart{Type: "agent_start", LeafID: leafID})
}

func (c *Conn) SendAgentEnd(ctx context.Context, end protocol.AgentEnd) error {
	end.Type = "agent_end"
	return c.sendFrame(ctx, end)
}

func (c *Conn) SendTurnEnd(ctx context.Context, leafID, turnID string) error {
	return c.sendFrame(ctx, protocol.TurnEnd{Type: "turn_end", LeafID: leafID, TurnID: turnID})
}

func (c *Conn) SendTurnsSent(ctx context.Context, sent protocol.TurnsSent) error {
	sent.Type = "turns_sent"
	return c.sendFrame(ctx, sent)
}

func (c *Conn) SendTurnStart(ctx context.Context, leafID, turnID string) error {
	return c.sendFrame(ctx, protocol.TurnStart{Type: "turn_start", LeafID: leafID, TurnID: turnID})
}

func (c *Conn) SendMessageStart(ctx context.Context, leafID, turnID string, content []protocol.ContentBlock) error {
	return c.sendFrame(ctx, protocol.MessageStart{Type: "message_start", LeafID: leafID, TurnID: turnID, Message: protocol.Message{Role: "assistant", Content: content}})
}

func (c *Conn) SendMessageUpdate(ctx context.Context, leafID, turnID, deltaType string, delta protocol.TextDelta, offset int) error {
	return c.sendFrame(ctx, protocol.MessageUpdate{Type: "message_update", LeafID: leafID, TurnID: turnID, DeltaType: deltaType, Delta: delta, Offset: offset})
}

func (c *Conn) SendMessageEnd(ctx context.Context, leafID, turnID string, message protocol.Message) error {
	message.Role = "assistant"
	return c.sendFrame(ctx, protocol.MessageEnd{Type: "message_end", LeafID: leafID, TurnID: turnID, Message: message})
}

func (c *Conn) SendTurnContent(ctx context.Context, turn protocol.TurnContent) error {
	turn.Type = "turn_content"
	return c.sendFrame(ctx, turn)
}

func (c *Conn) SendAttachmentChunk(ctx context.Context, chunk protocol.AttachmentChunk) error {
	chunk.Type = "attachment_chunk"
	return c.sendFrame(ctx, chunk)
}

func (c *Conn) SendLeafUpdated(ctx context.Context, update protocol.LeafUpdated) error {
	update.Type = "leaf_updated"
	return c.sendFrame(ctx, update)
}

func (c *Conn) SendQuestionReplyAck(ctx context.Context, reply protocol.QuestionReply) error {
	return c.sendFrame(ctx, protocol.QuestionReplyAck{
		Type: "question_reply_ack", LeafID: reply.LeafID, Kind: reply.Kind,
		Revision: reply.Revision, Reply: reply.Reply, RequestID: reply.RequestID,
	})
}

func (c *Conn) SendInformational(ctx context.Context, info protocol.Informational) error {
	info.Type = "informational"
	return c.sendFrame(ctx, info)
}

func (c *Conn) SendShutdown(ctx context.Context, reason string) error {
	return c.sendFrame(ctx, protocol.Shutdown{Type: "shutdown", RequestID: reason})
}

func (c *Conn) SendLeafFilesResult(ctx context.Context, leafID, requestID string, file protocol.LeafFileDescriptor) error {
	return c.sendFrame(ctx, protocol.LeafFilesResult{Type: "leaf_files_result", Operation: "attach", LeafID: leafID, RequestID: requestID, File: file})
}