diff --git a/bun.lockb b/bun.lockb index 6a8cd93..027941d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index c6c7432..573ee3c 100644 --- a/package.json +++ b/package.json @@ -19,31 +19,31 @@ "devDependencies": { "@commitlint/cli": "^19.5.0", "@commitlint/config-conventional": "^19.5.0", - "@eslint/js": "^9.12.0", + "@eslint/js": "^9.13.0", "@types/node-schedule": "^2.1.7", "@types/uuid": "^10.0.0", - "bun-types": "^1.1.30", - "eslint": "^9.12.0", + "bun-types": "^1.1.33", + "eslint": "^9.13.0", "eslint-plugin-simple-import-sort": "^12.1.1", "husky": "^9.1.6", "lint-staged": "^15.2.10", "prettier": "^3.3.3", - "typescript-eslint": "^8.9.0" + "typescript-eslint": "^8.12.1" }, "peerDependencies": { "typescript": "^5.5.4" }, "dependencies": { - "@dotenvx/dotenvx": "^1.19.3", + "@dotenvx/dotenvx": "^1.21.0", "@egg/hooks": "^1.2.0", - "@egg/lark-msg-tool": "^1.13.2", + "@egg/lark-msg-tool": "^1.14.0", "@egg/logger": "^1.4.4", "@egg/net-tool": "^1.9.2", "@egg/path-tool": "^1.4.1", - "@langchain/core": "^0.3.12", - "@langchain/openai": "^0.3.7", + "@langchain/core": "^0.3.15", + "@langchain/openai": "^0.3.11", "joi": "^17.13.3", - "langfuse-langchain": "^3.27.0", + "langfuse-langchain": "^3.28.0", "node-schedule": "^2.1.1", "p-limit": "^6.1.0", "pocketbase": "^0.21.5", diff --git a/routes/bot/groupAgent/index.ts b/routes/bot/groupAgent/index.ts index 7f8f637..15f868c 100644 --- a/routes/bot/groupAgent/index.ts +++ b/routes/bot/groupAgent/index.ts @@ -395,12 +395,12 @@ const manageActionMsg = async (ctx: Context.Data) => { */ const groupAgent = async (ctx: Context.Data) => { const { - larkBody: { isEventMsg, isActionMsg }, + larkBody: { isEvent, isAction }, } = ctx // 如果是Event,则解析自然语言并发送对应的卡片 - if (isEventMsg) return manageEventMsg(ctx) + if (isEvent) return manageEventMsg(ctx) // 如果是Action,则取出用户选的值并判断是否需要继续发送表单卡片或者开始大模型推理 - if (isActionMsg) return manageActionMsg(ctx) + if (isAction) return manageActionMsg(ctx) } export default groupAgent diff --git a/routes/bot/index.ts b/routes/bot/index.ts index d5084ac..43fa047 100644 --- a/routes/bot/index.ts +++ b/routes/bot/index.ts @@ -8,7 +8,7 @@ import { manageEventMsg } from "./eventMsg" * @returns {Promise} 返回响应对象 */ export const manageBotReq = async (ctx: Context.Data): Promise => { - const { body, larkBody } = ctx + const { body, larkBody, app, attachService } = ctx // 检查请求体是否为空 if (!body) { @@ -21,10 +21,15 @@ export const manageBotReq = async (ctx: Context.Data): Promise => { return Response.json({ challenge: body.challenge }) } - // 处理Event消息 - if (larkBody.isEventMsg) manageEventMsg(ctx) + // 如果是michat的Event转发给MiChatServer + if (app === "michat" && larkBody.isEvent) { + attachService.proxyMiChatEvent(body) + } + + // 处理消息事件 + if (larkBody.isMessageEvent) manageEventMsg(ctx) // 处理Action消息 - if (larkBody.isActionMsg) return await manageActionMsg(ctx) + if (larkBody.isAction) return await manageActionMsg(ctx) // 返回成功响应 return ctx.genResp.ok() diff --git a/services/attach/index.ts b/services/attach/index.ts index 51306a0..15fb8c4 100644 --- a/services/attach/index.ts +++ b/services/attach/index.ts @@ -21,6 +21,20 @@ class AttachService extends NetToolBase { const URL = "https://report.imoaix.cn/report" return this.post(URL, body).catch(() => "") } + + /** + * 代理MiChat事件 + * @param {LarkEvent.Data} body - 事件数据。 + * @returns {Promise} 返回空。 + */ + async proxyMiChatEvent(body: LarkEvent.Data) { + const hostList = ["michat-staging.ai.srv", "michat.ai.srv"] + const path = "/api/v1/bypass/robot_event_callback" + for (const host of hostList) { + const URL = `http://${host}${path}` + await this.post(URL, body).catch(() => "") + } + } } export default AttachService diff --git a/types/context.ts b/types/context.ts index b5d73e1..c6ecaed 100644 --- a/types/context.ts +++ b/types/context.ts @@ -22,6 +22,6 @@ export namespace Context { attachService: AttachService path: PathCheckTool searchParams: URLSearchParams - app: string + app: "michat" | "egg" | string } }