@adventurelabs/scout-core 1.0.62 → 1.0.63

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.
@@ -75,6 +75,7 @@ export async function server_load_herd_modules() {
75
75
  msg: "No herds found",
76
76
  data: null,
77
77
  time_finished: Date.now(),
78
+ time_sent: Date.now(),
78
79
  server_processing_time_ms: Date.now() - startTime,
79
80
  };
80
81
  }
@@ -87,11 +88,14 @@ export async function server_load_herd_modules() {
87
88
  const endTime = Date.now();
88
89
  const totalLoadTime = endTime - startTime;
89
90
  console.log(`[server_load_herd_modules] Loaded ${new_herds.data.length} herds in ${totalLoadTime}ms (parallel processing)`);
91
+ // Record the time when we're about to send the response
92
+ const timeSent = Date.now();
90
93
  return {
91
94
  status: EnumWebResponse.SUCCESS,
92
95
  msg: "Herd modules loaded successfully",
93
96
  data: serialized_herd_modules,
94
97
  time_finished: endTime,
98
+ time_sent: timeSent,
95
99
  server_processing_time_ms: totalLoadTime,
96
100
  };
97
101
  }
@@ -82,14 +82,37 @@ export function useScoutRefresh(options = {}) {
82
82
  if (herdModulesResponse.status === EnumWebResponse.SUCCESS &&
83
83
  herdModulesResponse.data) {
84
84
  const serverFinishTime = herdModulesResponse.time_finished;
85
+ const serverSentTime = herdModulesResponse.time_sent;
85
86
  const clientReceiveTime = Date.now();
86
- const estimatedNetworkLatency = clientReceiveTime - serverFinishTime;
87
+ // More accurate network latency: from when server sent to when client received
88
+ const estimatedNetworkLatency = clientReceiveTime - serverSentTime;
87
89
  networkLatencyMs = Math.max(0, estimatedNetworkLatency);
90
+ // Time between server finishing processing and sending response
91
+ const serverOverhead = serverSentTime - serverFinishTime;
88
92
  console.log(`[useScoutRefresh] Network latency calculation:`);
89
- console.log(` - Server finished at: ${new Date(serverFinishTime).toISOString()}`);
93
+ console.log(` - Server finished processing at: ${new Date(serverFinishTime).toISOString()}`);
94
+ console.log(` - Server sent response at: ${new Date(serverSentTime).toISOString()}`);
90
95
  console.log(` - Client received at: ${new Date(clientReceiveTime).toISOString()}`);
91
- console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
92
96
  console.log(` - Server processing time: ${herdModulesResponse.server_processing_time_ms}ms`);
97
+ console.log(` - Server overhead (finish to send): ${serverOverhead}ms`);
98
+ console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
99
+ console.log(` - Client total time: ${herdModulesDuration}ms`);
100
+ console.log(` - Breakdown: ${herdModulesResponse.server_processing_time_ms}ms (server) + ${serverOverhead}ms (overhead) + ${networkLatencyMs}ms (network) = ${herdModulesResponse.server_processing_time_ms +
101
+ serverOverhead +
102
+ networkLatencyMs}ms`);
103
+ // Additional analysis
104
+ if (herdModulesResponse.data.length > 0) {
105
+ const totalDevices = herdModulesResponse.data.reduce((sum, hm) => sum + (hm.devices?.length || 0), 0);
106
+ const totalEvents = herdModulesResponse.data.reduce((sum, hm) => sum + (hm.events?.length || 0), 0);
107
+ console.log(` - Response size analysis:`);
108
+ console.log(` * Herds: ${herdModulesResponse.data.length}`);
109
+ console.log(` * Total devices: ${totalDevices}`);
110
+ console.log(` * Total events: ${totalEvents}`);
111
+ console.log(` * Estimated payload: ~${Math.round((herdModulesResponse.data.length * 2 +
112
+ totalDevices * 3 +
113
+ totalEvents * 5) /
114
+ 1024)}KB`);
115
+ }
93
116
  }
94
117
  // Store timing values
95
118
  timingRefs.current.herdModulesDuration = herdModulesDuration;
@@ -109,6 +132,7 @@ export function useScoutRefresh(options = {}) {
109
132
  console.log(` - Estimated network latency: ${networkLatencyMs}ms`);
110
133
  }
111
134
  // Validate API responses
135
+ const validationStartTime = Date.now();
112
136
  if (!herdModulesResponse.data ||
113
137
  !Array.isArray(herdModulesResponse.data)) {
114
138
  throw new Error("Invalid herd modules response");
@@ -116,6 +140,8 @@ export function useScoutRefresh(options = {}) {
116
140
  if (!res_new_user || !res_new_user.data) {
117
141
  throw new Error("Invalid user response");
118
142
  }
143
+ const validationDuration = Date.now() - validationStartTime;
144
+ console.log(`[useScoutRefresh] Data validation took: ${validationDuration}ms`);
119
145
  // Use the validated data
120
146
  const compatible_new_herd_modules = herdModulesResponse.data;
121
147
  // Measure data processing duration
@@ -50,5 +50,6 @@ export interface IHerdModulesResponseWithStatus {
50
50
  msg: string;
51
51
  data: IHerdModule[] | null;
52
52
  time_finished: number;
53
+ time_sent: number;
53
54
  server_processing_time_ms: number;
54
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",