@getlimelight/sdk 0.7.10 → 0.7.11
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 +19 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +138 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -256,7 +256,7 @@ var LIMELIGHT_WEB_WSS_URL = "wss://api.getlimelight.io";
|
|
|
256
256
|
var LIMELIGHT_DESKTOP_WSS_URL = "ws://localhost:8484";
|
|
257
257
|
var LIMELIGHT_MCP_WS_URL = "ws://localhost:9229";
|
|
258
258
|
var WS_PATH = "/limelight";
|
|
259
|
-
var SDK_VERSION = true ? "0.7.
|
|
259
|
+
var SDK_VERSION = true ? "0.7.11" : "test-version";
|
|
260
260
|
var RENDER_THRESHOLDS = {
|
|
261
261
|
HOT_VELOCITY: 5,
|
|
262
262
|
HIGH_RENDER_COUNT: 50,
|
|
@@ -280,6 +280,9 @@ var BINARY_CONTENT_TYPES = [
|
|
|
280
280
|
"application/gzip"
|
|
281
281
|
];
|
|
282
282
|
var MAX_BODY_SIZE = 1024 * 1024;
|
|
283
|
+
var POSTHOG_API_KEY = true ? "phc_I4dF0Du3McRPRCdSiJfvTBMWrbsapXoTP83uaHTA1ry" : "";
|
|
284
|
+
var POSTHOG_HOST = true ? "https://us.i.posthog.com" : "";
|
|
285
|
+
var STORAGE_KEY = "limelight_anon_id";
|
|
283
286
|
|
|
284
287
|
// src/helpers/safety/redactSensitiveHeaders.ts
|
|
285
288
|
var redactSensitiveHeaders = (headers) => {
|
|
@@ -2911,6 +2914,119 @@ var createWithLimelight = (sendMessage, getSessionId, getConfig, options) => {
|
|
|
2911
2914
|
};
|
|
2912
2915
|
};
|
|
2913
2916
|
|
|
2917
|
+
// src/limelight/telemetry.ts
|
|
2918
|
+
var anonymousId = null;
|
|
2919
|
+
var enabled = false;
|
|
2920
|
+
var framework = "unknown";
|
|
2921
|
+
var detectFramework = () => {
|
|
2922
|
+
try {
|
|
2923
|
+
if (typeof navigator !== "undefined" && "ReactNative" in navigator)
|
|
2924
|
+
return "react-native";
|
|
2925
|
+
if (typeof process !== "undefined" && (process.env?.__NEXT_RUNTIME__ || process.env?.NEXT_RUNTIME))
|
|
2926
|
+
return "next";
|
|
2927
|
+
if (typeof window !== "undefined" && window.__NEXT_DATA__)
|
|
2928
|
+
return "next";
|
|
2929
|
+
if (hasDOM()) return "react";
|
|
2930
|
+
if (isServer()) return "node";
|
|
2931
|
+
} catch {
|
|
2932
|
+
}
|
|
2933
|
+
return "unknown";
|
|
2934
|
+
};
|
|
2935
|
+
var generateId = () => {
|
|
2936
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
2937
|
+
const r = Math.random() * 16 | 0;
|
|
2938
|
+
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
2939
|
+
});
|
|
2940
|
+
};
|
|
2941
|
+
var getOrCreateAnonymousId = () => {
|
|
2942
|
+
if (anonymousId) return anonymousId;
|
|
2943
|
+
try {
|
|
2944
|
+
if (typeof localStorage !== "undefined") {
|
|
2945
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
2946
|
+
if (stored) {
|
|
2947
|
+
anonymousId = stored;
|
|
2948
|
+
return anonymousId;
|
|
2949
|
+
}
|
|
2950
|
+
anonymousId = generateId();
|
|
2951
|
+
localStorage.setItem(STORAGE_KEY, anonymousId);
|
|
2952
|
+
return anonymousId;
|
|
2953
|
+
}
|
|
2954
|
+
} catch {
|
|
2955
|
+
}
|
|
2956
|
+
try {
|
|
2957
|
+
const _require = globalThis["require"];
|
|
2958
|
+
if (_require) {
|
|
2959
|
+
const fs = _require("fs");
|
|
2960
|
+
const os = _require("os");
|
|
2961
|
+
const path = _require("path");
|
|
2962
|
+
const filePath = path.join(os.homedir(), ".limelight_telemetry_id");
|
|
2963
|
+
try {
|
|
2964
|
+
anonymousId = fs.readFileSync(filePath, "utf-8").trim();
|
|
2965
|
+
if (anonymousId) return anonymousId;
|
|
2966
|
+
} catch {
|
|
2967
|
+
}
|
|
2968
|
+
anonymousId = generateId();
|
|
2969
|
+
fs.writeFileSync(filePath, anonymousId, "utf-8");
|
|
2970
|
+
return anonymousId;
|
|
2971
|
+
}
|
|
2972
|
+
} catch {
|
|
2973
|
+
}
|
|
2974
|
+
anonymousId = generateId();
|
|
2975
|
+
return anonymousId;
|
|
2976
|
+
};
|
|
2977
|
+
var capture = (event, properties = {}) => {
|
|
2978
|
+
if (!enabled) return;
|
|
2979
|
+
try {
|
|
2980
|
+
const payload = {
|
|
2981
|
+
api_key: POSTHOG_API_KEY,
|
|
2982
|
+
event,
|
|
2983
|
+
distinct_id: getOrCreateAnonymousId(),
|
|
2984
|
+
properties: {
|
|
2985
|
+
...properties,
|
|
2986
|
+
sdk_version: SDK_VERSION,
|
|
2987
|
+
framework
|
|
2988
|
+
}
|
|
2989
|
+
};
|
|
2990
|
+
fetch(`${POSTHOG_HOST}/capture/`, {
|
|
2991
|
+
method: "POST",
|
|
2992
|
+
headers: { "Content-Type": "application/json" },
|
|
2993
|
+
body: JSON.stringify(payload)
|
|
2994
|
+
}).catch(() => {
|
|
2995
|
+
});
|
|
2996
|
+
} catch {
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
var telemetry = {
|
|
3000
|
+
init(telemetryEnabled) {
|
|
3001
|
+
enabled = telemetryEnabled;
|
|
3002
|
+
if (!enabled) return;
|
|
3003
|
+
framework = detectFramework();
|
|
3004
|
+
capture("sdk_initialized", {
|
|
3005
|
+
framework,
|
|
3006
|
+
device_id: getOrCreateAnonymousId()
|
|
3007
|
+
});
|
|
3008
|
+
},
|
|
3009
|
+
sessionStarted() {
|
|
3010
|
+
capture("session_started");
|
|
3011
|
+
},
|
|
3012
|
+
sessionEnded(durationSeconds, eventCount) {
|
|
3013
|
+
capture("session_ended", {
|
|
3014
|
+
duration_seconds: durationSeconds,
|
|
3015
|
+
event_count: eventCount
|
|
3016
|
+
});
|
|
3017
|
+
},
|
|
3018
|
+
timelineGenerated(eventsCorrelated) {
|
|
3019
|
+
capture("timeline_generated", {
|
|
3020
|
+
events_correlated: eventsCorrelated,
|
|
3021
|
+
framework
|
|
3022
|
+
});
|
|
3023
|
+
},
|
|
3024
|
+
shutdown() {
|
|
3025
|
+
enabled = false;
|
|
3026
|
+
anonymousId = null;
|
|
3027
|
+
}
|
|
3028
|
+
};
|
|
3029
|
+
|
|
2914
3030
|
// src/limelight/LimelightClient.ts
|
|
2915
3031
|
var LimelightClient = class {
|
|
2916
3032
|
ws = null;
|
|
@@ -2922,6 +3038,8 @@ var LimelightClient = class {
|
|
|
2922
3038
|
reconnectTimer = null;
|
|
2923
3039
|
messageQueue = [];
|
|
2924
3040
|
maxQueueSize = 100;
|
|
3041
|
+
sessionStartTime = 0;
|
|
3042
|
+
sessionEventCount = 0;
|
|
2925
3043
|
networkInterceptor;
|
|
2926
3044
|
xhrInterceptor;
|
|
2927
3045
|
httpInterceptor;
|
|
@@ -3025,6 +3143,7 @@ var LimelightClient = class {
|
|
|
3025
3143
|
console.error("[Limelight] Failed to setup interceptors:", error);
|
|
3026
3144
|
}
|
|
3027
3145
|
}
|
|
3146
|
+
telemetry.init(this.config.telemetry ?? true);
|
|
3028
3147
|
}
|
|
3029
3148
|
/**
|
|
3030
3149
|
* Establishes a WebSocket connection to the Limelight server.
|
|
@@ -3089,8 +3208,11 @@ var LimelightClient = class {
|
|
|
3089
3208
|
};
|
|
3090
3209
|
this.ws.onopen = () => {
|
|
3091
3210
|
this.reconnectAttempts = 0;
|
|
3211
|
+
this.sessionStartTime = Date.now();
|
|
3212
|
+
this.sessionEventCount = 0;
|
|
3092
3213
|
this.flushMessageQueue();
|
|
3093
3214
|
this.sendMessage(message);
|
|
3215
|
+
telemetry.sessionStarted();
|
|
3094
3216
|
};
|
|
3095
3217
|
this.ws.onmessage = (event) => {
|
|
3096
3218
|
try {
|
|
@@ -3173,6 +3295,12 @@ var LimelightClient = class {
|
|
|
3173
3295
|
* @returns {void}
|
|
3174
3296
|
*/
|
|
3175
3297
|
sendMessage(message) {
|
|
3298
|
+
this.sessionEventCount++;
|
|
3299
|
+
if ("phase" in message && message.phase === "RENDER_SNAPSHOT" && "profiles" in message) {
|
|
3300
|
+
telemetry.timelineGenerated(
|
|
3301
|
+
message.profiles?.length ?? 0
|
|
3302
|
+
);
|
|
3303
|
+
}
|
|
3176
3304
|
if (this.ws?.readyState === 1) {
|
|
3177
3305
|
this.flushMessageQueue();
|
|
3178
3306
|
if (this.ws?.readyState === 1) {
|
|
@@ -3238,7 +3366,15 @@ var LimelightClient = class {
|
|
|
3238
3366
|
this.renderInterceptor.cleanup();
|
|
3239
3367
|
this.stateInterceptor.cleanup();
|
|
3240
3368
|
this.requestBridge.cleanup();
|
|
3369
|
+
if (this.sessionStartTime > 0) {
|
|
3370
|
+
const durationSeconds = Math.round(
|
|
3371
|
+
(Date.now() - this.sessionStartTime) / 1e3
|
|
3372
|
+
);
|
|
3373
|
+
telemetry.sessionEnded(durationSeconds, this.sessionEventCount);
|
|
3374
|
+
}
|
|
3241
3375
|
this.reconnectAttempts = 0;
|
|
3376
|
+
this.sessionStartTime = 0;
|
|
3377
|
+
this.sessionEventCount = 0;
|
|
3242
3378
|
this.messageQueue = [];
|
|
3243
3379
|
}
|
|
3244
3380
|
/**
|
|
@@ -3249,6 +3385,7 @@ var LimelightClient = class {
|
|
|
3249
3385
|
*/
|
|
3250
3386
|
reset() {
|
|
3251
3387
|
this.disconnect();
|
|
3388
|
+
telemetry.shutdown();
|
|
3252
3389
|
this.config = null;
|
|
3253
3390
|
this.sessionId = "";
|
|
3254
3391
|
}
|