rewrite agents schema and types

This commit is contained in:
Vaayne
2025-09-16 23:55:31 +08:00
parent 697f7d1946
commit 669f60273c
21 changed files with 871 additions and 766 deletions
@@ -17,7 +17,7 @@ const verifyAgentAndSession = async (agentId: string, sessionId: string) => {
throw { status: 404, code: 'session_not_found', message: 'Session not found' }
}
if (session.main_agent_id !== agentId) {
if (session.agent_id !== agentId) {
throw { status: 404, code: 'session_not_found', message: 'Session not found for this agent' }
}
@@ -43,7 +43,7 @@ export const createMessageStream = async (req: Request, res: Response): Promise<
res.setHeader('Access-Control-Allow-Headers', 'Cache-Control')
// Send initial connection event
res.write('data: {"type":"connected"}\n\n')
res.write('data: {"type":"start"}\n\n')
const messageStream = sessionMessageService.createSessionMessageStream(session, messageData)
@@ -78,7 +78,6 @@ export const getSession = async (req: Request, res: Response): Promise<Response>
}
// Verify session belongs to the agent
if (session.main_agent_id !== agentId) {
logger.warn(`Session ${sessionId} does not belong to agent ${agentId}`)
return res.status(404).json({
error: {
@@ -121,7 +120,7 @@ export const updateSession = async (req: Request, res: Response): Promise<Respon
// First check if session exists and belongs to agent
const existingSession = await sessionService.getSession(sessionId)
if (!existingSession || existingSession.main_agent_id !== agentId) {
if (!existingSession || existingSession.agent_id !== agentId) {
logger.warn(`Session ${sessionId} not found for agent ${agentId}`)
return res.status(404).json({
error: {
@@ -169,7 +168,7 @@ export const patchSession = async (req: Request, res: Response): Promise<Respons
// First check if session exists and belongs to agent
const existingSession = await sessionService.getSession(sessionId)
if (!existingSession || existingSession.main_agent_id !== agentId) {
if (!existingSession || existingSession.agent_id !== agentId) {
logger.warn(`Session ${sessionId} not found for agent ${agentId}`)
return res.status(404).json({
error: {
@@ -215,7 +214,7 @@ export const deleteSession = async (req: Request, res: Response): Promise<Respon
// First check if session exists and belongs to agent
const existingSession = await sessionService.getSession(sessionId)
if (!existingSession || existingSession.main_agent_id !== agentId) {
if (!existingSession || existingSession.agent_id !== agentId) {
logger.warn(`Session ${sessionId} not found for agent ${agentId}`)
return res.status(404).json({
error: {