{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/uphealth-us/json-schema/uphealth-us-cue-result-schema.json",
  "title": "CueResult",
  "description": "The `200` body from `POST /streams/{id}/cue` when a next cue is returned.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/uphealth-us-openapi.json#/components/schemas/CueResult",
  "type": "object",
  "required": [
    "stream_id",
    "state",
    "idempotent",
    "normalized_action",
    "next_cue",
    "_meta"
  ],
  "properties": {
    "stream_id": {
      "type": "integer"
    },
    "state": {
      "$ref": "#/$defs/StreamStateName"
    },
    "idempotent": {
      "type": "boolean",
      "description": "`true` when this response is the cached result of a repeated idempotency_key."
    },
    "normalized_action": {
      "type": [
        "string",
        "null"
      ],
      "description": "`null` when the submitted `response_action` was a recognized value;\notherwise the `acknowledge`-class value the (well-formed but unrecognized)\naction was folded to under forward-compat tolerance. Always present.\n"
    },
    "next_cue": {
      "$ref": "#/$defs/CueObject"
    },
    "_meta": {
      "$ref": "#/$defs/MetaBlock"
    }
  },
  "$defs": {
    "CueArc": {
      "type": "object",
      "description": "Arc position for a spine cue. `source` distinguishes a curated-arc cue\n(`spine`) from a round-robin continuation past the arc's end\n(`corpus_continuation`); the latter carries `source` only, the rest null.\n",
      "required": [
        "source"
      ],
      "properties": {
        "source": {
          "type": "string",
          "enum": [
            "spine",
            "corpus_continuation"
          ],
          "description": "Whether this cue came from the curated spine or the post-arc corpus round-robin."
        },
        "day": {
          "type": [
            "integer",
            "null"
          ],
          "description": "The curated arc day of this message. Null for a corpus-continuation cue."
        },
        "phase": {
          "type": [
            "string",
            "null"
          ],
          "description": "The curated arc phase (e.g. `starting_dose`, `titrating`, `re_entry`). Null for a corpus-continuation cue."
        },
        "seq": {
          "type": [
            "integer",
            "null"
          ],
          "description": "The 1-based position of this message in the spine."
        },
        "total": {
          "type": [
            "integer",
            "null"
          ],
          "description": "The total number of rows in the spine."
        }
      }
    },
    "CueObject": {
      "type": "object",
      "description": "A single cued message — the engine's selection for this step — plus the\nper-cue decision metadata (`receptivity` + `safety`) and arc position\n(`arc` + `day_of_stream`).\n",
      "required": [
        "cue_event_id",
        "message_id",
        "message_class",
        "kind",
        "body",
        "source_url",
        "source_quote",
        "receptivity",
        "safety",
        "arc",
        "day_of_stream",
        "cued_at"
      ],
      "properties": {
        "cue_event_id": {
          "type": "integer",
          "description": "Id of the `cued` event in this stream's event log."
        },
        "message_id": {
          "type": "integer",
          "description": "Id of the underlying message."
        },
        "message_class": {
          "type": "string",
          "description": "The message source class. Always `sandbox_message` in the Discovery sandbox."
        },
        "kind": {
          "type": "string",
          "enum": [
            "fact",
            "list",
            "tip"
          ],
          "description": "The message format."
        },
        "body": {
          "type": "string",
          "description": "The message text to render to the patient."
        },
        "source_url": {
          "type": "string",
          "format": "uri",
          "description": "The federal public-domain source the message is adapted from."
        },
        "source_quote": {
          "type": "string",
          "description": "The supporting quote from the source."
        },
        "receptivity": {
          "$ref": "#/$defs/ReceptivityScore"
        },
        "safety": {
          "$ref": "#/$defs/SafetyVerdict"
        },
        "arc": {
          "description": "Where this cue sits in the template's curated arc, or `null` when the\ncue is not on a spine — the sequencing engine is off, a Discovery\nsandbox stream, or a template with no committed spine. A\ncorpus-continuation cue (past the end of the arc) carries `source`\n(`corpus_continuation`) with `day`/`phase`/`seq`/`total` null.\n",
          "oneOf": [
            {
              "$ref": "#/$defs/CueArc"
            },
            {
              "type": "null"
            }
          ]
        },
        "day_of_stream": {
          "type": [
            "integer",
            "null"
          ],
          "description": "The 1-based wall-clock day the patient is on in this stream (anchored\nto enrollment; to the quit date for the smoking-cessation template).\nAdvisory. `null` on legacy cues issued before day-of-stream tracking.\n"
        },
        "cued_at": {
          "type": "string",
          "format": "date-time",
          "description": "When the cue was issued (ISO 8601, UTC)."
        }
      }
    },
    "MetaBlock": {
      "type": "object",
      "description": "Legal/disclosure block returned on every `200`/`201`. Buyer-facing\nsurfaces — do not strip. The per-cue `receptivity` score + `safety`\nverdict are NOT here — they live ON the cue object (see CueObject).\n",
      "required": [
        "api_version",
        "no_medical_advice",
        "not_samd",
        "license_attribution",
        "delivery_mode",
        "sequencing_ip_notice"
      ],
      "properties": {
        "api_version": {
          "type": "string",
          "description": "The API version that produced this response."
        },
        "no_medical_advice": {
          "type": "boolean",
          "description": "Always `true`. The content is informational, not medical advice."
        },
        "not_samd": {
          "type": "boolean",
          "description": "Always `true`. Not Software as a Medical Device."
        },
        "license_attribution": {
          "type": "string",
          "description": "Content licensing attribution."
        },
        "delivery_mode": {
          "type": "string",
          "enum": [
            "display",
            "deliver"
          ],
          "description": "The stream's delivery mode."
        },
        "sequencing_ip_notice": {
          "type": "string",
          "description": "IP notice covering the proprietary cueing decision."
        }
      }
    },
    "ReceptivityScore": {
      "type": "number",
      "format": "float",
      "minimum": 0,
      "maximum": 1,
      "description": "Advisory receptivity score in `[0.0, 1.0]`, rounded to two decimals. The\nengine's estimate of how receptive this patient is at this cue: `0.50` is\n\"at threshold\" (the neutral state of a brand-new patient with no feedback\nyet); it rises toward `1.0` as the patient engages (`did_it`) and falls\ntoward `0.0` as they disengage (`no_response`). Computed from the patient's\nown feedback on the stream so far (a smoothed engagement mean), not from\nany extra data. Advisory only — what you do with it is your mode's call\n(Display: you decide; Deliver: Reach composes it with its tier model).\n"
    },
    "SafetyVerdict": {
      "type": "object",
      "description": "The audience-safety verdict for the selected message — the `.us`\nsurfacing of the `.me` `safe_to_deliver?` gate. The engine filters\ncandidate messages by the patient's audience tags before selecting, so a\nRETURNED cue is always `included`; this object shows WHY (which tags\nadmitted it), so a buyer can display the audience-safety provenance the\nproduct sells. PHI-free: it carries audience tags + the decision, never\npatient identity.\n",
      "required": [
        "verdict",
        "reason",
        "matched_tags",
        "gating_tags",
        "excluded_tags"
      ],
      "properties": {
        "verdict": {
          "type": "string",
          "enum": [
            "included",
            "filtered"
          ],
          "description": "`included` — the message passed the audience gate for this patient\n(always the case for a returned cue). `filtered` — it would be\nwithheld (surfaced for completeness; a filtered message is never\nreturned as a cue).\n"
        },
        "reason": {
          "type": "string",
          "enum": [
            "unrestricted",
            "tag_match",
            "no_matching_tag",
            "excluded_tag"
          ],
          "description": "`unrestricted` — the message has no audience inclusion tags\n(universal). `tag_match` — the patient matched one of the message's\ninclusion tags. `no_matching_tag` / `excluded_tag` — filtered reasons.\n"
        },
        "matched_tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The inclusion tags the patient matched (why it was admitted). Empty for `unrestricted`."
        },
        "gating_tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The message's audience inclusion tags (the audience it is scoped to). Empty for `unrestricted`."
        },
        "excluded_tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The message's audience exclusion tags, honored against the patient roster."
        },
        "blocked_by": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Present only on a `filtered` `excluded_tag` verdict — the exclusion tag(s) the patient carried that blocked the message."
        }
      }
    },
    "StreamStateName": {
      "type": "string",
      "description": "Stream lifecycle state. v1 sandbox streams move through\n`awaiting_feedback` (between cues) and `ended` (sandbox exhausted).\n`created`, `cueing`, `stalled`, and `errored` are reserved for future\nDeliver-mode work.\n",
      "enum": [
        "created",
        "awaiting_feedback",
        "cueing",
        "ended",
        "stalled",
        "errored"
      ]
    }
  }
}