mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
85 lines
3.6 KiB
HTML
85 lines
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Extension System | Kit</title>
|
|
<meta name="description" content="Overview of Kit's Go-based extension system.">
|
|
<link rel="canonical" href="/extensions/overview">
|
|
<link rel="stylesheet" href="/assets/index-Di_r5hA0.css">
|
|
<script type="module" src="/assets/index-oiFiQxsS.js"></script>
|
|
<script type="application/ld+json">{"@context":"https://schema.org","@type":"TechArticle","headline":"Extension System","description":"Overview of Kit's Go-based extension system.","url":"https://go-kit.dev/extensions/overview","isPartOf":{"@type":"WebSite","name":"Kit","url":"https://go-kit.dev"}}</script>
|
|
</head>
|
|
<body>
|
|
<div id="tome-root"></div>
|
|
<div data-pagefind-body style="display:none"><h1>Extension System</h1>
|
|
# Extension System
|
|
|
|
Extensions are Go source files interpreted at runtime via [Yaegi](https://github.com/traefik/yaegi). They can add custom tools, slash commands, widgets, keyboard shortcuts, and intercept lifecycle events — all without recompiling Kit.
|
|
|
|
## Minimal extension
|
|
|
|
```go
|
|
//go:build ignore
|
|
|
|
package main
|
|
|
|
import "kit/ext"
|
|
|
|
func Init(api ext.API) {
|
|
api.OnSessionStart(func(_ ext.SessionStartEvent, ctx ext.Context) {
|
|
ctx.SetFooter(ext.HeaderFooterConfig{
|
|
Content: ext.WidgetContent{Text: "Custom Footer"},
|
|
})
|
|
})
|
|
}
|
|
```
|
|
|
|
Run it with:
|
|
|
|
```bash
|
|
kit -e examples/extensions/minimal.go
|
|
```
|
|
|
|
## How extensions work
|
|
|
|
1. Kit discovers extension files from [auto-discovery paths](/extensions/loading) or explicit `-e` flags
|
|
2. Each `.go` file is loaded into a Yaegi interpreter with access to the `kit/ext` package
|
|
3. Kit calls the `Init(api ext.API)` function in each extension
|
|
4. The extension registers callbacks, tools, commands, and UI components via the `api` and `ctx` objects
|
|
|
|
## Key concepts
|
|
|
|
### The `API` object
|
|
|
|
Passed to `Init()`, the `API` object is used to register lifecycle event handlers and static components:
|
|
|
|
- **Lifecycle handlers** — `api.OnSessionStart(...)`, `api.OnToolCall(...)`, etc.
|
|
- **Tools** — `api.RegisterTool(ext.ToolDef{...})`
|
|
- **Commands** — `api.RegisterCommand(ext.CommandDef{...})`
|
|
- **Shortcuts** — `api.RegisterShortcut(ext.ShortcutDef{...}, handler)`
|
|
- **Tool renderers** — `api.RegisterToolRenderer(ext.ToolRenderConfig{...})`
|
|
- **Message renderers** — `api.RegisterMessageRenderer(ext.MessageRendererConfig{...})`
|
|
- **Options** — `api.RegisterOption(ext.OptionDef{...})`
|
|
|
|
### The `Context` object
|
|
|
|
Passed to event handlers, the `Context` object provides runtime access to Kit's state and UI:
|
|
|
|
- **Output** — `ctx.Print(...)`, `ctx.PrintInfo(...)`, `ctx.PrintError(...)`
|
|
- **UI components** — `ctx.SetWidget(...)`, `ctx.SetHeader(...)`, `ctx.SetFooter(...)`, `ctx.SetStatus(...)`
|
|
- **Editor** — `ctx.SetEditor(...)`, `ctx.ResetEditor()`
|
|
- **Prompts** — `ctx.PromptSelect(...)`, `ctx.PromptConfirm(...)`, `ctx.PromptInput(...)`
|
|
- **Overlays** — `ctx.ShowOverlay(...)`
|
|
- **Messages** — `ctx.SendMessage(...)`, `ctx.GetMessages()`
|
|
- **Model** — `ctx.SetModel(...)`, `ctx.GetAvailableModels()`
|
|
- **Tools** — `ctx.GetAllTools()`, `ctx.SetActiveTools(...)`
|
|
- **Context stats** — `ctx.GetContextStats()`
|
|
- **Session data** — `ctx.AppendEntry(...)`, `ctx.GetEntries(...)`
|
|
- **Subagents** — `ctx.SpawnSubagent(...)`
|
|
- **LLM completion** — `ctx.Complete(...)`
|
|
- **Custom events** — `ctx.EmitCustomEvent(...)`
|
|
|
|
See [Capabilities](/extensions/capabilities) for full details on each component type, and [Testing](/extensions/testing) for writing tests for your extensions.</div>
|
|
</body>
|
|
</html> |