ansemedge 1.0.0

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/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # AnsemEdge SDK
2
+
3
+ Official Node/Browser SDK for AnsemEdge — Programmable Market Intelligence. Ingest real-time sentiment scoring, coin mentions, and emerging narrative shifts parsed directly from @blknoiz06's commentary on the Solana ecosystem.
4
+
5
+ Visit [ansemedge.xyz](https://ansemedge.xyz) to manage API credentials and view gating tiers.
6
+
7
+ ## Installation
8
+
9
+ Install via npm:
10
+
11
+ ```bash
12
+ npm install ansemedge
13
+ ```
14
+
15
+ ## Getting Started
16
+
17
+ Initialize the client with your developer API key:
18
+
19
+ ```javascript
20
+ import { AnsemEdge } from "ansemedge";
21
+
22
+ const edge = new AnsemEdge({
23
+ apiKey: "ae_live_your_api_key_here"
24
+ });
25
+ ```
26
+
27
+ ## Usage Examples
28
+
29
+ ### 1. Fetch Ecosystem Sentiment Index
30
+
31
+ Get the normalized real-time sentiment index aggregated across active feeds.
32
+
33
+ ```javascript
34
+ try {
35
+ const data = await edge.getSentiment("24h");
36
+ console.log(`Sentiment: ${data.sentimentIndex} (${data.label})`);
37
+ console.log(`Confidence Score: ${data.confidenceScore}`);
38
+ } catch (error) {
39
+ console.error("Failed to query sentiment:", error.message);
40
+ }
41
+ ```
42
+
43
+ ### 2. Retrieve Automated Signals
44
+
45
+ Fetch high-conviction automated signals computed by NLP extraction models.
46
+
47
+ ```javascript
48
+ const signals = await edge.getSignals(10, 0.90);
49
+ signals.forEach(signal => {
50
+ console.log(`Asset: $${signal.tokenSymbol} | Sentiment: ${signal.sentimentScore}`);
51
+ console.log(`Summary: ${signal.summary}`);
52
+ });
53
+ ```
54
+
55
+ ### 3. Stream Real-Time Updates via WebSockets
56
+
57
+ Subscribe to the low-latency streaming pipeline to receive structured events instantly.
58
+
59
+ ```javascript
60
+ // Connect and listen for real-time updates
61
+ edge.subscribe((payload) => {
62
+ console.log("Stream update parsed:", payload);
63
+ });
64
+
65
+ // To disconnect/cleanup:
66
+ // edge.close();
67
+ ```
68
+
69
+ ## API Methods
70
+
71
+ * `getSentiment(window?)`: Normalized ecosystem index [−1, +1].
72
+ * `getSignals(limit?, confidence?)`: Structured automated trading signals.
73
+ * `getTopics()`: Active narrative clusters with trend scores.
74
+ * `getSummary()`: Daily briefing document outlining catalyst events.
75
+ * `getMarket()`: Platform overview, convictions, and monitored channels status.
76
+ * `subscribe(callback)`: Open a WebSockets pipeline to listen to active scrape feeds.
77
+ * `unsubscribe(callback)`: Unregister listener and tear down sockets when inactive.
78
+ * `close()`: Shut down all active client feeds.
79
+
80
+ ## License
81
+
82
+ MIT License.
@@ -0,0 +1,90 @@
1
+ export interface SDKConfig {
2
+ apiKey: string;
3
+ baseUrl?: string;
4
+ wsUrl?: string;
5
+ }
6
+ export interface SentimentData {
7
+ sentimentIndex: number;
8
+ label: string;
9
+ confidenceScore: number;
10
+ sourceCount: number;
11
+ volume24h: string;
12
+ updatedAt: string;
13
+ }
14
+ export interface SignalData {
15
+ id: string;
16
+ tokenSymbol: string;
17
+ sentimentScore: number;
18
+ confidenceScore: number;
19
+ summary: string;
20
+ timestamp: string;
21
+ }
22
+ export interface TopicData {
23
+ name: string;
24
+ trendScore: number;
25
+ mentionsCount: number;
26
+ velocity: string;
27
+ }
28
+ export interface SummaryData {
29
+ summary: string;
30
+ topTokens: string[];
31
+ narrativesDetected: string[];
32
+ generatedAt: string;
33
+ }
34
+ export interface MarketData {
35
+ status: string;
36
+ overallConviction: number;
37
+ trendingToken: string;
38
+ topNarrative: string;
39
+ monitoredChannels: string[];
40
+ indexUpdateFrequency: string;
41
+ }
42
+ export declare class AnsemEdge {
43
+ private apiKey;
44
+ private baseUrl;
45
+ private wsUrl;
46
+ private ws;
47
+ private wsListeners;
48
+ private reconnectAttempts;
49
+ private maxReconnectAttempts;
50
+ private reconnectInterval;
51
+ constructor(config: SDKConfig);
52
+ private request;
53
+ /**
54
+ * Fetch normalized real-time sentiment index.
55
+ * @param window Timeframe window filter (e.g., '1h', '24h', '7d')
56
+ */
57
+ getSentiment(window?: string): Promise<SentimentData>;
58
+ /**
59
+ * Retrieve high-conviction automated trading signals.
60
+ * @param limit Max items to return
61
+ * @param confidence Min confidence threshold filter [0-1]
62
+ */
63
+ getSignals(limit?: number, confidence?: number): Promise<SignalData[]>;
64
+ /**
65
+ * Retrieve monitored narrative clusters and density shifts.
66
+ */
67
+ getTopics(): Promise<TopicData[]>;
68
+ /**
69
+ * Fetch automated daily catalyst briefs and sentiment summaries.
70
+ */
71
+ getSummary(): Promise<SummaryData>;
72
+ /**
73
+ * Fetch high level status metrics for the platform.
74
+ */
75
+ getMarket(): Promise<MarketData>;
76
+ /**
77
+ * Connect to the real-time sentiment WebSockets stream.
78
+ * @param onMessage Callback function executed on incoming feed payloads
79
+ */
80
+ subscribe(onMessage: (data: any) => void): void;
81
+ private connectWS;
82
+ /**
83
+ * Remove a message listener subscription.
84
+ */
85
+ unsubscribe(onMessage: (data: any) => void): void;
86
+ /**
87
+ * Close all active connection channels.
88
+ */
89
+ close(): void;
90
+ }
package/dist/index.js ADDED
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AnsemEdge = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
8
+ class AnsemEdge {
9
+ constructor(config) {
10
+ this.ws = null;
11
+ this.wsListeners = new Set();
12
+ this.reconnectAttempts = 0;
13
+ this.maxReconnectAttempts = 5;
14
+ this.reconnectInterval = 3000;
15
+ if (!config.apiKey) {
16
+ throw new Error("[AnsemEdge SDK] API key is required.");
17
+ }
18
+ this.apiKey = config.apiKey;
19
+ this.baseUrl = (config.baseUrl ?? "https://ansemedge.xyz").replace(/\/$/, "");
20
+ this.wsUrl = config.wsUrl ?? "wss://ansemedge.xyz";
21
+ }
22
+ async request(endpoint, params = {}) {
23
+ const url = new URL(`${this.baseUrl}${endpoint}`);
24
+ Object.keys(params).forEach(key => {
25
+ if (params[key] !== undefined && params[key] !== null) {
26
+ url.searchParams.append(key, String(params[key]));
27
+ }
28
+ });
29
+ const response = await fetch(url.toString(), {
30
+ method: "GET",
31
+ headers: {
32
+ "Authorization": `Bearer ${this.apiKey}`,
33
+ "Content-Type": "application/json",
34
+ },
35
+ });
36
+ if (!response.ok) {
37
+ if (response.status === 401) {
38
+ throw new Error("[AnsemEdge SDK] Unauthorized: Invalid API key.");
39
+ }
40
+ if (response.status === 403) {
41
+ throw new Error("[AnsemEdge SDK] Gated: Insufficient $EDGE token balance.");
42
+ }
43
+ if (response.status === 429) {
44
+ throw new Error("[AnsemEdge SDK] Rate Limit Exceeded: Upgrade your token balance tiers.");
45
+ }
46
+ throw new Error(`[AnsemEdge SDK] HTTP Error ${response.status}: ${response.statusText}`);
47
+ }
48
+ const payload = await response.json();
49
+ return payload.data ?? payload;
50
+ }
51
+ /**
52
+ * Fetch normalized real-time sentiment index.
53
+ * @param window Timeframe window filter (e.g., '1h', '24h', '7d')
54
+ */
55
+ async getSentiment(window) {
56
+ return this.request("/api/sentiment", { window });
57
+ }
58
+ /**
59
+ * Retrieve high-conviction automated trading signals.
60
+ * @param limit Max items to return
61
+ * @param confidence Min confidence threshold filter [0-1]
62
+ */
63
+ async getSignals(limit, confidence) {
64
+ return this.request("/api/signals", { limit, confidence });
65
+ }
66
+ /**
67
+ * Retrieve monitored narrative clusters and density shifts.
68
+ */
69
+ async getTopics() {
70
+ return this.request("/api/topics");
71
+ }
72
+ /**
73
+ * Fetch automated daily catalyst briefs and sentiment summaries.
74
+ */
75
+ async getSummary() {
76
+ return this.request("/api/summary");
77
+ }
78
+ /**
79
+ * Fetch high level status metrics for the platform.
80
+ */
81
+ async getMarket() {
82
+ return this.request("/api/market");
83
+ }
84
+ /**
85
+ * Connect to the real-time sentiment WebSockets stream.
86
+ * @param onMessage Callback function executed on incoming feed payloads
87
+ */
88
+ subscribe(onMessage) {
89
+ this.wsListeners.add(onMessage);
90
+ if (this.ws) {
91
+ return;
92
+ }
93
+ this.connectWS();
94
+ }
95
+ connectWS() {
96
+ const isBrowser = typeof window !== "undefined" && typeof window.WebSocket !== "undefined";
97
+ const WSClass = isBrowser ? window.WebSocket : ws_1.default;
98
+ if (!WSClass) {
99
+ console.warn("[AnsemEdge SDK] WebSocket class is not available in this environment.");
100
+ return;
101
+ }
102
+ const socketUrl = `${this.wsUrl}?apiKey=${this.apiKey}`;
103
+ this.ws = new WSClass(socketUrl);
104
+ this.ws.onopen = () => {
105
+ this.reconnectAttempts = 0;
106
+ console.log("[AnsemEdge SDK] Live WebSocket feed stream active.");
107
+ };
108
+ this.ws.onmessage = (event) => {
109
+ try {
110
+ const payload = JSON.parse(event.data);
111
+ this.wsListeners.forEach(listener => {
112
+ try {
113
+ listener(payload);
114
+ }
115
+ catch (err) {
116
+ console.error("[AnsemEdge SDK] Error in message listener callback:", err);
117
+ }
118
+ });
119
+ }
120
+ catch (err) {
121
+ // Handle raw message text if not JSON
122
+ this.wsListeners.forEach(listener => listener(event.data));
123
+ }
124
+ };
125
+ this.ws.onerror = (err) => {
126
+ console.error("[AnsemEdge SDK] WebSocket stream error:", err);
127
+ };
128
+ this.ws.onclose = () => {
129
+ this.ws = null;
130
+ if (this.reconnectAttempts < this.maxReconnectAttempts) {
131
+ this.reconnectAttempts++;
132
+ const delay = this.reconnectInterval * this.reconnectAttempts;
133
+ console.log(`[AnsemEdge SDK] Connection closed. Reconnecting in ${delay}ms...`);
134
+ setTimeout(() => this.connectWS(), delay);
135
+ }
136
+ else {
137
+ console.error("[AnsemEdge SDK] Max WebSocket reconnection attempts reached.");
138
+ }
139
+ };
140
+ }
141
+ /**
142
+ * Remove a message listener subscription.
143
+ */
144
+ unsubscribe(onMessage) {
145
+ this.wsListeners.delete(onMessage);
146
+ if (this.wsListeners.size === 0 && this.ws) {
147
+ this.ws.close();
148
+ this.ws = null;
149
+ }
150
+ }
151
+ /**
152
+ * Close all active connection channels.
153
+ */
154
+ close() {
155
+ this.wsListeners.clear();
156
+ if (this.ws) {
157
+ this.ws.close();
158
+ this.ws = null;
159
+ }
160
+ }
161
+ }
162
+ exports.AnsemEdge = AnsemEdge;
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "ansemedge",
3
+ "version": "1.0.0",
4
+ "description": "Official SDK for AnsemEdge — Programmable Market Intelligence.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc"
12
+ },
13
+ "keywords": [
14
+ "solana",
15
+ "ansem",
16
+ "sentiment",
17
+ "trading",
18
+ "intelligence",
19
+ "api",
20
+ "sdk"
21
+ ],
22
+ "author": "AnsemEdge",
23
+ "license": "MIT",
24
+ "homepage": "https://ansemedge.xyz",
25
+ "dependencies": {
26
+ "ws": "^8.18.0"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "^5.3.3",
30
+ "@types/node": "^20.11.24",
31
+ "@types/ws": "^8.5.10"
32
+ }
33
+ }