MCPcopy Create free account
hub / github.com/53AI/53AIHub / sendProcessStepRaw

Function sendProcessStepRaw

api/controller/relay/relay_process_step.go:141–187  ·  view source on GitHub ↗
(c *gin.Context, requestId string, hashedStep ProcessStep)

Source from the content-addressed store, hash-verified

139}
140
141func 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
189func shouldSkipProcessStepInCompact(step ProcessStep) bool {
190 // compact 模式只缩减 payload,不再丢弃任何步骤事件。

Callers 2

sendProcessStepFunction · 0.85
flushPendingProcessStepsFunction · 0.85

Calls 6

buildProcessStepPayloadFunction · 0.85
DebugfMethod · 0.80
GetMethod · 0.65
WriteMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected