Spaces:
Running
Running
import mongoose from "mongoose"; | |
// Schema for chat messages | |
const MessageSchema = new mongoose.Schema({ | |
role: { | |
type: String, | |
required: true, | |
enum: ["user", "assistant"] | |
}, | |
content: { | |
type: String, | |
required: true | |
}, | |
timestamp: { | |
type: Date, | |
default: Date.now | |
} | |
}); | |
// Schema for agent tasks | |
const AgentTaskSchema = new mongoose.Schema({ | |
id: String, | |
description: String, | |
status: { | |
type: String, | |
enum: ["pending", "in-progress", "completed", "failed"] | |
}, | |
result: String | |
}); | |
// Schema for agent files | |
const AgentFileSchema = new mongoose.Schema({ | |
path: String, | |
content: String | |
}); | |
// Schema for agent sessions | |
const AgentSessionSchema = new mongoose.Schema({ | |
projectName: String, | |
description: String, | |
tasks: [AgentTaskSchema], | |
files: [AgentFileSchema], | |
createdAt: { | |
type: Date, | |
default: Date.now | |
}, | |
updatedAt: { | |
type: Date, | |
default: Date.now | |
} | |
}); | |
const ProjectSchema = new mongoose.Schema({ | |
space_id: { | |
type: String, | |
required: true, | |
}, | |
user_id: { | |
type: String, | |
required: true, | |
}, | |
prompts: { | |
type: [String], | |
default: [], | |
}, | |
// Chat sessions | |
chatSessions: { | |
type: [MessageSchema], | |
default: [] | |
}, | |
// Agent sessions | |
agentSessions: { | |
type: [AgentSessionSchema], | |
default: [] | |
}, | |
_createdAt: { | |
type: Date, | |
default: Date.now, | |
}, | |
_updatedAt: { | |
type: Date, | |
default: Date.now, | |
}, | |
}); | |
// Mock Project model for local storage | |
// This replaces the Mongoose model with a simple interface | |
export interface Project { | |
_id?: string; | |
space_id: string; | |
user_id: string; | |
prompts: string[]; | |
chatSessions: any[]; | |
agentSessions: any[]; | |
_createdAt: Date; | |
_updatedAt: Date; | |
} | |
// Mock model functions | |
const Project = { | |
findOne: async (query: any) => { | |
// This would normally query MongoDB, but we'll simulate it | |
console.log("Using local storage instead of MongoDB for Project.findOne"); | |
return null; | |
}, | |
find: async (query: any) => { | |
// This would normally query MongoDB, but we'll simulate it | |
console.log("Using local storage instead of MongoDB for Project.find"); | |
return []; | |
}, | |
create: async (data: any) => { | |
// This would normally create a document in MongoDB, but we'll simulate it | |
console.log("Using local storage instead of MongoDB for Project.create"); | |
return { ...data, _id: Math.random().toString(36).substr(2, 9) }; | |
}, | |
updateOne: async (query: any, update: any) => { | |
// This would normally update a document in MongoDB, but we'll simulate it | |
console.log("Using local storage instead of MongoDB for Project.updateOne"); | |
return { modifiedCount: 1 }; | |
} | |
}; | |
export default Project; | |