client

package
v0.0.0-...-ac0ca41 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package client provides plugin gRPC client implementation

Package client provides plugin client interface definitions and implementations.

This package defines client interfaces used by AOG Host to communicate with plugins. These interfaces align with those in plugin-sdk/adapter package, but are located in SDK to allow Host-side usage without depending on AOG Core internal packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BidiMessage

type BidiMessage struct {
	Data        []byte
	MessageType string
	Metadata    map[string]string
	Error       error
}

BidiMessage represents a bidirectional streaming communication message.

Used for message transfer in bidirectional streaming service calls.

type BidirectionalPlugin

type BidirectionalPlugin interface {
	PluginProvider

	// InvokeServiceBidirectional handles bidirectional streaming communication.
	// Reads from inStream and writes to outStream until context is cancelled or streams are closed.
	InvokeServiceBidirectional(ctx context.Context, serviceName string, wsConnID string, authInfo string, inStream <-chan BidiMessage, outStream chan<- BidiMessage) error
}

BidirectionalPlugin extends PluginProvider with bidirectional streaming support.

Plugins implementing this interface can handle WebSocket-like bidirectional communication. This is optional - only implement if the plugin declares support_bidirectional = true in manifest.

type GRPCProviderClient

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

GRPCProviderClient is the gRPC client implementation on the Host side

It wraps the protobuf-generated ProviderServiceClient, implementing the PluginProvider, LocalPluginProvider, and RemotePluginProvider interfaces.

This client is responsible for: - Converting interface method calls to gRPC calls - Handling request/response serialization and deserialization - Handling error codes and error messages - Managing streaming communication

func NewGRPCProviderClient

func NewGRPCProviderClient(conn *grpc.ClientConn) *GRPCProviderClient

NewGRPCProviderClient creates a client from gRPC connection

func NewGRPCProviderClientFromStub

func NewGRPCProviderClientFromStub(client protocol.ProviderServiceClient) *GRPCProviderClient

NewGRPCProviderClient creates a gRPC client

Parameters:

  • client: protobuf-generated gRPC client stub

Returns:

  • *GRPCProviderClient: wrapped client implementing all plugin interfaces

func (*GRPCProviderClient) CheckEngine

func (c *GRPCProviderClient) CheckEngine() (bool, error)

CheckEngine checks if the engine is installed

func (*GRPCProviderClient) Close

func (c *GRPCProviderClient) Close() error

Close closes the client connection

func (*GRPCProviderClient) DeleteModel

func (c *GRPCProviderClient) DeleteModel(ctx context.Context, req *types.DeleteRequest) error

DeleteModel deletes a model

func (*GRPCProviderClient) GetConfig

GetConfig gets engine configuration

func (*GRPCProviderClient) GetManifest

func (c *GRPCProviderClient) GetManifest() *types.PluginManifest

GetManifest Get plugin metadata

func (*GRPCProviderClient) GetOperateStatus

func (c *GRPCProviderClient) GetOperateStatus() int

GetOperateStatus Get running status

func (*GRPCProviderClient) GetRunningModels

func (c *GRPCProviderClient) GetRunningModels(ctx context.Context) (*types.ListResponse, error)

GetRunningModels gets running models

func (*GRPCProviderClient) GetSupportModelList

func (c *GRPCProviderClient) GetSupportModelList(ctx context.Context) ([]types.RecommendModelData, error)

func (*GRPCProviderClient) GetVersion

GetVersion gets engine version

func (*GRPCProviderClient) HealthCheck

func (c *GRPCProviderClient) HealthCheck(ctx context.Context) error

HealthCheck Health Check

func (*GRPCProviderClient) InitEnv

func (c *GRPCProviderClient) InitEnv() error

InitEnv initializes environment

func (*GRPCProviderClient) InstallEngine

func (c *GRPCProviderClient) InstallEngine(ctx context.Context) error

InstallEngine installs the engine

func (*GRPCProviderClient) InvokeService

func (c *GRPCProviderClient) InvokeService(ctx context.Context, serviceName string, authInfo string, request []byte) ([]byte, error)

InvokeService invokes a plugin service (core method)

func (*GRPCProviderClient) InvokeServiceBidi

func (c *GRPCProviderClient) InvokeServiceBidi(
	ctx context.Context,
	serviceName string,
	authInfo string,
) (chan<- BidiMessage, <-chan BidiMessage, error)

InvokeServiceBidi bidirectional streaming call

func (*GRPCProviderClient) InvokeServiceBidirectional

func (c *GRPCProviderClient) InvokeServiceBidirectional(
	ctx context.Context,
	serviceName string,
	wsConnID string,
	authInfo string,
	inStream <-chan BidiMessage,
	outStream chan<- BidiMessage,
) error

InvokeServiceBidirectional bridges channels to the gRPC bidi stream to satisfy the BidirectionalPlugin interface.

func (*GRPCProviderClient) InvokeServiceStream

func (c *GRPCProviderClient) InvokeServiceStream(
	ctx context.Context,
	serviceName string,
	authInfo string,
	request []byte,
) (<-chan StreamChunk, error)

InvokeServiceStream performs server-side streaming invocation

func (*GRPCProviderClient) ListModels

func (c *GRPCProviderClient) ListModels(ctx context.Context) (*types.ListResponse, error)

ListModels lists all models

func (*GRPCProviderClient) LoadModel

func (c *GRPCProviderClient) LoadModel(ctx context.Context, req *types.LoadRequest) error

LoadModel loads a model

func (*GRPCProviderClient) PullModel

PullModel pulls a model

func (*GRPCProviderClient) PullModelStream

func (c *GRPCProviderClient) PullModelStream(ctx context.Context, req *types.PullModelRequest) (chan []byte, chan error)

PullModelStream pulls a model with streaming

func (*GRPCProviderClient) RefreshAuth

func (c *GRPCProviderClient) RefreshAuth(ctx context.Context) error

RefreshAuth Refresh authentication information

func (*GRPCProviderClient) SetAuth

func (c *GRPCProviderClient) SetAuth(req *http.Request, authType string, credentials map[string]string) error

SetAuth Set authentication information

func (*GRPCProviderClient) SetOperateStatus

func (c *GRPCProviderClient) SetOperateStatus(status int)

SetOperateStatus Set the running state

func (*GRPCProviderClient) StartEngine

func (c *GRPCProviderClient) StartEngine(mode string) error

StartEngine Start the engine

func (*GRPCProviderClient) StopEngine

func (c *GRPCProviderClient) StopEngine() error

StopEngine Stop the engine

func (*GRPCProviderClient) UnloadModel

func (c *GRPCProviderClient) UnloadModel(ctx context.Context, req *types.UnloadModelRequest) error

UnloadModel unloads models

func (*GRPCProviderClient) UpgradeEngine

func (c *GRPCProviderClient) UpgradeEngine(ctx context.Context) error

UpgradeEngine upgrades the engine

func (*GRPCProviderClient) ValidateAuth

func (c *GRPCProviderClient) ValidateAuth(ctx context.Context) error

ValidateAuth Verify authentication information

type LocalPluginProvider

type LocalPluginProvider interface {
	PluginProvider

	// StartEngine starts the engine.
	StartEngine(mode string) error

	// StopEngine stops the engine.
	StopEngine() error

	// GetConfig returns the engine configuration.
	GetConfig(ctx context.Context) (*types.EngineRecommendConfig, error)

	// CheckEngine checks if the engine is installed.
	CheckEngine() (bool, error)

	// InstallEngine installs the engine.
	InstallEngine(ctx context.Context) error

	// InitEnv initializes the environment.
	InitEnv() error

	// UpgradeEngine upgrades the engine.
	UpgradeEngine(ctx context.Context) error

	// PullModel pulls a model (blocking).
	PullModel(ctx context.Context, req *types.PullModelRequest, fn types.PullProgressFunc) (*types.ProgressResponse, error)

	// PullModelStream pulls a model (streaming).
	PullModelStream(ctx context.Context, req *types.PullModelRequest) (chan []byte, chan error)

	// DeleteModel deletes a model.
	DeleteModel(ctx context.Context, req *types.DeleteRequest) error

	// ListModels lists all downloaded models.
	ListModels(ctx context.Context) (*types.ListResponse, error)

	// LoadModel loads a model into memory.
	LoadModel(ctx context.Context, req *types.LoadRequest) error

	// UnloadModel unloads models from memory.
	UnloadModel(ctx context.Context, req *types.UnloadModelRequest) error

	// GetRunningModels returns currently running models.
	GetRunningModels(ctx context.Context) (*types.ListResponse, error)

	// GetVersion returns the engine version information.
	GetVersion(ctx context.Context, resp *types.EngineVersionResponse) (*types.EngineVersionResponse, error)
}

LocalPluginProvider is the local plugin interface.

Local plugins require local installation and running of engines (e.g., Ollama, OpenVINO). Provides engine lifecycle management and model management functionality.

type PluginProvider

type PluginProvider interface {
	// GetManifest returns the plugin metadata.
	GetManifest() *types.PluginManifest

	// GetOperateStatus returns the operational status.
	GetOperateStatus() int

	// SetOperateStatus sets the operational status.
	SetOperateStatus(status int)

	// HealthCheck performs a health check.
	HealthCheck(ctx context.Context) error

	GetSupportModelList(ctx context.Context) ([]types.RecommendModelData, error)

	// InvokeService invokes a plugin service (core method).
	// serviceName: Service name (e.g., "chat", "embed")
	// request: Serialized request data
	// Returns: Serialized response data
	InvokeService(ctx context.Context, serviceName string, authInfo string, request []byte) ([]byte, error)
}

PluginProvider is the base plugin interface.

All plugins must implement this interface. Provides plugin metadata, health checks, and service invocation functionality.

type RemotePluginProvider

type RemotePluginProvider interface {
	PluginProvider

	// SetAuth sets authentication information.
	SetAuth(req *http.Request, authInfo string, credentials map[string]string) error

	// ValidateAuth validates if authentication information is valid.
	ValidateAuth(ctx context.Context) error

	// RefreshAuth refreshes authentication information (for OAuth).
	RefreshAuth(ctx context.Context) error
}

RemotePluginProvider is the remote plugin interface.

Remote plugins don't require local engine installation (e.g., OpenAI, Anthropic cloud services). Primarily provides authentication management functionality.

type StreamChunk

type StreamChunk struct {
	Data     []byte
	Error    error
	IsFinal  bool
	Metadata map[string]string
}

StreamChunk represents a streaming response data chunk.

Used for data transfer in streaming service calls (e.g., streaming chat).

type StreamablePlugin

type StreamablePlugin interface {
	PluginProvider

	// InvokeServiceStream executes a streaming service request.
	// Returns a channel that sends data chunks and closes when complete.
	// authInfo: Authentication information for the request (can be empty for local plugins)
	InvokeServiceStream(ctx context.Context, serviceName string, authInfo string, request []byte) (<-chan StreamChunk, error)
}

StreamablePlugin extends PluginProvider with server-side streaming support.

Plugins implementing this interface can handle streaming service calls (e.g., SSE, NDJSON). This is optional - only implement if the plugin declares support_streaming = true in manifest.

Jump to

Keyboard shortcuts

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