KTD1 second step (behavior preserved): - squad defines ProgressSink (EmitPhase/Detail/Deliverable/Summary/Briefing) with its own DetailEvent/ToolEvent types; zero internal/stream imports left - bizdev assembly maps port to SSE streamer (squad_progress_adapter) and injects via ctx at the four squad entry points - process_bridge tests rewritten as port-contract tests (captureSink) - verified: build+vet clean, squad/bizdev/archtest green
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package bizdev
|
|
|
|
import (
|
|
"context"
|
|
|
|
"chat-agent-system/internal/squad"
|
|
"chat-agent-system/internal/stream"
|
|
)
|
|
|
|
// squadProgressAdapter 把小队过程端口映射到产品 SSE 流(KTD1 装配侧)。
|
|
// 小队不感知 stream 包;SSE 事件形态、持久化与重放由产品侧全权负责。
|
|
type squadProgressAdapter struct {
|
|
streamer *stream.Streamer
|
|
}
|
|
|
|
func (a *squadProgressAdapter) EmitPhase(phaseID, message, role string, stepIndex, totalSteps, progress int) {
|
|
a.streamer.EmitPhase(phaseID, message, role, stepIndex, totalSteps, progress)
|
|
}
|
|
|
|
func (a *squadProgressAdapter) EmitDetail(p squad.DetailEvent) {
|
|
var tool *stream.ToolCallInfo
|
|
if p.Tool != nil {
|
|
tool = &stream.ToolCallInfo{
|
|
Name: p.Tool.Name,
|
|
Status: p.Tool.Status,
|
|
Input: p.Tool.Input,
|
|
Output: p.Tool.Output,
|
|
DurationMs: p.Tool.DurationMs,
|
|
}
|
|
}
|
|
a.streamer.Emit(stream.StreamEvent{Type: stream.EventDetail, Detail: &stream.DetailPayload{
|
|
Category: p.Category,
|
|
StepID: p.StepID,
|
|
Role: p.Role,
|
|
ItemID: p.ItemID,
|
|
Title: p.Title,
|
|
Content: p.Content,
|
|
Collapsible: p.Collapsible,
|
|
Delta: p.Delta,
|
|
Done: p.Done,
|
|
Tool: tool,
|
|
}})
|
|
}
|
|
|
|
func (a *squadProgressAdapter) EmitDeliverable(taskKey, title, filePath string, wordCount int, score float64) {
|
|
a.streamer.EmitDeliverable(taskKey, title, filePath, wordCount, score)
|
|
}
|
|
|
|
func (a *squadProgressAdapter) EmitSummary(title, content string, maturityScore int, maturityLevel string) {
|
|
a.streamer.EmitSummary(title, content, maturityScore, maturityLevel)
|
|
}
|
|
|
|
func (a *squadProgressAdapter) EmitBriefing(brief any) {
|
|
a.streamer.EmitBriefing(brief)
|
|
}
|
|
|
|
// withSquadProgress 在调用小队前装配过程端口:ctx 已有 Streamer 时注入适配器,
|
|
// 否则原样返回(小队对缺失端口全程 no-op,行为与旧版 streamer==nil 分支一致)。
|
|
func withSquadProgress(ctx context.Context) context.Context {
|
|
st := stream.FromContext(ctx)
|
|
if st == nil {
|
|
return ctx
|
|
}
|
|
return squad.WithProgress(ctx, &squadProgressAdapter{streamer: st})
|
|
}
|