Files
go-sip/docs/contracts/task-discovery-v0.1-proposal.schema.json
T

153 lines
6.9 KiB
JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://go-sip.local/contracts/proposals/task-discovery-v0.1-proposal.schema.json",
"title": "Project-local contract: Dispatcher task discovery responses; external compatibility unverified",
"oneOf": [
{"$ref": "#/$defs/snapshot_response"},
{"$ref": "#/$defs/changes_response"},
{"$ref": "#/$defs/error_response"}
],
"$defs": {
"dispatcher_id": {
"type": "string",
"format": "uuid",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
},
"cursor": {
"type": "string",
"minLength": 1,
"maxLength": 512,
"$comment": "Opaque SaaS change watermark; never compare to task_id or infer numeric order."
},
"task_fields": {
"type": "object",
"required": ["task_id", "tenant_id", "tenant_key", "status", "task_revision"],
"properties": {
"task_id": {"type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$"},
"tenant_id": {"type": "string", "minLength": 1, "maxLength": 128},
"tenant_key": {
"type": "string",
"minLength": 1,
"maxLength": 196,
"$comment": "Also validate the existing UTF-8 byte limit and tenant_id mapping in business logic; tenant_key is not part of any queue or routing key."
},
"status": {"enum": ["running", "paused", "stopped", "finished"]},
"task_revision": {"type": "integer", "minimum": 1}
}
},
"queue": {
"type": "object",
"additionalProperties": false,
"required": ["exchange", "routing_key", "binding_key", "queue_name"],
"properties": {
"exchange": {"const": "agent-call.dispatchers.v3"},
"routing_key": {"type": "string", "maxLength": 175, "pattern": "^d\\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\.task\\.[A-Za-z0-9_-]{1,128}\\.in$"},
"binding_key": {"type": "string", "maxLength": 175, "pattern": "^d\\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\.task\\.[A-Za-z0-9_-]{1,128}\\.in$"},
"queue_name": {"type": "string", "maxLength": 186, "pattern": "^agent-call\\.d\\.[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\.task\\.[A-Za-z0-9_-]{1,128}\\.v3$"}
},
"$comment": "SaaS-created and managed queue address; D only consumes. Runtime derives names from dispatcher_id/task_id, requires binding_key = routing_key, and rejects mismatches. Max 256 assigned or draining task queues per D."
},
"snapshot_task": {
"allOf": [
{"$ref": "#/$defs/task_fields"},
{
"type": "object",
"required": ["queue"],
"properties": {"queue": {"$ref": "#/$defs/queue"}}
}
],
"unevaluatedProperties": false
},
"changed_task": {
"allOf": [
{"$ref": "#/$defs/task_fields"},
{
"type": "object",
"required": ["cursor", "operation", "queue"],
"properties": {
"cursor": {"$ref": "#/$defs/cursor"},
"operation": {"enum": ["assigned", "updated"]},
"queue": {"$ref": "#/$defs/queue"}
}
}
],
"unevaluatedProperties": false
},
"removed_task": {
"type": "object",
"additionalProperties": false,
"required": ["cursor", "operation", "task_id", "tenant_id", "tenant_key"],
"properties": {
"cursor": {"$ref": "#/$defs/cursor"},
"operation": {"const": "removed"},
"task_id": {"type": "string", "pattern": "^[A-Za-z0-9_-]{1,128}$"},
"tenant_id": {"type": "string", "minLength": 1, "maxLength": 128},
"tenant_key": {
"type": "string",
"minLength": 1,
"maxLength": 196,
"$comment": "Also validate the existing UTF-8 byte limit and tenant_id mapping in business logic."
}
}
},
"snapshot_response": {
"type": "object",
"additionalProperties": false,
"required": ["schema_version", "dispatcher_id", "mode", "snapshot_id", "cursor", "tasks", "next_page_token"],
"properties": {
"schema_version": {"const": "task-discovery.v0.1-proposal"},
"dispatcher_id": {"$ref": "#/$defs/dispatcher_id"},
"mode": {"const": "snapshot"},
"snapshot_id": {"type": "string", "minLength": 1, "maxLength": 128},
"cursor": {"$ref": "#/$defs/cursor"},
"tasks": {"type": "array", "maxItems": 100, "items": {"$ref": "#/$defs/snapshot_task"}},
"next_page_token": {"type": ["string", "null"], "minLength": 1, "maxLength": 512}
},
"$comment": "Each page has at most 100 tasks. All pages retain the first page's snapshot_id/cursor; stage and persist all pages before atomically replacing the active snapshot and advancing the cursor."
},
"changes_response": {
"type": "object",
"additionalProperties": false,
"required": ["schema_version", "dispatcher_id", "mode", "from_cursor", "next_cursor", "changes", "next_page_token"],
"properties": {
"schema_version": {"const": "task-discovery.v0.1-proposal"},
"dispatcher_id": {"$ref": "#/$defs/dispatcher_id"},
"mode": {"const": "changes"},
"from_cursor": {"$ref": "#/$defs/cursor"},
"next_cursor": {"$ref": "#/$defs/cursor"},
"changes": {
"type": "array",
"maxItems": 100,
"items": {
"oneOf": [
{"$ref": "#/$defs/changed_task"},
{"$ref": "#/$defs/removed_task"}
]
}
},
"next_page_token": {"type": ["string", "null"], "minLength": 1, "maxLength": 512}
},
"$comment": "Each page has at most 100 changes. All pages retain from_cursor/next_cursor for the same window; apply changes in response order and persist all pages before atomically advancing next_cursor. Cursor and page-token continuity are cross-response semantics."
},
"error_response": {
"type": "object",
"additionalProperties": false,
"required": ["schema_version", "resource", "error"],
"properties": {
"schema_version": {"const": "task-discovery.v0.1-proposal"},
"resource": {"const": "error"},
"error": {
"type": "object",
"$comment": "Local HTTP mapping: invalid_cursor/invalid_page_token=400, unauthorized=401, dispatcher_not_authorized=403, cursor_expired/snapshot_expired=410, service_unavailable=503. Status is transport metadata and is not part of the JSON body; external SaaS compatibility is unverified.",
"additionalProperties": false,
"required": ["code", "message"],
"properties": {
"code": {"enum": ["invalid_cursor", "cursor_expired", "snapshot_expired", "invalid_page_token", "unauthorized", "dispatcher_not_authorized", "service_unavailable"]},
"message": {"type": "string", "minLength": 1, "maxLength": 256}
}
}
}
}
}
}