@kelvinjhu/lexiang-search 1.0.0 → 1.0.2
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 +48 -183
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -9
- package/dist/cli.js.map +1 -1
- package/dist/constants/api.constants.d.ts.map +1 -1
- package/dist/constants/api.constants.js +17 -15
- package/dist/constants/api.constants.js.map +1 -1
- package/dist/dto/ai-qa-request.dto.d.ts +8 -9
- package/dist/dto/ai-qa-request.dto.d.ts.map +1 -1
- package/dist/dto/ai-qa-request.dto.js +49 -62
- package/dist/dto/ai-qa-request.dto.js.map +1 -1
- package/dist/dto/ai-qa-response.dto.d.ts.map +1 -1
- package/dist/dto/ai-qa-response.dto.js +16 -20
- package/dist/dto/ai-qa-response.dto.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +57 -32
- package/dist/server.js.map +1 -1
- package/dist/services/ai-qa.service.d.ts +12 -3
- package/dist/services/ai-qa.service.d.ts.map +1 -1
- package/dist/services/ai-qa.service.js +60 -34
- package/dist/services/ai-qa.service.js.map +1 -1
- package/dist/services/lexiang-api.service.d.ts +6 -2
- package/dist/services/lexiang-api.service.d.ts.map +1 -1
- package/dist/services/lexiang-api.service.js +76 -57
- package/dist/services/lexiang-api.service.js.map +1 -1
- package/dist/tools/ai-qa-stream.tool.d.ts +1 -9
- package/dist/tools/ai-qa-stream.tool.d.ts.map +1 -1
- package/dist/tools/ai-qa-stream.tool.js +36 -71
- package/dist/tools/ai-qa-stream.tool.js.map +1 -1
- package/dist/tools/ai-qa.tool.d.ts +1 -9
- package/dist/tools/ai-qa.tool.d.ts.map +1 -1
- package/dist/tools/ai-qa.tool.js +11 -23
- package/dist/tools/ai-qa.tool.js.map +1 -1
- package/dist/types/lexiang-api.types.js +1 -2
- package/dist/types/lexiang-api.types.js.map +1 -1
- package/dist/types/mcp.types.js +1 -2
- package/dist/types/mcp.types.js.map +1 -1
- package/dist/utils/error-handler.d.ts +37 -32
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +46 -79
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/logger.d.ts +1 -0
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +6 -8
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/validator.d.ts +4 -15
- package/dist/utils/validator.d.ts.map +1 -1
- package/dist/utils/validator.js +17 -66
- package/dist/utils/validator.js.map +1 -1
- package/package.json +6 -5
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* 乐享API客户端服务
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
exports.LexiangApiClient = void 0;
|
|
10
|
-
const axios_1 = __importDefault(require("axios"));
|
|
11
|
-
const logger_1 = require("../utils/logger");
|
|
12
|
-
const error_handler_1 = require("../utils/error-handler");
|
|
13
|
-
const api_constants_1 = require("../constants/api.constants");
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import { logger } from '../utils/logger.js';
|
|
6
|
+
import { TokenError, ApiError, NetworkError, TimeoutError, handleError, } from '../utils/error-handler.js';
|
|
7
|
+
import { LEXIANG_API_CONFIG, TIMEOUT_CONFIG, TOKEN_CACHE_TTL } from '../constants/api.constants.js';
|
|
14
8
|
/**
|
|
15
9
|
* 乐享API客户端
|
|
16
10
|
*/
|
|
17
|
-
class LexiangApiClient {
|
|
11
|
+
export class LexiangApiClient {
|
|
18
12
|
httpClient;
|
|
19
13
|
tokenCache = new Map();
|
|
20
14
|
constructor() {
|
|
21
|
-
this.httpClient =
|
|
22
|
-
baseURL:
|
|
23
|
-
timeout:
|
|
15
|
+
this.httpClient = axios.create({
|
|
16
|
+
baseURL: LEXIANG_API_CONFIG.BASE_URL,
|
|
17
|
+
timeout: TIMEOUT_CONFIG.DEFAULT,
|
|
24
18
|
headers: {
|
|
25
19
|
'Content-Type': 'application/json; charset=utf-8',
|
|
26
20
|
},
|
|
27
21
|
});
|
|
28
22
|
this.httpClient.interceptors.request.use((config) => {
|
|
29
|
-
|
|
23
|
+
logger.debug('API Request', { url: config.url, method: config.method });
|
|
30
24
|
return config;
|
|
31
25
|
});
|
|
32
26
|
this.httpClient.interceptors.response.use((response) => response, (error) => this.handleAxiosError(error));
|
|
@@ -39,19 +33,19 @@ class LexiangApiClient {
|
|
|
39
33
|
// 服务器返回错误响应
|
|
40
34
|
const status = error.response.status;
|
|
41
35
|
const data = error.response.data;
|
|
42
|
-
|
|
43
|
-
throw new
|
|
36
|
+
logger.error('API Error Response', { status, data });
|
|
37
|
+
throw new ApiError(`API error: ${status}`, { status, data });
|
|
44
38
|
}
|
|
45
39
|
else if (error.request) {
|
|
46
40
|
// 请求已发送但无响应
|
|
47
41
|
if (error.code === 'ECONNABORTED') {
|
|
48
|
-
throw new
|
|
42
|
+
throw new TimeoutError('Request timeout', { timeout: error.config?.timeout });
|
|
49
43
|
}
|
|
50
|
-
throw new
|
|
44
|
+
throw new NetworkError('Network error', { message: error.message });
|
|
51
45
|
}
|
|
52
46
|
else {
|
|
53
47
|
// 请求配置错误
|
|
54
|
-
|
|
48
|
+
logger.error('Request config error', { message: error.message });
|
|
55
49
|
throw new Error(`Request config error: ${error.message}`);
|
|
56
50
|
}
|
|
57
51
|
}
|
|
@@ -74,29 +68,30 @@ class LexiangApiClient {
|
|
|
74
68
|
const cacheKey = this.getCacheKey(appKey);
|
|
75
69
|
const cached = this.tokenCache.get(cacheKey);
|
|
76
70
|
if (cached && this.isTokenValid(cached)) {
|
|
77
|
-
|
|
71
|
+
logger.debug('Token cache hit', { appKey });
|
|
78
72
|
return cached.token;
|
|
79
73
|
}
|
|
80
|
-
|
|
74
|
+
logger.info('Fetching new access token', { appKey });
|
|
81
75
|
try {
|
|
82
|
-
const response = await this.httpClient.post(
|
|
76
|
+
const response = await this.httpClient.post(LEXIANG_API_CONFIG.TOKEN_PATH, {
|
|
83
77
|
app_key: appKey,
|
|
84
78
|
app_secret: appSecret,
|
|
79
|
+
grant_type: 'client_credentials', // 必须添加此参数
|
|
85
80
|
});
|
|
86
81
|
const token = response.data.access_token;
|
|
87
|
-
const expiresIn = response.data.expires_in ||
|
|
82
|
+
const expiresIn = response.data.expires_in || TOKEN_CACHE_TTL;
|
|
88
83
|
const expiresAt = Date.now() + expiresIn * 1000 - 60000; // 提前1分钟过期
|
|
89
84
|
const cacheItem = {
|
|
90
85
|
token,
|
|
91
86
|
expiresAt,
|
|
92
87
|
};
|
|
93
88
|
this.tokenCache.set(cacheKey, cacheItem);
|
|
94
|
-
|
|
89
|
+
logger.info('Token cached successfully', { appKey, expiresAt: new Date(expiresAt).toISOString() });
|
|
95
90
|
return token;
|
|
96
91
|
}
|
|
97
92
|
catch (error) {
|
|
98
|
-
|
|
99
|
-
throw new
|
|
93
|
+
logger.error('Failed to get access token', { appKey, error });
|
|
94
|
+
throw new TokenError('Failed to get access token', handleError(error).toJSON());
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
/**
|
|
@@ -105,80 +100,104 @@ class LexiangApiClient {
|
|
|
105
100
|
clearTokenCache(appKey) {
|
|
106
101
|
const cacheKey = this.getCacheKey(appKey);
|
|
107
102
|
this.tokenCache.delete(cacheKey);
|
|
108
|
-
|
|
103
|
+
logger.info('Token cache cleared', { appKey });
|
|
109
104
|
}
|
|
110
105
|
/**
|
|
111
106
|
* 非流式AI问答
|
|
112
107
|
*/
|
|
113
108
|
async queryAiQa(accessToken, staffId, request) {
|
|
114
109
|
try {
|
|
115
|
-
|
|
110
|
+
logger.info('Calling AI QA API', { query: request.query });
|
|
116
111
|
const startTime = Date.now();
|
|
117
|
-
const response = await this.httpClient.post(
|
|
112
|
+
const response = await this.httpClient.post(LEXIANG_API_CONFIG.API_PATH, request, {
|
|
118
113
|
headers: {
|
|
119
114
|
Authorization: `Bearer ${accessToken}`,
|
|
120
115
|
'x-staff-id': staffId,
|
|
121
116
|
},
|
|
122
|
-
timeout:
|
|
117
|
+
timeout: TIMEOUT_CONFIG.DEFAULT,
|
|
123
118
|
});
|
|
124
119
|
const duration = Date.now() - startTime;
|
|
125
|
-
|
|
120
|
+
logger.info('AI QA API success', { duration, request_id: response.data.request_id });
|
|
126
121
|
return response.data;
|
|
127
122
|
}
|
|
128
123
|
catch (error) {
|
|
129
|
-
|
|
124
|
+
logger.error('AI QA API failed', { query: request.query, error });
|
|
130
125
|
throw error;
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
128
|
/**
|
|
134
|
-
* 流式AI问答
|
|
129
|
+
* 流式AI问答 (Generator模式)
|
|
135
130
|
*/
|
|
136
|
-
async
|
|
131
|
+
async *streamAiQaGenerator(accessToken, staffId, request) {
|
|
137
132
|
try {
|
|
138
|
-
|
|
133
|
+
logger.info('Calling AI QA Stream API', { query: request.query });
|
|
139
134
|
const startTime = Date.now();
|
|
140
|
-
const response = await this.httpClient.post(
|
|
135
|
+
const response = await this.httpClient.post(LEXIANG_API_CONFIG.API_PATH, { ...request, stream: true }, {
|
|
141
136
|
headers: {
|
|
142
137
|
Authorization: `Bearer ${accessToken}`,
|
|
143
138
|
'x-staff-id': staffId,
|
|
144
139
|
Accept: 'text/event-stream',
|
|
145
140
|
},
|
|
146
141
|
responseType: 'stream',
|
|
147
|
-
timeout:
|
|
142
|
+
timeout: TIMEOUT_CONFIG.STREAM,
|
|
148
143
|
});
|
|
149
144
|
const stream = response.data;
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
let buffer = '';
|
|
146
|
+
for await (const chunk of stream) {
|
|
147
|
+
buffer += chunk.toString('utf-8');
|
|
148
|
+
const lines = buffer.split('\n');
|
|
149
|
+
// 保留最后一行,因为它可能不完整
|
|
150
|
+
buffer = lines.pop() || '';
|
|
152
151
|
for (const line of lines) {
|
|
153
|
-
if (line.startsWith('data:')
|
|
152
|
+
if (line.startsWith('data:')) {
|
|
154
153
|
try {
|
|
155
|
-
const dataLine = line.replace(/^data:\s*/, '')
|
|
154
|
+
const dataLine = line.replace(/^data:\s*/, '');
|
|
156
155
|
if (dataLine.trim()) {
|
|
157
156
|
const data = JSON.parse(dataLine);
|
|
158
|
-
|
|
157
|
+
yield data;
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
catch (e) {
|
|
162
|
-
|
|
161
|
+
logger.debug('Failed to parse SSE chunk', { line });
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
165
|
+
}
|
|
166
|
+
// 处理剩余的buffer
|
|
167
|
+
if (buffer && buffer.startsWith('data:')) {
|
|
168
|
+
try {
|
|
169
|
+
const dataLine = buffer.replace(/^data:\s*/, '');
|
|
170
|
+
if (dataLine.trim()) {
|
|
171
|
+
const data = JSON.parse(dataLine);
|
|
172
|
+
yield data;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
logger.debug('Failed to parse final SSE chunk', { buffer });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const duration = Date.now() - startTime;
|
|
180
|
+
logger.info('AI QA Stream completed', { duration });
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
logger.error('AI QA Stream API failed', { query: request.query, error });
|
|
184
|
+
throw handleError(error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @deprecated 使用 streamAiQaGenerator 代替
|
|
189
|
+
*/
|
|
190
|
+
async streamAiQa(accessToken, staffId, request, onChunk, onComplete, onError) {
|
|
191
|
+
try {
|
|
192
|
+
const generator = this.streamAiQaGenerator(accessToken, staffId, request);
|
|
193
|
+
for await (const chunk of generator) {
|
|
194
|
+
onChunk(chunk);
|
|
195
|
+
}
|
|
196
|
+
onComplete();
|
|
176
197
|
}
|
|
177
198
|
catch (error) {
|
|
178
|
-
|
|
179
|
-
onError((0, error_handler_1.handleError)(error));
|
|
199
|
+
onError(error);
|
|
180
200
|
}
|
|
181
201
|
}
|
|
182
202
|
}
|
|
183
|
-
exports.LexiangApiClient = LexiangApiClient;
|
|
184
203
|
//# sourceMappingURL=lexiang-api.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexiang-api.service.js","sourceRoot":"","sources":["../../src/services/lexiang-api.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lexiang-api.service.js","sourceRoot":"","sources":["../../src/services/lexiang-api.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAoC,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAUpG;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACnB,UAAU,CAAgB;IAC1B,UAAU,GAAgC,IAAI,GAAG,EAAE,CAAC;IAE5D;QACE,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;YAC7B,OAAO,EAAE,kBAAkB,CAAC,QAAQ;YACpC,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,OAAO,EAAE;gBACP,cAAc,EAAE,iCAAiC;aAClD;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAClD,MAAM,CAAC,KAAK,CAAC,a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C;YAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACzE,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CACd,WAAmB,EACnB,OAAe,EACf,OAAoB,EACpB,OAAqC,EACrC,UAAsB,EACtB,OAA+B;QAE7B,IAAI,CAAC;YACD,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAC1E,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;gBAClC,OAAO,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;YACD,UAAU,EAAE,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAc,CAAC,CAAC;QAC5B,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI问答工具处理器(流式)
|
|
3
3
|
*/
|
|
4
|
-
import { ToolHandler } from '../types/mcp.types';
|
|
4
|
+
import { ToolHandler } from '../types/mcp.types.js';
|
|
5
5
|
/**
|
|
6
6
|
* 流式AI问答工具
|
|
7
7
|
*/
|
|
@@ -11,14 +11,6 @@ export declare class AiQaStreamToolHandler implements ToolHandler {
|
|
|
11
11
|
inputSchema: {
|
|
12
12
|
type: "object";
|
|
13
13
|
properties: {
|
|
14
|
-
app_key: {
|
|
15
|
-
type: string;
|
|
16
|
-
description: string;
|
|
17
|
-
};
|
|
18
|
-
app_secret: {
|
|
19
|
-
type: string;
|
|
20
|
-
description: string;
|
|
21
|
-
};
|
|
22
14
|
query: {
|
|
23
15
|
type: string;
|
|
24
16
|
description: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-qa-stream.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-qa-stream.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ai-qa-stream.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-qa-stream.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAOpD;;GAEG;AACH,qBAAa,qBAAsB,YAAW,WAAW;IACvD,IAAI,SAAkB;IACtB,WAAW,SAAoD;IAC/D,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA0ET;IAEF,OAAO,CAAC,WAAW,CAAc;;IAM3B,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAU/E;;OAEG;YACY,cAAc;CAkC9B"}
|
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* AI问答工具处理器(流式)
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const logger_1 = require("../utils/logger");
|
|
11
|
-
const error_handler_1 = require("../utils/error-handler");
|
|
4
|
+
import { validateDto } from '../utils/validator.js';
|
|
5
|
+
import { AiQaRequestDto } from '../dto/ai-qa-request.dto.js';
|
|
6
|
+
import { AiQaService } from '../services/ai-qa.service.js';
|
|
7
|
+
import { logger } from '../utils/logger.js';
|
|
8
|
+
import { handleError } from '../utils/error-handler.js';
|
|
12
9
|
/**
|
|
13
10
|
* 流式AI问答工具
|
|
14
11
|
*/
|
|
15
|
-
class AiQaStreamToolHandler {
|
|
12
|
+
export class AiQaStreamToolHandler {
|
|
16
13
|
name = 'ai_qa_stream';
|
|
17
14
|
description = '乐享AI问答接口 - 流式模式,通过SSE协议实时推送增量内容。支持多种问答模式和多轮对话。';
|
|
18
15
|
inputSchema = {
|
|
19
16
|
type: 'object',
|
|
20
17
|
properties: {
|
|
21
|
-
app_key: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
description: '乐享应用Key',
|
|
24
|
-
},
|
|
25
|
-
app_secret: {
|
|
26
|
-
type: 'string',
|
|
27
|
-
description: '乐享应用密钥',
|
|
28
|
-
},
|
|
29
18
|
query: {
|
|
30
19
|
type: 'string',
|
|
31
20
|
description: '用户问题,最长1024字符',
|
|
@@ -33,7 +22,7 @@ class AiQaStreamToolHandler {
|
|
|
33
22
|
},
|
|
34
23
|
targets: {
|
|
35
24
|
type: 'array',
|
|
36
|
-
description: '知识范围数组,最多20
|
|
25
|
+
description: '知识范围数组,最多20个对象。如果不传,默认搜索全站知识。',
|
|
37
26
|
items: {
|
|
38
27
|
type: 'object',
|
|
39
28
|
properties: {
|
|
@@ -96,16 +85,16 @@ class AiQaStreamToolHandler {
|
|
|
96
85
|
default: 'zh-CN',
|
|
97
86
|
},
|
|
98
87
|
},
|
|
99
|
-
required: ['
|
|
88
|
+
required: ['query'],
|
|
100
89
|
};
|
|
101
90
|
aiQaService;
|
|
102
91
|
constructor() {
|
|
103
|
-
this.aiQaService = new
|
|
92
|
+
this.aiQaService = new AiQaService();
|
|
104
93
|
}
|
|
105
94
|
async execute(params) {
|
|
106
|
-
|
|
95
|
+
logger.info('Executing ai_qa_stream tool', { params });
|
|
107
96
|
// 校验参数
|
|
108
|
-
const dto = await
|
|
97
|
+
const dto = await validateDto(AiQaRequestDto, params);
|
|
109
98
|
// 返回异步生成器用于流式响应
|
|
110
99
|
return this.streamResponse(dto);
|
|
111
100
|
}
|
|
@@ -113,59 +102,35 @@ class AiQaStreamToolHandler {
|
|
|
113
102
|
* 流式响应生成器
|
|
114
103
|
*/
|
|
115
104
|
async *streamResponse(dto) {
|
|
116
|
-
const chunks = [];
|
|
117
|
-
const resultPromise = new Promise((resolve, reject) => {
|
|
118
|
-
this.aiQaService.executeStream(dto,
|
|
119
|
-
// onChunk
|
|
120
|
-
(deltaContent, content, isStop) => {
|
|
121
|
-
const chunk = {
|
|
122
|
-
type: 'chunk',
|
|
123
|
-
delta_content: deltaContent,
|
|
124
|
-
content: content,
|
|
125
|
-
is_stop: isStop,
|
|
126
|
-
};
|
|
127
|
-
chunks.push(chunk);
|
|
128
|
-
},
|
|
129
|
-
// onComplete
|
|
130
|
-
(sessionId) => {
|
|
131
|
-
logger_1.logger.info('Stream AI QA completed', { session_id: sessionId });
|
|
132
|
-
const completeChunk = {
|
|
133
|
-
type: 'complete',
|
|
134
|
-
session_id: sessionId,
|
|
135
|
-
is_stop: true,
|
|
136
|
-
};
|
|
137
|
-
chunks.push(completeChunk);
|
|
138
|
-
resolve(sessionId);
|
|
139
|
-
},
|
|
140
|
-
// onError
|
|
141
|
-
(error) => {
|
|
142
|
-
logger_1.logger.error('Stream AI QA error', { error });
|
|
143
|
-
reject(error);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
// 使用事件循环的方式来yield chunks
|
|
147
|
-
let currentIndex = 0;
|
|
148
|
-
while (true) {
|
|
149
|
-
// Yield当前可用的chunks
|
|
150
|
-
while (currentIndex < chunks.length) {
|
|
151
|
-
yield chunks[currentIndex];
|
|
152
|
-
currentIndex++;
|
|
153
|
-
}
|
|
154
|
-
// 检查是否完成
|
|
155
|
-
if (chunks.some(chunk => typeof chunk === 'object' && chunk !== null && 'is_stop' in chunk && chunk.is_stop)) {
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
// 等待一小段时间
|
|
159
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
160
|
-
}
|
|
161
|
-
// 等待promise完成(确保错误被处理)
|
|
162
105
|
try {
|
|
163
|
-
|
|
106
|
+
const generator = this.aiQaService.executeStreamGenerator(dto);
|
|
107
|
+
let sessionId = '';
|
|
108
|
+
for await (const chunk of generator) {
|
|
109
|
+
if (chunk.session_id && !sessionId) {
|
|
110
|
+
sessionId = chunk.session_id;
|
|
111
|
+
}
|
|
112
|
+
// 只有当有增量内容时才yield
|
|
113
|
+
if (chunk.delta_content) {
|
|
114
|
+
yield {
|
|
115
|
+
type: 'chunk',
|
|
116
|
+
delta_content: chunk.delta_content,
|
|
117
|
+
content: chunk.content,
|
|
118
|
+
is_stop: chunk.is_stop,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// 流结束,发送完成信号
|
|
123
|
+
logger.info('Stream AI QA completed', { session_id: sessionId });
|
|
124
|
+
yield {
|
|
125
|
+
type: 'complete',
|
|
126
|
+
session_id: sessionId,
|
|
127
|
+
is_stop: true,
|
|
128
|
+
};
|
|
164
129
|
}
|
|
165
130
|
catch (error) {
|
|
166
|
-
|
|
131
|
+
logger.error('Stream AI QA error', { error });
|
|
132
|
+
throw handleError(error);
|
|
167
133
|
}
|
|
168
134
|
}
|
|
169
135
|
}
|
|
170
|
-
exports.AiQaStreamToolHandler = AiQaStreamToolHandler;
|
|
171
136
|
//# sourceMappingURL=ai-qa-stream.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-qa-stream.tool.js","sourceRoot":"","sources":["../../src/tools/ai-qa-stream.tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-qa-stream.tool.js","sourceRoot":"","sources":["../../src/tools/ai-qa-stream.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,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;gBAClB,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;oBACxB,MAAM;wBACJ,IAAI,EAAE,OAAO;wBACb,aAAa,EAAE,KAAK,CAAC,aAAa;wBAClC,OAAO,EAAE,KAAK,CAAC,OAAO;wBACtB,OAAO,EAAE,KAAK,CAAC,OAAO;qBACvB,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,aAAa;YACb,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC;YACjE,MAAM;gBACJ,IAAI,EAAE,UAAU;gBAChB,UAAU,EAAE,SAAS;gBACrB,OAAO,EAAE,IAAI;aACd,CAAC;QAEJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC9C,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AI问答工具处理器(非流式)
|
|
3
3
|
*/
|
|
4
|
-
import { ToolHandler } from '../types/mcp.types';
|
|
4
|
+
import { ToolHandler } from '../types/mcp.types.js';
|
|
5
5
|
/**
|
|
6
6
|
* 非流式AI问答工具
|
|
7
7
|
*/
|
|
@@ -11,14 +11,6 @@ export declare class AiQaToolHandler implements ToolHandler {
|
|
|
11
11
|
inputSchema: {
|
|
12
12
|
type: "object";
|
|
13
13
|
properties: {
|
|
14
|
-
app_key: {
|
|
15
|
-
type: string;
|
|
16
|
-
description: string;
|
|
17
|
-
};
|
|
18
|
-
app_secret: {
|
|
19
|
-
type: string;
|
|
20
|
-
description: string;
|
|
21
|
-
};
|
|
22
14
|
query: {
|
|
23
15
|
type: string;
|
|
24
16
|
description: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-qa.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-qa.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ai-qa.tool.d.ts","sourceRoot":"","sources":["../../src/tools/ai-qa.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAMpD;;GAEG;AACH,qBAAa,eAAgB,YAAW,WAAW;IACjD,IAAI,SAAW;IACf,WAAW,SAA+C;IAC1D,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA0ET;IAEF,OAAO,CAAC,WAAW,CAAc;;IAM3B,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAgBjD"}
|
package/dist/tools/ai-qa.tool.js
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* AI问答工具处理器(非流式)
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const ai_qa_service_1 = require("../services/ai-qa.service");
|
|
10
|
-
const logger_1 = require("../utils/logger");
|
|
4
|
+
import { validateDto } from '../utils/validator.js';
|
|
5
|
+
import { AiQaRequestDto } from '../dto/ai-qa-request.dto.js';
|
|
6
|
+
import { AiQaService } from '../services/ai-qa.service.js';
|
|
7
|
+
import { logger } from '../utils/logger.js';
|
|
11
8
|
/**
|
|
12
9
|
* 非流式AI问答工具
|
|
13
10
|
*/
|
|
14
|
-
class AiQaToolHandler {
|
|
11
|
+
export class AiQaToolHandler {
|
|
15
12
|
name = 'ai_qa';
|
|
16
13
|
description = '乐享AI问答接口 - 非流式模式,一次性返回完整答案。支持多种问答模式和多轮对话。';
|
|
17
14
|
inputSchema = {
|
|
18
15
|
type: 'object',
|
|
19
16
|
properties: {
|
|
20
|
-
app_key: {
|
|
21
|
-
type: 'string',
|
|
22
|
-
description: '乐享应用Key',
|
|
23
|
-
},
|
|
24
|
-
app_secret: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
description: '乐享应用密钥',
|
|
27
|
-
},
|
|
28
17
|
query: {
|
|
29
18
|
type: 'string',
|
|
30
19
|
description: '用户问题,最长1024字符',
|
|
@@ -32,7 +21,7 @@ class AiQaToolHandler {
|
|
|
32
21
|
},
|
|
33
22
|
targets: {
|
|
34
23
|
type: 'array',
|
|
35
|
-
description: '知识范围数组,最多20
|
|
24
|
+
description: '知识范围数组,最多20个对象。如果不传,默认搜索全站知识。',
|
|
36
25
|
items: {
|
|
37
26
|
type: 'object',
|
|
38
27
|
properties: {
|
|
@@ -95,24 +84,23 @@ class AiQaToolHandler {
|
|
|
95
84
|
default: 'zh-CN',
|
|
96
85
|
},
|
|
97
86
|
},
|
|
98
|
-
required: ['
|
|
87
|
+
required: ['query'],
|
|
99
88
|
};
|
|
100
89
|
aiQaService;
|
|
101
90
|
constructor() {
|
|
102
|
-
this.aiQaService = new
|
|
91
|
+
this.aiQaService = new AiQaService();
|
|
103
92
|
}
|
|
104
93
|
async execute(params) {
|
|
105
|
-
|
|
94
|
+
logger.info('Executing ai_qa tool', { params });
|
|
106
95
|
// 校验参数
|
|
107
|
-
const dto = await
|
|
96
|
+
const dto = await validateDto(AiQaRequestDto, params);
|
|
108
97
|
// 执行AI问答
|
|
109
98
|
const result = await this.aiQaService.executeNonStream(dto);
|
|
110
|
-
|
|
99
|
+
logger.info('ai_qa tool executed successfully', { session_id: result.session_id });
|
|
111
100
|
return {
|
|
112
101
|
success: true,
|
|
113
102
|
data: result,
|
|
114
103
|
};
|
|
115
104
|
}
|
|
116
105
|
}
|
|
117
|
-
exports.AiQaToolHandler = AiQaToolHandler;
|
|
118
106
|
//# sourceMappingURL=ai-qa.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-qa.tool.js","sourceRoot":"","sources":["../../src/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,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexiang-api.types.js","sourceRoot":"","sources":["../../src/types/lexiang-api.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lexiang-api.types.js","sourceRoot":"","sources":["../../src/types/lexiang-api.types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/dist/types/mcp.types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.types.js","sourceRoot":"","sources":["../../src/types/mcp.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp.types.js","sourceRoot":"","sources":["../../src/types/mcp.types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|