Class OpenCodeCallbackParser

java.lang.Object
io.github.easy4j.opencode.api.mapper.OpenCodeCallbackParser

public class OpenCodeCallbackParser extends Object
Parses callback JSON from OpenCode AI text responses.

OpenCode does not have a native webhook/callback mechanism. This parser attempts to extract JSON blocks from the AI's text response, following the format conventions defined by cloud-agents prompt templates (e.g., the callback_url output format specified in SKILL.md).

The parser tries three strategies in order:

  1. Extract JSON from ```json ... ``` fenced code blocks
  2. Parse the entire text as JSON directly
  3. Extract bare JSON objects containing task_id, taskId, or title
Since:
1.0.0
Author:
Loong Wan
See Also:
  • Constructor Details

    • OpenCodeCallbackParser

      public OpenCodeCallbackParser()
  • Method Details

    • parseFromPromptResult

      public Map<String,Object> parseFromPromptResult(PromptResult result)
      从 PromptResult 中提取文本内容并解析为 Map。
      Parameters:
      result - OpenCode Prompt 执行结果
      Returns:
      OpenCode Server 返回的键值映射;无数据时为空映射
    • parseFromText

      public Map<String,Object> parseFromText(String text)
      从纯文本中尝试提取并解析 JSON。
      Parameters:
      text - 发送给模型的文本内容
      Returns:
      OpenCode Server 返回的键值映射;无数据时为空映射