Summary: - Fix Prompt list API response schema missing activeVersion and draftVersion fields - Fastify was filtering out undefined schema fields, causing version columns to show empty - Add detailed diagnostic logging for Prompt debug mode troubleshooting - Verify debug mode works correctly (DRAFT version is used when debug enabled) Changes: - backend/src/common/prompt/prompt.routes.ts: Add activeVersion and draftVersion to response schema - backend/src/common/prompt/prompt.service.ts: Add diagnostic logs for setDebugMode and get methods - PKB module: Various authentication and document handling fixes from previous session Tested: Debug mode verified working - v2 DRAFT version correctly loaded when debug enabled
3.3 KiB
3.3 KiB
工具C (Tool C) - 科研数据编辑器
📁 项目结构
tool-c/
├── services/
│ └── PythonExecutorService.ts # Python代码执行服务
├── controllers/
│ └── TestController.ts # 测试控制器(Day 1)
├── routes/
│ └── index.ts # 路由定义
└── README.md # 本文件
⚙️ 环境变量配置
在 backend/.env 文件中添加以下配置:
# Python微服务地址
EXTRACTION_SERVICE_URL=http://localhost:8000
说明:
- 默认值:
http://localhost:8000 - Python微服务需要先启动才能使用工具C
- 启动命令:
cd extraction_service && .\venv\Scripts\activate && uvicorn main:app --host 0.0.0.0 --port 8000
🚀 API端点(Day 1 测试)
1. 测试Python服务健康检查
GET /api/v1/dc/tool-c/test/health
响应:
{
"success": true,
"message": "Python服务正常",
"healthy": true
}
2. 测试代码验证
POST /api/v1/dc/tool-c/test/validate
请求体:
{
"code": "df['age_group'] = df['age'] > 60"
}
响应:
{
"success": true,
"data": {
"valid": true,
"errors": [],
"warnings": []
}
}
3. 测试代码执行
POST /api/v1/dc/tool-c/test/execute
请求体:
{
"data": [
{"age": 25},
{"age": 65}
],
"code": "df['old'] = df['age'] > 60"
}
响应:
{
"success": true,
"data": {
"success": true,
"result_data": [
{"age": 25, "old": false},
{"age": 65, "old": true}
],
"output": "",
"error": null,
"execution_time": 0.004,
"result_shape": [2, 2]
}
}
✅ Day 1 完成情况
- 创建Python微服务(dc_executor.py)
- 添加AST安全检查
- 实现Pandas代码执行
- 创建FastAPI端点(/api/dc/validate, /api/dc/execute)
- 创建Node.js服务(PythonExecutorService.ts)
- 创建测试控制器和路由
- 验证功能正常工作
📝 使用示例
启动Python微服务
cd extraction_service
.\venv\Scripts\activate
python main.py
启动Node.js后端
cd backend
npm run dev
测试API
# 1. 健康检查
curl http://localhost:3000/api/v1/dc/tool-c/test/health
# 2. 代码验证
curl -X POST http://localhost:3000/api/v1/dc/tool-c/test/validate \
-H "Content-Type: application/json" \
-d '{"code":"df[\"x\"] = 1"}'
# 3. 代码执行
curl -X POST http://localhost:3000/api/v1/dc/tool-c/test/execute \
-H "Content-Type: application/json" \
-d '{"data":[{"age":25},{"age":65}],"code":"df[\"old\"] = df[\"age\"] > 60"}'
🔐 安全特性
- AST静态检查:拦截危险模块导入(os, sys, subprocess等)
- 超时保护:代码执行超时30秒自动终止
- 沙箱环境:限制可用的内置函数
- 错误处理:完整的异常捕获和错误信息
📚 技术栈
- Python后端: FastAPI + Pandas + AST
- Node.js后端: Fastify + Axios + TypeScript
- 通信方式: HTTP REST API
- 数据格式: JSON
🎯 下一步(Day 2)
- Session管理(数据库 + OSS)
- 数据处理服务
- AI代码生成服务(LLMFactory集成)
- 前端基础框架搭建