feat(connectors): separate packages from scoped installations (#2027)

Packages are accepted once by the instance. Installations configure them at the instance, an organisation or a person; bindings and credentials resolve the person's, then their organisation's, then the instance's. Decisions, approval requests and held chat actions record the installation and scope that acted.

The dashboard lists packages separately from installations, shows every installation's scope, and creates, edits and disables installations at their scope.
This commit is contained in:
sam committed 2026-11-24 03:05:27 +11:00
1 parent 7e701f9a50
commit f24c2b4455
57 files changed
+3358 -1264

No files matched your search

+7 -6
View File
@@ -218,8 +218,8 @@ func (c *countingTool) Lookup(context.Context, string, jsontext.Value) (string,
// offered.
type staleBox struct{ tool *countingTool }
func (b staleBox) Declarations() []connectors.Declaration { return nil }
func (b staleBox) Tool(string) (connectors.Tool, bool) { return b.tool, true }
func (b staleBox) Declarations(context.Context) []connectors.Declaration { return nil }
func (b staleBox) Tool(context.Context, string) (connectors.Tool, bool) { return b.tool, true }
// TestOmittedToolCannotRun guards invocation: a tool the registry no longer
// declares is refused before anything runs, and names nothing new.
@@ -307,14 +307,15 @@ func TestToolNameCollisionsAreWithheld(t *testing.T) {
type collisionBox struct{}
func (collisionBox) Declarations() []connectors.Declaration {
func (collisionBox) Declarations(context.Context) []connectors.Declaration {
return []connectors.Declaration{
{Connector: "a_b", Privileged: noPrivilegedEffects, Kind: connectors.KindLookup, Name: "c"},
{Connector: "a", Privileged: noPrivilegedEffects, Kind: connectors.KindLookup, Name: "b_c"},
{Connector: "run", Privileged: noPrivilegedEffects, Kind: connectors.KindLookup, Name: "list"},
}
}
func (collisionBox) Tool(string) (connectors.Tool, bool) { return fakeTool{}, true }
func (collisionBox) Tool(context.Context, string) (connectors.Tool, bool) { return fakeTool{}, true }
// freshTurn is a turn in a conversation of its own. The taint flag is kept per
// conversation, so a turn sharing the zero session with another case would
@@ -404,14 +405,14 @@ func (f fakePeople) PrincipalFor(_ context.Context, id governance.IdentityID) (g
type fakeToolbox struct{ Toolbox }
func (fakeToolbox) Declarations() []connectors.Declaration {
func (fakeToolbox) Declarations(context.Context) []connectors.Declaration {
return []connectors.Declaration{
{Connector: "pager", Privileged: noPrivilegedEffects, Kind: connectors.KindAction, Name: "page", Description: "Page the on-call person", Schema: jsontext.Value(`{"type":"object"}`)},
{Connector: "pager", Privileged: noPrivilegedEffects, Kind: connectors.KindLookup, Name: "who", Description: "Who is on call", Schema: jsontext.Value(`{"type":"object"}`)},
}
}
func (fakeToolbox) Tool(string) (connectors.Tool, bool) { return fakeTool{}, true }
func (fakeToolbox) Tool(context.Context, string) (connectors.Tool, bool) { return fakeTool{}, true }
type fakeTool struct{ connectors.Tool }
+2 -2
View File
@@ -39,8 +39,8 @@ type Settings interface {
// Toolbox is where the agent finds the connector lookups and actions and the
// MCP server tools it may call.
type Toolbox interface {
Declarations() []connectors.Declaration
Tool(name string) (connectors.Tool, bool)
Declarations(ctx context.Context) []connectors.Declaration
Tool(ctx context.Context, name string) (connectors.Tool, bool)
}
// Judge decides whether an action runs, and runs only what it decided.
+10 -3
View File
@@ -73,6 +73,10 @@ type Action struct {
// digest. An action stored without them can't be run.
Binding jsontext.Value `db:"binding"`
BindingDigest string `db:"binding_digest"`
// InstallationID and InstallationScope name the installation the held
// action resolved to.
InstallationID uuid.UUID `db:"installation_id"`
InstallationScope string `db:"installation_scope"`
}
// Store is the chat module's Postgres store.
@@ -358,16 +362,19 @@ func (s *Store) EventsOf(ctx context.Context, sessionID uuid.UUID, kinds []strin
// one under its key, and returns the stored one either way.
func (s *Store) PutAction(ctx context.Context, orgID string, a Action) (Action, error) {
if _, err := s.db.ExecContext(ctx, `
INSERT INTO chat.actions (id, org_id, turn_id, key, decision, request_id, path, step_due, state, binding, binding_digest)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'waiting', $9, $10)
INSERT INTO chat.actions (id, org_id, turn_id, key, decision, request_id, path, step_due, state, binding, binding_digest,
installation_id, installation_scope)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'waiting', $9, $10, $11, $12)
ON CONFLICT (turn_id, key) DO NOTHING`,
a.ID, orgID, a.TurnID, a.Key, a.Decision, a.RequestID, a.Path, a.StepDue, a.Binding, a.BindingDigest); err != nil {
a.ID, orgID, a.TurnID, a.Key, a.Decision, a.RequestID, a.Path, a.StepDue, a.Binding, a.BindingDigest,
a.InstallationID, a.InstallationScope); err != nil {
return Action{}, fmt.Errorf("record held action: %w", err)
}
return s.actionBy(ctx, `turn_id = $1 AND key = $2`, a.TurnID, a.Key)
}
const actionColumns = `id, turn_id, key, decision, request_id, path, step, step_due, state, answer, result, binding, binding_digest,
installation_id, installation_scope,
(SELECT s.owner_id FROM chat.turns t JOIN chat.sessions s ON s.id = t.session_id WHERE t.id = chat.actions.turn_id) AS owner_id`
func (s *Store) actionBy(ctx context.Context, where string, args ...any) (Action, error) {
+3 -2
View File
@@ -1,6 +1,7 @@
package chat
import (
"context"
"encoding/json/jsontext"
"errors"
"log/slog"
@@ -19,8 +20,8 @@ type effectsBox struct {
tool *countingTool
}
func (b effectsBox) Declarations() []connectors.Declaration { return b.decls }
func (b effectsBox) Tool(string) (connectors.Tool, bool) { return b.tool, true }
func (b effectsBox) Declarations(context.Context) []connectors.Declaration { return b.decls }
func (b effectsBox) Tool(context.Context, string) (connectors.Tool, bool) { return b.tool, true }
// TestChatOffersAndRunsOnlyDeclaredHarmlessTools guards the chat prohibition:
// even for the organisation owner, a tool that changes privileges, accesses
+2 -2
View File
@@ -23,8 +23,8 @@ import (
// trustBox declares tools with explicit trust levels.
type trustBox struct{ decls []connectors.Declaration }
func (b trustBox) Declarations() []connectors.Declaration { return b.decls }
func (trustBox) Tool(string) (connectors.Tool, bool) { return fakeTool{}, true }
func (b trustBox) Declarations(context.Context) []connectors.Declaration { return b.decls }
func (trustBox) Tool(context.Context, string) (connectors.Tool, bool) { return fakeTool{}, true }
// taintJudge decides at a fixed level and mirrors the real Execute's hold and
// refusal switches, recording the level it was last executed with.
+7 -6
View File
@@ -87,7 +87,7 @@ func (m *Module) tools(ctx context.Context, d Deps, t store.Turn) core.ToolSet {
// tool name. Offering one of them would make the model's call ambiguous, so
// the name is withheld from both.
ambiguous := map[string]bool{}
for _, decl := range d.Toolbox.Declarations() {
for _, decl := range d.Toolbox.Declarations(ctx) {
if decl.Privileged.ProhibitedInChat() {
continue
}
@@ -155,9 +155,9 @@ var errToolProhibited = errors.New("chat can't run that tool: it changes privile
// call was offered for. A connector that stopped, or was replaced by one
// declaring fewer tools, leaves the old call refused. The effects are read
// from the running declaration, not the one the call was offered with.
func declared(d Deps, decl connectors.Declaration) (connectors.Declaration, bool) {
for _, current := range d.Toolbox.Declarations() {
if current.Connector == decl.Connector && current.Name == decl.Name && current.Kind == decl.Kind {
func declared(ctx context.Context, d Deps, decl connectors.Declaration) (connectors.Declaration, bool) {
for _, current := range d.Toolbox.Declarations(ctx) {
if current.Connector == decl.Connector && current.Installation == decl.Installation && current.Name == decl.Name && current.Kind == decl.Kind {
return current, true
}
}
@@ -175,14 +175,14 @@ func (m *Module) call(ctx context.Context, d Deps, t store.Turn, decl connectors
if err := m.allowed(ctx, d, need, governance.KindConnector, decl.Connector); err != nil {
return "", err
}
current, ok := declared(d, decl)
current, ok := declared(ctx, d, decl)
if !ok {
return "", errToolUnavailable
}
if current.Privileged.ProhibitedInChat() {
return "", errToolProhibited
}
tool, ok := d.Toolbox.Tool(decl.Connector)
tool, ok := d.Toolbox.Tool(ctx, decl.Ref())
if !ok {
return "", errToolUnavailable
}
@@ -320,6 +320,7 @@ func (m *Module) hold(ctx context.Context, d Deps, t store.Turn, decision judgem
if _, err := m.store.PutAction(ctx, m.orgID, store.Action{
ID: actionID, TurnID: t.ID, Key: key, Decision: rawDecision, RequestID: request.ID,
Path: rawPath, StepDue: request.StepDeadline, Binding: rawBinding, BindingDigest: digest,
InstallationID: decision.Action.Installation.ID, InstallationScope: decision.Action.Installation.Scope,
}); err != nil {
return "", err
}