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 ¶
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 Result ¶
type Result struct {
Content string
IsError bool
Images []ResultImage
SuggestedWorkingDir string
}
Result is the return value of Execute.
type ResultImage ¶
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.
Click to show internal directories.
Click to hide internal directories.