Files
sm-golem-plugin/plugin.go
Jakub Zych c93e2d9142 feat: AI models admin, settings import, Anthropic adapter and the rest of AIService
- golem15_golem_models (encrypted write-only api_key) with its cabana list
  and form under golem15.golem.access_settings, and the Settings lookups
  (Models, DefaultModel with PHP's position-0 quirk, Vision, Image, File,
  ByName), every one Trusted
- golem:import-settings copies the WinterCMS golem_settings repeater once
- AnthropicAdapter; SendStream, SendFile/SendFilePath/SendFileReader,
  SendWithModel, SendToImageModel, SendToVisionModel, GenerateImage, Ask
- PromptFactory; README documents the config keys, the environment
  variable, the command and the admin screen
2026-10-03 23:09:02 +02:00

81 lines
2.3 KiB
Go

// Package golem is the golem15.golem plugin: the shared AI layer of
// SummerCMS applications. It ports the WinterCMS Golem15.Golem plugin's AI
// service (provider adapters for the Anthropic Messages API and the
// OpenAI-compatible chat completions API, prompts, image generation, file
// uploads, streaming), its AI model settings with their admin screen and
// its SSRF guard.
package golem
import (
"embed"
"io/fs"
"git.golem15.com/golem15/sm-golem-plugin/console"
"git.golem15.com/golem15/sm-golem-plugin/models"
"git.golem15.com/golem15/sm-golem-plugin/updates"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/party"
"github.com/go-gormigrate/gormigrate/v2"
)
var (
_ party.Plugin = (*Plugin)(nil)
_ pact.HasConfig = (*Plugin)(nil)
_ pact.HasLang = (*Plugin)(nil)
_ pact.HasMigrations = (*Plugin)(nil)
_ pact.HasModels = (*Plugin)(nil)
_ pact.HasCommands = (*Plugin)(nil)
)
//go:embed config
var configFS embed.FS
//go:embed lang
var langFS embed.FS
// Plugin is the golem15.golem plugin.
type Plugin struct {
app *backpack.App
}
// ID is the plugin ID, also its config and lang namespace.
func (p *Plugin) ID() string { return "golem15.golem" }
// Requires is empty: the plugin depends on no other plugin.
func (p *Plugin) Requires() []string { return nil }
// Register keeps the application.
func (p *Plugin) Register(app *backpack.App) error {
p.app = app
return nil
}
// Boot keeps the application.
func (p *Plugin) Boot(app *backpack.App) error {
p.app = app
return nil
}
// ConfigFS ships config/config.yaml, merged under golem15.golem.*.
func (p *Plugin) ConfigFS() fs.FS { return configFS }
// LangFS ships the golem15.golem lang namespace.
func (p *Plugin) LangFS() fs.FS { return langFS }
// Migrations creates golem15_golem_models.
func (p *Plugin) Migrations() []*gormigrate.Migration { return updates.All() }
// Models is AiModel.
func (p *Plugin) Models() []any { return models.All() }
// Commands is golem:import-settings.
func (p *Plugin) Commands() []bonfire.Command {
return []bonfire.Command{console.ImportSettings(p.app)}
}
func init() {
party.Register(&Plugin{})
}