@baishuyun/chat-backend 0.0.18 → 0.0.19
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/CHANGELOG.md +7 -0
- package/config/default.ts +5 -5
- package/package.json +2 -2
- package/src/controllers/agent/bots.controller.ts +1 -1
- package/src/controllers/form/attachment-upload.controller.ts +16 -15
- package/src/controllers/form/conversation/clear.controller.ts +12 -15
- package/src/controllers/form/fill/batch-fill.controller.ts +1 -1
- package/src/controllers/form/fill/fill.controller.ts +1 -1
- package/src/controllers/report/query/query.controller.ts +1 -1
- package/src/services/fetchCozeInfo.ts +1 -1
package/CHANGELOG.md
CHANGED
package/config/default.ts
CHANGED
|
@@ -17,26 +17,26 @@ export default {
|
|
|
17
17
|
agent: {
|
|
18
18
|
host: process.env.AGENT_HOST || '47.99.202.157',
|
|
19
19
|
|
|
20
|
-
apiAuthKey: process.env.
|
|
20
|
+
apiAuthKey: process.env.BOT_API_KEY,
|
|
21
21
|
|
|
22
22
|
userId: process.env.BUILTIN_COZE_USER_ID,
|
|
23
23
|
|
|
24
24
|
common: {
|
|
25
|
-
baseUrl: `
|
|
25
|
+
baseUrl: `https://${process.env.AGENT_HOST}/v3/`,
|
|
26
26
|
apiKey: process.env.BOT_API_KEY, // load from env
|
|
27
27
|
},
|
|
28
28
|
|
|
29
29
|
form: {
|
|
30
30
|
build: {
|
|
31
31
|
botId: process.env.BUILD_BOT_ID || '7579927677256073216',
|
|
32
|
-
baseUrl: `
|
|
32
|
+
baseUrl: `https://${process.env.AGENT_HOST}/v3/`,
|
|
33
33
|
apiKey: process.env.BOT_API_KEY, // load from env
|
|
34
34
|
intentBotId: process.env.FORM_BUILD_INTENT_BOT_ID || '7615799745042186240',
|
|
35
35
|
},
|
|
36
36
|
|
|
37
37
|
fill: {
|
|
38
38
|
botId: process.env.FILL_BOT_ID || '7586483957357608960',
|
|
39
|
-
baseUrl: `
|
|
39
|
+
baseUrl: `https://${process.env.AGENT_HOST}/v3/`,
|
|
40
40
|
apiKey: process.env.BOT_API_KEY, // load from env
|
|
41
41
|
ocrApiKey: process.env.OCR_API_KEY || '', // load from env
|
|
42
42
|
},
|
|
@@ -45,7 +45,7 @@ export default {
|
|
|
45
45
|
report: {
|
|
46
46
|
query: {
|
|
47
47
|
botId: process.env.QUERY_BOT_ID || '7595888372090929152',
|
|
48
|
-
baseUrl: `
|
|
48
|
+
baseUrl: `https://${process.env.AGENT_HOST}/v3/`,
|
|
49
49
|
apiKey: process.env.BOT_API_KEY, // load from env
|
|
50
50
|
},
|
|
51
51
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baishuyun/chat-backend",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"parse-sse": "^0.1.0",
|
|
24
24
|
"pino": "^10.1.0",
|
|
25
25
|
"zod": "^4.1.13",
|
|
26
|
-
"@baishuyun/coze-provider": "0.1.0",
|
|
27
26
|
"@baishuyun/types": "1.1.0",
|
|
27
|
+
"@baishuyun/coze-provider": "0.1.1",
|
|
28
28
|
"@baishuyun/agents": "0.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
@@ -6,7 +6,7 @@ import type { ICozeInfoOfTokenExchange } from '../../types/coze.js';
|
|
|
6
6
|
|
|
7
7
|
export const listBots = async (c: Context) => {
|
|
8
8
|
const agentHost = config.get<string>('agent.host');
|
|
9
|
-
const apiBots = `
|
|
9
|
+
const apiBots = `https://${agentHost}/v1/bots`;
|
|
10
10
|
const cozeInfo = c.get('X-Coze-Info') as ICozeInfoOfTokenExchange;
|
|
11
11
|
|
|
12
12
|
logger.debug(`Fetching bots from ${apiBots} with cozeToken: ${cozeInfo.cozeToken}`);
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { type Context } from
|
|
2
|
-
import config from
|
|
3
|
-
import { logger } from
|
|
4
|
-
import { parseImg } from
|
|
1
|
+
import { type Context } from 'hono';
|
|
2
|
+
import config from 'config';
|
|
3
|
+
import { logger } from '../../logger/index.js';
|
|
4
|
+
import { parseImg } from './fill/utils.js';
|
|
5
5
|
|
|
6
6
|
export const uploadAttachment = async (c: Context) => {
|
|
7
7
|
const formData = await c.req.formData();
|
|
8
|
-
const file = formData.get(
|
|
8
|
+
const file = formData.get('file'); // as FormData | null;
|
|
9
9
|
// 校验文件是否存在
|
|
10
10
|
if (!file || !(file instanceof Blob)) {
|
|
11
|
-
return c.json({ error:
|
|
11
|
+
return c.json({ error: '请上传有效的文件' }, 400);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const forwardFormData = new FormData();
|
|
15
|
-
forwardFormData.append(
|
|
15
|
+
forwardFormData.append('file', file);
|
|
16
16
|
|
|
17
|
-
const apiKey = config.get<string>(
|
|
18
|
-
const host = config.get<string>(
|
|
19
|
-
const api = `
|
|
17
|
+
const apiKey = config.get<string>('agent.apiAuthKey');
|
|
18
|
+
const host = config.get<string>('agent.host');
|
|
19
|
+
const api = `https://${host}/v1/files/upload`;
|
|
20
20
|
|
|
21
21
|
logger.debug(c.body);
|
|
22
22
|
|
|
23
23
|
const response = await fetch(api, {
|
|
24
|
-
method:
|
|
24
|
+
method: 'POST',
|
|
25
25
|
body: formData,
|
|
26
26
|
headers: {
|
|
27
27
|
// Add any auth headers
|
|
@@ -30,9 +30,7 @@ export const uploadAttachment = async (c: Context) => {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
if (!response.ok) {
|
|
33
|
-
const errorData = await response
|
|
34
|
-
.json()
|
|
35
|
-
.catch(() => ({ message: "上传失败" }));
|
|
33
|
+
const errorData = await response.json().catch(() => ({ message: '上传失败' }));
|
|
36
34
|
return c.json({
|
|
37
35
|
error: `目标接口返回错误: ${errorData.message}`,
|
|
38
36
|
status: response.status,
|
|
@@ -44,8 +42,11 @@ export const uploadAttachment = async (c: Context) => {
|
|
|
44
42
|
|
|
45
43
|
const orcResult = await parseImg(file);
|
|
46
44
|
|
|
45
|
+
// replace file url protol to https
|
|
46
|
+
const secureUrl = url.replace('http://', 'https://');
|
|
47
|
+
|
|
47
48
|
return c.json({
|
|
48
|
-
url,
|
|
49
|
+
url: secureUrl,
|
|
49
50
|
name: uri,
|
|
50
51
|
contentType: file.type,
|
|
51
52
|
parsedData: orcResult,
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import type { Context } from
|
|
2
|
-
import config from
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import config from 'config';
|
|
3
3
|
|
|
4
4
|
export const clearConversation = async (c: Context) => {
|
|
5
5
|
let requestBody;
|
|
6
6
|
|
|
7
|
-
const agentHost = config.get<string>(
|
|
7
|
+
const agentHost = config.get<string>('agent.host');
|
|
8
8
|
|
|
9
|
-
const baseUrl = `
|
|
10
|
-
const apiKey = config.get<string>(
|
|
9
|
+
const baseUrl = `https://${agentHost}/v1`;
|
|
10
|
+
const apiKey = config.get<string>('agent.apiAuthKey');
|
|
11
11
|
|
|
12
12
|
try {
|
|
13
13
|
const json = await c.req.json();
|
|
14
14
|
requestBody = json;
|
|
15
15
|
} catch (_) {
|
|
16
|
-
return c.json({ error:
|
|
16
|
+
return c.json({ error: 'Invalid JSON' }, 400);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const result = await fetch(
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// Add any auth headers
|
|
25
|
-
Authorization: `Bearer ${apiKey}`,
|
|
26
|
-
},
|
|
19
|
+
const result = await fetch(`${baseUrl}/conversations/${requestBody.conversationId}/clear`, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
// Add any auth headers
|
|
23
|
+
Authorization: `Bearer ${apiKey}`,
|
|
27
24
|
},
|
|
28
|
-
);
|
|
25
|
+
});
|
|
29
26
|
|
|
30
27
|
return c.json(result);
|
|
31
28
|
};
|
|
@@ -13,7 +13,7 @@ export const queryReport = async (c: Context) => {
|
|
|
13
13
|
return c.json({ error: 'Invalid JSON' }, 400);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const uid = c.req.header('X-User-Id') || '';
|
|
16
|
+
const uid = c.req.header('X-Bs-User-Id') || '';
|
|
17
17
|
const messages: UIMessage[] = requestBody.messages;
|
|
18
18
|
|
|
19
19
|
const extraText = buildExtraMsgParts({
|
|
@@ -5,7 +5,7 @@ import { logger } from '../logger/index.js';
|
|
|
5
5
|
export const fetchCozeInfo = async (bsTeamId: string): Promise<ICozeInfoOfTokenExchange> => {
|
|
6
6
|
const agentHost = config.get<string>('agent.host');
|
|
7
7
|
|
|
8
|
-
const apiUrl = `
|
|
8
|
+
const apiUrl = `https://${agentHost}/api/by_teamid/tokens`;
|
|
9
9
|
const res = await fetch(apiUrl, {
|
|
10
10
|
method: 'POST',
|
|
11
11
|
headers: {
|