@dropout-ai/runtime 0.3.11 â 0.4.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/package.json +1 -1
- package/src/index.js +36 -10
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -17,7 +17,27 @@ const KNOWN_AI_DOMAINS = [
|
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
class Dropout {
|
|
20
|
+
// Singleton Instance Storage
|
|
21
|
+
static instance = null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Universal Initialization Method (Idempotent)
|
|
25
|
+
* Users call this explicitly in their code.
|
|
26
|
+
*/
|
|
27
|
+
static init(config) {
|
|
28
|
+
if (!Dropout.instance) {
|
|
29
|
+
new Dropout(config);
|
|
30
|
+
}
|
|
31
|
+
return Dropout.instance;
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
constructor(config = {}) {
|
|
35
|
+
// đĄī¸ SINGLETON GUARD (Prevent multiple initializations)
|
|
36
|
+
if (Dropout.instance) {
|
|
37
|
+
if (config.debug) console.log("[Dropout] âšī¸ Already initialized. Returning existing instance.");
|
|
38
|
+
return Dropout.instance;
|
|
39
|
+
}
|
|
40
|
+
|
|
21
41
|
// đĄī¸ 1. BROWSER GUARD (Client-Side Protection)
|
|
22
42
|
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
|
|
23
43
|
if (config.debug) console.warn("[Dropout] â ī¸ Skipped: Browser detected. SDK is Server-Only.");
|
|
@@ -26,7 +46,9 @@ class Dropout {
|
|
|
26
46
|
|
|
27
47
|
// đĄī¸ 2. CREDENTIAL GUARD
|
|
28
48
|
if (!config.apiKey || !config.projectId) {
|
|
29
|
-
if (config.debug)
|
|
49
|
+
if (config.debug) {
|
|
50
|
+
console.warn("\x1b[31m%s\x1b[0m", "[Dropout] đ´ Initialization Failed: Missing API Key or Project ID.");
|
|
51
|
+
}
|
|
30
52
|
return;
|
|
31
53
|
}
|
|
32
54
|
|
|
@@ -56,9 +78,10 @@ class Dropout {
|
|
|
56
78
|
this.lastPromptHash = null;
|
|
57
79
|
this.lastResponseHash = null;
|
|
58
80
|
|
|
59
|
-
//
|
|
81
|
+
// Global Guard (Extra safety for HMR environments like Next.js)
|
|
60
82
|
if (global.__dropout_initialized__) {
|
|
61
|
-
if (this.debug) console.log("[Dropout] âšī¸
|
|
83
|
+
if (this.debug) console.log("[Dropout] âšī¸ Global flag found. Skipping re-initialization.");
|
|
84
|
+
Dropout.instance = this; // Re-bind if lost
|
|
62
85
|
return;
|
|
63
86
|
}
|
|
64
87
|
global.__dropout_initialized__ = true;
|
|
@@ -68,7 +91,10 @@ class Dropout {
|
|
|
68
91
|
global.__dropout_session_id__ = this.generateSessionId();
|
|
69
92
|
}
|
|
70
93
|
|
|
71
|
-
|
|
94
|
+
// â
VISUAL SUCCESS INDICATOR
|
|
95
|
+
if (this.debug) {
|
|
96
|
+
console.log('\x1b[32m%s\x1b[0m', `[Dropout] đĸ Online | Project: ${this.projectId}`);
|
|
97
|
+
}
|
|
72
98
|
|
|
73
99
|
// Bindings
|
|
74
100
|
this.log = this.log.bind(this);
|
|
@@ -77,10 +103,12 @@ class Dropout {
|
|
|
77
103
|
// 4. Start Network Interceptor
|
|
78
104
|
this.patchNetwork();
|
|
79
105
|
|
|
80
|
-
// 5. SEND STARTUP PING
|
|
81
|
-
// This turns the dashboard status GREEN immediately on app boot.
|
|
106
|
+
// 5. SEND STARTUP PING
|
|
82
107
|
this.sendStartupSignal();
|
|
83
108
|
|
|
109
|
+
// Lock the instance
|
|
110
|
+
Dropout.instance = this;
|
|
111
|
+
|
|
84
112
|
} catch (err) {
|
|
85
113
|
// THE ULTIMATE CATCH-ALL: Ensure app NEVER crashes
|
|
86
114
|
if (config.debug) console.error("[Dropout] â Initialization Error:", err);
|
|
@@ -108,7 +136,6 @@ class Dropout {
|
|
|
108
136
|
turn_role: 'system',
|
|
109
137
|
turn_index: 0,
|
|
110
138
|
content: 'Dropout SDK Initialized',
|
|
111
|
-
// content_blob: 'Dropout SDK Initialized',
|
|
112
139
|
metadata_flags: {
|
|
113
140
|
type: 'system_boot',
|
|
114
141
|
environment: process.env.NODE_ENV || 'development',
|
|
@@ -185,7 +212,6 @@ class Dropout {
|
|
|
185
212
|
model: payload.model,
|
|
186
213
|
latency_ms: payload.latency_ms || null,
|
|
187
214
|
content: payload.content,
|
|
188
|
-
// content_blob: payload.content,
|
|
189
215
|
content_hash: payload.content_hash,
|
|
190
216
|
metadata_flags: payload.metadata_flags,
|
|
191
217
|
received_at: new Date().toISOString()
|
|
@@ -409,9 +435,9 @@ class Dropout {
|
|
|
409
435
|
}
|
|
410
436
|
}
|
|
411
437
|
|
|
412
|
-
// Auto-Start (
|
|
438
|
+
// Auto-Start (Backwards Compatibility & Environment Variable Support)
|
|
413
439
|
if (typeof process !== 'undefined' && process.env.DROPOUT_PROJECT_ID && process.env.DROPOUT_API_KEY) {
|
|
414
|
-
|
|
440
|
+
Dropout.init({
|
|
415
441
|
projectId: process.env.DROPOUT_PROJECT_ID,
|
|
416
442
|
apiKey: process.env.DROPOUT_API_KEY,
|
|
417
443
|
debug: process.env.DROPOUT_DEBUG === 'true'
|