feat: expose person API v1 through explicit auth and CSRF lanes
33 files changed,
+6,918
−134
docs/api/equipo-v1.openapi.json+4,527 −0docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+56 −0internal/equipo/app.go+12 −3internal/equipo/cancel.go+19 −3internal/equipo/conversation/views.go+13 −0internal/equipo/copy.go+18 −0internal/equipo/kernel/types.go+20 −0internal/equipo/migrations/0023_person_api_requests.sql+2 −0internal/equipo/migrations/schema.sql+2 −0internal/equipo/models.go+7 −17internal/equipo/person_api.go+58 −0internal/equipo/personapi/auth.go+131 −0internal/equipo/personapi/budget_test.go+9 −0internal/equipo/personapi/conversation.go+189 −0internal/equipo/personapi/handler.go+177 −0internal/equipo/personapi/reads.go+176 −0internal/equipo/personapi/requests.go+172 −0internal/equipo/personapi/types.go+261 −0internal/equipo/personapi/validate.go+175 −0internal/equipo/personapi/validate_test.go+19 −0internal/equipo/planning/task_views.go+54 −0internal/equipo/questions.go+2 −1internal/equipo/runner_api.go+0 −11internal/equipo/store.go+22 −1internal/equipo/task_merge.go+12 −4internal/equipo/task_views.go+9 −90internal/plan3test/person_api_contract_test.go+112 −0internal/plan3test/person_api_evidence_test.go+75 −0internal/plan3test/person_api_migration_test.go+58 −0internal/plan3test/person_api_operations_test.go+246 −0internal/plan3test/person_api_test.go+222 −0internal/plan3test/preferences_test.go+10 −4internal/runnerproto/question_views.go+53 −0
CI failed — run details
Intent
diff --git a/docs/api/equipo-v1.openapi.json b/docs/api/equipo-v1.openapi.json| new file mode 100644 |
| index 00000000..489ed25f |
| --- /dev/null |
| +++ b/docs/api/equipo-v1.openapi.json |
| @@ -0,0 +1,4527 @@ |
| +{ |
| + "openapi": "3.1.0", |
| + "info": { |
| + "title": "Equipo person API", |
| + "version": "1.0.0" |
| + }, |
| + "servers": [ |
| + { |
| + "url": "/api/v1" |
| + } |
| + ], |
| + "security": [ |
| + { |
| + "browserSession": [] |
| + } |
| + ], |
| + "paths": { |
| + "/me": { |
| + "get": { |
| + "operationId": "get_me", |
| + "parameters": [], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Me" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/capabilities": { |
| + "get": { |
| + "operationId": "get_capabilities", |
| + "parameters": [], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Capabilities" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/me/settings": { |
| + "get": { |
| + "operationId": "get_me_settings", |
| + "parameters": [], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Settings" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + }, |
| + "patch": { |
| + "operationId": "patch_me_settings", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Settings" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/SettingsInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/people": { |
| + "get": { |
| + "operationId": "get_people", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/PersonPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/conversation": { |
| + "get": { |
| + "operationId": "get_conversation", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/ConversationPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/conversation/messages": { |
| + "post": { |
| + "operationId": "post_conversation_messages", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": false, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Message" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/MessageInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/conversation/cards": { |
| + "get": { |
| + "operationId": "get_conversation_cards", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/CardPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/cards/{id}": { |
| + "get": { |
| + "operationId": "get_cards_id", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Card" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/tasks": { |
| + "get": { |
| + "operationId": "get_tasks", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/TaskPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + }, |
| + "post": { |
| + "operationId": "post_tasks", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": false, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Plan" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/PlanInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}": { |
| + "get": { |
| + "operationId": "get_tasks_id", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Task" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/tasks/{id}/cancel": { |
| + "post": { |
| + "operationId": "post_tasks_id_cancel", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Ack" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Empty" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}/thread": { |
| + "get": { |
| + "operationId": "get_tasks_id_thread", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/ConversationPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/tasks/{id}/thread/messages": { |
| + "post": { |
| + "operationId": "post_tasks_id_thread_messages", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": false, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Message" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/MessageInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/conversation/messages/{id}/route": { |
| + "post": { |
| + "operationId": "post_conversation_messages_id_route", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Message" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/RouteInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}/plan": { |
| + "get": { |
| + "operationId": "get_tasks_id_plan", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Plan" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + }, |
| + "patch": { |
| + "operationId": "patch_tasks_id_plan", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Plan" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/PlanInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}/plan/approve": { |
| + "post": { |
| + "operationId": "post_tasks_id_plan_approve", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Task" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Empty" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}/project": { |
| + "post": { |
| + "operationId": "post_tasks_id_project", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Task" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/ProjectInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/questions/{id}": { |
| + "get": { |
| + "operationId": "get_questions_id", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Question" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/questions/{id}/answer": { |
| + "post": { |
| + "operationId": "post_questions_id_answer", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Ack" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/AnswerInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}/rendered-approval": { |
| + "post": { |
| + "operationId": "post_tasks_id_rendered_approval", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Ack" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/RenderedInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/tasks/{id}/acknowledge-merge": { |
| + "post": { |
| + "operationId": "post_tasks_id_acknowledge_merge", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Ack" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/MergeInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/journey": { |
| + "get": { |
| + "operationId": "get_journey", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/TaskPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/needs-you": { |
| + "get": { |
| + "operationId": "get_needs_you", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/TaskPage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + } |
| + }, |
| + "/preferences": { |
| + "get": { |
| + "operationId": "get_preferences", |
| + "parameters": [ |
| + { |
| + "name": "cursor", |
| + "in": "query", |
| + "schema": { |
| + "type": "string" |
| + } |
| + }, |
| + { |
| + "name": "limit", |
| + "in": "query", |
| + "schema": { |
| + "type": "integer", |
| + "minimum": 1, |
| + "maximum": 100, |
| + "default": 50 |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/PreferencePage" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a" |
| + }, |
| + "post": { |
| + "operationId": "post_preferences", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": false, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Preference" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/PreferenceInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/preferences/{id}": { |
| + "patch": { |
| + "operationId": "patch_preferences_id", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Preference" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/PreferenceInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + }, |
| + "delete": { |
| + "operationId": "delete_preferences_id", |
| + "parameters": [ |
| + { |
| + "name": "id", |
| + "in": "path", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1 |
| + } |
| + }, |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Ack" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Empty" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/coordinator": { |
| + "get": { |
| + "operationId": "get_coordinator", |
| + "parameters": [], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Coordinator" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "x-unconfiguredRevision": 0 |
| + }, |
| + "patch": { |
| + "operationId": "patch_coordinator", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Coordinator" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/BindingInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/coordinator/reset": { |
| + "post": { |
| + "operationId": "post_coordinator_reset", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Coordinator" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Empty" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/coordinator/retry": { |
| + "post": { |
| + "operationId": "post_coordinator_retry", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Turn" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/RetryInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + }, |
| + "/coordinator/limits": { |
| + "patch": { |
| + "operationId": "patch_coordinator_limits", |
| + "parameters": [ |
| + { |
| + "name": "Idempotency-Key", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "minLength": 1, |
| + "maxLength": 256, |
| + "x-maxBytes": 256 |
| + } |
| + }, |
| + { |
| + "name": "If-Match", |
| + "in": "header", |
| + "required": true, |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + } |
| + ], |
| + "responses": { |
| + "200": { |
| + "description": "OK", |
| + "headers": { |
| + "ETag": { |
| + "schema": { |
| + "type": "string", |
| + "pattern": "^\"(0|[1-9][0-9]*)\"$" |
| + } |
| + }, |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Ack" |
| + } |
| + } |
| + } |
| + }, |
| + "401": { |
| + "$ref": "#/components/responses/unauthenticated" |
| + }, |
| + "403": { |
| + "$ref": "#/components/responses/forbidden" |
| + }, |
| + "404": { |
| + "$ref": "#/components/responses/not_found" |
| + }, |
| + "405": { |
| + "$ref": "#/components/responses/method_not_allowed" |
| + }, |
| + "409": { |
| + "$ref": "#/components/responses/revision_conflict" |
| + }, |
| + "410": { |
| + "$ref": "#/components/responses/cursor_expired" |
| + }, |
| + "422": { |
| + "$ref": "#/components/responses/invalid_input" |
| + }, |
| + "428": { |
| + "$ref": "#/components/responses/precondition_required" |
| + }, |
| + "503": { |
| + "$ref": "#/components/responses/unavailable" |
| + } |
| + }, |
| + "x-plan-part": "3a", |
| + "requestBody": { |
| + "required": true, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/LimitsInput" |
| + } |
| + } |
| + }, |
| + "x-maxBytes": 65536, |
| + "x-rejectDuplicateKeys": true, |
| + "x-rejectUnknownFields": true |
| + } |
| + } |
| + } |
| + }, |
| + "components": { |
| + "securitySchemes": { |
| + "browserSession": { |
| + "type": "apiKey", |
| + "in": "cookie", |
| + "name": "rastrillo_session" |
| + } |
| + }, |
| + "schemas": { |
| + "Error": { |
| + "type": "object", |
| + "properties": { |
| + "code": { |
| + "type": "string", |
| + "enum": [ |
| + "unauthenticated", |
| + "forbidden", |
| + "not_found", |
| + "method_not_allowed", |
| + "revision_conflict", |
| + "cursor_expired", |
| + "invalid_input", |
| + "precondition_required", |
| + "unavailable" |
| + ] |
| + }, |
| + "copy_key": { |
| + "type": "string", |
| + "enum": [ |
| + "api.unauthenticated", |
| + "api.forbidden", |
| + "api.not_found", |
| + "api.method_not_allowed", |
| + "api.revision_conflict", |
| + "api.cursor_expired", |
| + "api.invalid_input", |
| + "api.precondition_required", |
| + "api.unavailable" |
| + ] |
| + }, |
| + "request_id": { |
| + "type": "string" |
| + }, |
| + "current_revision": { |
| + "anyOf": [ |
| + { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "code", |
| + "copy_key", |
| + "request_id" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Person": { |
| + "type": "object", |
| + "properties": { |
| + "address": { |
| + "type": "string" |
| + }, |
| + "display_identity": { |
| + "type": "string" |
| + }, |
| + "active": { |
| + "type": "boolean" |
| + }, |
| + "role": { |
| + "type": "string", |
| + "enum": [ |
| + "owner", |
| + "member" |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "address", |
| + "display_identity", |
| + "active", |
| + "role" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Me": { |
| + "type": "object", |
| + "properties": { |
| + "person": { |
| + "$ref": "#/components/schemas/Person" |
| + }, |
| + "team_id": { |
| + "type": "string" |
| + }, |
| + "team_name": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "person", |
| + "team_id", |
| + "team_name", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Settings": { |
| + "type": "object", |
| + "properties": { |
| + "landing": { |
| + "type": "string", |
| + "enum": [ |
| + "conversation", |
| + "work" |
| + ] |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "landing", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Message": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "conversation_id": { |
| + "type": "string" |
| + }, |
| + "thread_id": { |
| + "type": "string" |
| + }, |
| + "author_kind": { |
| + "type": "string" |
| + }, |
| + "author_id": { |
| + "type": "string" |
| + }, |
| + "body": { |
| + "type": "string" |
| + }, |
| + "sequence": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "created_at": { |
| + "type": "string", |
| + "format": "date-time" |
| + }, |
| + "sources": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/SourceRef" |
| + } |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "conversation_id", |
| + "thread_id", |
| + "author_kind", |
| + "author_id", |
| + "body", |
| + "sequence", |
| + "revision", |
| + "created_at", |
| + "sources" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Card": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "kind": { |
| + "type": "string" |
| + }, |
| + "resource_id": { |
| + "type": "string" |
| + }, |
| + "task_id": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "copy_key": { |
| + "type": "string" |
| + }, |
| + "actions": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "type": "string" |
| + } |
| + }, |
| + "waiting_task_id": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "kind", |
| + "resource_id", |
| + "task_id", |
| + "revision", |
| + "copy_key", |
| + "actions", |
| + "waiting_task_id" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "ConversationPage": { |
| + "type": "object", |
| + "properties": { |
| + "messages": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Message" |
| + } |
| + }, |
| + "cards": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Card" |
| + } |
| + }, |
| + "next_cursor": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "messages", |
| + "cards", |
| + "next_cursor", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Preference": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "text": { |
| + "type": "string" |
| + }, |
| + "status": { |
| + "type": "string" |
| + }, |
| + "source_message_id": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "text", |
| + "status", |
| + "source_message_id", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Task": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "project_id": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "requester": { |
| + "type": "string" |
| + }, |
| + "description": { |
| + "type": "string" |
| + }, |
| + "kind": { |
| + "type": "string", |
| + "enum": [ |
| + "bug", |
| + "feature", |
| + "rendered_change", |
| + "recommendation", |
| + "investigation" |
| + ] |
| + }, |
| + "state": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "plan_revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "replacement_id": { |
| + "type": "string" |
| + }, |
| + "can_cancel": { |
| + "type": "boolean" |
| + }, |
| + "can_merge": { |
| + "type": "boolean" |
| + }, |
| + "needs_you": { |
| + "type": "boolean" |
| + }, |
| + "steps": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Step" |
| + } |
| + }, |
| + "usage": { |
| + "anyOf": [ |
| + { |
| + "$ref": "#/components/schemas/Usage" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "project_id", |
| + "requester", |
| + "description", |
| + "kind", |
| + "state", |
| + "revision", |
| + "plan_revision", |
| + "replacement_id", |
| + "can_cancel", |
| + "can_merge", |
| + "needs_you", |
| + "steps", |
| + "usage" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Usage": { |
| + "type": "object", |
| + "properties": { |
| + "calls": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "input_tokens": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "output_tokens": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "calls", |
| + "input_tokens", |
| + "output_tokens" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Step": { |
| + "type": "object", |
| + "properties": { |
| + "key": { |
| + "type": "string" |
| + }, |
| + "category": { |
| + "type": "string" |
| + }, |
| + "action": { |
| + "type": "string" |
| + }, |
| + "state": { |
| + "type": "string" |
| + }, |
| + "model": { |
| + "type": "string" |
| + }, |
| + "account": { |
| + "type": "string" |
| + }, |
| + "actual": { |
| + "type": "string" |
| + }, |
| + "reason": { |
| + "type": "string" |
| + }, |
| + "usage": { |
| + "anyOf": [ |
| + { |
| + "$ref": "#/components/schemas/Usage" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + }, |
| + "allowance_remaining": { |
| + "anyOf": [ |
| + { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "key", |
| + "category", |
| + "action", |
| + "state", |
| + "model", |
| + "account", |
| + "actual", |
| + "reason", |
| + "usage", |
| + "allowance_remaining" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Coordinator": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "runner_id": { |
| + "type": "string" |
| + }, |
| + "connection_id": { |
| + "type": "string" |
| + }, |
| + "generation": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "waiting_task_id": { |
| + "type": "string" |
| + }, |
| + "turns": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Turn" |
| + } |
| + }, |
| + "limits": { |
| + "anyOf": [ |
| + { |
| + "$ref": "#/components/schemas/Limits" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + }, |
| + "limits_revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "runner_id", |
| + "connection_id", |
| + "generation", |
| + "revision", |
| + "waiting_task_id", |
| + "turns", |
| + "limits", |
| + "limits_revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Turn": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "state": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "state", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Option": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "label": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "label" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Field": { |
| + "type": "object", |
| + "properties": { |
| + "key": { |
| + "type": "string" |
| + }, |
| + "prompt": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "key", |
| + "prompt" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Ack": { |
| + "type": "object", |
| + "properties": { |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "MessageInput": { |
| + "type": "object", |
| + "properties": { |
| + "body": { |
| + "type": "string", |
| + "minLength": 1, |
| + "x-maxBytes": 16384 |
| + } |
| + }, |
| + "required": [ |
| + "body" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "SettingsInput": { |
| + "type": "object", |
| + "properties": { |
| + "landing": { |
| + "type": "string", |
| + "enum": [ |
| + "conversation", |
| + "work" |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "landing" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "RouteInput": { |
| + "type": "object", |
| + "properties": { |
| + "task_id": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "task_id" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "ProjectInput": { |
| + "type": "object", |
| + "properties": { |
| + "project_id": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "project_id" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "PreferenceInput": { |
| + "type": "object", |
| + "properties": { |
| + "text": { |
| + "type": "string", |
| + "minLength": 1, |
| + "x-maxBytes": 8192 |
| + }, |
| + "source_message_id": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "text" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "BindingInput": { |
| + "type": "object", |
| + "properties": { |
| + "runner_id": { |
| + "type": "string" |
| + }, |
| + "connection_id": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "runner_id", |
| + "connection_id" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "RetryInput": { |
| + "type": "object", |
| + "properties": { |
| + "turn_id": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "turn_id" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Limits": { |
| + "type": "object", |
| + "properties": { |
| + "calls": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "input_tokens": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "output_tokens": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "seconds": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "calls", |
| + "input_tokens", |
| + "output_tokens", |
| + "seconds" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "LimitsInput": { |
| + "type": "object", |
| + "properties": { |
| + "person": { |
| + "type": "string" |
| + }, |
| + "limits": { |
| + "$ref": "#/components/schemas/Limits" |
| + } |
| + }, |
| + "required": [ |
| + "person", |
| + "limits" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "RenderedInput": { |
| + "type": "object", |
| + "properties": { |
| + "candidate_hash": { |
| + "type": "string", |
| + "pattern": "^[a-f0-9]{64}$" |
| + }, |
| + "diff_hash": { |
| + "type": "string", |
| + "pattern": "^[a-f0-9]{64}$" |
| + }, |
| + "render_hash": { |
| + "type": "string", |
| + "pattern": "^[a-f0-9]{64}$" |
| + }, |
| + "decision": { |
| + "type": "string", |
| + "enum": [ |
| + "copy", |
| + "design" |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "candidate_hash", |
| + "diff_hash", |
| + "render_hash", |
| + "decision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "MergeInput": { |
| + "type": "object", |
| + "properties": { |
| + "reference": { |
| + "type": "string", |
| + "format": "uri", |
| + "maxLength": 2048, |
| + "pattern": "^https://amadan\\.net/" |
| + } |
| + }, |
| + "required": [ |
| + "reference" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "AnswerInput": { |
| + "oneOf": [ |
| + { |
| + "type": "object", |
| + "properties": { |
| + "kind": { |
| + "const": "clarification" |
| + }, |
| + "option_id": { |
| + "type": "string", |
| + "minLength": 1 |
| + }, |
| + "text": { |
| + "type": "string", |
| + "minLength": 1, |
| + "x-maxBytes": 8192 |
| + } |
| + }, |
| + "required": [ |
| + "kind" |
| + ], |
| + "additionalProperties": false, |
| + "oneOf": [ |
| + { |
| + "required": [ |
| + "option_id" |
| + ], |
| + "not": { |
| + "required": [ |
| + "text" |
| + ] |
| + } |
| + }, |
| + { |
| + "required": [ |
| + "text" |
| + ], |
| + "not": { |
| + "required": [ |
| + "option_id" |
| + ] |
| + } |
| + } |
| + ] |
| + }, |
| + { |
| + "type": "object", |
| + "properties": { |
| + "kind": { |
| + "const": "native" |
| + }, |
| + "behavior": { |
| + "const": "allow" |
| + }, |
| + "updated_input": { |
| + "type": "object", |
| + "properties": { |
| + "answers": { |
| + "type": "object", |
| + "minProperties": 1, |
| + "additionalProperties": { |
| + "type": "string", |
| + "maxLength": 8192 |
| + } |
| + } |
| + }, |
| + "required": [ |
| + "answers" |
| + ], |
| + "additionalProperties": false |
| + } |
| + }, |
| + "required": [ |
| + "kind", |
| + "behavior" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + { |
| + "type": "object", |
| + "properties": { |
| + "kind": { |
| + "const": "native" |
| + }, |
| + "behavior": { |
| + "const": "deny" |
| + } |
| + }, |
| + "required": [ |
| + "kind", |
| + "behavior" |
| + ], |
| + "additionalProperties": false |
| + } |
| + ], |
| + "discriminator": { |
| + "propertyName": "kind" |
| + } |
| + }, |
| + "PlanInput": { |
| + "type": "object", |
| + "properties": { |
| + "kind": { |
| + "type": "string", |
| + "enum": [ |
| + "bug", |
| + "feature", |
| + "rendered_change", |
| + "recommendation", |
| + "investigation" |
| + ] |
| + }, |
| + "project_id": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "steps": { |
| + "type": "array", |
| + "items": { |
| + "$ref": "#/components/schemas/PlanStep" |
| + }, |
| + "minItems": 1 |
| + }, |
| + "playbook_id": { |
| + "type": "string" |
| + }, |
| + "playbook_revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "kind", |
| + "project_id", |
| + "steps" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "PlanStep": { |
| + "type": "object", |
| + "properties": { |
| + "depends_on": { |
| + "type": "array", |
| + "items": { |
| + "type": "string" |
| + } |
| + }, |
| + "key": { |
| + "type": "string" |
| + }, |
| + "specialist": { |
| + "type": "string" |
| + }, |
| + "action": { |
| + "type": "string" |
| + }, |
| + "instructions": { |
| + "type": "string" |
| + }, |
| + "connection_id": { |
| + "type": "string" |
| + }, |
| + "model": { |
| + "type": "string" |
| + }, |
| + "selection_reason": { |
| + "type": "string" |
| + } |
| + }, |
| + "required": [ |
| + "key", |
| + "action" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Plan": { |
| + "type": "object", |
| + "properties": { |
| + "kind": { |
| + "type": "string", |
| + "enum": [ |
| + "bug", |
| + "feature", |
| + "rendered_change", |
| + "recommendation", |
| + "investigation" |
| + ] |
| + }, |
| + "project_id": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "steps": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/PlanStep" |
| + } |
| + }, |
| + "playbook_id": { |
| + "type": "string" |
| + }, |
| + "playbook_revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "task_id": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "required_steps": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "type": "string" |
| + } |
| + } |
| + }, |
| + "required": [ |
| + "kind", |
| + "project_id", |
| + "steps", |
| + "playbook_id", |
| + "playbook_revision", |
| + "task_id", |
| + "revision", |
| + "required_steps" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "SourceRef": { |
| + "type": "object", |
| + "properties": { |
| + "kind": { |
| + "type": "string" |
| + }, |
| + "id": { |
| + "type": "string" |
| + }, |
| + "hash": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + } |
| + }, |
| + "required": [ |
| + "kind", |
| + "id", |
| + "hash", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Empty": { |
| + "type": "object", |
| + "maxProperties": 0, |
| + "additionalProperties": false |
| + }, |
| + "Capabilities": { |
| + "type": "object", |
| + "properties": { |
| + "version": { |
| + "const": "1.0.0" |
| + }, |
| + "browser_session": { |
| + "const": true |
| + }, |
| + "device_bearer": { |
| + "const": false |
| + }, |
| + "part": { |
| + "const": "3a" |
| + } |
| + }, |
| + "required": [ |
| + "version", |
| + "browser_session", |
| + "device_bearer", |
| + "part" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "PersonPage": { |
| + "type": "object", |
| + "properties": { |
| + "items": { |
| + "type": "array", |
| + "items": { |
| + "$ref": "#/components/schemas/Person" |
| + } |
| + }, |
| + "next_cursor": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "minimum": 1 |
| + } |
| + }, |
| + "required": [ |
| + "items", |
| + "next_cursor", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "TaskPage": { |
| + "type": "object", |
| + "properties": { |
| + "items": { |
| + "type": "array", |
| + "items": { |
| + "$ref": "#/components/schemas/Task" |
| + } |
| + }, |
| + "next_cursor": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "minimum": 1 |
| + } |
| + }, |
| + "required": [ |
| + "items", |
| + "next_cursor", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "CardPage": { |
| + "type": "object", |
| + "properties": { |
| + "items": { |
| + "type": "array", |
| + "items": { |
| + "$ref": "#/components/schemas/Card" |
| + } |
| + }, |
| + "next_cursor": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "minimum": 1 |
| + } |
| + }, |
| + "required": [ |
| + "items", |
| + "next_cursor", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "PreferencePage": { |
| + "type": "object", |
| + "properties": { |
| + "items": { |
| + "type": "array", |
| + "items": { |
| + "$ref": "#/components/schemas/Preference" |
| + } |
| + }, |
| + "next_cursor": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "minimum": 1 |
| + } |
| + }, |
| + "required": [ |
| + "items", |
| + "next_cursor", |
| + "revision" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "ClarificationQuestion": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "kind": { |
| + "const": "clarification" |
| + }, |
| + "task_id": { |
| + "type": "string" |
| + }, |
| + "text": { |
| + "type": "string" |
| + }, |
| + "state": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "can_answer": { |
| + "type": "boolean" |
| + }, |
| + "can_allow": { |
| + "type": "boolean" |
| + }, |
| + "options": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Option" |
| + } |
| + }, |
| + "fields": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Field" |
| + } |
| + }, |
| + "allow_text": { |
| + "type": "boolean" |
| + }, |
| + "expires_at": { |
| + "anyOf": [ |
| + { |
| + "type": "string", |
| + "format": "date-time" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "kind", |
| + "task_id", |
| + "text", |
| + "state", |
| + "revision", |
| + "can_answer", |
| + "can_allow", |
| + "options", |
| + "fields", |
| + "allow_text", |
| + "expires_at" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "NativeQuestion": { |
| + "type": "object", |
| + "properties": { |
| + "id": { |
| + "type": "string" |
| + }, |
| + "kind": { |
| + "const": "native" |
| + }, |
| + "task_id": { |
| + "type": "string" |
| + }, |
| + "text": { |
| + "type": "string" |
| + }, |
| + "state": { |
| + "type": "string" |
| + }, |
| + "revision": { |
| + "type": "integer", |
| + "format": "int64" |
| + }, |
| + "can_answer": { |
| + "type": "boolean" |
| + }, |
| + "can_allow": { |
| + "type": "boolean" |
| + }, |
| + "options": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Option" |
| + } |
| + }, |
| + "fields": { |
| + "type": [ |
| + "array", |
| + "null" |
| + ], |
| + "items": { |
| + "$ref": "#/components/schemas/Field" |
| + } |
| + }, |
| + "allow_text": { |
| + "const": false |
| + }, |
| + "expires_at": { |
| + "anyOf": [ |
| + { |
| + "type": "string", |
| + "format": "date-time" |
| + }, |
| + { |
| + "type": "null" |
| + } |
| + ] |
| + } |
| + }, |
| + "required": [ |
| + "id", |
| + "kind", |
| + "task_id", |
| + "text", |
| + "state", |
| + "revision", |
| + "can_answer", |
| + "can_allow", |
| + "options", |
| + "fields", |
| + "allow_text", |
| + "expires_at" |
| + ], |
| + "additionalProperties": false |
| + }, |
| + "Question": { |
| + "oneOf": [ |
| + { |
| + "$ref": "#/components/schemas/ClarificationQuestion" |
| + }, |
| + { |
| + "$ref": "#/components/schemas/NativeQuestion" |
| + } |
| + ], |
| + "discriminator": { |
| + "propertyName": "kind" |
| + } |
| + } |
| + }, |
| + "responses": { |
| + "unauthenticated": { |
| + "description": "unauthenticated", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "forbidden": { |
| + "description": "forbidden", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "not_found": { |
| + "description": "not_found", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "method_not_allowed": { |
| + "description": "method_not_allowed", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "revision_conflict": { |
| + "description": "revision_conflict", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "cursor_expired": { |
| + "description": "cursor_expired", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "invalid_input": { |
| + "description": "invalid_input", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "precondition_required": { |
| + "description": "precondition_required", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + }, |
| + "unavailable": { |
| + "description": "unavailable", |
| + "headers": { |
| + "Cache-Control": { |
| + "schema": { |
| + "const": "no-store" |
| + } |
| + } |
| + }, |
| + "content": { |
| + "application/json": { |
| + "schema": { |
| + "$ref": "#/components/schemas/Error" |
| + } |
| + } |
| + } |
| + } |
| + } |
| + }, |
| + "x-nativeBearerProduction": false, |
| + "x-sameOriginBrowserWrites": true, |
| + "x-requestReplayScope": [ |
| + "authenticated_person", |
| + "operation", |
| + "resource", |
| + "Idempotency-Key" |
| + ], |
| + "x-requestCanonicalInputIncludes": "original_revision", |
| + "x-copyReview": "COPY REVIEW REQUIRED" |
| +} |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index f9ccb930..822f79fd 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -3115,3 +3115,59 @@ The plan-revision mutation changed the expected stale-revision response from 409 |
| | `plan.action.design` | Design | |
| Full report: `.superpowers/sdd/2026-11-04-equipo-plan-3-coordinator/task-9-report.md`. No agents, push, merge, deployment, live provider use or copy-review server. |
| + |
| + |
| +## Task 10 |
| + |
| +Status: DONE_WITH_CONCERNS. Added all 35 Person API 3a operations, explicit browser/runner/person authentication dispatch, strict request validation, scoped list cursors, explicit safe projections, and atomic API request metadata in migration 0023. HTML and API use shared operations. Pending runtime copy is inventoried in the full task report. Production device bearers remain disabled until Task 20. |
| + |
| +The inherited CSRF change was `6d1901d4a4ea1e0b800c0a570dcddc1fd16c9c84` (runner-path exemptions). Starting HEAD `09aff24` still had a global wrapper, so this task implements the explicit dispatcher and runs the real app-level bearer/cookie regressions. The implementation subject is `feat: expose person API v1 through explicit auth and CSRF lanes`; author is `codex <codex~paul@keymail.dev>`. No push. |
| + |
| +### Test-first evidence |
| + |
| +The tests were written before the person API package existed. The required red command was: |
| + |
| +`CGO_ENABLED=0 go test ./internal/equipo/personapi ./internal/plan3test -run '^TestPersonAPI' -count=1` |
| + |
| +It exited 1 with no non-test Go files in personapi and undefined `MessageInput` / `Decode`. The same command now passes. |
| + |
| +Further test-first failures, each exit 1: |
| + |
| +- `CGO_ENABLED=0 go test ./internal/plan3test -run '^TestPersonAPIOpenAPIContract$' -count=1`: OpenAPI file absent. Added the 3.1.0 document with version 1.0.0 and all 35 required operations; the same command passed. |
| +- `CGO_ENABLED=0 go test ./internal/plan3test -run '^TestPersonAPI(ProjectionParity|InitialBindingETag)$' -count=1`: HTML preference replay returned 409 instead of 200. The API now supplies the same confirmed status as the HTML operation. |
| +- `CGO_ENABLED=0 go test ./internal/plan3test -run '^TestPersonAPIProjectionParity$' -count=1`: plan projection lost dependencies. Added explicit `depends_on` projection/input and a successful GET/edit round trip. |
| + |
| +Test development also exposed unused test imports and fixture mistakes: personal settings had already advanced the conversation revision; the limits request reused a setup request key and then exceeded the team cap; a cleanup request used ordinary JSON instead of runnerproto.Marshal. Those fixtures were corrected. The first size check found 11,038 root source lines against the existing 10,800 limit. Projection and shared view code was extracted, and the final size check passed. |
| + |
| +The broader targeted regression command initially exited 1 at `TestPreferencesAtomicInvalidation`, which expected only one personal notification. Existing HEAD already combines personal and conversation invalidations from Task 9. The test now asserts both exact private hashes, no plaintext address, no effects on rollback, and distinct hashes for the other person. Production notification behavior was unchanged. The same regression command passed after this test correction. |
| + |
| +### Final verification |
| + |
| +All final commands exited 0: |
| + |
| +- `CGO_ENABLED=0 go test ./internal/equipo/personapi ./internal/plan3test -run '^TestPersonAPI' -count=1`: personapi 0.007s, plan3test 2.600s. Covers all 35 3a operations, auth audiences, real outer-handler CSRF, runner and cleanup credentials, same-origin browser writes, current roster/session epoch, request replay, private resources, shared threads, preference/plan parity, coordinator binding/reset/retry/limits, both question kinds, rendered approval, merge acknowledgement, cursor scope/expiry, body limits, strict JSON, metadata rollback, nullable usage and migration upgrade/reopen. |
| +- `CGO_ENABLED=0 go test ./internal/plan3test -run '^(TestConversation(Scriptless|Question)|TestPreferences|TestPlan(Edit|Approval|ProjectCorrection)|TestRenderedChangeApprovalAuthority)' -count=1`: 8.284s after the stale preference notification expectation was corrected. |
| +- `CGO_ENABLED=0 go test ./internal/equipotest -run '^(TestRunnerAppCSRF|TestSigninCSRF|TestRosterChangesAffectExistingSession|TestTaskFormsCSRFAndRevision|TestQuestionBrowserAuthorityHTTP|TestTaskPagesWeeklyAndMergeAuthority)$' -count=1`: 13.704s. |
| +- `CGO_ENABLED=0 go test ./internal/plan3test -run '^TestPersonAPIOpenAPIContract$' -count=1`: 0.346s. The independent 3a route inventory matches the mounted routes and OpenAPI operations. All operations have typed success responses and mutation bodies. A separate local JSON reference walk found no broken OpenAPI references. |
| +- `make migration-check`: `CGO_ENABLED=0 go test ./internal/equipo -run '^TestMigrationModels$' -count=1`, 0.128s. |
| +- `CGO_ENABLED=0 go vet ./internal/equipo ./internal/equipo/personapi ./internal/equipo/conversation ./internal/equipo/planning ./internal/equipo/kernel ./internal/runnerproto ./internal/plan3test`. |
| +- `gofmt -l internal/equipo/*.go internal/equipo/personapi/*.go internal/equipo/conversation/*.go internal/equipo/planning/*.go internal/equipo/kernel/*.go internal/runnerproto/*.go internal/plan3test/*.go`: no output. |
| +- `CGO_ENABLED=0 go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size`: all 31 directories within their existing budgets. No exemption or ceiling changed. |
| +- `git diff --check`: no findings. |
| + |
| +### Guard mutations |
| + |
| +- **global-wrapper**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIBrowserCSRF -count=1`. Exit 1; person_api_operations_test.go:165: HTTP 403, want 200; person_api_test.go:109: HTTP 403, want 200. Restored byte-for-byte: yes. |
| +- **cookie-protection**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIBrowserCSRF$ -count=1`. Exit 1; person_api_test.go:109: HTTP 200, want 403. Restored byte-for-byte: yes. |
| +- **person-audience-default-deny**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIAuthAudiences$ -count=1`. Exit 1; person_api_test.go:63: HTTP 200, want 401. Restored byte-for-byte: yes. |
| +- **mixed-auth**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIBrowserCSRF$ -count=1`. Exit 1; person_api_test.go:109: HTTP 200, want 401. Restored byte-for-byte: yes. |
| +- **current-roster**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPISessionRevocationAndReplayAuthority$ -count=1`. Exit 1; person_api_test.go:221: HTTP 200, want 403. Restored byte-for-byte: yes. |
| +- **session-epoch**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPISessionRevocationAndReplayAuthority$ -count=1`. Exit 1; person_api_test.go:219: HTTP 200, want 403. Restored byte-for-byte: yes. |
| +- **revision**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIRevisionReplay$ -count=1`. Exit 1; person_api_test.go:137: HTTP 200, want 409. Restored byte-for-byte: yes. |
| +- **canonical-replay**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIRevisionReplay$ -count=1`. Exit 1; person_api_test.go:143: HTTP 200, want 409. Restored byte-for-byte: yes. |
| +- **metadata-atomicity**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIPaginationAndValidation$ -count=1`. Exit 1; person_api_operations_test.go:140: HTTP 200, want 503. Restored byte-for-byte: yes. |
| +- **duplicate-keys**: `CGO_ENABLED=0 go test ./internal/equipo/personapi -run ^TestPersonAPIValidate$ -count=1`. Exit 1; validate_test.go:12: accepted invalid input "{\"body\":\"a\",\"body\":\"b\"}". Restored byte-for-byte: yes. |
| +- **cursor-scope**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIPaginationAndValidation$ -count=1`. Exit 1; person_api_operations_test.go:128: HTTP 200, want 410. Restored byte-for-byte: yes. |
| +- **merge-owner-replay**: `CGO_ENABLED=0 go test ./internal/plan3test -run ^TestPersonAPIRenderedAndMerge$ -count=1`. Exit 1; person_api_evidence_test.go:71: HTTP 200, want 409. Restored byte-for-byte: yes. |
| + |
| +Full report: `.superpowers/sdd/2026-11-04-equipo-plan-3-coordinator/task-10-report.md`. No agents, live provider runs, sign-ins, enrolment, credential homes, make ci or full suite. Scratch stayed under on-disk TMPDIR and host Go caches stayed at their defaults. No persistent process was started. |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 3ee33ef3..0d63df90 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -11,10 +11,10 @@ import ( |
| "github.com/go-chi/chi/v5" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| "amadan.net/rastrillo/rastrillo" |
| "amadan.net/rastrillo/rastrillo/auth" |
| "amadan.net/rastrillo/rastrillo/background" |
| - "amadan.net/rastrillo/rastrillo/csrf" |
| "amadan.net/rastrillo/rastrillo/db" |
| "amadan.net/rastrillo/rastrillo/live" |
| _ "amadan.net/rastrillo/rastrillo/locales/en" |
| @@ -144,8 +144,17 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| } |
| a.Use(a.live.Middleware) |
| runner := a.store.runnerRouter() |
| - exempt := append([]string{"/api/enrolments", "/api/enrolments/token"}, runnerCSRFExemptPaths(runner)...) |
| - a.Use(csrf.Protect(cfg.Origin, csrf.Exempt(exempt...))) |
| + store.personOrigin = cfg.Origin |
| + store.personCookie = func(r *http.Request) (personapi.PersonPrincipal, error) { |
| + id, ok := authentication.SessionFrom(r) |
| + if !ok { |
| + return personapi.PersonPrincipal{}, personapi.ErrUnauthenticated |
| + } |
| + return personapi.PersonPrincipal{Address: id.Address, SessionEpoch: id.At.Unix()}, nil |
| + } |
| + person := store.personAPIRouter() |
| + a.Use(personapi.Dispatcher(cfg.Origin, runner, person, func(w http.ResponseWriter) { runnerFailure(w, ErrForbidden) })) |
| + a.Mount("/api/v1", person) |
| a.Post("/api/enrolments", a.beginEnrolment) |
| a.Post("/api/enrolments/token", a.exchangeEnrolment) |
| a.Mount("/api/runner/v2", runner) |
diff --git a/internal/equipo/cancel.go b/internal/equipo/cancel.go| index 27c46619..35d3a66a 100644 |
| --- a/internal/equipo/cancel.go |
| +++ b/internal/equipo/cancel.go |
| @@ -3,6 +3,7 @@ package equipo |
| import ( |
| "context" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| "amadan.net/oficina/equipo/internal/equipo/team" |
| "gorm.io/gorm" |
| ) |
| @@ -14,11 +15,15 @@ type TaskCancellation struct { |
| } |
| func (s *Store) CancelTask(ctx context.Context, actor Actor, id string) (TaskCancellation, error) { |
| + return s.cancelTask(ctx, actor, id, nil) |
| +} |
| +func (s *Store) cancelTask(ctx context.Context, actor Actor, id string, m *Mutation) (TaskCancellation, error) { |
| var result TaskCancellation |
| if s.execution == nil { |
| return result, ErrUnavailable |
| } |
| - err := s.execution.atomic(ctx, func(ctx context.Context, tx *gorm.DB) error { |
| + err := s.write(ctx, func(tx *gorm.DB) error { |
| + ctx := tx.Statement.Context |
| member, err := currentRunnerMember(tx, actor.Address) |
| if err != nil { |
| return err |
| @@ -30,6 +35,14 @@ func (s *Store) CancelTask(ctx context.Context, actor Actor, id string) (TaskCan |
| if member.Address != task.Requester && member.Role != RoleOwner { |
| return ErrForbidden |
| } |
| + if m != nil { |
| + if ok, e := personapi.Replay(tx, ctx, &result, ErrConflict); ok || e != nil { |
| + return e |
| + } |
| + if task.Revision != m.Revision { |
| + return ErrConflict |
| + } |
| + } |
| result.Contained = true |
| if task.JobID != 0 { |
| result.Report, err = s.execution.Core.Cancel(ctx, Scope{Account: team.AccountID(task.TeamID), Job: task.JobID}, actor.Address, "person_cancelled") |
| @@ -62,10 +75,13 @@ func (s *Store) CancelTask(ctx context.Context, actor Actor, id string) (TaskCan |
| if result.Contained { |
| state = "cancelled" |
| } |
| - if err = tx.Model(&Task{}).Where("id=?", id).Select("State").Updates(&Task{State: state}).Error; err != nil { |
| + if err = tx.Model(&Task{}).Where("id=?", id).Select("State", "Revision").Updates(&Task{State: state, Revision: task.Revision + 1}).Error; err != nil { |
| return storeError(err) |
| } |
| - return appendAudit(tx, actor, "task.cancel", id) |
| + if err = appendAudit(tx, actor, "task.cancel", id); err != nil { |
| + return err |
| + } |
| + return personapi.SaveResult(tx, ctx, result, ErrConflict) |
| }) |
| return result, err |
| } |
diff --git a/internal/equipo/conversation/views.go b/internal/equipo/conversation/views.go| index e61ffc26..1674ae09 100644 |
| --- a/internal/equipo/conversation/views.go |
| +++ b/internal/equipo/conversation/views.go |
| @@ -164,3 +164,16 @@ func (s *Store) questionView(a Actor, id string, now time.Time) (q runnerproto.C |
| } |
| return |
| } |
| + |
| +func (s *Application) Question(ctx context.Context, a Actor, id string) (q runnerproto.ClarificationQuestion, can bool, err error) { |
| + a.Address = s.Normalize(a.Address) |
| + err = s.Write(ctx, func(tx *gorm.DB) error { |
| + var e error |
| + q, can, e = s.Conversation(tx).questionView(a, id, s.Now().UTC()) |
| + if errors.Is(e, gorm.ErrRecordNotFound) { |
| + return s.NotFound |
| + } |
| + return e |
| + }) |
| + return |
| +} |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 52ac7064..43febed9 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -631,6 +631,24 @@ var runnerDraftCopy = map[string]string{ |
| "recovery.uncontained": "Uncontained attempts", |
| // COPY REVIEW REQUIRED: runner.preflight.unavailable |
| "runner.preflight.unavailable": "Runner preflight is unavailable.", |
| + // COPY REVIEW REQUIRED: api.unauthenticated |
| + "api.unauthenticated": "Sign in to continue.", |
| + // COPY REVIEW REQUIRED: api.forbidden |
| + "api.forbidden": "You cannot do that with your current access.", |
| + // COPY REVIEW REQUIRED: api.not_found |
| + "api.not_found": "This item is not available.", |
| + // COPY REVIEW REQUIRED: api.method_not_allowed |
| + "api.method_not_allowed": "This action is not available here.", |
| + // COPY REVIEW REQUIRED: api.precondition_required |
| + "api.precondition_required": "Send the request key and current revision.", |
| + // COPY REVIEW REQUIRED: api.revision_conflict |
| + "api.revision_conflict": "This item changed. Fetch its current revision and try again.", |
| + // COPY REVIEW REQUIRED: api.invalid_input |
| + "api.invalid_input": "Check the request fields and try again.", |
| + // COPY REVIEW REQUIRED: api.cursor_expired |
| + "api.cursor_expired": "This page link expired. Fetch the list again.", |
| + // COPY REVIEW REQUIRED: api.unavailable |
| + "api.unavailable": "This information is unavailable. Try again later.", |
| // COPY REVIEW REQUIRED: question.behavior |
| "question.behavior": "Decision", |
| // COPY REVIEW REQUIRED: question.allow |
diff --git a/internal/equipo/kernel/types.go b/internal/equipo/kernel/types.go| index ca9f5d3e..ac59f4fa 100644 |
| --- a/internal/equipo/kernel/types.go |
| +++ b/internal/equipo/kernel/types.go |
| @@ -8,3 +8,23 @@ type Mutation struct { |
| RequestID string |
| Revision int64 |
| } |
| + |
| +type ProjectKind string |
| + |
| +const ( |
| + ProjectApp ProjectKind = "app" |
| + ProjectWebsite ProjectKind = "website" |
| + ProjectRepository ProjectKind = "repository" |
| +) |
| + |
| +type Project struct { |
| + GrantVersion int64 `gorm:"not null;default:1"` |
| + ID int64 |
| + AccountID int64 |
| + Name string |
| + Repository string `gorm:"not null;uniqueIndex:project_binding"` |
| + AppName string `gorm:"not null;uniqueIndex:project_binding"` |
| + DefaultBranch string |
| + Kind ProjectKind |
| + Revision int64 |
| +} |
diff --git a/internal/equipo/migrations/0023_person_api_requests.sql b/internal/equipo/migrations/0023_person_api_requests.sql| new file mode 100644 |
| index 00000000..74e74a2b |
| --- /dev/null |
| +++ b/internal/equipo/migrations/0023_person_api_requests.sql |
| @@ -0,0 +1,2 @@ |
| +CREATE TABLE person_api_requests (principal text, operation text, resource text, request_id text, input_hash text, result text, created_at datetime, PRIMARY KEY (principal,operation,resource,request_id)); |
| +CREATE TABLE person_api_cursors (id text PRIMARY KEY, principal text, scope text, items text, revision integer, expires_at datetime); |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 95264e5d..cdbbbcc4 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -383,3 +383,5 @@ ALTER TABLE audit_events ADD COLUMN delegating_person text; |
| CREATE UNIQUE INDEX coordinator_active ON coordinator_turns(team_id,person) WHERE state='running'; |
| CREATE TABLE personal_preferences (id text PRIMARY KEY, text text, status text, source_message_id text, revision integer, team_id text, person text, source_revision integer, deleted_at datetime); |
| CREATE TABLE personal_settings (team_id text, person text, landing text, revision integer, PRIMARY KEY (team_id,person)); |
| +CREATE TABLE person_api_requests (principal text, operation text, resource text, request_id text, input_hash text, result text, created_at datetime, PRIMARY KEY (principal,operation,resource,request_id)); |
| +CREATE TABLE person_api_cursors (id text PRIMARY KEY, principal text, scope text, items text, revision integer, expires_at datetime); |
diff --git a/internal/equipo/models.go b/internal/equipo/models.go| index 4476ebd9..31af676a 100644 |
| --- a/internal/equipo/models.go |
| +++ b/internal/equipo/models.go |
| @@ -5,10 +5,11 @@ import ( |
| "amadan.net/oficina/equipo/internal/equipo/conversation" |
| "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| "amadan.net/oficina/equipo/internal/equipo/planning" |
| ) |
| -var Models = append(append(append([]any{&supervisedTrialRecord{}, &questionRecord{}, &runnerEvent{}, &runnerEventID{}, &runnerTimeline{}, &runnerArtifactRequest{}, &artifactBlob{}, &artifactBlobUpload{}, &runnerAssignment{}, &runnerCleanup{}, &runnerObservation{}, &runnerRotation{}, &executionAdmissionTicket{}, &Task{}, &taskOutbox{}, &Team{}, &Member{}, &AuditEvent{}, &Account{}, &Project{}, &DecisionOwner{}, &projectRequest{}, &budgetRecord{}, &Specialist{}, &runnerRecord{}, &runnerEnrolment{}, &runnerCredentialRecord{}, &runnerRate{}, &connectionRecord{}, &connectionChoiceRecord{}, &isolationAcknowledgementRecord{}, &ConnectionInvalidation{}}, executionModels...), conversation.Models...), planning.Models...) |
| +var Models = append(append(append(append([]any{&supervisedTrialRecord{}, &questionRecord{}, &runnerEvent{}, &runnerEventID{}, &runnerTimeline{}, &runnerArtifactRequest{}, &artifactBlob{}, &artifactBlobUpload{}, &runnerAssignment{}, &runnerCleanup{}, &runnerObservation{}, &runnerRotation{}, &executionAdmissionTicket{}, &Task{}, &taskOutbox{}, &Team{}, &Member{}, &AuditEvent{}, &Account{}, &Project{}, &DecisionOwner{}, &projectRequest{}, &budgetRecord{}, &Specialist{}, &runnerRecord{}, &runnerEnrolment{}, &runnerCredentialRecord{}, &runnerRate{}, &connectionRecord{}, &connectionChoiceRecord{}, &isolationAcknowledgementRecord{}, &ConnectionInvalidation{}}, executionModels...), conversation.Models...), planning.Models...), personapi.Models...) |
| type Role string |
| @@ -49,26 +50,15 @@ type Account struct { |
| Revision int64 |
| } |
| -type ProjectKind string |
| +type ProjectKind = kernel.ProjectKind |
| +type Project = kernel.Project |
| const ( |
| - ProjectApp ProjectKind = "app" |
| - ProjectWebsite ProjectKind = "website" |
| - ProjectRepository ProjectKind = "repository" |
| + ProjectApp = kernel.ProjectApp |
| + ProjectWebsite = kernel.ProjectWebsite |
| + ProjectRepository = kernel.ProjectRepository |
| ) |
| -type Project struct { |
| - GrantVersion int64 `gorm:"not null;default:1"` |
| - ID int64 |
| - AccountID int64 |
| - Name string |
| - Repository string `gorm:"not null;uniqueIndex:project_binding"` |
| - AppName string `gorm:"not null;uniqueIndex:project_binding"` |
| - DefaultBranch string |
| - Kind ProjectKind |
| - Revision int64 |
| -} |
| - |
| type DecisionOwner struct { |
| ProjectID int64 `gorm:"primaryKey;autoIncrement:false"` |
| Decision string `gorm:"primaryKey"` |
diff --git a/internal/equipo/person_api.go b/internal/equipo/person_api.go| new file mode 100644 |
| index 00000000..a03bcde6 |
| --- /dev/null |
| +++ b/internal/equipo/person_api.go |
| @@ -0,0 +1,58 @@ |
| +package equipo |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "net/http" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "github.com/go-chi/chi/v5" |
| + "gorm.io/gorm" |
| +) |
| + |
| +type PersonPrincipal = personapi.PersonPrincipal |
| +type VerifyPersonBearer = personapi.VerifyPersonBearer |
| + |
| +func WithPersonBearerVerifier(verify VerifyPersonBearer) StoreOption { |
| + return func(s *Store) { s.personBearer = verify } |
| +} |
| +func (s *Store) PersonAPIHandler() http.Handler { return s.personAPIRouter() } |
| +func (s *Store) personAPIRouter() chi.Router { |
| + auth := personapi.Authenticator{Origin: s.personOrigin, Cookie: s.personCookie, Bearer: s.personBearer, Forbidden: ErrForbidden, Member: func(r *http.Request, p PersonPrincipal) error { |
| + m, err := s.Member(r.Context(), p.Address) |
| + if errors.Is(err, ErrNotFound) { |
| + return ErrForbidden |
| + } |
| + if err != nil { |
| + return err |
| + } |
| + if !m.Active || p.SessionEpoch < m.SessionEpoch { |
| + return ErrForbidden |
| + } |
| + return nil |
| + }} |
| + return (&personapi.Handler{App: s, Authenticate: auth.Authenticate, Invalid: ErrInvalid, Forbidden: ErrForbidden, NotFound: ErrNotFound, Conflict: ErrConflict, Unavailable: ErrUnavailable, CursorExpired: ErrCursorExpired}).Router() |
| +} |
| +func (s *Store) PersonAPIPage(ctx context.Context, a Actor, scope, cursor string, limit int, in personapi.Result) (out personapi.Result, err error) { |
| + err = s.write(ctx, func(tx *gorm.DB) error { |
| + if _, e := currentRunnerMember(tx, a.Address); e != nil { |
| + return e |
| + } |
| + var e error |
| + out, e = personapi.Paginate(tx, a.Address, scope, cursor, limit, in, ErrCursorExpired) |
| + return e |
| + }) |
| + return |
| +} |
| +func (s *Store) PersonAPIRead(ctx context.Context, a Actor, op, id string) (personapi.Result, error) { |
| + reader := personapi.Reader{Conversation: s.coordinatorApplication(), TaskView: s.TaskView, Journey: s.Journey, NotFound: ErrNotFound, ReadTeam: func(ctx context.Context, a Actor, fn func(*gorm.DB, personapi.Team) error) error { |
| + return s.readTeam(ctx, a, func(tx *gorm.DB, t Team) error { |
| + return fn(tx, personapi.Team{ID: t.ID, Name: t.Name, RosterEpoch: t.RosterEpoch}) |
| + }) |
| + }} |
| + return reader.Read(ctx, a, op, id) |
| +} |
| +func (s *Store) PersonAPICancel(ctx context.Context, a Actor, id string, m Mutation) (personapi.Ack, error) { |
| + _, err := s.cancelTask(ctx, a, id, &m) |
| + return personapi.Ack{Revision: m.Revision + 1}, err |
| +} |
diff --git a/internal/equipo/personapi/auth.go b/internal/equipo/personapi/auth.go| new file mode 100644 |
| index 00000000..37b7b8d0 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/auth.go |
| @@ -0,0 +1,131 @@ |
| +package personapi |
| + |
| +import ( |
| + "context" |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + |
| + "amadan.net/rastrillo/rastrillo/csrf" |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +type Authenticator struct { |
| + Origin string |
| + Cookie func(*http.Request) (PersonPrincipal, error) |
| + Bearer VerifyPersonBearer |
| + Member func(*http.Request, PersonPrincipal) error |
| + Forbidden error |
| +} |
| + |
| +func (a Authenticator) Authenticate(r *http.Request) (PersonPrincipal, error) { |
| + var p PersonPrincipal |
| + var err error |
| + if headers := r.Header.Values("Authorization"); len(headers) != 0 { |
| + if len(headers) != 1 || len(r.Header.Values("Cookie")) != 0 || !strings.HasPrefix(headers[0], "Bearer ") || a.Bearer == nil { |
| + return p, ErrUnauthenticated |
| + } |
| + token := strings.TrimPrefix(headers[0], "Bearer ") |
| + if token == "" || strings.ContainsAny(token, " \t\r\n") { |
| + return p, ErrUnauthenticated |
| + } |
| + p, err = a.Bearer(r.Context(), token) |
| + if err != nil || p.CredentialID == "" { |
| + return PersonPrincipal{}, ErrUnauthenticated |
| + } |
| + } else { |
| + if a.Cookie == nil { |
| + return p, ErrUnauthenticated |
| + } |
| + p, err = a.Cookie(r) |
| + if err != nil { |
| + return p, err |
| + } |
| + } |
| + if p.Address == "" || p.SessionEpoch <= 0 { |
| + return PersonPrincipal{}, ErrUnauthenticated |
| + } |
| + if err = a.Member(r, p); err != nil { |
| + return PersonPrincipal{}, err |
| + } |
| + if !OriginAllowed(r, a.Origin) { |
| + return PersonPrincipal{}, a.Forbidden |
| + } |
| + if len(r.Header.Values("Authorization")) == 0 && Mutating(r.Method) && !csrf.SameOrigin(r, a.Origin) { |
| + return PersonPrincipal{}, a.Forbidden |
| + } |
| + return p, nil |
| +} |
| +func Mutating(method string) bool { return method != "GET" && method != "HEAD" && method != "OPTIONS" } |
| +func OriginAllowed(r *http.Request, origin string) bool { |
| + if values := r.Header.Values("Origin"); len(values) > 1 || len(values) == 1 && values[0] != origin { |
| + return false |
| + } |
| + if values := r.Header.Values("Referer"); len(values) > 1 { |
| + return false |
| + } else if len(values) == 1 { |
| + u, err := url.Parse(values[0]) |
| + if err != nil || u.Scheme+"://"+u.Host != origin { |
| + return false |
| + } |
| + } |
| + switch r.Header.Get("Sec-Fetch-Site") { |
| + case "", "same-origin", "none": |
| + return true |
| + default: |
| + return false |
| + } |
| +} |
| + |
| +// Dispatcher bypasses the browser wrapper only for registered protocol routes. |
| +// Their handlers verify their own credentials before accepting a mutation. |
| +func Dispatcher(origin string, runner, person chi.Routes, refuseRunner func(http.ResponseWriter)) func(http.Handler) http.Handler { |
| + return func(next http.Handler) http.Handler { |
| + browser := csrf.Protect(origin)(next) |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + protocol := registered(r, runner, "/api/runner/v2") |
| + personRoute := registered(r, person, "/api/v1") |
| + public := r.Method == "POST" && (r.URL.Path == "/api/enrolments" || r.URL.Path == "/api/enrolments/token") |
| + if personRoute { |
| + next.ServeHTTP(w, r) |
| + return |
| + } |
| + if protocol || public { |
| + if len(r.Header.Values("Cookie")) != 0 || !OriginAllowed(r, origin) { |
| + refuseRunner(w) |
| + return |
| + } |
| + next.ServeHTTP(w, r) |
| + return |
| + } |
| + if len(r.Header.Values("Authorization")) != 0 { |
| + WriteError(w, r, 401, "unauthenticated", nil) |
| + return |
| + } |
| + if strings.HasPrefix(r.URL.Path, "/api/v1/") || r.URL.Path == "/api/v1" { |
| + // Unknown methods/paths still receive API errors and identity validation. |
| + if Mutating(r.Method) && !csrf.SameOrigin(r, origin) { |
| + WriteError(w, r, 403, "forbidden", nil) |
| + return |
| + } |
| + next.ServeHTTP(w, r) |
| + return |
| + } |
| + browser.ServeHTTP(w, r) |
| + }) |
| + } |
| +} |
| +func registered(r *http.Request, routes chi.Routes, prefix string) bool { |
| + if !strings.HasPrefix(r.URL.Path, prefix+"/") { |
| + return false |
| + } |
| + return routes.Match(chi.NewRouteContext(), r.Method, strings.TrimPrefix(r.URL.Path, prefix)) |
| +} |
| +func PrincipalFrom(ctx context.Context) (PersonPrincipal, bool) { |
| + p, ok := ctx.Value(principalKey{}).(PersonPrincipal) |
| + return p, ok |
| +} |
| + |
| +func DenyPersonBearer(context.Context, string) (PersonPrincipal, error) { |
| + return PersonPrincipal{}, ErrUnauthenticated |
| +} |
diff --git a/internal/equipo/personapi/budget_test.go b/internal/equipo/personapi/budget_test.go| new file mode 100644 |
| index 00000000..80ae08e4 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/budget_test.go |
| @@ -0,0 +1,9 @@ |
| +package personapi |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/budget" |
| + "os" |
| + "testing" |
| +) |
| + |
| +func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |
diff --git a/internal/equipo/personapi/conversation.go b/internal/equipo/personapi/conversation.go| new file mode 100644 |
| index 00000000..8565a8e5 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/conversation.go |
| @@ -0,0 +1,189 @@ |
| +package personapi |
| + |
| +import ( |
| + "context" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/conversation" |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "amadan.net/oficina/equipo/internal/equipo/planning" |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| + "amadan.net/oficina/equipo/internal/taskplan" |
| +) |
| + |
| +func ProjectMessage(m conversation.Message) Message { |
| + return Message{ID: m.ID, ConversationID: m.ConversationID, ThreadID: m.ThreadID, AuthorKind: m.AuthorKind, AuthorID: m.AuthorID, Body: m.Body, Sequence: m.Sequence, Revision: m.Revision, CreatedAt: m.CreatedAt.UTC(), Sources: m.SourceRefs} |
| +} |
| +func ProjectCard(c conversation.Card) Card { |
| + return Card{ID: c.ID, Kind: c.Kind, ResourceID: c.ResourceID, TaskID: c.TaskID, Revision: c.Revision, CopyKey: c.CopyKey, Actions: c.ActionKeys, WaitingTaskID: c.WaitingTaskID} |
| +} |
| +func projectConversation(p conversation.ConversationPage) ConversationPage { |
| + out := ConversationPage{Messages: []Message{}, Cards: []Card{}, NextCursor: p.NextCursor, Revision: p.Revision} |
| + for _, m := range p.Messages { |
| + out.Messages = append(out.Messages, ProjectMessage(m)) |
| + } |
| + for _, c := range p.Cards { |
| + out.Cards = append(out.Cards, ProjectCard(c)) |
| + } |
| + return out |
| +} |
| +func ProjectPreference(p conversation.Preference) Preference { |
| + return Preference{p.ID, p.Text, p.Status, p.SourceMessageID, p.Revision} |
| +} |
| +func ProjectTask(t planning.Task) Task { |
| + return Task{ID: t.ID, ProjectID: t.ProjectID, Requester: t.Requester, Description: t.Description, Kind: t.Kind, State: t.State, Revision: t.Revision, PlanRevision: t.PlanRevision, ReplacementID: t.ReplacementID, Steps: []Step{}} |
| +} |
| +func ProjectBinding(b runnerproto.CoordinatorBinding) Coordinator { |
| + return Coordinator{ID: b.ID, RunnerID: b.RunnerID, ConnectionID: b.ConnectionID, Generation: b.Generation, Revision: b.Revision, WaitingTaskID: b.WaitingTaskID, Turns: []Turn{}} |
| +} |
| +func (p PlanInput) Value(id string, rev int64) taskplan.Plan { |
| + out := taskplan.Plan{TaskID: id, Revision: rev, Kind: p.Kind, ProjectID: p.ProjectID, PlaybookID: p.PlaybookID, PlaybookRevision: p.PlaybookRevision} |
| + for _, s := range p.Steps { |
| + out.Steps = append(out.Steps, taskplan.Step{Key: s.Key, Specialist: s.Specialist, Action: s.Action, Instructions: s.Instructions, ConnectionID: s.ConnectionID, Model: s.Model, SelectionReason: s.SelectionReason, DependsOn: s.DependsOn}) |
| + } |
| + return out |
| +} |
| +func ProjectPlan(p taskplan.Plan) Plan { |
| + out := Plan{TaskID: p.TaskID, Revision: p.Revision, RequiredSteps: []string{}, PlanInput: PlanInput{Kind: p.Kind, ProjectID: p.ProjectID, PlaybookID: p.PlaybookID, PlaybookRevision: p.PlaybookRevision, Steps: []PlanStep{}}} |
| + for _, s := range p.Steps { |
| + out.Steps = append(out.Steps, PlanStep{Key: s.Key, Specialist: s.Specialist, Action: s.Action, Instructions: s.Instructions, ConnectionID: s.ConnectionID, Model: s.Model, SelectionReason: s.SelectionReason, DependsOn: s.DependsOn}) |
| + if s.Required { |
| + out.RequiredSteps = append(out.RequiredSteps, s.Key) |
| + } |
| + } |
| + return out |
| +} |
| +func (h *Handler) read(ctx context.Context, a kernel.Actor, op, id, cursor string, limit int) (Result, error) { |
| + switch op { |
| + case "conversation", "thread": |
| + var p conversation.ConversationPage |
| + var err error |
| + if op == "conversation" { |
| + p, err = h.App.Conversation(ctx, a, cursor, limit) |
| + } else { |
| + p, err = h.App.TaskThread(ctx, a, id, cursor, limit) |
| + } |
| + return Result{projectConversation(p), p.Revision}, err |
| + case "settings": |
| + v, err := h.App.PersonalSettings(ctx, a) |
| + return Result{Settings{v.Landing, v.Revision}, v.Revision}, err |
| + case "plan": |
| + v, err := h.App.TaskPlan(ctx, a, id) |
| + return Result{ProjectPlan(v), v.Revision}, err |
| + case "preferences": |
| + v, err := h.App.Preferences(ctx, a) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + items := []Preference{} |
| + for _, p := range v { |
| + items = append(items, ProjectPreference(p)) |
| + } |
| + return h.App.PersonAPIPage(ctx, a, op, cursor, limit, Result{Value: items}) |
| + case "capabilities": |
| + return Result{struct { |
| + Version string `json:"version"` |
| + BrowserSession bool `json:"browser_session"` |
| + DeviceBearer bool `json:"device_bearer"` |
| + Part string `json:"part"` |
| + }{"1.0.0", true, false, "3a"}, 1}, nil |
| + } |
| + out, err := h.App.PersonAPIRead(ctx, a, op, id) |
| + if err != nil { |
| + return out, err |
| + } |
| + switch op { |
| + case "people", "cards", "tasks", "journey", "needs_you": |
| + return h.App.PersonAPIPage(ctx, a, op, cursor, limit, out) |
| + } |
| + if cursor != "" { |
| + return Result{}, h.Invalid |
| + } |
| + return out, nil |
| +} |
| +func (h *Handler) mutate(ctx context.Context, a kernel.Actor, op, id string, input any, m kernel.Mutation) (Result, error) { |
| + switch op { |
| + case "send", "send_thread": |
| + v := input.(*MessageInput) |
| + thread := "" |
| + if op == "send_thread" { |
| + thread = id |
| + } |
| + out, err := h.App.SendMessage(ctx, a, thread, v.Body, m) |
| + return Result{ProjectMessage(out), out.Revision}, err |
| + case "route": |
| + out, err := h.App.RouteMessage(ctx, a, id, input.(*RouteInput).TaskID, m) |
| + return Result{ProjectMessage(out), out.Revision}, err |
| + case "settings": |
| + out, err := h.App.SavePersonalSettings(ctx, a, conversation.PersonalSettings{Landing: input.(*SettingsInput).Landing}, m) |
| + return Result{Settings{out.Landing, out.Revision}, out.Revision}, err |
| + case "preference": |
| + v := input.(*PreferenceInput) |
| + out, err := h.App.SetPreference(ctx, a, conversation.Preference{ID: id, Text: v.Text, Status: "confirmed", SourceMessageID: v.SourceMessageID}, m) |
| + return Result{ProjectPreference(out), out.Revision}, err |
| + case "delete_preference": |
| + return Result{Ack{m.Revision + 1}, m.Revision + 1}, h.App.DeletePreference(ctx, a, id, m) |
| + case "propose", "edit_plan": |
| + v := input.(*PlanInput).Value(id, 0) |
| + var out taskplan.Plan |
| + var err error |
| + if op == "propose" { |
| + out, err = h.App.ProposePlan(ctx, a, v, m) |
| + } else { |
| + v.Revision = m.Revision |
| + out, err = h.App.EditPlan(ctx, a, v, m) |
| + } |
| + return Result{ProjectPlan(out), out.Revision}, err |
| + case "approve_plan": |
| + out, err := h.App.ApprovePlan(ctx, a, id, m) |
| + return Result{ProjectTask(out), out.Revision}, err |
| + case "project": |
| + out, err := h.App.CorrectTaskProject(ctx, a, id, input.(*ProjectInput).ProjectID, m) |
| + return Result{ProjectTask(out), out.Revision}, err |
| + case "binding": |
| + v := input.(*BindingInput) |
| + out, err := h.App.SaveCoordinatorBinding(ctx, a, v.RunnerID, v.ConnectionID, m) |
| + return Result{ProjectBinding(out), out.Revision}, err |
| + case "reset": |
| + out, err := h.App.ResetCoordinator(ctx, a, m) |
| + return Result{ProjectBinding(out), out.Revision}, err |
| + case "retry": |
| + out, err := h.App.RetryCoordinatorTurn(ctx, a, input.(*RetryInput).TurnID, m) |
| + return Result{Turn{out.ID, out.State, out.Revision}, out.Revision}, err |
| + case "limits": |
| + v := input.(*LimitsInput) |
| + l := v.Limits |
| + return Result{Ack{m.Revision + 1}, m.Revision + 1}, h.App.SetCoordinatorLimits(ctx, a, v.Person, team.Limits{Calls: l.Calls, InputTokens: l.InputTokens, OutputTokens: l.OutputTokens, Seconds: l.Seconds}, m) |
| + case "answer": |
| + v := input.(*AnswerInput) |
| + var err error |
| + switch v.Kind { |
| + case "clarification": |
| + if v.Behavior != "" || len(v.UpdatedInput) != 0 { |
| + return Result{}, h.Invalid |
| + } |
| + err = h.App.AnswerClarification(ctx, a, id, v.OptionID, v.Text, m) |
| + case "native": |
| + if v.OptionID != "" || v.Text != "" { |
| + return Result{}, h.Invalid |
| + } |
| + err = h.App.AnswerQuestion(ctx, a, id, m.Revision, runnerproto.QuestionAnswer{Behavior: v.Behavior, UpdatedInput: v.UpdatedInput}) |
| + default: |
| + return Result{}, h.Invalid |
| + } |
| + revision := m.Revision |
| + if v.Kind == "clarification" { |
| + revision++ |
| + } |
| + return Result{Ack{revision}, revision}, err |
| + case "rendered": |
| + v := input.(*RenderedInput) |
| + return Result{Ack{m.Revision + 1}, m.Revision + 1}, h.App.ApproveRenderedChange(ctx, a, id, v.CandidateHash, v.DiffHash, v.RenderHash, v.Decision, m) |
| + case "merge": |
| + return Result{Ack{m.Revision + 1}, m.Revision + 1}, h.App.AcknowledgeMerge(ctx, a, id, m.Revision, input.(*MergeInput).Reference) |
| + case "cancel": |
| + out, err := h.App.PersonAPICancel(ctx, a, id, m) |
| + return Result{out, out.Revision}, err |
| + } |
| + return Result{}, h.NotFound |
| +} |
diff --git a/internal/equipo/personapi/handler.go b/internal/equipo/personapi/handler.go| new file mode 100644 |
| index 00000000..1de9eb9c |
| --- /dev/null |
| +++ b/internal/equipo/personapi/handler.go |
| @@ -0,0 +1,177 @@ |
| +package personapi |
| + |
| +import ( |
| + "context" |
| + "crypto/rand" |
| + "encoding/json" |
| + "errors" |
| + "mime" |
| + "net/http" |
| + "strconv" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +type Handler struct { |
| + App Application |
| + Authenticate func(*http.Request) (PersonPrincipal, error) |
| + Invalid, Forbidden, NotFound, Conflict, Unavailable, CursorExpired error |
| +} |
| +type Route struct { |
| + Method, Path, Operation string |
| + Update bool |
| + Input func() any |
| +} |
| + |
| +var Routes = []Route{ |
| + {"GET", "/me", "me", false, nil}, {"GET", "/capabilities", "capabilities", false, nil}, |
| + {"GET", "/me/settings", "settings", false, nil}, {"PATCH", "/me/settings", "settings", true, func() any { return &SettingsInput{} }}, |
| + {"GET", "/people", "people", false, nil}, |
| + {"GET", "/conversation", "conversation", false, nil}, {"POST", "/conversation/messages", "send", false, func() any { return &MessageInput{} }}, |
| + {"GET", "/conversation/cards", "cards", false, nil}, {"GET", "/cards/{id}", "card", false, nil}, |
| + {"GET", "/tasks", "tasks", false, nil}, {"GET", "/tasks/{id}", "task", false, nil}, {"POST", "/tasks", "propose", false, func() any { return &PlanInput{} }}, |
| + {"POST", "/tasks/{id}/cancel", "cancel", true, func() any { return &struct{}{} }}, |
| + {"GET", "/tasks/{id}/thread", "thread", false, nil}, {"POST", "/tasks/{id}/thread/messages", "send_thread", false, func() any { return &MessageInput{} }}, |
| + {"POST", "/conversation/messages/{id}/route", "route", true, func() any { return &RouteInput{} }}, |
| + {"GET", "/tasks/{id}/plan", "plan", false, nil}, {"PATCH", "/tasks/{id}/plan", "edit_plan", true, func() any { return &PlanInput{} }}, |
| + {"POST", "/tasks/{id}/plan/approve", "approve_plan", true, func() any { return &struct{}{} }}, |
| + {"POST", "/tasks/{id}/project", "project", true, func() any { return &ProjectInput{} }}, |
| + {"GET", "/questions/{id}", "question", false, nil}, {"POST", "/questions/{id}/answer", "answer", true, func() any { return &AnswerInput{} }}, |
| + {"POST", "/tasks/{id}/rendered-approval", "rendered", true, func() any { return &RenderedInput{} }}, |
| + {"POST", "/tasks/{id}/acknowledge-merge", "merge", true, func() any { return &MergeInput{} }}, |
| + {"GET", "/journey", "journey", false, nil}, {"GET", "/needs-you", "needs_you", false, nil}, |
| + {"GET", "/preferences", "preferences", false, nil}, {"POST", "/preferences", "preference", false, func() any { return &PreferenceInput{} }}, |
| + {"PATCH", "/preferences/{id}", "preference", true, func() any { return &PreferenceInput{} }}, {"DELETE", "/preferences/{id}", "delete_preference", true, func() any { return &struct{}{} }}, |
| + {"GET", "/coordinator", "coordinator", false, nil}, {"PATCH", "/coordinator", "binding", true, func() any { return &BindingInput{} }}, |
| + {"POST", "/coordinator/reset", "reset", true, func() any { return &struct{}{} }}, {"POST", "/coordinator/retry", "retry", true, func() any { return &RetryInput{} }}, |
| + {"PATCH", "/coordinator/limits", "limits", true, func() any { return &LimitsInput{} }}, |
| +} |
| + |
| +func (h *Handler) Router() chi.Router { |
| + r := chi.NewRouter() |
| + r.Use(func(next http.Handler) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Cache-Control", "no-store") |
| + p, err := h.Authenticate(r) |
| + if err != nil { |
| + h.Failure(w, r, err) |
| + return |
| + } |
| + next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), principalKey{}, p))) |
| + }) |
| + }) |
| + for _, route := range Routes { |
| + r.Method(route.Method, route.Path, h.serve(route)) |
| + } |
| + r.NotFound(func(w http.ResponseWriter, r *http.Request) { WriteError(w, r, 404, "not_found", nil) }) |
| + r.MethodNotAllowed(func(w http.ResponseWriter, r *http.Request) { WriteError(w, r, 405, "method_not_allowed", nil) }) |
| + return r |
| +} |
| +func (h *Handler) serve(route Route) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + p, _ := r.Context().Value(principalKey{}).(PersonPrincipal) |
| + a := kernel.Actor{Address: p.Address} |
| + id := chi.URLParam(r, "id") |
| + var out Result |
| + var err error |
| + if route.Input == nil { |
| + cursor, limit, e := ListQuery(r) |
| + if e != nil { |
| + WriteError(w, r, 422, "invalid_input", nil) |
| + return |
| + } |
| + out, err = h.read(r.Context(), a, route.Operation, id, cursor, limit) |
| + } else { |
| + if len(r.URL.Query()) != 0 { |
| + WriteError(w, r, 422, "invalid_input", nil) |
| + return |
| + } |
| + m, status := Mutation(r, route.Update) |
| + if status != 0 { |
| + code := "invalid_input" |
| + if status == 428 { |
| + code = "precondition_required" |
| + } |
| + WriteError(w, r, status, code, nil) |
| + return |
| + } |
| + input := route.Input() |
| + media, _, e := mime.ParseMediaType(r.Header.Get("Content-Type")) |
| + if e != nil || media != "application/json" || Decode(r.Body, input) != nil { |
| + WriteError(w, r, 422, "invalid_input", nil) |
| + return |
| + } |
| + request := Request{Principal: p.Address, Operation: route.Operation, Resource: id, RequestID: m.RequestID} |
| + request.InputHash, err = CanonicalHash(struct { |
| + Input any |
| + Revision int64 |
| + }{input, m.Revision}) |
| + if err == nil { |
| + out, err = h.mutate(WithRequest(r.Context(), request), a, route.Operation, id, input, m) |
| + } |
| + } |
| + if err != nil { |
| + h.Failure(w, r, err) |
| + return |
| + } |
| + w.Header().Set("ETag", `"`+strconv.FormatInt(out.Revision, 10)+`"`) |
| + w.Header().Set("Content-Type", "application/json") |
| + _ = json.NewEncoder(w).Encode(out.Value) |
| + }) |
| +} |
| +func WriteError(w http.ResponseWriter, r *http.Request, status int, code string, current *int64) { |
| + w.Header().Set("Cache-Control", "no-store") |
| + w.Header().Set("Content-Type", "application/json") |
| + request := r.Header.Get("Idempotency-Key") |
| + if request == "" || len(request) > 256 { |
| + request = rand.Text() |
| + } |
| + w.WriteHeader(status) |
| + _ = json.NewEncoder(w).Encode(Error{Code: code, CopyKey: "api." + code, RequestID: request, CurrentRevision: current}) |
| +} |
| + |
| +var ErrUnauthenticated = errors.New("api.unauthenticated") |
| + |
| +func (h *Handler) Failure(w http.ResponseWriter, r *http.Request, err error) { |
| + code, status := "unavailable", 503 |
| + switch { |
| + case errors.Is(err, ErrUnauthenticated): |
| + code, status = "unauthenticated", 401 |
| + case errors.Is(err, h.Invalid), errors.Is(err, team.ErrInvalid): |
| + code, status = "invalid_input", 422 |
| + case errors.Is(err, h.Forbidden), errors.Is(err, team.ErrScope), errors.Is(err, team.ErrGrantRevoked): |
| + code, status = "forbidden", 403 |
| + case errors.Is(err, h.NotFound): |
| + code, status = "not_found", 404 |
| + case errors.Is(err, h.Conflict), errors.Is(err, team.ErrRevision), errors.Is(err, team.ErrConflict), errors.Is(err, team.ErrState): |
| + code, status = "revision_conflict", 409 |
| + case errors.Is(err, h.CursorExpired): |
| + code, status = "cursor_expired", 410 |
| + } |
| + WriteError(w, r, status, code, nil) |
| +} |
| + |
| +type principalKey struct{} |
| + |
| +func (h *Handler) currentRevision(ctx context.Context, a kernel.Actor, op, id string) *int64 { |
| + switch op { |
| + case "edit_plan", "approve_plan", "project": |
| + op = "plan" |
| + case "rendered", "merge", "cancel": |
| + op = "task" |
| + case "answer": |
| + op = "question" |
| + case "reset", "binding": |
| + op = "coordinator" |
| + case "settings": |
| + default: |
| + return nil |
| + } |
| + out, err := h.read(ctx, a, op, id, "", 50) |
| + if err != nil { |
| + return nil |
| + } |
| + return &out.Revision |
| +} |
diff --git a/internal/equipo/personapi/reads.go b/internal/equipo/personapi/reads.go| new file mode 100644 |
| index 00000000..f36ef232 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/reads.go |
| @@ -0,0 +1,176 @@ |
| +package personapi |
| + |
| +import ( |
| + "amadan.net/oficina/equipo/internal/equipo/conversation" |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "amadan.net/oficina/equipo/internal/equipo/planning" |
| + "context" |
| + "errors" |
| + "gorm.io/gorm" |
| +) |
| + |
| +type Team struct { |
| + ID, Name string |
| + RosterEpoch int64 |
| +} |
| +type member struct { |
| + Address, Role string |
| + Active bool |
| + Revision int64 |
| +} |
| +type Reader struct { |
| + Conversation *conversation.Application |
| + ReadTeam func(context.Context, kernel.Actor, func(*gorm.DB, Team) error) error |
| + TaskView func(context.Context, kernel.Actor, string) (planning.TaskViewData, error) |
| + Journey func(context.Context, kernel.Actor) ([]planning.TaskViewData, error) |
| + NotFound error |
| +} |
| + |
| +func (s *Reader) member(tx *gorm.DB, address string) (out member, err error) { |
| + err = tx.Table("members").Select("address,role,active,revision").Where("address=? AND active=?", address, true).Take(&out).Error |
| + return |
| +} |
| +func (s *Reader) Read(ctx context.Context, a kernel.Actor, op, id string) (Result, error) { |
| + switch op { |
| + case "me", "people": |
| + var out Result |
| + err := s.ReadTeam(ctx, a, func(tx *gorm.DB, t Team) error { |
| + if op == "me" { |
| + m, e := s.member(tx, a.Address) |
| + if e != nil { |
| + return e |
| + } |
| + out = Result{Value: Me{Person: apiPerson(m), TeamID: t.ID, TeamName: t.Name, Revision: m.Revision}, Revision: m.Revision} |
| + return nil |
| + } |
| + var members []member |
| + if e := tx.Table("members").Select("address,role,active,revision").Where("active=?", true).Order("address").Find(&members).Error; e != nil { |
| + return e |
| + } |
| + items := []Person{} |
| + for _, m := range members { |
| + items = append(items, apiPerson(m)) |
| + } |
| + out = Result{Value: items, Revision: t.RosterEpoch} |
| + return nil |
| + }) |
| + return out, err |
| + case "tasks", "journey", "needs_you", "task": |
| + var views []planning.TaskViewData |
| + if op == "task" { |
| + v, err := s.TaskView(ctx, a, id) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + return Result{Value: apiTask(v), Revision: v.Task.Revision}, nil |
| + } |
| + views, err := s.Journey(ctx, a) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + items := []Task{} |
| + for _, v := range views { |
| + if op != "needs_you" || v.NeedsYou { |
| + items = append(items, apiTask(v)) |
| + } |
| + } |
| + return Result{Value: items}, nil |
| + case "cards", "card": |
| + cards, err := s.Conversation.ConversationCards(ctx, a) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + out := []Card{} |
| + for _, c := range cards { |
| + if op == "card" && c.ID == id { |
| + return Result{Value: ProjectCard(c), Revision: c.Revision}, nil |
| + } |
| + out = append(out, ProjectCard(c)) |
| + } |
| + if op == "card" { |
| + return Result{}, s.NotFound |
| + } |
| + return Result{Value: out}, nil |
| + case "question": |
| + return s.question(ctx, a, id) |
| + case "coordinator": |
| + page, err := s.Conversation.CoordinatorPage(ctx, a) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + out := ProjectBinding(page.Binding) |
| + if !page.BudgetMissing { |
| + l := page.Limits |
| + out.Limits = &Limits{Calls: l.Calls, InputTokens: l.InputTokens, OutputTokens: l.OutputTokens, Seconds: l.Seconds} |
| + out.LimitsRevision = page.LimitsRevision |
| + } |
| + err = s.ReadTeam(ctx, a, func(tx *gorm.DB, _ Team) error { |
| + return tx.Table("coordinator_turns").Select("id,state,revision").Where("binding_id=? AND generation=?", page.Binding.ID, page.Binding.Generation).Order("sequence").Find(&out.Turns).Error |
| + }) |
| + return Result{Value: out, Revision: out.Revision}, err |
| + } |
| + return Result{}, s.NotFound |
| +} |
| +func apiPerson(m member) Person { |
| + return Person{Address: m.Address, DisplayIdentity: m.Address, Active: m.Active, Role: string(m.Role)} |
| +} |
| +func apiTask(v planning.TaskViewData) Task { |
| + out := ProjectTask(v.Task) |
| + out.CanCancel = v.CanCancel |
| + out.CanMerge = v.CanMerge |
| + out.NeedsYou = v.NeedsYou |
| + if v.UsageKnown { |
| + out.Usage = &Usage{Calls: v.CountedTurns, InputTokens: v.InputTokens, OutputTokens: v.OutputTokens} |
| + } |
| + for _, s := range v.Steps { |
| + step := Step{Key: s.Key, Category: s.Category, Action: s.Action, State: s.State, Model: s.Model, Account: s.Account, Actual: s.Actual, Reason: s.Reason} |
| + if s.UsageKnown { |
| + step.Usage = &Usage{Calls: s.CountedTurns, InputTokens: s.InputTokens, OutputTokens: s.OutputTokens} |
| + } |
| + if s.AllowanceKnown { |
| + n := s.AllowanceRemaining |
| + step.AllowanceRemaining = &n |
| + } |
| + out.Steps = append(out.Steps, step) |
| + } |
| + return out |
| +} |
| +func (s *Reader) question(ctx context.Context, a kernel.Actor, id string) (Result, error) { |
| + q, can, err := s.Conversation.Question(ctx, a, id) |
| + if err == nil { |
| + out := Question{ID: q.ID, Kind: "clarification", Text: q.Prompt, State: q.State, Revision: q.Revision, CanAnswer: can, AllowText: true, ExpiresAt: &q.ExpiresAt, Options: []Option{}, Fields: []Field{}} |
| + for _, o := range q.Options { |
| + out.Options = append(out.Options, Option{ID: o.ID, Label: o.Label}) |
| + } |
| + return Result{Value: out, Revision: q.Revision}, nil |
| + } |
| + if !errors.Is(err, s.NotFound) { |
| + return Result{}, err |
| + } |
| + var taskID string |
| + err = s.ReadTeam(ctx, a, func(tx *gorm.DB, t Team) error { |
| + var row struct{ TaskID string } |
| + if e := tx.Table("questions q").Select("q.task_id").Joins("JOIN tasks t ON t.id=q.task_id").Where("q.id=? AND t.team_id=?", id, t.ID).Take(&row).Error; e != nil { |
| + return e |
| + } |
| + taskID = row.TaskID |
| + return nil |
| + }) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + v, err := s.TaskView(ctx, a, taskID) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + for _, q := range v.Questions { |
| + if q.ID == id { |
| + out := Question{ID: q.ID, Kind: "native", TaskID: taskID, Text: q.Text, State: q.State, Revision: q.Revision, CanAnswer: q.CanAnswer, CanAllow: q.CanAllow, Options: []Option{}, Fields: []Field{}} |
| + for _, f := range q.Fields { |
| + out.Fields = append(out.Fields, Field{Key: f.Key, Prompt: f.Prompt}) |
| + } |
| + return Result{Value: out, Revision: q.Revision}, nil |
| + } |
| + } |
| + return Result{}, s.NotFound |
| +} |
diff --git a/internal/equipo/personapi/requests.go b/internal/equipo/personapi/requests.go| new file mode 100644 |
| index 00000000..09383007 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/requests.go |
| @@ -0,0 +1,172 @@ |
| +package personapi |
| + |
| +import ( |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "bytes" |
| + "context" |
| + "crypto/rand" |
| + "crypto/sha256" |
| + "encoding/binary" |
| + "encoding/json" |
| + "errors" |
| + "time" |
| + |
| + "gorm.io/gorm" |
| +) |
| + |
| +type Request struct { |
| + Principal string `gorm:"primaryKey"` |
| + Operation string `gorm:"primaryKey"` |
| + Resource string `gorm:"primaryKey"` |
| + RequestID string `gorm:"primaryKey"` |
| + InputHash string |
| + Result string |
| + CreatedAt time.Time |
| +} |
| + |
| +func (Request) TableName() string { return "person_api_requests" } |
| + |
| +type Cursor struct { |
| + ID string `gorm:"primaryKey"` |
| + Principal, Scope, Items string |
| + Revision int64 |
| + ExpiresAt time.Time |
| +} |
| + |
| +func (Cursor) TableName() string { return "person_api_cursors" } |
| + |
| +var Models = []any{&Request{}, &Cursor{}} |
| + |
| +type requestKey struct{} |
| + |
| +func WithRequest(ctx context.Context, r Request) context.Context { |
| + return context.WithValue(ctx, requestKey{}, r) |
| +} |
| +func RequestFrom(ctx context.Context) (Request, bool) { |
| + r, ok := ctx.Value(requestKey{}).(Request) |
| + return r, ok |
| +} |
| + |
| +// Record adds API metadata to the application's existing transaction. Application |
| +// replay records remain authoritative across browser and API requests. |
| +func Record(tx *gorm.DB, ctx context.Context, conflict error) error { |
| + r, ok := RequestFrom(ctx) |
| + if !ok { |
| + return nil |
| + } |
| + var old Request |
| + err := tx.Where("principal=? AND operation=? AND resource=? AND request_id=?", r.Principal, r.Operation, r.Resource, r.RequestID).Take(&old).Error |
| + if err == nil { |
| + if old.InputHash != r.InputHash { |
| + return conflict |
| + } |
| + return nil |
| + } |
| + if !errors.Is(err, gorm.ErrRecordNotFound) { |
| + return err |
| + } |
| + r.CreatedAt = time.Now().UTC() |
| + return tx.Create(&r).Error |
| +} |
| + |
| +// Replay is used after the legacy operation's current authority checks. |
| +func Replay(tx *gorm.DB, ctx context.Context, out any, conflict error) (bool, error) { |
| + r, ok := RequestFrom(ctx) |
| + if !ok { |
| + return false, nil |
| + } |
| + var old Request |
| + err := tx.Where("principal=? AND operation=? AND resource=? AND request_id=?", r.Principal, r.Operation, r.Resource, r.RequestID).Take(&old).Error |
| + if errors.Is(err, gorm.ErrRecordNotFound) { |
| + return false, nil |
| + } |
| + if err != nil { |
| + return false, err |
| + } |
| + if old.InputHash != r.InputHash { |
| + return false, conflict |
| + } |
| + if old.Result == "" { |
| + return false, nil |
| + } |
| + return true, json.Unmarshal([]byte(old.Result), out) |
| +} |
| +func SaveResult(tx *gorm.DB, ctx context.Context, out any, conflict error) error { |
| + if err := Record(tx, ctx, conflict); err != nil { |
| + return err |
| + } |
| + r, ok := RequestFrom(ctx) |
| + if !ok { |
| + return nil |
| + } |
| + b, err := json.Marshal(out) |
| + if err != nil { |
| + return err |
| + } |
| + return tx.Model(&Request{}).Where("principal=? AND operation=? AND resource=? AND request_id=?", r.Principal, r.Operation, r.Resource, r.RequestID).Select("result").Update("result", string(b)).Error |
| +} |
| +func Revision(v any) int64 { |
| + b, _ := json.Marshal(v) |
| + sum := sha256.Sum256(b) |
| + return int64(binary.BigEndian.Uint64(sum[:8])>>1) | 1 |
| +} |
| +func Paginate(tx *gorm.DB, principal, scope, cursor string, limit int, in Result, expired error) (Result, error) { |
| + var items []json.RawMessage |
| + revision := in.Revision |
| + if cursor != "" { |
| + var row Cursor |
| + err := tx.Where("id=? AND principal=? AND scope=?", cursor, principal, scope).Take(&row).Error |
| + if errors.Is(err, gorm.ErrRecordNotFound) || err == nil && !time.Now().Before(row.ExpiresAt) { |
| + return Result{}, expired |
| + } |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + if err = json.Unmarshal([]byte(row.Items), &items); err != nil { |
| + return Result{}, err |
| + } |
| + revision = row.Revision |
| + } else { |
| + b, err := json.Marshal(in.Value) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + if err = json.Unmarshal(b, &items); err != nil { |
| + return Result{}, err |
| + } |
| + if revision < 1 { |
| + revision = Revision(in.Value) |
| + } |
| + } |
| + if items == nil { |
| + items = []json.RawMessage{} |
| + } |
| + out := Page[json.RawMessage]{Items: items, Revision: revision} |
| + if len(items) > limit { |
| + b, err := json.Marshal(items[limit:]) |
| + if err != nil { |
| + return Result{}, err |
| + } |
| + row := Cursor{ID: rand.Text(), Principal: principal, Scope: scope, Items: string(b), Revision: revision, ExpiresAt: time.Now().UTC().Add(24 * time.Hour)} |
| + if err = tx.Create(&row).Error; err != nil { |
| + return Result{}, err |
| + } |
| + out.Items = items[:limit] |
| + out.NextCursor = row.ID |
| + } |
| + return Result{out, revision}, nil |
| +} |
| + |
| +func CanonicalHash(input any) (string, error) { |
| + raw, err := json.Marshal(input) |
| + if err != nil { |
| + return "", err |
| + } |
| + d := json.NewDecoder(bytes.NewReader(raw)) |
| + d.UseNumber() |
| + var value any |
| + if err = d.Decode(&value); err != nil { |
| + return "", err |
| + } |
| + return kernel.InputHash(value) |
| +} |
diff --git a/internal/equipo/personapi/types.go b/internal/equipo/personapi/types.go| new file mode 100644 |
| index 00000000..6125effc |
| --- /dev/null |
| +++ b/internal/equipo/personapi/types.go |
| @@ -0,0 +1,261 @@ |
| +package personapi |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/conversation" |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "amadan.net/oficina/equipo/internal/equipo/planning" |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| + "amadan.net/oficina/equipo/internal/taskplan" |
| +) |
| + |
| +type PersonPrincipal struct { |
| + Address, CredentialID string |
| + SessionEpoch int64 |
| +} |
| +type VerifyPersonBearer func(context.Context, string) (PersonPrincipal, error) |
| +type Page[T any] struct { |
| + Items []T `json:"items"` |
| + NextCursor string `json:"next_cursor"` |
| + Revision int64 `json:"revision"` |
| +} |
| +type Error struct { |
| + Code string `json:"code"` |
| + CopyKey string `json:"copy_key"` |
| + RequestID string `json:"request_id"` |
| + CurrentRevision *int64 `json:"current_revision,omitempty"` |
| +} |
| +type Result struct { |
| + Value any |
| + Revision int64 |
| +} |
| +type Person struct { |
| + Address string `json:"address"` |
| + DisplayIdentity string `json:"display_identity"` |
| + Active bool `json:"active"` |
| + Role string `json:"role"` |
| +} |
| +type Me struct { |
| + Person Person `json:"person"` |
| + TeamID string `json:"team_id"` |
| + TeamName string `json:"team_name"` |
| + Revision int64 `json:"revision"` |
| +} |
| +type Settings struct { |
| + Landing string `json:"landing"` |
| + Revision int64 `json:"revision"` |
| +} |
| +type Message struct { |
| + ID string `json:"id"` |
| + ConversationID string `json:"conversation_id"` |
| + ThreadID string `json:"thread_id"` |
| + AuthorKind string `json:"author_kind"` |
| + AuthorID string `json:"author_id"` |
| + Body string `json:"body"` |
| + Sequence int64 `json:"sequence"` |
| + Revision int64 `json:"revision"` |
| + CreatedAt time.Time `json:"created_at"` |
| + Sources []team.SourceRef `json:"sources"` |
| +} |
| +type Card struct { |
| + ID string `json:"id"` |
| + Kind string `json:"kind"` |
| + ResourceID string `json:"resource_id"` |
| + TaskID string `json:"task_id"` |
| + Revision int64 `json:"revision"` |
| + CopyKey string `json:"copy_key"` |
| + Actions []string `json:"actions"` |
| + WaitingTaskID string `json:"waiting_task_id"` |
| +} |
| +type ConversationPage struct { |
| + Messages []Message `json:"messages"` |
| + Cards []Card `json:"cards"` |
| + NextCursor string `json:"next_cursor"` |
| + Revision int64 `json:"revision"` |
| +} |
| +type Preference struct { |
| + ID string `json:"id"` |
| + Text string `json:"text"` |
| + Status string `json:"status"` |
| + SourceMessageID string `json:"source_message_id"` |
| + Revision int64 `json:"revision"` |
| +} |
| +type Task struct { |
| + ID string `json:"id"` |
| + ProjectID int64 `json:"project_id"` |
| + Requester string `json:"requester"` |
| + Description string `json:"description"` |
| + Kind taskplan.Kind `json:"kind"` |
| + State string `json:"state"` |
| + Revision int64 `json:"revision"` |
| + PlanRevision int64 `json:"plan_revision"` |
| + ReplacementID string `json:"replacement_id"` |
| + CanCancel bool `json:"can_cancel"` |
| + CanMerge bool `json:"can_merge"` |
| + NeedsYou bool `json:"needs_you"` |
| + Steps []Step `json:"steps"` |
| + Usage *Usage `json:"usage"` |
| +} |
| +type Usage struct { |
| + Calls int64 `json:"calls"` |
| + InputTokens int64 `json:"input_tokens"` |
| + OutputTokens int64 `json:"output_tokens"` |
| +} |
| +type Step struct { |
| + Key string `json:"key"` |
| + Category string `json:"category"` |
| + Action string `json:"action"` |
| + State string `json:"state"` |
| + Model string `json:"model"` |
| + Account string `json:"account"` |
| + Actual string `json:"actual"` |
| + Reason string `json:"reason"` |
| + Usage *Usage `json:"usage"` |
| + AllowanceRemaining *int64 `json:"allowance_remaining"` |
| +} |
| +type Coordinator struct { |
| + ID string `json:"id"` |
| + RunnerID string `json:"runner_id"` |
| + ConnectionID string `json:"connection_id"` |
| + Generation int64 `json:"generation"` |
| + Revision int64 `json:"revision"` |
| + WaitingTaskID string `json:"waiting_task_id"` |
| + Turns []Turn `json:"turns"` |
| + Limits *Limits `json:"limits"` |
| + LimitsRevision int64 `json:"limits_revision"` |
| +} |
| +type Turn struct { |
| + ID string `json:"id"` |
| + State string `json:"state"` |
| + Revision int64 `json:"revision"` |
| +} |
| +type Question struct { |
| + ID string `json:"id"` |
| + Kind string `json:"kind"` |
| + TaskID string `json:"task_id"` |
| + Text string `json:"text"` |
| + State string `json:"state"` |
| + Revision int64 `json:"revision"` |
| + CanAnswer bool `json:"can_answer"` |
| + CanAllow bool `json:"can_allow"` |
| + Options []Option `json:"options"` |
| + Fields []Field `json:"fields"` |
| + AllowText bool `json:"allow_text"` |
| + ExpiresAt *time.Time `json:"expires_at"` |
| +} |
| +type Option struct { |
| + ID string `json:"id"` |
| + Label string `json:"label"` |
| +} |
| +type Field struct { |
| + Key string `json:"key"` |
| + Prompt string `json:"prompt"` |
| +} |
| +type Ack struct { |
| + Revision int64 `json:"revision"` |
| +} |
| + |
| +type MessageInput struct { |
| + Body string `json:"body"` |
| +} |
| +type SettingsInput struct { |
| + Landing string `json:"landing"` |
| +} |
| +type RouteInput struct { |
| + TaskID string `json:"task_id"` |
| +} |
| +type ProjectInput struct { |
| + ProjectID int64 `json:"project_id"` |
| +} |
| +type PreferenceInput struct { |
| + Text string `json:"text"` |
| + SourceMessageID string `json:"source_message_id,omitempty"` |
| +} |
| +type BindingInput struct { |
| + RunnerID string `json:"runner_id"` |
| + ConnectionID string `json:"connection_id"` |
| +} |
| +type RetryInput struct { |
| + TurnID string `json:"turn_id"` |
| +} |
| +type Limits struct { |
| + Calls int64 `json:"calls"` |
| + InputTokens int64 `json:"input_tokens"` |
| + OutputTokens int64 `json:"output_tokens"` |
| + Seconds int64 `json:"seconds"` |
| +} |
| +type LimitsInput struct { |
| + Person string `json:"person"` |
| + Limits Limits `json:"limits"` |
| +} |
| +type RenderedInput struct { |
| + CandidateHash string `json:"candidate_hash"` |
| + DiffHash string `json:"diff_hash"` |
| + RenderHash string `json:"render_hash"` |
| + Decision string `json:"decision"` |
| +} |
| +type MergeInput struct { |
| + Reference string `json:"reference"` |
| +} |
| +type AnswerInput struct { |
| + Kind string `json:"kind"` |
| + OptionID string `json:"option_id,omitempty"` |
| + Text string `json:"text,omitempty"` |
| + Behavior string `json:"behavior,omitempty"` |
| + UpdatedInput json.RawMessage `json:"updated_input,omitempty"` |
| +} |
| +type PlanInput struct { |
| + Kind taskplan.Kind `json:"kind"` |
| + ProjectID int64 `json:"project_id"` |
| + Steps []PlanStep `json:"steps"` |
| + PlaybookID string `json:"playbook_id"` |
| + PlaybookRevision int64 `json:"playbook_revision"` |
| +} |
| +type PlanStep struct { |
| + DependsOn []string `json:"depends_on,omitempty"` |
| + Key string `json:"key"` |
| + Specialist string `json:"specialist"` |
| + Action string `json:"action"` |
| + Instructions string `json:"instructions"` |
| + ConnectionID string `json:"connection_id"` |
| + Model string `json:"model"` |
| + SelectionReason string `json:"selection_reason"` |
| +} |
| +type Plan struct { |
| + PlanInput |
| + TaskID string `json:"task_id"` |
| + Revision int64 `json:"revision"` |
| + RequiredSteps []string `json:"required_steps"` |
| +} |
| + |
| +type Application interface { |
| + Conversation(context.Context, kernel.Actor, string, int) (conversation.ConversationPage, error) |
| + SendMessage(context.Context, kernel.Actor, string, string, kernel.Mutation) (conversation.Message, error) |
| + TaskThread(context.Context, kernel.Actor, string, string, int) (conversation.ConversationPage, error) |
| + RouteMessage(context.Context, kernel.Actor, string, string, kernel.Mutation) (conversation.Message, error) |
| + PersonalSettings(context.Context, kernel.Actor) (conversation.PersonalSettings, error) |
| + SavePersonalSettings(context.Context, kernel.Actor, conversation.PersonalSettings, kernel.Mutation) (conversation.PersonalSettings, error) |
| + Preferences(context.Context, kernel.Actor) ([]conversation.Preference, error) |
| + SetPreference(context.Context, kernel.Actor, conversation.Preference, kernel.Mutation) (conversation.Preference, error) |
| + DeletePreference(context.Context, kernel.Actor, string, kernel.Mutation) error |
| + TaskPlan(context.Context, kernel.Actor, string) (taskplan.Plan, error) |
| + ProposePlan(context.Context, kernel.Actor, taskplan.Plan, kernel.Mutation) (taskplan.Plan, error) |
| + EditPlan(context.Context, kernel.Actor, taskplan.Plan, kernel.Mutation) (taskplan.Plan, error) |
| + ApprovePlan(context.Context, kernel.Actor, string, kernel.Mutation) (planning.Task, error) |
| + CorrectTaskProject(context.Context, kernel.Actor, string, int64, kernel.Mutation) (planning.Task, error) |
| + SaveCoordinatorBinding(context.Context, kernel.Actor, string, string, kernel.Mutation) (runnerproto.CoordinatorBinding, error) |
| + ResetCoordinator(context.Context, kernel.Actor, kernel.Mutation) (runnerproto.CoordinatorBinding, error) |
| + RetryCoordinatorTurn(context.Context, kernel.Actor, string, kernel.Mutation) (runnerproto.CoordinatorTurn, error) |
| + SetCoordinatorLimits(context.Context, kernel.Actor, string, team.Limits, kernel.Mutation) error |
| + AnswerClarification(context.Context, kernel.Actor, string, string, string, kernel.Mutation) error |
| + AnswerQuestion(context.Context, kernel.Actor, string, int64, runnerproto.QuestionAnswer) error |
| + ApproveRenderedChange(context.Context, kernel.Actor, string, string, string, string, string, kernel.Mutation) error |
| + AcknowledgeMerge(context.Context, kernel.Actor, string, int64, string) error |
| + PersonAPIRead(context.Context, kernel.Actor, string, string) (Result, error) |
| + PersonAPICancel(context.Context, kernel.Actor, string, kernel.Mutation) (Ack, error) |
| + PersonAPIPage(context.Context, kernel.Actor, string, string, int, Result) (Result, error) |
| +} |
diff --git a/internal/equipo/personapi/validate.go b/internal/equipo/personapi/validate.go| new file mode 100644 |
| index 00000000..c1799484 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/validate.go |
| @@ -0,0 +1,175 @@ |
| +package personapi |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| + "errors" |
| + "io" |
| + "net/http" |
| + "reflect" |
| + "strconv" |
| + "strings" |
| + "unicode/utf8" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| +) |
| + |
| +var errInput = errors.New("api.invalid_input") |
| + |
| +func Decode(r io.Reader, dst any) error { |
| + b, err := io.ReadAll(io.LimitReader(r, 65537)) |
| + if err != nil || len(b) > 65536 || !utf8.Valid(b) { |
| + return errInput |
| + } |
| + d := json.NewDecoder(bytes.NewReader(b)) |
| + d.UseNumber() |
| + if err = object(d, reflect.TypeOf(dst).Elem()); err != nil { |
| + return errInput |
| + } |
| + if _, err = d.Token(); err != io.EOF { |
| + return errInput |
| + } |
| + if _, ok := dst.(*AnswerInput); ok { |
| + var fields map[string]json.RawMessage |
| + if json.Unmarshal(b, &fields) != nil { |
| + return errInput |
| + } |
| + var kind string |
| + if json.Unmarshal(fields["kind"], &kind) != nil { |
| + return errInput |
| + } |
| + for k := range fields { |
| + if k == "kind" { |
| + continue |
| + } |
| + if kind == "clarification" && (k == "option_id" || k == "text") { |
| + continue |
| + } |
| + if kind == "native" && (k == "behavior" || k == "updated_input") { |
| + continue |
| + } |
| + return errInput |
| + } |
| + } |
| + d = json.NewDecoder(bytes.NewReader(b)) |
| + d.DisallowUnknownFields() |
| + if d.Decode(dst) != nil { |
| + return errInput |
| + } |
| + return nil |
| +} |
| +func object(d *json.Decoder, t reflect.Type) error { |
| + tok, err := d.Token() |
| + if err != nil { |
| + return err |
| + } |
| + if tok != json.Delim('{') { |
| + return errInput |
| + } |
| + seen := map[string]bool{} |
| + fields := map[string]reflect.Type{} |
| + if t != nil && t.Kind() == reflect.Struct { |
| + for i := 0; i < t.NumField(); i++ { |
| + f := t.Field(i) |
| + name := strings.Split(f.Tag.Get("json"), ",")[0] |
| + if name == "" { |
| + name = f.Name |
| + } |
| + fields[name] = f.Type |
| + } |
| + } |
| + for d.More() { |
| + key, err := d.Token() |
| + if err != nil { |
| + return err |
| + } |
| + k, ok := key.(string) |
| + if !ok || seen[k] { |
| + return errInput |
| + } |
| + seen[k] = true |
| + ft, exists := fields[k] |
| + if t != nil && t.Kind() == reflect.Struct && !exists { |
| + return errInput |
| + } |
| + if err = value(d, ft); err != nil { |
| + return err |
| + } |
| + } |
| + _, err = d.Token() |
| + return err |
| +} |
| +func value(d *json.Decoder, t reflect.Type) error { |
| + var raw json.RawMessage |
| + if err := d.Decode(&raw); err != nil { |
| + return err |
| + } |
| + if bytes.Equal(raw, []byte("null")) { |
| + return errInput |
| + } |
| + if len(raw) > 0 && raw[0] == '{' { |
| + return object(json.NewDecoder(bytes.NewReader(raw)), t) |
| + } |
| + if len(raw) > 0 && raw[0] == '[' { |
| + var items []json.RawMessage |
| + if json.Unmarshal(raw, &items) != nil { |
| + return errInput |
| + } |
| + var elem reflect.Type |
| + if t != nil && t.Kind() == reflect.Slice { |
| + elem = t.Elem() |
| + } |
| + for _, r := range items { |
| + if err := value(json.NewDecoder(bytes.NewReader(r)), elem); err != nil { |
| + return err |
| + } |
| + } |
| + } |
| + return nil |
| +} |
| +func Mutation(r *http.Request, required bool) (kernel.Mutation, int) { |
| + m := kernel.Mutation{RequestID: r.Header.Get("Idempotency-Key")} |
| + if len(r.Header.Values("Idempotency-Key")) != 1 || !m.Valid() { |
| + if m.RequestID == "" { |
| + return m, 428 |
| + } |
| + return m, 422 |
| + } |
| + values := r.Header.Values("If-Match") |
| + if len(values) == 0 { |
| + if required { |
| + return m, 428 |
| + } |
| + return m, 0 |
| + } |
| + if len(values) != 1 { |
| + return m, 422 |
| + } |
| + raw := values[0] |
| + if len(raw) < 3 || raw[0] != '"' || raw[len(raw)-1] != '"' { |
| + return m, 422 |
| + } |
| + n, err := strconv.ParseInt(raw[1:len(raw)-1], 10, 64) |
| + if err != nil || n < 0 || strconv.FormatInt(n, 10) != raw[1:len(raw)-1] { |
| + return m, 422 |
| + } |
| + m.Revision = n |
| + return m, 0 |
| +} |
| +func ListQuery(r *http.Request) (string, int, error) { |
| + q := r.URL.Query() |
| + for k, v := range q { |
| + if (k != "limit" && k != "cursor") || len(v) != 1 { |
| + return "", 0, errInput |
| + } |
| + } |
| + limit := 50 |
| + if raw, ok := q["limit"]; ok { |
| + n, err := strconv.Atoi(raw[0]) |
| + if err != nil || n < 1 || n > 100 { |
| + return "", 0, errInput |
| + } |
| + limit = n |
| + } |
| + return q.Get("cursor"), limit, nil |
| +} |
diff --git a/internal/equipo/personapi/validate_test.go b/internal/equipo/personapi/validate_test.go| new file mode 100644 |
| index 00000000..060cb959 |
| --- /dev/null |
| +++ b/internal/equipo/personapi/validate_test.go |
| @@ -0,0 +1,19 @@ |
| +package personapi |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestPersonAPIValidate(t *testing.T) { |
| + for _, raw := range []string{`{"body":"a","body":"b"}`, `{"body":"a","actor":"owner"}`, `{"body":"a"} {}`, `null`, `{"body":"a","BODY":"b"}`, `{"body":"` + strings.Repeat("x", 65536) + `"}`} { |
| + var in MessageInput |
| + if Decode(strings.NewReader(raw), &in) == nil { |
| + t.Fatalf("accepted invalid input %q", raw[:min(len(raw), 80)]) |
| + } |
| + } |
| + var in MessageInput |
| + if err := Decode(strings.NewReader(`{"body":"hello"}`), &in); err != nil || in.Body != "hello" { |
| + t.Fatal(in, err) |
| + } |
| +} |
diff --git a/internal/equipo/planning/task_views.go b/internal/equipo/planning/task_views.go| new file mode 100644 |
| index 00000000..394ad1f9 |
| --- /dev/null |
| +++ b/internal/equipo/planning/task_views.go |
| @@ -0,0 +1,54 @@ |
| +package planning |
| + |
| +import ( |
| + "amadan.net/oficina/equipo/internal/equipo/kernel" |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| + "time" |
| +) |
| + |
| +type StepCard struct { |
| + FinishedAt time.Time |
| + Key, Category, State, Model, Account, Actual, Person, Action, Reason string |
| + Isolation team.IsolationSnapshot |
| + Unconfined bool |
| + UsageKnown bool |
| + AllowanceKnown bool |
| + AllowanceRemaining int64 |
| + CountedTurns, InputTokens, OutputTokens int64 |
| +} |
| +type QuestionField = runnerproto.QuestionField |
| + |
| +type TaskQuestion struct { |
| + Fields []QuestionField |
| + ID, Text, State string |
| + Revision int64 |
| + CanAnswer bool |
| + CanAllow bool |
| +} |
| +type TaskEvidence struct { |
| + Actual string |
| + Role, Hash, Detail string |
| + Isolation team.IsolationSnapshot |
| + Unconfined bool |
| +} |
| +type TaskViewData struct { |
| + CanStopOldRunner bool |
| + Isolation team.IsolationSnapshot |
| + Task Task |
| + Project kernel.Project |
| + Steps []StepCard |
| + Questions []TaskQuestion |
| + Evidence []TaskEvidence |
| + Logs []TaskEvidence |
| + StateKey, Group, Topic, MergeReference string |
| + Unconfined, NeedsYou, CanCancel, CanMerge, UsageKnown bool |
| + CountedTurns, InputTokens, OutputTokens int64 |
| + FinishedAt time.Time |
| +} |
| +type SpecialistWorkView struct { |
| + Tasks []TaskViewData |
| + Working, Queued, Finished, Waiting int |
| + CountsKnown, UsageKnown bool |
| + InputTokens, OutputTokens, CountedTurns int64 |
| +} |
diff --git a/internal/equipo/questions.go b/internal/equipo/questions.go| index 5414cc6e..cffbfe98 100644 |
| --- a/internal/equipo/questions.go |
| +++ b/internal/equipo/questions.go |
| @@ -140,7 +140,8 @@ func (s *Store) answerQuestion(ctx context.Context, actor Actor, taskID, id stri |
| if s.execution == nil { |
| return ErrUnavailable |
| } |
| - return s.execution.atomic(ctx, func(ctx context.Context, tx *gorm.DB) error { |
| + return s.write(ctx, func(tx *gorm.DB) error { |
| + ctx := tx.Statement.Context |
| member, err := memberAt(tx, actor.Address) |
| if err != nil { |
| return err |
diff --git a/internal/equipo/runner_api.go b/internal/equipo/runner_api.go| index b50cf2fe..9496ecf0 100644 |
| --- a/internal/equipo/runner_api.go |
| +++ b/internal/equipo/runner_api.go |
| @@ -16,14 +16,3 @@ func (s *Store) runnerProtocol() *runnerproto.Handler { |
| } |
| func (s *Store) RunnerHandler() http.Handler { return s.runnerRouter() } |
| func (s *Store) runnerRouter() chi.Router { return s.runnerProtocol().Router() } |
| -func runnerCSRFExemptPaths(r chi.Routes) []string { |
| - var paths []string |
| - // Use the registered bearer routes so additions inherit the exemption. |
| - _ = chi.Walk(r, func(method, route string, _ http.Handler, _ ...func(http.Handler) http.Handler) error { |
| - if method != http.MethodGet && method != http.MethodHead && method != http.MethodOptions { |
| - paths = append(paths, "/api/runner/v2"+route) |
| - } |
| - return nil |
| - }) |
| - return paths |
| -} |
diff --git a/internal/equipo/store.go b/internal/equipo/store.go| index 4bffe678..00796412 100644 |
| --- a/internal/equipo/store.go |
| +++ b/internal/equipo/store.go |
| @@ -10,8 +10,10 @@ import ( |
| "gorm.io/gorm" |
| "gorm.io/plugin/dbresolver" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| "amadan.net/oficina/equipo/internal/equipo/team" |
| "amadan.net/rastrillo/rastrillo/db" |
| + "net/http" |
| ) |
| var ( |
| @@ -44,6 +46,9 @@ func (e *refusal) Unwrap() error { return e.kind } |
| // Store grants no access by itself. Mutators must check the trusted Actor |
| // against the current roster and append an AuditEvent in their transaction. |
| type Store struct { |
| + personBearer personapi.VerifyPersonBearer |
| + personCookie func(*http.Request) (personapi.PersonPrincipal, error) |
| + personOrigin string |
| notifier JobNotifier |
| db *db.DB |
| execution *Execution |
| @@ -62,7 +67,7 @@ func WithRunnerClock(clock team.Clock) StoreOption { |
| } |
| func NewStore(d *db.DB, options ...StoreOption) *Store { |
| - s := &Store{db: d, runnerClock: team.RealClock{}} |
| + s := &Store{db: d, runnerClock: team.RealClock{}, personBearer: personapi.DenyPersonBearer} |
| for _, option := range options { |
| option(s) |
| } |
| @@ -83,6 +88,22 @@ func (s *Store) write(ctx context.Context, fn func(*gorm.DB) error) error { |
| if s == nil || s.db == nil { |
| return ErrUnavailable |
| } |
| + original := fn |
| + fn = func(tx *gorm.DB) error { |
| + if p, ok := personapi.PrincipalFrom(ctx); ok { |
| + member, err := currentRunnerMember(tx, p.Address) |
| + if err != nil { |
| + return err |
| + } |
| + if p.SessionEpoch < member.SessionEpoch { |
| + return ErrForbidden |
| + } |
| + } |
| + if err := original(tx); err != nil { |
| + return err |
| + } |
| + return personapi.Record(tx, ctx, ErrConflict) |
| + } |
| var err error |
| if s.execution != nil { |
| err = s.execution.Write(ctx, fn) |
diff --git a/internal/equipo/task_merge.go b/internal/equipo/task_merge.go| index 597f306b..94b5810f 100644 |
| --- a/internal/equipo/task_merge.go |
| +++ b/internal/equipo/task_merge.go |
| @@ -1,6 +1,7 @@ |
| package equipo |
| import ( |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| "context" |
| "net/url" |
| "strings" |
| @@ -29,9 +30,6 @@ func (s *Store) AcknowledgeMerge(ctx context.Context, actor Actor, id string, re |
| if task.MergeOwner != member.Address { |
| return ErrForbidden |
| } |
| - if task.Revision != revision || task.State == "merged" { |
| - return ErrConflict |
| - } |
| var owner DecisionOwner |
| if err = tx.Where("project_id=? AND decision='merge'", task.ProjectID).First(&owner).Error; err != nil { |
| return storeError(err) |
| @@ -39,6 +37,13 @@ func (s *Store) AcknowledgeMerge(ctx context.Context, actor Actor, id string, re |
| if owner.Address != task.MergeOwner { |
| return ErrConflict |
| } |
| + var done bool |
| + if ok, e := personapi.Replay(tx, ctx, &done, ErrConflict); ok || e != nil { |
| + return e |
| + } |
| + if task.Revision != revision || task.State == "merged" { |
| + return ErrConflict |
| + } |
| var job executionJobs |
| if err = tx.Where("id=? AND account=?", task.JobID, instance.ID).First(&job).Error; err != nil { |
| return storeError(err) |
| @@ -52,6 +57,9 @@ func (s *Store) AcknowledgeMerge(ctx context.Context, actor Actor, id string, re |
| if err = tx.Model(&Task{}).Where("id=? AND revision=?", id, revision).Select("State", "Revision").Updates(&Task{State: "merged", Revision: revision + 1}).Error; err != nil { |
| return storeError(err) |
| } |
| - return appendAudit(tx, actor, "task.merge", id) |
| + if err = appendAudit(tx, actor, "task.merge", id); err != nil { |
| + return err |
| + } |
| + return personapi.SaveResult(tx, ctx, true, ErrConflict) |
| }) |
| } |
diff --git a/internal/equipo/task_views.go b/internal/equipo/task_views.go| index 15672e6d..93a9a57e 100644 |
| --- a/internal/equipo/task_views.go |
| +++ b/internal/equipo/task_views.go |
| @@ -1,7 +1,6 @@ |
| package equipo |
| import ( |
| - "bytes" |
| "context" |
| "database/sql" |
| "encoding/json" |
| @@ -9,6 +8,7 @@ import ( |
| "strings" |
| "time" |
| + "amadan.net/oficina/equipo/internal/equipo/planning" |
| "amadan.net/oficina/equipo/internal/equipo/team" |
| "amadan.net/oficina/equipo/internal/runnerproto" |
| "amadan.net/oficina/equipo/internal/taskplan" |
| @@ -16,51 +16,12 @@ import ( |
| "gorm.io/plugin/dbresolver" |
| ) |
| -type StepCard struct { |
| - FinishedAt time.Time |
| - Key, Category, State, Model, Account, Actual, Person, Action, Reason string |
| - Isolation team.IsolationSnapshot |
| - Unconfined bool |
| - UsageKnown bool |
| - AllowanceKnown bool |
| - AllowanceRemaining int64 |
| - CountedTurns, InputTokens, OutputTokens int64 |
| -} |
| -type QuestionField struct{ Key, Prompt string } |
| - |
| -type TaskQuestion struct { |
| - Fields []QuestionField |
| - ID, Text, State string |
| - Revision int64 |
| - CanAnswer bool |
| - CanAllow bool |
| -} |
| -type TaskEvidence struct { |
| - Actual string |
| - Role, Hash, Detail string |
| - Isolation team.IsolationSnapshot |
| - Unconfined bool |
| -} |
| -type TaskViewData struct { |
| - CanStopOldRunner bool |
| - Isolation team.IsolationSnapshot |
| - Task Task |
| - Project Project |
| - Steps []StepCard |
| - Questions []TaskQuestion |
| - Evidence []TaskEvidence |
| - Logs []TaskEvidence |
| - StateKey, Group, Topic, MergeReference string |
| - Unconfined, NeedsYou, CanCancel, CanMerge, UsageKnown bool |
| - CountedTurns, InputTokens, OutputTokens int64 |
| - FinishedAt time.Time |
| -} |
| -type SpecialistWorkView struct { |
| - Tasks []TaskViewData |
| - Working, Queued, Finished, Waiting int |
| - CountsKnown, UsageKnown bool |
| - InputTokens, OutputTokens, CountedTurns int64 |
| -} |
| +type StepCard = planning.StepCard |
| +type QuestionField = planning.QuestionField |
| +type TaskQuestion = planning.TaskQuestion |
| +type TaskEvidence = planning.TaskEvidence |
| +type TaskViewData = planning.TaskViewData |
| +type SpecialistWorkView = planning.SpecialistWorkView |
| func (s *Store) readTeam(ctx context.Context, actor Actor, fn func(*gorm.DB, Team) error) error { |
| return storeErrorRead(s.db.G.WithContext(ctx).Clauses(dbresolver.Read).Transaction(func(tx *gorm.DB) error { |
| @@ -501,47 +462,5 @@ func waitCopyKey(wait string) string { |
| } |
| } |
| -func displayJSON(raw string) string { |
| - var value any |
| - if json.Unmarshal([]byte(raw), &value) != nil { |
| - return raw |
| - } |
| - var buf bytes.Buffer |
| - enc := json.NewEncoder(&buf) |
| - enc.SetEscapeHTML(false) |
| - enc.SetIndent("", " ") |
| - if enc.Encode(value) != nil { |
| - return raw |
| - } |
| - return buf.String() |
| -} |
| - |
| -func questionFields(kind, raw string) []QuestionField { |
| - var q struct { |
| - Provider, Name, Question string |
| - Input struct { |
| - Questions []struct{ Question, Header string } |
| - } |
| - } |
| - if json.Unmarshal([]byte(raw), &q) != nil { |
| - return nil |
| - } |
| - if kind == "person" && q.Question != "" { |
| - return []QuestionField{{Key: "answer", Prompt: q.Question}} |
| - } |
| - if (q.Provider != "claude" || q.Name != "AskUserQuestion") && (q.Provider != "codex" || q.Name != "request_user_input") { |
| - return nil |
| - } |
| - var fields []QuestionField |
| - for _, f := range q.Input.Questions { |
| - key := f.Question |
| - if q.Provider == "codex" { |
| - key = f.Header |
| - } |
| - if key == "" { |
| - return nil |
| - } |
| - fields = append(fields, QuestionField{Key: key, Prompt: f.Question}) |
| - } |
| - return fields |
| -} |
| +func displayJSON(raw string) string { return runnerproto.DisplayJSON(raw) } |
| +func questionFields(kind, raw string) []QuestionField { return runnerproto.QuestionFields(kind, raw) } |
diff --git a/internal/plan3test/person_api_contract_test.go b/internal/plan3test/person_api_contract_test.go| new file mode 100644 |
| index 00000000..04c8b71c |
| --- /dev/null |
| +++ b/internal/plan3test/person_api_contract_test.go |
| @@ -0,0 +1,112 @@ |
| +package plan3test |
| + |
| +import ( |
| + "encoding/json" |
| + "net/http" |
| + "os" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +func TestPersonAPIOpenAPIContract(t *testing.T) { |
| + raw, err := os.ReadFile("../../docs/api/equipo-v1.openapi.json") |
| + must(t, err) |
| + var doc struct { |
| + OpenAPI string `json:"openapi"` |
| + Info struct { |
| + Version string `json:"version"` |
| + } `json:"info"` |
| + Paths map[string]map[string]json.RawMessage `json:"paths"` |
| + } |
| + must(t, json.Unmarshal(raw, &doc)) |
| + if doc.OpenAPI != "3.1.0" || doc.Info.Version != "1.0.0" { |
| + t.Fatal("wrong API version") |
| + } |
| + required := map[string]string{ |
| + "/me": "GET", "/capabilities": "GET", "/me/settings": "GET PATCH", "/people": "GET", |
| + "/conversation": "GET", "/conversation/messages": "POST", "/conversation/cards": "GET", "/cards/{id}": "GET", |
| + "/tasks": "GET POST", "/tasks/{id}": "GET", "/tasks/{id}/cancel": "POST", "/tasks/{id}/thread": "GET", "/tasks/{id}/thread/messages": "POST", "/conversation/messages/{id}/route": "POST", |
| + "/tasks/{id}/plan": "GET PATCH", "/tasks/{id}/plan/approve": "POST", "/tasks/{id}/project": "POST", |
| + "/questions/{id}": "GET", "/questions/{id}/answer": "POST", "/tasks/{id}/rendered-approval": "POST", "/tasks/{id}/acknowledge-merge": "POST", |
| + "/journey": "GET", "/needs-you": "GET", "/preferences": "GET POST", "/preferences/{id}": "PATCH DELETE", |
| + "/coordinator": "GET PATCH", "/coordinator/reset": "POST", "/coordinator/retry": "POST", "/coordinator/limits": "PATCH", |
| + } |
| + f := newFixture(t) |
| + registered := map[string]bool{} |
| + must(t, chi.Walk(f.Store.PersonAPIHandler().(chi.Routes), func(method, path string, _ http.Handler, _ ...func(http.Handler) http.Handler) error { |
| + registered[method+" "+path] = true |
| + return nil |
| + })) |
| + count := 0 |
| + for path, methods := range required { |
| + for _, method := range strings.Fields(methods) { |
| + count++ |
| + if !registered[method+" "+path] { |
| + t.Fatal("missing 3a route", method, path) |
| + } |
| + operation, ok := doc.Paths[path][strings.ToLower(method)] |
| + if !ok { |
| + t.Fatal("missing OpenAPI operation", method, path) |
| + } |
| + var value struct { |
| + Parameters []struct { |
| + Name string |
| + Required bool |
| + } |
| + Responses map[string]struct { |
| + Content map[string]struct{ Schema json.RawMessage } |
| + } |
| + RequestBody struct { |
| + Required bool |
| + Content map[string]struct{ Schema json.RawMessage } |
| + } |
| + } |
| + must(t, json.Unmarshal(operation, &value)) |
| + if len(value.Responses["200"].Content["application/json"].Schema) == 0 { |
| + t.Fatal("untyped response", method, path) |
| + } |
| + if method != "GET" { |
| + if !value.RequestBody.Required || len(value.RequestBody.Content["application/json"].Schema) == 0 { |
| + t.Fatal("untyped mutation", method, path) |
| + } |
| + key := false |
| + for _, p := range value.Parameters { |
| + if p.Name == "Idempotency-Key" && p.Required { |
| + key = true |
| + } |
| + } |
| + if !key { |
| + t.Fatal("missing request key contract", method, path) |
| + } |
| + } |
| + } |
| + } |
| + if count != len(registered) { |
| + t.Fatal("unexpected API route", count, len(registered)) |
| + } |
| + actual := 0 |
| + for _, methods := range doc.Paths { |
| + actual += len(methods) |
| + } |
| + if count != actual { |
| + t.Fatal("OpenAPI differs from 3a routes", count, actual) |
| + } |
| + p := proposed(t, f) |
| + w := apiRequest(t, f, owner, "GET", "/api/v1/conversation/cards", "", "", "") |
| + expectHTTP(t, w, 200) |
| + cards := apiValue[personapi.Page[personapi.Card]](t, w) |
| + found := false |
| + for _, c := range cards.Items { |
| + if c.ResourceID == p.TaskID { |
| + found = true |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/cards/"+c.ID, "", "", ""), 200) |
| + expectHTTP(t, apiRequest(t, f, peer, "GET", "/api/v1/cards/"+c.ID, "", "", ""), 404) |
| + } |
| + } |
| + if !found { |
| + t.Fatal("missing current task card") |
| + } |
| +} |
diff --git a/internal/plan3test/person_api_evidence_test.go b/internal/plan3test/person_api_evidence_test.go| new file mode 100644 |
| index 00000000..08342fa7 |
| --- /dev/null |
| +++ b/internal/plan3test/person_api_evidence_test.go |
| @@ -0,0 +1,75 @@ |
| +package plan3test |
| + |
| +import ( |
| + "amadan.net/oficina/equipo/internal/equipo" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "amadan.net/oficina/equipo/internal/taskplan" |
| + "bytes" |
| + "encoding/json" |
| + "fmt" |
| + "image" |
| + "image/png" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestPersonAPIRenderedAndMerge(t *testing.T) { |
| + f := newFixture(t) |
| + decider := owner |
| + |
| + p := proposed(t, f) |
| + x, task, scope := f.planCore(t, p) |
| + |
| + must(t, f.DB.G.Create(&equipo.DecisionOwner{ProjectID: p.ProjectID, Decision: "copy", Address: decider.Address}).Error) |
| + job, err := x.Core.GetJob(ctx, scope) |
| + must(t, err) |
| + job.Evidence.Predicate = team.PredicateRenderedChange |
| + job.Evidence.RequireBugFreeze = false |
| + job.Evidence.RequiredDecisions = []string{"copy"} |
| + encode := func(v any) []byte { b, e := json.Marshal(v); must(t, e); return b } |
| + f.exec(t, "UPDATE jobs SET evidence=? WHERE id=?", string(encode(job.Evidence)), job.ID) |
| + f.exec(t, "UPDATE tasks SET kind=? WHERE id=?", taskplan.RenderedChange, task.ID) |
| + h, err := x.Core.Claim(ctx, scope, "reproduce", "runner", "workspace") |
| + must(t, err) |
| + f.exec(t, "UPDATE attempts SET state='succeeded',containment='contained' WHERE id=?", h.Attempt) |
| + cand := team.GitCandidate{Repository: job.Target.Repository, BaseCommit: job.Target.BaseRevision, Commit: strings.Repeat("d", 40), Tree: strings.Repeat("e", 40)} |
| + raw, hash, err := team.CanonicalJSON(encode(cand)) |
| + must(t, err) |
| + diff := encode([]taskplan.RenderDiffFile{{Path: "copy.txt", Before: []byte("old words"), After: []byte("new words")}}) |
| + var pixels bytes.Buffer |
| + must(t, png.Encode(&pixels, image.NewRGBA(image.Rect(0, 0, 1, 1)))) |
| + render := team.RenderResult{Repository: cand.Repository, BaseCommit: cand.BaseCommit, CandidateHash: hash, DiffHash: team.ContentDigest(diff), RenderHash: team.ContentDigest(pixels.Bytes()), RecipeHash: strings.Repeat("b", 64), EnvironmentHash: strings.Repeat("c", 64)} |
| + for _, blob := range [][]byte{diff, pixels.Bytes()} { |
| + f.exec(t, "INSERT INTO artifact_blobs(team_id,job_id,digest,bytes) VALUES(?,?,?,?)", scope.Account, scope.Job, team.ContentDigest(blob), blob) |
| + } |
| + |
| + for role, body := range map[team.Role][]byte{team.RoleCandidate: raw, team.RoleRender: encode(render)} { |
| + id := int64(1) |
| + if role == team.RoleRender { |
| + id = 2 |
| + } |
| + f.exec(t, "INSERT INTO artifacts(id,job_id,step_id,attempt_id,fence,role,hash,media_type,size,provenance,payload,created_at) VALUES(?,?,1,?,?,?,?,?,?,?,?,'2026-11-03T00:00:00Z')", id, job.ID, h.Attempt, h.Fence, role, team.ContentDigest(body), team.GitCandidateMediaType, len(body), `{"producer":"fixture","provider":"fixture","context":"fixture"}`, body) |
| + } |
| + |
| + apiRouter(t, f, nil) |
| + body := jsonBody(t, personapi.RenderedInput{CandidateHash: hash, DiffHash: render.DiffHash, RenderHash: render.RenderHash, Decision: "copy"}) |
| + path := "/api/v1/tasks/" + task.ID |
| + expectHTTP(t, apiRequest(t, f, peer, "POST", path+"/rendered-approval", body, "render", fmt.Sprintf(`"%d"`, task.Revision)), 403) |
| + for i := 0; i < 2; i++ { |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/rendered-approval", body, "render", fmt.Sprintf(`"%d"`, task.Revision)), 200) |
| + } |
| + current, err := f.Store.Task(ctx, owner, task.ID) |
| + must(t, err) |
| + f.exec(t, "UPDATE jobs SET state='succeeded' WHERE id=?", job.ID) |
| + ref := `{"reference":"https://amadan.net/test/fixture/merge/1"}` |
| + for i := 0; i < 2; i++ { |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/acknowledge-merge", ref, "merge", fmt.Sprintf(`"%d"`, current.Revision)), 200) |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/acknowledge-merge", `{"reference":"https://amadan.net/test/fixture/merge/2"}`, "merge", fmt.Sprintf(`"%d"`, current.Revision)), 409) |
| + f.exec(t, "UPDATE decision_owners SET address=? WHERE project_id=? AND decision='merge'", peer.Address, task.ProjectID) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/acknowledge-merge", ref, "merge", fmt.Sprintf(`"%d"`, current.Revision)), 409) |
| + if f.count(t, "SELECT count(*) FROM audit_events WHERE kind='task.merge' AND record_id=?", task.ID) != 1 { |
| + t.Fatal("duplicate merge acknowledgement") |
| + } |
| +} |
diff --git a/internal/plan3test/person_api_migration_test.go b/internal/plan3test/person_api_migration_test.go| new file mode 100644 |
| index 00000000..9e02de26 |
| --- /dev/null |
| +++ b/internal/plan3test/person_api_migration_test.go |
| @@ -0,0 +1,58 @@ |
| +package plan3test |
| + |
| +import ( |
| + "io" |
| + "log/slog" |
| + "path/filepath" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo" |
| + "amadan.net/rastrillo/rastrillo/db" |
| + "amadan.net/rastrillo/rastrillo/migrate" |
| +) |
| + |
| +func TestPersonAPIMigrationUpgrade(t *testing.T) { |
| + path := filepath.Join(t.TempDir(), "person-api.db") |
| + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| + d, err := db.Open(path, logger) |
| + must(t, err) |
| + old := &migrate.Set{} |
| + for _, m := range equipo.BootSchema.All() { |
| + if m.ID != "equipo/0023_person_api_requests" { |
| + old.Add(m) |
| + } |
| + } |
| + _, err = migrate.Apply(ctx, d, old) |
| + must(t, err) |
| + s := equipo.NewStore(d) |
| + must(t, s.Bootstrap(ctx, []string{owner.Address})) |
| + msg, err := s.SendMessage(ctx, owner, "", "historical message", equipo.Mutation{RequestID: "historical"}) |
| + must(t, err) |
| + result, err := migrate.Apply(ctx, d, equipo.BootSchema) |
| + must(t, err) |
| + if len(result.Applied) != 1 || result.Applied[0] != "equipo/0023_person_api_requests" { |
| + t.Fatal(result.Applied) |
| + } |
| + f := newFixture(t) |
| + upgraded, err := migrate.Read(ctx, d.Writer()) |
| + must(t, err) |
| + fresh, err := migrate.Read(ctx, f.DB.Writer()) |
| + must(t, err) |
| + if !upgraded.Equal(fresh) { |
| + t.Fatal(upgraded.Diff(fresh)) |
| + } |
| + must(t, d.Close()) |
| + d, err = db.Open(path, logger) |
| + must(t, err) |
| + t.Cleanup(func() { must(t, d.Close()) }) |
| + result, err = migrate.Apply(ctx, d, equipo.BootSchema) |
| + must(t, err) |
| + if len(result.Applied) != 0 { |
| + t.Fatal("reapplied", result.Applied) |
| + } |
| + page, err := equipo.NewStore(d).Conversation(ctx, owner, "", 50) |
| + must(t, err) |
| + if len(page.Messages) != 1 || page.Messages[0].ID != msg.ID { |
| + t.Fatal("historical message lost") |
| + } |
| +} |
diff --git a/internal/plan3test/person_api_operations_test.go b/internal/plan3test/person_api_operations_test.go| new file mode 100644 |
| index 00000000..fdfadd22 |
| --- /dev/null |
| +++ b/internal/plan3test/person_api_operations_test.go |
| @@ -0,0 +1,246 @@ |
| +package plan3test |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "encoding/hex" |
| + "encoding/json" |
| + "fmt" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "amadan.net/oficina/equipo/internal/equipo/team" |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| +) |
| + |
| +func jsonBody(t *testing.T, v any) string { |
| + t.Helper() |
| + b, e := json.Marshal(v) |
| + must(t, e) |
| + return string(b) |
| +} |
| +func TestPersonAPIMutations(t *testing.T) { |
| + f, _, _, b := coordinatorFixture(t) |
| + apiRouter(t, f, nil) |
| + var project int64 |
| + must(t, f.DB.Writer().QueryRow("SELECT project_id FROM tasks LIMIT 1").Scan(&project)) |
| + proposal := personapi.PlanInput{Kind: "recommendation", ProjectID: project, Steps: []personapi.PlanStep{{Key: "research", Specialist: "product", Action: "recommend", Instructions: "Read project material"}, {Key: "merge", Action: "person"}}} |
| + w := apiRequest(t, f, owner, "POST", "/api/v1/tasks", jsonBody(t, proposal), "proposal", "") |
| + expectHTTP(t, w, 200) |
| + plan := apiValue[personapi.Plan](t, w) |
| + taskPath := "/api/v1/tasks/" + plan.TaskID |
| + proposal.Steps[0].Instructions = "Read the current project material" |
| + w = apiRequest(t, f, owner, "PATCH", taskPath+"/plan", jsonBody(t, proposal), "edit", `"1"`) |
| + expectHTTP(t, w, 200) |
| + plan = apiValue[personapi.Plan](t, w) |
| + if plan.Revision != 2 { |
| + t.Fatal("edit did not increment revision") |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", taskPath+"/plan/approve", `{}`, "approve", `"2"`), 200) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", taskPath+"/project", fmt.Sprintf(`{"project_id":%d}`, project), "project", `"2"`), 200) |
| + msg := apiValue[personapi.Message](t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", `{"body":"route this"}`, "route-source", "")) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages/"+msg.ID+"/route", jsonBody(t, personapi.RouteInput{TaskID: plan.TaskID}), "route", `"1"`), 200) |
| + expectHTTP(t, apiRequest(t, f, peer, "POST", taskPath+"/thread/messages", `{"body":"shared answer"}`, "thread", ""), 200) |
| + w = apiRequest(t, f, owner, "POST", "/api/v1/preferences", `{"text":"Use plain words"}`, "preference", "") |
| + expectHTTP(t, w, 200) |
| + pref := apiValue[personapi.Preference](t, w) |
| + expectHTTP(t, apiRequest(t, f, peer, "PATCH", "/api/v1/preferences/"+pref.ID, `{"text":"foreign"}`, "foreign", `"1"`), 404) |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", "/api/v1/preferences/"+pref.ID, `{"text":"Use short words"}`, "correct", `"1"`), 200) |
| + expectHTTP(t, apiRequest(t, f, owner, "DELETE", "/api/v1/preferences/"+pref.ID, `{}`, "delete", `"2"`), 200) |
| + expectHTTP(t, apiRequest(t, f, owner, "DELETE", "/api/v1/preferences/"+pref.ID, `{}`, "delete", `"2"`), 200) |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", "/api/v1/coordinator", `{"runner_id":"fixture-runner","connection_id":"codex"}`, "rebind", fmt.Sprintf(`"%d"`, b.Revision)), 200) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/coordinator/reset", `{}`, "reset", fmt.Sprintf(`"%d"`, b.Revision+1)), 200) |
| + w = apiRequest(t, f, owner, "PATCH", "/api/v1/coordinator/limits", jsonBody(t, personapi.LimitsInput{Person: owner.Address, Limits: personapi.Limits{Calls: 23, InputTokens: 200000, OutputTokens: 40000, Seconds: 10000}}), "api-limits", `"1"`) |
| + expectHTTP(t, w, 200) |
| + f.exec(t, "UPDATE members SET role='member' WHERE address=?", peer.Address) |
| + expectHTTP(t, apiRequest(t, f, peer, "PATCH", "/api/v1/coordinator/limits", `{"person":"peer@example.com","limits":{"calls":23,"input_tokens":200000,"output_tokens":40000,"seconds":10000}}`, "denied", `"0"`), 403) |
| + task, err := f.Store.Task(ctx, owner, plan.TaskID) |
| + must(t, err) |
| + for i := 0; i < 2; i++ { |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", taskPath+"/cancel", `{}`, "cancel", fmt.Sprintf(`"%d"`, task.Revision)), 200) |
| + } |
| + if f.count(t, "SELECT count(*) FROM audit_events WHERE kind='task.cancel' AND record_id=?", task.ID) != 1 { |
| + t.Fatal("cancel replay duplicated effect") |
| + } |
| + if f.count(t, "SELECT count(*) FROM person_api_requests WHERE request_id='proposal'") != 1 { |
| + t.Fatal("request metadata missing") |
| + } |
| +} |
| +func TestPersonAPIQuestions(t *testing.T) { |
| + t.Run("clarification", func(t *testing.T) { |
| + f, x, p, c := claimTools(t) |
| + apiRouter(t, f, nil) |
| + q := toolCall(t, x, p, c, "q", "ask_person", map[string]any{"message_id": c.Turn.MessageID, "question": "Choose", "options": []map[string]string{{"id": "one", "label": "One"}}}) |
| + path := "/api/v1/questions/" + q.ResourceID |
| + expectHTTP(t, apiRequest(t, f, peer, "GET", path, "", "", ""), 404) |
| + w := apiRequest(t, f, owner, "GET", path, "", "", "") |
| + expectHTTP(t, w, 200) |
| + view := apiValue[personapi.Question](t, w) |
| + if view.Kind != "clarification" || !view.CanAnswer || len(view.Options) != 1 { |
| + t.Fatal(view) |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/answer", `{"kind":"clarification","option_id":"one"}`, "answer", `"2"`), 409) |
| + for i := 0; i < 2; i++ { |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/answer", `{"kind":"clarification","option_id":"one"}`, "answer", `"1"`), 200) |
| + } |
| + if f.count(t, "SELECT count(*) FROM audit_events WHERE kind='clarification.answer'") != 1 { |
| + t.Fatal("duplicate answer") |
| + } |
| + }) |
| + t.Run("native", func(t *testing.T) { |
| + f, _, _, _, q := nativeConversationFixture(t) |
| + apiRouter(t, f, nil) |
| + path := "/api/v1/questions/" + q.ID |
| + w := apiRequest(t, f, owner, "GET", path, "", "", "") |
| + expectHTTP(t, w, 200) |
| + view := apiValue[personapi.Question](t, w) |
| + if view.Kind != "native" || !view.CanAnswer || len(view.Fields) != 1 { |
| + t.Fatal(view) |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/answer", `{"kind":"native","text":"yes"}`, "invalid", `"1"`), 422) |
| + body := `{"kind":"native","behavior":"allow","updated_input":{"answers":{"Which?":"Blue"}}}` |
| + for i := 0; i < 2; i++ { |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", path+"/answer", body, "answer", `"1"`), 200) |
| + } |
| + expectHTTP(t, formPost(t, f, owner, "/tasks/"+q.TaskID+"/questions/"+q.ID+"/answer", url.Values{"revision": {"1"}, "behavior": {"allow"}, "answer_0": {"Blue"}}), 303) |
| + }) |
| +} |
| +func TestPersonAPICoordinatorRetry(t *testing.T) { |
| + f, _, _, _ := coordinatorFixture(t) |
| + apiRouter(t, f, nil) |
| + turn := queueCoordinator(t, f, "read", "retry-message") |
| + f.exec(t, "UPDATE coordinator_turns SET state='context_limit' WHERE id=?", turn.ID) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/coordinator/retry", jsonBody(t, personapi.RetryInput{TurnID: turn.ID}), "retry", fmt.Sprintf(`"%d"`, turn.Revision)), 200) |
| +} |
| +func TestPersonAPIPaginationAndValidation(t *testing.T) { |
| + f := newFixture(t) |
| + w := apiRequest(t, f, owner, "GET", "/api/v1/people?limit=1", "", "", "") |
| + expectHTTP(t, w, 200) |
| + page := apiValue[personapi.Page[personapi.Person]](t, w) |
| + if len(page.Items) != 1 || page.NextCursor == "" { |
| + t.Fatal(page) |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/people?cursor="+page.NextCursor, "", "", ""), 200) |
| + expectHTTP(t, apiRequest(t, f, peer, "GET", "/api/v1/people?cursor="+page.NextCursor, "", "", ""), 410) |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/preferences?cursor="+page.NextCursor, "", "", ""), 410) |
| + f.exec(t, "UPDATE person_api_cursors SET expires_at='2000-01-01T00:00:00Z'") |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/people?cursor="+page.NextCursor, "", "", ""), 410) |
| + for _, query := range []string{"limit=0", "limit=101", "limit=x", "limit=1&limit=2", "person=peer@example.com"} { |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/people?"+query, "", "", ""), 422) |
| + } |
| + for _, body := range []string{`{"body":"a","body":"b"}`, `{"body":"a","address":"peer@example.com"}`, `{"body":"` + strings.Repeat("a", 16385) + `"}`, `{"body":"` + strings.Repeat("a", 65536) + `"}`} { |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", body, "invalid", ""), 422) |
| + } |
| + f.exec(t, "CREATE TRIGGER deny_api_metadata BEFORE INSERT ON person_api_requests BEGIN SELECT RAISE(ABORT,'fixture'); END") |
| + before := f.count(t, "SELECT count(*) FROM conversation_messages") |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", `{"body":"rollback"}`, "rollback", ""), 503) |
| + if f.count(t, "SELECT count(*) FROM conversation_messages") != before { |
| + t.Fatal("metadata failure left mutation committed") |
| + } |
| +} |
| +func TestPersonAPIBrowserCSRFRunner(t *testing.T) { |
| + f, x, principal, request, _ := nativeConversationFixture(t) |
| + apiRouter(t, f, nil) |
| + runnerToken := base64.RawURLEncoding.EncodeToString(make([]byte, 32)) |
| + hash := func(audience, token string) string { |
| + sum := sha256.Sum256([]byte(audience + "\x00" + token)) |
| + return hex.EncodeToString(sum[:]) |
| + } |
| + f.exec(t, "UPDATE runner_credentials SET token_hash=?,expires_at=? WHERE id='fixture-credential'", hash(runnerproto.RunnerAudience, runnerToken), time.Now().Add(time.Hour).UTC()) |
| + do := func(path, auth, body string, cookie bool) *httptest.ResponseRecorder { |
| + r := httptest.NewRequest("POST", path, strings.NewReader(body)) |
| + r.Header.Set("Content-Type", "application/json") |
| + r.Header.Set("Authorization", auth) |
| + if cookie { |
| + r.AddCookie(f.Cookies[owner.Address]) |
| + } |
| + w := httptest.NewRecorder() |
| + f.Handler.ServeHTTP(w, r) |
| + return w |
| + } |
| + expectHTTP(t, do("/api/runner/v2/heartbeat", "Bearer "+runnerToken, `{"version":2,"request_id":"heartbeat"}`, false), 200) |
| + expectHTTP(t, do("/api/runner/v2/heartbeat", "Bearer "+runnerToken, `{"version":2,"request_id":"mixed"}`, true), 403) |
| + expectHTTP(t, do("/api/v1/conversation/messages", "Bearer "+runnerToken, `{"body":"wrong audience"}`, false), 401) |
| + cleanup := "fixture-cleanup" |
| + f.exec(t, "UPDATE runner_cleanups SET token_hash=? WHERE assignment_id=?", hash(runnerproto.CleanupAudience, cleanup), request.AssignmentID) |
| + request.RequestID = "cleanup-intent" |
| + request.Intent = &team.IntentSpec{Key: "cleanup-turn", Operation: team.OpProviderCall, Payload: []byte(`{"task":"research"}`), Reserve: team.Usage{InputTokens: 10, OutputTokens: 10}} |
| + action, err := x.Mutate(ctx, principal, "intend", request) |
| + must(t, err) |
| + request.ActionID = action.(team.ActionID) |
| + request.Intent = nil |
| + request.RequestID = "cleanup-observation" |
| + request.Receipt = &team.Receipt{ID: "fixture-observation", Outcome: "success"} |
| + wire, err := runnerproto.Marshal(request) |
| + must(t, err) |
| + expectHTTP(t, do("/api/runner/v2/receipts", "Bearer "+runnerToken, string(wire), false), 200) |
| + request.RequestID = "cleanup-receipt" |
| + wire, err = runnerproto.Marshal(request) |
| + must(t, err) |
| + // Cleanup receipts are observations only; they cannot settle usage or admit work. |
| + expectHTTP(t, do("/api/runner/v2/receipts", "Cleanup "+cleanup, string(wire), false), 200) |
| + expectHTTP(t, do("/api/runner/v2/intend", "Cleanup "+cleanup, string(wire), false), 403) |
| + expectHTTP(t, do("/api/v1/conversation/messages", "Cleanup "+cleanup, `{"body":"wrong audience"}`, false), 401) |
| +} |
| + |
| +func TestPersonAPIProjectionParity(t *testing.T) { |
| + f := newFixture(t) |
| + expectHTTP(t, formPost(t, f, owner, "/preferences", url.Values{"request_id": {"html-preference"}, "revision": {"0"}, "text": {"Use plain words"}}), 303) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/preferences", `{"text":"Use plain words"}`, "html-preference", ""), 200) |
| + p := proposed(t, f) |
| + p.Steps[1].DependsOn = []string{p.Steps[0].Key} |
| + p, err := f.Store.EditPlan(ctx, owner, p, equipo.Mutation{RequestID: "dependency", Revision: p.Revision}) |
| + must(t, err) |
| + w := apiRequest(t, f, owner, "GET", "/api/v1/tasks/"+p.TaskID+"/plan", "", "", "") |
| + expectHTTP(t, w, 200) |
| + var value struct { |
| + Steps []struct { |
| + DependsOn []string `json:"depends_on"` |
| + } |
| + } |
| + must(t, json.Unmarshal(w.Body.Bytes(), &value)) |
| + if len(value.Steps[1].DependsOn) != 1 || value.Steps[1].DependsOn[0] != p.Steps[0].Key { |
| + t.Fatal("plan projection lost dependencies") |
| + } |
| + detail := apiRequest(t, f, owner, "GET", "/api/v1/tasks/"+p.TaskID, "", "", "") |
| + expectHTTP(t, detail, 200) |
| + task := apiValue[personapi.Task](t, detail) |
| + if task.Usage != nil { |
| + t.Fatal("unknown task usage became known") |
| + } |
| + for _, step := range task.Steps { |
| + if step.Usage != nil || step.AllowanceRemaining != nil { |
| + t.Fatal("unknown step quantity became known") |
| + } |
| + } |
| + projected := apiValue[personapi.Plan](t, w) |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", "/api/v1/tasks/"+p.TaskID+"/plan", jsonBody(t, projected.PlanInput), "dependency-roundtrip", w.Header().Get("ETag")), 200) |
| +} |
| +func TestPersonAPIInitialBindingETag(t *testing.T) { |
| + f := newFixture(t) |
| + task := f.createTask(t) |
| + f.planConnections(t, task.ProjectID) |
| + apiRouter(t, f, nil) |
| + w := apiRequest(t, f, owner, "GET", "/api/v1/coordinator", "", "", "") |
| + expectHTTP(t, w, 200) |
| + if w.Header().Get("ETag") != `"0"` { |
| + t.Fatal("unset binding revision", w.Header()) |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", "/api/v1/coordinator", `{"runner_id":"fixture-runner","connection_id":"claude"}`, "initial-binding", w.Header().Get("ETag")), 200) |
| +} |
| + |
| +func TestPersonAPIUnavailableQuery(t *testing.T) { |
| + f := newFixture(t) |
| + f.exec(t, "DROP TABLE personal_preferences") |
| + w := apiRequest(t, f, owner, "GET", "/api/v1/preferences", "", "", "") |
| + expectHTTP(t, w, 503) |
| + failure := apiValue[personapi.Error](t, w) |
| + if failure.Code != "unavailable" || failure.CopyKey != "api.unavailable" { |
| + t.Fatal("query failure became an empty list", failure) |
| + } |
| +} |
diff --git a/internal/plan3test/person_api_test.go b/internal/plan3test/person_api_test.go| new file mode 100644 |
| index 00000000..b4d32f65 |
| --- /dev/null |
| +++ b/internal/plan3test/person_api_test.go |
| @@ -0,0 +1,222 @@ |
| +package plan3test |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "fmt" |
| + "io" |
| + "log/slog" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo" |
| + "amadan.net/oficina/equipo/internal/equipo/personapi" |
| + "amadan.net/rastrillo/rastrillo/mail" |
| +) |
| + |
| +func apiRequest(t *testing.T, f *fixture, actor equipo.Actor, method, path, body, key, revision string) *httptest.ResponseRecorder { |
| + t.Helper() |
| + r := httptest.NewRequest(method, path, strings.NewReader(body)) |
| + if actor.Address != "" { |
| + r.AddCookie(f.Cookies[actor.Address]) |
| + } |
| + r.Header.Set("Origin", origin) |
| + r.Header.Set("Content-Type", "application/json") |
| + if key != "" { |
| + r.Header.Set("Idempotency-Key", key) |
| + } |
| + if revision != "" { |
| + r.Header.Set("If-Match", revision) |
| + } |
| + w := httptest.NewRecorder() |
| + f.Handler.ServeHTTP(w, r) |
| + return w |
| +} |
| +func apiValue[T any](t *testing.T, w *httptest.ResponseRecorder) T { |
| + t.Helper() |
| + var out T |
| + must(t, json.Unmarshal(w.Body.Bytes(), &out)) |
| + return out |
| +} |
| +func apiRouter(t *testing.T, f *fixture, verifier personapi.VerifyPersonBearer) { |
| + t.Helper() |
| + if verifier != nil { |
| + equipo.WithPersonBearerVerifier(verifier)(f.Store) |
| + } |
| + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) |
| + r, err := equipo.RouterWithStore(f.DB, equipo.Config{Origin: origin, InstanceKey: "plan3-fixture", AllowLoggedMail: true, Owners: []string{owner.Address}}, mail.Logged(logger), logger, f.Store) |
| + must(t, err) |
| + f.Handler = equipo.Mux(r) |
| +} |
| +func TestPersonAPIAuthAudiences(t *testing.T) { |
| + f := newFixture(t) |
| + expectHTTP(t, apiRequest(t, f, equipo.Actor{}, "GET", "/api/v1/me", "", "", ""), 401) |
| + for _, token := range []string{"runner", "cleanup", "coordinator", "other-instance", "invalid"} { |
| + r := httptest.NewRequest("GET", "/api/v1/me", nil) |
| + r.Header.Set("Authorization", "Bearer "+token) |
| + r.Header.Set("Origin", origin) |
| + w := httptest.NewRecorder() |
| + f.Handler.ServeHTTP(w, r) |
| + expectHTTP(t, w, 401) |
| + if !strings.HasPrefix(w.Header().Get("Content-Type"), "application/json") { |
| + t.Fatal("auth returned HTML") |
| + } |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", `{"body":"x","person":"peer@example.com"}`, "forged", ""), 422) |
| + f.exec(t, "DELETE FROM sessions WHERE subject=?", owner.Address) |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/me", "", "", ""), 401) |
| +} |
| +func TestPersonAPIBrowserCSRF(t *testing.T) { |
| + f := newFixture(t) |
| + apiRouter(t, f, func(_ context.Context, token string) (personapi.PersonPrincipal, error) { |
| + if token != "native-fixture" { |
| + return personapi.PersonPrincipal{}, equipo.ErrForbidden |
| + } |
| + return personapi.PersonPrincipal{Address: owner.Address, CredentialID: "native-fixture", SessionEpoch: time.Now().Unix()}, nil |
| + }) |
| + for _, tc := range []struct { |
| + name, auth, site string |
| + cookie bool |
| + status int |
| + }{ |
| + {"native", "Bearer native-fixture", "", false, 200}, |
| + {"cookie", "", origin, true, 200}, |
| + {"cross-cookie", "", "https://evil.example", true, 403}, |
| + {"missing", "", origin, false, 401}, |
| + {"invalid", "Bearer invalid", origin, false, 401}, |
| + {"mixed", "Bearer native-fixture", origin, true, 401}, |
| + {"cross-native", "Bearer native-fixture", "https://evil.example", false, 403}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + before := f.count(t, "SELECT count(*) FROM conversation_messages") |
| + r := httptest.NewRequest("POST", "/api/v1/conversation/messages", strings.NewReader(`{"body":"`+tc.name+`"}`)) |
| + r.Header.Set("Content-Type", "application/json") |
| + r.Header.Set("Idempotency-Key", tc.name) |
| + if tc.auth != "" { |
| + r.Header.Set("Authorization", tc.auth) |
| + } |
| + if tc.site != "" { |
| + r.Header.Set("Origin", tc.site) |
| + } |
| + if tc.cookie { |
| + r.AddCookie(f.Cookies[owner.Address]) |
| + } |
| + w := httptest.NewRecorder() |
| + f.Handler.ServeHTTP(w, r) |
| + expectHTTP(t, w, tc.status) |
| + after := f.count(t, "SELECT count(*) FROM conversation_messages") |
| + if tc.status != 200 && before != after { |
| + t.Fatal("rejected request wrote data") |
| + } |
| + }) |
| + } |
| + r := httptest.NewRequest("POST", "/conversation", strings.NewReader("body=bad&request_id=bad")) |
| + r.Header.Set("Authorization", "Bearer native-fixture") |
| + r.Header.Set("Origin", origin) |
| + w := httptest.NewRecorder() |
| + f.Handler.ServeHTTP(w, r) |
| + if w.Code < 400 { |
| + t.Fatal("bearer on cookie-only route accepted") |
| + } |
| +} |
| +func TestPersonAPIRevisionReplay(t *testing.T) { |
| + f := newFixture(t) |
| + path := "/api/v1/me/settings" |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", path, `{"landing":"work"}`, "settings", ""), 428) |
| + w := apiRequest(t, f, owner, "PATCH", path, `{"landing":"work"}`, "settings", `"1"`) |
| + expectHTTP(t, w, 200) |
| + replay := apiRequest(t, f, owner, "PATCH", path, `{"landing":"work"}`, "settings", `"1"`) |
| + expectHTTP(t, replay, 200) |
| + if w.Body.String() != replay.Body.String() { |
| + t.Fatal("replay changed result") |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", path, `{"landing":"conversation"}`, "settings", `"1"`), 409) |
| + expectHTTP(t, apiRequest(t, f, owner, "PATCH", path, `{"landing":"conversation"}`, "new", `"1"`), 409) |
| + page, err := f.Store.Conversation(ctx, owner, "", 50) |
| + must(t, err) |
| + revision := fmt.Sprintf(`"%d"`, page.Revision) |
| + values := url.Values{"request_id": {"cross-surface"}, "revision": {fmt.Sprint(page.Revision)}, "body": {"from HTML"}} |
| + expectHTTP(t, formPost(t, f, owner, "/conversation", values), 303) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", `{"body":"changed"}`, "cross-surface", revision), 409) |
| + w = apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", `{"body":"from HTML"}`, "cross-surface", revision) |
| + expectHTTP(t, w, 200) |
| + if f.count(t, "SELECT count(*) FROM conversation_messages WHERE body='from HTML'") != 1 { |
| + t.Fatal("cross-surface duplicate") |
| + } |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/conversation/messages", `{"body":"changed"}`, "cross-surface", revision), 409) |
| +} |
| +func TestPersonAPIConversationParity(t *testing.T) { |
| + f := newFixture(t) |
| + p := proposed(t, f) |
| + _, err := f.Store.SendMessage(ctx, owner, "", "private text", equipo.Mutation{RequestID: "private"}) |
| + must(t, err) |
| + _, err = f.Store.SendMessage(ctx, owner, p.TaskID, "shared text", equipo.Mutation{RequestID: "shared"}) |
| + must(t, err) |
| + w := apiRequest(t, f, peer, "GET", "/api/v1/conversation", "", "", "") |
| + expectHTTP(t, w, 200) |
| + if strings.Contains(w.Body.String(), "private text") { |
| + t.Fatal("private conversation leaked") |
| + } |
| + w = apiRequest(t, f, peer, "GET", "/api/v1/tasks/"+p.TaskID+"/thread", "", "", "") |
| + expectHTTP(t, w, 200) |
| + if !strings.Contains(w.Body.String(), "shared text") { |
| + t.Fatal("shared thread absent") |
| + } |
| + w = apiRequest(t, f, owner, "GET", "/api/v1/conversation/cards", "", "", "") |
| + expectHTTP(t, w, 200) |
| + if !strings.Contains(w.Body.String(), p.TaskID) { |
| + t.Fatal("task card absent") |
| + } |
| + if w.Header().Get("Cache-Control") != "no-store" || w.Header().Get("ETag") == "" { |
| + t.Fatal("missing privacy/revision headers") |
| + } |
| +} |
| +func TestPersonAPIPeopleReadOnly(t *testing.T) { |
| + f := newFixture(t) |
| + w := apiRequest(t, f, peer, "GET", "/api/v1/people", "", "", "") |
| + expectHTTP(t, w, 200) |
| + var page struct{ Items []map[string]any } |
| + must(t, json.Unmarshal(w.Body.Bytes(), &page)) |
| + if len(page.Items) != 2 { |
| + t.Fatal("missing members", page) |
| + } |
| + for _, item := range page.Items { |
| + for k := range item { |
| + if k != "address" && k != "display_identity" && k != "active" && k != "role" { |
| + t.Fatal("unsafe people field", k) |
| + } |
| + } |
| + } |
| + for _, method := range []string{"POST", "PUT", "PATCH", "DELETE"} { |
| + expectHTTP(t, apiRequest(t, f, owner, method, "/api/v1/people", `{}`, "write", ""), 405) |
| + } |
| + f.exec(t, "UPDATE members SET active=0 WHERE address=?", peer.Address) |
| + expectHTTP(t, apiRequest(t, f, peer, "GET", "/api/v1/people", "", "", ""), 403) |
| +} |
| +func TestPersonAPIRequiredReads(t *testing.T) { |
| + f := newFixture(t) |
| + p := proposed(t, f) |
| + for _, path := range []string{"/me", "/capabilities", "/me/settings", "/people", "/conversation", "/conversation/cards", "/tasks", "/tasks/" + p.TaskID, "/tasks/" + p.TaskID + "/plan", "/tasks/" + p.TaskID + "/thread", "/journey", "/needs-you", "/preferences", "/coordinator"} { |
| + t.Run(path, func(t *testing.T) { |
| + w := apiRequest(t, f, owner, "GET", "/api/v1"+path, "", "", "") |
| + expectHTTP(t, w, 200) |
| + if w.Header().Get("ETag") == "" { |
| + t.Fatal("missing ETag", fmt.Sprint(w.Header())) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestPersonAPISessionRevocationAndReplayAuthority(t *testing.T) { |
| + f := newFixture(t) |
| + w := apiRequest(t, f, owner, "POST", "/api/v1/preferences", `{"text":"plain"}`, "preference", "") |
| + expectHTTP(t, w, 200) |
| + f.exec(t, "UPDATE members SET session_epoch=? WHERE address=?", time.Now().Add(time.Hour).Unix(), owner.Address) |
| + expectHTTP(t, apiRequest(t, f, owner, "POST", "/api/v1/preferences", `{"text":"plain"}`, "preference", ""), 403) |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/capabilities", "", "", ""), 403) |
| + f.exec(t, "UPDATE members SET session_epoch=0,active=0 WHERE address=?", owner.Address) |
| + expectHTTP(t, apiRequest(t, f, owner, "GET", "/api/v1/capabilities", "", "", ""), 403) |
| +} |
diff --git a/internal/plan3test/preferences_test.go b/internal/plan3test/preferences_test.go| index 6d11fbe0..082d4e7d 100644 |
| --- a/internal/plan3test/preferences_test.go |
| +++ b/internal/plan3test/preferences_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "log/slog" |
| "net/http/httptest" |
| "net/url" |
| + "slices" |
| "strings" |
| "testing" |
| "time" |
| @@ -262,10 +263,15 @@ func TestPreferencesAtomicInvalidation(t *testing.T) { |
| f.Store.SetJobNotifier(spy) |
| pref, err := f.Store.SetPreference(ctx, owner, equipo.Preference{Text: "private preference"}, equipo.Mutation{RequestID: "notify"}) |
| must(t, err) |
| - if len(spy.topics) != 1 || !strings.HasPrefix(spy.topics[0], "personal/") || strings.Contains(spy.topics[0], owner.Address) { |
| + topicsFor := func(actor equipo.Actor) []string { |
| + var id string |
| + must(t, f.DB.Writer().QueryRow("SELECT id FROM conversations WHERE person=?", actor.Address).Scan(&id)) |
| + return []string{conversation.ConversationTopic(f.TeamID, actor.Address, id), conversation.PersonalTopic(f.TeamID, actor.Address)} |
| + } |
| + topics := topicsFor(owner) |
| + if !slices.Equal(spy.topics, topics) || strings.Contains(strings.Join(spy.topics, " "), owner.Address) { |
| t.Fatal("missing private invalidation", spy.topics) |
| } |
| - topic := spy.topics[0] |
| spy.topics = nil |
| before := f.count(t, "SELECT revision FROM conversations WHERE person=?", owner.Address) |
| f.exec(t, `CREATE TRIGGER fail_preference_audit BEFORE INSERT ON audit_events WHEN NEW.kind='preference.set' BEGIN SELECT RAISE(ABORT,'fixture audit failure'); END`) |
| @@ -281,13 +287,13 @@ func TestPreferencesAtomicInvalidation(t *testing.T) { |
| f.exec(t, "DROP TRIGGER fail_preference_audit") |
| _, err = f.Store.SetPreference(ctx, owner, pref, equipo.Mutation{RequestID: "rollback", Revision: 1}) |
| must(t, err) |
| - if len(spy.topics) != 1 || spy.topics[0] != topic { |
| + if !slices.Equal(spy.topics, topics) { |
| t.Fatal("commit omitted invalidation", spy.topics) |
| } |
| spy.topics = nil |
| _, err = f.Store.SetPreference(ctx, peer, equipo.Preference{Text: "other person"}, equipo.Mutation{RequestID: "peer"}) |
| must(t, err) |
| - if len(spy.topics) != 1 || spy.topics[0] == topic { |
| + if !slices.Equal(spy.topics, topicsFor(peer)) || slices.Contains(spy.topics, topics[0]) || slices.Contains(spy.topics, topics[1]) { |
| t.Fatal("private topics overlap", spy.topics) |
| } |
| } |
diff --git a/internal/runnerproto/question_views.go b/internal/runnerproto/question_views.go| new file mode 100644 |
| index 00000000..e115283e |
| --- /dev/null |
| +++ b/internal/runnerproto/question_views.go |
| @@ -0,0 +1,53 @@ |
| +package runnerproto |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| +) |
| + |
| +type QuestionField struct{ Key, Prompt string } |
| + |
| +func DisplayJSON(raw string) string { |
| + var value any |
| + if json.Unmarshal([]byte(raw), &value) != nil { |
| + return raw |
| + } |
| + var buf bytes.Buffer |
| + enc := json.NewEncoder(&buf) |
| + enc.SetEscapeHTML(false) |
| + enc.SetIndent("", " ") |
| + if enc.Encode(value) != nil { |
| + return raw |
| + } |
| + return buf.String() |
| +} |
| + |
| +func QuestionFields(kind, raw string) []QuestionField { |
| + var q struct { |
| + Provider, Name, Question string |
| + Input struct { |
| + Questions []struct{ Question, Header string } |
| + } |
| + } |
| + if json.Unmarshal([]byte(raw), &q) != nil { |
| + return nil |
| + } |
| + if kind == "person" && q.Question != "" { |
| + return []QuestionField{{Key: "answer", Prompt: q.Question}} |
| + } |
| + if (q.Provider != "claude" || q.Name != "AskUserQuestion") && (q.Provider != "codex" || q.Name != "request_user_input") { |
| + return nil |
| + } |
| + var fields []QuestionField |
| + for _, f := range q.Input.Questions { |
| + key := f.Question |
| + if q.Provider == "codex" { |
| + key = f.Header |
| + } |
| + if key == "" { |
| + return nil |
| + } |
| + fields = append(fields, QuestionField{Key: key, Prompt: f.Question}) |
| + } |
| + return fields |
| +} |