parseJSONStep 解析 JSON 格式的步骤
(text string)
| 201 | |
| 202 | // parseJSONStep 解析 JSON 格式的步骤 |
| 203 | func (e *Engine) parseJSONStep(text string) (*Step, error) { |
| 204 | // 提取 JSON 代码块 |
| 205 | jsonPattern := regexp.MustCompile("```json\\s*\\n([\\s\\S]*?)\\n```") |
| 206 | matches := jsonPattern.FindStringSubmatch(text) |
| 207 | |
| 208 | var jsonText string |
| 209 | if len(matches) > 1 { |
| 210 | jsonText = matches[1] |
| 211 | } else { |
| 212 | // 尝试直接解析整个文本 |
| 213 | jsonText = text |
| 214 | } |
| 215 | |
| 216 | var step Step |
| 217 | if err := json.Unmarshal([]byte(jsonText), &step); err != nil { |
| 218 | return nil, fmt.Errorf("unmarshal json step: %w", err) |
| 219 | } |
| 220 | |
| 221 | step.Status = StepStatusCompleted |
| 222 | return &step, nil |
| 223 | } |
| 224 | |
| 225 | // parseTextStep 解析文本格式的步骤 |
| 226 | func (e *Engine) parseTextStep(text string) (*Step, error) { |