@agent-inspect/viewer 6.12.1 → 6.13.0
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 +295 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +295 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -500,12 +500,12 @@ function persistedInspectEventToTraceEvents(event) {
|
|
|
500
500
|
if (!isPersistedInspectEvent(event)) {
|
|
501
501
|
throw new Error("Invalid PersistedInspectEvent: failed isPersistedInspectEvent");
|
|
502
502
|
}
|
|
503
|
-
const
|
|
504
|
-
if (
|
|
505
|
-
if (
|
|
506
|
-
if (
|
|
507
|
-
if (
|
|
508
|
-
if (
|
|
503
|
+
const legacyEvent2 = event.attributes?.legacyEvent;
|
|
504
|
+
if (legacyEvent2 === "run_started") return [fromLegacyRunStarted(event)];
|
|
505
|
+
if (legacyEvent2 === "run_completed") return [fromLegacyRunCompleted(event)];
|
|
506
|
+
if (legacyEvent2 === "step_started") return [fromLegacyStepStarted(event)];
|
|
507
|
+
if (legacyEvent2 === "step_completed") return [fromLegacyStepCompleted(event)];
|
|
508
|
+
if (legacyEvent2 === "outcome_observed") return [fromLegacyOutcomeObserved(event)];
|
|
509
509
|
if (event.kind === "RUN") {
|
|
510
510
|
return fromNativeRun(event);
|
|
511
511
|
}
|
|
@@ -2223,6 +2223,265 @@ async function resolveSuiteCaseTrace(suiteCase, options) {
|
|
|
2223
2223
|
};
|
|
2224
2224
|
}
|
|
2225
2225
|
|
|
2226
|
+
// packages/core/src/checks/logical-events.ts
|
|
2227
|
+
function isRecord5(value) {
|
|
2228
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2229
|
+
}
|
|
2230
|
+
function legacyEvent(event) {
|
|
2231
|
+
const value = event.attributes?.legacyEvent;
|
|
2232
|
+
return typeof value === "string" ? value : void 0;
|
|
2233
|
+
}
|
|
2234
|
+
function stepIdOf(event) {
|
|
2235
|
+
const value = event.attributes?.stepId;
|
|
2236
|
+
if (typeof value === "string" && value.trim() !== "") return value;
|
|
2237
|
+
return void 0;
|
|
2238
|
+
}
|
|
2239
|
+
function cloneEvent(event) {
|
|
2240
|
+
return {
|
|
2241
|
+
...event,
|
|
2242
|
+
...event.attributes !== void 0 ? { attributes: { ...event.attributes } } : {},
|
|
2243
|
+
...event.error !== void 0 ? { error: { ...event.error } } : {},
|
|
2244
|
+
...event.tokenUsage !== void 0 ? { tokenUsage: { ...event.tokenUsage } } : {},
|
|
2245
|
+
...event.source !== void 0 ? { source: { ...event.source } } : {}
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
function mergeAttributes(start, complete) {
|
|
2249
|
+
const merged = {
|
|
2250
|
+
...isRecord5(complete.attributes) ? complete.attributes : {},
|
|
2251
|
+
...isRecord5(start.attributes) ? start.attributes : {}
|
|
2252
|
+
};
|
|
2253
|
+
merged.legacyEvent = start.attributes?.legacyEvent ?? complete.attributes?.legacyEvent;
|
|
2254
|
+
merged.legacyCompleteEvent = complete.attributes?.legacyEvent;
|
|
2255
|
+
if (complete.attributes?.errorStack !== void 0) {
|
|
2256
|
+
merged.errorStack = complete.attributes.errorStack;
|
|
2257
|
+
}
|
|
2258
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
2259
|
+
}
|
|
2260
|
+
function pairStartComplete(start, complete) {
|
|
2261
|
+
const attributes = mergeAttributes(start, complete);
|
|
2262
|
+
const paired = {
|
|
2263
|
+
...cloneEvent(start),
|
|
2264
|
+
status: complete.status,
|
|
2265
|
+
timestamp: complete.timestamp ?? start.timestamp,
|
|
2266
|
+
...complete.endedAt !== void 0 ? { endedAt: complete.endedAt } : {},
|
|
2267
|
+
...complete.durationMs !== void 0 ? { durationMs: complete.durationMs } : {},
|
|
2268
|
+
...complete.error !== void 0 ? { error: { ...complete.error } } : {},
|
|
2269
|
+
...complete.tokenUsage !== void 0 && start.tokenUsage === void 0 ? { tokenUsage: { ...complete.tokenUsage } } : {},
|
|
2270
|
+
...attributes !== void 0 ? { attributes } : {}
|
|
2271
|
+
};
|
|
2272
|
+
return {
|
|
2273
|
+
...paired,
|
|
2274
|
+
sourceEventIds: Object.freeze([start.eventId, complete.eventId]),
|
|
2275
|
+
projection: {
|
|
2276
|
+
paired: true,
|
|
2277
|
+
absorbedEventIds: Object.freeze([complete.eventId]),
|
|
2278
|
+
parentNormalized: false,
|
|
2279
|
+
...start.parentId !== void 0 ? { originalParentId: start.parentId } : {}
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
function asLogical(event, extras) {
|
|
2284
|
+
return {
|
|
2285
|
+
...cloneEvent(event),
|
|
2286
|
+
sourceEventIds: Object.freeze([event.eventId]),
|
|
2287
|
+
projection: {
|
|
2288
|
+
paired: false,
|
|
2289
|
+
absorbedEventIds: Object.freeze([]),
|
|
2290
|
+
parentNormalized: extras?.parentNormalized === true,
|
|
2291
|
+
...{}
|
|
2292
|
+
}
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
function projectLogicalEvents(events) {
|
|
2296
|
+
const diagnostics = [];
|
|
2297
|
+
const byRun = /* @__PURE__ */ new Map();
|
|
2298
|
+
for (const event of events) {
|
|
2299
|
+
const list = byRun.get(event.runId) ?? [];
|
|
2300
|
+
list.push(event);
|
|
2301
|
+
byRun.set(event.runId, list);
|
|
2302
|
+
}
|
|
2303
|
+
const absorbedIds = /* @__PURE__ */ new Set();
|
|
2304
|
+
const logicalByRawId = /* @__PURE__ */ new Map();
|
|
2305
|
+
const stepIdToLogicalId = /* @__PURE__ */ new Map();
|
|
2306
|
+
const logical = [];
|
|
2307
|
+
const orderedRuns = [...byRun.keys()].sort((a, b) => a.localeCompare(b));
|
|
2308
|
+
for (const runId of orderedRuns) {
|
|
2309
|
+
const runEvents = byRun.get(runId) ?? [];
|
|
2310
|
+
const starts = [];
|
|
2311
|
+
const completes = [];
|
|
2312
|
+
const others = [];
|
|
2313
|
+
for (const event of runEvents) {
|
|
2314
|
+
const legacy = legacyEvent(event);
|
|
2315
|
+
if (legacy === "step_started" || legacy === "run_started" && event.status === "running") {
|
|
2316
|
+
starts.push(event);
|
|
2317
|
+
} else if (legacy === "step_completed" || legacy === "run_completed") {
|
|
2318
|
+
completes.push(event);
|
|
2319
|
+
} else {
|
|
2320
|
+
others.push(event);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
const usedCompletes = /* @__PURE__ */ new Set();
|
|
2324
|
+
for (const start of starts) {
|
|
2325
|
+
const stepId = stepIdOf(start);
|
|
2326
|
+
let match;
|
|
2327
|
+
if (legacyEvent(start) === "run_started") {
|
|
2328
|
+
const candidates = completes.filter(
|
|
2329
|
+
(c) => !usedCompletes.has(c.eventId) && legacyEvent(c) === "run_completed"
|
|
2330
|
+
);
|
|
2331
|
+
if (candidates.length > 1) {
|
|
2332
|
+
diagnostics.push({
|
|
2333
|
+
code: "AI_LOGICAL_PAIR_AMBIGUOUS",
|
|
2334
|
+
message: `Multiple run_completed rows for run ${runId}; using first by eventId.`,
|
|
2335
|
+
eventIds: candidates.map((c) => c.eventId)
|
|
2336
|
+
});
|
|
2337
|
+
candidates.sort((a, b) => a.eventId.localeCompare(b.eventId));
|
|
2338
|
+
}
|
|
2339
|
+
match = candidates[0];
|
|
2340
|
+
} else if (stepId) {
|
|
2341
|
+
const candidates = completes.filter(
|
|
2342
|
+
(c) => !usedCompletes.has(c.eventId) && legacyEvent(c) === "step_completed" && stepIdOf(c) === stepId
|
|
2343
|
+
);
|
|
2344
|
+
if (candidates.length > 1) {
|
|
2345
|
+
diagnostics.push({
|
|
2346
|
+
code: "AI_LOGICAL_PAIR_AMBIGUOUS",
|
|
2347
|
+
message: `Multiple step_completed rows for stepId ${stepId}; using first by eventId.`,
|
|
2348
|
+
eventIds: candidates.map((c) => c.eventId)
|
|
2349
|
+
});
|
|
2350
|
+
candidates.sort((a, b) => a.eventId.localeCompare(b.eventId));
|
|
2351
|
+
}
|
|
2352
|
+
match = candidates[0];
|
|
2353
|
+
}
|
|
2354
|
+
if (match) {
|
|
2355
|
+
usedCompletes.add(match.eventId);
|
|
2356
|
+
absorbedIds.add(match.eventId);
|
|
2357
|
+
const paired = pairStartComplete(start, match);
|
|
2358
|
+
logical.push(paired);
|
|
2359
|
+
logicalByRawId.set(start.eventId, paired);
|
|
2360
|
+
logicalByRawId.set(match.eventId, paired);
|
|
2361
|
+
if (stepId) stepIdToLogicalId.set(`${runId}:${stepId}`, paired.eventId);
|
|
2362
|
+
} else {
|
|
2363
|
+
diagnostics.push({
|
|
2364
|
+
code: "AI_LOGICAL_PAIR_UNMATCHED_START",
|
|
2365
|
+
message: `No matching complete for start ${start.eventId}.`,
|
|
2366
|
+
eventIds: [start.eventId]
|
|
2367
|
+
});
|
|
2368
|
+
const alone = asLogical(start);
|
|
2369
|
+
logical.push(alone);
|
|
2370
|
+
logicalByRawId.set(start.eventId, alone);
|
|
2371
|
+
if (stepId) stepIdToLogicalId.set(`${runId}:${stepId}`, alone.eventId);
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
for (const complete of completes) {
|
|
2375
|
+
if (usedCompletes.has(complete.eventId)) continue;
|
|
2376
|
+
diagnostics.push({
|
|
2377
|
+
code: "AI_LOGICAL_PAIR_UNMATCHED_COMPLETE",
|
|
2378
|
+
message: `No matching start for complete ${complete.eventId}.`,
|
|
2379
|
+
eventIds: [complete.eventId]
|
|
2380
|
+
});
|
|
2381
|
+
const alone = asLogical(complete);
|
|
2382
|
+
logical.push(alone);
|
|
2383
|
+
logicalByRawId.set(complete.eventId, alone);
|
|
2384
|
+
const stepId = stepIdOf(complete);
|
|
2385
|
+
if (stepId && !stepIdToLogicalId.has(`${runId}:${stepId}`)) {
|
|
2386
|
+
stepIdToLogicalId.set(`${runId}:${stepId}`, alone.eventId);
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
for (const event of others) {
|
|
2390
|
+
const alone = asLogical(event);
|
|
2391
|
+
logical.push(alone);
|
|
2392
|
+
logicalByRawId.set(event.eventId, alone);
|
|
2393
|
+
const stepId = stepIdOf(event);
|
|
2394
|
+
if (stepId && !stepIdToLogicalId.has(`${runId}:${stepId}`)) {
|
|
2395
|
+
stepIdToLogicalId.set(`${runId}:${stepId}`, alone.eventId);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
const logicalById = new Map(logical.map((e) => [e.eventId, e]));
|
|
2400
|
+
const normalized = [];
|
|
2401
|
+
for (const event of logical) {
|
|
2402
|
+
const originalParentId = event.parentId;
|
|
2403
|
+
if (!originalParentId) {
|
|
2404
|
+
normalized.push(event);
|
|
2405
|
+
continue;
|
|
2406
|
+
}
|
|
2407
|
+
let nextParent = originalParentId;
|
|
2408
|
+
let remapped = false;
|
|
2409
|
+
const viaAbsorbed = logicalByRawId.get(originalParentId);
|
|
2410
|
+
if (viaAbsorbed && viaAbsorbed.eventId !== originalParentId) {
|
|
2411
|
+
nextParent = viaAbsorbed.eventId;
|
|
2412
|
+
remapped = true;
|
|
2413
|
+
} else if (!logicalById.has(originalParentId)) {
|
|
2414
|
+
const viaStep = stepIdToLogicalId.get(`${event.runId}:${originalParentId}`);
|
|
2415
|
+
if (viaStep) {
|
|
2416
|
+
nextParent = viaStep;
|
|
2417
|
+
remapped = true;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
if (!remapped) {
|
|
2421
|
+
if (!logicalById.has(originalParentId) && !logicalByRawId.has(originalParentId)) {
|
|
2422
|
+
const mapping = event.attributes?.parentMapping;
|
|
2423
|
+
const unresolved = mapping === "unresolved" || event.attributes?.parentUnresolved === true || event.attributes?.unresolvedParent === true || // LangGraph/framework scaffolding sentinel labels are not event ids.
|
|
2424
|
+
/^LangGraph$/i.test(originalParentId) || originalParentId.startsWith("unresolved:");
|
|
2425
|
+
if (!unresolved) {
|
|
2426
|
+
diagnostics.push({
|
|
2427
|
+
code: "AI_LOGICAL_PARENT_UNRESOLVED",
|
|
2428
|
+
message: `Parent ${originalParentId} unresolved for ${event.eventId}.`,
|
|
2429
|
+
eventIds: [event.eventId]
|
|
2430
|
+
});
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
normalized.push(event);
|
|
2434
|
+
continue;
|
|
2435
|
+
}
|
|
2436
|
+
diagnostics.push({
|
|
2437
|
+
code: "AI_LOGICAL_PARENT_REMAPPED",
|
|
2438
|
+
message: `Remapped parent ${originalParentId} \u2192 ${nextParent} for ${event.eventId}.`,
|
|
2439
|
+
eventIds: [event.eventId]
|
|
2440
|
+
});
|
|
2441
|
+
normalized.push({
|
|
2442
|
+
...event,
|
|
2443
|
+
parentId: nextParent,
|
|
2444
|
+
projection: {
|
|
2445
|
+
...event.projection,
|
|
2446
|
+
parentNormalized: true,
|
|
2447
|
+
originalParentId
|
|
2448
|
+
}
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
const rawIndex = new Map(events.map((e, i) => [e.eventId, i]));
|
|
2452
|
+
normalized.sort((a, b) => {
|
|
2453
|
+
const ai = rawIndex.get(a.sourceEventIds[0]) ?? 0;
|
|
2454
|
+
const bi = rawIndex.get(b.sourceEventIds[0]) ?? 0;
|
|
2455
|
+
return ai - bi || a.eventId.localeCompare(b.eventId);
|
|
2456
|
+
});
|
|
2457
|
+
return {
|
|
2458
|
+
logicalEvents: Object.freeze(normalized),
|
|
2459
|
+
diagnostics: Object.freeze(diagnostics)
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
function resolveCanonicalToolName(event) {
|
|
2463
|
+
const attrs = event.attributes;
|
|
2464
|
+
const direct = pickString(attrs, ["toolName", "tool"]);
|
|
2465
|
+
if (direct) return direct;
|
|
2466
|
+
const metadata = attrs?.metadata;
|
|
2467
|
+
if (isRecord5(metadata)) {
|
|
2468
|
+
const nested = pickString(metadata, ["toolName", "tool"]);
|
|
2469
|
+
if (nested) return nested;
|
|
2470
|
+
}
|
|
2471
|
+
for (const prefix of ["tool:", "function:", "mcp-tools:"]) {
|
|
2472
|
+
if (event.name.startsWith(prefix)) return event.name.slice(prefix.length);
|
|
2473
|
+
}
|
|
2474
|
+
return event.name;
|
|
2475
|
+
}
|
|
2476
|
+
function pickString(record, keys) {
|
|
2477
|
+
if (!record) return void 0;
|
|
2478
|
+
for (const key of keys) {
|
|
2479
|
+
const value = record[key];
|
|
2480
|
+
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
2481
|
+
}
|
|
2482
|
+
return void 0;
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2226
2485
|
// packages/core/src/checks/index.ts
|
|
2227
2486
|
var SEVERITY_RANK = {
|
|
2228
2487
|
error: 0,
|
|
@@ -2286,10 +2545,13 @@ function buildFacts(input, selectedRun) {
|
|
|
2286
2545
|
childrenByParentId.set(parentId, children);
|
|
2287
2546
|
}
|
|
2288
2547
|
}
|
|
2548
|
+
const projection = projectLogicalEvents(scopedEvents);
|
|
2289
2549
|
return {
|
|
2290
2550
|
format: input.read.format,
|
|
2291
2551
|
runs: Object.freeze([...input.read.runs]),
|
|
2292
2552
|
events: Object.freeze([...scopedEvents]),
|
|
2553
|
+
logicalEvents: projection.logicalEvents,
|
|
2554
|
+
logicalProjectionDiagnostics: projection.diagnostics,
|
|
2293
2555
|
readerWarnings: Object.freeze([...input.read.warnings]),
|
|
2294
2556
|
unsupportedFields: Object.freeze([...input.read.unsupportedFields]),
|
|
2295
2557
|
sourceFiles: Object.freeze([...input.read.sourceFiles]),
|
|
@@ -2468,7 +2730,10 @@ function failFinding(ruleId, message, evidence, expected, actual, meta) {
|
|
|
2468
2730
|
};
|
|
2469
2731
|
}
|
|
2470
2732
|
function toolName(event) {
|
|
2471
|
-
return
|
|
2733
|
+
return resolveCanonicalToolName(event);
|
|
2734
|
+
}
|
|
2735
|
+
function semanticEvents(context) {
|
|
2736
|
+
return context.logicalEvents ?? context.events;
|
|
2472
2737
|
}
|
|
2473
2738
|
function llmModel(event) {
|
|
2474
2739
|
return stringAttr(event, ["model", "modelId", "responseModelId", "modelName", "model_name"]) ?? stripPrefix(event.name, ["llm:", "generation:", "transcription:", "speech:"]);
|
|
@@ -2480,7 +2745,7 @@ function llmFinishReason(event) {
|
|
|
2480
2745
|
return stringAttr(event, ["finishReason", "rawFinishReason", "finish_reason"]);
|
|
2481
2746
|
}
|
|
2482
2747
|
function finishedEvents(context, kind) {
|
|
2483
|
-
return context.
|
|
2748
|
+
return semanticEvents(context).filter(
|
|
2484
2749
|
(event) => (kind === void 0 || event.kind === kind) && event.status !== "running"
|
|
2485
2750
|
);
|
|
2486
2751
|
}
|
|
@@ -2506,7 +2771,7 @@ function createRunStatusRule(options = {}) {
|
|
|
2506
2771
|
);
|
|
2507
2772
|
}
|
|
2508
2773
|
if (!allowIncomplete) {
|
|
2509
|
-
const running = context.
|
|
2774
|
+
const running = semanticEvents(context).filter((event) => event.status === "running");
|
|
2510
2775
|
if (running.length > 0) {
|
|
2511
2776
|
findings.push(
|
|
2512
2777
|
failFinding(
|
|
@@ -2743,14 +3008,14 @@ function runTraceChecks(input, options = {}) {
|
|
|
2743
3008
|
}
|
|
2744
3009
|
|
|
2745
3010
|
// packages/core/src/persisted/token-usage.ts
|
|
2746
|
-
function
|
|
3011
|
+
function isRecord6(value) {
|
|
2747
3012
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2748
3013
|
}
|
|
2749
3014
|
function nonNegativeFinite(value) {
|
|
2750
3015
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
2751
3016
|
}
|
|
2752
3017
|
function normalizeTokenUsage(value) {
|
|
2753
|
-
if (!
|
|
3018
|
+
if (!isRecord6(value)) return void 0;
|
|
2754
3019
|
const input = nonNegativeFinite(value.input);
|
|
2755
3020
|
const output = nonNegativeFinite(value.output);
|
|
2756
3021
|
const suppliedTotal = nonNegativeFinite(value.total);
|
|
@@ -3519,7 +3784,7 @@ function persistedEventsForParsedTrace(parsed) {
|
|
|
3519
3784
|
sourceName: "agent-inspect-jsonl-reader"
|
|
3520
3785
|
});
|
|
3521
3786
|
}
|
|
3522
|
-
function
|
|
3787
|
+
function isRecord7(value) {
|
|
3523
3788
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3524
3789
|
}
|
|
3525
3790
|
function isNonEmptyString4(value) {
|
|
@@ -3534,13 +3799,13 @@ function readStringField(record, keys) {
|
|
|
3534
3799
|
}
|
|
3535
3800
|
function readRecordField(record, key) {
|
|
3536
3801
|
const value = record[key];
|
|
3537
|
-
return
|
|
3802
|
+
return isRecord7(value) ? value : void 0;
|
|
3538
3803
|
}
|
|
3539
3804
|
function parseJsonDocument(content) {
|
|
3540
3805
|
return JSON.parse(content);
|
|
3541
3806
|
}
|
|
3542
3807
|
function looksLikeOpenInferenceSpan(value) {
|
|
3543
|
-
if (!
|
|
3808
|
+
if (!isRecord7(value)) return false;
|
|
3544
3809
|
const attributes = readRecordField(value, "attributes");
|
|
3545
3810
|
return readStringField(value, ["trace_id", "traceId"]) !== void 0 && readStringField(value, ["span_id", "spanId"]) !== void 0 && (readStringField(value, ["name"]) !== void 0 || attributes?.["openinference.span.kind"] !== void 0);
|
|
3546
3811
|
}
|
|
@@ -3565,7 +3830,7 @@ function extractOpenInferenceDocument(root) {
|
|
|
3565
3830
|
unsupportedFields
|
|
3566
3831
|
};
|
|
3567
3832
|
}
|
|
3568
|
-
if (!
|
|
3833
|
+
if (!isRecord7(root)) return void 0;
|
|
3569
3834
|
const rootFormat = root.format;
|
|
3570
3835
|
const rootCompatibility = root.compatibility;
|
|
3571
3836
|
const version = typeof root.version === "string" && root.version.trim() !== "" ? root.version : void 0;
|
|
@@ -3705,7 +3970,7 @@ function summarizeAttributeValue(value) {
|
|
|
3705
3970
|
if (Array.isArray(value)) {
|
|
3706
3971
|
return { type: "array", length: value.length };
|
|
3707
3972
|
}
|
|
3708
|
-
if (
|
|
3973
|
+
if (isRecord7(value)) {
|
|
3709
3974
|
return { type: "object", keyCount: Object.keys(value).length };
|
|
3710
3975
|
}
|
|
3711
3976
|
if (value === null) {
|
|
@@ -3792,7 +4057,7 @@ function mapOpenInferenceKind(span, attributes, pathPrefix) {
|
|
|
3792
4057
|
}
|
|
3793
4058
|
}
|
|
3794
4059
|
function mapOpenInferenceStatus(status) {
|
|
3795
|
-
if (!
|
|
4060
|
+
if (!isRecord7(status)) return void 0;
|
|
3796
4061
|
const rawCode = status.code;
|
|
3797
4062
|
if (typeof rawCode !== "string") return void 0;
|
|
3798
4063
|
switch (rawCode.toUpperCase()) {
|
|
@@ -3892,7 +4157,7 @@ function mapOpenInferenceSpan(span, index, version) {
|
|
|
3892
4157
|
warnings.push(...kindWarnings);
|
|
3893
4158
|
const status = mapOpenInferenceStatus(span.status);
|
|
3894
4159
|
const tokenUsage = readOpenInferenceTokenUsage(rawAttributes);
|
|
3895
|
-
const errorMessage =
|
|
4160
|
+
const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
|
|
3896
4161
|
const event = {
|
|
3897
4162
|
schemaVersion: "0.2",
|
|
3898
4163
|
eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : spanId,
|
|
@@ -4038,7 +4303,7 @@ var openInferenceJsonReader = {
|
|
|
4038
4303
|
}
|
|
4039
4304
|
};
|
|
4040
4305
|
function parseOtlpAnyValue(value, field, warnings, unsupportedFields) {
|
|
4041
|
-
if (!
|
|
4306
|
+
if (!isRecord7(value)) {
|
|
4042
4307
|
unsupportedFields.push(field);
|
|
4043
4308
|
warnings.push({
|
|
4044
4309
|
code: "otlp_attribute_value_invalid",
|
|
@@ -4060,15 +4325,15 @@ function parseOtlpAnyValue(value, field, warnings, unsupportedFields) {
|
|
|
4060
4325
|
if (typeof value.doubleValue === "number" && Number.isFinite(value.doubleValue)) {
|
|
4061
4326
|
return value.doubleValue;
|
|
4062
4327
|
}
|
|
4063
|
-
if (
|
|
4328
|
+
if (isRecord7(value.arrayValue) && Array.isArray(value.arrayValue.values)) {
|
|
4064
4329
|
return value.arrayValue.values.map(
|
|
4065
4330
|
(item, index) => parseOtlpAnyValue(item, `${field}.arrayValue.values[${index}]`, warnings, unsupportedFields)
|
|
4066
4331
|
);
|
|
4067
4332
|
}
|
|
4068
|
-
if (
|
|
4333
|
+
if (isRecord7(value.kvlistValue) && Array.isArray(value.kvlistValue.values)) {
|
|
4069
4334
|
const out = {};
|
|
4070
4335
|
for (const [index, item] of value.kvlistValue.values.entries()) {
|
|
4071
|
-
if (!
|
|
4336
|
+
if (!isRecord7(item) || typeof item.key !== "string") {
|
|
4072
4337
|
unsupportedFields.push(`${field}.kvlistValue.values[${index}]`);
|
|
4073
4338
|
continue;
|
|
4074
4339
|
}
|
|
@@ -4119,7 +4384,7 @@ function parseOtlpAttributes(value, pathPrefix) {
|
|
|
4119
4384
|
}
|
|
4120
4385
|
for (const [index, item] of value.entries()) {
|
|
4121
4386
|
const field = `${pathPrefix}[${index}]`;
|
|
4122
|
-
if (!
|
|
4387
|
+
if (!isRecord7(item) || typeof item.key !== "string") {
|
|
4123
4388
|
unsupportedFields.push(field);
|
|
4124
4389
|
warnings.push({
|
|
4125
4390
|
code: "otlp_attribute_invalid",
|
|
@@ -4142,16 +4407,16 @@ function parseOtlpAttributes(value, pathPrefix) {
|
|
|
4142
4407
|
return { attributes, warnings, unsupportedFields };
|
|
4143
4408
|
}
|
|
4144
4409
|
function looksLikeOtlpSpan(value) {
|
|
4145
|
-
return
|
|
4410
|
+
return isRecord7(value) && readStringField(value, ["traceId"]) !== void 0 && readStringField(value, ["spanId"]) !== void 0 && readStringField(value, ["name"]) !== void 0;
|
|
4146
4411
|
}
|
|
4147
4412
|
function extractOtlpDocument(root) {
|
|
4148
|
-
if (!
|
|
4413
|
+
if (!isRecord7(root) || !Array.isArray(root.resourceSpans)) return void 0;
|
|
4149
4414
|
const spans = [];
|
|
4150
4415
|
const warnings = [];
|
|
4151
4416
|
const unsupportedFields = [];
|
|
4152
4417
|
for (const [resourceIndex, resourceSpan] of root.resourceSpans.entries()) {
|
|
4153
4418
|
const resourcePath = `resourceSpans[${resourceIndex}]`;
|
|
4154
|
-
if (!
|
|
4419
|
+
if (!isRecord7(resourceSpan)) {
|
|
4155
4420
|
unsupportedFields.push(resourcePath);
|
|
4156
4421
|
continue;
|
|
4157
4422
|
}
|
|
@@ -4174,7 +4439,7 @@ function extractOtlpDocument(root) {
|
|
|
4174
4439
|
}
|
|
4175
4440
|
for (const [scopeIndex, scopeSpan] of resourceSpan.scopeSpans.entries()) {
|
|
4176
4441
|
const scopePath = `${resourcePath}.scopeSpans[${scopeIndex}]`;
|
|
4177
|
-
if (!
|
|
4442
|
+
if (!isRecord7(scopeSpan)) {
|
|
4178
4443
|
unsupportedFields.push(scopePath);
|
|
4179
4444
|
continue;
|
|
4180
4445
|
}
|
|
@@ -4241,7 +4506,7 @@ function extractOtlpDocument(root) {
|
|
|
4241
4506
|
};
|
|
4242
4507
|
}
|
|
4243
4508
|
function mapOtlpStatus(status) {
|
|
4244
|
-
if (!
|
|
4509
|
+
if (!isRecord7(status)) return void 0;
|
|
4245
4510
|
const rawCode = status.code;
|
|
4246
4511
|
if (typeof rawCode !== "string") return void 0;
|
|
4247
4512
|
switch (rawCode.toUpperCase()) {
|
|
@@ -4341,7 +4606,7 @@ function mapOtlpEvents(value, pathPrefix) {
|
|
|
4341
4606
|
const events = [];
|
|
4342
4607
|
for (const [index, event] of value.entries()) {
|
|
4343
4608
|
const eventPath = `${pathPrefix}[${index}]`;
|
|
4344
|
-
if (!
|
|
4609
|
+
if (!isRecord7(event)) {
|
|
4345
4610
|
unsupportedFields.push(eventPath);
|
|
4346
4611
|
continue;
|
|
4347
4612
|
}
|
|
@@ -4479,7 +4744,7 @@ function mapOtlpSpan(context) {
|
|
|
4479
4744
|
warnings.push(...kindWarnings);
|
|
4480
4745
|
const status = mapOtlpStatus(span.status);
|
|
4481
4746
|
const tokenUsage = readOtlpTokenUsage(parsedSpanAttributes.attributes);
|
|
4482
|
-
const errorMessage =
|
|
4747
|
+
const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
|
|
4483
4748
|
const event = {
|
|
4484
4749
|
schemaVersion: "0.2",
|
|
4485
4750
|
eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : spanId,
|