name: "sentiment-score-cli"
type: pipeline

config:
  input:
    stdin:
      codec: all
      max_buffer: 1048576

  pipeline:
    processors:
      - mapping: |
          meta trace_id = uuid_v4()
          root.messages = [
            {"role": "system", "content": "Score the sentiment of text. Return JSON: 'score' (-1 to 1, decimals ok), 'label' (positive/negative/neutral), 'confidence' (0-1). Be precise."},
            {"role": "user", "content": content()}
          ]

      - openai_chat_completion:
          api_key: "${OPENAI_API_KEY}"
          model: gpt-4o-mini

      - mapping: |
          let r = this.choices.0.message.content.parse_json().catch({"score": 0, "label": "neutral"})
          root.score = $r.score
          root.label = $r.label
          root.confidence = $r.confidence.or(0.5)
          root.metadata = {"skill": "sentiment-score", "mode": "cli", "trace_id": meta("trace_id"), "timestamp": now()}

  output:
    stdout:
      codec: json_object
