tmp
This commit is contained in:
@@ -7,7 +7,7 @@ import EscortAdminPrompts from "./prompts.js";
|
|||||||
import {
|
import {
|
||||||
getEnvTool, webFetchTool, webSearchTool, getCalendarInfoTool,
|
getEnvTool, webFetchTool, webSearchTool, getCalendarInfoTool,
|
||||||
getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool, getLatLngTool,
|
getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool, getLatLngTool,
|
||||||
httpGetTool, httpPostTool, escortRecordQueryTool
|
httpGetTool, httpPostTool, escortRecordQueryTool, escortRecordSetTool
|
||||||
} from "./tools/index.js";
|
} from "./tools/index.js";
|
||||||
|
|
||||||
export default class EscortAdminAgent {
|
export default class EscortAdminAgent {
|
||||||
@@ -140,7 +140,7 @@ export default class EscortAdminAgent {
|
|||||||
backend,
|
backend,
|
||||||
tools: [getEnvTool, webFetchTool, webSearchTool, getLatLngTool, httpGetTool, httpPostTool,
|
tools: [getEnvTool, webFetchTool, webSearchTool, getLatLngTool, httpGetTool, httpPostTool,
|
||||||
getCalendarInfoTool, getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool,
|
getCalendarInfoTool, getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool,
|
||||||
escortRecordQueryTool]
|
escortRecordQueryTool, escortRecordSetTool]
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.agent;
|
return this.agent;
|
||||||
|
|||||||
@@ -3,20 +3,27 @@ import z from "zod";
|
|||||||
import { DBModel } from "../../../../models/index.js";
|
import { DBModel } from "../../../../models/index.js";
|
||||||
|
|
||||||
const escortRecordSetTool = tool(
|
const escortRecordSetTool = tool(
|
||||||
async ({ mobile, status, notes, payment }) => {
|
async ({ orderId, status, notes, payment }) => {
|
||||||
try {
|
try {
|
||||||
if (!mobile) {
|
if (!orderId) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
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) {
|
if (!record) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
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",
|
name: "escort_record_set",
|
||||||
description:
|
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({
|
schema: z.object({
|
||||||
mobile: z
|
orderId: z
|
||||||
.string()
|
.string()
|
||||||
.describe("Patient mobile phone number used as the lookup key"),
|
.describe("Order ID (_id or orderNo) used as the lookup key"),
|
||||||
status: z
|
status: z
|
||||||
.enum(["pending", "confirmed", "in_progress", "completed", "cancelled"])
|
.enum(["pending", "confirmed", "in_progress", "completed", "cancelled"])
|
||||||
.optional()
|
.optional()
|
||||||
|
|||||||
@@ -21,5 +21,6 @@ export { getEnvTool } from './system/envs.js';
|
|||||||
|
|
||||||
// db
|
// db
|
||||||
export { escortRecordQueryTool } from './db/escort_record_query.js';
|
export { escortRecordQueryTool } from './db/escort_record_query.js';
|
||||||
|
export { escortRecordSetTool } from './db/escort_record_set.js';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
{
|
{
|
||||||
"wechat": {
|
"app": {
|
||||||
"appid": "wxf73c79e16837af07",
|
"wxapp-escort": {
|
||||||
"secret": "5a061d65f4d35d19e62e83b98f6c63cf"
|
},
|
||||||
|
"wxapp-escort-admin": {
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"mongodb": {
|
"mongodb": {
|
||||||
"str": "mongodb://huashengtec.com:6000",
|
"str": "mongodb://huashengtec.com:6000",
|
||||||
|
|||||||
22
websocket.js
22
websocket.js
@@ -1,5 +1,6 @@
|
|||||||
import WebSocket, { WebSocketServer } from 'ws';
|
import WebSocket, { WebSocketServer } from 'ws';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
import { DBModel } from "./models/index.js";
|
import { DBModel } from "./models/index.js";
|
||||||
import { chatTask } from "./agent/escort/task.js";
|
import { chatTask } from "./agent/escort/task.js";
|
||||||
import { adminAgent } from "./agent/escort-admin/agent.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.type === 'chat' || msg.type === 'clear') {
|
||||||
if (msg.agent === 'escort-admin') {
|
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) => {
|
adminAgent.streamChat(userInfo, [msg], (source, type, content, id) => {
|
||||||
ws.send(JSON.stringify({ source, type, content, id }));
|
ws.send(JSON.stringify({ source, type, content, id }));
|
||||||
});
|
});
|
||||||
} else {
|
} 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) => {
|
chatTask.streamChat(userInfo, msg, (source, type, content, id) => {
|
||||||
ws.send(JSON.stringify({ 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;
|
return this.wss.clients.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserInfo(userId) {
|
async getUserInfo(token, userId) {
|
||||||
if (!DBModel.User || userId.length === 0) return null;
|
if (!token || !userId) return null;
|
||||||
return await DBModel.User.findById(userId).lean().exec();
|
|
||||||
|
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