2026-10-05 08:00:40 +00:00
// Module ID: 16763
// Function ID: 16764
// Name: ConjureTraceUtils
2026-09-16 07:03:15 +00:00
// Dependencies: [2]
// Exports: filterTrace, findTraceEntry, groupTraceByTurn, isModelEntry, isToolEntry, traceCategoryTotals, traceChildren, traceExportPayload
2026-10-05 08:00:40 +00:00
// Module 16763 (ConjureTraceUtils)
2026-09-16 07:03:15 +00:00
import size from "module_2" /* 2 */ ;
2026-10-03 08:58:59 +00:00
let NEGATIVE_INFINITY , POSITIVE_INFINITY ;
2026-09-16 07:03:15 +00:00
function traceCategory ( entry ) {
2026-10-03 08:58:59 +00:00
let str2 ;
2026-09-16 07:03:15 +00:00
let str = "model" ;
if ( "model" === entry . kind ) {
let str4 = "context" ;
if ( "compaction" !== entry . agent ) {
if ( "subagent" === entry . agent ) {
str = "subagent" ;
}
str4 = str ;
}
2026-10-03 08:58:59 +00:00
str2 = str4 ;
2026-09-16 07:03:15 +00:00
} else {
str2 = "tool" ;
if ( "subagent" === entry . agent ) {
str2 = "delegated" ;
}
}
return str2 ;
}
function groupSpanMs ( arg0 ) {
const iter = arg0 [ Symbol . iterator ] ( ) ;
const nextResult = iter . next ( ) ;
while ( iter !== undefined ) {
let tmp2 = nextResult ;
let _Date = Date ;
let parsed = Date . parse ( nextResult . startedAt ) ;
let tmp4 = parsed ;
let _Number = Number ;
if ( ! Number . isNaN ( parsed ) ) {
let _Math = Math ;
POSITIVE_INFINITY = Math . min ( POSITIVE_INFINITY , tmp4 ) ;
if ( null != tmp2 . durationMs ) {
let _Math2 = Math ;
NEGATIVE_INFINITY = Math . max ( NEGATIVE_INFINITY , tmp4 + tmp2 . durationMs ) ;
}
}
continue ;
}
let bound = null ;
if ( Number . isFinite ( POSITIVE_INFINITY ) ) {
const _Number2 = Number ;
bound = null ;
if ( Number . isFinite ( NEGATIVE_INFINITY ) ) {
const _Math3 = Math ;
bound = Math . max ( 0 , NEGATIVE_INFINITY - POSITIVE_INFINITY ) ;
}
}
return bound ;
}
function traceSearchText ( kind ) {
2026-10-03 08:58:59 +00:00
let items1 ;
let stopReason ;
let str4 ;
let summary ;
2026-09-16 07:03:15 +00:00
let str = "model" ;
if ( "model" === kind . kind ) {
items = [ , , , ] ;
( { model : arr2 [ 0 ] , agent : arr2 [ 1 ] , stopReason } = kind ) ;
if ( stopReason == null ) {
stopReason = "" ;
}
items [ 2 ] = stopReason ;
let str3 = kind . error ;
if ( str3 == null ) {
str3 = "" ;
}
items [ 3 ] = str3 ;
2026-10-03 08:58:59 +00:00
items1 = items ;
2026-09-16 07:03:15 +00:00
} else {
items1 = [ , , , ] ;
( { tool : arr [ 0 ] , agent : arr [ 1 ] , summary } = kind ) ;
if ( summary == null ) {
summary = "" ;
}
items1 [ 2 ] = summary ;
let str2 = kind . error ;
if ( str2 == null ) {
str2 = "" ;
}
items1 [ 3 ] = str2 ;
}
2026-10-03 08:58:59 +00:00
const push = items1 . push ;
2026-09-16 07:03:15 +00:00
if ( str === kind . kind ) {
let str6 = "context" ;
if ( "compaction" !== kind . agent ) {
if ( "subagent" === kind . agent ) {
str = "subagent" ;
}
str6 = str ;
}
2026-10-03 08:58:59 +00:00
str4 = str6 ;
2026-09-16 07:03:15 +00:00
} else {
str4 = "tool" ;
if ( "subagent" === kind . agent ) {
str4 = "delegated" ;
}
}
2026-10-03 08:58:59 +00:00
push ( str4 ) ;
const str9 = items1 . join ( " " ) ;
return str9 . toLowerCase ( ) ;
2026-09-16 07:03:15 +00:00
}
let items = [ "model" , "tool" , "subagent" , "delegated" , "context" ] ;
2026-10-05 08:00:40 +00:00
const result = size . fileFinishedImporting ( "modules/conjure/debug/ConjureTraceUtils.tsx" ) ;
2026-09-16 07:03:15 +00:00
export { traceCategory } ;
export const TRACE_CATEGORIES = items ;
export const traceCategoryTotals = function traceCategoryTotals ( entries ) {
let obj = { model : 0 , subagent : 0 , context : 0 , tool : 0 , delegated : 0 } ;
const obj2 = { model : 0 , subagent : 0 , context : 0 , tool : 0 , delegated : 0 } ;
const iter = entries [ Symbol . iterator ] ( ) ;
const nextResult = iter . next ( ) ;
while ( iter !== undefined ) {
let tmp3 = traceCategory ( nextResult ) ;
let tmp4 = tmp3 ;
let num = nextResult . durationMs ;
2026-10-03 08:58:59 +00:00
let tmp5 = obj [ tmp3 ] ;
2026-09-16 07:03:15 +00:00
if ( num == null ) {
num = 0 ;
}
2026-10-03 08:58:59 +00:00
obj [ tmp3 ] = tmp5 + num ;
2026-09-16 07:03:15 +00:00
obj2 [ tmp4 ] = obj2 [ tmp4 ] + 1 ;
continue ;
}
return items . map ( ( category ) = > {
obj = { category , ms : obj [ category ] , calls : obj2 [ category ] } ;
return obj ;
} ) ;
} ;
export const groupTraceByTurn = function groupTraceByTurn ( stateFromStoresArray ) {
items = [ ] ;
let tmp = null ;
const iter = stateFromStoresArray [ Symbol . iterator ] ( ) ;
const nextResult = iter . next ( ) ;
while ( iter !== undefined ) {
let tmp3 = nextResult ;
let turnId = nextResult . turnId ;
if ( turnId == null ) {
turnId = null ;
}
let tmp5 = turnId ;
let tmp7 = null != tmp ;
if ( tmp7 ) {
tmp7 = tmp . turnId === tmp5 ;
}
if ( ! tmp7 ) {
2026-10-03 08:58:59 +00:00
let obj = { turnId : tmp5 , entries : [ ] } ;
2026-09-16 07:03:15 +00:00
tmp = obj ;
2026-10-03 08:58:59 +00:00
let obj2 = { turnId : tmp5 , entries : obj.entries , startedAt : tmp3.startedAt , spanMs : null } ;
2026-09-16 07:03:15 +00:00
let arr = items . push ( obj2 ) ;
}
let entries = tmp . entries ;
let arr2 = entries . push ( tmp3 ) ;
continue ;
}
return items . map ( ( item ) = > {
2026-10-03 08:58:59 +00:00
const obj = { spanMs : groupSpanMs ( item . entries ) } ;
2026-09-16 07:03:15 +00:00
const merged = Object . assign ( item ) ;
return obj ;
} ) ;
} ;
export { traceSearchText } ;
2026-10-03 08:58:59 +00:00
export const filterTrace = function filterTrace ( entries , first1 ) {
const str = first1 . trim ( ) ;
const formatted = str . toLowerCase ( ) ;
2026-09-16 07:03:15 +00:00
let found = entries ;
if ( "" !== formatted ) {
2026-10-03 08:58:59 +00:00
found = entries . filter ( ( item ) = > {
const obj = traceSearchText ( item ) ;
return obj . includes ( formatted ) ;
} ) ;
2026-09-16 07:03:15 +00:00
}
return found ;
} ;
export const traceChildren = function traceChildren ( stateFromStoresArray , id ) {
2026-10-03 08:58:59 +00:00
let closure_0 = id ;
return stateFromStoresArray . filter ( ( kind ) = > "tool" === kind . kind && kind . parentId === id ) ;
2026-09-16 07:03:15 +00:00
} ;
export const findTraceEntry = function findTraceEntry ( stateFromStoresArray , entryId ) {
2026-10-03 08:58:59 +00:00
let closure_0 = entryId ;
2026-09-16 07:03:15 +00:00
let tmp = null ;
if ( null != entryId ) {
2026-10-03 08:58:59 +00:00
let found = stateFromStoresArray . find ( ( id ) = > id . id === entryId ) ;
2026-09-16 07:03:15 +00:00
if ( found == null ) {
found = null ;
}
tmp = found ;
}
return tmp ;
} ;
2026-09-18 06:58:00 +00:00
export const traceExportPayload = function traceExportPayload ( projectId , stateFromStoresArray , date ) {
2026-10-03 08:58:59 +00:00
const obj = { kind : "vibegrations.trace" , version : 1 , project_id : projectId , exported_at : date , note : "Redacted developer trace. Tool arguments, results and prompts are reported as sizes and allowlisted technical values only; token counts marked \"estimated\" are a chars/4 heuristic measured before sending." , entries : stateFromStoresArray } ;
return JSON . stringify ( obj , null , 2 ) ;
2026-09-16 07:03:15 +00:00
} ;
export const isToolEntry = function isToolEntry ( kind ) {
return "tool" === kind . kind ;
} ;
export const isModelEntry = function isModelEntry ( kind ) {
return "model" === kind . kind ;
} ;