UNPKG

@defikitdotnet/x-ai-combat

Version:

XCombatAI - Social Media Engagement Template for the Agent Framework

184 lines 6.04 kB
import { log } from '../utils/logger'; /** * Mock database adapter for development */ export class MockDatabaseAdapter { constructor(db) { this.db = db; } init() { throw new Error("Method not implemented."); } close() { throw new Error("Method not implemented."); } createAccount(account) { throw new Error("Method not implemented."); } getMemories(params) { throw new Error("Method not implemented."); } getMemoryById(id) { throw new Error("Method not implemented."); } getMemoriesByRoomIds(params) { throw new Error("Method not implemented."); } getCachedEmbeddings(params) { throw new Error("Method not implemented."); } log(params) { throw new Error("Method not implemented."); } getActorDetails(params) { throw new Error("Method not implemented."); } searchMemories(params) { throw new Error("Method not implemented."); } updateGoalStatus(params) { throw new Error("Method not implemented."); } searchMemoriesByEmbedding(embedding, params) { throw new Error("Method not implemented."); } createMemory(memory, tableName, unique) { throw new Error("Method not implemented."); } removeMemory(memoryId, tableName) { throw new Error("Method not implemented."); } removeAllMemories(roomId, tableName) { throw new Error("Method not implemented."); } countMemories(roomId, unique, tableName) { throw new Error("Method not implemented."); } getGoals(params) { throw new Error("Method not implemented."); } updateGoal(goal) { throw new Error("Method not implemented."); } createGoal(goal) { throw new Error("Method not implemented."); } removeGoal(goalId) { throw new Error("Method not implemented."); } removeAllGoals(roomId) { throw new Error("Method not implemented."); } getRoom(roomId) { throw new Error("Method not implemented."); } createRoom(roomId) { throw new Error("Method not implemented."); } removeRoom(roomId) { throw new Error("Method not implemented."); } getRoomsForParticipant(userId) { throw new Error("Method not implemented."); } getRoomsForParticipants(userIds) { throw new Error("Method not implemented."); } addParticipant(userId, roomId) { throw new Error("Method not implemented."); } removeParticipant(userId, roomId) { throw new Error("Method not implemented."); } getParticipantsForAccount(userId) { throw new Error("Method not implemented."); } getParticipantsForRoom(roomId) { throw new Error("Method not implemented."); } getParticipantUserState(roomId, userId) { throw new Error("Method not implemented."); } setParticipantUserState(roomId, userId, state) { throw new Error("Method not implemented."); } createRelationship(params) { throw new Error("Method not implemented."); } getRelationship(params) { throw new Error("Method not implemented."); } getRelationships(params) { throw new Error("Method not implemented."); } getRagData(accountId) { throw new Error("Method not implemented."); } addRagData(accountId, data) { throw new Error("Method not implemented."); } updateRagDataStatus(ragId, status) { throw new Error("Method not implemented."); } async getAccountById(id) { const sql = "SELECT * FROM accounts WHERE id = ?"; const account = this.db.prepare(sql).get(id); if (!account) log("Account not found db mock"); if (!account) return null; // Parse JSON fields if (typeof account.details === "string") { account.details = JSON.parse(account.details); } if (typeof account.character === "string") { account.character = JSON.parse(account.character); } return account; } async createTemplate(template) { try { // Bật foreign key constraints this.db.prepare('PRAGMA foreign_keys = ON;').run(); // Kiểm tra account tồn tại if (template.sourceAgentId) { const account = this.db .prepare('SELECT id FROM accounts WHERE id = ?') .get(template.sourceAgentId); log("Found account:", account); // Debug log if (!account) { log("Source agent not found:", template.sourceAgentId); return false; } } const sql = ` INSERT INTO templates ( id, name, username, character, createdBy, sourceAgentId, templateType, rating, createdAt ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) `; const result = this.db.prepare(sql).run(template.id ?? `${Date.now()}-${Math.floor(Math.random() * 10000)}`, template.name, template.username ?? null, JSON.stringify(template.character), template.createdBy ?? null, template.sourceAgentId ?? null, template.templateType ?? 'user', template.rating ?? 0); log("Insert result:", result); // Debug log return true; } catch (error) { log("Error creating template:", error); // Log chi tiết hơn về lỗi if (error instanceof Error) { log("Error details:", { message: error.message, stack: error.stack }); } return false; } } } //# sourceMappingURL=mock.js.map