Template doc_proj ids were skipping CheckDocTaskAccess and returning 400 not-found. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
1.8 KiB
Go
74 lines
1.8 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
|
|
IdempotencyKey string // 新 run 稳定键;旧行保持 NULL 不参与唯一索引
|
|
TaskKey string
|
|
Stage string
|
|
WorkflowInstanceID int64
|
|
StageInstanceID int64
|
|
WorkflowStageKey string
|
|
Status string // pending | running | completed | failed | cancelled | pending_author_confirmation | blocked_pending_governance | …
|
|
WorkspaceID string
|
|
AssistantMsgID int64
|
|
WorkerID string
|
|
LeaseExpiresAt *time.Time
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
ErrorMessage string
|
|
Attempt int
|
|
}
|
|
|
|
// BuildTaskRunIdempotencyKey 新创建用稳定幂等键;空 client_turn 不设键。
|
|
func BuildTaskRunIdempotencyKey(sessionID, clientTurnID string) string {
|
|
if sessionID == "" || clientTurnID == "" {
|
|
return ""
|
|
}
|
|
return "turn:" + sessionID + ":" + clientTurnID
|
|
}
|
|
|
|
// 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
|
|
}
|