interpluginclient

package
v1.2.2 Latest Latest
Warning

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

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

README

AI Plugin Inter-Plugin Client

This package provides a client for interacting with the Mattermost AI plugin from other Mattermost plugins.

Usage

Basic Usage
// Create a client from your plugin
client, err := interpluginclient.NewClient(&p.MattermostPlugin)
if err != nil {
    // Handle error
}

// Create a completion request
request := interpluginclient.SimpleCompletionRequest{
    Prompt:          "Summarize this text: " + text,
    RequesterUserID: userID,
}

// Get the AI completion
response, err := client.SimpleCompletion(request)
if err != nil {
    // Handle error
}

// Use the response
fmt.Println("AI response:", response)
Advanced Usage
request := interpluginclient.SimpleCompletionRequest{
    Prompt:          "Explain quantum computing in simple terms",
    BotUsername:     "ai",  // Use a specific bot if configured
    RequesterUserID: userID,
    Parameters:      map[string]any{},
}

// Set a custom timeout with context
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

// Get the AI completion with context
response, err := client.SimpleCompletionWithContext(ctx, request)
if err != nil {
    // Handle error
}

Security Notice

Important: The AI plugin's inter-plugin API endpoints do not perform permission checks. The calling plugin is responsible for:

  • Verifying that the user specified in RequesterUserID has permission to use the AI features
  • Ensuring the user has access to any data being sent to the AI model
  • Implementing appropriate rate limiting or usage restrictions
  • Validating that the request is authorized for the intended purpose

The AI plugin will process requests on behalf of any user ID provided by the calling plugin, so proper authorization checks are critical.

API Documentation

Types
  • CompletionRequest: Represents a request to the AI plugin for text completion

    • Prompt: The text prompt to send to the AI model
    • BotUsername: Which AI bot to use (optional, uses default bot if empty)
    • RequesterUserID: The user ID of the user requesting the completion
    • Parameters: Optional map for customizing the completion behavior
  • Client: The main client for communicating with the AI plugin

Methods
  • NewClient(p *plugin.MattermostPlugin) (*Client, error): Creates a client from a plugin instance
  • SimpleCompletion(req SimpleCompletionRequest) (string, error): Makes a completion request with default timeout (30 seconds)
  • SimpleCompletionWithContext(ctx context.Context, req SimpleCompletionRequest) (string, error): Makes a completion request with a custom context
Constants
  • DefaultTimeout: The default timeout for all requests to the AI plugin (30 seconds)

Documentation

Overview

Package interpluginclient provides a client for interacting with the Mattermost AI plugin from other Mattermost plugins.

Security Notice: The AI plugin's inter-plugin API does not perform permission checks. The calling plugin is responsible for verifying that the user has appropriate permissions before making requests on their behalf.

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for all requests to the AI plugin
	DefaultTimeout = 10 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client allows calling the AI plugin functions from other plugins

func NewClient

func NewClient(p *plugin.MattermostPlugin) *Client

NewClientFromPlugin creates a new Client using the plugin's API client

func (*Client) SimpleCompletion

func (c *Client) SimpleCompletion(req SimpleCompletionRequest) (string, error)

SimpleCompletion sends a prompt to the AI plugin and returns the generated response (with default timeout). The calling plugin must ensure that the user specified in RequesterUserID has permission to use AI features and access any data being sent to the AI model.

func (*Client) SimpleCompletionWithContext

func (c *Client) SimpleCompletionWithContext(ctx context.Context, req SimpleCompletionRequest) (string, error)

SimpleCompletionWithContext sends a prompt to the AI plugin with context and returns the generated response. The calling plugin must ensure that the user specified in RequesterUserID has permission to use AI features and access any data being sent to the AI model.

type PluginAPI

type PluginAPI interface {
	PluginHTTP(*http.Request) *http.Response
}

type SimpleCompletionRequest

type SimpleCompletionRequest struct {
	// SystemPrompt is the text system prompt to send to the AI model
	SystemPrompt string `json:"systemPrompt"`

	// UserPrompt is the text user prompt to send to the AI model
	UserPrompt string `json:"userPrompt"`

	// BotUsername specifies which AI bot to use (optional, uses default bot if empty)
	BotUsername string `json:"botUsername,omitempty"`

	// RequesterUserID is the user ID of the user requesting the completion
	RequesterUserID string `json:"requesterUserID"`

	// Parameters allows customizing the completion behavior
	Parameters map[string]interface{} `json:"parameters,omitempty"`
}

CompletionRequest represents the data needed for an interplugin completion request

type SimpleCompletionResponse

type SimpleCompletionResponse struct {
	Response string `json:"response"`
}

CompletionResponse represents the response from an interplugin completion request

Jump to

Keyboard shortcuts

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