{
  "openapi": "3.1.0",
  "info": {
    "title": "OmniConflux Social API",
    "version": "1.0.0",
    "description": "Agent-first publishing API. The CLI and the web UI are clients of this same surface. Every write is idempotent; every state is explicit; \"published\" means the platform confirmed it."
  },
  "servers": [
    {
      "url": "/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message",
              "retryable"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "hint": {
                "type": "string"
              }
            }
          }
        }
      },
      "Post": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "channelId": {
            "type": "string"
          },
          "platform": {
            "type": "string"
          },
          "state": {
            "enum": [
              "queued",
              "submitting",
              "processing",
              "awaiting_user",
              "published",
              "failed"
            ]
          },
          "mode": {
            "enum": [
              "inbox",
              "direct"
            ]
          },
          "caption": {
            "type": "string"
          },
          "mediaUrl": {
            "type": "string"
          },
          "publicId": {
            "type": [
              "string",
              "null"
            ]
          },
          "failCode": {
            "type": [
              "string",
              "null"
            ]
          },
          "failMessage": {
            "type": [
              "string",
              "null"
            ]
          },
          "retryable": {
            "type": "boolean"
          },
          "attempts": {
            "type": "integer"
          },
          "next": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Liveness",
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/channels": {
      "get": {
        "summary": "List connected channels",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "channels:read",
        "responses": {
          "200": {
            "description": "channels"
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/channels/health": {
      "get": {
        "summary": "Token and connection health per channel",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "channels:read",
        "responses": {
          "200": {
            "description": "health"
          }
        }
      }
    },
    "/channels/link": {
      "post": {
        "summary": "Link a brokered provider key and mirror its accounts",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "channels:write",
        "responses": {
          "201": {
            "description": "linked channels"
          },
          "422": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connect/{id}": {
      "get": {
        "summary": "Open a sign-in link. Redirects to the network sign-in; expires after an hour.",
        "responses": {
          "302": {
            "description": "redirect to sign-in"
          },
          "410": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/channels/connect-url": {
      "post": {
        "summary": "Mint a link on this host for an account owner to authorize a platform",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "channels:write",
        "responses": {
          "200": {
            "description": "url"
          },
          "409": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/posts": {
      "post": {
        "summary": "Create a post. Requires Idempotency-Key.",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "posts:write",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "channelId",
                  "caption",
                  "mediaUrl"
                ],
                "properties": {
                  "channelId": {
                    "type": "string"
                  },
                  "caption": {
                    "type": "string",
                    "maxLength": 2200
                  },
                  "mediaUrl": {
                    "type": "string",
                    "format": "uri"
                  },
                  "mode": {
                    "enum": [
                      "inbox",
                      "direct"
                    ]
                  },
                  "privacy": {
                    "type": "string"
                  },
                  "scheduledFor": {
                    "type": "integer",
                    "description": "epoch ms"
                  },
                  "settings": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "idempotent replay"
          },
          "202": {
            "description": "accepted"
          },
          "400": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List recent posts",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "posts:read",
        "responses": {
          "200": {
            "description": "posts"
          }
        }
      }
    },
    "/posts/{id}": {
      "get": {
        "summary": "Get a post and its explicit state",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "posts:read",
        "responses": {
          "200": {
            "description": "post"
          },
          "404": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/posts/{id}/step": {
      "post": {
        "summary": "Advance a post now instead of waiting for the worker",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "posts:write",
        "responses": {
          "200": {
            "description": "post"
          }
        }
      }
    },
    "/keys": {
      "get": {
        "summary": "List API keys (never the secrets)",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "keys:admin",
        "responses": {
          "200": {
            "description": "keys"
          }
        }
      },
      "post": {
        "summary": "Create a key; the secret is shown once",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "keys:admin",
        "responses": {
          "201": {
            "description": "key"
          }
        }
      }
    },
    "/keys/{id}": {
      "delete": {
        "summary": "Revoke a key",
        "security": [
          {
            "bearer": []
          }
        ],
        "x-scope": "keys:admin",
        "responses": {
          "200": {
            "description": "revoked"
          }
        }
      }
    },
    "/webhooks/provider": {
      "post": {
        "summary": "Upstream delivery receiver. HMAC-SHA256 of the raw body, deduped by event id.",
        "responses": {
          "200": {
            "description": "acknowledged"
          },
          "401": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
