@glasstrace/sdk 0.4.0 → 0.4.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.d.cts CHANGED
@@ -467,6 +467,9 @@ declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: s
467
467
  * explicit, opt-in API for manual error reporting. If no span is active
468
468
  * or OTel is not available, the call is silently ignored.
469
469
  *
470
+ * On the first captured error, may display a one-time diagnostic nudge
471
+ * to stderr if the MCP connection marker is absent (dev environments only).
472
+ *
470
473
  * @param error - The error to capture. Accepts `Error` objects, strings, or any value.
471
474
  *
472
475
  * @example
package/dist/index.d.ts CHANGED
@@ -467,6 +467,9 @@ declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: s
467
467
  * explicit, opt-in API for manual error reporting. If no span is active
468
468
  * or OTel is not available, the call is silently ignored.
469
469
  *
470
+ * On the first captured error, may display a one-time diagnostic nudge
471
+ * to stderr if the MCP connection marker is absent (dev environments only).
472
+ *
470
473
  * @param error - The error to capture. Accepts `Error` objects, strings, or any value.
471
474
  *
472
475
  * @example
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  buildImportGraph,
3
3
  discoverTestFiles,
4
4
  extractImports
5
- } from "./chunk-TJ6ETQPH.js";
5
+ } from "./chunk-LAMTBURS.js";
6
6
  import {
7
7
  DEFAULT_CAPTURE_CONFIG,
8
8
  GLASSTRACE_ATTRIBUTE_NAMES,
@@ -3542,7 +3542,7 @@ function registerGlasstrace(options) {
3542
3542
  if (config.verbose) {
3543
3543
  console.info("[glasstrace] Background init firing.");
3544
3544
  }
3545
- await performInit(config, anonKey, "0.4.0");
3545
+ await performInit(config, anonKey, "0.4.1");
3546
3546
  maybeInstallConsoleCapture();
3547
3547
  } catch (err) {
3548
3548
  console.warn(
@@ -3562,7 +3562,7 @@ function registerGlasstrace(options) {
3562
3562
  if (config.verbose) {
3563
3563
  console.info("[glasstrace] Background init firing.");
3564
3564
  }
3565
- await performInit(config, anonKey, "0.4.0");
3565
+ await performInit(config, anonKey, "0.4.1");
3566
3566
  maybeInstallConsoleCapture();
3567
3567
  } catch (err) {
3568
3568
  console.warn(
@@ -3584,7 +3584,7 @@ function registerGlasstrace(options) {
3584
3584
  if (config.verbose) {
3585
3585
  console.info("[glasstrace] Background init firing.");
3586
3586
  }
3587
- await performInit(config, anonKeyForInit, "0.4.0");
3587
+ await performInit(config, anonKeyForInit, "0.4.1");
3588
3588
  maybeInstallConsoleCapture();
3589
3589
  } catch (err) {
3590
3590
  console.warn(
@@ -3683,7 +3683,10 @@ async function uploadSourceMaps(apiKey, endpoint, buildHash, maps) {
3683
3683
  sourceMap: m.content
3684
3684
  }))
3685
3685
  };
3686
- const baseUrl = endpoint.replace(/\/+$/, "");
3686
+ let baseUrl = endpoint;
3687
+ while (baseUrl.endsWith("/")) {
3688
+ baseUrl = baseUrl.slice(0, -1);
3689
+ }
3687
3690
  const response = await fetch(`${baseUrl}/v1/source-maps`, {
3688
3691
  method: "POST",
3689
3692
  headers: {
@@ -3767,6 +3770,41 @@ async function handleSourceMapUpload(distDir) {
3767
3770
  }
3768
3771
  }
3769
3772
 
3773
+ // src/nudge/error-nudge.ts
3774
+ import { existsSync } from "fs";
3775
+ import { join as join3 } from "path";
3776
+ var hasFired = false;
3777
+ function sanitize(input) {
3778
+ return input.replace(/[\x00-\x1f\x7f]/g, "");
3779
+ }
3780
+ function maybeShowMcpNudge(errorSummary) {
3781
+ if (hasFired) {
3782
+ return;
3783
+ }
3784
+ const config = resolveConfig();
3785
+ if (isProductionDisabled(config)) {
3786
+ return;
3787
+ }
3788
+ let markerExists = false;
3789
+ try {
3790
+ const markerPath = join3(process.cwd(), ".glasstrace", "mcp-connected");
3791
+ markerExists = existsSync(markerPath);
3792
+ } catch {
3793
+ markerExists = false;
3794
+ }
3795
+ if (markerExists) {
3796
+ return;
3797
+ }
3798
+ hasFired = true;
3799
+ const safe = sanitize(errorSummary);
3800
+ process.stderr.write(
3801
+ `[glasstrace] Error captured: ${safe}
3802
+ Debug with AI: ask your agent "What's the latest Glasstrace error?"
3803
+ Not connected? Run: npx glasstrace mcp add
3804
+ `
3805
+ );
3806
+ }
3807
+
3770
3808
  // src/capture-error.ts
3771
3809
  function captureError(error) {
3772
3810
  try {
@@ -3779,6 +3817,7 @@ function captureError(error) {
3779
3817
  attributes["error.type"] = error.constructor.name;
3780
3818
  }
3781
3819
  span.addEvent("glasstrace.error", attributes);
3820
+ maybeShowMcpNudge(String(error));
3782
3821
  } catch {
3783
3822
  }
3784
3823
  }