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()
|
||||
type TriggerResult struct {
|
||||
Accepted bool `json:"accepted"`
|
||||
Queued bool `json:"queued"`
|
||||
Execution *types.Execution `json:"execution,omitempty"`
|
||||
JobID string `json:"job_id,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Accepted bool `json:"accepted"`
|
||||
Queued bool `json:"queued"`
|
||||
Execution *types.Execution `json:"execution,omitempty"`
|
||||
JobID string `json:"job_id,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// 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 {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
|
||||
memberIDs := c.byTeam[teamID]
|
||||
robots := make([]*types.Robot, 0, len(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) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
|
||||
c.robots[robot.MemberID] = robot
|
||||
|
||||
|
||||
// Update team index
|
||||
if _, exists := c.byTeam[robot.TeamID]; !exists {
|
||||
c.byTeam[robot.TeamID] = []string{}
|
||||
}
|
||||
|
||||
|
||||
// Check if member ID already in team list
|
||||
found := false
|
||||
for _, id := range c.byTeam[robot.TeamID] {
|
||||
|
|
@ -87,14 +87,14 @@ func (c *Cache) Add(robot *types.Robot) {
|
|||
func (c *Cache) Remove(memberID string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
|
||||
robot := c.robots[memberID]
|
||||
if robot == nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
delete(c.robots, memberID)
|
||||
|
||||
|
||||
// Remove from team index
|
||||
teamMembers := c.byTeam[robot.TeamID]
|
||||
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
|
||||
// Relationship: 1 Execution = 1 job.Job
|
||||
type Execution struct {
|
||||
ID string `json:"id"` // unique execution ID
|
||||
MemberID string `json:"member_id"` // robot member ID
|
||||
ID string `json:"id"` // unique execution ID
|
||||
MemberID string `json:"member_id"` // robot member ID
|
||||
TeamID string `json:"team_id"`
|
||||
TriggerType TriggerType `json:"trigger_type"` // clock | human | event
|
||||
StartTime time.Time `json:"start_time"`
|
||||
|
|
@ -120,9 +120,9 @@ type Execution struct {
|
|||
// TriggerInput - stored trigger input for traceability
|
||||
type TriggerInput struct {
|
||||
// For human intervention
|
||||
Action InterventionAction `json:"action,omitempty"` // task.add, goal.adjust, etc.
|
||||
Messages []agentcontext.Message `json:"messages,omitempty"` // user's input (text, images, files)
|
||||
UserID string `json:"user_id,omitempty"` // who triggered
|
||||
Action InterventionAction `json:"action,omitempty"` // task.add, goal.adjust, etc.
|
||||
Messages []agentcontext.Message `json:"messages,omitempty"` // user's input (text, images, files)
|
||||
UserID string `json:"user_id,omitempty"` // who triggered
|
||||
|
||||
// For event trigger
|
||||
Source EventSource `json:"source,omitempty"` // webhook | database
|
||||
|
|
@ -145,13 +145,11 @@ type CurrentState struct {
|
|||
// Example:
|
||||
// ## Goals
|
||||
// 1. [High] Analyze sales data and identify trends
|
||||
// - Reason: Sales up 50%, need to understand why
|
||||
// 2. [Normal] Prepare weekly report for manager
|
||||
// - Reason: Friday 5pm, weekly report due
|
||||
// 3. [Low] Update CRM with new leads
|
||||
// - Reason: 3 pending leads from yesterday
|
||||
// - Reason: Sales up 50%, need to understand why
|
||||
// - Reason: Friday 5pm, weekly report due
|
||||
// - Reason: Friday 5pm, weekly report due
|
||||
type Goals struct {
|
||||
Content string `json:"content"` // markdown text
|
||||
// - Reason: 3 pending leads from yesterday
|
||||
}
|
||||
|
||||
// Task - planned task (structured, for execution)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,23 @@ func TestRobotCanRun(t *testing.T) {
|
|||
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) {
|
||||
robot := &types.Robot{
|
||||
Config: &types.Config{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue