Adds a human-consent gate for tools marked RequiresApproval, exposes
session management as LLM-invokable chat tools, and gives the operator
/delete to retire conversations permanently.
**Tool-approval gate (internal/tools, internal/agentexec)**
- ApprovalRequester contract lives in internal/tools (not gateway) so
agentexec can import it without pulling in the chat-adapter stack.
- ToolSetOptions.Approval wires the approver through to toolExecute.
- BuildToolSetFrom omits RequiresApproval tools when no approver is
configured; dispatch paths (invokeTool, tool_call bridge) refuse
them too, so the invariant holds at every indirection.
- The gate fails closed: only Approved/PermanentlyApproved pass;
an unknown decision value from a faulty approver does not execute.
- Tool-level timeout (2 min) returns a plain error, not a context
cancellation, so the model can report "approval timed out" instead
of the turn aborting.
- BuildApprovalDescription callback lets a tool surface the specific
resource being acted on ("Delete session \"abc123\"") rather than
showing a static tool description.
**Session tools (internal/gateware/session_tools.go)**
- session_list (idempotent), session_resume (mutating), session_title
(mutating), session_delete (mutating + RequiresApproval).
- Scoped to the current platform + channel: GetByChannel replaces
List() so a model in chat A cannot list or manipulate chat B.
- session_title validates the session belongs to this channel before
writing; session_resume/session_delete resolve refs against the
channel-scoped list.
- Shared limit helper extracted to tools.ListLimit.
**Telegram approval adapter (internal/channels/telegram/approval.go)**
- telegramApprover implements ApprovalRequester via the three-button
inline keyboard (Approve/Permanent/Deny). 2-min token expiry.
- Own map + mutex + "approval:" callback prefix — separate from the
dangerous-command system.
- Permanent approval uses exact-match (not prefix) lookup keyed by
action + resource description, so permanently approving "delete
session abc123" only covers that one session, not every call to
session_delete for 24h.
**Session lifecycle**
- /delete <session-id>: removes a session and its history. Refuses
prefixes shorter than 4 chars even when unique. Exact ID wins over
an ambiguous prefix. sessionTracker.forget sweeps every channel+
thread pointing at the deleted session.
- Extracted resolveSessionRef and shortSessionID for /resume and
/delete to share.
**Wiring**
- submitTurn builds the approver onto ctx before the LLM turn.
- chatGenerateOptions reads approver from ctx, passes it through
ToolSetOptions.
- SessionTools built per turn on the current message, combined with
taskTools into a single toolset.
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
// Package gateway: approval.go — re-exports the tool-approval contract
|
|
// from internal/tools so existing gateway-internal and adapter code
|
|
// continues to compile against the names it already uses.
|
|
//
|
|
// The canonical definitions live in internal/tools/approval.go so that
|
|
// internal/agentexec (also used by the archie-agent sandbox binary) can
|
|
// import them without pulling in the chat-gateway domain stack.
|
|
|
|
package gateway
|
|
|
|
import "github.com/samcharles93/archie-core/internal/tools"
|
|
|
|
// Re-exported types so gateway-internal code uses the same concrete types
|
|
// as the dispatch layer without qualification churn.
|
|
type (
|
|
ApprovalRequester = tools.ApprovalRequester
|
|
ApprovalDecision = tools.ApprovalDecision
|
|
)
|
|
|
|
// Re-exported constants.
|
|
const (
|
|
ApprovalApproved = tools.ApprovalApproved
|
|
ApprovalPermanentlyApproved = tools.ApprovalPermanentlyApproved
|
|
ApprovalDenied = tools.ApprovalDenied
|
|
ToolApprovalTimeout = tools.ToolApprovalTimeout
|
|
)
|
|
|
|
// Re-exported sentinel errors.
|
|
var (
|
|
ErrApprovalDenied = tools.ErrApprovalDenied
|
|
ErrApprovalNotConfigured = tools.ErrApprovalNotConfigured
|
|
)
|
|
|
|
// Re-exported context plumbing.
|
|
var (
|
|
WithApprovalRequester = tools.WithApprovalRequester
|
|
ApprovalFromContext = tools.ApprovalFromContext
|
|
)
|