@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.mjs
CHANGED
|
@@ -493,12 +493,12 @@ function persistedInspectEventToTraceEvents(event) {
|
|
|
493
493
|
if (!isPersistedInspectEvent(event)) {
|
|
494
494
|
throw new Error("Invalid PersistedInspectEvent: failed isPersistedInspectEvent");
|
|
495
495
|
}
|
|
496
|
-
const
|
|
497
|
-
if (
|
|
498
|
-
if (
|
|
499
|
-
if (
|
|
500
|
-
if (
|
|
501
|
-
if (
|
|
496
|
+
const legacyEvent2 = event.attributes?.legacyEvent;
|
|
497
|
+
if (legacyEvent2 === "run_started") return [fromLegacyRunStarted(event)];
|
|
498
|
+
if (legacyEvent2 === "run_completed") return [fromLegacyRunCompleted(event)];
|
|
499
|
+
if (legacyEvent2 === "step_started") return [fromLegacyStepStarted(event)];
|
|
500
|
+
if (legacyEvent2 === "step_completed") return [fromLegacyStepCompleted(event)];
|
|
501
|
+
if (legacyEvent2 === "outcome_observed") return [fromLegacyOutcomeObserved(event)];
|
|
502
502
|
if (event.kind === "RUN") {
|
|
503
503
|
return fromNativeRun(event);
|
|
504
504
|
}
|
|
@@ -2216,6 +2216,265 @@ async function resolveSuiteCaseTrace(suiteCase, options) {
|
|
|
2216
2216
|
};
|
|
2217
2217
|
}
|
|
2218
2218
|
|
|
2219
|
+
// packages/core/src/checks/logical-events.ts
|
|
2220
|
+
function isRecord5(value) {
|
|
2221
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2222
|
+
}
|
|
2223
|
+
function legacyEvent(event) {
|
|
2224
|
+
const value = event.attributes?.legacyEvent;
|
|
2225
|
+
return typeof value === "string" ? value : void 0;
|
|
2226
|
+
}
|
|
2227
|
+
function stepIdOf(event) {
|
|
2228
|
+
const value = event.attributes?.stepId;
|
|
2229
|
+
if (typeof value === "string" && value.trim() !== "") return value;
|
|
2230
|
+
return void 0;
|
|
2231
|
+
}
|
|
2232
|
+
function cloneEvent(event) {
|
|
2233
|
+
return {
|
|
2234
|
+
...event,
|
|
2235
|
+
...event.attributes !== void 0 ? { attributes: { ...event.attributes } } : {},
|
|
2236
|
+
...event.error !== void 0 ? { error: { ...event.error } } : {},
|
|
2237
|
+
...event.tokenUsage !== void 0 ? { tokenUsage: { ...event.tokenUsage } } : {},
|
|
2238
|
+
...event.source !== void 0 ? { source: { ...event.source } } : {}
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
function mergeAttributes(start, complete) {
|
|
2242
|
+
const merged = {
|
|
2243
|
+
...isRecord5(complete.attributes) ? complete.attributes : {},
|
|
2244
|
+
...isRecord5(start.attributes) ? start.attributes : {}
|
|
2245
|
+
};
|
|
2246
|
+
merged.legacyEvent = start.attributes?.legacyEvent ?? complete.attributes?.legacyEvent;
|
|
2247
|
+
merged.legacyCompleteEvent = complete.attributes?.legacyEvent;
|
|
2248
|
+
if (complete.attributes?.errorStack !== void 0) {
|
|
2249
|
+
merged.errorStack = complete.attributes.errorStack;
|
|
2250
|
+
}
|
|
2251
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
2252
|
+
}
|
|
2253
|
+
function pairStartComplete(start, complete) {
|
|
2254
|
+
const attributes = mergeAttributes(start, complete);
|
|
2255
|
+
const paired = {
|
|
2256
|
+
...cloneEvent(start),
|
|
2257
|
+
status: complete.status,
|
|
2258
|
+
timestamp: complete.timestamp ?? start.timestamp,
|
|
2259
|
+
...complete.endedAt !== void 0 ? { endedAt: complete.endedAt } : {},
|
|
2260
|
+
...complete.durationMs !== void 0 ? { durationMs: complete.durationMs } : {},
|
|
2261
|
+
...complete.error !== void 0 ? { error: { ...complete.error } } : {},
|
|
2262
|
+
...complete.tokenUsage !== void 0 && start.tokenUsage === void 0 ? { tokenUsage: { ...complete.tokenUsage } } : {},
|
|
2263
|
+
...attributes !== void 0 ? { attributes } : {}
|
|
2264
|
+
};
|
|
2265
|
+
return {
|
|
2266
|
+
...paired,
|
|
2267
|
+
sourceEventIds: Object.freeze([start.eventId, complete.eventId]),
|
|
2268
|
+
projection: {
|
|
2269
|
+
paired: true,
|
|
2270
|
+
absorbedEventIds: Object.freeze([complete.eventId]),
|
|
2271
|
+
parentNormalized: false,
|
|
2272
|
+
...start.parentId !== void 0 ? { originalParentId: start.parentId } : {}
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2276
|
+
function asLogical(event, extras) {
|
|
2277
|
+
return {
|
|
2278
|
+
...cloneEvent(event),
|
|
2279
|
+
sourceEventIds: Object.freeze([event.eventId]),
|
|
2280
|
+
projection: {
|
|
2281
|
+
paired: false,
|
|
2282
|
+
absorbedEventIds: Object.freeze([]),
|
|
2283
|
+
parentNormalized: extras?.parentNormalized === true,
|
|
2284
|
+
...{}
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
function projectLogicalEvents(events) {
|
|
2289
|
+
const diagnostics = [];
|
|
2290
|
+
const byRun = /* @__PURE__ */ new Map();
|
|
2291
|
+
for (const event of events) {
|
|
2292
|
+
const list = byRun.get(event.runId) ?? [];
|
|
2293
|
+
list.push(event);
|
|
2294
|
+
byRun.set(event.runId, list);
|
|
2295
|
+
}
|
|
2296
|
+
const absorbedIds = /* @__PURE__ */ new Set();
|
|
2297
|
+
const logicalByRawId = /* @__PURE__ */ new Map();
|
|
2298
|
+
const stepIdToLogicalId = /* @__PURE__ */ new Map();
|
|
2299
|
+
const logical = [];
|
|
2300
|
+
const orderedRuns = [...byRun.keys()].sort((a, b) => a.localeCompare(b));
|
|
2301
|
+
for (const runId of orderedRuns) {
|
|
2302
|
+
const runEvents = byRun.get(runId) ?? [];
|
|
2303
|
+
const starts = [];
|
|
2304
|
+
const completes = [];
|
|
2305
|
+
const others = [];
|
|
2306
|
+
for (const event of runEvents) {
|
|
2307
|
+
const legacy = legacyEvent(event);
|
|
2308
|
+
if (legacy === "step_started" || legacy === "run_started" && event.status === "running") {
|
|
2309
|
+
starts.push(event);
|
|
2310
|
+
} else if (legacy === "step_completed" || legacy === "run_completed") {
|
|
2311
|
+
completes.push(event);
|
|
2312
|
+
} else {
|
|
2313
|
+
others.push(event);
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
const usedCompletes = /* @__PURE__ */ new Set();
|
|
2317
|
+
for (const start of starts) {
|
|
2318
|
+
const stepId = stepIdOf(start);
|
|
2319
|
+
let match;
|
|
2320
|
+
if (legacyEvent(start) === "run_started") {
|
|
2321
|
+
const candidates = completes.filter(
|
|
2322
|
+
(c) => !usedCompletes.has(c.eventId) && legacyEvent(c) === "run_completed"
|
|
2323
|
+
);
|
|
2324
|
+
if (candidates.length > 1) {
|
|
2325
|
+
diagnostics.push({
|
|
2326
|
+
code: "AI_LOGICAL_PAIR_AMBIGUOUS",
|
|
2327
|
+
message: `Multiple run_completed rows for run ${runId}; using first by eventId.`,
|
|
2328
|
+
eventIds: candidates.map((c) => c.eventId)
|
|
2329
|
+
});
|
|
2330
|
+
candidates.sort((a, b) => a.eventId.localeCompare(b.eventId));
|
|
2331
|
+
}
|
|
2332
|
+
match = candidates[0];
|
|
2333
|
+
} else if (stepId) {
|
|
2334
|
+
const candidates = completes.filter(
|
|
2335
|
+
(c) => !usedCompletes.has(c.eventId) && legacyEvent(c) === "step_completed" && stepIdOf(c) === stepId
|
|
2336
|
+
);
|
|
2337
|
+
if (candidates.length > 1) {
|
|
2338
|
+
diagnostics.push({
|
|
2339
|
+
code: "AI_LOGICAL_PAIR_AMBIGUOUS",
|
|
2340
|
+
message: `Multiple step_completed rows for stepId ${stepId}; using first by eventId.`,
|
|
2341
|
+
eventIds: candidates.map((c) => c.eventId)
|
|
2342
|
+
});
|
|
2343
|
+
candidates.sort((a, b) => a.eventId.localeCompare(b.eventId));
|
|
2344
|
+
}
|
|
2345
|
+
match = candidates[0];
|
|
2346
|
+
}
|
|
2347
|
+
if (match) {
|
|
2348
|
+
usedCompletes.add(match.eventId);
|
|
2349
|
+
absorbedIds.add(match.eventId);
|
|
2350
|
+
const paired = pairStartComplete(start, match);
|
|
2351
|
+
logical.push(paired);
|
|
2352
|
+
logicalByRawId.set(start.eventId, paired);
|
|
2353
|
+
logicalByRawId.set(match.eventId, paired);
|
|
2354
|
+
if (stepId) stepIdToLogicalId.set(`${runId}:${stepId}`, paired.eventId);
|
|
2355
|
+
} else {
|
|
2356
|
+
diagnostics.push({
|
|
2357
|
+
code: "AI_LOGICAL_PAIR_UNMATCHED_START",
|
|
2358
|
+
message: `No matching complete for start ${start.eventId}.`,
|
|
2359
|
+
eventIds: [start.eventId]
|
|
2360
|
+
});
|
|
2361
|
+
const alone = asLogical(start);
|
|
2362
|
+
logical.push(alone);
|
|
2363
|
+
logicalByRawId.set(start.eventId, alone);
|
|
2364
|
+
if (stepId) stepIdToLogicalId.set(`${runId}:${stepId}`, alone.eventId);
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
for (const complete of completes) {
|
|
2368
|
+
if (usedCompletes.has(complete.eventId)) continue;
|
|
2369
|
+
diagnostics.push({
|
|
2370
|
+
code: "AI_LOGICAL_PAIR_UNMATCHED_COMPLETE",
|
|
2371
|
+
message: `No matching start for complete ${complete.eventId}.`,
|
|
2372
|
+
eventIds: [complete.eventId]
|
|
2373
|
+
});
|
|
2374
|
+
const alone = asLogical(complete);
|
|
2375
|
+
logical.push(alone);
|
|
2376
|
+
logicalByRawId.set(complete.eventId, alone);
|
|
2377
|
+
const stepId = stepIdOf(complete);
|
|
2378
|
+
if (stepId && !stepIdToLogicalId.has(`${runId}:${stepId}`)) {
|
|
2379
|
+
stepIdToLogicalId.set(`${runId}:${stepId}`, alone.eventId);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
for (const event of others) {
|
|
2383
|
+
const alone = asLogical(event);
|
|
2384
|
+
logical.push(alone);
|
|
2385
|
+
logicalByRawId.set(event.eventId, alone);
|
|
2386
|
+
const stepId = stepIdOf(event);
|
|
2387
|
+
if (stepId && !stepIdToLogicalId.has(`${runId}:${stepId}`)) {
|
|
2388
|
+
stepIdToLogicalId.set(`${runId}:${stepId}`, alone.eventId);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
const logicalById = new Map(logical.map((e) => [e.eventId, e]));
|
|
2393
|
+
const normalized = [];
|
|
2394
|
+
for (const event of logical) {
|
|
2395
|
+
const originalParentId = event.parentId;
|
|
2396
|
+
if (!originalParentId) {
|
|
2397
|
+
normalized.push(event);
|
|
2398
|
+
continue;
|
|
2399
|
+
}
|
|
2400
|
+
let nextParent = originalParentId;
|
|
2401
|
+
let remapped = false;
|
|
2402
|
+
const viaAbsorbed = logicalByRawId.get(originalParentId);
|
|
2403
|
+
if (viaAbsorbed && viaAbsorbed.eventId !== originalParentId) {
|
|
2404
|
+
nextParent = viaAbsorbed.eventId;
|
|
2405
|
+
remapped = true;
|
|
2406
|
+
} else if (!logicalById.has(originalParentId)) {
|
|
2407
|
+
const viaStep = stepIdToLogicalId.get(`${event.runId}:${originalParentId}`);
|
|
2408
|
+
if (viaStep) {
|
|
2409
|
+
nextParent = viaStep;
|
|
2410
|
+
remapped = true;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
if (!remapped) {
|
|
2414
|
+
if (!logicalById.has(originalParentId) && !logicalByRawId.has(originalParentId)) {
|
|
2415
|
+
const mapping = event.attributes?.parentMapping;
|
|
2416
|
+
const unresolved = mapping === "unresolved" || event.attributes?.parentUnresolved === true || event.attributes?.unresolvedParent === true || // LangGraph/framework scaffolding sentinel labels are not event ids.
|
|
2417
|
+
/^LangGraph$/i.test(originalParentId) || originalParentId.startsWith("unresolved:");
|
|
2418
|
+
if (!unresolved) {
|
|
2419
|
+
diagnostics.push({
|
|
2420
|
+
code: "AI_LOGICAL_PARENT_UNRESOLVED",
|
|
2421
|
+
message: `Parent ${originalParentId} unresolved for ${event.eventId}.`,
|
|
2422
|
+
eventIds: [event.eventId]
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
normalized.push(event);
|
|
2427
|
+
continue;
|
|
2428
|
+
}
|
|
2429
|
+
diagnostics.push({
|
|
2430
|
+
code: "AI_LOGICAL_PARENT_REMAPPED",
|
|
2431
|
+
message: `Remapped parent ${originalParentId} \u2192 ${nextParent} for ${event.eventId}.`,
|
|
2432
|
+
eventIds: [event.eventId]
|
|
2433
|
+
});
|
|
2434
|
+
normalized.push({
|
|
2435
|
+
...event,
|
|
2436
|
+
parentId: nextParent,
|
|
2437
|
+
projection: {
|
|
2438
|
+
...event.projection,
|
|
2439
|
+
parentNormalized: true,
|
|
2440
|
+
originalParentId
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
const rawIndex = new Map(events.map((e, i) => [e.eventId, i]));
|
|
2445
|
+
normalized.sort((a, b) => {
|
|
2446
|
+
const ai = rawIndex.get(a.sourceEventIds[0]) ?? 0;
|
|
2447
|
+
const bi = rawIndex.get(b.sourceEventIds[0]) ?? 0;
|
|
2448
|
+
return ai - bi || a.eventId.localeCompare(b.eventId);
|
|
2449
|
+
});
|
|
2450
|
+
return {
|
|
2451
|
+
logicalEvents: Object.freeze(normalized),
|
|
2452
|
+
diagnostics: Object.freeze(diagnostics)
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
function resolveCanonicalToolName(event) {
|
|
2456
|
+
const attrs = event.attributes;
|
|
2457
|
+
const direct = pickString(attrs, ["toolName", "tool"]);
|
|
2458
|
+
if (direct) return direct;
|
|
2459
|
+
const metadata = attrs?.metadata;
|
|
2460
|
+
if (isRecord5(metadata)) {
|
|
2461
|
+
const nested = pickString(metadata, ["toolName", "tool"]);
|
|
2462
|
+
if (nested) return nested;
|
|
2463
|
+
}
|
|
2464
|
+
for (const prefix of ["tool:", "function:", "mcp-tools:"]) {
|
|
2465
|
+
if (event.name.startsWith(prefix)) return event.name.slice(prefix.length);
|
|
2466
|
+
}
|
|
2467
|
+
return event.name;
|
|
2468
|
+
}
|
|
2469
|
+
function pickString(record, keys) {
|
|
2470
|
+
if (!record) return void 0;
|
|
2471
|
+
for (const key of keys) {
|
|
2472
|
+
const value = record[key];
|
|
2473
|
+
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
2474
|
+
}
|
|
2475
|
+
return void 0;
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2219
2478
|
// packages/core/src/checks/index.ts
|
|
2220
2479
|
var SEVERITY_RANK = {
|
|
2221
2480
|
error: 0,
|
|
@@ -2279,10 +2538,13 @@ function buildFacts(input, selectedRun) {
|
|
|
2279
2538
|
childrenByParentId.set(parentId, children);
|
|
2280
2539
|
}
|
|
2281
2540
|
}
|
|
2541
|
+
const projection = projectLogicalEvents(scopedEvents);
|
|
2282
2542
|
return {
|
|
2283
2543
|
format: input.read.format,
|
|
2284
2544
|
runs: Object.freeze([...input.read.runs]),
|
|
2285
2545
|
events: Object.freeze([...scopedEvents]),
|
|
2546
|
+
logicalEvents: projection.logicalEvents,
|
|
2547
|
+
logicalProjectionDiagnostics: projection.diagnostics,
|
|
2286
2548
|
readerWarnings: Object.freeze([...input.read.warnings]),
|
|
2287
2549
|
unsupportedFields: Object.freeze([...input.read.unsupportedFields]),
|
|
2288
2550
|
sourceFiles: Object.freeze([...input.read.sourceFiles]),
|
|
@@ -2461,7 +2723,10 @@ function failFinding(ruleId, message, evidence, expected, actual, meta) {
|
|
|
2461
2723
|
};
|
|
2462
2724
|
}
|
|
2463
2725
|
function toolName(event) {
|
|
2464
|
-
return
|
|
2726
|
+
return resolveCanonicalToolName(event);
|
|
2727
|
+
}
|
|
2728
|
+
function semanticEvents(context) {
|
|
2729
|
+
return context.logicalEvents ?? context.events;
|
|
2465
2730
|
}
|
|
2466
2731
|
function llmModel(event) {
|
|
2467
2732
|
return stringAttr(event, ["model", "modelId", "responseModelId", "modelName", "model_name"]) ?? stripPrefix(event.name, ["llm:", "generation:", "transcription:", "speech:"]);
|
|
@@ -2473,7 +2738,7 @@ function llmFinishReason(event) {
|
|
|
2473
2738
|
return stringAttr(event, ["finishReason", "rawFinishReason", "finish_reason"]);
|
|
2474
2739
|
}
|
|
2475
2740
|
function finishedEvents(context, kind) {
|
|
2476
|
-
return context.
|
|
2741
|
+
return semanticEvents(context).filter(
|
|
2477
2742
|
(event) => (kind === void 0 || event.kind === kind) && event.status !== "running"
|
|
2478
2743
|
);
|
|
2479
2744
|
}
|
|
@@ -2499,7 +2764,7 @@ function createRunStatusRule(options = {}) {
|
|
|
2499
2764
|
);
|
|
2500
2765
|
}
|
|
2501
2766
|
if (!allowIncomplete) {
|
|
2502
|
-
const running = context.
|
|
2767
|
+
const running = semanticEvents(context).filter((event) => event.status === "running");
|
|
2503
2768
|
if (running.length > 0) {
|
|
2504
2769
|
findings.push(
|
|
2505
2770
|
failFinding(
|
|
@@ -2736,14 +3001,14 @@ function runTraceChecks(input, options = {}) {
|
|
|
2736
3001
|
}
|
|
2737
3002
|
|
|
2738
3003
|
// packages/core/src/persisted/token-usage.ts
|
|
2739
|
-
function
|
|
3004
|
+
function isRecord6(value) {
|
|
2740
3005
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2741
3006
|
}
|
|
2742
3007
|
function nonNegativeFinite(value) {
|
|
2743
3008
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
2744
3009
|
}
|
|
2745
3010
|
function normalizeTokenUsage(value) {
|
|
2746
|
-
if (!
|
|
3011
|
+
if (!isRecord6(value)) return void 0;
|
|
2747
3012
|
const input = nonNegativeFinite(value.input);
|
|
2748
3013
|
const output = nonNegativeFinite(value.output);
|
|
2749
3014
|
const suppliedTotal = nonNegativeFinite(value.total);
|
|
@@ -3512,7 +3777,7 @@ function persistedEventsForParsedTrace(parsed) {
|
|
|
3512
3777
|
sourceName: "agent-inspect-jsonl-reader"
|
|
3513
3778
|
});
|
|
3514
3779
|
}
|
|
3515
|
-
function
|
|
3780
|
+
function isRecord7(value) {
|
|
3516
3781
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3517
3782
|
}
|
|
3518
3783
|
function isNonEmptyString4(value) {
|
|
@@ -3527,13 +3792,13 @@ function readStringField(record, keys) {
|
|
|
3527
3792
|
}
|
|
3528
3793
|
function readRecordField(record, key) {
|
|
3529
3794
|
const value = record[key];
|
|
3530
|
-
return
|
|
3795
|
+
return isRecord7(value) ? value : void 0;
|
|
3531
3796
|
}
|
|
3532
3797
|
function parseJsonDocument(content) {
|
|
3533
3798
|
return JSON.parse(content);
|
|
3534
3799
|
}
|
|
3535
3800
|
function looksLikeOpenInferenceSpan(value) {
|
|
3536
|
-
if (!
|
|
3801
|
+
if (!isRecord7(value)) return false;
|
|
3537
3802
|
const attributes = readRecordField(value, "attributes");
|
|
3538
3803
|
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);
|
|
3539
3804
|
}
|
|
@@ -3558,7 +3823,7 @@ function extractOpenInferenceDocument(root) {
|
|
|
3558
3823
|
unsupportedFields
|
|
3559
3824
|
};
|
|
3560
3825
|
}
|
|
3561
|
-
if (!
|
|
3826
|
+
if (!isRecord7(root)) return void 0;
|
|
3562
3827
|
const rootFormat = root.format;
|
|
3563
3828
|
const rootCompatibility = root.compatibility;
|
|
3564
3829
|
const version = typeof root.version === "string" && root.version.trim() !== "" ? root.version : void 0;
|
|
@@ -3698,7 +3963,7 @@ function summarizeAttributeValue(value) {
|
|
|
3698
3963
|
if (Array.isArray(value)) {
|
|
3699
3964
|
return { type: "array", length: value.length };
|
|
3700
3965
|
}
|
|
3701
|
-
if (
|
|
3966
|
+
if (isRecord7(value)) {
|
|
3702
3967
|
return { type: "object", keyCount: Object.keys(value).length };
|
|
3703
3968
|
}
|
|
3704
3969
|
if (value === null) {
|
|
@@ -3785,7 +4050,7 @@ function mapOpenInferenceKind(span, attributes, pathPrefix) {
|
|
|
3785
4050
|
}
|
|
3786
4051
|
}
|
|
3787
4052
|
function mapOpenInferenceStatus(status) {
|
|
3788
|
-
if (!
|
|
4053
|
+
if (!isRecord7(status)) return void 0;
|
|
3789
4054
|
const rawCode = status.code;
|
|
3790
4055
|
if (typeof rawCode !== "string") return void 0;
|
|
3791
4056
|
switch (rawCode.toUpperCase()) {
|
|
@@ -3885,7 +4150,7 @@ function mapOpenInferenceSpan(span, index, version) {
|
|
|
3885
4150
|
warnings.push(...kindWarnings);
|
|
3886
4151
|
const status = mapOpenInferenceStatus(span.status);
|
|
3887
4152
|
const tokenUsage = readOpenInferenceTokenUsage(rawAttributes);
|
|
3888
|
-
const errorMessage =
|
|
4153
|
+
const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
|
|
3889
4154
|
const event = {
|
|
3890
4155
|
schemaVersion: "0.2",
|
|
3891
4156
|
eventId: typeof rawAttributes["agent_inspect.event_id"] === "string" ? rawAttributes["agent_inspect.event_id"] : spanId,
|
|
@@ -4031,7 +4296,7 @@ var openInferenceJsonReader = {
|
|
|
4031
4296
|
}
|
|
4032
4297
|
};
|
|
4033
4298
|
function parseOtlpAnyValue(value, field, warnings, unsupportedFields) {
|
|
4034
|
-
if (!
|
|
4299
|
+
if (!isRecord7(value)) {
|
|
4035
4300
|
unsupportedFields.push(field);
|
|
4036
4301
|
warnings.push({
|
|
4037
4302
|
code: "otlp_attribute_value_invalid",
|
|
@@ -4053,15 +4318,15 @@ function parseOtlpAnyValue(value, field, warnings, unsupportedFields) {
|
|
|
4053
4318
|
if (typeof value.doubleValue === "number" && Number.isFinite(value.doubleValue)) {
|
|
4054
4319
|
return value.doubleValue;
|
|
4055
4320
|
}
|
|
4056
|
-
if (
|
|
4321
|
+
if (isRecord7(value.arrayValue) && Array.isArray(value.arrayValue.values)) {
|
|
4057
4322
|
return value.arrayValue.values.map(
|
|
4058
4323
|
(item, index) => parseOtlpAnyValue(item, `${field}.arrayValue.values[${index}]`, warnings, unsupportedFields)
|
|
4059
4324
|
);
|
|
4060
4325
|
}
|
|
4061
|
-
if (
|
|
4326
|
+
if (isRecord7(value.kvlistValue) && Array.isArray(value.kvlistValue.values)) {
|
|
4062
4327
|
const out = {};
|
|
4063
4328
|
for (const [index, item] of value.kvlistValue.values.entries()) {
|
|
4064
|
-
if (!
|
|
4329
|
+
if (!isRecord7(item) || typeof item.key !== "string") {
|
|
4065
4330
|
unsupportedFields.push(`${field}.kvlistValue.values[${index}]`);
|
|
4066
4331
|
continue;
|
|
4067
4332
|
}
|
|
@@ -4112,7 +4377,7 @@ function parseOtlpAttributes(value, pathPrefix) {
|
|
|
4112
4377
|
}
|
|
4113
4378
|
for (const [index, item] of value.entries()) {
|
|
4114
4379
|
const field = `${pathPrefix}[${index}]`;
|
|
4115
|
-
if (!
|
|
4380
|
+
if (!isRecord7(item) || typeof item.key !== "string") {
|
|
4116
4381
|
unsupportedFields.push(field);
|
|
4117
4382
|
warnings.push({
|
|
4118
4383
|
code: "otlp_attribute_invalid",
|
|
@@ -4135,16 +4400,16 @@ function parseOtlpAttributes(value, pathPrefix) {
|
|
|
4135
4400
|
return { attributes, warnings, unsupportedFields };
|
|
4136
4401
|
}
|
|
4137
4402
|
function looksLikeOtlpSpan(value) {
|
|
4138
|
-
return
|
|
4403
|
+
return isRecord7(value) && readStringField(value, ["traceId"]) !== void 0 && readStringField(value, ["spanId"]) !== void 0 && readStringField(value, ["name"]) !== void 0;
|
|
4139
4404
|
}
|
|
4140
4405
|
function extractOtlpDocument(root) {
|
|
4141
|
-
if (!
|
|
4406
|
+
if (!isRecord7(root) || !Array.isArray(root.resourceSpans)) return void 0;
|
|
4142
4407
|
const spans = [];
|
|
4143
4408
|
const warnings = [];
|
|
4144
4409
|
const unsupportedFields = [];
|
|
4145
4410
|
for (const [resourceIndex, resourceSpan] of root.resourceSpans.entries()) {
|
|
4146
4411
|
const resourcePath = `resourceSpans[${resourceIndex}]`;
|
|
4147
|
-
if (!
|
|
4412
|
+
if (!isRecord7(resourceSpan)) {
|
|
4148
4413
|
unsupportedFields.push(resourcePath);
|
|
4149
4414
|
continue;
|
|
4150
4415
|
}
|
|
@@ -4167,7 +4432,7 @@ function extractOtlpDocument(root) {
|
|
|
4167
4432
|
}
|
|
4168
4433
|
for (const [scopeIndex, scopeSpan] of resourceSpan.scopeSpans.entries()) {
|
|
4169
4434
|
const scopePath = `${resourcePath}.scopeSpans[${scopeIndex}]`;
|
|
4170
|
-
if (!
|
|
4435
|
+
if (!isRecord7(scopeSpan)) {
|
|
4171
4436
|
unsupportedFields.push(scopePath);
|
|
4172
4437
|
continue;
|
|
4173
4438
|
}
|
|
@@ -4234,7 +4499,7 @@ function extractOtlpDocument(root) {
|
|
|
4234
4499
|
};
|
|
4235
4500
|
}
|
|
4236
4501
|
function mapOtlpStatus(status) {
|
|
4237
|
-
if (!
|
|
4502
|
+
if (!isRecord7(status)) return void 0;
|
|
4238
4503
|
const rawCode = status.code;
|
|
4239
4504
|
if (typeof rawCode !== "string") return void 0;
|
|
4240
4505
|
switch (rawCode.toUpperCase()) {
|
|
@@ -4334,7 +4599,7 @@ function mapOtlpEvents(value, pathPrefix) {
|
|
|
4334
4599
|
const events = [];
|
|
4335
4600
|
for (const [index, event] of value.entries()) {
|
|
4336
4601
|
const eventPath = `${pathPrefix}[${index}]`;
|
|
4337
|
-
if (!
|
|
4602
|
+
if (!isRecord7(event)) {
|
|
4338
4603
|
unsupportedFields.push(eventPath);
|
|
4339
4604
|
continue;
|
|
4340
4605
|
}
|
|
@@ -4472,7 +4737,7 @@ function mapOtlpSpan(context) {
|
|
|
4472
4737
|
warnings.push(...kindWarnings);
|
|
4473
4738
|
const status = mapOtlpStatus(span.status);
|
|
4474
4739
|
const tokenUsage = readOtlpTokenUsage(parsedSpanAttributes.attributes);
|
|
4475
|
-
const errorMessage =
|
|
4740
|
+
const errorMessage = isRecord7(span.status) && typeof span.status.message === "string" ? span.status.message : void 0;
|
|
4476
4741
|
const event = {
|
|
4477
4742
|
schemaVersion: "0.2",
|
|
4478
4743
|
eventId: typeof parsedSpanAttributes.attributes["agent_inspect.event_id"] === "string" ? parsedSpanAttributes.attributes["agent_inspect.event_id"] : spanId,
|