tmp
This commit is contained in:
@@ -7,7 +7,7 @@ import EscortAdminPrompts from "./prompts.js";
|
||||
import {
|
||||
getEnvTool, webFetchTool, webSearchTool, getCalendarInfoTool,
|
||||
getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool, getLatLngTool,
|
||||
httpGetTool, httpPostTool, escortRecordQueryTool
|
||||
httpGetTool, httpPostTool, escortRecordQueryTool, escortRecordSetTool
|
||||
} from "./tools/index.js";
|
||||
|
||||
export default class EscortAdminAgent {
|
||||
@@ -140,7 +140,7 @@ export default class EscortAdminAgent {
|
||||
backend,
|
||||
tools: [getEnvTool, webFetchTool, webSearchTool, getLatLngTool, httpGetTool, httpPostTool,
|
||||
getCalendarInfoTool, getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool,
|
||||
escortRecordQueryTool]
|
||||
escortRecordQueryTool, escortRecordSetTool]
|
||||
});
|
||||
|
||||
return this.agent;
|
||||
|
||||
@@ -3,20 +3,27 @@ import z from "zod";
|
||||
import { DBModel } from "../../../../models/index.js";
|
||||
|
||||
const escortRecordSetTool = tool(
|
||||
async ({ mobile, status, notes, payment }) => {
|
||||
async ({ orderId, status, notes, payment }) => {
|
||||
try {
|
||||
if (!mobile) {
|
||||
if (!orderId) {
|
||||
return {
|
||||
success: false,
|
||||
error: "Mobile phone number is required as the lookup key",
|
||||
error: "Order ID (_id or orderNo) is required as the lookup key",
|
||||
};
|
||||
}
|
||||
|
||||
const record = await DBModel.EscortRecord.findOne({ "patient.mobile": mobile });
|
||||
const query = {
|
||||
$or: [
|
||||
{ _id: orderId },
|
||||
{ orderNo: orderId }
|
||||
]
|
||||
};
|
||||
|
||||
const record = await DBModel.EscortRecord.findOne(query);
|
||||
if (!record) {
|
||||
return {
|
||||
success: false,
|
||||
error: `No escort record found for mobile: ${mobile}`,
|
||||
error: `No escort record found for order ID: ${orderId}`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -72,11 +79,11 @@ const escortRecordSetTool = tool(
|
||||
{
|
||||
name: "escort_record_set",
|
||||
description:
|
||||
"Update escort record fields by patient mobile phone number. Supports updating status, notes (patientNote, escortNote, medicalSummary), and payment (totalFee, paidFee, status). Only provided fields will be updated.",
|
||||
"Update escort record fields by order ID (_id or orderNo). Supports updating status, notes (patientNote, escortNote, medicalSummary), and payment (totalFee, paidFee, status). Only provided fields will be updated.",
|
||||
schema: z.object({
|
||||
mobile: z
|
||||
orderId: z
|
||||
.string()
|
||||
.describe("Patient mobile phone number used as the lookup key"),
|
||||
.describe("Order ID (_id or orderNo) used as the lookup key"),
|
||||
status: z
|
||||
.enum(["pending", "confirmed", "in_progress", "completed", "cancelled"])
|
||||
.optional()
|
||||
|
||||
@@ -21,5 +21,6 @@ export { getEnvTool } from './system/envs.js';
|
||||
|
||||
// db
|
||||
export { escortRecordQueryTool } from './db/escort_record_query.js';
|
||||
export { escortRecordSetTool } from './db/escort_record_set.js';
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"wechat": {
|
||||
"appid": "wxf73c79e16837af07",
|
||||
"secret": "5a061d65f4d35d19e62e83b98f6c63cf"
|
||||
"app": {
|
||||
"wxapp-escort": {
|
||||
},
|
||||
"wxapp-escort-admin": {
|
||||
}
|
||||
},
|
||||
"mongodb": {
|
||||
"str": "mongodb://huashengtec.com:6000",
|
||||
|
||||
22
websocket.js
22
websocket.js
@@ -1,5 +1,6 @@
|
||||
import WebSocket, { WebSocketServer } from 'ws';
|
||||
import http from 'http';
|
||||
import fetch from 'node-fetch';
|
||||
import { DBModel } from "./models/index.js";
|
||||
import { chatTask } from "./agent/escort/task.js";
|
||||
import { adminAgent } from "./agent/escort-admin/agent.js"
|
||||
@@ -81,12 +82,12 @@ export default class WebSocketServerManager {
|
||||
|
||||
if (msg.type === 'chat' || msg.type === 'clear') {
|
||||
if (msg.agent === 'escort-admin') {
|
||||
const userInfo = await this.getUserInfo(msg.userId);
|
||||
const userInfo = await this.getUserInfo(msg.token, msg.userId);
|
||||
adminAgent.streamChat(userInfo, [msg], (source, type, content, id) => {
|
||||
ws.send(JSON.stringify({ source, type, content, id }));
|
||||
});
|
||||
} else {
|
||||
const userInfo = await this.getUserInfo(msg.userId);
|
||||
const userInfo = await this.getUserInfo(msg.token, msg.userId);
|
||||
chatTask.streamChat(userInfo, msg, (source, type, content, id) => {
|
||||
ws.send(JSON.stringify({ source, type, content, id }));
|
||||
});
|
||||
@@ -132,8 +133,19 @@ export default class WebSocketServerManager {
|
||||
return this.wss.clients.size;
|
||||
}
|
||||
|
||||
async getUserInfo(userId) {
|
||||
if (!DBModel.User || userId.length === 0) return null;
|
||||
return await DBModel.User.findById(userId).lean().exec();
|
||||
async getUserInfo(token, userId) {
|
||||
if (!token || !userId) return null;
|
||||
|
||||
const url = "http://127.0.0.1:9010/user/userInfo";
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
token,
|
||||
userId
|
||||
})
|
||||
});
|
||||
const data = await res.json();
|
||||
return data.data.user;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user