Refactor TriggerRequest and InterveneRequest Structures in TECHNICAL.md

- Updated the TriggerRequest and InterveneRequest structs to replace the Description field with an Input field, enhancing clarity on user input for task actions.
- Revised related code examples to reflect the new Input field, ensuring consistency across the implementation.
- Improved documentation comments for better understanding of the changes and their impact on task management.
This commit is contained in:
Max 2026-01-14 16:10:39 +08:00
parent 27bb499fbc
commit 822cccd189

View file

@ -260,11 +260,11 @@ type TriggerRequest struct {
Type types.TriggerType `json:"type"` // human | event Type types.TriggerType `json:"type"` // human | event
// Human intervention fields (when Type = human) // Human intervention fields (when Type = human)
Action types.InterventionAction `json:"action,omitempty"` // task.add | goal.adjust | task.cancel | plan.add Action types.InterventionAction `json:"action,omitempty"` // task.add | goal.adjust | task.cancel | plan.add
Description string `json:"description,omitempty"` // task/goal description Input string `json:"input,omitempty"` // user's input
PlanAt *time.Time `json:"plan_at,omitempty"` // for action=plan.add PlanAt *time.Time `json:"plan_at,omitempty"` // for action=plan.add
InsertAt InsertPosition `json:"insert_at,omitempty"` // where to insert: first | last | next | at InsertAt InsertPosition `json:"insert_at,omitempty"` // where to insert: first | last | next | at
AtIndex int `json:"at_index,omitempty"` // index when insert_at=at AtIndex int `json:"at_index,omitempty"` // index when insert_at=at
// Event fields (when Type = event) // Event fields (when Type = event)
Source types.EventSource `json:"source,omitempty"` // webhook | database Source types.EventSource `json:"source,omitempty"` // webhook | database
@ -366,7 +366,7 @@ const list = Process("robot.List", {
const result = Process("robot.Trigger", "mem_abc123", { const result = Process("robot.Trigger", "mem_abc123", {
type: "human", type: "human",
action: "task.add", action: "task.add",
description: "Prepare meeting materials for BigCorp", input: "Prepare meeting materials for BigCorp",
insert_at: "first", insert_at: "first",
}); });
@ -506,7 +506,7 @@ interface TriggerRequest {
| "plan.remove" | "plan.remove"
| "plan.update" | "plan.update"
| "instruct"; | "instruct";
description?: string; input?: string;
insert_at?: "first" | "last" | "next" | "at"; insert_at?: "first" | "last" | "next" | "at";
at_index?: number; at_index?: number;
plan_at?: string; // ISO date for plan.add plan_at?: string; // ISO date for plan.add
@ -620,7 +620,7 @@ if (state.status === "idle") {
const result = bot.Trigger({ const result = bot.Trigger({
type: "human", type: "human",
action: "task.add", action: "task.add",
description: "Analyze sales data", input: "Analyze sales data",
insert_at: "first", insert_at: "first",
}); });
console.log("Triggered:", result.accepted); console.log("Triggered:", result.accepted);
@ -653,7 +653,7 @@ function Create(ctx, messages) {
const result = bot.Trigger({ const result = bot.Trigger({
type: "human", type: "human",
action: "task.add", action: "task.add",
description: "Analyze this data", input: "Analyze this data",
insert_at: "first", insert_at: "first",
}); });
@ -1211,9 +1211,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.
Description string `json:"description,omitempty"` // user's original input Input string `json:"input,omitempty"` // user's original input
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
@ -1419,12 +1419,12 @@ import (
// InterveneRequest - human intervention request // InterveneRequest - human intervention request
type InterveneRequest struct { type InterveneRequest struct {
TeamID string `json:"team_id"` TeamID string `json:"team_id"`
MemberID string `json:"member_id"` MemberID string `json:"member_id"`
Action InterventionAction `json:"action"` Action InterventionAction `json:"action"`
Description string `json:"description"` Input string `json:"input"`
Priority Priority `json:"priority,omitempty"` Priority Priority `json:"priority,omitempty"`
PlanTime *time.Time `json:"plan_time,omitempty"` // for action=plan PlanTime *time.Time `json:"plan_time,omitempty"` // for action=plan
} }
// EventRequest - event trigger request // EventRequest - event trigger request
@ -1468,84 +1468,56 @@ type RobotState struct {
// types/interfaces.go // types/interfaces.go
package types package types
import ( import "time"
"context"
"time"
)
// ==================== Internal Interfaces ==================== // ==================== Internal Interfaces ====================
// These are internal implementation interfaces, not exposed via API. // These are internal implementation interfaces, not exposed via API.
// External API is defined in api/api.go // External API is defined in api/api.go
// All interfaces use *Context (not context.Context) for consistency.
// Manager - robot lifecycle and clock trigger management // Manager - robot lifecycle and clock trigger management
type Manager interface { type Manager interface {
// Start/Stop the manager (clock ticker, workers)
Start() error Start() error
Stop() error Stop() error
Tick(ctx *Context, now time.Time) error
// Tick - called by internal clock ticker
Tick(ctx context.Context, now time.Time) error
} }
// Executor - executes robot phases // Executor - executes robot phases
type Executor interface { type Executor interface {
// Execute runs all phases for a trigger, returns Execution Execute(ctx *Context, robot *Robot, trigger TriggerType, data interface{}) (*Execution, error)
Execute(ctx context.Context, robot *Robot, trigger TriggerType, data interface{}) (*Execution, error)
} }
// Pool - worker pool for concurrent execution // Pool - worker pool for concurrent execution
type Pool interface { type Pool interface {
// Start/Stop the pool
Start() error Start() error
Stop() error Stop() error
Submit(ctx *Context, robot *Robot, trigger TriggerType, data interface{}) (string, error)
// Submit execution request to pool Running() int
Submit(robot *Robot, trigger TriggerType, data interface{}) (string, error) // returns execID Queued() int
// Stats
Running() int // current running count
Queued() int // current queue size
} }
// Cache - in-memory robot cache // Cache - in-memory robot cache
type Cache interface { type Cache interface {
// Load all active robots from DB Load(ctx *Context) error
Load(ctx context.Context) error
// Get robot by member ID
Get(memberID string) *Robot Get(memberID string) *Robot
// List all cached robots (optionally by team)
List(teamID string) []*Robot List(teamID string) []*Robot
Refresh(ctx *Context, memberID string) error
// Refresh single robot from DB
Refresh(memberID string) error
// Add/Remove (called on member create/delete)
Add(robot *Robot) Add(robot *Robot)
Remove(memberID string) Remove(memberID string)
} }
// Dedup - deduplication check // Dedup - deduplication check
type Dedup interface { type Dedup interface {
// Check if execution should proceed Check(ctx *Context, memberID string, trigger TriggerType) (DedupResult, error)
Check(ctx context.Context, memberID string, trigger TriggerType) (DedupResult, error)
// Mark as executed (for time-window dedup)
Mark(memberID string, trigger TriggerType, window time.Duration) Mark(memberID string, trigger TriggerType, window time.Duration)
} }
// Store - data storage operations (KB, DB) // Store - data storage operations (KB, DB)
type Store interface { type Store interface {
// Private KB operations SaveLearning(ctx *Context, memberID string, entries []LearningEntry) error
SaveLearning(ctx context.Context, memberID string, entries []LearningEntry) error GetHistory(ctx *Context, memberID string, limit int) ([]LearningEntry, error)
GetHistory(ctx context.Context, memberID string, limit int) ([]LearningEntry, error) SearchKB(ctx *Context, collections []string, query string) ([]interface{}, error)
QueryDB(ctx *Context, models []string, query interface{}) ([]interface{}, error)
// Shared KB query
SearchKB(ctx context.Context, collections []string, query string) ([]interface{}, error)
// Shared DB query
QueryDB(ctx context.Context, models []string, query interface{}) ([]interface{}, error)
} }
``` ```