web3-research-mcp
Version:
Deep Research for crypto - free & fully local
113 lines • 3.66 kB
JavaScript
import * as fs from "fs/promises";
import * as path from "path";
export class ResearchStorage {
constructor(dataDir = "./research_data") {
this.dataDir = dataDir;
this.ensureDataDir();
this.currentResearch = {
tokenName: "",
tokenTicker: "",
researchPlan: {},
searchResults: {},
technicalData: {},
marketData: {},
socialData: {},
newsData: [],
teamData: {},
relatedTokens: [],
resources: {},
researchData: {},
status: "not_started",
logs: [],
};
}
async ensureDataDir() {
try {
await fs.mkdir(this.dataDir, { recursive: true });
}
catch (error) {
console.error("Failed to create data directory:", error);
}
}
startNewResearch(tokenName, tokenTicker) {
if (this.currentResearch.status !== "not_started") {
this.saveCurrentResearch();
}
this.currentResearch = {
tokenName,
tokenTicker,
researchPlan: {},
searchResults: {},
technicalData: {},
marketData: {},
socialData: {},
newsData: [],
teamData: {},
relatedTokens: [],
resources: {},
researchData: {},
status: "in_progress",
logs: [],
};
this.addLogEntry(`Started research on ${tokenName} (${tokenTicker})`);
}
getCurrentResearch() {
return this.currentResearch;
}
getSection(section) {
return this.currentResearch[section];
}
updateSection(section, data) {
this.currentResearch[section] = data;
this.addLogEntry(`Updated section: ${section}`);
}
addToSection(section, data) {
const currentSection = this.currentResearch[section];
if (Array.isArray(currentSection)) {
this.currentResearch[section].push(data);
this.addLogEntry(`Added item to section: ${section}`);
}
else if (typeof currentSection === "object" && currentSection !== null) {
this.currentResearch[section] = {
...currentSection,
...data,
};
this.addLogEntry(`Updated object section: ${section}`);
}
else {
this.addLogEntry(`Error: Section ${section} has unsupported type`);
}
}
getResource(resourceId) {
return this.currentResearch.resources[resourceId] || null;
}
getAllResources() {
return this.currentResearch.resources;
}
addLogEntry(message) {
const logEntry = {
timestamp: new Date().toISOString(),
message,
};
this.currentResearch.logs.push(logEntry);
}
completeResearch() {
this.currentResearch.status = "completed";
this.addLogEntry(`Completed research on ${this.currentResearch.tokenName}`);
this.saveCurrentResearch();
}
async saveCurrentResearch() {
try {
const filename = `${this.currentResearch.tokenTicker.toLowerCase()}_${new Date()
.toISOString()
.replace(/[:T.]/g, "_")}.json`;
const filepath = path.join(this.dataDir, filename);
await fs.writeFile(filepath, JSON.stringify(this.currentResearch, null, 2));
}
catch (error) {
console.error("Failed to save research data:", error);
}
}
}
export default ResearchStorage;
//# sourceMappingURL=researchStorage.js.map