feat(agent): add Projects + Compliance agents, webhook notifications
- Add AgentFAB to ProjectsPage and CompliancePage - Add AgentWebhookNotifier for agent events (activated, message, escalation, error) - Webhook URL configurable via AGENT_WEBHOOK_URL env var - Build fresh web-v2 dist
This commit is contained in:
@@ -38,6 +38,7 @@ type AgentOrchestrator struct {
|
||||
anthropicKey string
|
||||
apiEndpoint string
|
||||
dataProvider *AgentDataProvider
|
||||
webhook *AgentWebhookNotifier
|
||||
}
|
||||
|
||||
// NewAgentOrchestrator creates a new agent orchestrator
|
||||
@@ -51,6 +52,7 @@ func NewAgentOrchestrator(db, ledgerDB *sql.DB) *AgentOrchestrator {
|
||||
anthropicKey: key,
|
||||
apiEndpoint: "https://api.anthropic.com/v1/messages",
|
||||
dataProvider: NewAgentDataProvider(db, ledgerDB),
|
||||
webhook: NewAgentWebhookNotifier(os.Getenv("AGENT_WEBHOOK_URL")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +102,10 @@ func (o *AgentOrchestrator) HandleAgentChat(w http.ResponseWriter, r *http.Reque
|
||||
svar, err := o.callAnthropic(enhancedPrompt, req.Meddelanden)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("rum", req.Rum).Msg("Agent chat failed")
|
||||
// Notify error
|
||||
if o.webhook != nil {
|
||||
o.webhook.NotifyAgentError(req.Rum, "", err.Error())
|
||||
}
|
||||
// Fallback to mock
|
||||
mockSvar := generateMockResponse(req.Rum, req.Meddelanden)
|
||||
respondWithJSON(w, AgentChatResponse{
|
||||
@@ -110,6 +116,11 @@ func (o *AgentOrchestrator) HandleAgentChat(w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
// Notify message sent
|
||||
if o.webhook != nil {
|
||||
o.webhook.NotifyAgentMessage(req.Rum, "", "response")
|
||||
}
|
||||
|
||||
respondWithJSON(w, AgentChatResponse{
|
||||
Svar: svar,
|
||||
Rum: req.Rum,
|
||||
|
||||
Reference in New Issue
Block a user