Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions client/agents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package client

import "encoding/json"

// AgentInfo describes a single agent as returned by agents.list.
type AgentInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Model string `json:"model"`
Provider string `json:"provider"`
AgentType string `json:"agentType"`
Status string `json:"status"`
IsRunning bool `json:"isRunning"`
}

// AgentsListResult is the response payload for agents.list.
type AgentsListResult struct {
Agents []AgentInfo `json:"agents"`
}

// AgentsList lists agents visible to the caller.
func (ws *WSClient) AgentsList() (*AgentsListResult, error) {
payload, err := ws.Call("agents.list", nil)
if err != nil {
return nil, err
}
var result AgentsListResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// AgentParams are the params for agent and agent.wait.
type AgentParams struct {
AgentID string `json:"agentId"`
}

// AgentResult is the response payload for the agent method.
type AgentResult struct {
ID string `json:"id"`
IsRunning bool `json:"isRunning"`
}

// Agent returns the running state for a single agent.
func (ws *WSClient) Agent(params AgentParams) (*AgentResult, error) {
payload, err := ws.Call("agent", params)
if err != nil {
return nil, err
}
var result AgentResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// AgentWaitResult is the response payload for agent.wait.
type AgentWaitResult struct {
ID string `json:"id"`
Status string `json:"status"`
}

// AgentWait waits for (or reports the current status of) an agent.
func (ws *WSClient) AgentWait(params AgentParams) (*AgentWaitResult, error) {
payload, err := ws.Call("agent.wait", params)
if err != nil {
return nil, err
}
var result AgentWaitResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}
File renamed without changes.
File renamed without changes.
168 changes: 168 additions & 0 deletions client/chat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package client

import "encoding/json"

// ChatMediaItem represents a media file attached to a chat message.
type ChatMediaItem struct {
Path string `json:"path"`
Filename string `json:"filename,omitempty"`
}

// ChatSendParams are the params for chat.send.
type ChatSendParams struct {
Message string `json:"message"`
AgentID string `json:"agentId"`
SessionKey string `json:"sessionKey,omitempty"`
Stream bool `json:"stream,omitempty"`
Media json.RawMessage `json:"media,omitempty"` // []string (legacy) or []ChatMediaItem
}

// ChatSendResult is the response payload for chat.send.
type ChatSendResult struct {
RunID string `json:"runId"`
Content string `json:"content"`
Usage json.RawMessage `json:"usage,omitempty"`
Thinking string `json:"thinking,omitempty"`
Media json.RawMessage `json:"media,omitempty"`
Cancelled bool `json:"cancelled,omitempty"`
Injected bool `json:"injected,omitempty"`
}

// ChatSend sends a chat message to an agent.
func (ws *WSClient) ChatSend(params ChatSendParams) (*ChatSendResult, error) {
payload, err := ws.Call("chat.send", params)
if err != nil {
return nil, err
}
var result ChatSendResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ChatSendStream sends a chat message and streams events until run completion.
func (ws *WSClient) ChatSendStream(params ChatSendParams, onEvent func(*WSEvent)) (*ChatSendResult, error) {
payload, err := ws.Stream("chat.send", params, onEvent)
if err != nil {
return nil, err
}
var result ChatSendResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ChatHistoryParams are the params for chat.history.
type ChatHistoryParams struct {
AgentID string `json:"agentId"`
SessionKey string `json:"sessionKey"`
}

// ChatHistoryResult is the response payload for chat.history.
type ChatHistoryResult struct {
Messages json.RawMessage `json:"messages"`
}

// ChatHistory fetches the message history for a session.
func (ws *WSClient) ChatHistory(params ChatHistoryParams) (*ChatHistoryResult, error) {
payload, err := ws.Call("chat.history", params)
if err != nil {
return nil, err
}
var result ChatHistoryResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ChatInjectParams are the params for chat.inject.
type ChatInjectParams struct {
SessionKey string `json:"sessionKey"`
Message string `json:"message"`
Label string `json:"label,omitempty"`
}

// ChatInjectResult is the response payload for chat.inject.
type ChatInjectResult struct {
OK bool `json:"ok"`
MessageID string `json:"messageId"`
}

// ChatInject injects a message into a session transcript without running the agent.
func (ws *WSClient) ChatInject(params ChatInjectParams) (*ChatInjectResult, error) {
payload, err := ws.Call("chat.inject", params)
if err != nil {
return nil, err
}
var result ChatInjectResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ChatAbortParams are the params for chat.abort.
type ChatAbortParams struct {
RunID string `json:"runId,omitempty"`
SessionKey string `json:"sessionKey,omitempty"`
}

// ChatAbortResult is the response payload for chat.abort.
type ChatAbortResult struct {
OK bool `json:"ok"`
Aborted bool `json:"aborted"`
Stopped bool `json:"stopped"`
Forced bool `json:"forced"`
AlreadyAborting bool `json:"alreadyAborting"`
NotFound bool `json:"notFound"`
Unauthorized bool `json:"unauthorized"`
RunIDs []string `json:"runIds"`
}

// ChatAbort cancels running agent invocations for a session or specific run.
func (ws *WSClient) ChatAbort(params ChatAbortParams) (*ChatAbortResult, error) {
payload, err := ws.Call("chat.abort", params)
if err != nil {
return nil, err
}
var result ChatAbortResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ChatSessionStatusParams are the params for chat.session.status.
type ChatSessionStatusParams struct {
SessionKey string `json:"sessionKey"`
}

// ChatActivity describes the current in-flight agent activity for a session.
type ChatActivity struct {
Phase string `json:"phase"`
Tool string `json:"tool"`
Iteration int `json:"iteration"`
}

// ChatSessionStatusResult is the response payload for chat.session.status.
type ChatSessionStatusResult struct {
IsRunning bool `json:"isRunning"`
RunID string `json:"runId"`
Activity *ChatActivity `json:"activity"`
}

// ChatSessionStatus returns the running state and activity for a session.
func (ws *WSClient) ChatSessionStatus(params ChatSessionStatusParams) (*ChatSessionStatusResult, error) {
payload, err := ws.Call("chat.session.status", params)
if err != nil {
return nil, err
}
var result ChatSessionStatusResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}
82 changes: 82 additions & 0 deletions client/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package client

import "encoding/json"

// ConfigGetResult is the response payload for config.get.
type ConfigGetResult struct {
Config json.RawMessage `json:"config"`
Hash string `json:"hash"`
Path string `json:"path"`
}

// ConfigGet returns the current masked config, its hash, and file path.
func (ws *WSClient) ConfigGet() (*ConfigGetResult, error) {
payload, err := ws.Call("config.get", nil)
if err != nil {
return nil, err
}
var result ConfigGetResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ConfigApplyParams are the params for config.apply and config.patch.
type ConfigApplyParams struct {
Raw string `json:"raw"`
BaseHash string `json:"baseHash,omitempty"`
}

// ConfigApplyResult is the response payload for config.apply and config.patch.
type ConfigApplyResult struct {
OK bool `json:"ok"`
Path string `json:"path"`
Config json.RawMessage `json:"config"`
Hash string `json:"hash"`
Restart bool `json:"restart"`
}

// ConfigApply replaces the entire config with raw JSON5 content.
func (ws *WSClient) ConfigApply(params ConfigApplyParams) (*ConfigApplyResult, error) {
payload, err := ws.Call("config.apply", params)
if err != nil {
return nil, err
}
var result ConfigApplyResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ConfigPatch merges a partial JSON5 config update into the current config.
func (ws *WSClient) ConfigPatch(params ConfigApplyParams) (*ConfigApplyResult, error) {
payload, err := ws.Call("config.patch", params)
if err != nil {
return nil, err
}
var result ConfigApplyResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}

// ConfigSchemaResult is the response payload for config.schema.
type ConfigSchemaResult struct {
JSON json.RawMessage `json:"json"`
}

// ConfigSchema returns the config JSON schema for UI form generation.
func (ws *WSClient) ConfigSchema() (*ConfigSchemaResult, error) {
payload, err := ws.Call("config.schema", nil)
if err != nil {
return nil, err
}
var result ConfigSchemaResult
if err := json.Unmarshal(payload, &result); err != nil {
return nil, err
}
return &result, nil
}
Loading