{
  "openapi": "3.0.3",
  "info": {
    "title": "Machina Project API",
    "description": "API for managing project resources, agents, workflows, and AI-powered content generation",
    "version": "1.13.0",
    "contact": {
      "name": "Machina Support",
      "email": "support@machina.gg",
      "url": "https://machina.gg"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "servers": [
    {
      "url": "http://localhost:5003",
      "description": "Development server"
    },
    {
      "url": "https://api.machina.gg",
      "description": "Production server"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiTokenAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Token",
        "description": "API authentication token"
      }
    },
    "schemas": {
      "Resource": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique resource identifier"
          },
          "name": {
            "type": "string",
            "description": "Resource name"
          },
          "type": {
            "type": "string",
            "enum": ["databases", "applications", "projects", "services"],
            "description": "Resource type"
          },
          "description": {
            "type": "string",
            "description": "Resource description"
          },
          "url": {
            "type": "string",
            "description": "Resource URL"
          },
          "status": {
            "type": "string",
            "enum": ["active", "archived", "draft"],
            "description": "Resource status"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Creation timestamp"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Last update timestamp"
          }
        },
        "required": ["name", "type"]
      },
      "Agent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique agent identifier"
          },
          "name": {
            "type": "string",
            "description": "Agent name"
          },
          "status": {
            "type": "string",
            "enum": ["active", "archived", "draft"],
            "description": "Agent status"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": ["name"]
      },
      "Document": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique document identifier"
          },
          "name": {
            "type": "string",
            "description": "Document name"
          },
          "content": {
            "type": "string",
            "description": "Document content"
          },
          "metadata": {
            "type": "object",
            "description": "Document metadata"
          },
          "status": {
            "type": "string",
            "enum": ["active", "archived", "draft"],
            "description": "Document status"
          },
          "created": {
            "type": "string",
            "format": "date-time",
            "description": "Creation timestamp"
          },
          "updated": {
            "type": "string",
            "format": "date-time",
            "description": "Last update timestamp"
          }
        },
        "required": ["name"]
      },
      "SearchRequest": {
        "type": "object",
        "properties": {
          "filters": {
            "type": "object",
            "description": "Search filters"
          },
          "page": {
            "type": "integer",
            "minimum": 1,
            "default": 1,
            "description": "Page number"
          },
          "page_size": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 10,
            "description": "Number of items per page"
          },
          "sorters": {
            "type": "array",
            "items": {
              "oneOf": [
                {"type": "string"},
                {"type": "integer"}
              ]
            },
            "description": "Sort configuration"
          }
        }
      },
      "HealthCheckResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": ["healthy", "unhealthy"],
            "description": "Service health status"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Health check timestamp"
          },
          "services": {
            "type": "object",
            "description": "Individual service statuses"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error message"
          },
          "code": {
            "type": "string",
            "description": "Error code"
          },
          "details": {
            "type": "object",
            "description": "Additional error details"
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "system",
      "description": "System health and monitoring endpoints"
    },
    {
      "name": "document",
      "description": "Document storage and retrieval"
    },
    {
      "name": "resources",
      "description": "Project resource management"
    },
    {
      "name": "agent",
      "description": "AI agent management and execution"
    },
    {
      "name": "connector",
      "description": "External service connectors"
    },
    {
      "name": "workflow",
      "description": "Workflow orchestration and execution"
    },
    {
      "name": "prompt",
      "description": "AI prompt management"
    },
    {
      "name": "content",
      "description": "Content generation and management"
    },
    {
      "name": "dataset",
      "description": "Dataset loading and management"
    }
  ],
  "paths": {
    "/": {
      "get": {
        "tags": ["system"],
        "summary": "API Root",
        "description": "API homepage with links to documentation",
        "operationId": "getRoot",
        "responses": {
          "200": {
            "description": "API information and links",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/resource": {
      "get": {
        "tags": ["resources"],
        "summary": "List Resources",
        "description": "List project resources with optional filtering",
        "operationId": "listResources",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["databases", "applications", "projects", "services"]
            },
            "description": "Filter by resource type"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            },
            "description": "Number of items to return"
          }
        ],
        "responses": {
          "200": {
            "description": "List of resources",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "resources": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Resource"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "page_size": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["resources"],
        "summary": "Create Resource",
        "description": "Create a new project resource",
        "operationId": "createResource",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Resource name"
                  },
                  "type": {
                    "type": "string",
                    "enum": ["databases", "applications", "projects", "services"],
                    "description": "Resource type"
                  },
                  "description": {
                    "type": "string",
                    "description": "Resource description"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Resource URL"
                  }
                },
                "required": ["name", "type"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resource created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Resource"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/agent": {
      "post": {
        "tags": ["agent"],
        "summary": "Create Agent",
        "description": "Create a new AI agent",
        "operationId": "createAgent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "AGENT 006"
                  }
                },
                "required": ["name"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Agent created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Agent"
                }
              }
            }
          }
        }
      }
    },
    "/agent/search": {
      "post": {
        "tags": ["agent"],
        "summary": "Search Agents",
        "description": "Search and filter agents",
        "operationId": "searchAgents",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Agent"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/document": {
      "post": {
        "tags": ["document"],
        "summary": "Create Document",
        "description": "Create a new document",
        "operationId": "createDocument",
        "security": [
          {"ApiTokenAuth": []}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Document name"
                  },
                  "content": {
                    "type": "string",
                    "description": "Document content"
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Document metadata"
                  },
                  "status": {
                    "type": "string",
                    "enum": ["active", "archived", "draft"],
                    "description": "Document status"
                  }
                },
                "required": ["name"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Document"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/document/search": {
      "post": {
        "tags": ["document"],
        "summary": "Search Documents",
        "description": "Search and filter documents",
        "operationId": "searchDocuments",
        "security": [
          {"ApiTokenAuth": []}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Document"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "page_size": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/document/{item_id}": {
      "get": {
        "tags": ["document"],
        "summary": "Get Document",
        "description": "Retrieve a document by ID",
        "operationId": "getDocument",
        "security": [
          {"ApiTokenAuth": []}
        ],
        "parameters": [
          {
            "name": "item_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Document ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Document retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Document"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Document not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": ["document"],
        "summary": "Update Document",
        "description": "Update an existing document",
        "operationId": "updateDocument",
        "security": [
          {"ApiTokenAuth": []}
        ],
        "parameters": [
          {
            "name": "item_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Document ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Document name"
                  },
                  "content": {
                    "type": "string",
                    "description": "Document content"
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Document metadata"
                  },
                  "status": {
                    "type": "string",
                    "enum": ["active", "archived", "draft"],
                    "description": "Document status"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Document"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Document not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": ["document"],
        "summary": "Delete Document",
        "description": "Delete a document by ID",
        "operationId": "deleteDocument",
        "security": [
          {"ApiTokenAuth": []}
        ],
        "parameters": [
          {
            "name": "item_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Document ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Document deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Document not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/system/client-health-check": {
      "get": {
        "tags": ["system"],
        "summary": "Client Health Check",
        "description": "Check client service health",
        "operationId": "clientHealthCheck",
        "responses": {
          "200": {
            "description": "Client service health status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthCheckResponse"
                }
              }
            }
          }
        }
      }
    }
  }
} 