externalcli

package
v0.1.17 Latest Latest
Warning

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

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

Documentation

Overview

Package externalcli adapts external agent CLI providers to the agent.Runtime contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsumeResult

type ConsumeResult struct {
	Message           string
	ProviderSessionID string
	Usage             *agent.Usage
}

ConsumeResult is the provider-independent result extracted from an event stream.

func ConsumeEvents

func ConsumeEvents(
	ctx context.Context,
	sink events.Sink,
	handle *Invocation,
	runID string,
	traceID string,
	approvalHandler provider.ApprovalHandler,
	questionHandler provider.QuestionHandler,
) (ConsumeResult, error)

ConsumeEvents parses provider activity events and forwards normalized activity to sink.

type Driver

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

Driver contains the shared process, provider-session, and event parsing machinery used by concrete CLI Runtime implementations.

func NewDriver

func NewDriver(name string, invoker Invoker, options ...DriverOptions) (*Driver, error)

NewDriver creates shared infrastructure for one concrete CLI Runtime.

func (*Driver) RunInvocation

func (r *Driver) RunInvocation(
	ctx context.Context,
	request agent.ExecutionRequest,
	observer agent.Observer,
) (agent.ExecutionResult, error)

RunInvocation executes one request for the concrete Runtime that owns this provider invocation facility.

type DriverOptions

type DriverOptions struct {
	SessionStore    ProviderSessionStore
	ApprovalHandler provider.ApprovalHandler
	QuestionHandler provider.QuestionHandler
	MCPServers      []provider.MCPServerConfig
}

DriverOptions configures shared provider-session and interaction facilities.

type InMemoryProviderSessionStore

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

InMemoryProviderSessionStore 在进程内存中存储提供者会话绑定。

func NewInMemoryProviderSessionStore

func NewInMemoryProviderSessionStore() *InMemoryProviderSessionStore

NewInMemoryProviderSessionStore 创建内存中的提供者会话存储。

func (*InMemoryProviderSessionStore) Get

Get 返回对应键的提供者会话绑定。

func (*InMemoryProviderSessionStore) MarkFailed

MarkFailed 将提供者会话绑定标记为失败。

func (*InMemoryProviderSessionStore) Upsert

Upsert 创建或替换提供者会话绑定。

type Invocation

type Invocation struct {
	Process   provider.Process
	Events    <-chan agent.Event
	Responder provider.ApprovalResponder
	Questions provider.QuestionResponder
}

Invocation is a running provider process and its normalized activity stream.

type InvocationRequest

type InvocationRequest struct {
	ExecutionID     string
	SessionID       string
	Resume          bool
	WorkDir         string
	TaskDir         string
	SystemPrompt    string
	Prompt          string
	Messages        []agent.Message
	Tools           []agent.Tool
	AllowedTools    []string
	TraceID         string
	SessionKey      string
	Model           agent.ModelConfig
	ExtraEnv        []string
	PermissionMode  provider.PermissionMode
	ApprovalHandler provider.ApprovalHandler
	MCPServers      []provider.MCPServerConfig
}

InvocationRequest contains the provider-specific process input derived from one immutable agent execution request.

type Invoker

type Invoker interface {
	Prepare(ctx context.Context, workDir string) error
	Invoke(ctx context.Context, request InvocationRequest) (*Invocation, error)
}

Invoker starts a single external CLI provider process.

It is deliberately narrower than agent.Runtime: it does not resolve runtime names, own provider-session persistence, or publish execution lifecycle.

type ProviderSessionBinding

type ProviderSessionBinding struct {
	InternalSessionID string
	Provider          string
	ProviderSessionID string
	WorkDir           string
	AssistantID       string
	Status            string
	LastError         string
	CreatedAt         time.Time
	UpdatedAt         time.Time
}

ProviderSessionBinding 将 Leros 会话映射到提供者原生 CLI 会话。

type ProviderSessionKey

type ProviderSessionKey struct {
	InternalSessionID string
	Provider          string
	WorkDir           string
	AssistantID       string
}

ProviderSessionKey 标识一个外部 CLI 会话绑定。

type ProviderSessionMetadata

type ProviderSessionMetadata struct {
	Provider          string    `json:"provider"`
	ProviderSessionID string    `json:"provider_session_id"`
	CreatedAt         time.Time `json:"created_at"`
}

ProviderSessionMetadata 在 Session.Metadata 中存储提供者原生会话信息。

type ProviderSessionStore

type ProviderSessionStore interface {
	Get(ctx context.Context, key ProviderSessionKey) (*ProviderSessionBinding, error)
	Upsert(ctx context.Context, binding *ProviderSessionBinding) error
	MarkFailed(ctx context.Context, key ProviderSessionKey, reason string) error
}

ProviderSessionStore 持久化提供者会话绑定,用于外部 CLI 恢复。

func NewProviderSessionStore

func NewProviderSessionStore() ProviderSessionStore

NewProviderSessionStore creates the process-owned provider session store. SQLite is preferred; an in-memory store is used when local persistence is unavailable.

Jump to

Keyboard shortcuts

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