flowmarkup:
  title: Chat Completion
  version: 1
  description: "Stream LLM token output via yield/onYield for real-time SSE delivery."
  documentation: >
    Demonstrates yield/onYield for LLM token streaming.
    The flow yields each token as it arrives from the AI service,
    enabling real-time SSE streaming to the caller. The caller
    chooses: onYield for streaming, or $yields for collected list.
  requires:
    SERVICES: [claude]
  input:
    prompt: TEXT
  yields:
    $kind: TEXT
    _notes_: Individual tokens from the AI model response.
  output:
    response: TEXT
  examples:
    short_question:
      _notes_: Ask a short question and receive a streamed response
      input:
        prompt: What is the speed of light?
      output:
        response: The speed of light in a vacuum is approximately 299,792,458 metres per second.
    creative_prompt:
      _notes_: Creative writing prompt streamed token by token
      input:
        prompt: Write a haiku about the ocean
      output:
        response: "Waves crash on the shore / Salt and foam in endless dance / Sea returns to calm"

  do:
  - call:
      service: claude
      operation: generate
      timeout: 120s
      params: {prompt: =prompt, stream: true}
      onYield:
        as: token
        do:
        - yield: =token
      result:
        full_response: =RESULT.text
  - return: {response: =full_response}

# ─── Caller examples ─────────────────────────────────────────────
# Streaming consumer — onYield: FORWARD re-yields tokens to caller
#   - run:
#       flow: streaming-llm.flowmarkup.yaml
#       params: {prompt: =user_prompt}
#       onYield: FORWARD
#       result: {answer: =RESULT.response}
#
# Materialized consumer — $yields collects all tokens into a list
#   - run:
#       flow: streaming-llm.flowmarkup.yaml
#       params: {prompt: =user_prompt}
#       result:
#         answer: =RESULT.response
#         all_tokens: =$yields
