mirror of
https://github.com/langgenius/dify.git
synced 2026-09-05 00:31:19 +08:00
Restore the current skill/agent stack from origin/main after the merge, then fix marketplace lint, formatting, and type mismatches so Style Check can pass.
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""Inner API for published workspace Skills.
|
|
|
|
These endpoints are called by trusted runtime services. They expose only
|
|
published Skill artifacts, never draft files or editable metadata.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
|
|
from flask import request, send_file
|
|
from flask_restx import Resource
|
|
from pydantic import BaseModel, ValidationError
|
|
from sqlalchemy.orm import Session
|
|
|
|
from controllers.common.session import with_session
|
|
from controllers.console.wraps import setup_required
|
|
from controllers.inner_api import inner_api_ns
|
|
from controllers.inner_api.wraps import plugin_inner_api_only
|
|
from services.skill_management_service import SkillManagementService, SkillManagementServiceError
|
|
|
|
|
|
class _SkillTargetQuery(BaseModel):
|
|
tenant_id: str
|
|
|
|
|
|
def _target_query_from_request() -> _SkillTargetQuery:
|
|
return _SkillTargetQuery.model_validate({"tenant_id": request.args.get("tenant_id")})
|
|
|
|
|
|
def _error_response(exc: SkillManagementServiceError) -> tuple[dict[str, str], int]:
|
|
return {"code": exc.code, "message": exc.message}, exc.status_code
|
|
|
|
|
|
@inner_api_ns.route("/skills/<string:skill_id>/pull")
|
|
class PublishedSkillPullApi(Resource):
|
|
@setup_required
|
|
@plugin_inner_api_only
|
|
@inner_api_ns.doc("published_skill_pull")
|
|
@with_session(write=False)
|
|
def get(self, session: Session, skill_id: str):
|
|
try:
|
|
query = _target_query_from_request()
|
|
result = SkillManagementService(session=session).pull_published_archive(
|
|
tenant_id=query.tenant_id, skill_id=skill_id
|
|
)
|
|
return send_file(
|
|
io.BytesIO(result.payload),
|
|
mimetype=result.mime_type,
|
|
as_attachment=True,
|
|
download_name=result.filename,
|
|
)
|
|
except ValidationError as exc:
|
|
return {"code": "invalid_request", "message": str(exc)}, 400
|
|
except SkillManagementServiceError as exc:
|
|
return _error_response(exc)
|
|
|
|
|
|
__all__ = ["PublishedSkillPullApi"]
|