feat(system):优化后端

1.新增后端测试
2.增加了后端的加密
3.增加了i18n(国际化)
This commit is contained in:
2026-05-31 15:39:34 +00:00
parent affe460180
commit 99520c69d7
118 changed files with 8174 additions and 1491 deletions
@@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .file_reader import FileReaderData, file_reader
from .file_reader import FileReaderToolData, file_reader
__all__ = ["FileReaderData", "file_reader"]
__all__ = ["FileReaderToolData", "file_reader"]
@@ -12,36 +12,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from pydantic_ai import RunContext
"""File Reader Tool Plugin for KiloStar.
Reads the contents of a file from the local filesystem.
"""
from kilostar.plugin.tool_plugin.base_tool import BaseToolData
import os
from typing import List, Literal, Dict
class FileReaderData(BaseToolData):
"""``file_reader`` 工具的元数据:声明工具的名称、描述与是否系统级别"""
class FileReaderToolData(BaseToolData):
"""``file_reader`` 工具的元数据。"""
is_system: bool = True
name: str = "file_reader"
description: str = "读取本地文件的内容"
action_scope: List[
Literal[
"control_node",
"consciousness_node",
"regulatory_node",
"growth_node",
"",
]
] = ["control_node"]
config_args: Dict[str, str] = {}
category: str = "system"
def file_reader(ctx: RunContext, filepath: str) -> str:
"""读取本地文件内容的工具
async def file_reader(file_path: str) -> str:
"""读取本地文件内容。
Args:
filepath: 目标文件的绝对路径或相对路径
file_path: 文件的绝对路径或相对路径
Returns:
如果文件存在并可读,返回文件内容;否则返回错误信息
文件内容文本,若文件不存在则返回错误信息
"""
if not os.path.exists(filepath):
return f"Error: 文件 {filepath} 不存在。"
if not os.path.isfile(filepath):
return f"Error: {filepath} 不是一个文件。"
try:
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
return content
with open(file_path, "r", encoding="utf-8") as f:
return f.read()
except FileNotFoundError:
return f"[Error] File not found: {file_path}"
except Exception as e:
return f"Error: 读取文件失败,原因:{str(e)}"
return f"[Error] Failed to read file: {str(e)}"