@taphubhq/sdk-core 0.24.0 → 0.24.1

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/dist/index.cjs CHANGED
@@ -1983,20 +1983,9 @@ function classifyNetworkLevel(rtt) {
1983
1983
  // src/network/RttSmoother.ts
1984
1984
  var EMA_ALPHA = 0.25;
1985
1985
  var OUTLIER_MULTIPLIER = 3;
1986
- var DEBOUNCE_DEGRADE = 2;
1987
- var DEBOUNCE_IMPROVE = 5;
1988
- var LEVEL_RANK = {
1989
- good: 0,
1990
- fair: 1,
1991
- poor: 2,
1992
- offline: 3
1993
- };
1994
1986
  var RttSmoother = class {
1995
1987
  ema = 0;
1996
1988
  level = "good";
1997
- committed = "good";
1998
- candidate = "good";
1999
- candidateCount = 0;
2000
1989
  overrideOffline = false;
2001
1990
  consecutiveOutliers = 0;
2002
1991
  add(rtt) {
@@ -2008,23 +1997,7 @@ var RttSmoother = class {
2008
1997
  }
2009
1998
  const coldStart = this.ema === 0;
2010
1999
  this.ema = coldStart ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
2011
- const next = classifyNetworkLevel(this.ema);
2012
- if (coldStart) {
2013
- this.committed = next;
2014
- this.candidate = next;
2015
- this.candidateCount = 1;
2016
- } else {
2017
- if (next === this.candidate) {
2018
- this.candidateCount += 1;
2019
- } else {
2020
- this.candidate = next;
2021
- this.candidateCount = 1;
2022
- }
2023
- if (this.candidateCount >= this.requiredSamplesFor(next)) {
2024
- this.committed = next;
2025
- }
2026
- }
2027
- this.level = this.overrideOffline ? "offline" : this.committed;
2000
+ this.level = this.overrideOffline ? "offline" : classifyNetworkLevel(this.ema);
2028
2001
  }
2029
2002
  forceOffline() {
2030
2003
  this.overrideOffline = true;
@@ -2032,20 +2005,14 @@ var RttSmoother = class {
2032
2005
  }
2033
2006
  releaseOffline() {
2034
2007
  this.overrideOffline = false;
2035
- this.level = this.committed;
2008
+ this.level = classifyNetworkLevel(this.ema);
2036
2009
  }
2037
2010
  reset() {
2038
2011
  this.ema = 0;
2039
- this.committed = "good";
2040
- this.candidate = "good";
2041
- this.candidateCount = 0;
2042
2012
  this.consecutiveOutliers = 0;
2043
2013
  this.overrideOffline = false;
2044
2014
  this.level = "good";
2045
2015
  }
2046
- requiredSamplesFor(next) {
2047
- return LEVEL_RANK[next] > LEVEL_RANK[this.committed] ? DEBOUNCE_DEGRADE : DEBOUNCE_IMPROVE;
2048
- }
2049
2016
  };
2050
2017
 
2051
2018
  // src/network/NetworkQualityMonitor.ts
@@ -2072,7 +2039,6 @@ var NetworkQualityMonitor = class {
2072
2039
  smoother = new RttSmoother();
2073
2040
  mqttConnected = false;
2074
2041
  mqttDisconnectedAt = null;
2075
- committedNetwork = "good";
2076
2042
  committedBackend = "ok";
2077
2043
  // The last snapshot we emitted, used to decide whether the next recompute is
2078
2044
  // worth emitting. Seeded with the initial default so the first real change
@@ -2150,7 +2116,6 @@ var NetworkQualityMonitor = class {
2150
2116
  this.smoother.reset();
2151
2117
  this.mqttConnected = false;
2152
2118
  this.mqttDisconnectedAt = null;
2153
- this.committedNetwork = "good";
2154
2119
  this.committedBackend = "ok";
2155
2120
  this.emitIfChanged(this.snapshot());
2156
2121
  }
@@ -2214,26 +2179,12 @@ var NetworkQualityMonitor = class {
2214
2179
  const useConnection = realSamples.length < COLD_START_REAL_SAMPLE_THRESHOLD;
2215
2180
  const effectiveSamples = useConnection ? allSamples : realSamples;
2216
2181
  const httpSamples = effectiveSamples.filter((s) => isHttpSource(s.source));
2217
- const backend = classifyBackendHealth(httpSamples);
2218
- const metrics = this.deriveMetricsFrom(effectiveSamples);
2219
- const candidate = classifyNetworkLevel(metrics.emaForLevel);
2220
- let nextNetwork = this.smoother.level;
2221
- if (effectiveSamples.length === 0) {
2222
- nextNetwork = this.committedNetwork;
2223
- } else if (this.smoother.ema > 0) {
2224
- nextNetwork = this.smoother.level;
2225
- } else {
2226
- nextNetwork = candidate;
2227
- }
2182
+ this.committedBackend = classifyBackendHealth(httpSamples);
2228
2183
  if (this.isHardOffline()) {
2229
2184
  this.smoother.forceOffline();
2230
- nextNetwork = "offline";
2231
2185
  } else if (this.smoother.level === "offline") {
2232
2186
  this.smoother.releaseOffline();
2233
- nextNetwork = this.smoother.level;
2234
2187
  }
2235
- this.committedNetwork = nextNetwork;
2236
- this.committedBackend = backend;
2237
2188
  this.emitIfChanged(this.snapshot());
2238
2189
  }
2239
2190
  // Emits network:change when any *displayed* field of the snapshot moves. This
@@ -2294,10 +2245,12 @@ var NetworkQualityMonitor = class {
2294
2245
  snapshot() {
2295
2246
  const samples = this.allHttpAndMqttSamples();
2296
2247
  const metrics = this.deriveMetricsFrom(samples);
2248
+ const rtt = Math.round(metrics.emaForLevel);
2249
+ const network = this.smoother.level === "offline" ? "offline" : classifyNetworkLevel(rtt);
2297
2250
  return {
2298
- network: this.committedNetwork,
2251
+ network,
2299
2252
  backend: this.committedBackend,
2300
- rtt: Math.round(metrics.emaForLevel),
2253
+ rtt,
2301
2254
  jitter: Math.round(metrics.jitter),
2302
2255
  lossRate: metrics.lossRate,
2303
2256
  mqttConnected: this.mqttConnected,
package/dist/index.d.mts CHANGED
@@ -1099,7 +1099,6 @@ declare class NetworkQualityMonitor {
1099
1099
  private readonly smoother;
1100
1100
  private mqttConnected;
1101
1101
  private mqttDisconnectedAt;
1102
- private committedNetwork;
1103
1102
  private committedBackend;
1104
1103
  private lastEmitted;
1105
1104
  private tickHandle;
package/dist/index.d.ts CHANGED
@@ -1099,7 +1099,6 @@ declare class NetworkQualityMonitor {
1099
1099
  private readonly smoother;
1100
1100
  private mqttConnected;
1101
1101
  private mqttDisconnectedAt;
1102
- private committedNetwork;
1103
1102
  private committedBackend;
1104
1103
  private lastEmitted;
1105
1104
  private tickHandle;
package/dist/index.js CHANGED
@@ -1917,20 +1917,9 @@ function classifyNetworkLevel(rtt) {
1917
1917
  // src/network/RttSmoother.ts
1918
1918
  var EMA_ALPHA = 0.25;
1919
1919
  var OUTLIER_MULTIPLIER = 3;
1920
- var DEBOUNCE_DEGRADE = 2;
1921
- var DEBOUNCE_IMPROVE = 5;
1922
- var LEVEL_RANK = {
1923
- good: 0,
1924
- fair: 1,
1925
- poor: 2,
1926
- offline: 3
1927
- };
1928
1920
  var RttSmoother = class {
1929
1921
  ema = 0;
1930
1922
  level = "good";
1931
- committed = "good";
1932
- candidate = "good";
1933
- candidateCount = 0;
1934
1923
  overrideOffline = false;
1935
1924
  consecutiveOutliers = 0;
1936
1925
  add(rtt) {
@@ -1942,23 +1931,7 @@ var RttSmoother = class {
1942
1931
  }
1943
1932
  const coldStart = this.ema === 0;
1944
1933
  this.ema = coldStart ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
1945
- const next = classifyNetworkLevel(this.ema);
1946
- if (coldStart) {
1947
- this.committed = next;
1948
- this.candidate = next;
1949
- this.candidateCount = 1;
1950
- } else {
1951
- if (next === this.candidate) {
1952
- this.candidateCount += 1;
1953
- } else {
1954
- this.candidate = next;
1955
- this.candidateCount = 1;
1956
- }
1957
- if (this.candidateCount >= this.requiredSamplesFor(next)) {
1958
- this.committed = next;
1959
- }
1960
- }
1961
- this.level = this.overrideOffline ? "offline" : this.committed;
1934
+ this.level = this.overrideOffline ? "offline" : classifyNetworkLevel(this.ema);
1962
1935
  }
1963
1936
  forceOffline() {
1964
1937
  this.overrideOffline = true;
@@ -1966,20 +1939,14 @@ var RttSmoother = class {
1966
1939
  }
1967
1940
  releaseOffline() {
1968
1941
  this.overrideOffline = false;
1969
- this.level = this.committed;
1942
+ this.level = classifyNetworkLevel(this.ema);
1970
1943
  }
1971
1944
  reset() {
1972
1945
  this.ema = 0;
1973
- this.committed = "good";
1974
- this.candidate = "good";
1975
- this.candidateCount = 0;
1976
1946
  this.consecutiveOutliers = 0;
1977
1947
  this.overrideOffline = false;
1978
1948
  this.level = "good";
1979
1949
  }
1980
- requiredSamplesFor(next) {
1981
- return LEVEL_RANK[next] > LEVEL_RANK[this.committed] ? DEBOUNCE_DEGRADE : DEBOUNCE_IMPROVE;
1982
- }
1983
1950
  };
1984
1951
 
1985
1952
  // src/network/NetworkQualityMonitor.ts
@@ -2006,7 +1973,6 @@ var NetworkQualityMonitor = class {
2006
1973
  smoother = new RttSmoother();
2007
1974
  mqttConnected = false;
2008
1975
  mqttDisconnectedAt = null;
2009
- committedNetwork = "good";
2010
1976
  committedBackend = "ok";
2011
1977
  // The last snapshot we emitted, used to decide whether the next recompute is
2012
1978
  // worth emitting. Seeded with the initial default so the first real change
@@ -2084,7 +2050,6 @@ var NetworkQualityMonitor = class {
2084
2050
  this.smoother.reset();
2085
2051
  this.mqttConnected = false;
2086
2052
  this.mqttDisconnectedAt = null;
2087
- this.committedNetwork = "good";
2088
2053
  this.committedBackend = "ok";
2089
2054
  this.emitIfChanged(this.snapshot());
2090
2055
  }
@@ -2148,26 +2113,12 @@ var NetworkQualityMonitor = class {
2148
2113
  const useConnection = realSamples.length < COLD_START_REAL_SAMPLE_THRESHOLD;
2149
2114
  const effectiveSamples = useConnection ? allSamples : realSamples;
2150
2115
  const httpSamples = effectiveSamples.filter((s) => isHttpSource(s.source));
2151
- const backend = classifyBackendHealth(httpSamples);
2152
- const metrics = this.deriveMetricsFrom(effectiveSamples);
2153
- const candidate = classifyNetworkLevel(metrics.emaForLevel);
2154
- let nextNetwork = this.smoother.level;
2155
- if (effectiveSamples.length === 0) {
2156
- nextNetwork = this.committedNetwork;
2157
- } else if (this.smoother.ema > 0) {
2158
- nextNetwork = this.smoother.level;
2159
- } else {
2160
- nextNetwork = candidate;
2161
- }
2116
+ this.committedBackend = classifyBackendHealth(httpSamples);
2162
2117
  if (this.isHardOffline()) {
2163
2118
  this.smoother.forceOffline();
2164
- nextNetwork = "offline";
2165
2119
  } else if (this.smoother.level === "offline") {
2166
2120
  this.smoother.releaseOffline();
2167
- nextNetwork = this.smoother.level;
2168
2121
  }
2169
- this.committedNetwork = nextNetwork;
2170
- this.committedBackend = backend;
2171
2122
  this.emitIfChanged(this.snapshot());
2172
2123
  }
2173
2124
  // Emits network:change when any *displayed* field of the snapshot moves. This
@@ -2228,10 +2179,12 @@ var NetworkQualityMonitor = class {
2228
2179
  snapshot() {
2229
2180
  const samples = this.allHttpAndMqttSamples();
2230
2181
  const metrics = this.deriveMetricsFrom(samples);
2182
+ const rtt = Math.round(metrics.emaForLevel);
2183
+ const network = this.smoother.level === "offline" ? "offline" : classifyNetworkLevel(rtt);
2231
2184
  return {
2232
- network: this.committedNetwork,
2185
+ network,
2233
2186
  backend: this.committedBackend,
2234
- rtt: Math.round(metrics.emaForLevel),
2187
+ rtt,
2235
2188
  jitter: Math.round(metrics.jitter),
2236
2189
  lossRate: metrics.lossRate,
2237
2190
  mqttConnected: this.mqttConnected,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taphubhq/sdk-core",
3
- "version": "0.24.0",
3
+ "version": "0.24.1",
4
4
  "description": "Core SDK for building on the TabHub platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",