File size: 9,326 Bytes
1e3bc19 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "ai-stream.schema.json",
"title": "AiStreamEvent",
"description": "One event of the v2 answer stream, shared by the ML service, the edge and the app (POST /api/ai with Accept: text/event-stream). seq starts at 0 and grows by one; exactly one terminal event (done or error) closes the stream. claim_delta only carries a block whose references and checkable numbers were validated; error is never a finished answer. Transport-level names (token, chunk, complete) are internal and are translated, never exposed. The shape of `data` depends on `event` and is fixed by the $defs of the same name: the validators of both languages (semantic.check_stream / errors_of_stream_event in Python, stream.ts errorsOfStreamEvent in TypeScript) pick the $defs by `event` and check `data` against it, since the shared subset has no conditional keyword.",
"type": "object",
"additionalProperties": false,
"required": [
"schema_version",
"request_id",
"seq",
"event",
"data"
],
"properties": {
"schema_version": {
"$ref": "common.schema.json#/$defs/schema_version"
},
"request_id": {
"$ref": "common.schema.json#/$defs/id"
},
"seq": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"event": {
"enum": [
"meta",
"status",
"evidence",
"claim_delta",
"tool_result",
"warning",
"done",
"error"
]
},
"data": {
"type": "object"
}
},
"$defs": {
"code": {
"description": "A stable machine word: a warning or error code, a status word, a degradation code.",
"type": "string",
"pattern": "^[a-z][a-z0-9_]{0,63}$"
},
"meta": {
"description": "The first event. The phase is the server's; environment says where the answer really runs ('fake' is a fixture, never a real answer). The app's bridge sends its own meta (phase and origin 'app') when the service cannot be reached, so only the phase is required.",
"type": "object",
"additionalProperties": false,
"required": [
"phase"
],
"properties": {
"environment": {
"$ref": "common.schema.json#/$defs/environment"
},
"phase": {
"$ref": "common.schema.json#/$defs/phase"
},
"purpose": {
"$ref": "common.schema.json#/$defs/purpose"
},
"pack_id": {
"$ref": "common.schema.json#/$defs/id"
},
"question_id": {
"$ref": "common.schema.json#/$defs/question_id"
},
"origin": {
"description": "Who produced the stream: the ML service ('ml') or the app's bridge standing in for it ('app').",
"enum": [
"ml",
"app"
]
}
}
},
"status": {
"type": "object",
"additionalProperties": false,
"required": [
"state"
],
"properties": {
"state": {
"$ref": "#/$defs/code"
}
}
},
"evidence": {
"description": "The pack the answer may cite and the items its content_hash binds (evidence-pack-items), exactly as the retrieval produced them; the only source of the app's sources drawer.",
"type": "object",
"additionalProperties": false,
"required": [
"pack",
"items",
"degradations"
],
"properties": {
"pack": {
"$ref": "evidence-pack-ref.schema.json"
},
"items": {
"type": "array",
"items": {
"$ref": "evidence-pack-items.schema.json#/$defs/item"
}
},
"degradations": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"code"
],
"properties": {
"code": {
"$ref": "#/$defs/code"
},
"detail": {
"type": [
"string",
"null"
],
"maxLength": 300
}
}
}
}
}
},
"claim_delta": {
"description": "One validated block: the claim as it will appear in the answer's claim_refs and the citations it points at (citation_refs of grounded-answer). validated is always true; an unvalidated block is never sent.",
"type": "object",
"additionalProperties": false,
"required": [
"validated",
"claim",
"citations"
],
"properties": {
"validated": {
"const": true
},
"claim": {
"$ref": "grounded-answer.schema.json#/properties/claim_refs/items"
},
"citations": {
"type": "array",
"items": {
"$ref": "grounded-answer.schema.json#/properties/citation_refs/items"
}
}
}
},
"tool_result": {
"description": "A tool the model called, by its receipt: id, status and error class. The output stays on the server; the full receipts travel in done.",
"type": "object",
"additionalProperties": false,
"required": [
"tool_receipt_id",
"tool_id",
"status",
"error_class"
],
"properties": {
"tool_receipt_id": {
"$ref": "common.schema.json#/$defs/id"
},
"tool_id": {
"$ref": "common.schema.json#/$defs/id"
},
"status": {
"enum": [
"ok",
"error"
]
},
"error_class": {
"type": [
"string",
"null"
],
"pattern": "^[a-z][a-z0-9_]{0,63}$"
}
}
},
"warning": {
"type": "object",
"additionalProperties": false,
"required": [
"code"
],
"properties": {
"code": {
"$ref": "#/$defs/code"
},
"reason": {
"$ref": "#/$defs/code"
},
"detail": {
"type": "string",
"maxLength": 600
}
}
},
"error": {
"description": "The terminal that is never an answer. code 'cancelled' (service) and 'interrupted' (bridge, browser) mean the reader or the connection stopped it; the rest are failures.",
"type": "object",
"additionalProperties": false,
"required": [
"code"
],
"properties": {
"code": {
"$ref": "#/$defs/code"
},
"reason": {
"$ref": "#/$defs/code"
},
"detail": {
"type": "string",
"maxLength": 600
},
"environment": {
"$ref": "common.schema.json#/$defs/environment"
},
"execution_receipt_id": {
"type": [
"string",
"null"
],
"pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$"
},
"execution_receipt": {
"$ref": "model-execution-receipt.schema.json"
},
"execution_receipt_ids": {
"type": "array",
"items": {
"$ref": "common.schema.json#/$defs/id"
}
}
}
},
"done": {
"description": "The finished answer (grounded-answer) with every receipt of the run and the claims the validation rejected, with their reasons.",
"type": "object",
"additionalProperties": false,
"required": [
"environment",
"answer",
"execution_receipts",
"tool_receipts",
"rejected"
],
"properties": {
"environment": {
"$ref": "common.schema.json#/$defs/environment"
},
"answer": {
"$ref": "grounded-answer.schema.json"
},
"execution_receipts": {
"type": "array",
"items": {
"$ref": "model-execution-receipt.schema.json"
}
},
"tool_receipts": {
"type": "array",
"items": {
"type": "object",
"required": [
"receipt_id",
"tool_id",
"status"
],
"properties": {
"receipt_id": {
"$ref": "common.schema.json#/$defs/id"
},
"tool_id": {
"$ref": "common.schema.json#/$defs/id"
},
"status": {
"enum": [
"ok",
"error"
]
}
}
}
},
"rejected": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"claim_text",
"reason",
"detail"
],
"properties": {
"claim_text": {
"type": "string",
"maxLength": 200
},
"reason": {
"$ref": "#/$defs/code"
},
"detail": {
"type": "string",
"maxLength": 600
}
}
}
}
}
}
}
}
|