Refactor Structs for Consistency and Enhanced Readability
- Standardized field formatting in TriggerResult and Execution structs for improved code clarity. - Added test cases in robot_test.go to ensure Robot can run with nil config and quota, verifying default behavior. - Enhanced comments in the Goals struct to clarify task objectives and improve documentation consistency.
This commit is contained in:
parent
90b52eaf22
commit
4ceb74da9e
4 changed files with 38 additions and 23 deletions
|
|
@ -176,11 +176,11 @@ type TriggerRequest struct {
|
||||||
|
|
||||||
// TriggerResult - result of Trigger()
|
// TriggerResult - result of Trigger()
|
||||||
type TriggerResult struct {
|
type TriggerResult struct {
|
||||||
Accepted bool `json:"accepted"`
|
Accepted bool `json:"accepted"`
|
||||||
Queued bool `json:"queued"`
|
Queued bool `json:"queued"`
|
||||||
Execution *types.Execution `json:"execution,omitempty"`
|
Execution *types.Execution `json:"execution,omitempty"`
|
||||||
JobID string `json:"job_id,omitempty"`
|
JobID string `json:"job_id,omitempty"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecutionQuery - query options for GetExecutions()
|
// ExecutionQuery - query options for GetExecutions()
|
||||||
|
|
|
||||||
14
agent/robot/cache/cache.go
vendored
14
agent/robot/cache/cache.go
vendored
|
|
@ -41,7 +41,7 @@ func (c *Cache) Get(memberID string) *types.Robot {
|
||||||
func (c *Cache) List(teamID string) []*types.Robot {
|
func (c *Cache) List(teamID string) []*types.Robot {
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
defer c.mu.RUnlock()
|
defer c.mu.RUnlock()
|
||||||
|
|
||||||
memberIDs := c.byTeam[teamID]
|
memberIDs := c.byTeam[teamID]
|
||||||
robots := make([]*types.Robot, 0, len(memberIDs))
|
robots := make([]*types.Robot, 0, len(memberIDs))
|
||||||
for _, memberID := range memberIDs {
|
for _, memberID := range memberIDs {
|
||||||
|
|
@ -62,14 +62,14 @@ func (c *Cache) Refresh(ctx *types.Context, memberID string) error {
|
||||||
func (c *Cache) Add(robot *types.Robot) {
|
func (c *Cache) Add(robot *types.Robot) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
c.robots[robot.MemberID] = robot
|
c.robots[robot.MemberID] = robot
|
||||||
|
|
||||||
// Update team index
|
// Update team index
|
||||||
if _, exists := c.byTeam[robot.TeamID]; !exists {
|
if _, exists := c.byTeam[robot.TeamID]; !exists {
|
||||||
c.byTeam[robot.TeamID] = []string{}
|
c.byTeam[robot.TeamID] = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if member ID already in team list
|
// Check if member ID already in team list
|
||||||
found := false
|
found := false
|
||||||
for _, id := range c.byTeam[robot.TeamID] {
|
for _, id := range c.byTeam[robot.TeamID] {
|
||||||
|
|
@ -87,14 +87,14 @@ func (c *Cache) Add(robot *types.Robot) {
|
||||||
func (c *Cache) Remove(memberID string) {
|
func (c *Cache) Remove(memberID string) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
robot := c.robots[memberID]
|
robot := c.robots[memberID]
|
||||||
if robot == nil {
|
if robot == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(c.robots, memberID)
|
delete(c.robots, memberID)
|
||||||
|
|
||||||
// Remove from team index
|
// Remove from team index
|
||||||
teamMembers := c.byTeam[robot.TeamID]
|
teamMembers := c.byTeam[robot.TeamID]
|
||||||
for i, id := range teamMembers {
|
for i, id := range teamMembers {
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,8 @@ func (r *Robot) GetExecutions() []*Execution {
|
||||||
// Each trigger creates a new Execution, mapped to a job.Job for monitoring
|
// Each trigger creates a new Execution, mapped to a job.Job for monitoring
|
||||||
// Relationship: 1 Execution = 1 job.Job
|
// Relationship: 1 Execution = 1 job.Job
|
||||||
type Execution struct {
|
type Execution struct {
|
||||||
ID string `json:"id"` // unique execution ID
|
ID string `json:"id"` // unique execution ID
|
||||||
MemberID string `json:"member_id"` // robot member ID
|
MemberID string `json:"member_id"` // robot member ID
|
||||||
TeamID string `json:"team_id"`
|
TeamID string `json:"team_id"`
|
||||||
TriggerType TriggerType `json:"trigger_type"` // clock | human | event
|
TriggerType TriggerType `json:"trigger_type"` // clock | human | event
|
||||||
StartTime time.Time `json:"start_time"`
|
StartTime time.Time `json:"start_time"`
|
||||||
|
|
@ -120,9 +120,9 @@ type Execution struct {
|
||||||
// TriggerInput - stored trigger input for traceability
|
// TriggerInput - stored trigger input for traceability
|
||||||
type TriggerInput struct {
|
type TriggerInput struct {
|
||||||
// For human intervention
|
// For human intervention
|
||||||
Action InterventionAction `json:"action,omitempty"` // task.add, goal.adjust, etc.
|
Action InterventionAction `json:"action,omitempty"` // task.add, goal.adjust, etc.
|
||||||
Messages []agentcontext.Message `json:"messages,omitempty"` // user's input (text, images, files)
|
Messages []agentcontext.Message `json:"messages,omitempty"` // user's input (text, images, files)
|
||||||
UserID string `json:"user_id,omitempty"` // who triggered
|
UserID string `json:"user_id,omitempty"` // who triggered
|
||||||
|
|
||||||
// For event trigger
|
// For event trigger
|
||||||
Source EventSource `json:"source,omitempty"` // webhook | database
|
Source EventSource `json:"source,omitempty"` // webhook | database
|
||||||
|
|
@ -145,13 +145,11 @@ type CurrentState struct {
|
||||||
// Example:
|
// Example:
|
||||||
// ## Goals
|
// ## Goals
|
||||||
// 1. [High] Analyze sales data and identify trends
|
// 1. [High] Analyze sales data and identify trends
|
||||||
// - Reason: Sales up 50%, need to understand why
|
// - Reason: Sales up 50%, need to understand why
|
||||||
// 2. [Normal] Prepare weekly report for manager
|
// - Reason: Friday 5pm, weekly report due
|
||||||
// - Reason: Friday 5pm, weekly report due
|
// - Reason: Friday 5pm, weekly report due
|
||||||
// 3. [Low] Update CRM with new leads
|
|
||||||
// - Reason: 3 pending leads from yesterday
|
|
||||||
type Goals struct {
|
type Goals struct {
|
||||||
Content string `json:"content"` // markdown text
|
// - Reason: 3 pending leads from yesterday
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task - planned task (structured, for execution)
|
// Task - planned task (structured, for execution)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,23 @@ func TestRobotCanRun(t *testing.T) {
|
||||||
assert.True(t, robot.CanRun())
|
assert.True(t, robot.CanRun())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("can run with nil config (uses default quota)", func(t *testing.T) {
|
||||||
|
robot := &types.Robot{
|
||||||
|
Config: nil, // nil config should not panic
|
||||||
|
}
|
||||||
|
// Should not panic and use default max (2)
|
||||||
|
assert.True(t, robot.CanRun())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("can run with nil quota (uses default)", func(t *testing.T) {
|
||||||
|
robot := &types.Robot{
|
||||||
|
Config: &types.Config{
|
||||||
|
Quota: nil, // nil quota should use default
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.True(t, robot.CanRun())
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("cannot run when at quota", func(t *testing.T) {
|
t.Run("cannot run when at quota", func(t *testing.T) {
|
||||||
robot := &types.Robot{
|
robot := &types.Robot{
|
||||||
Config: &types.Config{
|
Config: &types.Config{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue