Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions frontend/server/skills/devenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
_sandbox_model_config,
_validated_activities,
)
from veadk.cli.studio_sandbox_tools import studio_sandbox_agent_model_name
from veadk.cli.studio_model_catalog import provider_allows_model
from veadk.cli.studio_sandbox_tools import studio_sandbox_agent_model_name
from veadk.skills.skill import Skill
from veadk.utils.cloud_provider import cloud_provider_from_env
from veadk.utils.logger import get_logger
Expand Down Expand Up @@ -2659,6 +2659,7 @@ def publish(
"SKILL_PUBLISH_FAILED",
"发布 Skill 失败,无法确认本次发布结果,请刷新 Skill 中心确认。",
status_code=502,
original_error=error,
) from error
except Exception as error:
logger.error(
Expand All @@ -2672,6 +2673,7 @@ def publish(
"SKILL_PUBLISH_FAILED",
"发布 Skill 失败,无法确认本次发布结果,请刷新 Skill 中心确认。",
status_code=502,
original_error=error,
) from error

def _publish_once(
Expand Down Expand Up @@ -2762,13 +2764,17 @@ def report(phase: str, message: str) -> None:
),
)
from agentkit.toolkit.cli.cli_skills_workflow import (
_ensure_bucket_ready,
_make_content_hashed_zip_copy,
_tos_upload,
_wait_for_running_version,
)
from agentkit.toolkit.config import GlobalConfigManager
from agentkit.toolkit.volcengine.services.tos_service import TOSService

from .storage import (
ensure_skill_publish_bucket,
resolve_skill_publish_credentials,
resolve_skill_publish_storage,
upload_skill_archive,
)

config = GlobalConfigManager().load()
effective_region = (
Expand All @@ -2777,33 +2783,23 @@ def report(phase: str, message: str) -> None:
and source_region in supported_regions
else body.region or self._region
)
configured_bucket = (
os.getenv("VEADK_SKILL_CREATOR_TOS_BUCKET") or config.tos.bucket or ""
).strip()
bucket = configured_bucket or TOSService.generate_bucket_name()
prefix = (
os.getenv("VEADK_SKILL_CREATOR_TOS_PREFIX")
or config.tos.prefix
or "agentkit/skills"
).strip()
_ensure_bucket_ready(
bucket_name=bucket,
prefix=prefix,
storage = resolve_skill_publish_storage(
region=effective_region,
auto_bucket=not bool(configured_bucket),
assume_yes=True,
assume_no=False,
config_bucket=config.tos.bucket or "",
config_prefix=config.tos.prefix or "",
)
credentials = resolve_skill_publish_credentials(provider=storage.provider)
bucket = storage.bucket
report("preparing", "正在准备发布存储")
ensure_skill_publish_bucket(storage, credentials)
report("uploading", "正在上传 Skill 包")
with tempfile.TemporaryDirectory(prefix="veadk-skill-publish-") as directory:
archive_path = Path(directory) / f"{archive.name}.zip"
archive_path.write_bytes(archive.content)
hashed_path = _make_content_hashed_zip_copy(
str(archive_path), archive.name, directory
)
tos_url = _tos_upload(
hashed_path, bucket, prefix, effective_region, verify_bucket=False
)
tos_url = upload_skill_archive(hashed_path, storage, credentials)
report("registering", "正在写入 AgentKit Skill")
client = self._skills_client_factory(effective_region)
effective_project = (
Expand Down
98 changes: 67 additions & 31 deletions frontend/server/skills/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,64 +319,53 @@ def publish_archive(
) -> dict[str, object]:
from agentkit.sdk.skills import types as skills_types
from agentkit.toolkit.cli.cli_skills_workflow import (
_ensure_bucket_ready,
_make_content_hashed_zip_copy,
_tos_upload,
_wait_for_running_version,
)
from agentkit.toolkit.config import GlobalConfigManager
from agentkit.toolkit.volcengine.services.tos_service import TOSService

client = self._client_factory(region)
existing = client.list_skills(
skills_types.ListSkillsRequest(
PageNumber=1,
PageSize=50,
Filter=skills_types.SkillFilter(Name=archive.name),
ProjectName=project_name,
)
from .storage import (
ensure_skill_publish_bucket,
resolve_skill_publish_credentials,
resolve_skill_publish_storage,
upload_skill_archive,
)
if existing.items:

client = self._client_factory(region)
if self._space_has_skill_named(
client,
skills_types,
space_id=space_id,
name=archive.name,
):
raise SkillRepositoryError(
"SKILL_NAME_CONFLICT",
f"已存在同名 Skill“{archive.name}”,请重命名后上传,或使用优化功能覆盖。",
status_code=409,
)

config = GlobalConfigManager().load()
configured_bucket = (
os.getenv("VEADK_SKILL_CREATOR_TOS_BUCKET") or config.tos.bucket or ""
).strip()
bucket = configured_bucket or TOSService.generate_bucket_name()
prefix = (
os.getenv("VEADK_SKILL_CREATOR_TOS_PREFIX")
or config.tos.prefix
or "agentkit/skills"
).strip()
_ensure_bucket_ready(
bucket_name=bucket,
prefix=prefix,
storage = resolve_skill_publish_storage(
region=region,
auto_bucket=not bool(configured_bucket),
assume_yes=True,
assume_no=False,
config_bucket=config.tos.bucket or "",
config_prefix=config.tos.prefix or "",
)
credentials = resolve_skill_publish_credentials(provider=storage.provider)
ensure_skill_publish_bucket(storage, credentials)
with tempfile.TemporaryDirectory(prefix="veadk-skill-upload-") as directory:
archive_path = Path(directory) / f"{archive.name}.zip"
archive_path.write_bytes(archive.content)
hashed_path = _make_content_hashed_zip_copy(
str(archive_path), archive.name, directory
)
tos_url = _tos_upload(
hashed_path, bucket, prefix, region, verify_bucket=False
)
tos_url = upload_skill_archive(hashed_path, storage, credentials)
created = client.create_skill(
skills_types.CreateSkillRequest(
Name=archive.name,
Description=archive.description,
TosUrl=tos_url,
SkillSpaces=[space_id],
BucketName=bucket,
BucketName=storage.bucket,
ProjectName=project_name,
Tags=[skills_types.TagForSkill(Key="author", Value=author)],
)
Expand Down Expand Up @@ -409,6 +398,53 @@ def publish_archive(
"skillSpaceId": space_id,
}

@staticmethod
def _space_has_skill_named(
client: Any,
skills_types: Any,
*,
space_id: str,
name: str,
) -> bool:
page = 1
page_size = 100
expected = name.casefold()
while True:
response = client.list_skills_by_skill_space(
skills_types.ListSkillsBySkillSpaceRequest(
SkillSpaceId=space_id,
PageNumber=page,
PageSize=page_size,
)
)
items = list(getattr(response, "items", None) or [])
if any(
AgentKitSkillRepository._skill_relation_name(item).casefold()
== expected
for item in items
):
return True
total_count = getattr(response, "total_count", None)
if total_count is not None:
try:
if page * page_size >= int(total_count):
return False
except (TypeError, ValueError):
pass
if len(items) < page_size:
return False
page += 1

@staticmethod
def _skill_relation_name(value: Any) -> str:
return str(
getattr(value, "skill_name", None)
or getattr(value, "skillName", None)
or getattr(value, "name", None)
or getattr(value, "Name", None)
or ""
)

@staticmethod
def _space_item(value: Any, region: str) -> dict[str, object]:
tags = {
Expand Down
Loading
Loading