Skip to content

Commit f011ba1

Browse files
authored
Merge pull request #63 from knabben/refactor/job-history
Refactor/job history
2 parents ea4c531 + 479473c commit f011ba1

13 files changed

Lines changed: 461 additions & 477 deletions

File tree

front/app/ui/dashboard/base/ai-troubleshooting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function AITroubleshooting({
5353
if (broken.size > 0) {
5454
setRequest(Array.from(broken).join(', '));
5555
}
56-
}, [conditions, objectType]);
56+
}, [conditions, objectType, objectName, objectNamespace]);
5757

5858
return (
5959
<Grid justify="flex-start" align="flex-start">
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package llm
2+
3+
import "time"
4+
5+
type Agent struct {
6+
ID string `json:"id"`
7+
Name string `json:"name"`
8+
Type string `json:"type"`
9+
Status string `json:"status"`
10+
Activity string `json:"activity"`
11+
LastUpdate time.Time `json:"last_update"`
12+
Capabilities []string `json:"capabilities"`
13+
}
14+
15+
func (s *ObservationService) initializeAgents() {
16+
agents := []*Agent{
17+
{
18+
ID: "cluster-agent",
19+
Name: "Cluster Agent",
20+
Type: "analysis",
21+
Status: "active",
22+
Activity: "Monitoring cluster health and analyzing issues",
23+
Capabilities: []string{"cluster-analysis", "resource-monitoring", "pattern-detection"},
24+
LastUpdate: time.Now(),
25+
},
26+
}
27+
for _, agent := range agents {
28+
s.agents[agent.ID] = agent
29+
}
30+
}

webserver/internal/infra/llm/client.go

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package llm
2+
3+
import (
4+
"github.com/anthropics/anthropic-sdk-go"
5+
)
6+
7+
// ConversationManager handles message history
8+
type ConversationManager struct {
9+
stopper int
10+
messages []anthropic.MessageParam
11+
}
12+
13+
// NewConversationManager creates a new conversation manager
14+
func NewConversationManager(stopper int) *ConversationManager {
15+
return &ConversationManager{
16+
stopper: stopper,
17+
messages: make([]anthropic.MessageParam, 0),
18+
}
19+
}
20+
21+
// AddUserMessage adds a user message to the conversation history
22+
func (cm *ConversationManager) AddUserMessage(content string) {
23+
message := anthropic.NewUserMessage(anthropic.NewTextBlock(content))
24+
cm.messages = append(cm.messages, message)
25+
}
26+
27+
// AddAssistantMessage adds an assistant message to the conversation history
28+
func (cm *ConversationManager) AddAssistantMessage(content string) {
29+
message := anthropic.NewAssistantMessage(anthropic.NewTextBlock(content))
30+
cm.messages = append(cm.messages, message)
31+
}
32+
33+
// GetConversationHistory returns the current conversation history
34+
func (cm *ConversationManager) GetConversationHistory() []anthropic.MessageParam {
35+
if len(cm.messages) <= cm.stopper {
36+
return cm.messages
37+
}
38+
return cm.messages[:cm.stopper]
39+
}
40+
41+
// ClearHistory clears the conversation history
42+
func (cm *ConversationManager) ClearHistory() {
43+
cm.messages = make([]anthropic.MessageParam, 0)
44+
}
45+
46+
// GetHistoryLength returns the number of messages in history
47+
func (cm *ConversationManager) GetHistoryLength() int {
48+
return len(cm.messages)
49+
}
50+
51+
// TrimHistory removes older messages to stay within token limits
52+
// Keeps the last 'stopper' messages
53+
func (cm *ConversationManager) TrimHistory() {
54+
if len(cm.messages) <= cm.stopper {
55+
return
56+
}
57+
cm.messages = cm.messages[len(cm.messages)-cm.stopper:]
58+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package llm
2+
3+
import (
4+
"testing"
5+
6+
"github.com/anthropics/anthropic-sdk-go"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestTrimHistory(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
initialLength int
14+
keepCount int
15+
expectedCount int
16+
}{
17+
{
18+
name: "NoTrimmingNeeded",
19+
initialLength: 3,
20+
keepCount: 5,
21+
expectedCount: 3,
22+
},
23+
{
24+
name: "ExactKeepCount",
25+
initialLength: 5,
26+
keepCount: 5,
27+
expectedCount: 5,
28+
},
29+
{
30+
name: "TrimToKeepCount",
31+
initialLength: 10,
32+
keepCount: 7,
33+
expectedCount: 7,
34+
},
35+
{
36+
name: "KeepNone",
37+
initialLength: 5,
38+
keepCount: 0,
39+
expectedCount: 0,
40+
},
41+
{
42+
name: "KeepOne",
43+
initialLength: 5,
44+
keepCount: 1,
45+
expectedCount: 1,
46+
},
47+
{
48+
name: "EmptyHistory",
49+
initialLength: 0,
50+
keepCount: 5,
51+
expectedCount: 0,
52+
},
53+
}
54+
55+
for _, tt := range tests {
56+
t.Run(tt.name, func(t *testing.T) {
57+
cm := &ConversationManager{
58+
stopper: tt.keepCount,
59+
messages: make([]anthropic.MessageParam, tt.initialLength),
60+
}
61+
cm.TrimHistory()
62+
assert.Equal(t, tt.expectedCount, len(cm.messages))
63+
})
64+
}
65+
}
66+
67+
func TestGetConversationHistory(t *testing.T) {
68+
tests := []struct {
69+
name string
70+
initialLength int
71+
stopper int
72+
expectLength int
73+
}{
74+
{
75+
name: "EmptyHistory",
76+
initialLength: 0,
77+
stopper: 5,
78+
expectLength: 0,
79+
},
80+
{
81+
name: "UnderStopper",
82+
initialLength: 3,
83+
stopper: 5,
84+
expectLength: 3,
85+
},
86+
{
87+
name: "EqualToStopper",
88+
initialLength: 5,
89+
stopper: 5,
90+
expectLength: 5,
91+
},
92+
{
93+
name: "OverStopper",
94+
initialLength: 10,
95+
stopper: 7,
96+
expectLength: 7,
97+
},
98+
}
99+
100+
for _, tt := range tests {
101+
t.Run(tt.name, func(t *testing.T) {
102+
cm := &ConversationManager{
103+
stopper: tt.stopper,
104+
messages: make([]anthropic.MessageParam, tt.initialLength),
105+
}
106+
history := cm.GetConversationHistory()
107+
assert.Equal(t, tt.expectLength, len(history))
108+
})
109+
}
110+
}

webserver/internal/infra/llm/mcp.go

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)