@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/cli/init.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  buildImportGraph
4
- } from "../chunk-TJ6ETQPH.js";
4
+ } from "../chunk-LAMTBURS.js";
5
5
  import {
6
6
  addCoverageMapEnv,
7
7
  detectAgents,
package/dist/index.cjs CHANGED
@@ -19143,7 +19143,7 @@ function registerGlasstrace(options) {
19143
19143
  if (config2.verbose) {
19144
19144
  console.info("[glasstrace] Background init firing.");
19145
19145
  }
19146
- await performInit(config2, anonKey, "0.4.0");
19146
+ await performInit(config2, anonKey, "0.4.1");
19147
19147
  maybeInstallConsoleCapture();
19148
19148
  } catch (err) {
19149
19149
  console.warn(
@@ -19163,7 +19163,7 @@ function registerGlasstrace(options) {
19163
19163
  if (config2.verbose) {
19164
19164
  console.info("[glasstrace] Background init firing.");
19165
19165
  }
19166
- await performInit(config2, anonKey, "0.4.0");
19166
+ await performInit(config2, anonKey, "0.4.1");
19167
19167
  maybeInstallConsoleCapture();
19168
19168
  } catch (err) {
19169
19169
  console.warn(
@@ -19185,7 +19185,7 @@ function registerGlasstrace(options) {
19185
19185
  if (config2.verbose) {
19186
19186
  console.info("[glasstrace] Background init firing.");
19187
19187
  }
19188
- await performInit(config2, anonKeyForInit, "0.4.0");
19188
+ await performInit(config2, anonKeyForInit, "0.4.1");
19189
19189
  maybeInstallConsoleCapture();
19190
19190
  } catch (err) {
19191
19191
  console.warn(
@@ -19284,7 +19284,10 @@ async function uploadSourceMaps(apiKey, endpoint, buildHash, maps) {
19284
19284
  sourceMap: m.content
19285
19285
  }))
19286
19286
  };
19287
- const baseUrl = endpoint.replace(/\/+$/, "");
19287
+ let baseUrl = endpoint;
19288
+ while (baseUrl.endsWith("/")) {
19289
+ baseUrl = baseUrl.slice(0, -1);
19290
+ }
19288
19291
  const response = await fetch(`${baseUrl}/v1/source-maps`, {
19289
19292
  method: "POST",
19290
19293
  headers: {
@@ -19370,6 +19373,43 @@ async function handleSourceMapUpload(distDir) {
19370
19373
 
19371
19374
  // src/capture-error.ts
19372
19375
  init_esm();
19376
+
19377
+ // src/nudge/error-nudge.ts
19378
+ var import_node_fs2 = require("fs");
19379
+ var import_node_path3 = require("path");
19380
+ var hasFired = false;
19381
+ function sanitize(input) {
19382
+ return input.replace(/[\x00-\x1f\x7f]/g, "");
19383
+ }
19384
+ function maybeShowMcpNudge(errorSummary) {
19385
+ if (hasFired) {
19386
+ return;
19387
+ }
19388
+ const config2 = resolveConfig();
19389
+ if (isProductionDisabled(config2)) {
19390
+ return;
19391
+ }
19392
+ let markerExists = false;
19393
+ try {
19394
+ const markerPath = (0, import_node_path3.join)(process.cwd(), ".glasstrace", "mcp-connected");
19395
+ markerExists = (0, import_node_fs2.existsSync)(markerPath);
19396
+ } catch {
19397
+ markerExists = false;
19398
+ }
19399
+ if (markerExists) {
19400
+ return;
19401
+ }
19402
+ hasFired = true;
19403
+ const safe = sanitize(errorSummary);
19404
+ process.stderr.write(
19405
+ `[glasstrace] Error captured: ${safe}
19406
+ Debug with AI: ask your agent "What's the latest Glasstrace error?"
19407
+ Not connected? Run: npx glasstrace mcp add
19408
+ `
19409
+ );
19410
+ }
19411
+
19412
+ // src/capture-error.ts
19373
19413
  function captureError(error48) {
19374
19414
  try {
19375
19415
  const span = trace.getSpan(context.active());
@@ -19381,6 +19421,7 @@ function captureError(error48) {
19381
19421
  attributes["error.type"] = error48.constructor.name;
19382
19422
  }
19383
19423
  span.addEvent("glasstrace.error", attributes);
19424
+ maybeShowMcpNudge(String(error48));
19384
19425
  } catch {
19385
19426
  }
19386
19427
  }
@@ -19506,12 +19547,18 @@ function extractImports(fileContent) {
19506
19547
  imports.push(importPath);
19507
19548
  }
19508
19549
  };
19509
- const esImportRegex = /import\s+(?:(?:[\w*{}\s,]+)\s+from\s+)?['"]([^'"]+)['"]/g;
19550
+ const esFromImportRegex = /\bimport\b[^'"]+\bfrom\s+['"]([^'"]+)['"]/g;
19551
+ const esSideEffectRegex = /\bimport\s+['"]([^'"]+)['"]/g;
19510
19552
  let match;
19511
- match = esImportRegex.exec(fileContent);
19553
+ match = esFromImportRegex.exec(fileContent);
19554
+ while (match !== null) {
19555
+ addUnique(match[1]);
19556
+ match = esFromImportRegex.exec(fileContent);
19557
+ }
19558
+ match = esSideEffectRegex.exec(fileContent);
19512
19559
  while (match !== null) {
19513
19560
  addUnique(match[1]);
19514
- match = esImportRegex.exec(fileContent);
19561
+ match = esSideEffectRegex.exec(fileContent);
19515
19562
  }
19516
19563
  const requireRegex = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
19517
19564
  match = requireRegex.exec(fileContent);