@cicctencent/agent-midway 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +280 -0
- package/dist/adapters/express.d.ts +8 -0
- package/dist/adapters/express.js +91 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.js +21 -0
- package/dist/adapters/koa.d.ts +3 -0
- package/dist/adapters/koa.js +75 -0
- package/dist/adapters/midway.d.ts +5 -0
- package/dist/adapters/midway.js +11 -0
- package/dist/adapters/next.d.ts +12 -0
- package/dist/adapters/next.js +89 -0
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/adapters/shared.js +31 -0
- package/dist/channel/dingtalk.d.ts +18 -0
- package/dist/channel/dingtalk.js +68 -0
- package/dist/channel/feishu.d.ts +20 -0
- package/dist/channel/feishu.js +96 -0
- package/dist/channel/index.d.ts +46 -0
- package/dist/channel/index.js +311 -0
- package/dist/channel/types.d.ts +77 -0
- package/dist/channel/types.js +7 -0
- package/dist/channel/wecom.d.ts +22 -0
- package/dist/channel/wecom.js +106 -0
- package/dist/component.d.ts +49 -0
- package/dist/component.js +129 -0
- package/dist/connector/calendar-adapter.d.ts +19 -0
- package/dist/connector/calendar-adapter.js +236 -0
- package/dist/connector/db-adapter.d.ts +28 -0
- package/dist/connector/db-adapter.js +193 -0
- package/dist/connector/email-adapter.d.ts +23 -0
- package/dist/connector/email-adapter.js +192 -0
- package/dist/connector/fs-adapter.d.ts +15 -0
- package/dist/connector/fs-adapter.js +199 -0
- package/dist/connector/http-adapter.d.ts +29 -0
- package/dist/connector/http-adapter.js +181 -0
- package/dist/connector/index.d.ts +24 -0
- package/dist/connector/index.js +454 -0
- package/dist/connector/mcp-adapter.d.ts +27 -0
- package/dist/connector/mcp-adapter.js +156 -0
- package/dist/connector/mq-adapter.d.ts +25 -0
- package/dist/connector/mq-adapter.js +181 -0
- package/dist/connector/types.d.ts +205 -0
- package/dist/connector/types.js +9 -0
- package/dist/controller/a2a.controller.d.ts +41 -0
- package/dist/controller/a2a.controller.js +150 -0
- package/dist/controller/agent-profile.controller.d.ts +97 -0
- package/dist/controller/agent-profile.controller.js +200 -0
- package/dist/controller/agent.controller.d.ts +199 -0
- package/dist/controller/agent.controller.js +414 -0
- package/dist/controller/application.controller.d.ts +113 -0
- package/dist/controller/application.controller.js +217 -0
- package/dist/controller/automation.controller.d.ts +113 -0
- package/dist/controller/automation.controller.js +246 -0
- package/dist/controller/channel.controller.d.ts +73 -0
- package/dist/controller/channel.controller.js +183 -0
- package/dist/controller/chat.controller.d.ts +188 -0
- package/dist/controller/chat.controller.js +375 -0
- package/dist/controller/connector.controller.d.ts +134 -0
- package/dist/controller/connector.controller.js +257 -0
- package/dist/controller/knowledge-base.controller.d.ts +157 -0
- package/dist/controller/knowledge-base.controller.js +278 -0
- package/dist/controller/mcp-server.controller.d.ts +115 -0
- package/dist/controller/mcp-server.controller.js +236 -0
- package/dist/controller/model-config.controller.d.ts +139 -0
- package/dist/controller/model-config.controller.js +274 -0
- package/dist/controller/observability.controller.d.ts +124 -0
- package/dist/controller/observability.controller.js +142 -0
- package/dist/controller/security.controller.d.ts +91 -0
- package/dist/controller/security.controller.js +172 -0
- package/dist/controller/settings.controller.d.ts +83 -0
- package/dist/controller/settings.controller.js +280 -0
- package/dist/core/ai-workstation.d.ts +17 -0
- package/dist/core/ai-workstation.js +129 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +20 -0
- package/dist/core/service-container.d.ts +12 -0
- package/dist/core/service-container.js +54 -0
- package/dist/core/sse.d.ts +6 -0
- package/dist/core/sse.js +56 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/core/types.js +2 -0
- package/dist/dto/agent.dto.d.ts +21 -0
- package/dist/dto/agent.dto.js +79 -0
- package/dist/dto/ai-config.dto.d.ts +67 -0
- package/dist/dto/ai-config.dto.js +249 -0
- package/dist/dto/chat.dto.d.ts +40 -0
- package/dist/dto/chat.dto.js +122 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +195 -0
- package/dist/memory/db-store.d.ts +33 -0
- package/dist/memory/db-store.js +143 -0
- package/dist/memory/index.d.ts +187 -0
- package/dist/memory/index.js +443 -0
- package/dist/model/ai-agent-profile.entity.d.ts +32 -0
- package/dist/model/ai-agent-profile.entity.js +289 -0
- package/dist/model/ai-application.entity.d.ts +20 -0
- package/dist/model/ai-application.entity.js +166 -0
- package/dist/model/ai-chat-memory.entity.d.ts +16 -0
- package/dist/model/ai-chat-memory.entity.js +123 -0
- package/dist/model/ai-chat-message.entity.d.ts +16 -0
- package/dist/model/ai-chat-message.entity.js +122 -0
- package/dist/model/ai-chat-skill.entity.d.ts +19 -0
- package/dist/model/ai-chat-skill.entity.js +155 -0
- package/dist/model/ai-chat-thread.entity.d.ts +15 -0
- package/dist/model/ai-chat-thread.entity.js +113 -0
- package/dist/model/ai-chat-workspace.entity.d.ts +17 -0
- package/dist/model/ai-chat-workspace.entity.js +136 -0
- package/dist/model/ai-kb-document.entity.d.ts +16 -0
- package/dist/model/ai-kb-document.entity.js +122 -0
- package/dist/model/ai-knowledge-base.entity.d.ts +22 -0
- package/dist/model/ai-knowledge-base.entity.js +185 -0
- package/dist/model/ai-mcp-server.entity.d.ts +23 -0
- package/dist/model/ai-mcp-server.entity.js +198 -0
- package/dist/model/ai-model-config.entity.d.ts +24 -0
- package/dist/model/ai-model-config.entity.js +200 -0
- package/dist/service/a2a.service.d.ts +142 -0
- package/dist/service/a2a.service.js +537 -0
- package/dist/service/agent-profile.service.d.ts +34 -0
- package/dist/service/agent-profile.service.js +110 -0
- package/dist/service/agent-server.service.d.ts +91 -0
- package/dist/service/agent-server.service.js +634 -0
- package/dist/service/agent-task-queue.service.d.ts +98 -0
- package/dist/service/agent-task-queue.service.js +283 -0
- package/dist/service/ai-chat.service.d.ts +103 -0
- package/dist/service/ai-chat.service.js +431 -0
- package/dist/service/ai-skill.service.d.ts +116 -0
- package/dist/service/ai-skill.service.js +457 -0
- package/dist/service/application.service.d.ts +42 -0
- package/dist/service/application.service.js +139 -0
- package/dist/service/automation.service.d.ts +37 -0
- package/dist/service/automation.service.js +196 -0
- package/dist/service/connector.service.d.ts +136 -0
- package/dist/service/connector.service.js +524 -0
- package/dist/service/knowledge-base.service.d.ts +138 -0
- package/dist/service/knowledge-base.service.js +528 -0
- package/dist/service/mcp-server.service.d.ts +39 -0
- package/dist/service/mcp-server.service.js +143 -0
- package/dist/service/model-config.service.d.ts +57 -0
- package/dist/service/model-config.service.js +168 -0
- package/dist/service/observability.service.d.ts +145 -0
- package/dist/service/observability.service.js +281 -0
- package/dist/service/openai.service.d.ts +88 -0
- package/dist/service/openai.service.js +406 -0
- package/dist/service/prompt-builder.service.d.ts +50 -0
- package/dist/service/prompt-builder.service.js +246 -0
- package/dist/tools/code-exec.tool.d.ts +37 -0
- package/dist/tools/code-exec.tool.js +162 -0
- package/dist/tools/datetime.tool.d.ts +21 -0
- package/dist/tools/datetime.tool.js +379 -0
- package/dist/tools/http-request.tool.d.ts +43 -0
- package/dist/tools/http-request.tool.js +455 -0
- package/dist/tools/registry.d.ts +71 -0
- package/dist/tools/registry.js +77 -0
- package/dist/tools/text-process.tool.d.ts +7 -0
- package/dist/tools/text-process.tool.js +366 -0
- package/dist/tools/web-search.tool.d.ts +28 -0
- package/dist/tools/web-search.tool.js +304 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js +7 -0
- package/package.json +69 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.A2AController = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* A2A 协议控制器
|
|
18
|
+
*
|
|
19
|
+
* 路由说明:
|
|
20
|
+
* - GET /.well-known/agent.json — Agent Card 发现(不需要登录)
|
|
21
|
+
* - POST /a2a — JSON-RPC 分发入口(不需要登录,支持 SSE 流式)
|
|
22
|
+
* - POST /api/a2a/discover — 发现远程 Agent(需要登录)
|
|
23
|
+
*
|
|
24
|
+
* 注意:`/.well-known/agent.json` 和 `/a2a` 挂载在根路径
|
|
25
|
+
*/
|
|
26
|
+
const core_1 = require("@midwayjs/core");
|
|
27
|
+
const midwayjs_base_1 = require("@cicctencent/midwayjs-base");
|
|
28
|
+
const a2a_service_1 = require("../service/a2a.service");
|
|
29
|
+
let A2AController = class A2AController extends midwayjs_base_1.BaseController {
|
|
30
|
+
/**
|
|
31
|
+
* Agent Card 发现端点
|
|
32
|
+
* GET /.well-known/agent.json
|
|
33
|
+
*/
|
|
34
|
+
async getAgentCard() {
|
|
35
|
+
const baseUrl = `${this.ctx.protocol}://${this.ctx.host}`;
|
|
36
|
+
const card = this.a2aService.generateAgentCard(baseUrl);
|
|
37
|
+
return card;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* JSON-RPC 分发入口
|
|
41
|
+
* POST /a2a
|
|
42
|
+
* 支持 SSE 流式响应(当 method 为 tasks/sendSubscribe 时)
|
|
43
|
+
*/
|
|
44
|
+
async handleJsonRpc(body) {
|
|
45
|
+
// 检查是否为流式请求
|
|
46
|
+
const acceptHeader = this.ctx.headers['accept'] || '';
|
|
47
|
+
const isStreaming = body?.method === 'tasks/sendSubscribe' ||
|
|
48
|
+
acceptHeader.includes('text/event-stream');
|
|
49
|
+
if (isStreaming) {
|
|
50
|
+
return this.handleStreaming(body);
|
|
51
|
+
}
|
|
52
|
+
// 非流式:直接返回 JSON-RPC 响应
|
|
53
|
+
const response = await this.a2aService.handleJsonRpc(body);
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 发现远程 Agent
|
|
58
|
+
* POST /api/a2a/discover
|
|
59
|
+
*/
|
|
60
|
+
async discoverAgent(body) {
|
|
61
|
+
try {
|
|
62
|
+
if (!body?.url) {
|
|
63
|
+
return { ret: 1, msg: 'URL is required' };
|
|
64
|
+
}
|
|
65
|
+
const card = await this.a2aService.discoverRemoteAgent(body.url, body.auth);
|
|
66
|
+
return { ret: 0, data: card, msg: 'success' };
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return { ret: 1, msg: error.message };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 处理流式 JSON-RPC 请求(SSE)
|
|
74
|
+
*/
|
|
75
|
+
async handleStreaming(body) {
|
|
76
|
+
this.ctx.set('Cache-Control', 'no-cache');
|
|
77
|
+
this.ctx.set('Connection', 'keep-alive');
|
|
78
|
+
this.ctx.set('X-Accel-Buffering', 'no');
|
|
79
|
+
try {
|
|
80
|
+
const params = body?.params || {};
|
|
81
|
+
const generator = this.a2aService.handleSendTaskStreaming(params);
|
|
82
|
+
for await (const event of generator) {
|
|
83
|
+
const sseData = this.formatSSEEvent(event);
|
|
84
|
+
this.ctx.res.write(sseData);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const errorEvent = this.formatSSEEvent({
|
|
89
|
+
type: 'error',
|
|
90
|
+
data: { message: error.message },
|
|
91
|
+
});
|
|
92
|
+
this.ctx.res.write(errorEvent);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
this.ctx.res.end();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 格式化 SSE 事件
|
|
100
|
+
*/
|
|
101
|
+
formatSSEEvent(event) {
|
|
102
|
+
const jsonRpcResponse = {
|
|
103
|
+
jsonrpc: '2.0',
|
|
104
|
+
id: 0,
|
|
105
|
+
result: {
|
|
106
|
+
type: event.type,
|
|
107
|
+
data: event.data,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
return `data: ${JSON.stringify(jsonRpcResponse)}\n\n`;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
exports.A2AController = A2AController;
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, core_1.Inject)(),
|
|
116
|
+
__metadata("design:type", a2a_service_1.A2AService)
|
|
117
|
+
], A2AController.prototype, "a2aService", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, core_1.Get)('.well-known/agent.json'),
|
|
120
|
+
midwayjs_base_1.decorators.checkLogin(false),
|
|
121
|
+
__metadata("design:type", Function),
|
|
122
|
+
__metadata("design:paramtypes", []),
|
|
123
|
+
__metadata("design:returntype", Promise)
|
|
124
|
+
], A2AController.prototype, "getAgentCard", null);
|
|
125
|
+
__decorate([
|
|
126
|
+
(0, core_1.Post)('a2a'),
|
|
127
|
+
midwayjs_base_1.decorators.checkLogin(false),
|
|
128
|
+
__param(0, (0, core_1.Body)()),
|
|
129
|
+
__metadata("design:type", Function),
|
|
130
|
+
__metadata("design:paramtypes", [Object]),
|
|
131
|
+
__metadata("design:returntype", Promise)
|
|
132
|
+
], A2AController.prototype, "handleJsonRpc", null);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, core_1.Post)('api/a2a/discover'),
|
|
135
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
136
|
+
__param(0, (0, core_1.Body)()),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", [Object]),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], A2AController.prototype, "discoverAgent", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, core_1.ContentType)('text/event-stream'),
|
|
143
|
+
__metadata("design:type", Function),
|
|
144
|
+
__metadata("design:paramtypes", [Object]),
|
|
145
|
+
__metadata("design:returntype", Promise)
|
|
146
|
+
], A2AController.prototype, "handleStreaming", null);
|
|
147
|
+
exports.A2AController = A2AController = __decorate([
|
|
148
|
+
(0, core_1.Provide)(),
|
|
149
|
+
(0, core_1.Controller)('/')
|
|
150
|
+
], A2AController);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { BaseController } from '@cicctencent/midwayjs-base';
|
|
2
|
+
import { CreateAgentProfileDTO } from '../dto/ai-config.dto';
|
|
3
|
+
import { AgentProfileService } from '../service/agent-profile.service';
|
|
4
|
+
import { ApplicationService } from '../service/application.service';
|
|
5
|
+
/**
|
|
6
|
+
* Agent Profile 管理 Controller
|
|
7
|
+
*/
|
|
8
|
+
export declare class AgentProfileController extends BaseController {
|
|
9
|
+
profileService: AgentProfileService;
|
|
10
|
+
applicationService: ApplicationService;
|
|
11
|
+
/** 获取当前应用ID */
|
|
12
|
+
private getApplicationId;
|
|
13
|
+
/** 获取 Profile 列表 */
|
|
14
|
+
list(): Promise<{
|
|
15
|
+
ret: number;
|
|
16
|
+
data: import("..").AIAgentProfileEntity[];
|
|
17
|
+
msg: string;
|
|
18
|
+
} | {
|
|
19
|
+
ret: number;
|
|
20
|
+
msg: any;
|
|
21
|
+
data?: undefined;
|
|
22
|
+
}>;
|
|
23
|
+
/** 获取单个 Profile */
|
|
24
|
+
detail(id: number): Promise<{
|
|
25
|
+
ret: number;
|
|
26
|
+
data: import("..").AIAgentProfileEntity;
|
|
27
|
+
msg: string;
|
|
28
|
+
} | {
|
|
29
|
+
ret: number;
|
|
30
|
+
msg: any;
|
|
31
|
+
data?: undefined;
|
|
32
|
+
}>;
|
|
33
|
+
/** 获取 Profile 完整配置 */
|
|
34
|
+
fullConfig(id: number): Promise<{
|
|
35
|
+
ret: number;
|
|
36
|
+
data: {
|
|
37
|
+
profile: import("..").AIAgentProfileEntity;
|
|
38
|
+
mcpServers: any[];
|
|
39
|
+
skills: any[];
|
|
40
|
+
};
|
|
41
|
+
msg: string;
|
|
42
|
+
} | {
|
|
43
|
+
ret: number;
|
|
44
|
+
msg: any;
|
|
45
|
+
data?: undefined;
|
|
46
|
+
}>;
|
|
47
|
+
/** 获取默认 Profile */
|
|
48
|
+
getDefault(): Promise<{
|
|
49
|
+
ret: number;
|
|
50
|
+
data: import("..").AIAgentProfileEntity;
|
|
51
|
+
msg: string;
|
|
52
|
+
} | {
|
|
53
|
+
ret: number;
|
|
54
|
+
msg: any;
|
|
55
|
+
data?: undefined;
|
|
56
|
+
}>;
|
|
57
|
+
/** 创建 Profile */
|
|
58
|
+
create(body: CreateAgentProfileDTO): Promise<{
|
|
59
|
+
ret: number;
|
|
60
|
+
data: import("..").AIAgentProfileEntity;
|
|
61
|
+
msg: string;
|
|
62
|
+
} | {
|
|
63
|
+
ret: number;
|
|
64
|
+
msg: any;
|
|
65
|
+
data?: undefined;
|
|
66
|
+
}>;
|
|
67
|
+
/** 更新 Profile */
|
|
68
|
+
update(id: number, body: any): Promise<{
|
|
69
|
+
ret: number;
|
|
70
|
+
data: import("..").AIAgentProfileEntity;
|
|
71
|
+
msg: string;
|
|
72
|
+
} | {
|
|
73
|
+
ret: number;
|
|
74
|
+
msg: any;
|
|
75
|
+
data?: undefined;
|
|
76
|
+
}>;
|
|
77
|
+
/** 删除 Profile */
|
|
78
|
+
remove(id: number): Promise<{
|
|
79
|
+
ret: number;
|
|
80
|
+
data: any;
|
|
81
|
+
msg: string;
|
|
82
|
+
} | {
|
|
83
|
+
ret: number;
|
|
84
|
+
msg: any;
|
|
85
|
+
data?: undefined;
|
|
86
|
+
}>;
|
|
87
|
+
/** 设置为默认 */
|
|
88
|
+
setDefault(id: number): Promise<{
|
|
89
|
+
ret: number;
|
|
90
|
+
data: import("..").AIAgentProfileEntity;
|
|
91
|
+
msg: string;
|
|
92
|
+
} | {
|
|
93
|
+
ret: number;
|
|
94
|
+
msg: any;
|
|
95
|
+
data?: undefined;
|
|
96
|
+
}>;
|
|
97
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AgentProfileController = void 0;
|
|
16
|
+
const core_1 = require("@midwayjs/core");
|
|
17
|
+
const midwayjs_base_1 = require("@cicctencent/midwayjs-base");
|
|
18
|
+
const ai_config_dto_1 = require("../dto/ai-config.dto");
|
|
19
|
+
const agent_profile_service_1 = require("../service/agent-profile.service");
|
|
20
|
+
const application_service_1 = require("../service/application.service");
|
|
21
|
+
/**
|
|
22
|
+
* Agent Profile 管理 Controller
|
|
23
|
+
*/
|
|
24
|
+
let AgentProfileController = class AgentProfileController extends midwayjs_base_1.BaseController {
|
|
25
|
+
/** 获取当前应用ID */
|
|
26
|
+
async getApplicationId() {
|
|
27
|
+
const app = await this.applicationService.getDefault();
|
|
28
|
+
return app?.id || 0;
|
|
29
|
+
}
|
|
30
|
+
/** 获取 Profile 列表 */
|
|
31
|
+
async list() {
|
|
32
|
+
try {
|
|
33
|
+
const applicationId = await this.getApplicationId();
|
|
34
|
+
const profiles = await this.profileService.list(applicationId);
|
|
35
|
+
return { ret: 0, data: profiles, msg: 'success' };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return { ret: 1, msg: error.message };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** 获取单个 Profile */
|
|
42
|
+
async detail(id) {
|
|
43
|
+
try {
|
|
44
|
+
const applicationId = await this.getApplicationId();
|
|
45
|
+
const profile = await this.profileService.get(Number(id), applicationId);
|
|
46
|
+
if (!profile) {
|
|
47
|
+
return { ret: 1, msg: 'Profile 不存在' };
|
|
48
|
+
}
|
|
49
|
+
return { ret: 0, data: profile, msg: 'success' };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return { ret: 1, msg: error.message };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** 获取 Profile 完整配置 */
|
|
56
|
+
async fullConfig(id) {
|
|
57
|
+
try {
|
|
58
|
+
const applicationId = await this.getApplicationId();
|
|
59
|
+
const config = await this.profileService.getFullConfig(Number(id), applicationId);
|
|
60
|
+
if (!config) {
|
|
61
|
+
return { ret: 1, msg: 'Profile 不存在' };
|
|
62
|
+
}
|
|
63
|
+
return { ret: 0, data: config, msg: 'success' };
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return { ret: 1, msg: error.message };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** 获取默认 Profile */
|
|
70
|
+
async getDefault() {
|
|
71
|
+
try {
|
|
72
|
+
const applicationId = await this.getApplicationId();
|
|
73
|
+
const profile = await this.profileService.getDefault(applicationId);
|
|
74
|
+
return { ret: 0, data: profile, msg: 'success' };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return { ret: 1, msg: error.message };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** 创建 Profile */
|
|
81
|
+
async create(body) {
|
|
82
|
+
try {
|
|
83
|
+
const applicationId = await this.getApplicationId();
|
|
84
|
+
const profile = await this.profileService.create(applicationId, body);
|
|
85
|
+
return { ret: 0, data: profile, msg: 'success' };
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
return { ret: 1, msg: error.message };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** 更新 Profile */
|
|
92
|
+
async update(id, body) {
|
|
93
|
+
try {
|
|
94
|
+
const applicationId = await this.getApplicationId();
|
|
95
|
+
const profile = await this.profileService.update(Number(id), applicationId, body);
|
|
96
|
+
return { ret: 0, data: profile, msg: 'success' };
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
return { ret: 1, msg: error.message };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** 删除 Profile */
|
|
103
|
+
async remove(id) {
|
|
104
|
+
try {
|
|
105
|
+
const applicationId = await this.getApplicationId();
|
|
106
|
+
await this.profileService.delete(Number(id), applicationId);
|
|
107
|
+
return { ret: 0, data: null, msg: 'success' };
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return { ret: 1, msg: error.message };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** 设置为默认 */
|
|
114
|
+
async setDefault(id) {
|
|
115
|
+
try {
|
|
116
|
+
const applicationId = await this.getApplicationId();
|
|
117
|
+
const profile = await this.profileService.setDefault(Number(id), applicationId);
|
|
118
|
+
return { ret: 0, data: profile, msg: 'success' };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
return { ret: 1, msg: error.message };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
exports.AgentProfileController = AgentProfileController;
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, core_1.Inject)(),
|
|
128
|
+
__metadata("design:type", agent_profile_service_1.AgentProfileService)
|
|
129
|
+
], AgentProfileController.prototype, "profileService", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
(0, core_1.Inject)(),
|
|
132
|
+
__metadata("design:type", application_service_1.ApplicationService)
|
|
133
|
+
], AgentProfileController.prototype, "applicationService", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, core_1.Get)('/'),
|
|
136
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
137
|
+
__metadata("design:type", Function),
|
|
138
|
+
__metadata("design:paramtypes", []),
|
|
139
|
+
__metadata("design:returntype", Promise)
|
|
140
|
+
], AgentProfileController.prototype, "list", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
(0, core_1.Get)('/:id'),
|
|
143
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
144
|
+
__param(0, (0, core_1.Param)('id')),
|
|
145
|
+
__metadata("design:type", Function),
|
|
146
|
+
__metadata("design:paramtypes", [Number]),
|
|
147
|
+
__metadata("design:returntype", Promise)
|
|
148
|
+
], AgentProfileController.prototype, "detail", null);
|
|
149
|
+
__decorate([
|
|
150
|
+
(0, core_1.Get)('/:id/full'),
|
|
151
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
152
|
+
__param(0, (0, core_1.Param)('id')),
|
|
153
|
+
__metadata("design:type", Function),
|
|
154
|
+
__metadata("design:paramtypes", [Number]),
|
|
155
|
+
__metadata("design:returntype", Promise)
|
|
156
|
+
], AgentProfileController.prototype, "fullConfig", null);
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, core_1.Get)('/default'),
|
|
159
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
160
|
+
__metadata("design:type", Function),
|
|
161
|
+
__metadata("design:paramtypes", []),
|
|
162
|
+
__metadata("design:returntype", Promise)
|
|
163
|
+
], AgentProfileController.prototype, "getDefault", null);
|
|
164
|
+
__decorate([
|
|
165
|
+
(0, core_1.Post)('/'),
|
|
166
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
167
|
+
__param(0, (0, core_1.Body)()),
|
|
168
|
+
__metadata("design:type", Function),
|
|
169
|
+
__metadata("design:paramtypes", [ai_config_dto_1.CreateAgentProfileDTO]),
|
|
170
|
+
__metadata("design:returntype", Promise)
|
|
171
|
+
], AgentProfileController.prototype, "create", null);
|
|
172
|
+
__decorate([
|
|
173
|
+
(0, core_1.Put)('/:id'),
|
|
174
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
175
|
+
__param(0, (0, core_1.Param)('id')),
|
|
176
|
+
__param(1, (0, core_1.Body)()),
|
|
177
|
+
__metadata("design:type", Function),
|
|
178
|
+
__metadata("design:paramtypes", [Number, Object]),
|
|
179
|
+
__metadata("design:returntype", Promise)
|
|
180
|
+
], AgentProfileController.prototype, "update", null);
|
|
181
|
+
__decorate([
|
|
182
|
+
(0, core_1.Del)('/:id'),
|
|
183
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
184
|
+
__param(0, (0, core_1.Param)('id')),
|
|
185
|
+
__metadata("design:type", Function),
|
|
186
|
+
__metadata("design:paramtypes", [Number]),
|
|
187
|
+
__metadata("design:returntype", Promise)
|
|
188
|
+
], AgentProfileController.prototype, "remove", null);
|
|
189
|
+
__decorate([
|
|
190
|
+
(0, core_1.Post)('/:id/default'),
|
|
191
|
+
midwayjs_base_1.decorators.checkLogin(true),
|
|
192
|
+
__param(0, (0, core_1.Param)('id')),
|
|
193
|
+
__metadata("design:type", Function),
|
|
194
|
+
__metadata("design:paramtypes", [Number]),
|
|
195
|
+
__metadata("design:returntype", Promise)
|
|
196
|
+
], AgentProfileController.prototype, "setDefault", null);
|
|
197
|
+
exports.AgentProfileController = AgentProfileController = __decorate([
|
|
198
|
+
(0, core_1.Provide)(),
|
|
199
|
+
(0, core_1.Controller)('/api/agent-profiles')
|
|
200
|
+
], AgentProfileController);
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { BaseController } from '@cicctencent/midwayjs-base';
|
|
2
|
+
import { RunAgentDTO } from '../dto/agent.dto';
|
|
3
|
+
import { AgentServerService } from '../service/agent-server.service';
|
|
4
|
+
import { AgentTaskQueueService } from '../service/agent-task-queue.service';
|
|
5
|
+
import { ApplicationService } from '../service/application.service';
|
|
6
|
+
/**
|
|
7
|
+
* Agent 运行 Controller
|
|
8
|
+
*
|
|
9
|
+
* 提供 Agent 运行接口,支持流式和非流式响应(按 Application 隔离)
|
|
10
|
+
*/
|
|
11
|
+
export declare class AgentController extends BaseController {
|
|
12
|
+
agentServerService: AgentServerService;
|
|
13
|
+
taskQueueService: AgentTaskQueueService;
|
|
14
|
+
applicationService: ApplicationService;
|
|
15
|
+
/** 获取当前应用ID */
|
|
16
|
+
private getApplicationId;
|
|
17
|
+
/**
|
|
18
|
+
* 运行 Agent(流式响应)
|
|
19
|
+
*/
|
|
20
|
+
runAgent(body: RunAgentDTO): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* 运行 Agent(非流式响应)
|
|
23
|
+
*/
|
|
24
|
+
runAgentSync(body: RunAgentDTO): Promise<{
|
|
25
|
+
ret: number;
|
|
26
|
+
data: any;
|
|
27
|
+
msg: string;
|
|
28
|
+
} | {
|
|
29
|
+
ret: number;
|
|
30
|
+
msg: any;
|
|
31
|
+
data?: undefined;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* 提交异步任务
|
|
35
|
+
*/
|
|
36
|
+
submitTask(body: {
|
|
37
|
+
prompt: string;
|
|
38
|
+
threadId?: number;
|
|
39
|
+
profileId?: number;
|
|
40
|
+
maxSteps?: number;
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
ret: number;
|
|
44
|
+
data: {
|
|
45
|
+
taskId: string;
|
|
46
|
+
};
|
|
47
|
+
msg: string;
|
|
48
|
+
} | {
|
|
49
|
+
ret: number;
|
|
50
|
+
msg: any;
|
|
51
|
+
data?: undefined;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* 获取任务状态
|
|
55
|
+
*/
|
|
56
|
+
getTaskStatus(taskId: string): Promise<{
|
|
57
|
+
ret: number;
|
|
58
|
+
data: import("../service/agent-task-queue.service").AgentTask;
|
|
59
|
+
msg: string;
|
|
60
|
+
} | {
|
|
61
|
+
ret: number;
|
|
62
|
+
msg: any;
|
|
63
|
+
data?: undefined;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* 取消任务
|
|
67
|
+
*/
|
|
68
|
+
cancelTask(taskId: string): Promise<{
|
|
69
|
+
ret: number;
|
|
70
|
+
data: {
|
|
71
|
+
cancelled: boolean;
|
|
72
|
+
};
|
|
73
|
+
msg: string;
|
|
74
|
+
} | {
|
|
75
|
+
ret: number;
|
|
76
|
+
msg: any;
|
|
77
|
+
data?: undefined;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* 获取队列状态
|
|
81
|
+
*/
|
|
82
|
+
getQueueStatus(): Promise<{
|
|
83
|
+
ret: number;
|
|
84
|
+
data: {
|
|
85
|
+
total: number;
|
|
86
|
+
pending: number;
|
|
87
|
+
running: number;
|
|
88
|
+
completed: number;
|
|
89
|
+
failed: number;
|
|
90
|
+
maxConcurrency: number;
|
|
91
|
+
};
|
|
92
|
+
msg: string;
|
|
93
|
+
} | {
|
|
94
|
+
ret: number;
|
|
95
|
+
msg: any;
|
|
96
|
+
data?: undefined;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* 获取用户任务列表
|
|
100
|
+
*/
|
|
101
|
+
getUserTasks(): Promise<{
|
|
102
|
+
ret: number;
|
|
103
|
+
data: import("../service/agent-task-queue.service").AgentTask[];
|
|
104
|
+
msg: string;
|
|
105
|
+
} | {
|
|
106
|
+
ret: number;
|
|
107
|
+
msg: any;
|
|
108
|
+
data?: undefined;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* 中止 Agent 执行
|
|
112
|
+
*/
|
|
113
|
+
abortAgent(threadId: number): Promise<{
|
|
114
|
+
ret: number;
|
|
115
|
+
data: any;
|
|
116
|
+
msg: string;
|
|
117
|
+
} | {
|
|
118
|
+
ret: number;
|
|
119
|
+
msg: any;
|
|
120
|
+
data?: undefined;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* SSE 断线重连
|
|
124
|
+
*/
|
|
125
|
+
reconnectAgent(threadId: number): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* 编辑消息后重新生成
|
|
128
|
+
*/
|
|
129
|
+
editMessage(body: {
|
|
130
|
+
threadId: number;
|
|
131
|
+
messageId: number;
|
|
132
|
+
content: string;
|
|
133
|
+
}): Promise<{
|
|
134
|
+
ret: number;
|
|
135
|
+
data: any;
|
|
136
|
+
msg: string;
|
|
137
|
+
} | {
|
|
138
|
+
ret: number;
|
|
139
|
+
msg: any;
|
|
140
|
+
data?: undefined;
|
|
141
|
+
}>;
|
|
142
|
+
/**
|
|
143
|
+
* 重新生成最后一条 AI 回复
|
|
144
|
+
*/
|
|
145
|
+
regenerate(body: {
|
|
146
|
+
threadId: number;
|
|
147
|
+
}): Promise<{
|
|
148
|
+
ret: number;
|
|
149
|
+
data: any;
|
|
150
|
+
msg: string;
|
|
151
|
+
} | {
|
|
152
|
+
ret: number;
|
|
153
|
+
msg: any;
|
|
154
|
+
data?: undefined;
|
|
155
|
+
}>;
|
|
156
|
+
/**
|
|
157
|
+
* 从指定位置分叉创建新对话
|
|
158
|
+
*/
|
|
159
|
+
forkThread(body: {
|
|
160
|
+
threadId: number;
|
|
161
|
+
messageId: number;
|
|
162
|
+
title?: string;
|
|
163
|
+
}): Promise<{
|
|
164
|
+
ret: number;
|
|
165
|
+
data: any;
|
|
166
|
+
msg: string;
|
|
167
|
+
} | {
|
|
168
|
+
ret: number;
|
|
169
|
+
msg: any;
|
|
170
|
+
data?: undefined;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* 引擎工具列表诊断
|
|
174
|
+
*/
|
|
175
|
+
diagnose(): Promise<{
|
|
176
|
+
ret: number;
|
|
177
|
+
data: {
|
|
178
|
+
toolCount: number;
|
|
179
|
+
tools: {
|
|
180
|
+
name: any;
|
|
181
|
+
description: any;
|
|
182
|
+
}[];
|
|
183
|
+
available: boolean;
|
|
184
|
+
};
|
|
185
|
+
msg: string;
|
|
186
|
+
} | {
|
|
187
|
+
ret: number;
|
|
188
|
+
msg: any;
|
|
189
|
+
data?: undefined;
|
|
190
|
+
}>;
|
|
191
|
+
/**
|
|
192
|
+
* 写入 SSE 事件
|
|
193
|
+
*/
|
|
194
|
+
private writeSSE;
|
|
195
|
+
/**
|
|
196
|
+
* 获取当前用户 ID
|
|
197
|
+
*/
|
|
198
|
+
private getUserId;
|
|
199
|
+
}
|