mirror of
https://github.com/langgenius/dify.git
synced 2026-10-16 15:35:32 +08:00
- services/workflow/dsl_import.py owns the openapi import rules (stale-draft refusal, graph-error refusal, editor defaults, kept secrets) and parses the YAML once - CheckAppMode raises AppModeMismatch (app_mode_mismatch); graph-app ops declare modes in their guards instead of checking in the handler - one branch_handles() shared by graph_check and the variable reference validator; fail-branch nodes now count as branch nodes in the check - graph_check reads each node once and fills defaults itself - guard factories: WORKSPACE_READ_GUARDS, workspace_write_guards, account_app_guards with roles/modes - next-page hints for runs and versions go through the shared hint helper - enterprise access-mode allowlist written out, sso_verified included
56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
"""Knowledge bases a workflow's knowledge-retrieval node can search."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from http import HTTPStatus
|
|
from typing import Any
|
|
|
|
from flask_restx import Resource
|
|
|
|
from controllers.openapi import openapi_ns
|
|
from controllers.openapi._contract import Example, Kind, endpoint
|
|
from controllers.openapi._models import (
|
|
KnowledgeBaseListQuery,
|
|
KnowledgeBaseListResponse,
|
|
KnowledgeBaseRow,
|
|
KnowledgeRetrievalFragment,
|
|
)
|
|
from controllers.openapi.auth.context import Context
|
|
from controllers.openapi.auth.requirements import WORKSPACE_READ_GUARDS
|
|
from extensions.ext_application_services import application_services
|
|
from services.knowledge.datasets.application import DatasetListFilter
|
|
|
|
|
|
def knowledge_base_row(record: Mapping[str, Any]) -> KnowledgeBaseRow:
|
|
return KnowledgeBaseRow(
|
|
id=record["id"],
|
|
name=record["name"],
|
|
description=record.get("description"),
|
|
provider=record["provider"],
|
|
indexing_technique=record.get("indexing_technique"),
|
|
document_count=record["document_count"],
|
|
usable=record.get("embedding_available") is not False,
|
|
node_data=KnowledgeRetrievalFragment(dataset_ids=[record["id"]]),
|
|
)
|
|
|
|
|
|
@openapi_ns.route("/workspaces/<string:workspace_id>/knowledge-bases")
|
|
class KnowledgeBasesApi(Resource):
|
|
@endpoint(
|
|
op="get.knowledge_base",
|
|
kind=Kind.LIST,
|
|
summary="Knowledge bases you can use, each with the knowledge-retrieval node data to paste",
|
|
examples=(Example(title="Find product docs", input={"query": "product"}),),
|
|
requirements=WORKSPACE_READ_GUARDS,
|
|
query=KnowledgeBaseListQuery,
|
|
returns=(HTTPStatus.OK, KnowledgeBaseListResponse, "Knowledge bases"),
|
|
)
|
|
def get(self, ctx: Context, workspace_id: str, *, query: KnowledgeBaseListQuery):
|
|
page = application_services().knowledge.datasets.list_datasets(
|
|
ctx.request_context, DatasetListFilter(page=query.page, limit=query.limit, keyword=query.query or None)
|
|
)
|
|
return KnowledgeBaseListResponse.build(
|
|
page=query.page, limit=query.limit, total=page["total"], items=[knowledge_base_row(r) for r in page["data"]]
|
|
)
|