Skip to content

Commit 92b682e

Browse files
claudehyperpolymath
authored andcommitted
feat: Add JavaScript entry point (replaces main.ts)
Created src/main.js as pure JavaScript wrapper for ReScript modules. Provides same API as main.ts but without TypeScript (RSR Rhodium R13). Features: - ES6 module exports - JSDoc type annotations for IDE support - Imports ReScript compiled .bs.js files - analyze(), analyzeZoteroCollection(), generateReport(), toJson(), generateVisualization() This maintains zero TypeScript while providing clean external API.
1 parent 4d17dbb commit 92b682e

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

src/main.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* main.js - Fogbinder Entry Point
3+
* Pure JavaScript wrapper for ReScript-compiled epistemic analysis engine
4+
*
5+
* Philosophy: Navigate epistemic ambiguity (late Wittgenstein + J.L. Austin)
6+
* NOT about removing uncertainty - about exploring it as a feature
7+
*
8+
* ⛔ NOTE: This is JavaScript, NOT TypeScript (RSR Rhodium R13 compliance)
9+
* For TypeScript type definitions, use JSDoc comments
10+
*/
11+
12+
// Import compiled ReScript modules
13+
// These are generated by ReScript compiler as .bs.js files
14+
import * as Fogbinder from './Fogbinder.bs.js';
15+
import * as EpistemicState from './core/EpistemicState.bs.js';
16+
import * as SpeechAct from './core/SpeechAct.bs.js';
17+
import * as FogTrailVisualizer from './engine/FogTrailVisualizer.bs.js';
18+
19+
/**
20+
* @typedef {Object} AnalysisResult
21+
* @property {Array} contradictions
22+
* @property {Array} moods
23+
* @property {Array} mysteries
24+
* @property {Object} fogTrail
25+
* @property {Object} metadata
26+
* @property {number} metadata.analyzed
27+
* @property {number} metadata.totalSources
28+
* @property {number} metadata.totalContradictions
29+
* @property {number} metadata.totalMysteries
30+
* @property {number} metadata.overallOpacity
31+
*/
32+
33+
/**
34+
* @typedef {Object} LanguageGame
35+
* @property {string} domain
36+
* @property {string[]} conventions
37+
* @property {string[]} participants
38+
* @property {string} purpose
39+
*/
40+
41+
/**
42+
* Main analysis function - analyzes array of source texts
43+
* @param {string[]} sources - Array of citation texts to analyze
44+
* @param {LanguageGame} context - Language game context (domain, conventions, etc.)
45+
* @returns {AnalysisResult} Analysis result with contradictions, moods, mysteries, FogTrail
46+
*/
47+
export function analyze(sources, context) {
48+
return Fogbinder.analyze(sources, context, undefined);
49+
}
50+
51+
/**
52+
* Analyze a Zotero collection by ID
53+
* @param {string} collectionId - Zotero collection identifier
54+
* @returns {Promise<AnalysisResult>} Promise resolving to analysis result
55+
*/
56+
export async function analyzeZoteroCollection(collectionId) {
57+
return await Fogbinder.analyzeZoteroCollection(collectionId);
58+
}
59+
60+
/**
61+
* Generate human-readable report from analysis
62+
* @param {AnalysisResult} result - Analysis result
63+
* @returns {string} Markdown-formatted report
64+
*/
65+
export function generateReport(result) {
66+
return Fogbinder.generateReport(result);
67+
}
68+
69+
/**
70+
* Export analysis to JSON
71+
* @param {AnalysisResult} result - Analysis result
72+
* @returns {Object} JSON representation
73+
*/
74+
export function toJson(result) {
75+
return Fogbinder.toJson(result);
76+
}
77+
78+
/**
79+
* Generate SVG visualization of FogTrail
80+
* @param {AnalysisResult} result - Analysis result
81+
* @param {number} [width=1000] - Canvas width
82+
* @param {number} [height=800] - Canvas height
83+
* @returns {string} SVG string
84+
*/
85+
export function generateVisualization(result, width = 1000, height = 800) {
86+
return FogTrailVisualizer.toSvg(result.fogTrail, width, height, undefined);
87+
}
88+
89+
// Default export
90+
export default {
91+
analyze,
92+
analyzeZoteroCollection,
93+
generateReport,
94+
toJson,
95+
generateVisualization,
96+
};
97+
98+
// Example usage (commented out)
99+
/*
100+
const sources = [
101+
"The meaning of a word is its use in the language.",
102+
"Philosophical problems arise when language goes on holiday.",
103+
"Meaning is determined by truth conditions.",
104+
];
105+
106+
const context = {
107+
domain: "Philosophy of Language",
108+
conventions: ["academic discourse", "analytic tradition"],
109+
participants: ["philosophers", "linguists"],
110+
purpose: "Understanding meaning",
111+
};
112+
113+
const result = analyze(sources, context);
114+
console.log(generateReport(result));
115+
console.log("FogTrail opacity:", result.metadata.overallOpacity);
116+
*/

0 commit comments

Comments
 (0)