plugin

package
v1.3.87 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package plugin provides the public Go SDK for developing ggcode gRPC plugins.

This package is the public entry point for plugin developers. It is located outside the internal/ directory so external modules can import it.

Quick start:

package main

import (
	"encoding/json"
	"github.com/topcheer/ggcode/sdk/plugin"
)

type myPlugin struct{}

func (p *myPlugin) ListTools() []plugin.ToolSpec {
	return []plugin.ToolSpec{{
		Name:        "hello",
		Description: "Says hello",
		Parameters:  json.RawMessage(`{"type":"object","properties":{"name":{"type":"string"}}}`),
	}}
}

func (p *myPlugin) Execute(toolName string, input json.RawMessage, ctx plugin.Context) (*plugin.Result, error) {
	return &plugin.Result{Content: "Hello!"}, nil
}

func (p *myPlugin) Shutdown() {}

func main() {
	plugin.Serve(&myPlugin{})
}

Index

Constants

This section is empty.

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "GGCODE_PLUGIN",
	MagicCookieValue: "ggcode-grpc-plugin-v1",
}

HandshakeConfig is shared between host and plugin.

Functions

func MustGetEnv

func MustGetEnv(key string) string

MustGetEnv returns the value of an environment variable or exits.

func Serve

func Serve(provider ToolProvider)

Serve starts the plugin process, listening for gRPC connections from the host. This function blocks until the host disconnects.

Types

type Context

type Context struct {
	WorkingDir string
	SessionID  string
	Extra      map[string]string
}

Context provides runtime information from the host.

type Result

type Result struct {
	Content             string
	IsError             bool
	Images              []ResultImage
	SuggestedWorkingDir string
}

Result is the return value of Execute.

type ResultImage

type ResultImage struct {
	Mime   string
	Base64 string
	Width  int
	Height int
}

ResultImage carries an image in the tool result.

type ToolProvider

type ToolProvider interface {
	ListTools() []ToolSpec
	Execute(toolName string, input json.RawMessage, ctx Context) (*Result, error)
	Shutdown()
}

ToolProvider is the interface plugin developers implement.

type ToolSpec

type ToolSpec struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"` // JSON Schema
	Categories  []string        `json:"categories,omitempty"`
}

ToolSpec describes a single tool that a plugin provides.

Jump to

Keyboard shortcuts

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