(c *gin.Context, requestId string, hashedStep ProcessStep)
| 139 | } |
| 140 | |
| 141 | func sendProcessStepRaw(c *gin.Context, requestId string, hashedStep ProcessStep) error { |
| 142 | if streamDone, exists := c.Get("stream_response_done"); exists { |
| 143 | if done, ok := streamDone.(bool); ok && done { |
| 144 | return nil |
| 145 | } |
| 146 | } |
| 147 | if hashedStep.StepCode != "llm_delta" { |
| 148 | logger.SysLogf( |
| 149 | "步骤 step=%s status=%s name=%s msg=%s", |
| 150 | hashedStep.StepCode, |
| 151 | hashedStep.Status, |
| 152 | hashedStep.Name, |
| 153 | hashedStep.Message, |
| 154 | ) |
| 155 | } |
| 156 | payload := buildProcessStepPayload(requestId, hashedStep) |
| 157 | |
| 158 | b, err := json.Marshal(payload) |
| 159 | if err != nil { |
| 160 | return err |
| 161 | } |
| 162 | var reqCtx context.Context |
| 163 | if c.Request != nil { |
| 164 | reqCtx = c.Request.Context() |
| 165 | } else { |
| 166 | reqCtx = context.Background() |
| 167 | } |
| 168 | if hashedStep.StepCode == STEP_REF_ANALYSIS { |
| 169 | logger.Debugf(reqCtx, "【引用分析】准备写入前的 payload: request_id=%s, payload=%s", |
| 170 | requestId, string(b)) |
| 171 | } |
| 172 | |
| 173 | chunk := append([]byte("data: "), b...) |
| 174 | chunk = append(chunk, []byte("\n\n")...) |
| 175 | |
| 176 | logger.Debugf(reqCtx, "【SSE发送】step=%s, request_id=%s, 完整包体=\n%s", |
| 177 | hashedStep.StepCode, requestId, string(chunk)) |
| 178 | |
| 179 | if _, err := c.Writer.Write(chunk); err != nil { |
| 180 | return err |
| 181 | } |
| 182 | if flusher, ok := c.Writer.(http.Flusher); ok { |
| 183 | flusher.Flush() |
| 184 | } |
| 185 | mirrorAgentRunTimelineEvent(c, requestId, model.AgentRunEventProcessStep, payload) |
| 186 | return nil |
| 187 | } |
| 188 | |
| 189 | func shouldSkipProcessStepInCompact(step ProcessStep) bool { |
| 190 | // compact 模式只缩减 payload,不再丢弃任何步骤事件。 |
no test coverage detected