@dropout-ai/runtime 0.2.0 → 0.2.2
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 +64 -30
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
const originalFetch = global.fetch;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const sessionId =
|
|
7
|
+
global.__dropout_session_id__ ||
|
|
8
|
+
(global.__dropout_session_id__ = crypto.randomUUID());
|
|
9
|
+
|
|
10
|
+
// 4. Internal telemetry sender (Neutral naming)
|
|
11
|
+
async function safeSendTelemetry(payload) {
|
|
12
|
+
try {
|
|
13
|
+
await originalFetch('http://localhost:4000/capture', {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: { 'Content-Type': 'application/json' },
|
|
16
|
+
body: JSON.stringify(payload)
|
|
17
|
+
});
|
|
18
|
+
} catch (e) {
|
|
19
|
+
// Fail silently
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
(function () {
|
|
2
24
|
// 1. Guard global.fetch existence and idempotency
|
|
3
25
|
if (typeof global.fetch !== 'function' || global.fetch.__dropout_patched__) {
|
|
4
26
|
return;
|
|
5
27
|
}
|
|
6
28
|
|
|
7
|
-
const originalFetch = global.fetch;
|
|
8
|
-
|
|
9
29
|
// 2. Default Configuration
|
|
10
30
|
let config = {
|
|
11
31
|
version: 1,
|
|
@@ -27,18 +47,6 @@
|
|
|
27
47
|
}
|
|
28
48
|
}, 0);
|
|
29
49
|
|
|
30
|
-
// 4. Internal telemetry sender (Neutral naming)
|
|
31
|
-
async function safeSendTelemetry(payload) {
|
|
32
|
-
try {
|
|
33
|
-
await originalFetch('http://localhost:4000/capture', {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: { 'Content-Type': 'application/json' },
|
|
36
|
-
body: JSON.stringify(payload)
|
|
37
|
-
});
|
|
38
|
-
} catch (e) {
|
|
39
|
-
// Fail silently
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
50
|
|
|
43
51
|
// 5. Detection Helpers
|
|
44
52
|
function matchesKnownProvider(url) {
|
|
@@ -119,7 +127,8 @@
|
|
|
119
127
|
prompt,
|
|
120
128
|
output,
|
|
121
129
|
latency_ms: latency,
|
|
122
|
-
timestamp: Math.floor(Date.now() / 1000)
|
|
130
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
131
|
+
session_id: sessionId
|
|
123
132
|
};
|
|
124
133
|
|
|
125
134
|
// 9. Fire-and-forget
|
|
@@ -131,21 +140,46 @@
|
|
|
131
140
|
};
|
|
132
141
|
|
|
133
142
|
global.fetch.__dropout_patched__ = true;
|
|
143
|
+
})();
|
|
134
144
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
// 11. Manual capture (combo mode)
|
|
146
|
+
async function capture(target, options = {}) {
|
|
147
|
+
const start = Date.now();
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const result =
|
|
151
|
+
typeof target === 'function'
|
|
152
|
+
? await target()
|
|
153
|
+
: await Promise.resolve(target);
|
|
154
|
+
|
|
155
|
+
const payload = {
|
|
156
|
+
provider: options.provider || 'manual',
|
|
157
|
+
model: options.model,
|
|
158
|
+
prompt: options.prompt,
|
|
159
|
+
output: typeof result === 'string'
|
|
160
|
+
? result
|
|
161
|
+
: JSON.stringify(result).slice(0, 20000),
|
|
162
|
+
latency_ms: Date.now() - start,
|
|
163
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
164
|
+
mode: 'manual'
|
|
149
165
|
};
|
|
166
|
+
|
|
167
|
+
setTimeout(() => safeSendTelemetry(payload), 0);
|
|
168
|
+
return result;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
const payload = {
|
|
171
|
+
provider: options.provider || 'manual',
|
|
172
|
+
error: error?.message || String(error),
|
|
173
|
+
latency_ms: Date.now() - start,
|
|
174
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
175
|
+
mode: 'manual'
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
setTimeout(() => safeSendTelemetry(payload), 0);
|
|
179
|
+
throw error;
|
|
150
180
|
}
|
|
151
|
-
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = {
|
|
184
|
+
capture
|
|
185
|
+
};
|