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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
add yuqye(https://www.yuque.com)tools (#8960)
Oliver Lee424a7da470b1
diff --git a/api/core/tools/provider/_position.yaml b/api/core/tools/provider/_position.yamlindex 6bab9a09d88..336588e3e2c 100644--- a/api/core/tools/provider/_position.yaml+++ b/api/core/tools/provider/_position.yaml@@ -61,6 +61,7 @@- vectorizer- qrcode- tianditu+- aliyuque- google_translate- hap- json_processdiff --git a/api/core/tools/provider/builtin/aliyuque/_assets/icon.svg b/api/core/tools/provider/builtin/aliyuque/_assets/icon.svgnew file mode 100644index 00000000000..82b23ebbc66--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/_assets/icon.svg@@ -0,0 +1,32 @@+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="26" height="26" viewBox="0 0 26 26" version="1.1">+ <title>绿 lgo</title>+ <defs>+ <linearGradient x1="82.745802%" y1="0%" x2="20.2771185%" y2="79.4063539%" id="linearGradient-1">+ <stop stop-color="#7BD26A" offset="0%"/>+ <stop stop-color="#07B26A" offset="100%"/>+ </linearGradient>+ <rect id="path-2" x="0" y="0" width="26" height="26" rx="6.24"/>+ <radialGradient cx="60.2119822%" cy="64.1956281%" fx="60.2119822%" fy="64.1956281%" r="51.002811%" gradientTransform="translate(0.602120,0.641956),scale(0.852482,1.000000),rotate(-68.414776),translate(-0.602120,-0.641956)" id="radialGradient-4">+ <stop stop-color="#57CB86" offset="0%"/>+ <stop stop-color="#FFFFFF" stop-opacity="0.8" offset="100%"/>+ </radialGradient>+ <path d="M9.85484814,0 L9.92760405,0 L9.99188961,0 L9.99188961,0 L10.0574235,0.000331576155 L10.0574235,0.000331576155 L10.1241951,0.000681979331 L10.1241951,0.000681979331 L10.1921938,0.00116250403 L10.1921938,0.00116250403 L10.2614091,0.00177843386 L10.2614091,0.00177843386 L10.3318302,0.0025350524 L10.3318302,0.0025350524 L10.4034465,0.00343764326 L10.4034465,0.00343764326 L10.4518496,0.00412307541 L10.4518496,0.00412307541 L10.500776,0.00487729792 L10.500776,0.00487729792 L10.57514,0.00614103816 L10.57514,0.00614103816 L10.650664,0.0075683627 L10.650664,0.0075683627 L10.7273371,0.00916455514 L10.7273371,0.00916455514 L10.7790859,0.0103251081 L10.7790859,0.0103251081 L10.8576509,0.0122144884 L10.8576509,0.0122144884 L10.9373369,0.0142868261 L10.9373369,0.0142868261 L11.0181333,0.0165474049 L11.0181333,0.0165474049 L11.0726092,0.018161645 L11.0726092,0.018161645 L11.1552325,0.0207477003 L11.1552325,0.0207477003 L11.2389379,0.0235360862 L11.2389379,0.0235360862 L11.2953374,0.0255100253 L11.2953374,0.0255100253 L11.35221,0.0275778029 L11.35221,0.0275778029 L11.4095524,0.0297409845 L11.4095524,0.0297409845 L11.4673616,0.0320011357 L11.4673616,0.0320011357 L11.5256345,0.0343598219 L11.5256345,0.0343598219 L11.5843677,0.0368186086 L11.5843677,0.0368186086 L11.6733242,0.0406979018 L11.6733242,0.0406979018 L11.7331948,0.0434137891 L11.7331948,0.0434137891 L11.8238426,0.0476860714 L11.8238426,0.0476860714 L11.8848311,0.0506688435 L11.8848311,0.0506688435 L11.9462611,0.0537611093 L11.9462611,0.0537611093 L12.0392272,0.0586082331 L12.0392272,0.0586082331 L12.1017475,0.061981082 L12.1017475,0.061981082 L12.1646984,0.0654689039 L12.1646984,0.0654689039 L12.2280767,0.0690732641 L12.2280767,0.0690732641 L12.2918792,0.0727957283 L12.2918792,0.0727957283 L12.356103,0.0766378619 L12.356103,0.0766378619 L12.4207447,0.0806012304 L12.4207447,0.0806012304 L12.4858014,0.0846873994 L12.4858014,0.0846873994 L12.5512697,0.0888979343 L12.5512697,0.0888979343 L12.6171466,0.0932344007 L12.6171466,0.0932344007 L12.6834289,0.0976983641 L12.6834289,0.0976983641 C15.0633644,0.259796072 15.6936665,1.96792848 15.760735,2.17232082 L15.7642625,2.18329556 L15.7642625,2.18329556 L15.7670022,2.19228685 L15.7670022,2.19228685 L16.8001701,2.24835336 L16.8001701,2.24835336 C16.8553047,2.24835336 16.9,2.29289806 16.9,2.34784674 C16.9,2.38723092 16.877039,2.42127034 16.8437303,2.43739409 C15.7832184,3.0093152 15.4592286,4.1714334 15.649705,4.92842573 C15.7110936,5.17239652 15.8064718,5.38211813 15.9126536,5.60378714 L15.9797416,5.74331821 C16.225531,6.25567571 16.5014964,6.87607121 16.546561,8.1246874 C16.6474375,10.9196977 14.182272,13.4317662 11.2653296,13.4317662 L11.2334107,13.4317788 L11.2334107,13.4317788 L11.1652829,13.4318803 L11.1652829,13.4318803 L11.0523665,13.4322227 L11.0523665,13.4322227 L10.9699392,13.4325778 L10.9699392,13.4325778 L10.8355736,13.4333006 L10.8355736,13.4333006 L10.7388467,13.4339094 L10.7388467,13.4339094 L10.6364,13.4346195 L10.6364,13.4346195 L10.4720054,13.435875 L10.4720054,13.435875 L10.2947412,13.4373588 L10.2947412,13.4373588 L10.1046074,13.4390708 L10.1046074,13.4390708 L9.83107637,13.4417086 L9.83107637,13.4417086 L9.61091359,13.4439533 L9.61091359,13.4439533 L9.21537657,13.4482017 L9.21537657,13.4482017 L8.78409074,13.4530841 L8.78409074,13.4530841 L8.31705609,13.4586007 L8.31705609,13.4586007 L8.01967588,13.4622149 L8.01967588,13.4622149 L7.60314959,13.4673891 L7.60314959,13.4673891 L7.0503178,13.4744274 L7.0503178,13.4744274 L6.46173719,13.4820999 L6.46173719,13.4820999 L5.96513357,13.4886944 L5.96513357,13.4886944 L5.17732955,13.499347 L5.17732955,13.499347 L4.62352783,13.506956 L4.62352783,13.506956 L3.59932164,13.5212483 L3.59932164,13.5212483 L2.50504778,13.5367834 L2.50504778,13.5367834 L1.51133062,13.5510884 L1.51133062,13.5510884 L0.995167673,13.5585833 L7.23297964,6.48906312 L7.28950732,6.42484653 L7.28950732,6.42484653 L7.34588164,6.36094751 L7.34588164,6.36094751 L7.40208979,6.29734935 L7.40208979,6.29734935 L7.68018955,5.98328638 L7.68018955,5.98328638 L7.7351316,5.92114234 L7.7351316,5.92114234 L7.78981779,5.85918213 L7.78981779,5.85918213 L7.84423531,5.79738905 C7.85328179,5.7871032 7.86231655,5.77682362 7.87133931,5.76654996 L7.92532978,5.70497623 C7.93430349,5.69472485 7.94326466,5.68447869 7.95221305,5.67423741 L8.00574764,5.6128454 L8.00574764,5.6128454 L8.05896231,5.55155366 C8.67788397,4.83700317 9.22886996,4.13950919 9.62035594,3.33961638 C10.054917,2.11638587 9.6125332,1.20361183 9.16095237,0.650548948 C9.12608593,0.607847103 9.09116466,0.567289621 9.05658796,0.528899171 C8.90264637,0.332507516 9.00746099,0.00530922209 9.30061481,0.00530922209 C9.32450177,0.00530922209 9.34887407,0.00494128632 9.37372943,0.00446664733 L9.43046818,0.00332885546 C9.4432575,0.00308498022 9.45616716,0.00286341029 9.46919687,0.00269679974 L9.52332357,0.00205054544 L9.52332357,0.00205054544 L9.57878004,0.00148243835 L9.57878004,0.00148243835 L9.61648455,0.00114971997 L9.61648455,0.00114971997 L9.7132903,0.000490388031 L9.7132903,0.000490388031 L9.79332616,0.000153206697 L9.79332616,0.000153206697 L9.85484814,0 L9.85484814,0 Z" id="path-5"/>+ </defs>+ <g id="绿-lgo" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">+ <g id="5.品牌LOGO/APP应用图形/外网">+ <mask id="mask-3" fill="white">+ <use xlink:href="#path-2"/>+ </mask>+ <use id="蒙版" fill="url(#linearGradient-1)" xlink:href="#path-2"/>+ <g id="编组" mask="url(#mask-3)">+ <g transform="translate(3.770000, 5.460000)">+ <g id="路径" fill="none">+ <use fill="#E5FBEF" xlink:href="#path-5"/>+ <use fill-opacity="0.3" fill="url(#radialGradient-4)" xlink:href="#path-5"/>+ </g>+ <path d="M7.23297964,6.48906312 C4.53317815,9.51701725 1.31997191,13.2011384 0.100287229,14.5850572 C-0.134670504,14.8516526 0.0930577608,15.1033984 0.2750595,15.1345827 C9.37469167,16.6937185 12.2638818,12.4199854 12.9074496,10.466332 C13.7879752,7.79335527 12.5438372,6.48906312 11.8397426,6.06373002 C9.45219821,4.62145002 7.68074862,5.98686918 7.23297964,6.48906312 Z" id="Fill-12-Copy" fill="#FAFFFC"/>+ </g>+ </g>+ </g>+ </g>+</svg>\ No newline at end of filediff --git a/api/core/tools/provider/builtin/aliyuque/aliyuque.py b/api/core/tools/provider/builtin/aliyuque/aliyuque.pynew file mode 100644index 00000000000..56eac1a4b57--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/aliyuque.py@@ -0,0 +1,19 @@+from core.tools.errors import ToolProviderCredentialValidationError+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController+++class AliYuqueProvider(BuiltinToolProviderController):+ def _validate_credentials(self, credentials: dict) -> None:+ token = credentials.get("token")+ if not token:+ raise ToolProviderCredentialValidationError("token is required")++ try:+ resp = AliYuqueTool.auth(token)+ if resp and resp.get("data", {}).get("id"):+ return++ raise ToolProviderCredentialValidationError(resp)+ except Exception as e:+ raise ToolProviderCredentialValidationError(str(e))diff --git a/api/core/tools/provider/builtin/aliyuque/aliyuque.yaml b/api/core/tools/provider/builtin/aliyuque/aliyuque.yamlnew file mode 100644index 00000000000..73d39aa96cf--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/aliyuque.yaml@@ -0,0 +1,29 @@+identity:+ author: 佐井+ name: aliyuque+ label:+ en_US: yuque+ zh_Hans: 语雀+ pt_BR: yuque+ description:+ en_US: Yuque, https://www.yuque.com.+ zh_Hans: 语雀,https://www.yuque.com。+ pt_BR: Yuque, https://www.yuque.com.+ icon: icon.svg+ tags:+ - productivity+ - search+credentials_for_provider:+ token:+ type: secret-input+ required: true+ label:+ en_US: Yuque Team Token+ zh_Hans: 语雀团队Token+ placeholder:+ en_US: Please input your Yuque team token+ zh_Hans: 请输入你的语雀团队Token+ help:+ en_US: Get Alibaba Yuque team token+ zh_Hans: 先获取语雀团队Token+ url: https://www.yuque.com/settings/tokensdiff --git a/api/core/tools/provider/builtin/aliyuque/tools/base.py b/api/core/tools/provider/builtin/aliyuque/tools/base.pynew file mode 100644index 00000000000..fb7e219bffe--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/base.py@@ -0,0 +1,50 @@+"""+语雀客户端+"""++__author__ = "佐井"+__created__ = "2024-06-01 09:45:20"++from typing import Any++import requests+++class AliYuqueTool:+ # yuque service url+ server_url = "https://www.yuque.com"++ @staticmethod+ def auth(token):+ session = requests.Session()+ session.headers.update({"Accept": "application/json", "X-Auth-Token": token})+ login = session.request("GET", AliYuqueTool.server_url + "/api/v2/user")+ login.raise_for_status()+ resp = login.json()+ return resp++ def request(self, method: str, token, tool_parameters: dict[str, Any], path: str) -> str:+ if not token:+ raise Exception("token is required")+ session = requests.Session()+ session.headers.update({"accept": "application/json", "X-Auth-Token": token})+ new_params = {**tool_parameters}+ # 找出需要替换的变量+ replacements = {k: v for k, v in new_params.items() if f"{{{k}}}" in path}++ # 替换 path 中的变量+ for key, value in replacements.items():+ path = path.replace(f"{{{key}}}", str(value))+ del new_params[key] # 从 kwargs 中删除已经替换的变量+ # 请求接口+ if method.upper() in {"POST", "PUT"}:+ session.headers.update(+ {+ "Content-Type": "application/json",+ }+ )+ response = session.request(method.upper(), self.server_url + path, json=new_params)+ else:+ response = session.request(method, self.server_url + path, params=new_params)+ response.raise_for_status()+ return response.textdiff --git a/api/core/tools/provider/builtin/aliyuque/tools/create_document.py b/api/core/tools/provider/builtin/aliyuque/tools/create_document.pynew file mode 100644index 00000000000..feadc292584--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/create_document.py@@ -0,0 +1,22 @@+"""+创建文档+"""++__author__ = "佐井"+__created__ = "2024-06-01 10:45:20"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class AliYuqueCreateDocumentTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ return self.create_text_message(self.request("POST", token, tool_parameters, "/api/v2/repos/{book_id}/docs"))diff --git a/api/core/tools/provider/builtin/aliyuque/tools/create_document.yaml b/api/core/tools/provider/builtin/aliyuque/tools/create_document.yamlnew file mode 100644index 00000000000..b9d1c60327f--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/create_document.yaml@@ -0,0 +1,99 @@+identity:+ name: aliyuque_create_document+ author: 佐井+ label:+ en_US: Create Document+ zh_Hans: 创建文档+ icon: icon.svg+description:+ human:+ en_US: Creates a new document within a knowledge base without automatic addition to the table of contents. Requires a subsequent call to the "knowledge base directory update API". Supports setting visibility, format, and content. # 接口英文描述+ zh_Hans: 在知识库中创建新文档,但不会自动加入目录,需额外调用“知识库目录更新接口”。允许设置公开性、格式及正文内容。+ llm: Creates docs in a KB.++parameters:+ - name: book_id+ type: number+ required: true+ form: llm+ label:+ en_US: Knowledge Base ID+ zh_Hans: 知识库ID+ human_description:+ en_US: The unique identifier of the knowledge base where the document will be created.+ zh_Hans: 文档将被创建的知识库的唯一标识。+ llm_description: ID of the target knowledge base.++ - name: title+ type: string+ required: false+ form: llm+ label:+ en_US: Title+ zh_Hans: 标题+ human_description:+ en_US: The title of the document, defaults to 'Untitled' if not provided.+ zh_Hans: 文档标题,默认为'无标题'如未提供。+ llm_description: Title of the document, defaults to 'Untitled'.++ - name: public+ type: select+ required: false+ form: llm+ options:+ - value: 0+ label:+ en_US: Private+ zh_Hans: 私密+ - value: 1+ label:+ en_US: Public+ zh_Hans: 公开+ - value: 2+ label:+ en_US: Enterprise-only+ zh_Hans: 企业内公开+ label:+ en_US: Visibility+ zh_Hans: 公开性+ human_description:+ en_US: Document visibility (0 Private, 1 Public, 2 Enterprise-only).+ zh_Hans: 文档可见性(0 私密, 1 公开, 2 企业内公开)。+ llm_description: Doc visibility options, 0-private, 1-public, 2-enterprise.++ - name: format+ type: select+ required: false+ form: llm+ options:+ - value: markdown+ label:+ en_US: markdown+ zh_Hans: markdown+ - value: html+ label:+ en_US: html+ zh_Hans: html+ - value: lake+ label:+ en_US: lake+ zh_Hans: lake+ label:+ en_US: Content Format+ zh_Hans: 内容格式+ human_description:+ en_US: Format of the document content (markdown, HTML, Lake).+ zh_Hans: 文档内容格式(markdown, HTML, Lake)。+ llm_description: Content format choices, markdown, HTML, Lake.++ - name: body+ type: string+ required: true+ form: llm+ label:+ en_US: Body Content+ zh_Hans: 正文内容+ human_description:+ en_US: The actual content of the document.+ zh_Hans: 文档的实际内容。+ llm_description: Content of the document.diff --git a/api/core/tools/provider/builtin/aliyuque/tools/delete_document.py b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.pynew file mode 100644index 00000000000..74c731a944c--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.py@@ -0,0 +1,25 @@+#!/usr/bin/env python3+"""+删除文档+"""++__author__ = "佐井"+__created__ = "2024-09-17 22:04"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class AliYuqueDeleteDocumentTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ return self.create_text_message(+ self.request("DELETE", token, tool_parameters, "/api/v2/repos/{book_id}/docs/{id}")+ )diff --git a/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yaml b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yamlnew file mode 100644index 00000000000..87372c53502--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/delete_document.yaml@@ -0,0 +1,37 @@+identity:+ name: aliyuque_delete_document+ author: 佐井+ label:+ en_US: Delete Document+ zh_Hans: 删除文档+ icon: icon.svg+description:+ human:+ en_US: Delete Document+ zh_Hans: 根据id删除文档+ llm: Delete document.++parameters:+ - name: book_id+ type: number+ required: true+ form: llm+ label:+ en_US: Knowledge Base ID+ zh_Hans: 知识库ID+ human_description:+ en_US: The unique identifier of the knowledge base where the document will be created.+ zh_Hans: 文档将被创建的知识库的唯一标识。+ llm_description: ID of the target knowledge base.++ - name: id+ type: string+ required: true+ form: llm+ label:+ en_US: Document ID or Path+ zh_Hans: 文档 ID or 路径+ human_description:+ en_US: Document ID or path.+ zh_Hans: 文档 ID or 路径。+ llm_description: Document ID or path.diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.pynew file mode 100644index 00000000000..02bf603a24b--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.py@@ -0,0 +1,24 @@+"""+获取知识库首页+"""++__author__ = "佐井"+__created__ = "2024-06-01 22:57:14"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class AliYuqueDescribeBookIndexPageTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ return self.create_text_message(+ self.request("GET", token, tool_parameters, "/api/v2/repos/{group_login}/{book_slug}/index_page")+ )diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.yaml b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.yamlnew file mode 100644index 00000000000..5e490725d18--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_index_page.yaml@@ -0,0 +1,38 @@+identity:+ name: aliyuque_describe_book_index_page+ author: 佐井+ label:+ en_US: Get Repo Index Page+ zh_Hans: 获取知识库首页+ icon: icon.svg++description:+ human:+ en_US: Retrieves the homepage of a knowledge base within a group, supporting both book ID and group login with book slug access.+ zh_Hans: 获取团队中知识库的首页信息,可通过书籍ID或团队登录名与书籍路径访问。+ llm: Fetches the knowledge base homepage using group and book identifiers with support for alternate access paths.++parameters:+ - name: group_login+ type: string+ required: true+ form: llm+ label:+ en_US: Group Login+ zh_Hans: 团队登录名+ human_description:+ en_US: The login name of the group that owns the knowledge base.+ zh_Hans: 拥有该知识库的团队登录名。+ llm_description: Team login identifier for the knowledge base owner.++ - name: book_slug+ type: string+ required: true+ form: llm+ label:+ en_US: Book Slug+ zh_Hans: 知识库路径+ human_description:+ en_US: The unique slug representing the path of the knowledge base.+ zh_Hans: 知识库的唯一路径标识。+ llm_description: Unique path identifier for the knowledge base.diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.pynew file mode 100644index 00000000000..fcfe449c6df--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.py@@ -0,0 +1,23 @@+#!/usr/bin/env python3+"""+获取知识库目录+"""++__author__ = "佐井"+__created__ = "2024-09-17 15:17:11"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class YuqueDescribeBookTableOfContentsTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> (Union)[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ return self.create_text_message(self.request("GET", token, tool_parameters, "/api/v2/repos/{book_id}/toc"))diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yaml b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yamlnew file mode 100644index 00000000000..0c2bd221323--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_book_table_of_contents.yaml@@ -0,0 +1,25 @@+identity:+ name: aliyuque_describe_book_table_of_contents+ author: 佐井+ label:+ en_US: Get Book's Table of Contents+ zh_Hans: 获取知识库的目录+ icon: icon.svg+description:+ human:+ en_US: Get Book's Table of Contents.+ zh_Hans: 获取知识库的目录。+ llm: Get Book's Table of Contents.++parameters:+ - name: book_id+ type: number+ required: true+ form: llm+ label:+ en_US: Book ID+ zh_Hans: 知识库 ID+ human_description:+ en_US: Book ID.+ zh_Hans: 知识库 ID。+ llm_description: Book ID.diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.pynew file mode 100644index 00000000000..1e70593879e--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.py@@ -0,0 +1,61 @@+"""+获取文档+"""++__author__ = "佐井"+__created__ = "2024-06-02 07:11:45"++import json+from typing import Any, Union+from urllib.parse import urlparse++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class AliYuqueDescribeDocumentContentTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:+ new_params = {**tool_parameters}+ token = new_params.pop("token")+ if not token or token.lower() == "none":+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ new_params = {**tool_parameters}+ url = new_params.pop("url")+ if not url or not url.startswith("http"):+ raise Exception("url is not valid")++ parsed_url = urlparse(url)+ path_parts = parsed_url.path.strip("/").split("/")+ if len(path_parts) < 3:+ raise Exception("url is not correct")+ doc_id = path_parts[-1]+ book_slug = path_parts[-2]+ group_id = path_parts[-3]++ # 1. 请求首页信息,获取book_id+ new_params["group_login"] = group_id+ new_params["book_slug"] = book_slug+ index_page = json.loads(+ self.request("GET", token, new_params, "/api/v2/repos/{group_login}/{book_slug}/index_page")+ )+ book_id = index_page.get("data", {}).get("book", {}).get("id")+ if not book_id:+ raise Exception(f"can not parse book_id from {index_page}")+ # 2. 获取文档内容+ new_params["book_id"] = book_id+ new_params["id"] = doc_id+ data = self.request("GET", token, new_params, "/api/v2/repos/{book_id}/docs/{id}")+ data = json.loads(data)+ body_only = tool_parameters.get("body_only") or ""+ if body_only.lower() == "true":+ return self.create_text_message(data.get("data").get("body"))+ else:+ raw = data.get("data")+ del raw["body_lake"]+ del raw["body_html"]+ return self.create_text_message(json.dumps(data))diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.yaml b/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.yamlnew file mode 100644index 00000000000..6116886a96b--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_document_content.yaml@@ -0,0 +1,50 @@+identity:+ name: aliyuque_describe_document_content+ author: 佐井+ label:+ en_US: Fetch Document Content+ zh_Hans: 获取文档内容+ icon: icon.svg++description:+ human:+ en_US: Retrieves document content from Yuque based on the provided document URL, which can be a normal or shared link.+ zh_Hans: 根据提供的语雀文档地址(支持正常链接或分享链接)获取文档内容。+ llm: Fetches Yuque document content given a URL.++parameters:+ - name: url+ type: string+ required: true+ form: llm+ label:+ en_US: Document URL+ zh_Hans: 文档地址+ human_description:+ en_US: The URL of the document to retrieve content from, can be normal or shared.+ zh_Hans: 需要获取内容的文档地址,可以是正常链接或分享链接。+ llm_description: URL of the Yuque document to fetch content.++ - name: body_only+ type: string+ required: false+ form: llm+ label:+ en_US: return body content only+ zh_Hans: 仅返回body内容+ human_description:+ en_US: true:Body content only, false:Full response with metadata.+ zh_Hans: true:仅返回body内容,不返回其他元数据,false:返回所有元数据。+ llm_description: true:Body content only, false:Full response with metadata.++ - name: token+ type: secret-input+ required: false+ form: llm+ label:+ en_US: Yuque API Token+ zh_Hans: 语雀接口Token+ human_description:+ en_US: The token for calling the Yuque API defaults to the Yuque token bound to the current tool if not provided.+ zh_Hans: 调用语雀接口的token,如果不传则默认为当前工具绑定的语雀Token。+ llm_description: If the token for calling the Yuque API is not provided, it will default to the Yuque token bound to the current tool.diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.py b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.pynew file mode 100644index 00000000000..ed1b2a86431--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.py@@ -0,0 +1,24 @@+"""+获取文档+"""++__author__ = "佐井"+__created__ = "2024-06-01 10:45:20"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class AliYuqueDescribeDocumentsTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ return self.create_text_message(+ self.request("GET", token, tool_parameters, "/api/v2/repos/{book_id}/docs/{id}")+ )diff --git a/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yaml b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yamlnew file mode 100644index 00000000000..5156345d719--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/describe_documents.yaml@@ -0,0 +1,38 @@+identity:+ name: aliyuque_describe_documents+ author: 佐井+ label:+ en_US: Get Doc Detail+ zh_Hans: 获取文档详情+ icon: icon.svg++description:+ human:+ en_US: Retrieves detailed information of a specific document identified by its ID or path within a knowledge base.+ zh_Hans: 根据知识库ID和文档ID或路径获取文档详细信息。+ llm: Fetches detailed doc info using ID/path from a knowledge base; supports doc lookup in Yuque.++parameters:+ - name: book_id+ type: number+ required: true+ form: llm+ label:+ en_US: Knowledge Base ID+ zh_Hans: 知识库 ID+ human_description:+ en_US: Identifier for the knowledge base where the document resides.+ zh_Hans: 文档所属知识库的唯一标识。+ llm_description: ID of the knowledge base holding the document.++ - name: id+ type: string+ required: true+ form: llm+ label:+ en_US: Document ID or Path+ zh_Hans: 文档 ID 或路径+ human_description:+ en_US: The unique identifier or path of the document to retrieve.+ zh_Hans: 需要获取的文档的ID或其在知识库中的路径。+ llm_description: Unique doc ID or its path for retrieval.diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.py b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.pynew file mode 100644index 00000000000..932559445ee--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.py@@ -0,0 +1,29 @@+#!/usr/bin/env python3+"""+获取知识库目录+"""++__author__ = "佐井"+__created__ = "2024-09-17 15:17:11"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class YuqueDescribeBookTableOfContentsTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> (Union)[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")++ doc_ids = tool_parameters.get("doc_ids")+ if doc_ids:+ doc_ids = [int(doc_id.strip()) for doc_id in doc_ids.split(",")]+ tool_parameters["doc_ids"] = doc_ids++ return self.create_text_message(self.request("PUT", token, tool_parameters, "/api/v2/repos/{book_id}/toc"))diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yaml b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yamlnew file mode 100644index 00000000000..f0c0024f17f--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/update_book_table_of_contents.yaml@@ -0,0 +1,222 @@+identity:+ name: aliyuque_update_book_table_of_contents+ author: 佐井+ label:+ en_US: Update Book's Table of Contents+ zh_Hans: 更新知识库目录+ icon: icon.svg+description:+ human:+ en_US: Update Book's Table of Contents.+ zh_Hans: 更新知识库目录。+ llm: Update Book's Table of Contents.++parameters:+ - name: book_id+ type: number+ required: true+ form: llm+ label:+ en_US: Book ID+ zh_Hans: 知识库 ID+ human_description:+ en_US: Book ID.+ zh_Hans: 知识库 ID。+ llm_description: Book ID.++ - name: action+ type: select+ required: true+ form: llm+ options:+ - value: appendNode+ label:+ en_US: appendNode+ zh_Hans: appendNode+ pt_BR: appendNode+ - value: prependNode+ label:+ en_US: prependNode+ zh_Hans: prependNode+ pt_BR: prependNode+ - value: editNode+ label:+ en_US: editNode+ zh_Hans: editNode+ pt_BR: editNode+ - value: editNode+ label:+ en_US: removeNode+ zh_Hans: removeNode+ pt_BR: removeNode+ label:+ en_US: Action Type+ zh_Hans: 操作+ human_description:+ en_US: In the operation scenario, sibling node prepending is not supported, deleting a node doesn't remove associated documents, and node deletion has two modes, 'sibling' (delete current node) and 'child' (delete current node and its children).+ zh_Hans: 操作,创建场景下不支持同级头插 prependNode,删除节点不会删除关联文档,删除节点时action_mode=sibling (删除当前节点), action_mode=child (删除当前节点及子节点)+ llm_description: In the operation scenario, sibling node prepending is not supported, deleting a node doesn't remove associated documents, and node deletion has two modes, 'sibling' (delete current node) and 'child' (delete current node and its children).+++ - name: action_mode+ type: select+ required: false+ form: llm+ options:+ - value: sibling+ label:+ en_US: sibling+ zh_Hans: 同级+ pt_BR: sibling+ - value: child+ label:+ en_US: child+ zh_Hans: 子集+ pt_BR: child+ label:+ en_US: Action Type+ zh_Hans: 操作+ human_description:+ en_US: Operation mode (sibling:same level, child:child level).+ zh_Hans: 操作模式 (sibling:同级, child:子级)。+ llm_description: Operation mode (sibling:same level, child:child level).++ - name: target_uuid+ type: string+ required: false+ form: llm+ label:+ en_US: Target node UUID+ zh_Hans: 目标节点 UUID+ human_description:+ en_US: Target node UUID, defaults to root node if left empty.+ zh_Hans: 目标节点 UUID, 不填默认为根节点。+ llm_description: Target node UUID, defaults to root node if left empty.++ - name: node_uuid+ type: string+ required: false+ form: llm+ label:+ en_US: Node UUID+ zh_Hans: 操作节点 UUID+ human_description:+ en_US: Operation node UUID [required for move/update/delete].+ zh_Hans: 操作节点 UUID [移动/更新/删除必填]。+ llm_description: Operation node UUID [required for move/update/delete].++ - name: doc_ids+ type: string+ required: false+ form: llm+ label:+ en_US: Document IDs+ zh_Hans: 文档id列表+ human_description:+ en_US: Document IDs [required for creating documents], separate multiple IDs with ','.+ zh_Hans: 文档 IDs [创建文档必填],多个用','分隔。+ llm_description: Document IDs [required for creating documents], separate multiple IDs with ','.+++ - name: type+ type: select+ required: false+ form: llm+ default: DOC+ options:+ - value: DOC+ label:+ en_US: DOC+ zh_Hans: 文档+ pt_BR: DOC+ - value: LINK+ label:+ en_US: LINK+ zh_Hans: 链接+ pt_BR: LINK+ - value: TITLE+ label:+ en_US: TITLE+ zh_Hans: 分组+ pt_BR: TITLE+ label:+ en_US: Node type+ zh_Hans: 操节点类型+ human_description:+ en_US: Node type [required for creation] (DOC:document, LINK:external link, TITLE:group).+ zh_Hans: 操节点类型 [创建必填] (DOC:文档, LINK:外链, TITLE:分组)。+ llm_description: Node type [required for creation] (DOC:document, LINK:external link, TITLE:group).++ - name: title+ type: string+ required: false+ form: llm+ label:+ en_US: Node Name+ zh_Hans: 节点名称+ human_description:+ en_US: Node name [required for creating groups/external links].+ zh_Hans: 节点名称 [创建分组/外链必填]。+ llm_description: Node name [required for creating groups/external links].++ - name: url+ type: string+ required: false+ form: llm+ label:+ en_US: Node URL+ zh_Hans: 节点URL+ human_description:+ en_US: Node URL [required for creating external links].+ zh_Hans: 节点 URL [创建外链必填]。+ llm_description: Node URL [required for creating external links].+++ - name: open_window+ type: select+ required: false+ form: llm+ default: 0+ options:+ - value: 0+ label:+ en_US: DOC+ zh_Hans: Current Page+ pt_BR: DOC+ - value: 1+ label:+ en_US: LINK+ zh_Hans: New Page+ pt_BR: LINK+ label:+ en_US: Open in new window+ zh_Hans: 是否新窗口打开+ human_description:+ en_US: Open in new window [optional for external links] (0:open in current page, 1:open in new window).+ zh_Hans: 是否新窗口打开 [外链选填] (0:当前页打开, 1:新窗口打开)。+ llm_description: Open in new window [optional for external links] (0:open in current page, 1:open in new window).+++ - name: visible+ type: select+ required: false+ form: llm+ default: 1+ options:+ - value: 0+ label:+ en_US: Invisible+ zh_Hans: 隐藏+ pt_BR: Invisible+ - value: 1+ label:+ en_US: Visible+ zh_Hans: 可见+ pt_BR: Visible+ label:+ en_US: Visibility+ zh_Hans: 是否可见+ human_description:+ en_US: Visibility (0:invisible, 1:visible).+ zh_Hans: 是否可见 (0:不可见, 1:可见)。+ llm_description: Visibility (0:invisible, 1:visible).diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_document.py b/api/core/tools/provider/builtin/aliyuque/tools/update_document.pynew file mode 100644index 00000000000..0c6e0205e1b--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/update_document.py@@ -0,0 +1,24 @@+"""+更新文档+"""++__author__ = "佐井"+__created__ = "2024-06-19 16:50:07"++from typing import Any, Union++from core.tools.entities.tool_entities import ToolInvokeMessage+from core.tools.provider.builtin.aliyuque.tools.base import AliYuqueTool+from core.tools.tool.builtin_tool import BuiltinTool+++class AliYuqueUpdateDocumentTool(AliYuqueTool, BuiltinTool):+ def _invoke(+ self, user_id: str, tool_parameters: dict[str, Any]+ ) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:+ token = self.runtime.credentials.get("token", None)+ if not token:+ raise Exception("token is required")+ return self.create_text_message(+ self.request("PUT", token, tool_parameters, "/api/v2/repos/{book_id}/docs/{id}")+ )diff --git a/api/core/tools/provider/builtin/aliyuque/tools/update_document.yaml b/api/core/tools/provider/builtin/aliyuque/tools/update_document.yamlnew file mode 100644index 00000000000..87f88c9b1b0--- /dev/null+++ b/api/core/tools/provider/builtin/aliyuque/tools/update_document.yaml@@ -0,0 +1,87 @@+identity:+ name: aliyuque_update_document+ author: 佐井+ label:+ en_US: Update Document+ zh_Hans: 更新文档+ icon: icon.svg+description:+ human:+ en_US: Update an existing document within a specified knowledge base by providing the document ID or path.+ zh_Hans: 通过提供文档ID或路径,更新指定知识库中的现有文档。+ llm: Update doc in a knowledge base via ID/path.+parameters:+ - name: book_id+ type: number+ required: true+ form: llm+ label:+ en_US: Knowledge Base ID+ zh_Hans: 知识库 ID+ human_description:+ en_US: The unique identifier of the knowledge base where the document resides.+ zh_Hans: 文档所属知识库的ID。+ llm_description: ID of the knowledge base holding the doc.+ - name: id+ type: string+ required: true+ form: llm+ label:+ en_US: Document ID or Path+ zh_Hans: 文档 ID 或 路径+ human_description:+ en_US: The unique identifier or the path of the document to be updated.+ zh_Hans: 要更新的文档的唯一ID或路径。+ llm_description: Doc's ID or path for update.++ - name: title+ type: string+ required: false+ form: llm+ label:+ en_US: Title+ zh_Hans: 标题+ human_description:+ en_US: The title of the document, defaults to 'Untitled' if not provided.+ zh_Hans: 文档标题,默认为'无标题'如未提供。+ llm_description: Title of the document, defaults to 'Untitled'.++ - name: format+ type: select+ required: false+ form: llm+ options:+ - value: markdown+ label:+ en_US: markdown+ zh_Hans: markdown+ pt_BR: markdown+ - value: html+ label:+ en_US: html+ zh_Hans: html+ pt_BR: html+ - value: lake+ label:+ en_US: lake+ zh_Hans: lake+ pt_BR: lake+ label:+ en_US: Content Format+ zh_Hans: 内容格式+ human_description:+ en_US: Format of the document content (markdown, HTML, Lake).+ zh_Hans: 文档内容格式(markdown, HTML, Lake)。+ llm_description: Content format choices, markdown, HTML, Lake.++ - name: body+ type: string+ required: true+ form: llm+ label:+ en_US: Body Content+ zh_Hans: 正文内容+ human_description:+ en_US: The actual content of the document.+ zh_Hans: 文档的实际内容。+ llm_description: Content of the document.