No description
Find a file
tbscode 40c2af8ff3 integrationinterface: add coder agent-default Definition hooks
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.
2026-11-06 13:51:23 +01:00
docs feat(ci-relay): add the versioned ci_failure event contract + sink (ci#607) 2026-10-19 12:32:12 +00:00
integrationinterface integrationinterface: add coder agent-default Definition hooks 2026-11-06 13:51:23 +01:00
COPYRIGHT Relicense under AGPL-3.0-or-later 2026-09-20 17:11:35 +02:00
go.mod feat(cli): allow integrations to contribute top-level CLI commands 2026-10-13 23:09:12 +00:00
go.sum feat(cli): allow integrations to contribute top-level CLI commands 2026-10-13 23:09:12 +00:00
LICENSE Relicense under AGPL-3.0-or-later 2026-09-20 17:11:35 +02:00
NOTICE docs: add AGPL-3.0-or-later NOTICE with licensing exceptions 2026-09-27 01:33:54 +02:00
README.md feat(interface): add stable versioned Host capability surface 2026-10-14 23:51:07 +00:00

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 /api prefixes.
  • Frontend pages require Definition.FrontendAssets and AssetPath points 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.