feat(19.7-01): SDK-free pact contracts for MCP, account contributions and prompted actions
- pact/mcp.go: HasMCP, MCP, MCPTool, MCPPrompt, MCPGuard, MCPGuards, MCPSubject, MCPDispatch, MCPTokenVerifier, MCPGrant, ErrMCPTokenInvalid, MCPPersonalTokenResolver, MCPLinkedBackendResolver, LinkedBackendUser, MCPSubjectChanged and its kinds, FrontendPermission, HasFrontendPermissions - capabilities.go: AdminActionPrompt, AdminRecordAction.Prompt, AdminRecordActionInput.Value, HasAccountContributions, AccountContribution, AccountAction, AccountActionInput, AccountActionResult - discovery tests, MCPGuards registry test and a go list -deps assertion that pact names neither the MCP SDK, jsonschema-go nor bouncer - pact README and docs/plugins/registration.md rows
This commit is contained in:
@@ -348,18 +348,39 @@ type AdminRecordAction struct {
|
||||
// Danger marks an action that moves money out or cannot be undone: the
|
||||
// admin's confirm dialog then uses its danger variant (serialized as
|
||||
// `danger` in the record response). The footer button itself is unchanged.
|
||||
Danger bool
|
||||
Danger bool
|
||||
|
||||
// Prompt, when set, asks the administrator for one text value in the
|
||||
// confirm dialog before the action runs; the trimmed answer reaches Run
|
||||
// as AdminRecordActionInput.Value. An action without a Prompt carries no
|
||||
// input beyond the record and refuses a posted value.
|
||||
Prompt *AdminActionPrompt
|
||||
|
||||
Applies func(ctx context.Context, record any) (bool, error) `json:"-"`
|
||||
Run func(ctx context.Context, in AdminRecordActionInput) (AdminRecordActionResult, error) `json:"-"`
|
||||
}
|
||||
|
||||
// AdminActionPrompt describes the one text input a prompted record action
|
||||
// shows in its confirm dialog. Label, Placeholder and Comment are phrase keys
|
||||
// (containing "::") or literal text; Label is required. MaxLength caps the
|
||||
// value in runes, 0 meaning 255. The admin refuses an empty or over-long
|
||||
// value with a validation error on the input before the action runs.
|
||||
type AdminActionPrompt struct {
|
||||
Label string
|
||||
Placeholder string
|
||||
Comment string
|
||||
MaxLength int
|
||||
}
|
||||
|
||||
// AdminRecordActionInput is what the framework hands an AdminRecordAction.
|
||||
// Record is the record the framework loaded through the controller's
|
||||
// FormExtendQuery scope with a row lock, inside the action's transaction;
|
||||
// RecordID is its primary key.
|
||||
// RecordID is its primary key. Value is the trimmed prompt answer of a
|
||||
// prompted action; empty for an action without a Prompt.
|
||||
type AdminRecordActionInput struct {
|
||||
RecordID uint64
|
||||
Record any
|
||||
Value string
|
||||
}
|
||||
|
||||
// AdminRecordActionResult is a record action's answer. Message is a phrase key
|
||||
@@ -392,7 +413,10 @@ type HasAdminRecordActions interface {
|
||||
// its outranking check inside the action transaction before the
|
||||
// contributor's Run; a non-superuser whose grants do not cover the
|
||||
// target's effective grants gets 403 with backend::lang.user.outranked and
|
||||
// Run is not called. A record action carries no input beyond the record.
|
||||
// Run is not called. A record action carries no input beyond the record,
|
||||
// unless it declares a Prompt: then the admin asks for one text value and
|
||||
// hands the trimmed answer to Run as AdminRecordActionInput.Value; a Prompt
|
||||
// with an empty Label stops the boot.
|
||||
//
|
||||
// The admin compiles extensions at boot, only when it is active (some
|
||||
// plugin registers admin controllers). An unknown controller ID, a target
|
||||
@@ -411,6 +435,63 @@ type HasAdminActionExtensions interface {
|
||||
AdminActionExtensions() []AdminActionExtension
|
||||
}
|
||||
|
||||
// HasAccountContributions is implemented by plugins that add a section to
|
||||
// the admin's My account page: a titled card with a status line and
|
||||
// buttons, shown to the signed-in administrator only.
|
||||
type HasAccountContributions interface {
|
||||
AccountContributions() []AccountContribution
|
||||
}
|
||||
|
||||
// AccountContribution is one section a plugin adds to the admin's My account
|
||||
// page. Name is an identifier unique across plugins; Label and Description
|
||||
// are phrase keys (containing "::") or literal text. Status, when set, is a
|
||||
// pure read that answers the line shown under the description for the
|
||||
// signed-in administrator (an empty string shows none). Actions are the
|
||||
// section's buttons.
|
||||
//
|
||||
// The admin compiles contributions at boot, only when it is active. A name
|
||||
// that is not an identifier, a name another plugin already contributed, an
|
||||
// empty Label, an action whose name is not an identifier or repeats within
|
||||
// the section, a nil Run or an empty action Label stops the boot.
|
||||
type AccountContribution struct {
|
||||
Name string
|
||||
Label string
|
||||
Description string
|
||||
Status func(ctx context.Context, adminID uint) (string, error) `json:"-"`
|
||||
Actions []AccountAction
|
||||
}
|
||||
|
||||
// AccountAction is one button of an AccountContribution. Confirm, when set,
|
||||
// is the confirmation text the admin shows first (Danger selects its danger
|
||||
// variant). Permissions are extra backend permission codes the administrator
|
||||
// needs. Applies, when set, must be a pure read: it decides whether the
|
||||
// button is offered and is checked again before Run. Run acts for the
|
||||
// signed-in administrator only, inside a transaction (cabana.TxFromContext
|
||||
// reads it), and may answer a URL the admin opens in a new tab.
|
||||
type AccountAction struct {
|
||||
Name string
|
||||
Label string
|
||||
Confirm string
|
||||
Danger bool
|
||||
Permissions []string
|
||||
Applies func(ctx context.Context, adminID uint) (bool, error) `json:"-"`
|
||||
Run func(ctx context.Context, in AccountActionInput) (AccountActionResult, error) `json:"-"`
|
||||
}
|
||||
|
||||
// AccountActionInput is what the framework hands an AccountAction: the id of
|
||||
// the signed-in administrator and nothing else.
|
||||
type AccountActionInput struct {
|
||||
AdminID uint
|
||||
}
|
||||
|
||||
// AccountActionResult is an account action's answer. Message is a phrase key
|
||||
// or text, localized by the framework and shown as a toast; URL, when set,
|
||||
// is opened by the admin in a new tab and shown as a link.
|
||||
type AccountActionResult struct {
|
||||
Message string
|
||||
URL string
|
||||
}
|
||||
|
||||
// AdminPartialData supplies the view model a controller partial template
|
||||
// renders (config_list.yaml headerPartial, fields.yaml `type: partial`). name
|
||||
// is the partial name; record is the scoped record for a form partial on an
|
||||
|
||||
Reference in New Issue
Block a user