mirror of
https://github.com/msgmate-io/open-chat-go-integration-interface.git
synced 2026-11-26 16:59:56 +00:00
No description
- Go 100%
Add AgentConfig/AgentDefaults/AgentInteractionDefaults/AgentChatSetup/ AgentInteractionTags to Definition so a coding integration owns the agent config defaults the core used to hardcode, delivered through the integration interface instead of backend/nativecoder. |
||
|---|---|---|
| docs | ||
| integrationinterface | ||
| COPYRIGHT | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| NOTICE | ||
| README.md | ||
go-integration-interface
Small Go SDK for registering Open Chat integrations.
Integrations can contribute:
- DB models/migrations
- API route registration
- frontend HTML routes under
/integrations/<integration_name>/... - static frontend HTML pages backed by integration-owned embedded assets
- tool definitions (using go-tool-interface)
- callable integration functions
- default bot bootstrap configs (applied at server startup)
Usage
package myintegration
import (
"context"
"net/http"
"github.com/msgmate-io/go-integration-interface/integrationinterface"
"github.com/msgmate-io/go-tool-interface/toolinterface"
)
func init() {
integrationinterface.MustRegister(integrationinterface.Definition{
Name: "my_integration",
ModelProviders: []func() []interface{}{
func() []interface{} { return []interface{}{} },
},
RouteRegistrar: func(v1Private *http.ServeMux, root *http.ServeMux) {
_ = root
v1Private.HandleFunc("GET /integrations/my-integration/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
},
FrontendRoutes: []integrationinterface.FrontendRoute{
{
Route: "/integrations/my_integration",
Public: true,
Description: "Public integration landing page",
Handler: func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("<html><body><h1>My Integration</h1></body></html>"))
},
},
},
FrontendPages: []integrationinterface.FrontendPage{
{
Route: "/integrations/my_integration/servers",
Public: false,
Description: "Bundled servers page",
AssetPath: "servers/index.html",
},
},
FrontendAssets: myEmbeddedAssetsFS,
Functions: map[string]integrationinterface.Function{
"health": func(ctx context.Context, payload map[string]interface{}) (interface{}, error) {
_ = ctx
_ = payload
return map[string]interface{}{"ok": true}, nil
},
},
ToolDefinitions: []toolinterface.Definition{
{
Name: "my_integration_echo",
Description: "Echo a message",
InputType: struct {
Message string `json:"message"`
}{},
RequiredParams: []string{"message"},
Parameters: map[string]interface{}{
"message": map[string]interface{}{"type": "string"},
},
Run: func(input interface{}, init map[string]interface{}) (string, error) {
_ = init
in := input.(struct {
Message string `json:"message"`
})
return in.Message, nil
},
},
},
BotBootstrapConfigs: []integrationinterface.BotBootstrapConfig{
{
PrimaryOwner: "admin",
Bot: integrationinterface.BotIdentityConfig{
Username: "my-integration-bot",
Password: "random",
Name: "my_integration_bot",
},
DefaultSharedConfig: map[string]interface{}{
"tools": []string{"my_integration_echo"},
},
},
},
})
}
Notes:
- Frontend routes are auto-registered by the backend for all compiled integrations.
- Frontend route paths must be under
/integrations/<integration_name>. - Frontend routes must not use
/apiprefixes. - Frontend pages require
Definition.FrontendAssetsandAssetPathpoints to an HTML file in that filesystem. - Tool names are global across all integrations; duplicate tool names fail registration.
- Integration bot bootstrap configs reuse the same schema as
open-chat.json/open-chat.yaml bootstrap.bots. - Integration bot configs are intended as defaults; user-provided bot bootstrap config should take precedence.
Host capability interface
Integrations should reach core capabilities through the stable, versioned Host
interface instead of importing backend/... packages directly. The core installs
an adapter at startup (backend/integrationhost); integrations read it via
integrationinterface.RequireHost() at request/bootstrap time:
host := integrationinterface.RequireHost()
values := host.Config().All() // resolved runtime config
storage, user, err := host.HTTP().DBAndUser(r)
orm := storage.Handle().(*gorm.DB) // gorm is a third-party dependency
host.Logger().Infof("handled %s", user.Username())
The surface is versioned via integrationinterface.HostVersion and does not
expose fs.FS, http.ServeMux or gorm.DB. See the repository docs
(frontend/pages/docs/content/integration-host-migration.mdx) for the migration
recipe.