Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(openapi): exclude directories from skill import file counts (#45393)

-LAN-0257f20b487d
diff --git a/api/controllers/openapi/skills.py b/api/controllers/openapi/skills.py
index b66aa2a07a2..20f04e60992 100644
--- a/api/controllers/openapi/skills.py
+++ b/api/controllers/openapi/skills.py
@@ -406,7 +406,10 @@ class SkillImportApi(Resource):
),
)
def post(self, ctx: RequestContext, workspace_id: str, *, body: SkillImportPayload):
- """Import never publishes. ``draft_hash`` is the draft's ``updated_at`` in whole seconds,
+ """Import an admitted editor's validated folder, returning a count of file entries only.
+
+ Creates a draft (201) or overwrites it (200), relaying archive and service errors.
+ Import never publishes. ``draft_hash`` is the draft's ``updated_at`` in whole seconds,
so an edit made in the same second as the export is not detected.
"""
content = _archive_of(body.files)
@@ -438,7 +441,7 @@ class SkillImportApi(Resource):
id=record["id"],
name=record["name"],
draft_hash=_draft_hash(record["updated_at"]),
- file_count=len(record["files"]),
+ file_count=sum(file["kind"] == "file" for file in record["files"]),
hints=[
Hint(
summary="Publish so agents use it",
diff --git a/api/openapi/markdown/openapi-openapi.md b/api/openapi/markdown/openapi-openapi.md
index b64969e6150..1763b05ec5d 100644
--- a/api/openapi/markdown/openapi-openapi.md
+++ b/api/openapi/markdown/openapi-openapi.md
@@ -2002,9 +2002,10 @@ Returns a depth- and page-size-bounded tree rooted at path, equivalent to difyct
| default | Error | **application/json**: [ErrorBody](#errorbody)<br> |
### [POST] /workspaces/{workspace_id}/skills/imports
-**Import never publishes**
+**Import an admitted editor's validated folder, returning a count of file entries only**
-``draft_hash`` is the draft's ``updated_at`` in whole seconds,
+Creates a draft (201) or overwrites it (200), relaying archive and service errors.
+Import never publishes. ``draft_hash`` is the draft's ``updated_at`` in whole seconds,
so an edit made in the same second as the export is not detected.
#### Parameters
diff --git a/api/tests/unit_tests/controllers/openapi/test_skills.py b/api/tests/unit_tests/controllers/openapi/test_skills.py
index ad99b17caf3..e72431c97de 100644
--- a/api/tests/unit_tests/controllers/openapi/test_skills.py
+++ b/api/tests/unit_tests/controllers/openapi/test_skills.py
@@ -103,7 +103,7 @@ def _skill(**extra: object) -> Record:
"tags": ["ops"],
"latest_published_version_id": "ver-2",
"updated_at": UPDATED_AT,
- "files": [{"path": "SKILL.md"}],
+ "files": [{"path": "SKILL.md", "kind": "file"}],
**extra,
}
@@ -308,7 +308,11 @@ def test_publish_passes_name_and_note(monkeypatch: pytest.MonkeyPatch) -> None:
def test_import_folder_creates_skill(monkeypatch: pytest.MonkeyPatch) -> None:
- seen = _record(monkeypatch, "import_skill", _skill(files=[{"path": "SKILL.md"}, {"path": "scripts/run.py"}]))
+ seen = _record(
+ monkeypatch,
+ "import_skill",
+ _skill(files=[{"path": "SKILL.md", "kind": "file"}, {"path": "scripts/run.py", "kind": "file"}]),
+ )
response, status = _import({"SKILL.md": b"---\nname: expense-sop\n---\n", "scripts/run.py": b"x"})
assert status == 201
[sent] = seen
@@ -332,6 +336,25 @@ def test_import_with_skill_id_overwrites(monkeypatch: pytest.MonkeyPatch) -> Non
assert response.hints[0].op == "publish.skill"
[email protected]("overwrite", [False, True], ids=["create", "overwrite"])
[email protected]("script_path", ["check.py", "scripts/check.py", "scripts/tools/check.py"])
+def test_import_file_count_excludes_directories(overwrite: bool, script_path: str) -> None:
+ """Importing a valid folder returns its file count, including when replacing a draft."""
+ files = {
+ "SKILL.md": b"---\nname: file-count-repro\ndescription: Count only files\n---\n# File count\n",
+ script_path: b"print('check')\n",
+ }
+ fields: dict[str, str] = {}
+ if overwrite:
+ initial, _ = _import({"SKILL.md": files["SKILL.md"]})
+ fields = {"skill_id": initial.id, "draft_hash": initial.draft_hash}
+
+ response, status = _import(files, **fields)
+
+ assert status == (200 if overwrite else 201)
+ assert response.file_count == 2
+
+
@pytest.mark.parametrize(
("fields", "loc"),
[
diff --git a/packages/contracts/generated/api/openapi/orpc.gen.ts b/packages/contracts/generated/api/openapi/orpc.gen.ts
index 18fa0582125..b41909ce02c 100644
--- a/packages/contracts/generated/api/openapi/orpc.gen.ts
+++ b/packages/contracts/generated/api/openapi/orpc.gen.ts
@@ -2328,20 +2328,21 @@ export const plugins2 = {
}
/**
- * Import never publishes
+ * Import an admitted editor's validated folder, returning a count of file entries only
*
- * ``draft_hash`` is the draft's ``updated_at`` in whole seconds,
+ * Creates a draft (201) or overwrites it (200), relaying archive and service errors.
+ * Import never publishes. ``draft_hash`` is the draft's ``updated_at`` in whole seconds,
* so an edit made in the same second as the export is not detected.
*/
export const post31 = oc
.route({
description:
- "``draft_hash`` is the draft's ``updated_at`` in whole seconds,\nso an edit made in the same second as the export is not detected.",
+ "Creates a draft (201) or overwrites it (200), relaying archive and service errors.\nImport never publishes. ``draft_hash`` is the draft's ``updated_at`` in whole seconds,\nso an edit made in the same second as the export is not detected.",
inputStructure: 'detailed',
method: 'POST',
operationId: 'postWorkspacesByWorkspaceIdSkillsImports',
path: '/workspaces/{workspace_id}/skills/imports',
- summary: 'Import never publishes',
+ summary: "Import an admitted editor's validated folder, returning a count of file entries only",
tags: ['openapi'],
})
.input(