actions

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package actions 实现服务端的动作处理与消息路由

该包包含 prompt、session、update、初始化等服务器动作的处理逻辑

Index

Constants

This section is empty.

Variables

View Source
var AgentCapabilities = u.H{
	"loadSession": true,
	"promptCapabilities": u.H{
		"image":           false,
		"audio":           false,
		"embeddedContext": false,
	},
	"mcp":  false,
	"list": u.H{},
	"sessionCapabilities": u.H{
		"delete": u.H{},
	},
}

AgentCapabilities 服务端能力常量

View Source
var AgentInfo = u.H{
	"name":    "alkaid0",
	"title":   "Alkaid0",
	"version": product.Version,
}

AgentInfo 服务端信息常量

View Source
var ReasonMap = map[loop.StopReason]string{
	loop.StopReasonNone:        "end_turn",
	loop.StopReasonModel:       "end_turn",
	loop.StopReasonUser:        "cancelled",
	loop.StopReasonError:       "refusal",
	loop.StopReasonPendingTool: "end_turn",
}

ReasonMap 停止原因到字符串的映射

View Source
var ToolNameToTypeMap = map[string]string{
	"agent":            "other",
	"scope":            "other",
	"activate_agent":   "other",
	"deactivate_agent": "other",
	"edit":             "edit",
	"trace":            "read",
	"run":              "execute",
}

ToolNameToTypeMap 工具名称到类型的映射,用于规范化工具调用类型

Functions

func Close

func Close(req any, call func(string, any, *string) error, connID uint64) (any, error)

Close 关闭连接 连接断开后不会立即释放会话,而是启动延迟释放定时器 若在超时时间内有新的客户端重连,会话会继续正常运行

func ConfigSet added in v0.2.8

func ConfigSet(req ConfigSetRequest, _ func(string, any, *string) error, _ uint64) (any, error)

ConfigSet 写入配置并自动重载 接受完整的或部分的配置 JSON,通过 json.Unmarshal 合并到现有配置中 只有请求中显式指定的字段会被更新,未指定的字段保持现有值 保存后自动触发所有注册的重载钩子(配置广播推送等)

func FsChmod added in v0.2.6

func FsChmod(req FsChmodRequest, _ func(string, any, *string) error, _ uint64) (u.H, error)

FsChmod 更改文件权限

func FsChown added in v0.2.6

func FsChown(req FsChownRequest, _ func(string, any, *string) error, _ uint64) (u.H, error)

FsChown 更改文件所有者

func FsMkdir added in v0.2.6

func FsMkdir(req FsCommonRequest, _ func(string, any, *string) error, _ uint64) (u.H, error)

FsMkdir 递归创建目录

func FsRm added in v0.2.6

func FsRm(req FsCommonRequest, _ func(string, any, *string) error, _ uint64) (u.H, error)

FsRm 递归删除文件或目录

func GetStates added in v0.2.10

func GetStates(_ any) (any, error)

GetStates 获取状态

func InitFuncs

func InitFuncs(srv *jsonrpc.Server)

InitFuncs 初始化函数

func SessionCancel

func SessionCancel(req SessionCancelRequest, call func(string, any, *string) error, connID uint64) (any, error)

SessionCancel 处理 session/cancel 请求 取消正在进行的 prompt turn

func SessionDelete added in v0.2.5

func SessionDelete(req SessionDeleteRequest, call func(string, any, *string) error, connID uint64) (u.H, error)

SessionDelete 删除会话(ACP session/delete) 根据 ACP 规范:

  • 删除的会话不再出现在 session/list 结果中
  • 删除已删除或不存在的会话应静默成功
  • 返回空对象 {}

Types

type AgentTagsInfo

type AgentTagsInfo struct {
	Name        string `json:"name"`
	ID          string `json:"id"`
	ModelID     int32  `json:"modelId"`
	Color       string `json:"color"`
	AutoApprove string `json:"autoApproveExpr"`
	AutoReject  string `json:"autoRejectExpr"`
	Description string `json:"description"`
	Prompt      string `json:"prompt"`
	ShortPrompt string `json:"shortPrompt"`
}

AgentTagsInfo subagent tag 信息

type AgentsInfo

type AgentsInfo struct {
	Name string `json:"name"`
	Tag  string `json:"tag"`
	Path string `json:"path"`
}

AgentsInfo subagent 信息

type AvailableModel

type AvailableModel struct {
	ModelID string `json:"modelId"`
	Name    string `json:"name"`
	RealID  int32  `json:"alk.cxykevin.top/model_real_id"`
}

AvailableModel 可用的模型

type ConfigGetRequest added in v0.2.8

type ConfigGetRequest struct{}

ConfigGetRequest 获取配置的请求(无需参数)

type ConfigGetResponse added in v0.2.8

type ConfigGetResponse struct {
	Config *cfgStructs.Config `json:"config"`
}

ConfigGetResponse 获取配置的响应

func ConfigGet added in v0.2.8

func ConfigGet(_ ConfigGetRequest, _ func(string, any, *string) error, _ uint64) (ConfigGetResponse, error)

ConfigGet 返回完整的当前配置

type ConfigOption

type ConfigOption struct {
	ID           string              `json:"id"`
	Name         string              `json:"name"`
	Description  string              `json:"description,omitempty"`
	Category     string              `json:"category,omitempty"`
	Type         string              `json:"type"`
	CurrentValue string              `json:"currentValue"`
	Options      []ConfigOptionValue `json:"options"`
}

ConfigOption 配置选项

type ConfigOptionValue

type ConfigOptionValue struct {
	Value       string `json:"value"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	RealID      int32  `json:"alk.cxykevin.top/model_real_id"`
}

ConfigOptionValue 配置选项值

type ConfigSetRequest added in v0.2.8

type ConfigSetRequest struct {
	Config json.RawMessage `json:"config"`
}

ConfigSetRequest 设置配置的请求 Config 字段接受部分配置,未指定的字段保持现有值不变

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

ContentBlock 内容块

type FsChmodRequest added in v0.2.6

type FsChmodRequest struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	Mode      string `json:"mode"`
}

FsChmodRequest 更改权限的请求

type FsChownRequest added in v0.2.6

type FsChownRequest struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	Owner     string `json:"owner"`
}

FsChownRequest 更改所有者的请求

type FsCommonRequest added in v0.2.6

type FsCommonRequest struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
}

FsCommonRequest 通用的路径操作请求(stat, mkdir, rm)

type FsDirEntry added in v0.2.6

type FsDirEntry struct {
	Name string `json:"name"`
	Type string `json:"type"` // "file" | "directory"
	Size *int64 `json:"size,omitempty"`
}

FsDirEntry 目录条目

type FsReadRequest added in v0.2.6

type FsReadRequest struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	Binary    bool   `json:"binary,omitempty"`
	Offset    int64  `json:"offset,omitempty"`
	Length    int64  `json:"length,omitempty"`
}

FsReadRequest 读取文件/列出目录的请求

type FsReadResponse added in v0.2.6

type FsReadResponse struct {
	Content any `json:"content"` // string | []FsDirEntry
}

FsReadResponse 读取文件/列出目录的响应

func FsRead added in v0.2.6

func FsRead(req FsReadRequest, _ func(string, any, *string) error, _ uint64) (FsReadResponse, error)

FsRead 读取文件或列出目录。 sessionId 可选:

  • 设置 sessionId:仅接受相对路径,在会话工作目录内访问
  • 不设置 sessionId:仅接受绝对路径,不能访问 /etc 或 C:\ProgramData

type FsStatResponse added in v0.2.6

type FsStatResponse struct {
	Size        *int64 `json:"size,omitempty"`
	Permissions string `json:"permissions"`
	Owner       string `json:"owner"`
	Type        string `json:"type"` // "file" | "directory"
}

FsStatResponse stat 响应

func FsStat added in v0.2.6

func FsStat(req FsCommonRequest, _ func(string, any, *string) error, _ uint64) (FsStatResponse, error)

FsStat 获取文件/文件夹信息

type FsWriteRequest added in v0.2.6

type FsWriteRequest struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	Content   string `json:"content"`
	Binary    bool   `json:"binary,omitempty"`
	Append    bool   `json:"append,omitempty"`
}

FsWriteRequest 写文件的请求

type FsWriteResponse added in v0.2.6

type FsWriteResponse struct {
	BytesWritten int64 `json:"bytesWritten"`
}

FsWriteResponse 写文件的响应

func FsWrite added in v0.2.6

func FsWrite(req FsWriteRequest, _ func(string, any, *string) error, _ uint64) (FsWriteResponse, error)

FsWrite 写文件(不存在则创建,支持追加模式)

type InitializeRequest

type InitializeRequest struct {
	ProtocolVersion    int `json:"protocolVersion"`
	ClientCapabilities u.H `json:"clientCapabilities"`
	ClientInfo         struct {
		Name    string `json:"name"`
		Title   string `json:"title"`
		Version string `json:"version"`
	} `json:"clientInfo"`
}

InitializeRequest 初始化请求

type InitializeResponse

type InitializeResponse struct {
	ProtocolVersion   int   `json:"protocolVersion"`
	AgentCapabilities u.H   `json:"agentCapabilities"`
	AgentInfo         u.H   `json:"agentInfo"`
	AuthMethods       []u.H `json:"authMethods"`
}

InitializeResponse 初始化响应

func Initialize

func Initialize(req InitializeRequest, call func(string, any, *string) error, connID uint64) (InitializeResponse, error)

Initialize 初始化

type ModelConfig

type ModelConfig struct {
	CurrentModelID  string           `json:"currentModelId"`
	AvailableModels []AvailableModel `json:"availableModels"`
}

ModelConfig 模型配置

type SessionCancelRequest

type SessionCancelRequest struct {
	SessionID string `json:"sessionId"`
}

SessionCancelRequest session 取消请求

type SessionDeleteRequest added in v0.2.5

type SessionDeleteRequest struct {
	SessionID string `json:"sessionId"`
}

SessionDeleteRequest 删除会话的请求

type SessionGetBackgroundRequest added in v0.2.8

type SessionGetBackgroundRequest struct {
	SessionID string `json:"sessionId"`
}

SessionGetBackgroundRequest 获取后台模式状态的请求

type SessionGetBackgroundResponse added in v0.2.8

type SessionGetBackgroundResponse struct {
	Background bool `json:"background"`
}

SessionGetBackgroundResponse 获取后台模式状态的响应

func SessionGetBackground added in v0.2.8

func SessionGetBackground(req SessionGetBackgroundRequest, call func(string, any, *string) error, connID uint64) (SessionGetBackgroundResponse, error)

SessionGetBackground 获取会话的后台运行模式状态

type SessionGetEffortRequest added in v0.2.8

type SessionGetEffortRequest struct {
	SessionID string `json:"sessionId"`
}

SessionGetEffortRequest 获取推理强度设置的请求

type SessionGetEffortResponse added in v0.2.8

type SessionGetEffortResponse struct {
	Effort string `json:"effort"`
}

SessionGetEffortResponse 获取推理强度设置的响应

func SessionGetEffort added in v0.2.8

func SessionGetEffort(req SessionGetEffortRequest, call func(string, any, *string) error, connID uint64) (SessionGetEffortResponse, error)

SessionGetEffort 获取会话当前的 reasoning effort 设置

type SessionInfo

type SessionInfo struct {
	SessionID string `json:"sessionId"`
	Cwd       string `json:"cwd"`
	Title     string `json:"title"`
}

SessionInfo 会话信息

type SessionListModelsRequest added in v0.2.11

type SessionListModelsRequest struct {
	SessionID string `json:"sessionId"`
}

SessionListModelsRequest 列出会话可用模型的请求

type SessionListModelsResponse added in v0.2.11

type SessionListModelsResponse struct {
	CurrentModelID  string           `json:"currentModelId"`
	AvailableModels []AvailableModel `json:"availableModels"`
}

SessionListModelsResponse 列出会话可用模型的响应

func SessionListModels added in v0.2.11

func SessionListModels(req SessionListModelsRequest, call func(string, any, *string) error, connID uint64) (SessionListModelsResponse, error)

SessionListModels 列出会话可用的所有模型列表 返回所有配置的模型以及当前会话选中的模型 ID

type SessionListRequest

type SessionListRequest struct {
	Cwd    string `json:"cwd"`
	Cursor string `json:"cursor,omitempty"`
}

SessionListRequest 列出会话的请求

type SessionListResponse

type SessionListResponse struct {
	Sessions []SessionInfo `json:"sessions"`
}

SessionListResponse 列出会话的响应

func SessionList

func SessionList(req SessionListRequest, call func(string, any, *string) error, connID uint64) (SessionListResponse, error)

SessionList 列出工作目录中的所有会话

type SessionLoadRequest

type SessionLoadRequest struct {
	Cwd         string `json:"cwd"`
	SessionID   string `json:"sessionId"`
	SkipHistory bool   `json:"alk.cxkevin.top/skip_history"`
}

SessionLoadRequest 加载会话的请求

type SessionLoadResponse

type SessionLoadResponse struct {
	Models        ModelConfig    `json:"models"`
	ConfigOptions []ConfigOption `json:"configOptions"`
}

SessionLoadResponse 加载会话的响应

func SessionLoad

func SessionLoad(req SessionLoadRequest, call func(string, any, *string) error, connID uint64) (SessionLoadResponse, error)

SessionLoad 加载会话并发送历史回放

type SessionNewRequest

type SessionNewRequest struct {
	Cwd string `json:"cwd"`
}

SessionNewRequest 创建新会话的请求

type SessionNewResponse

type SessionNewResponse struct {
	SessionID     string         `json:"sessionId"`
	Models        ModelConfig    `json:"models"`
	ConfigOptions []ConfigOption `json:"configOptions"`
}

SessionNewResponse 创建新会话的响应

func SessionNew

func SessionNew(req SessionNewRequest, call func(string, any, *string) error, connID uint64) (SessionNewResponse, error)

SessionNew 创建新会话

type SessionPromptRequest

type SessionPromptRequest struct {
	SessionID string `json:"sessionId"`
	Prompt    []u.H  `json:"prompt,omitempty"`
}

SessionPromptRequest prompt turn 的请求

type SessionPromptResponse

type SessionPromptResponse struct {
	StopReason string  `json:"stopReason"`
	ErrorMsg   *string `json:"alk.cxykevin.top/error_msg,omitempty"`
}

SessionPromptResponse prompt turn 的响应,包含stopReason

func SessionPrompt

func SessionPrompt(req SessionPromptRequest, call func(string, any, *string) error, connID uint64) (SessionPromptResponse, error)

SessionPrompt 处理 prompt turn 请求

type SessionRequestPermission

type SessionRequestPermission struct {
	SessionID string `json:"sessionId"`
	Update    any    `json:"update"`
}

SessionRequestPermission 批准工具调用

type SessionSetConfigOptionRequest

type SessionSetConfigOptionRequest struct {
	SessionID string `json:"sessionId"`
	ConfigID  string `json:"configId"`
	Value     string `json:"value"`
}

SessionSetConfigOptionRequest 设置配置选项的请求

type SessionSetConfigOptionResponse

type SessionSetConfigOptionResponse struct {
	ConfigOptions []ConfigOption `json:"configOptions"`
}

SessionSetConfigOptionResponse 设置配置选项的响应

func SessionSetConfigOption

func SessionSetConfigOption(req SessionSetConfigOptionRequest, call func(string, any, *string) error, connID uint64) (SessionSetConfigOptionResponse, error)

SessionSetConfigOption 设置配置选项(如模型选择)

type SessionSetModelRequest

type SessionSetModelRequest struct {
	SessionID string `json:"sessionId"`
	ModelID   string `json:"modelId"`
}

SessionSetModelRequest 设置会话模型的请求(向后兼容的老接口)

type SessionSetModelResponse

type SessionSetModelResponse struct {
	CurrentModelID  string           `json:"currentModelId"`
	AvailableModels []AvailableModel `json:"availableModels"`
}

SessionSetModelResponse 设置会话模型的响应

func SessionSetModel

func SessionSetModel(req SessionSetModelRequest, call func(string, any, *string) error, connID uint64) (SessionSetModelResponse, error)

SessionSetModel 设置会话模型 这个接口提供与 session/set_config_option 相同的功能

type SessionUpdate

type SessionUpdate struct {
	SessionID string `json:"sessionId"`
	Update    any    `json:"update"`
}

SessionUpdate 更新会话的请求

type SessionUpdateUpdate

type SessionUpdateUpdate struct {
	SessionUpdate    string  `json:"sessionUpdate"`
	Content          any     `json:"content,omitempty"`
	ToolCallID       string  `json:"toolCallId,omitempty"`
	Title            string  `json:"title,omitempty"`
	Kind             string  `json:"kind,omitempty"`
	Status           string  `json:"status,omitempty"`
	ExpandErrorMsg   string  `json:"alk.cxykevin.top/error_msg,omitempty"`
	CompabiltyIgnore string  `json:"alk.cxykevin.top/ignore,omitempty"`
	AgentStatus      *string `json:"alk.cxykevin.top/agent_status,omitempty"`
}

SessionUpdateUpdate 更新会话的参数

type StopMsg

type StopMsg struct {
	StopReason string
	ErrorMsg   *string
}

StopMsg 停止会话的消息

type SubAgentListRequest

type SubAgentListRequest struct {
	SessionID string `json:"sessionId"`
}

SubAgentListRequest 列出 subagent 的请求

type SubAgentListResponse

type SubAgentListResponse struct {
	Subagents []AgentsInfo    `json:"agents"`
	Tags      []AgentTagsInfo `json:"tags"`
}

SubAgentListResponse 列出 subagent 的响应

func SubAgentList

func SubAgentList(req SubAgentListRequest, call func(string, any, *string) error, connID uint64) (SubAgentListResponse, error)

SubAgentList 列出工作目录中所有 subagent

Jump to

Keyboard shortcuts

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