small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
albedo docs extensions.md
14 kB · 353 lines
Markdown
at main

# Write an extension Use this guide to add capabilities through an extension. Read the [extension reference](../robot-docs/extensions.md), [plugin contracts](../robot-docs/plugins.md), and [shared contribution rules](../robot-docs/contributing.md) before choosing an owner. Follow the [SDK import contract](../robot-docs/extensions.md#sdk-imports-and-native-bindings) when choosing shared helpers, daemon imports, and native bindings. The [extension API reference](extension-api.md) covers every public SDK function and explains how to build the searchable reference with exact signatures. ## Build a command extension This example adds `commands.greet(name)` to the model's Python namespace. It reads a declared `prefix` setting and returns a greeting. It needs no new Erlang, actor, database table, or provider credentials. Extensions are compiled into Albedo. Adding a source file does not install it into an already running daemon, and the SDK is currently part of this repository rather than a separately versioned package. Create `src/albedo/harness/extensions/greeting/extension.gleam`: ```gleam import albedo/harness/sdk/command import albedo/harness/sdk/extension import albedo/harness/sdk/settings import gleam/dict import gleam/dynamic/decode import gleam/json import gleam/option.{None} import gleam/result pub fn extension() -> extension.Extension { extension.Extension( name: "greeting", description: "A configurable greeting command.", requires: ["commands"], plugins: [ extension.SettingsPlugin(settings.declaration(configuration())), extension.CommandPlugin([greet()]), ], initialise: extension.no_initialise, ) } fn configuration() -> settings.Section(String) { let prefix = settings.text( "prefix", "Greeting prefix", "Text before the person's name.", "Hello", ) settings.section( "greeting", "Greeting", settings.Tools, [settings.field(prefix)], { use value <- settings.value(prefix) decode.success(value) }…