Compare commits

...

2 Commits

Author SHA1 Message Date
pablonyx
39106e57b2 k 2025-02-21 11:19:13 -08:00
pablonyx
7e478f0e90 default on for non-ee 2025-02-21 09:10:41 -08:00
8 changed files with 134 additions and 83 deletions

View File

@@ -568,6 +568,7 @@ class GoogleDriveConnector(LoadConnector, PollConnector, SlimConnector):
callback: IndexingHeartbeatInterface | None = None,
) -> GenerateSlimDocumentOutput:
slim_batch = []
# ERROR here.
for file in self._fetch_drive_items(
is_slim=True,
start=start,

View File

@@ -14,6 +14,7 @@ from fastapi import Request
from fastapi import status
from fastapi.exceptions import RequestValidationError
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse
from httpx_oauth.clients.google import GoogleOAuth2
from sentry_sdk.integrations.fastapi import FastApiIntegration
@@ -28,8 +29,6 @@ from onyx.auth.users import auth_backend
from onyx.auth.users import create_onyx_oauth_router
from onyx.auth.users import fastapi_users
from onyx.configs.app_configs import APP_API_PREFIX
from onyx.configs.app_configs import APP_HOST
from onyx.configs.app_configs import APP_PORT
from onyx.configs.app_configs import AUTH_RATE_LIMITING_ENABLED
from onyx.configs.app_configs import AUTH_TYPE
from onyx.configs.app_configs import DISABLE_GENERATIVE_AI
@@ -105,7 +104,6 @@ from onyx.utils.telemetry import get_or_generate_uuid
from onyx.utils.telemetry import optional_telemetry
from onyx.utils.telemetry import RecordType
from onyx.utils.variable_functionality import fetch_versioned_implementation
from onyx.utils.variable_functionality import global_version
from onyx.utils.variable_functionality import set_is_ee_based_on_env_variable
from shared_configs.configs import CORS_ALLOWED_ORIGIN
from shared_configs.configs import MULTI_TENANT
@@ -263,7 +261,12 @@ def log_http_error(request: Request, exc: Exception) -> JSONResponse:
def get_application() -> FastAPI:
application = FastAPI(title="Onyx Backend", version=__version__, lifespan=lifespan)
application = FastAPI(
title="Onyx Backend",
version=__version__,
openapi_url="/openapi.json",
lifespan=lifespan,
)
if SENTRY_DSN:
sentry_sdk.init(
dsn=SENTRY_DSN,
@@ -397,24 +400,48 @@ def get_application() -> FastAPI:
if LOG_ENDPOINT_LATENCY:
add_latency_logging_middleware(application, logger)
# Ensure all routes have auth enabled or are explicitly marked as public
# # Ensure all routes have auth enabled or are explicitly marked as public
check_router_auth(application)
# @application.get("/")
# async def root():
# return {"message": "Hello World"}
def custom_openapi():
if application.openapi_schema:
return application.openapi_schema
openapi_schema = get_openapi(
title=application.title,
version=application.version,
description="Your API description here",
routes=application.routes,
)
# Force OpenAPI version 2.0 instead of 3.1.0
application.openapi_schema = openapi_schema
return application.openapi_schema
application.openapi = custom_openapi
return application
# NOTE: needs to be outside of the `if __name__ == "__main__"` block so that the
# app is exportable
set_is_ee_based_on_env_variable()
# app = get_application()
app = fetch_versioned_implementation(module="onyx.main", attribute="get_application")
# from fastapi import FastAPI
# app = FastAPI()
# @app.get("/")
# async def root():
# return {"message": "Hello World"}
# @app.get("/hi")
# async def docs():
# return {"message": "Hello World"}
if __name__ == "__main__":
logger.notice(
f"Starting Onyx Backend version {__version__} on http://{APP_HOST}:{str(APP_PORT)}/"
)
if global_version.is_ee_version():
logger.notice("Running Enterprise Edition")
uvicorn.run(app, host=APP_HOST, port=APP_PORT)
uvicorn.run(app, host="0.0.0.0", port=8000)

View File

@@ -1,61 +1,47 @@
from fastapi import APIRouter
from fastapi import Depends
from fastapi import HTTPException
from fastapi_users.exceptions import InvalidPasswordException
from sqlalchemy.orm import Session
from onyx.auth.users import current_admin_user
from onyx.auth.users import current_user
from onyx.auth.users import get_user_manager
from onyx.auth.users import User
from onyx.auth.users import UserManager
from onyx.db.engine import get_session
from onyx.db.users import get_user_by_email
from onyx.server.features.password.models import ChangePasswordRequest
from onyx.server.features.password.models import UserResetRequest
from onyx.server.features.password.models import UserResetResponse
router = APIRouter(prefix="/password")
@router.post("/change-password")
async def change_my_password(
form_data: ChangePasswordRequest,
user_manager: UserManager = Depends(get_user_manager),
current_user: User = Depends(current_user),
) -> None:
"""
Change the password for the current user.
"""
try:
await user_manager.change_password_if_old_matches(
user=current_user,
old_password=form_data.old_password,
new_password=form_data.new_password,
)
except InvalidPasswordException as e:
raise HTTPException(status_code=400, detail=str(e.reason))
except Exception as e:
raise HTTPException(
status_code=500, detail=f"An unexpected error occurred: {str(e)}"
)
# @router.post("/change-password")
# async def change_my_password(
# form_data: ChangePasswordRequest,
# user_manager: UserManager = Depends(get_user_manager),
# current_user: User = Depends(current_user),
# ) -> None:
# """
# Change the password for the current user.
# """
# try:
# await user_manager.change_password_if_old_matches(
# user=current_user,
# old_password=form_data.old_password,
# new_password=form_data.new_password,
# )
# except InvalidPasswordException as e:
# raise HTTPException(status_code=400, detail=str(e.reason))
# except Exception as e:
# raise HTTPException(
# status_code=500, detail=f"An unexpected error occurred: {str(e)}"
# )
@router.post("/reset_password")
async def admin_reset_user_password(
user_reset_request: UserResetRequest,
user_manager: UserManager = Depends(get_user_manager),
db_session: Session = Depends(get_session),
_: User = Depends(current_admin_user),
) -> UserResetResponse:
"""
Reset the password for a user (admin only).
"""
user = get_user_by_email(user_reset_request.user_email, db_session)
if not user:
raise HTTPException(status_code=404, detail="User not found")
new_password = await user_manager.reset_password_as_admin(user.id)
return UserResetResponse(
user_id=str(user.id),
new_password=new_password,
)
# @router.post("/reset_password")
# async def admin_reset_user_password(
# user_reset_request: UserResetRequest,
# user_manager: UserManager = Depends(get_user_manager),
# db_session: Session = Depends(get_session),
# _: User = Depends(current_admin_user),
# ) -> UserResetResponse:
# """
# Reset the password for a user (admin only).
# """
# user = get_user_by_email(user_reset_request.user_email, db_session)
# if not user:
# raise HTTPException(status_code=404, detail="User not found")
# new_password = await user_manager.reset_password_as_admin(user.id)
# return UserResetResponse(
# user_id=str(user.id),
# new_password=new_password,
# )

View File

@@ -68,6 +68,22 @@ const nextConfig = {
},
];
},
async rewrites() {
return [
{
source: "/api/docs/:path*", // catch /api/docs and /api/docs/...
destination: "http://localhost:8000/docs/:path*",
},
{
source: "/api/docs", // if you also need the exact /api/docs
destination: "http://localhost:8000/docs",
},
{
source: "/openapi.json",
destination: "http://localhost:8000/openapi.json",
},
];
},
};
// Sentry configuration for error monitoring:

17
web/package-lock.json generated
View File

@@ -75,6 +75,7 @@
"semver": "^7.5.4",
"sharp": "^0.33.5",
"stripe": "^17.0.0",
"swagger-ui-dist": "^5.19.0",
"swr": "^2.1.5",
"tailwind-merge": "^2.5.4",
"tailwindcss": "^3.3.1",
@@ -6180,6 +6181,13 @@
"integrity": "sha512-qC/xYId4NMebE6w/V33Fh9gWxLgURiNYgVNObbJl2LZv0GUUItCcCqC5axQSwRaAgaxl2mELq1rMzlswaQ0Zxg==",
"dev": true
},
"node_modules/@scarf/scarf": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.4.0.tgz",
"integrity": "sha512-xxeapPiUXdZAE3che6f3xogoJPeZgig6omHEy1rIY5WVsB3H2BHNnZH+gHG6x91SCWyQCzWGsuL2Hh3ClO5/qQ==",
"hasInstallScript": true,
"license": "Apache-2.0"
},
"node_modules/@segment/analytics-core": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/@segment/analytics-core/-/analytics-core-1.4.1.tgz",
@@ -20122,6 +20130,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/swagger-ui-dist": {
"version": "5.19.0",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.19.0.tgz",
"integrity": "sha512-bSVZeYaqanMFeW5ZY3+EejFbsjkjazYxm1I7Lz3xayYz5XU3m2aUzvuPC0jI95WCQdduszHYV3ER4buQoy8DXA==",
"license": "Apache-2.0",
"dependencies": {
"@scarf/scarf": "=1.4.0"
}
},
"node_modules/swr": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz",

View File

@@ -78,6 +78,7 @@
"semver": "^7.5.4",
"sharp": "^0.33.5",
"stripe": "^17.0.0",
"swagger-ui-dist": "^5.19.0",
"swr": "^2.1.5",
"tailwind-merge": "^2.5.4",
"tailwindcss": "^3.3.1",

View File

@@ -61,20 +61,20 @@ export async function OPTIONS(
}
async function handleRequest(request: NextRequest, path: string[]) {
if (
process.env.NODE_ENV !== "development" &&
// NOTE: Set this environment variable to 'true' for preview environments
// Where you want finer-grained control over API access
process.env.OVERRIDE_API_PRODUCTION !== "true"
) {
return NextResponse.json(
{
message:
"This API is only available in development mode. In production, something else (e.g. nginx) should handle this.",
},
{ status: 404 }
);
}
// if (
// process.env.NODE_ENV !== "development" &&
// // NOTE: Set this environment variable to 'true' for preview environments
// // Where you want finer-grained control over API access
// process.env.OVERRIDE_API_PRODUCTION !== "true"
// ) {
// return NextResponse.json(
// {
// message:
// "This API is only available in development mode. In production, something else (e.g. nginx) should handle this.",
// },
// { status: 404 }
// );
// }
try {
const backendUrl = new URL(`${INTERNAL_URL}/${path.join("/")}`);
@@ -87,14 +87,17 @@ async function handleRequest(request: NextRequest, path: string[]) {
backendUrl.searchParams.append(key, value);
});
const response = await fetch(backendUrl, {
const fetchDetails = {
method: request.method,
headers: request.headers,
body: request.body,
signal: request.signal,
// @ts-ignore
duplex: "half",
});
};
console.log(fetchDetails);
console.log("BACKEND URL: ", backendUrl);
const response = await fetch(backendUrl, fetchDetails);
// Check if the response is a stream
if (

View File

@@ -95,7 +95,7 @@ export async function fetchSettingsSS(): Promise<CombinedSettings | null> {
}
}
if (enterpriseSettings && settings.pro_search_enabled == null) {
if (settings.pro_search_enabled == null) {
settings.pro_search_enabled = true;
}