adapter

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright 2026 Teradata

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Package adapter provides adapters to bridge Crush's TUI interfaces with Loom's gRPC client. This allows the Crush TUI components to work with Loom's server without modification.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	TopicMessages    = "tui.messages"
	TopicSessions    = "tui.sessions"
	TopicPermissions = "tui.permissions"
	TopicProgress    = "tui.progress"
)

Topics for TUI events when using Loom's MessageBus.

Variables

View Source
var ErrAgentBusy = &AgentBusyError{}

ErrAgentBusy is returned when trying to run while already busy.

Functions

func HITLRequestToPermission

func HITLRequestToPermission(hitl *loomv1.HITLRequestInfo) permission.PermissionRequest

HITLRequestToPermission converts a HITL request to a permission.PermissionRequest.

func ProgressToMessage

func ProgressToMessage(progress *loomv1.WeaveProgress, sessionID string, messageID string, agentID string) message.Message

ProgressToMessage converts a WeaveProgress to a message.Message for display. The messageID parameter should be consistent across all progress events for the same turn. Deprecated: Use ProgressToMessageWithHistory for better progress tracking.

func ProgressToMessageWithHistory

func ProgressToMessageWithHistory(progress *loomv1.WeaveProgress, sessionID string, messageID string, agentID string, startTimestamp int64, history []StageInfo) message.Message

ProgressToMessageWithHistory converts a WeaveProgress to a message.Message with stage history. Shows completed stages with ⏺ and the current stage with ◌ (spinner). The startTimestamp should be the timestamp of the first progress event in this turn for accurate duration calculation.

func ProtoToMessage

func ProtoToMessage(m *loomv1.Message, sessionID string) message.Message

ProtoToMessage converts a proto Message to internal message.Message type.

func ProtoToToolCall

func ProtoToToolCall(tc *loomv1.ToolCall) message.ToolCall

ProtoToToolCall converts a proto ToolCall to message.ToolCall. Note: ToolCall proto doesn't have an Id field, so we use the name as the ID.

Types

type AgentBusyError

type AgentBusyError struct{}

AgentBusyError indicates the agent is already processing.

func (*AgentBusyError) Error

func (e *AgentBusyError) Error() string

type AgentResult

type AgentResult struct {
	SessionID string
	Response  string
	Cost      *CostInfo
	Error     error
}

AgentResult represents the result of an agent run.

type ConfigOptions

type ConfigOptions struct {
	Editor       string
	InitializeAs string
	TUI          TUIOptions
}

ConfigOptions holds TUI options.

type CoordinatorAdapter

type CoordinatorAdapter struct {
	// contains filtered or unexported fields
}

CoordinatorAdapter wraps the gRPC client for agent coordination. Implements agent.Coordinator interface.

func NewCoordinatorAdapter

func NewCoordinatorAdapter(c *client.Client, events chan<- tea.Msg) *CoordinatorAdapter

NewCoordinatorAdapter creates a new coordinator adapter.

func (*CoordinatorAdapter) Cancel

func (c *CoordinatorAdapter) Cancel()

Cancel cancels the current agent's processing.

func (*CoordinatorAdapter) CancelAll

func (c *CoordinatorAdapter) CancelAll()

CancelAll cancels all active agent processing.

func (*CoordinatorAdapter) ClearQueue

func (c *CoordinatorAdapter) ClearQueue(sessionID string)

ClearQueue clears the prompt queue for a session.

func (*CoordinatorAdapter) GetAgentID

func (c *CoordinatorAdapter) GetAgentID() string

GetAgentID returns the current agent ID.

func (*CoordinatorAdapter) IsBusy

func (c *CoordinatorAdapter) IsBusy(agentID string) bool

IsBusy returns true if the specified agent is processing. If agentID is empty, checks if the default agent is busy.

func (*CoordinatorAdapter) IsSessionBusy

func (c *CoordinatorAdapter) IsSessionBusy(sessionID string) bool

IsSessionBusy returns true if the agent associated with the given session is busy.

func (*CoordinatorAdapter) ListAgents

func (c *CoordinatorAdapter) ListAgents(ctx context.Context) ([]agent.AgentInfo, error)

ListAgents returns the list of available agents from the server.

func (*CoordinatorAdapter) QueuedPrompts

func (c *CoordinatorAdapter) QueuedPrompts() int

QueuedPrompts returns the number of queued prompts.

func (*CoordinatorAdapter) QueuedPromptsList

func (c *CoordinatorAdapter) QueuedPromptsList(sessionID string) []string

QueuedPromptsList returns the list of queued prompts for a session.

func (*CoordinatorAdapter) Run

func (c *CoordinatorAdapter) Run(ctx context.Context, sessionID, prompt string, attachments ...any) (any, error)

Run starts agent processing for a prompt. Implements agent.Coordinator interface. Attachments[0] can be the agent ID if provided.

func (*CoordinatorAdapter) SetAgentID

func (c *CoordinatorAdapter) SetAgentID(agentID string)

SetAgentID sets the default agent ID for operations.

func (*CoordinatorAdapter) Summarize

func (c *CoordinatorAdapter) Summarize(ctx context.Context, sessionID string) error

Summarize is a stub for context summarization.

func (*CoordinatorAdapter) UpdateModels

func (c *CoordinatorAdapter) UpdateModels(ctx context.Context) error

UpdateModels is a stub - Loom handles model updates differently.

type CostInfo

type CostInfo struct {
	TotalCost    float64
	InputTokens  int32
	OutputTokens int32
	Provider     string
	Model        string
}

CostInfo represents cost information.

type EventSubscriber

type EventSubscriber[T any] func(ctx context.Context) <-chan pubsub.Event[T]

EventSubscriber defines a function that returns an event channel. Matches Crush's subscription pattern.

type LoomApp

type LoomApp struct {

	// Services matching Crush's App interface
	Sessions    *SessionAdapter
	Messages    *MessageAdapter
	Permissions *PermissionAdapter

	// Agent coordinator wrapping gRPC streaming
	AgentCoordinator *CoordinatorAdapter
	// contains filtered or unexported fields
}

LoomApp adapts Loom's gRPC client to match Crush's app.App interface. This allows Crush TUI components to work seamlessly with Loom's server.

func NewLoomApp

func NewLoomApp(c *client.Client) *LoomApp

NewLoomApp creates a new LoomApp wrapping the gRPC client.

func (*LoomApp) Client

func (a *LoomApp) Client() *client.Client

Client returns the underlying gRPC client.

func (*LoomApp) Config

func (a *LoomApp) Config() *LoomConfig

Config returns the application configuration.

func (*LoomApp) IsBusy

func (a *LoomApp) IsBusy() bool

IsBusy returns true if the current default agent is busy.

func (*LoomApp) ListAgents

func (a *LoomApp) ListAgents(ctx context.Context) ([]*loomv1.AgentInfo, error)

ListAgents returns available agents from the server.

func (*LoomApp) ListAvailableModels

func (a *LoomApp) ListAvailableModels(ctx context.Context) ([]*loomv1.ModelInfo, error)

ListAvailableModels returns available models from the server.

func (*LoomApp) SetAgentID

func (a *LoomApp) SetAgentID(agentID string)

SetAgentID sets the current agent/thread ID.

func (*LoomApp) Shutdown

func (a *LoomApp) Shutdown()

Shutdown performs a graceful shutdown of the application.

func (*LoomApp) Subscribe

func (a *LoomApp) Subscribe(program *tea.Program)

Subscribe sends events to the TUI as tea.Msgs. Matches Crush's app.Subscribe interface.

func (*LoomApp) SwitchModel

func (a *LoomApp) SwitchModel(ctx context.Context, sessionID, provider, model string, role loomv1.LLMRole) (*loomv1.SwitchModelResponse, error)

SwitchModel switches the model for a session. role specifies which LLM role to switch (0/unspecified = main agent LLM for backward compatibility).

type LoomConfig

type LoomConfig struct {
	ServerAddr string
	WorkingDir string
	AgentID    string // Selected agent/thread
	Options    ConfigOptions
}

LoomConfig holds TUI configuration.

type MessageAdapter

type MessageAdapter struct {
	// contains filtered or unexported fields
}

MessageAdapter wraps the gRPC client for message operations. Implements message.Service interface.

func NewMessageAdapter

func NewMessageAdapter(c *client.Client) *MessageAdapter

NewMessageAdapter creates a new message adapter.

func (*MessageAdapter) List

func (m *MessageAdapter) List(ctx context.Context, sessionID string) ([]message.Message, error)

List returns all messages for a session.

func (*MessageAdapter) Subscribe

func (m *MessageAdapter) Subscribe(ctx context.Context) <-chan pubsub.Event[message.Message]

Subscribe subscribes to message events. Note: Real-time message updates come through WeaveProgress streaming, not a separate subscription. This is handled by the CoordinatorAdapter.

type NoopCoordinator added in v1.1.0

type NoopCoordinator struct {
	// contains filtered or unexported fields
}

NoopCoordinator is a no-op coordinator for when server is unavailable.

func (*NoopCoordinator) Cancel added in v1.1.0

func (n *NoopCoordinator) Cancel()

func (*NoopCoordinator) CancelAll added in v1.1.0

func (n *NoopCoordinator) CancelAll()

func (*NoopCoordinator) ClearQueue added in v1.1.0

func (n *NoopCoordinator) ClearQueue(sessionID string)

func (*NoopCoordinator) GetAgentID added in v1.1.0

func (n *NoopCoordinator) GetAgentID() string

func (*NoopCoordinator) IsBusy added in v1.1.0

func (n *NoopCoordinator) IsBusy(agentID string) bool

func (*NoopCoordinator) IsSessionBusy added in v1.1.0

func (n *NoopCoordinator) IsSessionBusy(sessionID string) bool

func (*NoopCoordinator) ListAgents added in v1.1.0

func (n *NoopCoordinator) ListAgents(ctx context.Context) ([]agent.AgentInfo, error)

func (*NoopCoordinator) QueuedPrompts added in v1.1.0

func (n *NoopCoordinator) QueuedPrompts() int

func (*NoopCoordinator) QueuedPromptsList added in v1.1.0

func (n *NoopCoordinator) QueuedPromptsList(sessionID string) []string

func (*NoopCoordinator) Run added in v1.1.0

func (n *NoopCoordinator) Run(ctx context.Context, sessionID, prompt string, attachments ...any) (any, error)

func (*NoopCoordinator) SetAgentID added in v1.1.0

func (n *NoopCoordinator) SetAgentID(agentID string)

func (*NoopCoordinator) Summarize added in v1.1.0

func (n *NoopCoordinator) Summarize(ctx context.Context, sessionID string) error

func (*NoopCoordinator) UpdateModels added in v1.1.0

func (n *NoopCoordinator) UpdateModels(ctx context.Context) error

type NoopMessageAdapter added in v1.1.0

type NoopMessageAdapter struct{}

NoopMessageAdapter is a no-op message adapter for when server is unavailable.

func (*NoopMessageAdapter) Create added in v1.1.0

func (n *NoopMessageAdapter) Create(ctx context.Context, msg message.Message) error

func (*NoopMessageAdapter) Delete added in v1.1.0

func (n *NoopMessageAdapter) Delete(ctx context.Context, messageID string) error

func (*NoopMessageAdapter) Get added in v1.1.0

func (n *NoopMessageAdapter) Get(ctx context.Context, messageID string) (message.Message, error)

func (*NoopMessageAdapter) List added in v1.1.0

func (n *NoopMessageAdapter) List(ctx context.Context, sessionID string) ([]message.Message, error)

func (*NoopMessageAdapter) Subscribe added in v1.1.0

func (n *NoopMessageAdapter) Subscribe(ctx context.Context) <-chan pubsub.Event[message.Message]

func (*NoopMessageAdapter) Update added in v1.1.0

func (n *NoopMessageAdapter) Update(ctx context.Context, msg message.Message) error

type NoopSessionAdapter added in v1.1.0

type NoopSessionAdapter struct {
	// contains filtered or unexported fields
}

NoopSessionAdapter is a no-op session adapter for when server is unavailable.

func (*NoopSessionAdapter) Create added in v1.1.0

func (n *NoopSessionAdapter) Create(ctx context.Context, title string) (session.Session, error)

func (*NoopSessionAdapter) CreateAgentToolSessionID added in v1.1.0

func (n *NoopSessionAdapter) CreateAgentToolSessionID(messageID, toolCallID string) string

func (*NoopSessionAdapter) Delete added in v1.1.0

func (n *NoopSessionAdapter) Delete(ctx context.Context, sessionID string) error

func (*NoopSessionAdapter) Get added in v1.1.0

func (n *NoopSessionAdapter) Get(ctx context.Context, sessionID string) (session.Session, error)

func (*NoopSessionAdapter) List added in v1.1.0

func (*NoopSessionAdapter) ParseAgentToolSessionID added in v1.1.0

func (n *NoopSessionAdapter) ParseAgentToolSessionID(sessionID string) (string, string, bool)

func (*NoopSessionAdapter) SetAgentID added in v1.1.0

func (n *NoopSessionAdapter) SetAgentID(agentID string)

func (*NoopSessionAdapter) Subscribe added in v1.1.0

func (n *NoopSessionAdapter) Subscribe(ctx context.Context) <-chan pubsub.Event[session.Session]

func (*NoopSessionAdapter) Update added in v1.1.0

func (n *NoopSessionAdapter) Update(ctx context.Context, sess session.Session) error

type PermissionAdapter

type PermissionAdapter struct {
	// contains filtered or unexported fields
}

PermissionAdapter manages permission requests for tool execution. Implements permission.Service interface. In Loom, HITL requests come via WeaveProgress, not a separate permission system.

func NewPermissionAdapter

func NewPermissionAdapter() *PermissionAdapter

NewPermissionAdapter creates a new permission adapter.

func (*PermissionAdapter) AddPendingRequest

func (p *PermissionAdapter) AddPendingRequest(perm permission.PermissionRequest)

AddPendingRequest adds a pending permission request.

func (*PermissionAdapter) AutoApproveSession

func (p *PermissionAdapter) AutoApproveSession(sessionID string)

AutoApproveSession enables auto-approval for a session.

func (*PermissionAdapter) Deny

Deny denies a permission request.

func (*PermissionAdapter) GetPendingRequest

func (p *PermissionAdapter) GetPendingRequest(toolCallID string) *permission.PermissionRequest

GetPendingRequest gets a pending request by tool call ID.

func (*PermissionAdapter) Grant

Grant grants a one-time permission.

func (*PermissionAdapter) GrantPersistent

func (p *PermissionAdapter) GrantPersistent(perm permission.PermissionRequest)

GrantPersistent grants a persistent permission for a tool.

func (*PermissionAdapter) IsGranted

func (p *PermissionAdapter) IsGranted(toolCallID string) bool

IsGranted checks if a tool call is granted.

func (*PermissionAdapter) IsPersistentlyGranted

func (p *PermissionAdapter) IsPersistentlyGranted(toolName string) bool

IsPersistentlyGranted checks if a tool has persistent permission.

func (*PermissionAdapter) SetSkipRequests

func (p *PermissionAdapter) SetSkipRequests(skip bool)

SetSkipRequests enables/disables auto-approval mode.

func (*PermissionAdapter) SkipRequests

func (p *PermissionAdapter) SkipRequests() bool

SkipRequests returns whether auto-approval is enabled.

func (*PermissionAdapter) Subscribe

Subscribe subscribes to permission request events. Note: In Loom, HITL requests come via WeaveProgress streaming.

func (*PermissionAdapter) SubscribeNotifications

func (p *PermissionAdapter) SubscribeNotifications(ctx context.Context) <-chan pubsub.Event[permission.PermissionNotification]

SubscribeNotifications subscribes to permission notification events.

type ProgressEvent

type ProgressEvent struct {
	Progress *loomv1.WeaveProgress
}

ProgressEvent wraps a WeaveProgress for TUI consumption.

type SessionAdapter

type SessionAdapter struct {
	// contains filtered or unexported fields
}

SessionAdapter wraps the gRPC client for session operations. Implements session.Service interface.

func NewSessionAdapter

func NewSessionAdapter(c *client.Client) *SessionAdapter

NewSessionAdapter creates a new session adapter.

func (*SessionAdapter) Create

func (s *SessionAdapter) Create(ctx context.Context, title string) (session.Session, error)

Create creates a new session.

func (*SessionAdapter) CreateAgentToolSessionID

func (s *SessionAdapter) CreateAgentToolSessionID(messageID, toolCallID string) string

CreateAgentToolSessionID is a stub for compatibility.

func (*SessionAdapter) Delete

func (s *SessionAdapter) Delete(ctx context.Context, id string) error

Delete removes a session.

func (*SessionAdapter) Get

Get retrieves a session by ID.

func (*SessionAdapter) List

func (s *SessionAdapter) List(ctx context.Context) ([]session.Session, error)

List returns all sessions.

func (*SessionAdapter) ParseAgentToolSessionID

func (s *SessionAdapter) ParseAgentToolSessionID(sessionID string) (string, string, bool)

ParseAgentToolSessionID is a stub for compatibility. Returns false since Loom handles agent sessions differently.

func (*SessionAdapter) SetAgentID

func (s *SessionAdapter) SetAgentID(agentID string)

SetAgentID sets the agent ID for session operations.

func (*SessionAdapter) Subscribe

func (s *SessionAdapter) Subscribe(ctx context.Context) <-chan pubsub.Event[session.Session]

Subscribe subscribes to session events. Note: Loom doesn't have real-time session events via gRPC, so this returns an empty channel. Session updates are handled differently in the TUI.

type StageInfo

type StageInfo struct {
	Stage    loomv1.ExecutionStage
	Message  string
	ToolName string // Tool name for TOOL_EXECUTION stages
	Content  string // Actual content for LLM_GENERATION stages
	Failed   bool   // Whether this stage failed
	Done     bool
}

StageInfo tracks information about a completed or current execution stage

type TUIOptions

type TUIOptions struct {
	DiffMode string
}

TUIOptions holds TUI-specific options.

type UpdateAvailableMsg

type UpdateAvailableMsg struct {
	CurrentVersion string
	LatestVersion  string
	IsDevelopment  bool
}

UpdateAvailableMsg is sent when an update is available. Matches Crush's pubsub.UpdateAvailableMsg.

Jump to

Keyboard shortcuts

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