Add POST/GET/POST cancel task run APIs, background worker with event replay, workspace reconcile, runner child cancel, and chat message metadata updates. Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package taskrun
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
|
|
"chat-agent-system/internal/stream"
|
|
)
|
|
|
|
// CreateRequest 创建后台任务运行实例。
|
|
type CreateRequest struct {
|
|
SessionID string
|
|
ProjectID int64
|
|
UserID int64
|
|
ClientTurnID string
|
|
TaskKey string
|
|
Stage string
|
|
WorkDir string
|
|
UserMessage string
|
|
AssistantMsgID int64
|
|
IncludeDetails bool
|
|
TaskReq any // *server task payload converted to bizdev request at execution layer
|
|
}
|
|
|
|
// RunRecord 运行实例状态。
|
|
type RunRecord struct {
|
|
RunID string
|
|
SessionID string
|
|
ProjectID int64
|
|
UserID int64
|
|
ClientTurnID string
|
|
TaskKey string
|
|
Stage string
|
|
Status string // pending | running | completed | failed | cancelled | status_conflict
|
|
WorkspaceID string
|
|
AssistantMsgID int64
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
ErrorMessage string
|
|
}
|
|
|
|
// StoredEvent 持久化 SSE 事件(支持重连重放)。
|
|
type StoredEvent struct {
|
|
Seq int64
|
|
Event stream.StreamEvent
|
|
}
|
|
|
|
type activeRun struct {
|
|
record *RunRecord
|
|
events []StoredEvent
|
|
nextSeq int64
|
|
subs map[int]chan StoredEvent
|
|
subSeq int
|
|
cancel context.CancelFunc
|
|
done chan struct{}
|
|
mu sync.RWMutex
|
|
}
|