Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ test.js
config/manifest.json

dt-skill/dist/
agent-market/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run
logs
cache
.history
public
/public
resources
agent-market
app/view
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ config/manifest.json
# Build output and runtime data (already in .gitignore)
dt-skill/dist/
run/
agent-market/
67 changes: 38 additions & 29 deletions app/controller/agents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const Controller = require('egg').Controller;
const fs = require('fs');

class AgentsController extends Controller {
async getAgentList() {
Expand Down Expand Up @@ -35,40 +34,50 @@ class AgentsController extends Controller {
this.ctx.body = this.app.utils.response(true, data);
}

async importAgentFile() {
const files = this.ctx.request.files
? Array.isArray(this.ctx.request.files)
? this.ctx.request.files
: [this.ctx.request.files]
: [];
const file = files[0];

if (!file) {
this.ctx.throw(400, '缺少上传文件');
async deleteAgent() {
const data = await this.ctx.service.agents.deleteAgent(this.ctx.request.body || {});
this.ctx.body = this.app.utils.response(true, data);
}
// 从指定 GitLab 仓库导入 Agent
async importAgentFromGit() {
const { gitUrl, gitBranch, category } = this.ctx.request.body || {};
if (!gitUrl) {
this.ctx.throw(400, '缺少 gitUrl 参数');
}
const data = await this.ctx.service.agents.importAgentFromGit(
gitUrl,
gitBranch || 'master',
category
);
this.ctx.body = this.app.utils.response(true, data);
}

try {
const data = await this.ctx.service.agents.importAgentFile(
this.ctx.request.body || {},
file
);
// 同步 Git 仓库代码,支持按 name 单独同步或全量同步
async syncGitAgents() {
const { name } = this.ctx.request.body || {};
if (name) {
// 单独同步单个 Agent
const data = await this.ctx.service.agents.syncGitAgentByName(name);
this.ctx.body = this.app.utils.response(true, data);
} finally {
// 清理本次请求上传的所有临时文件,防止多文件或异常时泄漏
for (const item of files) {
if (item?.filepath && fs.existsSync(item.filepath)) {
try {
fs.unlinkSync(item.filepath);
} catch (error) {
this.ctx.logger.warn(`[agents] 清理上传文件失败: ${error.message}`);
}
}
}
return;
}
const data = await this.ctx.service.agents.syncAllGitAgents();
this.ctx.body = this.app.utils.response(true, data);
}

async deleteAgent() {
const data = await this.ctx.service.agents.deleteAgent(this.ctx.request.body || {});
// 更新 Agent 的 Git 仓库配置,支持可选立即同步
async updateAgentGitConfig() {
const { name, gitUrl, gitBranch, category, syncNow } = this.ctx.request.body || {};
if (!name) {
this.ctx.throw(400, '缺少 name 参数');
}
const data = await this.ctx.service.agents.updateAgentGitConfig({
name,
gitUrl,
gitBranch,
category,
syncNow: Boolean(syncNow),
});
this.ctx.body = this.app.utils.response(true, data);
}
}
Expand Down
28 changes: 18 additions & 10 deletions app/model/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ module.exports = (app) => {
},
logo_size: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
allowNull: true,
comment: 'Logo 大小',
},
logo_hash: {
Expand All @@ -79,15 +78,24 @@ module.exports = (app) => {
allowNull: false,
comment: '内容哈希',
},
source_file_name: {
type: STRING(255),
comment: '上传文件名',
git_url: {
type: STRING(1000),
comment: 'GitLab 仓库地址',
},
file_count: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '文件数量',
git_branch: {
type: STRING(100),
defaultValue: 'master',
comment: 'GitLab 仓库分支',
},
last_git_refresh_at: {
type: DATE,
allowNull: true,
comment: '最近一次刷新/检查 Git 时间',
},
last_git_sync_at: {
type: DATE,
allowNull: true,
comment: '最近一次代码变动同步时间',
},
is_delete: {
type: TINYINT,
Expand Down
84 changes: 0 additions & 84 deletions app/model/agent_file.js

This file was deleted.

Loading
Loading