@0xward/thesisai-sdk 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +149 -3
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,7 +1,153 @@
|
|
|
1
|
-
//
|
|
1
|
+
// @0xward/thesisai-sdk
|
|
2
|
+
// Autonomous Research Agent framework for academic writing synthesis on Stacks
|
|
3
|
+
|
|
4
|
+
const CITATION_STYLES = ["APA", "MLA", "Chicago", "Harvard", "IEEE"];
|
|
5
|
+
const MAX_SOURCES = 100;
|
|
6
|
+
const MIN_TOPIC_LENGTH = 3;
|
|
7
|
+
const MAX_TOPIC_LENGTH = 300;
|
|
8
|
+
|
|
9
|
+
const STRUCTURE_TEMPLATES = {
|
|
10
|
+
thesis: ["Introduction", "Literature Review", "Methodology", "Results", "Discussion", "Conclusion"],
|
|
11
|
+
essay: ["Introduction", "Body", "Counterargument", "Conclusion"],
|
|
12
|
+
review: ["Abstract", "Background", "Analysis", "Synthesis", "Future Directions"],
|
|
13
|
+
report: ["Executive Summary", "Introduction", "Findings", "Recommendations"],
|
|
14
|
+
};
|
|
15
|
+
|
|
2
16
|
class ThesisAISDK {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.blockchain = options.blockchain || "Stacks";
|
|
19
|
+
this.citationStyle = options.citationStyle || "APA";
|
|
20
|
+
this.maxSources = options.maxSources || MAX_SOURCES;
|
|
21
|
+
this.language = options.language || "en";
|
|
22
|
+
this.version = "1.0.6";
|
|
23
|
+
this._validateOptions();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
_validateOptions() {
|
|
27
|
+
if (!CITATION_STYLES.includes(this.citationStyle)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Invalid citationStyle: "${this.citationStyle}". Supported: ${CITATION_STYLES.join(", ")}.`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (typeof this.maxSources !== "number" || this.maxSources < 1 || this.maxSources > MAX_SOURCES) {
|
|
33
|
+
throw new Error(`maxSources must be a number between 1 and ${MAX_SOURCES}.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
_validateTopic(topic) {
|
|
38
|
+
if (typeof topic !== "string" || topic.trim().length === 0) {
|
|
39
|
+
throw new Error("topic must be a non-empty string.");
|
|
40
|
+
}
|
|
41
|
+
if (topic.trim().length < MIN_TOPIC_LENGTH) {
|
|
42
|
+
throw new Error(`topic must be at least ${MIN_TOPIC_LENGTH} characters.`);
|
|
43
|
+
}
|
|
44
|
+
if (topic.length > MAX_TOPIC_LENGTH) {
|
|
45
|
+
throw new Error(`topic must not exceed ${MAX_TOPIC_LENGTH} characters.`);
|
|
46
|
+
}
|
|
47
|
+
return topic.trim();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_validateSources(sources) {
|
|
51
|
+
if (!Array.isArray(sources)) {
|
|
52
|
+
throw new Error("sources must be an array.");
|
|
53
|
+
}
|
|
54
|
+
if (sources.length > this.maxSources) {
|
|
55
|
+
throw new Error(`Too many sources: ${sources.length}. Maximum allowed: ${this.maxSources}.`);
|
|
56
|
+
}
|
|
57
|
+
return sources.filter((s) => {
|
|
58
|
+
if (typeof s === "string") return s.trim().length > 0;
|
|
59
|
+
if (typeof s === "object" && s !== null) return !!(s.url || s.title || s.doi);
|
|
60
|
+
return false;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_structureCitations(sources) {
|
|
65
|
+
return sources.map((s, i) => {
|
|
66
|
+
if (typeof s === "string") {
|
|
67
|
+
return { id: i + 1, reference: s.trim(), type: "text", style: this.citationStyle };
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
id: i + 1,
|
|
71
|
+
reference: s.title || s.url || s.doi || "Unknown",
|
|
72
|
+
type: s.doi ? "doi" : s.url ? "url" : "text",
|
|
73
|
+
doi: s.doi || null,
|
|
74
|
+
url: s.url || null,
|
|
75
|
+
author: s.author || null,
|
|
76
|
+
year: s.year || null,
|
|
77
|
+
style: this.citationStyle,
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
3
82
|
async synthesizeResearch(topic, sources = []) {
|
|
4
|
-
|
|
83
|
+
const validTopic = this._validateTopic(topic);
|
|
84
|
+
const validSources = this._validateSources(sources);
|
|
85
|
+
const citations = this._structureCitations(validSources);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
topic: validTopic,
|
|
89
|
+
summary: `Autonomous synthesis completed for: "${validTopic}"`,
|
|
90
|
+
citationsCount: citations.length,
|
|
91
|
+
invalidSources: sources.length - validSources.length,
|
|
92
|
+
citations,
|
|
93
|
+
citationStyle: this.citationStyle,
|
|
94
|
+
language: this.language,
|
|
95
|
+
blockchain: this.blockchain,
|
|
96
|
+
securedBy: "Bitcoin",
|
|
97
|
+
timestamp: new Date().toISOString(),
|
|
98
|
+
sdkVersion: this.version,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
generateStructure(documentType = "thesis") {
|
|
103
|
+
const type = documentType.toLowerCase();
|
|
104
|
+
if (!STRUCTURE_TEMPLATES[type]) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Unknown document type: "${documentType}". Supported: ${Object.keys(STRUCTURE_TEMPLATES).join(", ")}.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
documentType: type,
|
|
111
|
+
sections: STRUCTURE_TEMPLATES[type].map((title, i) => ({
|
|
112
|
+
order: i + 1,
|
|
113
|
+
title,
|
|
114
|
+
placeholder: `Write your ${title.toLowerCase()} here...`,
|
|
115
|
+
})),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
formatCitation(citation) {
|
|
120
|
+
if (!citation || typeof citation !== "object") {
|
|
121
|
+
throw new Error("citation must be a valid object.");
|
|
122
|
+
}
|
|
123
|
+
if (!citation.reference) {
|
|
124
|
+
throw new Error("citation.reference is required.");
|
|
125
|
+
}
|
|
126
|
+
const id = citation.id || "?";
|
|
127
|
+
const ref = citation.reference;
|
|
128
|
+
const yr = citation.year ? ` (${citation.year})` : "";
|
|
129
|
+
const au = citation.author ? `${citation.author}. ` : "";
|
|
130
|
+
return `[${id}] ${au}${ref}${yr}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getSupportedCitationStyles() {
|
|
134
|
+
return [...CITATION_STYLES];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getSupportedDocumentTypes() {
|
|
138
|
+
return Object.keys(STRUCTURE_TEMPLATES);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getMetadata() {
|
|
142
|
+
return {
|
|
143
|
+
sdk: "ThesisAI SDK",
|
|
144
|
+
version: this.version,
|
|
145
|
+
blockchain: this.blockchain,
|
|
146
|
+
citationStyle: this.citationStyle,
|
|
147
|
+
maxSources: this.maxSources,
|
|
148
|
+
language: this.language,
|
|
149
|
+
};
|
|
5
150
|
}
|
|
6
151
|
}
|
|
7
|
-
|
|
152
|
+
|
|
153
|
+
module.exports = { ThesisAISDK, CITATION_STYLES, STRUCTURE_TEMPLATES };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xward/thesisai-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "High-performance Autonomous Research Agent designed to streamline and synthesize academic writing.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
"url": "https://github.com/0xward/thesisai-sdk/issues"
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://www.npmjs.com/package/@0xward/thesisai-sdk#readme"
|
|
24
|
-
}
|
|
24
|
+
}
|