chore: 初始化 eightbf-analysis-go(对齐 Java 会商作业服务)

Go 实现 /api/v1/analysis 契约、Demo/Live Worker、DeerFlow SSE;含设计文档与冒烟脚本。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
gozerosandCursor committed 2026-11-03 00:13:46 +08:00
commit 0c45b86d67
29 files changed
+3789

No files matched your search

+217
View File
@@ -0,0 +1,217 @@
package service
import (
"fmt"
"strings"
"git.gozeros.com/wsk/eightbf-analysis-go/internal/domain"
)
const (
RoleAdmin = "admin"
RoleTaskOwner = "task_owner"
RolePositionOwner = "position_owner"
RoleViewer = "viewer"
)
// Caller 当前请求调用方(来自 X-Account-Id / X-Analysis-Role)。
type Caller struct {
AccountID string
Role string
}
func NewCaller(accountID, role string) Caller {
r := strings.TrimSpace(role)
if r == "" {
r = RoleViewer
}
return Caller{AccountID: strings.TrimSpace(accountID), Role: r}
}
// AccessService 岗位账号限制与对话投影。
type AccessService struct {
AuthEnabled bool
}
func (a *AccessService) CanMutate(job *domain.AnalysisJob, c Caller) bool {
if !a.AuthEnabled {
return true
}
if c.AccountID == "" {
return false
}
if c.Role == RoleAdmin || c.Role == RoleTaskOwner {
return true
}
if c.AccountID == strings.TrimSpace(job.OwnerAccountID) {
return true
}
if a.isListedTaskOwner(job, c.AccountID) {
return true
}
return c.Role == RolePositionOwner && len(a.boundSeats(job, c.AccountID)) > 0
}
func (a *AccessService) CanCancel(job *domain.AnalysisJob, c Caller) bool {
if c.Role == RolePositionOwner {
if c.AccountID == strings.TrimSpace(job.OwnerAccountID) || a.isListedTaskOwner(job, c.AccountID) {
return true
}
return false
}
if !a.AuthEnabled {
return true
}
if c.AccountID == "" {
return false
}
if c.Role == RoleAdmin || c.Role == RoleTaskOwner {
return true
}
if c.AccountID == strings.TrimSpace(job.OwnerAccountID) {
return true
}
return a.isListedTaskOwner(job, c.AccountID)
}
func (a *AccessService) CanRead(job *domain.AnalysisJob, c Caller) bool {
if !a.AuthEnabled {
return true
}
if c.AccountID == "" {
return false
}
if a.CanMutate(job, c) || a.CanCancel(job, c) {
return true
}
return len(a.boundSeats(job, c.AccountID)) > 0
}
// ProjectForCaller 按角色裁剪对话后返回(责任人全量;岗位只见本席+总控/系统)。
func (a *AccessService) ProjectForCaller(job *domain.AnalysisJob, c Caller) *domain.AnalysisJob {
if job == nil {
return nil
}
if c.AccountID == "" {
return job
}
if c.Role == RoleAdmin || c.Role == RoleTaskOwner ||
c.AccountID == strings.TrimSpace(job.OwnerAccountID) ||
a.isListedTaskOwner(job, c.AccountID) {
return job
}
if c.Role != RolePositionOwner && !a.AuthEnabled {
return job
}
seats := a.boundSeats(job, c.AccountID)
copyJob := *job
if len(seats) == 0 {
var filtered []map[string]interface{}
for _, d := range job.Dialogues {
role := asStr(d["role"])
if role == "system" || role == "user" {
filtered = append(filtered, d)
}
}
copyJob.Dialogues = filtered
if job.Result != nil {
r := cloneMap(job.Result)
delete(r, "seatDeliveries")
copyJob.Result = r
}
return &copyJob
}
var filtered []map[string]interface{}
for _, d := range job.Dialogues {
role := asStr(d["role"])
agentID := asStr(d["agentId"])
if role == "system" || role == "user" || role == "leader" {
filtered = append(filtered, d)
} else if seats[agentID] {
filtered = append(filtered, d)
}
}
copyJob.Dialogues = filtered
if job.Result != nil {
r := cloneMap(job.Result)
if raw, ok := r["seatDeliveries"].([]interface{}); ok {
var kept []interface{}
for _, o := range raw {
m, ok := o.(map[string]interface{})
if !ok {
continue
}
if seats[asStr(m["agentId"])] {
kept = append(kept, m)
}
}
r["seatDeliveries"] = kept
}
copyJob.Result = r
}
return &copyJob
}
func (a *AccessService) boundSeats(job *domain.AnalysisJob, accountID string) map[string]bool {
out := map[string]bool{}
if job == nil || accountID == "" || job.Access == nil {
return out
}
raw, ok := job.Access["seatAccounts"]
if !ok {
return out
}
m, ok := raw.(map[string]interface{})
if !ok {
return out
}
for k, v := range m {
if accountInList(v, accountID) {
out[k] = true
}
}
return out
}
func (a *AccessService) isListedTaskOwner(job *domain.AnalysisJob, accountID string) bool {
if job == nil || job.Access == nil {
return false
}
return accountInList(job.Access["taskOwnerAccountIds"], accountID) ||
accountInList(job.Access["adminAccountIds"], accountID)
}
func accountInList(raw interface{}, accountID string) bool {
if raw == nil || accountID == "" {
return false
}
switch t := raw.(type) {
case []interface{}:
for _, o := range t {
if strings.TrimSpace(asStr(o)) == accountID {
return true
}
}
return false
default:
return strings.TrimSpace(asStr(raw)) == accountID
}
}
func cloneMap(m map[string]interface{}) map[string]interface{} {
out := make(map[string]interface{}, len(m))
for k, v := range m {
out[k] = v
}
return out
}
func asStr(v interface{}) string {
if v == nil {
return ""
}
if s, ok := v.(string); ok {
return s
}
return strings.TrimSpace(fmt.Sprint(v))
}
+50
View File
@@ -0,0 +1,50 @@
package service
import (
"testing"
"git.gozeros.com/wsk/eightbf-analysis-go/internal/domain"
)
func TestPositionOwnerProjection(t *testing.T) {
a := &AccessService{AuthEnabled: false}
job := &domain.AnalysisJob{
OwnerAccountID: "owner1",
Access: map[string]interface{}{
"seatAccounts": map[string]interface{}{
"seat-a": []interface{}{"acc-a"},
},
},
Dialogues: []map[string]interface{}{
{"role": "leader", "agentId": "coord", "content": "派活"},
{"role": "special", "agentId": "seat-a", "content": "本席"},
{"role": "special", "agentId": "seat-b", "content": "它席"},
{"role": "user", "content": "我说"},
},
}
out := a.ProjectForCaller(job, NewCaller("acc-a", RolePositionOwner))
if len(out.Dialogues) != 3 {
t.Fatalf("期望 3 条(leader+本席+user),得到 %d", len(out.Dialogues))
}
for _, d := range out.Dialogues {
if asStr(d["agentId"]) == "seat-b" {
t.Fatal("岗位责任人不应看到它席气泡")
}
}
}
func TestPositionOwnerCannotCancel(t *testing.T) {
a := &AccessService{AuthEnabled: false}
job := &domain.AnalysisJob{
OwnerAccountID: "owner1",
Access: map[string]interface{}{
"seatAccounts": map[string]interface{}{"seat-a": []interface{}{"acc-a"}},
},
}
if a.CanCancel(job, NewCaller("acc-a", RolePositionOwner)) {
t.Fatal("岗位责任人默认不能 cancel")
}
if !a.CanMutate(job, NewCaller("acc-a", RolePositionOwner)) {
t.Fatal("岗位责任人应可 resume/inject")
}
}
+277
View File
@@ -0,0 +1,277 @@
package service
import (
"log"
"strconv"
"time"
"git.gozeros.com/wsk/eightbf-analysis-go/internal/domain"
"git.gozeros.com/wsk/eightbf-analysis-go/internal/repo"
)
// DemoWorker 假进度推进(仅 ANALYSIS_MODE=demo)。
type DemoWorker struct {
Repo *repo.JobRepo
Every time.Duration
}
var demoLines = []string{
"【演示】我先说观点:当前应先收窄目标,再谈方案细节。",
"【演示】节奏上建议短周期验证,避免一次铺太开。",
"【演示】依赖和数据口径要尽早对齐,否则后面容易返工。",
"【演示】成本先压到能证明价值的最小投入。",
"【演示】主要风险是范围蔓延和决策偏慢,需要明确拍板人。",
"【演示】我同意形成一版可执行共识,可以进入总结。",
}
const charsPerTick = 8
func (w *DemoWorker) Start() {
if w.Every <= 0 {
w.Every = 400 * time.Millisecond
}
go func() {
t := time.NewTicker(w.Every)
defer t.Stop()
for range t.C {
list, err := w.Repo.FindActiveJobs()
if err != nil {
continue
}
for _, job := range list {
if err := w.advance(job); err != nil {
log.Printf("demo worker advance failed jobId=%s: %v", job.ID, err)
job.Status = domain.StatusError
job.Phase = "error"
job.Error = err.Error()
_ = w.Repo.UpdateProgress(job)
}
}
}
}()
}
func (w *DemoWorker) advance(job *domain.AnalysisJob) error {
if ok, _ := w.Repo.IsCancelFlag(job.ID); ok {
finishCurrentBubble(job, "cancelled")
job.Status = domain.StatusCancelled
job.Phase = "cancelled"
job.Error = "cancelled"
p := job.EnsureProgress()
p["message"] = "cancelled"
return w.Repo.UpdateProgress(job)
}
if job.Status == domain.StatusAwaitingInput {
return nil
}
agents := job.Agents
if agents == nil {
agents = []map[string]interface{}{}
}
agentCount := len(agents)
if agentCount < 1 {
agentCount = 1
}
dialogues := job.EnsureDialogues()
progress := job.EnsureProgress()
if job.Status == domain.StatusQueued {
job.Status = domain.StatusRunning
job.Phase = "analyzing"
job.Cycle = 1
progress["percent"] = 5
progress["message"] = "席位开始发言"
progress["lineIndex"] = 0
progress["charIndex"] = 0
applyAgentStatus(agents, 0, "speaking")
job.ActiveAgentID = agentIDAt(agents, 0)
job.Agents = agents
openDemoBubble(job, dialogues, agents, 0, "席位输出中…")
// openDemoBubble 已写回 job.Dialogues;切勿再用旧 dialogues 切片盖掉新气泡
return w.Repo.UpdateProgress(job)
}
lineIndex := toIntVal(progress["lineIndex"], 0)
charIndex := toIntVal(progress["charIndex"], 0)
if lineIndex < len(demoLines) {
speakerIdx := lineIndex % agentCount
wantAgent := agentIDAt(agents, speakerIdx)
if job.ActiveAgentID != wantAgent || (charIndex == 0 && !hasStreaming(dialogues)) {
if charIndex == 0 {
finishCurrentBubble(job, "")
for i := range agents {
st := "listening"
if i == speakerIdx {
st = "speaking"
}
applyAgentStatus(agents, i, st)
}
job.ActiveAgentID = wantAgent
openDemoBubble(job, dialogues, agents, speakerIdx, "席位输出中…")
dialogues = job.Dialogues
}
}
line := demoLines[lineIndex]
end := charIndex + charsPerTick
if end > len([]rune(line)) {
end = len([]rune(line))
}
rs := []rune(line)
if end > charIndex {
appendStreaming(dialogues, string(rs[charIndex:end]))
charIndex = end
}
if charIndex >= len(rs) {
appendStreaming(dialogues, "\n\n")
finishCurrentBubble(job, "")
lineIndex++
charIndex = 0
}
totalChars := 0
for _, l := range demoLines {
totalChars += len([]rune(l))
}
doneChars := 0
for i := 0; i < lineIndex && i < len(demoLines); i++ {
doneChars += len([]rune(demoLines[i]))
}
doneChars += charIndex
percent := 5 + (doneChars*85)/max(totalChars, 1)
if percent > 90 {
percent = 90
}
progress["lineIndex"] = lineIndex
progress["charIndex"] = charIndex
progress["percent"] = percent
progress["message"] = "发言中 " + itoa(percent) + "%"
job.Cycle = 1 + lineIndex/max(agentCount, 1)
job.ConsensusPercentage = min(95, percent)
job.Agents = agents
job.Dialogues = dialogues
return w.Repo.UpdateProgress(job)
}
finishCurrentBubble(job, "")
summary := "【演示总结】以上均为占位发言,用于验证「关浏览器后任务仍继续 + 页面流式展示」。" +
"接入真实模型后,这里会换成总控根据各席发言生成的真正总结。" +
"(job=" + job.ID + ")"
dialogues = append(dialogues, map[string]interface{}{
"id": "dlg_" + job.ID + "_leader", "role": "leader", "sender": "总控协调",
"agentId": "coordinator", "content": summary, "status": "done", "phaseLabel": "全案盖印",
})
for i := range agents {
applyAgentStatus(agents, i, "done")
}
job.ActiveAgentID = ""
job.Agents = agents
job.Status = domain.StatusDone
job.Phase = "done"
job.ConsensusPercentage = 100
progress["percent"] = 100
progress["message"] = "completed"
job.Dialogues = dialogues
job.Result = map[string]interface{}{
"summary": summary,
"consensusPercentage": 100,
"recommendations": []string{"确认产品边界与里程碑", "补充关键风险与资源假设", "安排下一轮执行评审"},
}
return w.Repo.UpdateProgress(job)
}
func openDemoBubble(job *domain.AnalysisJob, dialogues, agents []map[string]interface{}, idx int, phase string) {
bubble := map[string]interface{}{
"id": "dlg_" + job.ID + "_" + itoa(len(dialogues)+1), "role": "special",
"sender": agentNameAt(agents, idx), "agentId": agentIDAt(agents, idx),
"content": "", "status": "streaming", "phaseLabel": phase,
}
job.Dialogues = append(dialogues, bubble)
}
func finishCurrentBubble(job *domain.AnalysisJob, override string) {
for i := len(job.Dialogues) - 1; i >= 0; i-- {
b := job.Dialogues[i]
if asStr(b["status"]) == "streaming" {
st := "done"
if override != "" {
st = override
}
b["status"] = st
b["phaseLabel"] = ""
return
}
}
}
func appendStreaming(dialogues []map[string]interface{}, chunk string) {
for i := len(dialogues) - 1; i >= 0; i-- {
b := dialogues[i]
if asStr(b["status"]) == "streaming" {
b["content"] = asStr(b["content"]) + chunk
return
}
}
}
func hasStreaming(dialogues []map[string]interface{}) bool {
for i := len(dialogues) - 1; i >= 0; i-- {
if asStr(dialogues[i]["status"]) == "streaming" {
return true
}
}
return false
}
func agentIDAt(agents []map[string]interface{}, idx int) string {
if len(agents) == 0 {
return ""
}
return asStr(agents[idx%len(agents)]["id"])
}
func agentNameAt(agents []map[string]interface{}, idx int) string {
if len(agents) == 0 {
return "席位"
}
a := agents[idx%len(agents)]
if n := asStr(a["name"]); n != "" {
return n
}
return asStr(a["id"])
}
func applyAgentStatus(agents []map[string]interface{}, idx int, status string) {
if idx < 0 || idx >= len(agents) {
return
}
agents[idx]["status"] = status
}
func toIntVal(v interface{}, def int) int {
switch t := v.(type) {
case int:
return t
case int64:
return int(t)
case float64:
return int(t)
default:
return def
}
}
func itoa(n int) string { return strconv.Itoa(n) }
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
+23
View File
@@ -0,0 +1,23 @@
package service
import "errors"
// 业务错误:HTTP 层按类型映射 403/400。
var (
ErrForbidden = errors.New("forbidden")
ErrBadState = errors.New("bad state")
ErrBadArg = errors.New("bad argument")
)
// BizError 带给人看的文案。
type BizError struct {
Kind error
Msg string
}
func (e *BizError) Error() string { return e.Msg }
func (e *BizError) Unwrap() error { return e.Kind }
func Forbidden(msg string) error { return &BizError{Kind: ErrForbidden, Msg: msg} }
func BadState(msg string) error { return &BizError{Kind: ErrBadState, Msg: msg} }
func BadArg(msg string) error { return &BizError{Kind: ErrBadArg, Msg: msg} }
+352
View File
@@ -0,0 +1,352 @@
package service
import (
"crypto/rand"
"encoding/hex"
"strconv"
"strings"
"git.gozeros.com/wsk/eightbf-analysis-go/internal/domain"
"git.gozeros.com/wsk/eightbf-analysis-go/internal/repo"
)
// CreateJobRequest 创建会商作业入参。
type CreateJobRequest struct {
RequestID string `json:"requestId"`
TaskID string `json:"taskId"`
DraftID string `json:"draftId"`
DraftKey string `json:"draftKey"`
Model string `json:"model"`
OrchestrationMode string `json:"orchestrationMode"`
Title string `json:"title"`
Description string `json:"description"`
OwnerAccountID string `json:"ownerAccountId"`
ManualIntervention *bool `json:"manualIntervention"`
Agents []map[string]interface{} `json:"agents"`
Payload map[string]interface{} `json:"payload"`
Access map[string]interface{} `json:"access"`
}
type ResumeJobRequest struct {
Answer string `json:"answer"`
Reason string `json:"reason"`
}
type PatchJobPlanRequest struct {
ManualIntervention *bool `json:"manualIntervention"`
Model *string `json:"model"`
}
type InjectJobRequest struct {
Text string `json:"text"`
}
// JobService 会商作业编排(不直接调大模型)。
type JobService struct {
Repo *repo.JobRepo
Access *AccessService
}
func (s *JobService) Create(req *CreateJobRequest, caller Caller) (*domain.AnalysisJob, error) {
if req == nil {
req = &CreateJobRequest{}
}
manual := true
if req.ManualIntervention != nil {
manual = *req.ManualIntervention
}
owner := blankToNull(req.OwnerAccountID)
if owner == "" && caller.AccountID != "" {
owner = caller.AccountID
}
mode := blankToNull(req.OrchestrationMode)
if mode == "" {
mode = "roundtable"
}
job := &domain.AnalysisJob{
ID: "job_" + randHex(8),
RequestID: firstNonEmpty(blankToNull(req.RequestID), "req_"+randHex(6)),
TaskID: blankToNull(req.TaskID),
DraftID: blankToNull(req.DraftID),
DraftKey: blankToNull(req.DraftKey),
Status: domain.StatusQueued,
Phase: "queued",
OrchestrationMode: mode,
Model: strings.TrimSpace(req.Model),
OwnerAccountID: owner,
Agents: normalizeAgents(req.Agents),
Dialogues: []map[string]interface{}{},
Access: orEmptyMap(req.Access),
Plan: map[string]interface{}{
"seatIndex": 0,
"manualIntervention": manual,
"seedMessage": nil,
"pendingInject": nil,
"awaitReason": nil,
},
Progress: map[string]interface{}{
"percent": 0,
"message": "queued",
"title": req.Title,
"description": req.Description,
},
}
if req.Payload != nil {
job.Progress["payload"] = req.Payload
}
if err := s.Repo.Insert(job); err != nil {
return nil, err
}
return s.Access.ProjectForCaller(job, caller), nil
}
func (s *JobService) Get(id string, caller Caller) (*domain.AnalysisJob, error) {
job, err := s.Repo.FindByID(id)
if err != nil || job == nil {
return job, err
}
if !s.Access.CanRead(job, caller) {
return nil, Forbidden("无权查看该会商作业")
}
return s.Access.ProjectForCaller(job, caller), nil
}
func (s *JobService) GetByTaskID(taskID string, latestOnly bool, caller Caller) (*domain.AnalysisJob, error) {
var job *domain.AnalysisJob
var err error
if latestOnly {
job, err = s.Repo.FindLatestByTaskID(taskID)
} else {
job, err = s.Repo.FindActiveByTaskID(taskID)
if err == nil && job == nil {
job, err = s.Repo.FindLatestByTaskID(taskID)
}
}
if err != nil || job == nil {
return job, err
}
if !s.Access.CanRead(job, caller) {
return nil, Forbidden("无权查看该会商作业")
}
return s.Access.ProjectForCaller(job, caller), nil
}
func (s *JobService) Cancel(id string, caller Caller) (*domain.AnalysisJob, error) {
job, err := s.Repo.FindByID(id)
if err != nil || job == nil {
return job, err
}
if !s.Access.CanCancel(job, caller) {
return nil, Forbidden("无权取消该会商作业(仅任务责任人/创建人/管理员)")
}
if domain.IsTerminal(job.Status) {
return s.Access.ProjectForCaller(job, caller), nil
}
_, _ = s.Repo.MarkCancel(id)
job.Status = domain.StatusCancelled
job.Phase = "cancelled"
job.Error = "cancelled by client"
p := job.EnsureProgress()
p["message"] = "cancelled"
if err := s.Repo.UpdateProgress(job); err != nil {
return nil, err
}
return s.Access.ProjectForCaller(job, caller), nil
}
func (s *JobService) Resume(id string, body *ResumeJobRequest, caller Caller) (*domain.AnalysisJob, error) {
job, err := s.Repo.FindByID(id)
if err != nil || job == nil {
return job, err
}
if !s.Access.CanMutate(job, caller) {
return nil, Forbidden("无权续跑该会商作业")
}
if job.Status != domain.StatusAwaitingInput {
return nil, BadState("当前状态不是等待输入,无法 resume(status=" + job.Status + ")")
}
answer := ""
if body != nil {
answer = strings.TrimSpace(body.Answer)
}
plan := job.EnsurePlan()
if answer != "" {
appendUserDialogue(job, answer)
prev := asStr(plan["pendingInject"])
merged := answer
if strings.TrimSpace(prev) != "" {
merged = prev + "\n\n" + answer
}
plan["pendingInject"] = "用户对澄清的回复:\n" + merged
}
plan["awaitReason"] = nil
job.PendingClarification = ""
job.Status = domain.StatusQueued
job.Phase = "resume_queued"
p := job.EnsureProgress()
p["message"] = "已收到补充,准备继续"
if err := s.Repo.UpdateProgress(job); err != nil {
return nil, err
}
fresh, err := s.Repo.FindByID(id)
if err != nil {
return nil, err
}
return s.Access.ProjectForCaller(fresh, caller), nil
}
func (s *JobService) PatchPlan(id string, body *PatchJobPlanRequest, caller Caller) (*domain.AnalysisJob, error) {
job, err := s.Repo.FindByID(id)
if err != nil || job == nil {
return job, err
}
if !s.Access.CanMutate(job, caller) {
return nil, Forbidden("无权修改该会商作业设置")
}
if domain.IsTerminal(job.Status) {
return nil, BadState("作业已结束,无法修改设置")
}
if body == nil {
return s.Access.ProjectForCaller(job, caller), nil
}
touched := false
plan := job.EnsurePlan()
progress := job.EnsureProgress()
if body.Model != nil {
model := strings.TrimSpace(*body.Model)
job.Model = model
if model == "" {
progress["message"] = "已清除模型指定(用默认)"
} else {
progress["message"] = "已切换模型为 " + model
}
touched = true
}
if body.ManualIntervention != nil {
manual := *body.ManualIntervention
plan["manualIntervention"] = manual
if manual {
progress["message"] = "已开启人工干预(下一席结束后将等待确认)"
} else {
progress["message"] = "已关闭人工干预(将自动连跑)"
}
touched = true
atGate := job.Status == domain.StatusAwaitingInput && asStr(plan["awaitReason"]) == "manual_continue"
if !manual && atGate {
plan["awaitReason"] = nil
job.PendingClarification = ""
job.Status = domain.StatusQueued
job.Phase = "resume_queued"
progress["message"] = "已关闭人工干预,自动继续下一席"
}
}
if !touched {
return s.Access.ProjectForCaller(job, caller), nil
}
if err := s.Repo.UpdateProgress(job); err != nil {
return nil, err
}
fresh, err := s.Repo.FindByID(id)
if err != nil {
return nil, err
}
return s.Access.ProjectForCaller(fresh, caller), nil
}
func (s *JobService) Inject(id string, body *InjectJobRequest, caller Caller) (*domain.AnalysisJob, error) {
job, err := s.Repo.FindByID(id)
if err != nil || job == nil {
return job, err
}
if !s.Access.CanMutate(job, caller) {
return nil, Forbidden("无权向该会商注入消息")
}
text := ""
if body != nil {
text = strings.TrimSpace(body.Text)
}
if text == "" {
return nil, BadArg("注入内容不能为空")
}
if domain.IsTerminal(job.Status) {
return nil, BadState("作业已结束,无法注入")
}
appendUserDialogue(job, text)
plan := job.EnsurePlan()
prev := asStr(plan["pendingInject"])
merged := text
if strings.TrimSpace(prev) != "" {
merged = prev + "\n\n" + text
}
plan["pendingInject"] = "用户向会商插入的补充说明:\n" + merged
p := job.EnsureProgress()
p["message"] = "已收到用户补充,将在下一轮派活时带入"
if err := s.Repo.UpdateProgress(job); err != nil {
return nil, err
}
fresh, err := s.Repo.FindByID(id)
if err != nil {
return nil, err
}
return s.Access.ProjectForCaller(fresh, caller), nil
}
func appendUserDialogue(job *domain.AnalysisJob, text string) {
list := job.EnsureDialogues()
bubble := map[string]interface{}{
"id": "dlg_" + job.ID + "_user_" + strconv.Itoa(len(list)+1),
"role": "user",
"sender": "我",
"content": text,
"status": "done",
"phaseLabel": "",
}
job.Dialogues = append(list, bubble)
}
func normalizeAgents(agents []map[string]interface{}) []map[string]interface{} {
if len(agents) > 0 {
out := make([]map[string]interface{}, 0, len(agents))
for _, a := range agents {
copy := cloneMap(a)
if _, ok := copy["id"]; !ok {
if aid, ok := copy["agentId"]; ok {
copy["id"] = aid
}
}
if _, ok := copy["status"]; !ok {
copy["status"] = "idle"
}
out = append(out, copy)
}
return out
}
return []map[string]interface{}{
{"id": "local-flow-stub-intel", "name": "联调桩-情报采集", "status": "idle"},
{"id": "local-flow-stub-plan", "name": "联调桩-筹划规划", "status": "idle"},
}
}
func blankToNull(s string) string {
return strings.TrimSpace(s)
}
func firstNonEmpty(a, b string) string {
if a != "" {
return a
}
return b
}
func orEmptyMap(m map[string]interface{}) map[string]interface{} {
if m == nil {
return map[string]interface{}{}
}
return m
}
func randHex(nBytes int) string {
b := make([]byte, nBytes)
_, _ = rand.Read(b)
return hex.EncodeToString(b)
}