stringreplace

package
v0.1.93 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package stringreplace is the built-in string_replace plugin: it rewrites, flags, or blocks prompt and completion text that matches a list of literal or regular-expression rules, in place for non-streaming responses and in flight for streams. It doubles as a reference implementation of a mutating pluginapi plugin with prompt, response, and stream hooks.

Index

Constants

View Source
const (
	ModeLiteral = "literal"
	ModeRegex   = "regex"
)

Mode values for the "mode" config key.

View Source
const (
	OnMatchReplace = "replace"
	OnMatchBlock   = "block"
	OnMatchRespond = "respond"
	OnMatchWarn    = "warn"
)

OnMatch values for the "on_match" config key.

View Source
const (
	DefaultMessage          = "Request blocked by policy"
	DefaultStreamLookbehind = 64
)

Defaults for optional config keys.

View Source
const Code = "string_replace_match"

Code is the Decision.Code recorded when a rule matches and on_match is block, respond, or warn.

View Source
const Name = "string_replace"

Name is the manifest name of the plugin.

Variables

This section is empty.

Functions

func New

func New() pluginapi.Plugin

New returns an unconfigured plugin; call Init before use.

Types

type Plugin

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

Plugin is one configured string_replace instance.

func (*Plugin) Close

func (p *Plugin) Close(context.Context) error

Close releases nothing; the plugin holds no resources.

func (*Plugin) EditsContent added in v0.1.92

func (p *Plugin) EditsContent() bool

EditsContent reports whether this instance rewrites the text it matches. Every other on_match (block, respond, warn) leaves the request as it is.

func (*Plugin) Init

func (p *Plugin) Init(_ context.Context, raw json.RawMessage, _ pluginapi.Host) error

Init decodes and validates the instance configuration.

func (*Plugin) Manifest

func (p *Plugin) Manifest() pluginapi.Manifest

Manifest describes the plugin and its configuration form.

func (*Plugin) OnPrompt

OnPrompt edits or inspects the text of the prompt messages of the configured roles, tool-result text included.

func (*Plugin) OnResponse

func (p *Plugin) OnResponse(_ context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)

OnResponse edits or inspects the text of every completion choice.

func (*Plugin) OnStreamEnd

func (p *Plugin) OnStreamEnd(_ context.Context, x *pluginapi.Exchange) (pluginapi.Decision, error)

OnStreamEnd reports a warning when on_match is warn and a rule matched during the stream; otherwise it allows.

func (*Plugin) OnStreamEvent

OnStreamEvent rewrites text deltas for replace, remembers matches for warn, and passes everything else through.

func (*Plugin) StreamPolicy

func (p *Plugin) StreamPolicy() pluginapi.StreamPolicy

StreamPolicy transforms text deltas in flight for replace and warn, and buffers the whole stream for block and respond so the decision is taken on the assembled completion before anything reaches the client.

func (*Plugin) Summarize

func (p *Plugin) Summarize(raw json.RawMessage) string

Summarize returns one line describing the instance for the dashboard list.

Jump to

Keyboard shortcuts

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