MCPcopy Create free account
hub / github.com/microsoft/Webwright / extractTrajectoryUsage

Function extractTrajectoryUsage

assets/compare_trajectory/app.js:140–162  ·  view source on GitHub ↗
(text, fileName)

Source from the content-addressed store, hash-verified

138}
139
140function extractTrajectoryUsage(text, fileName) {
141 const parsed = safeJsonParse(String(text || '').trim());
142 if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.messages)) {
143 throw new Error('Attachment must be a valid trajectory.json file.');
144 }
145 let latestUsage = null;
146 parsed.messages.forEach((message) => {
147 const usage = message && message.extra && message.extra.usage;
148 const cumulative = usage && usage.cumulative_response;
149 if (cumulative && typeof cumulative.total_tokens === 'number') {
150 latestUsage = cumulative;
151 }
152 });
153 if (!latestUsage) {
154 throw new Error('trajectory.json does not contain messages[].extra.usage.cumulative_response.');
155 }
156 return {
157 fileName,
158 exactTokens: latestUsage,
159 tokenRows: tokenRowsFromTotals(latestUsage),
160 tokenSourceLabel: 'Exact tokens from attached trajectory.json.'
161 };
162}
163
164function applyTrajectoryCompanion(trace, companion) {
165 return Object.assign({}, trace, {

Callers 1

handleCompanionInputFunction · 0.85

Calls 2

safeJsonParseFunction · 0.85
tokenRowsFromTotalsFunction · 0.85

Tested by

no test coverage detected