Vibe.Plugin behaviour (vibe v0.2.1)

Copy Markdown View Source

Behaviour for Vibe plugins.

Plugins are BEAM modules, not model-facing tools by default. They can observe lifecycle events, expose supervised children, register slash commands, provide eval APIs, add model-facing actions, and update renderer-neutral UI state.

Use plugin APIs when a capability should be composable from Vibe.Eval; expose model-facing actions only when the model needs direct tool access.

Summary

Types

context()

@type context() :: map()

event()

@type event() :: %{:type => atom(), optional(atom()) => term()}

result()

@type result() :: :ok | {:ok, map()} | {:error, term()} | {:halt, term()}

Callbacks

actions(term)

(optional)
@callback actions(term()) :: [module()]

apis(term)

(optional)
@callback apis(term()) :: [Vibe.Plugin.API.t() | keyword() | map()]

before_command(t, context, term)

(optional)
@callback before_command(String.t(), context(), term()) ::
  {:ok, term()} | {:warn, String.t(), term()} | {:block, String.t(), term()}

children(term)

(optional)
@callback children(term()) :: [Supervisor.child_spec() | {module(), term()} | module()]

children(term, map)

(optional)
@callback children(term(), map()) :: [
  Supervisor.child_spec() | {module(), term()} | module()
]

commands(term)

(optional)
@callback commands(term()) :: [module() | map()]

context(list, context, term)

(optional)
@callback context(list(), context(), term()) :: {:ok, term()} | {:ok, list(), term()}

handle_event(event, context, term)

@callback handle_event(event(), context(), term()) :: {result(), term()}

init(keyword)

@callback init(keyword()) :: {:ok, term()} | {:error, term()}

presentation_document(term)

(optional)
@callback presentation_document(term()) ::
  Vibe.Presentation.Document.t() | keyword() | map()

shutdown(term)

(optional)
@callback shutdown(term()) :: :ok

system_prompt(context, term)

(optional)
@callback system_prompt(context(), term()) :: {String.t() | nil, term()}

tool_call(map, context, term)

(optional)
@callback tool_call(map(), context(), term()) ::
  {:ok, term()} | {:ok, map(), term()} | {:block, String.t(), term()}

tool_result(map, context, term)

(optional)
@callback tool_result(map(), context(), term()) :: {:ok, term()} | {:ok, map(), term()}

Functions

api(attrs)

(macro)