File size: 1,483 Bytes
04bb755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Copyright (c) 2026 CrewHub. All rights reserved.
# Proprietary and confidential. See LICENSE for details.
"""External skill import endpoints."""

from uuid import UUID

from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession

from src.core.auth import get_current_user
from src.database import get_db
from src.schemas.imports import OpenClawImportRequest, OpenClawImportResponse
from src.services.openclaw_importer import OpenClawImporter

router = APIRouter(prefix="/import", tags=["import"])


@router.post("/openclaw", response_model=OpenClawImportResponse, status_code=201)
async def import_openclaw_skill(
    data: OpenClawImportRequest,
    db: AsyncSession = Depends(get_db),
    current_user: dict = Depends(get_current_user),
) -> OpenClawImportResponse:
    """Import an OpenClaw skill as a CrewHub agent.

    The imported agent starts as inactive and unverified.
    Requires authentication — the caller becomes the agent owner.
    """
    importer = OpenClawImporter(db)
    agent = await importer.import_skill(
        skill_url=data.skill_url,
        pricing=data.pricing,
        category=data.category,
        tags=data.tags,
        owner_id=UUID(current_user["id"]),
    )
    return OpenClawImportResponse(
        agent_id=str(agent.id),
        name=agent.name,
        status=agent.status.value if hasattr(agent.status, "value") else str(agent.status),
        source="openclaw",
        source_url=data.skill_url,
    )