{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://go-sip.local/contracts/proposals/command-next-v0.1-proposal.schema.json", "title": "Project-local contract: SaaS command and command-result messages; external compatibility unverified", "$comment": "Project-local contract derived from docs/thirds/第三方对接事件与请求消费顺序_v0.1.md; not the published MQ v2 contract. Serialized UTF-8 JSON bodies are capped at 8,388,608 bytes by runtime validation.", "oneOf": [ {"$ref": "#/$defs/call_execute"}, {"$ref": "#/$defs/control_pause"}, {"$ref": "#/$defs/control_resume"}, {"$ref": "#/$defs/control_stop"}, {"$ref": "#/$defs/command_result_call"}, {"$ref": "#/$defs/command_result_control"} ], "$defs": { "id": {"$ref": "https://go-sip.local/contracts/v1/mq.schema.json#/$defs/id"}, "dispatcher_id": {"$ref": "https://go-sip.local/contracts/v1/mq.schema.json#/$defs/dispatcherId"}, "task_id": {"type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$"}, "tenant_key": {"$ref": "https://go-sip.local/contracts/v1/mq.schema.json#/$defs/tenantKey"}, "time": {"$ref": "https://go-sip.local/contracts/v1/mq.schema.json#/$defs/time"}, "command_base": { "type": "object", "required": ["schema_version", "dispatcher_id", "tenant_id", "tenant_key", "trace_id", "issued_at", "not_after"], "properties": { "schema_version": {"const": "command-next.v0.1-proposal"}, "dispatcher_id": {"$ref": "#/$defs/dispatcher_id"}, "tenant_id": {"$ref": "#/$defs/id"}, "tenant_key": {"$ref": "#/$defs/tenant_key"}, "trace_id": {"$ref": "#/$defs/id"}, "issued_at": {"$ref": "#/$defs/time"}, "not_after": {"$ref": "#/$defs/time"} } }, "call_execute": { "allOf": [ {"$ref": "#/$defs/command_base"}, { "type": "object", "required": ["command_id", "command_type", "payload"], "properties": { "command_id": {"$ref": "#/$defs/id"}, "command_type": {"const": "call.execute"}, "payload": { "type": "object", "additionalProperties": false, "required": ["task_id", "callee"], "properties": { "task_id": {"$ref": "#/$defs/task_id"}, "callee": {"type": "string", "minLength": 1} } } } } ], "unevaluatedProperties": false, "$comment": "Check not_after against current time and bind the task/tenant snapshot before originate; not_after must be later than issued_at." }, "control_pause": { "allOf": [ {"$ref": "#/$defs/command_base"}, { "type": "object", "required": ["command_type", "payload"], "properties": { "command_type": {"const": "task.control"}, "payload": { "type": "object", "additionalProperties": false, "required": ["task_id", "action", "active_call_policy", "reason"], "properties": { "task_id": {"$ref": "#/$defs/task_id"}, "action": {"const": "pause"}, "active_call_policy": {"enum": ["drain", "hangup"]}, "reason": {"type": "string", "minLength": 1, "maxLength": 512} } } } } ], "unevaluatedProperties": false }, "control_resume": { "allOf": [ {"$ref": "#/$defs/command_base"}, { "type": "object", "required": ["command_type", "payload"], "properties": { "command_type": {"const": "task.control"}, "payload": { "type": "object", "additionalProperties": false, "required": ["task_id", "action", "reason"], "properties": { "task_id": {"$ref": "#/$defs/task_id"}, "action": {"const": "resume"}, "reason": {"type": "string", "minLength": 1, "maxLength": 512} } } } } ], "unevaluatedProperties": false }, "control_stop": { "allOf": [ {"$ref": "#/$defs/command_base"}, { "type": "object", "required": ["command_type", "payload"], "properties": { "command_type": {"const": "task.control"}, "payload": { "type": "object", "additionalProperties": false, "required": ["task_id", "action", "active_call_policy", "reason"], "properties": { "task_id": {"$ref": "#/$defs/task_id"}, "action": {"const": "stop"}, "active_call_policy": {"enum": ["drain", "hangup"]}, "reason": {"type": "string", "minLength": 1, "maxLength": 512} } } } } ], "unevaluatedProperties": false }, "event_base": { "type": "object", "required": ["schema_version", "event_id", "event_type", "dispatcher_id", "tenant_id", "tenant_key", "trace_id", "occurred_at", "aggregate_type", "aggregate_id", "aggregate_version"], "properties": { "schema_version": {"const": "command-next.v0.1-proposal"}, "event_id": {"$ref": "#/$defs/id"}, "event_type": {"const": "command.result"}, "dispatcher_id": {"$ref": "#/$defs/dispatcher_id"}, "tenant_id": {"$ref": "#/$defs/id"}, "tenant_key": {"$ref": "#/$defs/tenant_key"}, "trace_id": {"$ref": "#/$defs/id"}, "occurred_at": {"$ref": "#/$defs/time"}, "aggregate_type": {"enum": ["command", "task"]}, "aggregate_id": {"$ref": "#/$defs/id"}, "aggregate_version": {"type": "integer", "minimum": 1} } }, "command_result_call": { "allOf": [ {"$ref": "#/$defs/event_base"}, { "type": "object", "required": ["aggregate_type", "payload"], "properties": { "aggregate_type": {"const": "command"}, "payload": { "type": "object", "additionalProperties": false, "required": ["command_id", "command_type", "status", "reason_code"], "properties": { "command_id": {"$ref": "#/$defs/id"}, "command_type": {"const": "call.execute"}, "status": {"enum": ["accepted", "rejected"]}, "reason_code": {"type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$"}, "execution_id": {"$ref": "#/$defs/id"} }, "allOf": [ { "if": {"properties": {"status": {"const": "accepted"}}}, "then": {"required": ["execution_id"]} } ] } } } ], "unevaluatedProperties": false }, "command_result_control": { "allOf": [ {"$ref": "#/$defs/event_base"}, { "type": "object", "required": ["aggregate_type", "payload"], "properties": { "aggregate_type": {"const": "task"}, "payload": { "type": "object", "additionalProperties": false, "required": ["command_type", "task_id", "action", "status", "reason_code", "task_state"], "properties": { "command_type": {"const": "task.control"}, "task_id": {"$ref": "#/$defs/task_id"}, "action": {"enum": ["pause", "resume", "stop"]}, "status": {"enum": ["applied", "rejected"]}, "reason_code": {"type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$"}, "task_state": {"enum": ["running", "paused", "stopped", "finished"]} }, "allOf": [ {"if": {"properties": {"action": {"const": "pause"}, "status": {"const": "applied"}}}, "then": {"properties": {"task_state": {"const": "paused"}}}}, {"if": {"properties": {"action": {"const": "resume"}, "status": {"const": "applied"}}}, "then": {"properties": {"task_state": {"const": "running"}}}}, {"if": {"properties": {"action": {"const": "stop"}, "status": {"const": "applied"}}}, "then": {"properties": {"task_state": {"const": "stopped"}}}} ] } } } ], "unevaluatedProperties": false, "$comment": "No control command_id or request dedupe identity exists. event_id identifies a receipt event, not a control command." } } }