Skip to content

Commit

Permalink
Plugin RPC interface (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Morozko authored Jan 8, 2024
1 parent dcbe411 commit 51868cc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
Expand Down
55 changes: 55 additions & 0 deletions pluginInterface/v1/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package plugin

import (
"github.com/Masterminds/semver/v3"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"
)

// The interface exposed and used by the go-plugin (versioned as 1)
type PluginRPC interface {
GetPlugins() []Plugin
Call(args Args) Result
}

// One go-plugin binary can provide multiple plugins and/or one plugin with multiple versions
// Deciding if we actually will do bundling in that way or stick with one plugin - one binary
// is a different question, but the interface wouldn't limit us either way.
type Plugin struct {
// The namespace used during installation of the plugins
Namespace string
// "content" or "data" for now
Kind string
// "text", "plugin_a", etc.
Name string
// version of the plugin `Kind Name` that is provided by the current binary
Version semver.Version
// Specification of the `config` block for this plugin
// If nil - providing a `config Kind Name` is an error
ConfigSpec hcldec.Spec
// Specification of the invocation block's body, i.e. `content text {<spec of what's here>}`
InvocationSpec hcldec.Spec
}

type Args struct {
// Specifies which kind, name and version of plugin to execute
Kind string
Name string
Version semver.Version

// Result of decoding a config block with ConfigSpec
Config cty.Value
// Result of decoding an invocation block with InvocationSpec
Args cty.Value
// Passed to content plugins, nil for data plugins
Context map[string]any
}

type Result struct {
// `content` plugins return a markdown string
// `data` plugins return a map[string]any that would be put into the global config
// TODO: hard-code typecast based on the plugin kind while handling the result
result any
diags hcl.Diagnostics
}

0 comments on commit 51868cc

Please sign in to comment.