@m4trix/trace-viewer 0.20.0 → 0.20.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.js CHANGED
@@ -13,7 +13,7 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
13
13
  import { initTRPC } from '@trpc/server';
14
14
 
15
15
  // package.json
16
- var version = "0.20.0";
16
+ var version = "0.20.1";
17
17
 
18
18
  // src/cli-args.ts
19
19
  var DEFAULT_PORT = 4319;
@@ -360,6 +360,9 @@ var TraceToolError = class extends Error {
360
360
  this.name = "TraceToolError";
361
361
  }
362
362
  };
363
+ function isUnsupportedSchemaVersionError(error) {
364
+ return error instanceof Error && error.name === "UnsupportedSchemaVersionError";
365
+ }
363
366
  function shortId(id) {
364
367
  return id.length > 12 ? id.slice(0, 8) : id;
365
368
  }
@@ -369,20 +372,24 @@ function compareRunsByStartTime(left, right) {
369
372
  async function scanTraces(api, query, visit, maxScan = MAX_TRACE_SCAN) {
370
373
  let cursor;
371
374
  let scanned = 0;
375
+ let skippedIncompatibleCount = 0;
372
376
  while (scanned < maxScan) {
373
377
  const page = await api.listTraces({
374
378
  ...query,
375
379
  limit: Math.min(SCAN_PAGE_SIZE, maxScan - scanned),
376
380
  ...cursor ? { cursor } : {}
377
381
  });
382
+ skippedIncompatibleCount += page.skippedIncompatibleCount ?? 0;
378
383
  for (const trace of page.traces) {
379
384
  scanned += 1;
380
- if (!visit(trace)) return { scanned, exhausted: false };
385
+ if (!visit(trace)) return { scanned, exhausted: false, skippedIncompatibleCount };
386
+ }
387
+ if (!page.nextCursor || page.traces.length === 0) {
388
+ return { scanned, exhausted: true, skippedIncompatibleCount };
381
389
  }
382
- if (!page.nextCursor || page.traces.length === 0) return { scanned, exhausted: true };
383
390
  cursor = page.nextCursor;
384
391
  }
385
- return { scanned, exhausted: false };
392
+ return { scanned, exhausted: false, skippedIncompatibleCount };
386
393
  }
387
394
  async function resolveTrace(api, traceRef) {
388
395
  const ref = traceRef.trim();
@@ -393,7 +400,10 @@ async function resolveTrace(api, traceRef) {
393
400
  if (!latest) throw new TraceToolError("No traces found in the trace store.");
394
401
  return requireRecord(api, latest.traceId);
395
402
  }
396
- const exact = await api.getTrace(ref).catch(() => null);
403
+ const exact = await api.getTrace(ref).catch((error) => {
404
+ if (isUnsupportedSchemaVersionError(error)) throw new TraceToolError(error.message);
405
+ return null;
406
+ });
397
407
  if (exact) return exact;
398
408
  const candidates = [];
399
409
  await scanTraces(api, {}, (trace) => {
@@ -1207,7 +1217,7 @@ var TraceTools = class {
1207
1217
  const offset = input.offset ?? 0;
1208
1218
  const namePattern = input.name ? compileUserRegex(input.name, "name") : null;
1209
1219
  const matches = [];
1210
- const { scanned, exhausted } = await scanTraces(
1220
+ const { scanned, exhausted, skippedIncompatibleCount } = await scanTraces(
1211
1221
  this.api,
1212
1222
  {
1213
1223
  ...input.status ? { status: input.status } : {},
@@ -1222,9 +1232,12 @@ var TraceTools = class {
1222
1232
  return matches.length <= offset + limit;
1223
1233
  }
1224
1234
  );
1235
+ const incompatibleNote = skippedIncompatibleCount > 0 ? `Note: skipped ${plural(skippedIncompatibleCount, "trace")} written with a newer schemaVersion; upgrade @m4trix/tracing / @m4trix/trace-viewer to view them.` : "";
1225
1236
  const page = matches.slice(offset, offset + limit);
1226
1237
  if (page.length === 0) {
1227
- return offset > 0 ? `No traces at offset ${offset}.` : "No traces match.";
1238
+ const empty = offset > 0 ? `No traces at offset ${offset}.` : "No traces match.";
1239
+ return incompatibleNote ? `${empty}
1240
+ ${incompatibleNote}` : empty;
1228
1241
  }
1229
1242
  const hasMore = matches.length > offset + limit;
1230
1243
  const lines = page.map((trace) => {
@@ -1232,7 +1245,12 @@ var TraceTools = class {
1232
1245
  return `${formatTraceRow(trace)}${loaded}`;
1233
1246
  });
1234
1247
  const footer = hasMore ? `More traces available: call again with offset=${offset + limit}.` : !exhausted && scanned >= MAX_TRACE_SCAN ? `Scan stopped after ${MAX_TRACE_SCAN} traces; narrow with since/until/status.` : "";
1235
- return [`${plural(page.length, "trace")} (newest first, offset ${offset}):`, ...lines, footer].filter(Boolean).join("\n");
1248
+ return [
1249
+ `${plural(page.length, "trace")} (newest first, offset ${offset}):`,
1250
+ ...lines,
1251
+ footer,
1252
+ incompatibleNote
1253
+ ].filter(Boolean).join("\n");
1236
1254
  }
1237
1255
  async getTrace(input) {
1238
1256
  const record = await resolveTrace(this.api, input.traceId);