reorder api endpoints (#2377)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,58 @@ from skyvern.schemas.browser_sessions import CreateBrowserSessionRequest
|
||||
from skyvern.webeye.schemas import BrowserSessionResponse
|
||||
|
||||
|
||||
@base_router.post(
|
||||
"/browser_sessions",
|
||||
response_model=BrowserSessionResponse,
|
||||
tags=["Browser Sessions"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "browser_session",
|
||||
"x-fern-sdk-method-name": "create_browser_session",
|
||||
},
|
||||
description="Create a new browser session",
|
||||
summary="Create a new browser session",
|
||||
responses={
|
||||
200: {"description": "Successfully created browser session"},
|
||||
403: {"description": "Unauthorized - Invalid or missing authentication"},
|
||||
},
|
||||
)
|
||||
async def create_browser_session(
|
||||
browser_session_request: CreateBrowserSessionRequest,
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> BrowserSessionResponse:
|
||||
browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(
|
||||
organization_id=current_org.organization_id,
|
||||
timeout_minutes=browser_session_request.timeout,
|
||||
)
|
||||
return BrowserSessionResponse.from_browser_session(browser_session)
|
||||
|
||||
|
||||
@base_router.post(
|
||||
"/browser_sessions/{browser_session_id}/close",
|
||||
tags=["Browser Sessions"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "browser_session",
|
||||
"x-fern-sdk-method-name": "close_browser_session",
|
||||
},
|
||||
description="Close a browser session",
|
||||
summary="Close a browser session",
|
||||
responses={
|
||||
200: {"description": "Successfully closed browser session"},
|
||||
403: {"description": "Unauthorized - Invalid or missing authentication"},
|
||||
},
|
||||
)
|
||||
async def close_browser_session(
|
||||
browser_session_id: str,
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> ORJSONResponse:
|
||||
await app.PERSISTENT_SESSIONS_MANAGER.close_session(current_org.organization_id, browser_session_id)
|
||||
return ORJSONResponse(
|
||||
content={"message": "Browser session closed"},
|
||||
status_code=200,
|
||||
media_type="application/json",
|
||||
)
|
||||
|
||||
|
||||
@base_router.get(
|
||||
"/browser_sessions/{browser_session_id}",
|
||||
response_model=BrowserSessionResponse,
|
||||
@@ -62,55 +114,3 @@ async def get_browser_sessions(
|
||||
analytics.capture("skyvern-oss-agent-browser-sessions-get")
|
||||
browser_sessions = await app.PERSISTENT_SESSIONS_MANAGER.get_active_sessions(current_org.organization_id)
|
||||
return [BrowserSessionResponse.from_browser_session(browser_session) for browser_session in browser_sessions]
|
||||
|
||||
|
||||
@base_router.post(
|
||||
"/browser_sessions",
|
||||
response_model=BrowserSessionResponse,
|
||||
tags=["Browser Sessions"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "browser_session",
|
||||
"x-fern-sdk-method-name": "create_browser_session",
|
||||
},
|
||||
description="Create a new browser session",
|
||||
summary="Create a new browser session",
|
||||
responses={
|
||||
200: {"description": "Successfully created browser session"},
|
||||
403: {"description": "Unauthorized - Invalid or missing authentication"},
|
||||
},
|
||||
)
|
||||
async def create_browser_session(
|
||||
browser_session_request: CreateBrowserSessionRequest,
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> BrowserSessionResponse:
|
||||
browser_session = await app.PERSISTENT_SESSIONS_MANAGER.create_session(
|
||||
organization_id=current_org.organization_id,
|
||||
timeout_minutes=browser_session_request.timeout,
|
||||
)
|
||||
return BrowserSessionResponse.from_browser_session(browser_session)
|
||||
|
||||
|
||||
@base_router.post(
|
||||
"/browser_sessions/{browser_session_id}/close",
|
||||
tags=["Browser Sessions"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "browser_session",
|
||||
"x-fern-sdk-method-name": "close_browser_session",
|
||||
},
|
||||
description="Close a browser session",
|
||||
summary="Close a browser session",
|
||||
responses={
|
||||
200: {"description": "Successfully closed browser session"},
|
||||
403: {"description": "Unauthorized - Invalid or missing authentication"},
|
||||
},
|
||||
)
|
||||
async def close_browser_session(
|
||||
browser_session_id: str,
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> ORJSONResponse:
|
||||
await app.PERSISTENT_SESSIONS_MANAGER.close_session(current_org.organization_id, browser_session_id)
|
||||
return ORJSONResponse(
|
||||
content={"message": "Browser session closed"},
|
||||
status_code=200,
|
||||
media_type="application/json",
|
||||
)
|
||||
|
||||
@@ -19,6 +19,12 @@ from skyvern.forge.sdk.services.bitwarden import BitwardenService
|
||||
LOG = structlog.get_logger()
|
||||
|
||||
|
||||
async def parse_totp_code(content: str) -> str | None:
|
||||
prompt = prompt_engine.load_prompt("parse-verification-code", content=content)
|
||||
code_resp = await app.SECONDARY_LLM_API_HANDLER(prompt=prompt, prompt_name="parse-verification-code")
|
||||
return code_resp.get("code", None)
|
||||
|
||||
|
||||
@legacy_base_router.post(
|
||||
"/totp",
|
||||
tags=["agent"],
|
||||
@@ -65,184 +71,6 @@ async def send_totp_code(
|
||||
)
|
||||
|
||||
|
||||
async def parse_totp_code(content: str) -> str | None:
|
||||
prompt = prompt_engine.load_prompt("parse-verification-code", content=content)
|
||||
code_resp = await app.SECONDARY_LLM_API_HANDLER(prompt=prompt, prompt_name="parse-verification-code")
|
||||
return code_resp.get("code", None)
|
||||
|
||||
|
||||
@legacy_base_router.get("/credentials")
|
||||
@legacy_base_router.get("/credentials/", include_in_schema=False)
|
||||
@base_router.get(
|
||||
"/credentials",
|
||||
response_model=list[CredentialResponse],
|
||||
summary="Get all credentials",
|
||||
description="Retrieves a paginated list of credentials for the current organization",
|
||||
tags=["Credentials"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "credentials",
|
||||
"x-fern-sdk-method-name": "get_credentials",
|
||||
},
|
||||
)
|
||||
async def get_credentials(
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
page: int = Query(
|
||||
1,
|
||||
ge=1,
|
||||
description="Page number for pagination",
|
||||
example=1,
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "page"},
|
||||
),
|
||||
page_size: int = Query(
|
||||
10,
|
||||
ge=1,
|
||||
description="Number of items per page",
|
||||
example=10,
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "page_size"},
|
||||
),
|
||||
) -> list[CredentialResponse]:
|
||||
organization_bitwarden_collection = await app.DATABASE.get_organization_bitwarden_collection(
|
||||
current_org.organization_id
|
||||
)
|
||||
if not organization_bitwarden_collection:
|
||||
return []
|
||||
|
||||
credentials = await app.DATABASE.get_credentials(current_org.organization_id, page=page, page_size=page_size)
|
||||
items = await BitwardenService.get_collection_items(organization_bitwarden_collection.collection_id)
|
||||
|
||||
response_items = []
|
||||
for credential in credentials:
|
||||
item = next((item for item in items if item.item_id == credential.item_id), None)
|
||||
if not item:
|
||||
continue
|
||||
if item.credential_type == CredentialType.PASSWORD:
|
||||
credential_response = PasswordCredentialResponse(username=item.credential.username)
|
||||
response_items.append(
|
||||
CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=item.credential_type,
|
||||
name=item.name,
|
||||
)
|
||||
)
|
||||
elif item.credential_type == CredentialType.CREDIT_CARD:
|
||||
credential_response = CreditCardCredentialResponse(
|
||||
last_four=item.credential.card_number[-4:],
|
||||
brand=item.credential.card_brand,
|
||||
)
|
||||
response_items.append(
|
||||
CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=item.credential_type,
|
||||
name=item.name,
|
||||
)
|
||||
)
|
||||
return response_items
|
||||
|
||||
|
||||
@legacy_base_router.get("/credentials/{credential_id}")
|
||||
@legacy_base_router.get("/credentials/{credential_id}/", include_in_schema=False)
|
||||
@base_router.get(
|
||||
"/credentials/{credential_id}",
|
||||
response_model=CredentialResponse,
|
||||
summary="Get credential by ID",
|
||||
description="Retrieves a specific credential by its ID",
|
||||
tags=["Credentials"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "credentials",
|
||||
"x-fern-sdk-method-name": "get_credential",
|
||||
},
|
||||
)
|
||||
async def get_credential(
|
||||
credential_id: str = Path(
|
||||
...,
|
||||
description="The unique identifier of the credential",
|
||||
example="cred_1234567890",
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "credential_id"},
|
||||
),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> CredentialResponse:
|
||||
organization_bitwarden_collection = await app.DATABASE.get_organization_bitwarden_collection(
|
||||
current_org.organization_id
|
||||
)
|
||||
if not organization_bitwarden_collection:
|
||||
raise HTTPException(status_code=404, detail="Credential account not found. It might have been deleted.")
|
||||
|
||||
credential = await app.DATABASE.get_credential(
|
||||
credential_id=credential_id, organization_id=current_org.organization_id
|
||||
)
|
||||
if not credential:
|
||||
raise HTTPException(status_code=404, detail="Credential not found")
|
||||
|
||||
credential_item = await BitwardenService.get_credential_item(credential.item_id)
|
||||
if not credential_item:
|
||||
raise HTTPException(status_code=404, detail="Credential not found")
|
||||
|
||||
if credential_item.credential_type == CredentialType.PASSWORD:
|
||||
credential_response = PasswordCredentialResponse(
|
||||
username=credential_item.credential.username,
|
||||
)
|
||||
return CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=credential_item.credential_type,
|
||||
name=credential_item.name,
|
||||
)
|
||||
if credential_item.credential_type == CredentialType.CREDIT_CARD:
|
||||
credential_response = CreditCardCredentialResponse(
|
||||
last_four=credential_item.credential.card_number[-4:],
|
||||
brand=credential_item.credential.card_brand,
|
||||
)
|
||||
return CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=credential_item.credential_type,
|
||||
name=credential_item.name,
|
||||
)
|
||||
raise HTTPException(status_code=400, detail="Invalid credential type")
|
||||
|
||||
|
||||
@legacy_base_router.delete("/credentials/{credential_id}")
|
||||
@legacy_base_router.delete("/credentials/{credential_id}/", include_in_schema=False)
|
||||
@base_router.post(
|
||||
"/credentials/{credential_id}/delete",
|
||||
status_code=204,
|
||||
summary="Delete credential",
|
||||
description="Deletes a specific credential by its ID",
|
||||
tags=["Credentials"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "credentials",
|
||||
"x-fern-sdk-method-name": "delete_credential",
|
||||
},
|
||||
)
|
||||
async def delete_credential(
|
||||
credential_id: str = Path(
|
||||
...,
|
||||
description="The unique identifier of the credential to delete",
|
||||
example="cred_1234567890",
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "credential_id"},
|
||||
),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> None:
|
||||
organization_bitwarden_collection = await app.DATABASE.get_organization_bitwarden_collection(
|
||||
current_org.organization_id
|
||||
)
|
||||
if not organization_bitwarden_collection:
|
||||
raise HTTPException(status_code=404, detail="Credential account not found. It might have been deleted.")
|
||||
|
||||
credential = await app.DATABASE.get_credential(
|
||||
credential_id=credential_id, organization_id=current_org.organization_id
|
||||
)
|
||||
if not credential:
|
||||
raise HTTPException(status_code=404, detail=f"Credential not found, credential_id={credential_id}")
|
||||
|
||||
await app.DATABASE.delete_credential(credential.credential_id, current_org.organization_id)
|
||||
await BitwardenService.delete_credential_item(credential.item_id)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@legacy_base_router.post("/credentials")
|
||||
@legacy_base_router.post("/credentials/", include_in_schema=False)
|
||||
@base_router.post(
|
||||
@@ -319,3 +147,175 @@ async def create_credential(
|
||||
credential_type=data.credential_type,
|
||||
name=data.name,
|
||||
)
|
||||
|
||||
|
||||
@legacy_base_router.delete("/credentials/{credential_id}")
|
||||
@legacy_base_router.delete("/credentials/{credential_id}/", include_in_schema=False)
|
||||
@base_router.post(
|
||||
"/credentials/{credential_id}/delete",
|
||||
status_code=204,
|
||||
summary="Delete credential",
|
||||
description="Deletes a specific credential by its ID",
|
||||
tags=["Credentials"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "credentials",
|
||||
"x-fern-sdk-method-name": "delete_credential",
|
||||
},
|
||||
)
|
||||
async def delete_credential(
|
||||
credential_id: str = Path(
|
||||
...,
|
||||
description="The unique identifier of the credential to delete",
|
||||
example="cred_1234567890",
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "credential_id"},
|
||||
),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> None:
|
||||
organization_bitwarden_collection = await app.DATABASE.get_organization_bitwarden_collection(
|
||||
current_org.organization_id
|
||||
)
|
||||
if not organization_bitwarden_collection:
|
||||
raise HTTPException(status_code=404, detail="Credential account not found. It might have been deleted.")
|
||||
|
||||
credential = await app.DATABASE.get_credential(
|
||||
credential_id=credential_id, organization_id=current_org.organization_id
|
||||
)
|
||||
if not credential:
|
||||
raise HTTPException(status_code=404, detail=f"Credential not found, credential_id={credential_id}")
|
||||
|
||||
await app.DATABASE.delete_credential(credential.credential_id, current_org.organization_id)
|
||||
await BitwardenService.delete_credential_item(credential.item_id)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@legacy_base_router.get("/credentials/{credential_id}")
|
||||
@legacy_base_router.get("/credentials/{credential_id}/", include_in_schema=False)
|
||||
@base_router.get(
|
||||
"/credentials/{credential_id}",
|
||||
response_model=CredentialResponse,
|
||||
summary="Get credential by ID",
|
||||
description="Retrieves a specific credential by its ID",
|
||||
tags=["Credentials"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "credentials",
|
||||
"x-fern-sdk-method-name": "get_credential",
|
||||
},
|
||||
)
|
||||
async def get_credential(
|
||||
credential_id: str = Path(
|
||||
...,
|
||||
description="The unique identifier of the credential",
|
||||
example="cred_1234567890",
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "credential_id"},
|
||||
),
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
) -> CredentialResponse:
|
||||
organization_bitwarden_collection = await app.DATABASE.get_organization_bitwarden_collection(
|
||||
current_org.organization_id
|
||||
)
|
||||
if not organization_bitwarden_collection:
|
||||
raise HTTPException(status_code=404, detail="Credential account not found. It might have been deleted.")
|
||||
|
||||
credential = await app.DATABASE.get_credential(
|
||||
credential_id=credential_id, organization_id=current_org.organization_id
|
||||
)
|
||||
if not credential:
|
||||
raise HTTPException(status_code=404, detail="Credential not found")
|
||||
|
||||
credential_item = await BitwardenService.get_credential_item(credential.item_id)
|
||||
if not credential_item:
|
||||
raise HTTPException(status_code=404, detail="Credential not found")
|
||||
|
||||
if credential_item.credential_type == CredentialType.PASSWORD:
|
||||
credential_response = PasswordCredentialResponse(
|
||||
username=credential_item.credential.username,
|
||||
)
|
||||
return CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=credential_item.credential_type,
|
||||
name=credential_item.name,
|
||||
)
|
||||
if credential_item.credential_type == CredentialType.CREDIT_CARD:
|
||||
credential_response = CreditCardCredentialResponse(
|
||||
last_four=credential_item.credential.card_number[-4:],
|
||||
brand=credential_item.credential.card_brand,
|
||||
)
|
||||
return CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=credential_item.credential_type,
|
||||
name=credential_item.name,
|
||||
)
|
||||
raise HTTPException(status_code=400, detail="Invalid credential type")
|
||||
|
||||
|
||||
@legacy_base_router.get("/credentials")
|
||||
@legacy_base_router.get("/credentials/", include_in_schema=False)
|
||||
@base_router.get(
|
||||
"/credentials",
|
||||
response_model=list[CredentialResponse],
|
||||
summary="Get all credentials",
|
||||
description="Retrieves a paginated list of credentials for the current organization",
|
||||
tags=["Credentials"],
|
||||
openapi_extra={
|
||||
"x-fern-sdk-group-name": "credentials",
|
||||
"x-fern-sdk-method-name": "get_credentials",
|
||||
},
|
||||
)
|
||||
async def get_credentials(
|
||||
current_org: Organization = Depends(org_auth_service.get_current_org),
|
||||
page: int = Query(
|
||||
1,
|
||||
ge=1,
|
||||
description="Page number for pagination",
|
||||
example=1,
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "page"},
|
||||
),
|
||||
page_size: int = Query(
|
||||
10,
|
||||
ge=1,
|
||||
description="Number of items per page",
|
||||
example=10,
|
||||
openapi_extra={"x-fern-sdk-parameter-name": "page_size"},
|
||||
),
|
||||
) -> list[CredentialResponse]:
|
||||
organization_bitwarden_collection = await app.DATABASE.get_organization_bitwarden_collection(
|
||||
current_org.organization_id
|
||||
)
|
||||
if not organization_bitwarden_collection:
|
||||
return []
|
||||
|
||||
credentials = await app.DATABASE.get_credentials(current_org.organization_id, page=page, page_size=page_size)
|
||||
items = await BitwardenService.get_collection_items(organization_bitwarden_collection.collection_id)
|
||||
|
||||
response_items = []
|
||||
for credential in credentials:
|
||||
item = next((item for item in items if item.item_id == credential.item_id), None)
|
||||
if not item:
|
||||
continue
|
||||
if item.credential_type == CredentialType.PASSWORD:
|
||||
credential_response = PasswordCredentialResponse(username=item.credential.username)
|
||||
response_items.append(
|
||||
CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=item.credential_type,
|
||||
name=item.name,
|
||||
)
|
||||
)
|
||||
elif item.credential_type == CredentialType.CREDIT_CARD:
|
||||
credential_response = CreditCardCredentialResponse(
|
||||
last_four=item.credential.card_number[-4:],
|
||||
brand=item.credential.card_brand,
|
||||
)
|
||||
response_items.append(
|
||||
CredentialResponse(
|
||||
credential=credential_response,
|
||||
credential_id=credential.credential_id,
|
||||
credential_type=item.credential_type,
|
||||
name=item.name,
|
||||
)
|
||||
)
|
||||
return response_items
|
||||
|
||||
Reference in New Issue
Block a user