@peasant-labs/fairtrade 0.0.39 → 0.0.41
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/THIRD_PARTY_NOTICES.md +14 -0
- package/dist/lib/{GraphLegend-DwLFq2JU.js → GraphLegend-CBKZsRta.js} +1401 -1488
- package/dist/lib/adapter-Dulh38C2.js +1214 -0
- package/dist/lib/analytics.css +1 -1
- package/dist/lib/analytics.js +289 -292
- package/dist/lib/commons.js +807 -805
- package/dist/lib/components.css +1 -1
- package/dist/lib/format-B3uT2wzU.js +41 -0
- package/dist/lib/graph.js +383 -381
- package/dist/lib/share-fonts/AtkinsonHyperlegible-Bold.ttf +0 -0
- package/dist/lib/share-fonts/AtkinsonHyperlegible-Regular.ttf +0 -0
- package/dist/lib/share-fonts/AtkinsonHyperlegibleMono-Bold.ttf +0 -0
- package/dist/lib/share-fonts/AtkinsonHyperlegibleMono-Regular.ttf +0 -0
- package/dist/lib/share-fonts/OFL-AtkinsonHyperlegible.txt +92 -0
- package/dist/lib/share-fonts/OFL-AtkinsonHyperlegibleMono.txt +93 -0
- package/dist/lib/share.js +1311 -0
- package/dist/lib/time-CpVBzcqQ.js +157 -0
- package/dist/lib/types/BrandMark.d.ts +2 -6
- package/dist/lib/types/CliOnboard.d.ts +11 -0
- package/dist/lib/types/DiffView.d.ts +5 -3
- package/dist/lib/types/Publish.d.ts +29 -7
- package/dist/lib/types/Switch.d.ts +8 -1
- package/dist/lib/types/analytics/format.d.ts +2 -1
- package/dist/lib/types/brand-geometry.d.ts +22 -0
- package/dist/lib/types/commons/providers.d.ts +1 -1
- package/dist/lib/types/format.d.ts +35 -4
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/share/ShareCard.d.ts +40 -0
- package/dist/lib/types/share/data.d.ts +54 -0
- package/dist/lib/types/share/fonts.d.ts +16 -0
- package/dist/lib/types/share/index.d.ts +5 -0
- package/dist/lib/types/share/marks.d.ts +23 -0
- package/dist/lib/types/share/metrics.d.ts +10 -0
- package/dist/lib/types/transcript/title.d.ts +21 -0
- package/dist/lib/types/ui/brand-geometry.d.ts +22 -0
- package/dist/lib/types/ui/format.d.ts +35 -0
- package/dist/lib/types/ui/provider-policy.d.ts +27 -0
- package/dist/lib/types/ui/transcript/adapter.d.ts +66 -0
- package/dist/lib/types/ui/transcript/adapter.parse.d.ts +103 -0
- package/dist/lib/types/ui/transcript/analytics.d.ts +213 -0
- package/dist/lib/types/ui/transcript/time.d.ts +47 -0
- package/dist/lib/types/ui/transcript/title.d.ts +84 -0
- package/dist/lib/types/ui/transcript/usage.d.ts +19 -0
- package/dist/lib/types/ui/transcript/view-model.d.ts +700 -0
- package/dist/lib/types/ui/transcript/wire-types.d.ts +63 -0
- package/dist/lib/{ui-CBsfaQMA.js → ui-Bhk29YuW.js} +4198 -5412
- package/dist/lib/ui.js +7 -4
- package/package.json +20 -6
|
@@ -0,0 +1,1214 @@
|
|
|
1
|
+
import { o as e } from "./time-CpVBzcqQ.js";
|
|
2
|
+
import { UsageScope as t, parseSessionDetailPayloadValue as n, zContentProvenance as r, zObservedModelID as i, zSessionRelationshipNavigation as a, zSourceEntryRef as o } from "@peasant-labs/schema";
|
|
3
|
+
//#region src/ui/transcript/adapter.parse.js
|
|
4
|
+
function s(e) {
|
|
5
|
+
if (e) try {
|
|
6
|
+
return JSON.parse(e);
|
|
7
|
+
} catch {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function c(e) {
|
|
12
|
+
return s(e);
|
|
13
|
+
}
|
|
14
|
+
function l(e) {
|
|
15
|
+
return s(e);
|
|
16
|
+
}
|
|
17
|
+
function u(e) {
|
|
18
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
19
|
+
}
|
|
20
|
+
function d(e) {
|
|
21
|
+
return typeof e == "string" ? e : void 0;
|
|
22
|
+
}
|
|
23
|
+
function f(e) {
|
|
24
|
+
if (e.filePath) return e.filePath;
|
|
25
|
+
let t = u(c(e.arguments));
|
|
26
|
+
if (t) return d(t.file_path) ?? d(t.path) ?? d(t.notebook_path);
|
|
27
|
+
}
|
|
28
|
+
function p(e) {
|
|
29
|
+
let t = u(c(e.arguments));
|
|
30
|
+
if (!t) return [];
|
|
31
|
+
if (Array.isArray(t.edits)) {
|
|
32
|
+
let e = [];
|
|
33
|
+
for (let n of t.edits) {
|
|
34
|
+
let t = u(n);
|
|
35
|
+
t && e.push({
|
|
36
|
+
old_string: d(t.old_string) ?? "",
|
|
37
|
+
new_string: d(t.new_string) ?? ""
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (e.length) return e;
|
|
41
|
+
}
|
|
42
|
+
let n = d(t.old_string), r = d(t.new_string);
|
|
43
|
+
return n !== void 0 || r !== void 0 ? [{
|
|
44
|
+
old_string: n ?? "",
|
|
45
|
+
new_string: r ?? ""
|
|
46
|
+
}] : [];
|
|
47
|
+
}
|
|
48
|
+
function m(e) {
|
|
49
|
+
let t = u(c(e.arguments));
|
|
50
|
+
return (t && d(t.content)) ?? "";
|
|
51
|
+
}
|
|
52
|
+
function h(e, t) {
|
|
53
|
+
let n = e === "" ? [] : e.split("\n"), r = t === "" ? [] : t.split("\n"), i = n.length, a = r.length, o = Array.from({ length: i + 1 }, () => Array(a + 1).fill(0));
|
|
54
|
+
for (let e = i - 1; e >= 0; e--) for (let t = a - 1; t >= 0; t--) o[e][t] = n[e] === r[t] ? o[e + 1][t + 1] + 1 : Math.max(o[e + 1][t], o[e][t + 1]);
|
|
55
|
+
let s = [], c = 0, l = 0, u = 1, d = 1;
|
|
56
|
+
for (; c < i && l < a;) n[c] === r[l] ? (s.push({
|
|
57
|
+
sign: "ctx",
|
|
58
|
+
oldNo: String(u++),
|
|
59
|
+
newNo: String(d++),
|
|
60
|
+
text: n[c]
|
|
61
|
+
}), c++, l++) : o[c + 1][l] >= o[c][l + 1] ? (s.push({
|
|
62
|
+
sign: "del",
|
|
63
|
+
oldNo: String(u++),
|
|
64
|
+
text: n[c]
|
|
65
|
+
}), c++) : (s.push({
|
|
66
|
+
sign: "add",
|
|
67
|
+
newNo: String(d++),
|
|
68
|
+
text: r[l]
|
|
69
|
+
}), l++);
|
|
70
|
+
for (; c < i;) s.push({
|
|
71
|
+
sign: "del",
|
|
72
|
+
oldNo: String(u++),
|
|
73
|
+
text: n[c++]
|
|
74
|
+
});
|
|
75
|
+
for (; l < a;) s.push({
|
|
76
|
+
sign: "add",
|
|
77
|
+
newNo: String(d++),
|
|
78
|
+
text: r[l++]
|
|
79
|
+
});
|
|
80
|
+
return s;
|
|
81
|
+
}
|
|
82
|
+
var g = /* @__PURE__ */ new WeakMap();
|
|
83
|
+
function _(e) {
|
|
84
|
+
if (g.has(e)) return g.get(e);
|
|
85
|
+
let t = e.name.toLowerCase(), n;
|
|
86
|
+
if (t === "write") n = [h("", m(e))];
|
|
87
|
+
else if (t === "edit" || t === "multiedit" || t === "notebookedit") {
|
|
88
|
+
let t = p(e);
|
|
89
|
+
t.length && (n = t.map((e) => h(e.old_string, e.new_string)));
|
|
90
|
+
}
|
|
91
|
+
let r;
|
|
92
|
+
if (n) {
|
|
93
|
+
let e = 0, t = 0;
|
|
94
|
+
for (let r of n) {
|
|
95
|
+
let n = r.length > 0 && r[r.length - 1].text === "" ? r.slice(0, -1) : r;
|
|
96
|
+
for (let r of n) r.sign === "add" ? e++ : r.sign === "del" && t++;
|
|
97
|
+
}
|
|
98
|
+
r = {
|
|
99
|
+
spans: n,
|
|
100
|
+
adds: e,
|
|
101
|
+
dels: t
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return g.set(e, r), r;
|
|
105
|
+
}
|
|
106
|
+
function v(e) {
|
|
107
|
+
let t = _(e);
|
|
108
|
+
return t ? {
|
|
109
|
+
adds: t.adds,
|
|
110
|
+
dels: t.dels
|
|
111
|
+
} : {
|
|
112
|
+
adds: 0,
|
|
113
|
+
dels: 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/ui/transcript/analytics.js
|
|
118
|
+
function y(e) {
|
|
119
|
+
if (e.length === 0) return [];
|
|
120
|
+
let t = [];
|
|
121
|
+
for (let n = 0; n < e.length; n++) {
|
|
122
|
+
let r = e[n];
|
|
123
|
+
r.role === "user" && (r.depth ?? 0) === 0 && r.content?.trim() && t.push(n);
|
|
124
|
+
}
|
|
125
|
+
(t.length === 0 || t[0] !== 0) && t.unshift(0);
|
|
126
|
+
let n = [];
|
|
127
|
+
for (let r = 0; r < t.length; r++) {
|
|
128
|
+
let i = t[r], a = (r + 1 < t.length ? t[r + 1] : e.length) - 1;
|
|
129
|
+
n.push(ee(e, i, a));
|
|
130
|
+
}
|
|
131
|
+
return n;
|
|
132
|
+
}
|
|
133
|
+
function ee(e, t, n) {
|
|
134
|
+
let r = e[t], i = 0, a = /* @__PURE__ */ new Set(), o = 0, s = 0, c = !1, l = 0, u;
|
|
135
|
+
for (let r = t; r <= n; r++) {
|
|
136
|
+
let t = e[r];
|
|
137
|
+
l += (t.tokensIn ?? 0) + (t.tokensOut ?? 0), t.role === "assistant" && (t.depth ?? 0) === 0 && (u = t.index);
|
|
138
|
+
for (let e of t.toolCalls ?? []) {
|
|
139
|
+
i++, e.isError && (c = !0);
|
|
140
|
+
let t = f(e);
|
|
141
|
+
t && a.add(t);
|
|
142
|
+
let { adds: n, dels: r } = v(e);
|
|
143
|
+
o += n, s += r;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
let d = new Date(r.timestamp).getTime(), p = new Date(e[n].timestamp).getTime(), m = Number.isFinite(d) && Number.isFinite(p) ? Math.max(0, p - d) : 0, h = {
|
|
147
|
+
startIndex: t,
|
|
148
|
+
endIndex: n,
|
|
149
|
+
promptEntryIndex: r.index,
|
|
150
|
+
prompt: r.content ?? "",
|
|
151
|
+
toolCallCount: i,
|
|
152
|
+
filesTouched: Array.from(a),
|
|
153
|
+
insertions: o,
|
|
154
|
+
deletions: s,
|
|
155
|
+
durationMs: m,
|
|
156
|
+
hasErrors: c,
|
|
157
|
+
tokens: l
|
|
158
|
+
};
|
|
159
|
+
return u !== void 0 && (h.finalEntryIndex = u), h;
|
|
160
|
+
}
|
|
161
|
+
function b(e) {
|
|
162
|
+
if (e.length === 0) return [];
|
|
163
|
+
let t = y(e), n = /* @__PURE__ */ new Map();
|
|
164
|
+
for (let e = 0; e < t.length; e++) n.set(t[e].startIndex, e + 1);
|
|
165
|
+
let r = Array(e.length), i = 0, a = 0;
|
|
166
|
+
for (let t = 0; t < e.length; t++) {
|
|
167
|
+
let e = n.get(t);
|
|
168
|
+
e === void 0 ? i === 0 ? r[t] = `${t + 1}` : (a += 1, r[t] = `${i}${te(a)}`) : (i = e, a = 0, r[t] = `${i}`);
|
|
169
|
+
}
|
|
170
|
+
return r;
|
|
171
|
+
}
|
|
172
|
+
function te(e) {
|
|
173
|
+
let t = "", n = e;
|
|
174
|
+
for (; n > 0;) t = String.fromCharCode(97 + (n - 1) % 26) + t, n = Math.floor((n - 1) / 26);
|
|
175
|
+
return t;
|
|
176
|
+
}
|
|
177
|
+
function ne(e) {
|
|
178
|
+
let t = e.reduce((e, t) => e + Math.max(0, t.durationMs), 0), n = 0;
|
|
179
|
+
return e.map((e) => {
|
|
180
|
+
let r = Math.max(0, e.durationMs), i = t > 0 ? n / t * 100 : 0, a = t > 0 ? r / t * 100 : 0;
|
|
181
|
+
return n += r, {
|
|
182
|
+
promptEntryIndex: e.promptEntryIndex,
|
|
183
|
+
offsetPct: i,
|
|
184
|
+
widthPct: a,
|
|
185
|
+
durationMs: r
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
var re = /* @__PURE__ */ new Set([
|
|
190
|
+
"Task",
|
|
191
|
+
"EnterWorktree",
|
|
192
|
+
"SendMessage",
|
|
193
|
+
"TeamCreate"
|
|
194
|
+
]), ie = /* @__PURE__ */ new Set([
|
|
195
|
+
"Write",
|
|
196
|
+
"Edit",
|
|
197
|
+
"NotebookEdit"
|
|
198
|
+
]);
|
|
199
|
+
function x(e) {
|
|
200
|
+
let t = [], n = [], r = /* @__PURE__ */ new Map();
|
|
201
|
+
for (let i = 0; i < e.length; i++) {
|
|
202
|
+
let a = e[i];
|
|
203
|
+
if (a.toolCalls) for (let e of a.toolCalls) {
|
|
204
|
+
if ((e.isError || e.exitCode !== void 0 && e.exitCode !== null && e.exitCode !== 0) && t.push({
|
|
205
|
+
turnIndex: i,
|
|
206
|
+
type: "error",
|
|
207
|
+
label: `${e.name} failed`,
|
|
208
|
+
severity: "error"
|
|
209
|
+
}), re.has(e.name) && t.push({
|
|
210
|
+
turnIndex: i,
|
|
211
|
+
type: "subagent",
|
|
212
|
+
label: `Subagent: ${e.name}`,
|
|
213
|
+
severity: "info"
|
|
214
|
+
}), ie.has(e.name)) {
|
|
215
|
+
let t = f(e);
|
|
216
|
+
if (t) {
|
|
217
|
+
let e = r.get(t) ?? [];
|
|
218
|
+
e.push(i), r.set(t, e);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
n.filter((t) => i - t.index <= 5 && t.name === e.name).length >= 2 && (t.push({
|
|
222
|
+
turnIndex: i,
|
|
223
|
+
type: "retry",
|
|
224
|
+
label: "Retry loop",
|
|
225
|
+
severity: "warning"
|
|
226
|
+
}), n.length = 0), n.push({
|
|
227
|
+
name: e.name,
|
|
228
|
+
index: i
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (let [e, n] of r) if (n.length > 1) {
|
|
233
|
+
let r = n[n.length - 1], i = e.split("/").pop() ?? e;
|
|
234
|
+
t.push({
|
|
235
|
+
turnIndex: r,
|
|
236
|
+
type: "revert",
|
|
237
|
+
label: `Re-edit: ${i}`,
|
|
238
|
+
severity: "warning"
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return t.sort((e, t) => e.turnIndex - t.turnIndex);
|
|
242
|
+
}
|
|
243
|
+
var ae = {
|
|
244
|
+
planning: "Planning",
|
|
245
|
+
exploration: "Exploration",
|
|
246
|
+
implementation: "Implementation",
|
|
247
|
+
testing: "Testing",
|
|
248
|
+
error: "Errors",
|
|
249
|
+
debug: "Debugging",
|
|
250
|
+
"retry-loop": "Retry loop",
|
|
251
|
+
"user-correction": "User correction",
|
|
252
|
+
recovery: "Recovery",
|
|
253
|
+
abandonment: "Abandonment"
|
|
254
|
+
};
|
|
255
|
+
function S(e) {
|
|
256
|
+
return ae[e] ?? String(e);
|
|
257
|
+
}
|
|
258
|
+
var C = /* @__PURE__ */ new Set([
|
|
259
|
+
"Read",
|
|
260
|
+
"Glob",
|
|
261
|
+
"Grep",
|
|
262
|
+
"WebSearch",
|
|
263
|
+
"WebFetch"
|
|
264
|
+
]), w = /* @__PURE__ */ new Set([
|
|
265
|
+
"Write",
|
|
266
|
+
"Edit",
|
|
267
|
+
"NotebookEdit"
|
|
268
|
+
]), oe = [
|
|
269
|
+
/\btest\b/i,
|
|
270
|
+
/\bjest\b/i,
|
|
271
|
+
/\bpytest\b/i,
|
|
272
|
+
/\bgo\s+test\b/i,
|
|
273
|
+
/\bnpm\s+test\b/i,
|
|
274
|
+
/\bmake\s+check\b/i,
|
|
275
|
+
/\bcargo\s+test\b/i,
|
|
276
|
+
/\bvitest\b/i,
|
|
277
|
+
/\bplaywright\b/i,
|
|
278
|
+
/\bmocha\b/i,
|
|
279
|
+
/\brspec\b/i
|
|
280
|
+
];
|
|
281
|
+
function se(e, t) {
|
|
282
|
+
return e.toolCalls?.some((e) => t.has(e.name)) ?? !1;
|
|
283
|
+
}
|
|
284
|
+
function ce(e, t) {
|
|
285
|
+
return e.toolCalls?.length ? e.toolCalls.every((e) => t.has(e.name)) : !1;
|
|
286
|
+
}
|
|
287
|
+
function T(e) {
|
|
288
|
+
for (let t of e.toolCalls ?? []) if (t.isError || t.exitCode !== void 0 && t.exitCode !== null && t.exitCode !== 0) return !0;
|
|
289
|
+
return !1;
|
|
290
|
+
}
|
|
291
|
+
function le(e) {
|
|
292
|
+
for (let t of e.toolCalls ?? []) if (t.name === "Bash" && oe.some((e) => e.test(t.arguments))) return !0;
|
|
293
|
+
return !1;
|
|
294
|
+
}
|
|
295
|
+
function ue(e) {
|
|
296
|
+
let t = [], n = [], r = -1;
|
|
297
|
+
for (let i = 0; i < e.length; i++) {
|
|
298
|
+
let a = e[i];
|
|
299
|
+
if (a.role === "user") {
|
|
300
|
+
n.length > 0 && r >= 0 && (n = [], r = -1);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (a.toolCalls?.length) {
|
|
304
|
+
r < 0 && (r = i);
|
|
305
|
+
for (let e of a.toolCalls) n.push(e.name), (e.isError || e.exitCode !== void 0 && e.exitCode !== null && e.exitCode !== 0) && n.length > 0 && (n.some((e) => w.has(e) || e === "Bash") && t.push({
|
|
306
|
+
tools: [...n],
|
|
307
|
+
turnRange: [r, i]
|
|
308
|
+
}), n = [], r = -1);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return t;
|
|
312
|
+
}
|
|
313
|
+
function de(e, t) {
|
|
314
|
+
let n = new Set(e), r = new Set(t), i = [...n].filter((e) => r.has(e)).length, a = (/* @__PURE__ */ new Set([...n, ...r])).size;
|
|
315
|
+
return a > 0 ? i / a : 0;
|
|
316
|
+
}
|
|
317
|
+
function fe(e) {
|
|
318
|
+
let t = ue(e), n = [], r = 0;
|
|
319
|
+
for (; r < t.length;) {
|
|
320
|
+
let e = r + 1;
|
|
321
|
+
for (; e < t.length && de(t[r].tools, t[e].tools) >= .5;) e++;
|
|
322
|
+
e - r >= 2 && n.push([t[r].turnRange[0], t[e - 1].turnRange[1]]), r = e;
|
|
323
|
+
}
|
|
324
|
+
return n;
|
|
325
|
+
}
|
|
326
|
+
var pe = [
|
|
327
|
+
/\bi already said\b/i,
|
|
328
|
+
/\bi told you\b/i,
|
|
329
|
+
/\bno,?\s+not that\b/i,
|
|
330
|
+
/\bthat'?s not what i\b/i,
|
|
331
|
+
/\bnot what i asked\b/i,
|
|
332
|
+
/\bwrong,?\s+i\b/i,
|
|
333
|
+
/\bplease (re-?read|read again)\b/i
|
|
334
|
+
], me = /\b(let'?s move on|forget it|different approach|never mind)\b/i;
|
|
335
|
+
function he(e, t, n, r, i) {
|
|
336
|
+
for (let [e, n] of i) if (t >= e && t <= n) return "retry-loop";
|
|
337
|
+
return e.role === "user" ? pe.some((t) => t.test(e.content)) ? "user-correction" : n ?? "planning" : T(e) ? "error" : le(e) ? "testing" : r > 0 && ce(e, C) ? "debug" : se(e, w) ? n === "retry-loop" || n === "user-correction" ? "recovery" : "implementation" : ce(e, C) && r === 0 ? "exploration" : e.role === "assistant" && !e.toolCalls?.length && e.content.length > 100 ? "planning" : n ?? "planning";
|
|
338
|
+
}
|
|
339
|
+
var ge = /* @__PURE__ */ new Set([
|
|
340
|
+
"error",
|
|
341
|
+
"user-correction",
|
|
342
|
+
"retry-loop",
|
|
343
|
+
"abandonment"
|
|
344
|
+
]);
|
|
345
|
+
function _e(e) {
|
|
346
|
+
if (e.length <= 1) return e;
|
|
347
|
+
let t = [];
|
|
348
|
+
for (let n = 0; n < e.length; n++) {
|
|
349
|
+
let r = e[n], i = r.endTurn - r.startTurn + 1, a = t[t.length - 1];
|
|
350
|
+
if (a && a.type === r.type) {
|
|
351
|
+
a.endTurn = r.endTurn;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (i < 3 && !ge.has(r.type) && a) {
|
|
355
|
+
a.endTurn = r.endTurn;
|
|
356
|
+
let e = a.badges.find((e) => e.type === r.type);
|
|
357
|
+
e ? e.count += i : a.badges.push({
|
|
358
|
+
type: r.type,
|
|
359
|
+
count: i
|
|
360
|
+
});
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (r.type === "error" && i === 1 && a) {
|
|
364
|
+
let t = e[n + 1];
|
|
365
|
+
if (t && t.type === a.type) {
|
|
366
|
+
a.endTurn = r.endTurn;
|
|
367
|
+
let e = a.badges.find((e) => e.type === "error");
|
|
368
|
+
e ? e.count++ : a.badges.push({
|
|
369
|
+
type: "error",
|
|
370
|
+
count: 1
|
|
371
|
+
});
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
t.push({
|
|
376
|
+
...r,
|
|
377
|
+
badges: [...r.badges]
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return t;
|
|
381
|
+
}
|
|
382
|
+
function ve(e) {
|
|
383
|
+
if (e.length === 0) return [];
|
|
384
|
+
let t = fe(e), n = [];
|
|
385
|
+
for (let r = 0; r < e.length; r++) {
|
|
386
|
+
let i = 0;
|
|
387
|
+
for (let t = Math.max(0, r - 3); t < r; t++) T(e[t]) && i++;
|
|
388
|
+
let a = n.length > 0 ? n[n.length - 1].type : null;
|
|
389
|
+
n.push({
|
|
390
|
+
type: he(e[r], r, a, i, t),
|
|
391
|
+
turn: r
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
let r = [], i = null;
|
|
395
|
+
for (let { type: e, turn: t } of n) i && i.type === e ? i.endTurn = t : (i && r.push(i), i = {
|
|
396
|
+
type: e,
|
|
397
|
+
startTurn: t,
|
|
398
|
+
endTurn: t,
|
|
399
|
+
badges: []
|
|
400
|
+
});
|
|
401
|
+
if (i && r.push(i), r.length > 0) {
|
|
402
|
+
let t = e[e.length - 1], n = r[r.length - 1], i = T(t) && t.role === "assistant", a = t.role === "user" && me.test(t.content), o = !e.slice(Math.floor(e.length * .8)).some((e) => se(e, w));
|
|
403
|
+
if ((i || a || o && n.type !== "planning") && (e.filter(T).length > 0 || a) && n.type !== "abandonment") {
|
|
404
|
+
let t = e.length - 1;
|
|
405
|
+
r.push({
|
|
406
|
+
type: "abandonment",
|
|
407
|
+
startTurn: t,
|
|
408
|
+
endTurn: t,
|
|
409
|
+
badges: []
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return _e(r);
|
|
414
|
+
}
|
|
415
|
+
function E(e) {
|
|
416
|
+
return ve(e).map((t, n) => {
|
|
417
|
+
let r = 0;
|
|
418
|
+
for (let n = t.startTurn; n <= t.endTurn; n++) e[n] && T(e[n]) && r++;
|
|
419
|
+
let i = {
|
|
420
|
+
id: `phase-${n + 1}`,
|
|
421
|
+
label: S(t.type),
|
|
422
|
+
from: e[t.startTurn]?.index ?? t.startTurn,
|
|
423
|
+
to: e[t.endTurn]?.index ?? t.endTurn,
|
|
424
|
+
icon: t.type
|
|
425
|
+
};
|
|
426
|
+
return r > 0 && (i.errors = r), i;
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
function D(e) {
|
|
430
|
+
let t = e.filter((e) => Number.isFinite(e)).sort((e, t) => e - t);
|
|
431
|
+
if (t.length === 0) return;
|
|
432
|
+
let n = Math.floor(t.length / 2);
|
|
433
|
+
return t.length % 2 == 0 ? (t[n - 1] + t[n]) / 2 : t[n];
|
|
434
|
+
}
|
|
435
|
+
function ye(e) {
|
|
436
|
+
if (!e || e.length === 0) return {};
|
|
437
|
+
let t = [], n = [], r = [];
|
|
438
|
+
for (let i of e) i.totalTokens > 0 && Number.isFinite(i.retryTokensWasted) && t.push(i.retryTokensWasted / i.totalTokens), Number.isFinite(i.specQualityScore) && i.specQualityScore > 0 && n.push(i.specQualityScore), Number.isFinite(i.withinSessionReverts) && r.push(i.withinSessionReverts);
|
|
439
|
+
let i = {}, a = D(t), o = D(n), s = D(r);
|
|
440
|
+
return a !== void 0 && (i.retryShare = a), o !== void 0 && (i.specQualityScore = o), s !== void 0 && (i.withinSessionReverts = s), i;
|
|
441
|
+
}
|
|
442
|
+
var O = .2, k = 70, A = 50, j = 40, M = 30, N = 4, P = 3;
|
|
443
|
+
function F(e) {
|
|
444
|
+
return e != null;
|
|
445
|
+
}
|
|
446
|
+
function I(e) {
|
|
447
|
+
return e === "bad" ? 2 : +(e === "watch");
|
|
448
|
+
}
|
|
449
|
+
function L(e) {
|
|
450
|
+
return e.reduce((e, t) => I(t) > I(e) ? t : e, "good");
|
|
451
|
+
}
|
|
452
|
+
function R(e, t = {}) {
|
|
453
|
+
if (!e) return [];
|
|
454
|
+
let n = [];
|
|
455
|
+
{
|
|
456
|
+
let r = [], i = [], a = F(e.totalTokens) && (e.totalTokens ?? 0) > 0 && F(e.retryTokensWasted) ? (e.retryTokensWasted ?? 0) / (e.totalTokens ?? 1) : void 0;
|
|
457
|
+
if (a !== void 0 && (r.push(a > O ? "bad" : "good"), a > O && i.push(`${Math.round(a * 100)}% of tokens spent on retries`)), F(e.m5ContextUtilizationPct)) {
|
|
458
|
+
let t = e.m5ContextUtilizationPct ?? 0;
|
|
459
|
+
r.push(t > k ? "watch" : "good"), t > k && i.push(`Context ${Math.round(t)}% full`);
|
|
460
|
+
}
|
|
461
|
+
if (F(e.m6OutputSurvivalPct)) {
|
|
462
|
+
let t = e.m6OutputSurvivalPct ?? 0;
|
|
463
|
+
r.push(t < A ? "watch" : "good"), t < A && i.push(`Only ${Math.round(t)}% of output survived`);
|
|
464
|
+
}
|
|
465
|
+
e.outcome === "failed" && F(e.costTotalUsd) && a !== void 0 && t.retryShare !== void 0 && a > t.retryShare && (r.push("bad"), i.push("Failed outcome with above-median spend")), (a !== void 0 || F(e.m5ContextUtilizationPct) || F(e.m6OutputSurvivalPct)) && n.push(z("token", "Token efficiency", a === void 0 ? F(e.m5ContextUtilizationPct) ? `${Math.round(e.m5ContextUtilizationPct ?? 0)}% context used` : "—" : `${Math.round(a * 100)}% retry tokens`, L(r), i));
|
|
466
|
+
}
|
|
467
|
+
{
|
|
468
|
+
let t = [], r = [];
|
|
469
|
+
if (F(e.specQualityScore)) {
|
|
470
|
+
let n = e.specQualityScore ?? 0;
|
|
471
|
+
t.push(n < j ? "bad" : "good"), n < j && r.push(`Spec quality low (${Math.round(n)}/100)`);
|
|
472
|
+
}
|
|
473
|
+
if (F(e.signalDensity)) {
|
|
474
|
+
let n = e.signalDensity ?? 0;
|
|
475
|
+
t.push(n < M ? "watch" : "good"), n < M && r.push(`Sparse direction (${Math.round(n)}% signal)`);
|
|
476
|
+
}
|
|
477
|
+
e.m7SpecHasExamples === !1 && (t.push("watch"), r.push("No examples in the prompt")), e.m7SpecHasConstraints === !1 && (t.push("watch"), r.push("No constraints in the prompt")), (F(e.specQualityScore) || F(e.signalDensity) || F(e.m7SpecHasExamples) || F(e.m7SpecHasConstraints)) && n.push(z("prompt", "Prompt quality", F(e.specQualityScore) ? `Spec ${Math.round(e.specQualityScore ?? 0)}/100` : F(e.signalDensity) ? `${Math.round(e.signalDensity ?? 0)}% signal` : "—", L(t), r));
|
|
478
|
+
}
|
|
479
|
+
{
|
|
480
|
+
let t = [], r = [];
|
|
481
|
+
if (F(e.m4ConsecutiveErrorMax)) {
|
|
482
|
+
let n = e.m4ConsecutiveErrorMax ?? 0;
|
|
483
|
+
t.push(n >= N ? "bad" : "good"), n >= N && r.push(`${n} errors in a row`);
|
|
484
|
+
}
|
|
485
|
+
if (F(e.withinSessionReverts)) {
|
|
486
|
+
let n = e.withinSessionReverts ?? 0;
|
|
487
|
+
t.push(n >= P ? "bad" : "good"), n >= P && r.push(`${n} reverts mid-session`);
|
|
488
|
+
}
|
|
489
|
+
(F(e.m4ConsecutiveErrorMax) || F(e.withinSessionReverts)) && n.push(z("loop", "Loop efficiency", F(e.m4ConsecutiveErrorMax) ? `${e.m4ConsecutiveErrorMax ?? 0} max error streak` : F(e.withinSessionReverts) ? `${e.withinSessionReverts ?? 0} reverts` : "—", L(t), r));
|
|
490
|
+
}
|
|
491
|
+
return n;
|
|
492
|
+
}
|
|
493
|
+
function z(e, t, n, r, i) {
|
|
494
|
+
let a = {
|
|
495
|
+
id: e,
|
|
496
|
+
label: t,
|
|
497
|
+
band: r,
|
|
498
|
+
value: n,
|
|
499
|
+
icon: e
|
|
500
|
+
};
|
|
501
|
+
return i.length && (a.flags = i, a.detail = i.join(", ")), a;
|
|
502
|
+
}
|
|
503
|
+
function be(e, t) {
|
|
504
|
+
let n = t[e.turnIndex]?.index ?? e.turnIndex;
|
|
505
|
+
return {
|
|
506
|
+
id: `pattern-${e.type}-${e.turnIndex}`,
|
|
507
|
+
kind: e.type,
|
|
508
|
+
turn: n,
|
|
509
|
+
label: e.label
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function xe(e, t, n) {
|
|
513
|
+
let r = [];
|
|
514
|
+
for (let t = e.startIndex; t <= e.endIndex; t++) {
|
|
515
|
+
let e = n[t];
|
|
516
|
+
e && r.push(e.index);
|
|
517
|
+
}
|
|
518
|
+
let i = {
|
|
519
|
+
id: `task-${t + 1}`,
|
|
520
|
+
index: t + 1,
|
|
521
|
+
prompt: e.prompt,
|
|
522
|
+
turnIndices: r,
|
|
523
|
+
outcome: e.hasErrors ? "error" : "ok"
|
|
524
|
+
};
|
|
525
|
+
e.durationMs && (i.durationMs = e.durationMs), e.toolCallCount && (i.tools = e.toolCallCount);
|
|
526
|
+
let a = e.filesTouched.length, o = [];
|
|
527
|
+
return a > 0 && o.push(`${a} ${a === 1 ? "file" : "files"}`), (e.insertions > 0 || e.deletions > 0) && o.push(`+${e.insertions} −${e.deletions}`), o.length && (i.stat = o.join(", ")), i;
|
|
528
|
+
}
|
|
529
|
+
function B(e) {
|
|
530
|
+
return y(e).map((t, n) => xe(t, n, e));
|
|
531
|
+
}
|
|
532
|
+
function V(e, t = {}) {
|
|
533
|
+
let n = E(e), r = x(e).map((t) => be(t, e)), i = B(e), a = R(t.scorecard, t.medians), o = {};
|
|
534
|
+
return n.length && (o.phases = n), a.length && (o.scorecardBands = a), r.length && (o.patternAnnotations = r), i.length && (o.taskGroups = i), o;
|
|
535
|
+
}
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region src/ui/transcript/usage.js
|
|
538
|
+
var H = Object.freeze({
|
|
539
|
+
input: "input",
|
|
540
|
+
output: "output",
|
|
541
|
+
cacheRead: "cache read",
|
|
542
|
+
cacheWrite: "cache write",
|
|
543
|
+
cacheWrite1h: "cache write 1h (subset)",
|
|
544
|
+
reasoning: "reasoning (subset)",
|
|
545
|
+
totalTokens: "total tokens"
|
|
546
|
+
}), U = Object.freeze({
|
|
547
|
+
input: "input",
|
|
548
|
+
output: "output",
|
|
549
|
+
cacheRead: "cache read",
|
|
550
|
+
cacheWrite: "cache write",
|
|
551
|
+
total: "total"
|
|
552
|
+
});
|
|
553
|
+
function Se(e) {
|
|
554
|
+
if (e.length === 1) return e[0];
|
|
555
|
+
let t = e.map((e) => {
|
|
556
|
+
let [t, n = "0"] = e.toLowerCase().split("e"), [r, i = ""] = t.split(".");
|
|
557
|
+
return {
|
|
558
|
+
coefficient: BigInt(r + i),
|
|
559
|
+
scale: i.length - Number(n)
|
|
560
|
+
};
|
|
561
|
+
}), n = Math.max(0, ...t.map((e) => e.scale)), r = t.reduce((e, t) => e + t.coefficient * 10n ** BigInt(n - t.scale), 0n).toString().padStart(n + 1, "0");
|
|
562
|
+
return n ? (r.slice(0, -n) + "." + r.slice(-n)).replace(/\.?0+$/, "") || "0" : r;
|
|
563
|
+
}
|
|
564
|
+
function W(e) {
|
|
565
|
+
let n = e.flatMap((e) => [e.usage, ...(e.toolCalls ?? []).map((e) => e.usage)]).filter((e) => e != null);
|
|
566
|
+
return Object.values(t).flatMap((e) => {
|
|
567
|
+
let t = n.filter((t) => t.scope === e);
|
|
568
|
+
if (!t.length) return [];
|
|
569
|
+
let r = (n, r) => Object.entries(r).map(([r, i]) => {
|
|
570
|
+
let a = t.map((e) => e[n]?.[r]).filter((e) => e != null), o = "unknown";
|
|
571
|
+
if (a.length && n === "cost" && (o = Se(a.map(String))), a.length && n === "tokens") {
|
|
572
|
+
let t = a.reduce((e, t) => e + BigInt(t), 0n);
|
|
573
|
+
if (t > BigInt(2 ** 53 - 1)) throw RangeError(`Detailed usage aggregate failed in Fairtrade adaptTranscript during ${e} ${r} summation: the known token sum exceeds the JS-safe contract bound; no trustworthy total can be displayed. Reduce the session scope or repair the producer accounting and retry.`);
|
|
574
|
+
o = String(t);
|
|
575
|
+
}
|
|
576
|
+
return {
|
|
577
|
+
label: i,
|
|
578
|
+
value: o,
|
|
579
|
+
completeness: a.length ? a.length === t.length ? "complete" : "partial" : "unknown"
|
|
580
|
+
};
|
|
581
|
+
});
|
|
582
|
+
return [{
|
|
583
|
+
scope: e,
|
|
584
|
+
ownerCount: t.length,
|
|
585
|
+
tokens: r("tokens", H),
|
|
586
|
+
cost: r("cost", U)
|
|
587
|
+
}];
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/ui/transcript/title.js
|
|
592
|
+
var Ce = 80, we = "<user_query>", Te = "</user_query>", Ee = /^\s*(?:<([a-z][a-z0-9_-]*)>[\s\S]*?<\/\1>\s*)*<user_query>/;
|
|
593
|
+
function G(e) {
|
|
594
|
+
if (!e) return "";
|
|
595
|
+
let t = Ee.exec(e);
|
|
596
|
+
if (!t) return e;
|
|
597
|
+
let n = t[0].length, r = e.indexOf(Te, n);
|
|
598
|
+
if (r === -1) return e.slice(n).trim();
|
|
599
|
+
let i = e.slice(n, r).trim(), a = e.slice(r + 13).trim();
|
|
600
|
+
return a && !a.startsWith(we) ? `${i}\n\n${a}` : i;
|
|
601
|
+
}
|
|
602
|
+
function De(e) {
|
|
603
|
+
return G(e).replace(/\s+/g, " ").trim();
|
|
604
|
+
}
|
|
605
|
+
var K = 160;
|
|
606
|
+
function Oe({ title: e, hasNormalizedEvidence: t, firstTaskPrompt: n, firstUserContent: r, id: i }) {
|
|
607
|
+
let a = String(e ?? (t ? void 0 : n ?? r) ?? i ?? "transcript");
|
|
608
|
+
if (a.length <= K) return a;
|
|
609
|
+
let o = (a.codePointAt(K - 2) ?? 0) > 65535 ? K - 2 : K - 1;
|
|
610
|
+
return a.slice(0, o).trimEnd() + "…";
|
|
611
|
+
}
|
|
612
|
+
function q(e, t = Ce) {
|
|
613
|
+
if (!e) return "";
|
|
614
|
+
let n = Ae(G(e)), { slashCommand: r, rest: i } = je(n);
|
|
615
|
+
n = i;
|
|
616
|
+
let a = n.replace(/<\/?[a-zA-Z][a-zA-Z0-9-]*[^>]*>/g, " ").replace(/[ \t\r\f\v]+/g, " ").trim();
|
|
617
|
+
return a ? Pe(Ne(Me(a).replace(/\s+/g, " ").trim()), t) : r ? Pe(r, t) : "";
|
|
618
|
+
}
|
|
619
|
+
function J(e) {
|
|
620
|
+
if (!e) return "";
|
|
621
|
+
let t = e.trim().replace(/[\\/]+$/, "");
|
|
622
|
+
if (!t) return "";
|
|
623
|
+
let n = t.split(/[\\/]/).filter(Boolean);
|
|
624
|
+
return n.length > 0 ? n[n.length - 1] : t;
|
|
625
|
+
}
|
|
626
|
+
function ke(e) {
|
|
627
|
+
let t = e.id.slice(0, 8), n = J(e.project), r = q(e.promptContent, e.limit), i;
|
|
628
|
+
i = n && r ? `${n}: ${r}` : n ? `${n}, ${t}` : r ? `${t} — ${r}` : `Session ${t}`;
|
|
629
|
+
let a = (e.promptContent ?? i).trim() || i;
|
|
630
|
+
return {
|
|
631
|
+
title: i,
|
|
632
|
+
tooltip: a
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
function Ae(e) {
|
|
636
|
+
let t = e.replace(/^\s+/, "");
|
|
637
|
+
for (;;) {
|
|
638
|
+
let e = t.match(/^<system-reminder>[\s\S]*?<\/system-reminder>\s*/i);
|
|
639
|
+
if (!e) break;
|
|
640
|
+
t = t.slice(e[0].length);
|
|
641
|
+
}
|
|
642
|
+
let n = t.match(/^```[\s\S]*?```\s*/);
|
|
643
|
+
return n && (t = t.slice(n[0].length)), t;
|
|
644
|
+
}
|
|
645
|
+
function je(e) {
|
|
646
|
+
if (!/^\s*<command-[a-z-]+>/i.test(e)) return {
|
|
647
|
+
slashCommand: null,
|
|
648
|
+
rest: e
|
|
649
|
+
};
|
|
650
|
+
let t = null, n = "", r = e.replace(/^\s+/, ""), i = /^<command-([a-z-]+)>([\s\S]*?)<\/command-\1>\s*/i;
|
|
651
|
+
for (;;) {
|
|
652
|
+
let e = r.match(i);
|
|
653
|
+
if (!e) break;
|
|
654
|
+
let a = e[1].toLowerCase(), o = e[2].trim();
|
|
655
|
+
if (a === "name" && o) {
|
|
656
|
+
let e = o.replace(/^\/+/, "");
|
|
657
|
+
e && (t = `/${e}`);
|
|
658
|
+
} else a === "args" && o && t ? t = `${t} ${o}` : a === "message" && o && (n = n ? `${n} ${o}` : o);
|
|
659
|
+
r = r.slice(e[0].length);
|
|
660
|
+
}
|
|
661
|
+
let a = r.trim(), o = n ? a ? `${n} ${a}` : n : a;
|
|
662
|
+
return {
|
|
663
|
+
slashCommand: t,
|
|
664
|
+
rest: o
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function Me(e) {
|
|
668
|
+
let t = -1, n = "";
|
|
669
|
+
for (let r = 0; r < e.length; r++) {
|
|
670
|
+
let i = e[r];
|
|
671
|
+
if (i === "\n" || i === "." || i === "?" || i === "!") {
|
|
672
|
+
t = r, n = i;
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (t === -1) return e;
|
|
677
|
+
let r = e.slice(0, t).trim();
|
|
678
|
+
return r ? n === "?" || n === "!" ? r + n : r : e.trim();
|
|
679
|
+
}
|
|
680
|
+
function Ne(e) {
|
|
681
|
+
if (!e) return e;
|
|
682
|
+
let t = e.charAt(0);
|
|
683
|
+
return t >= "a" && t <= "z" ? t.toUpperCase() + e.slice(1) : e;
|
|
684
|
+
}
|
|
685
|
+
function Pe(e, t) {
|
|
686
|
+
return e.length <= t ? e : e.slice(0, t - 1).trimEnd() + "…";
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/ui/transcript/adapter.js
|
|
690
|
+
function Y(e, t = 80) {
|
|
691
|
+
if (!e) return "";
|
|
692
|
+
let n = e.replace(/\s+/g, " ").trim();
|
|
693
|
+
return n.length > t ? n.slice(0, t - 1) + "…" : n;
|
|
694
|
+
}
|
|
695
|
+
function Fe(e) {
|
|
696
|
+
if (!e) return "";
|
|
697
|
+
let t = e.replace(/\/+$/, ""), n = t.lastIndexOf("/");
|
|
698
|
+
return n === -1 ? t : t.slice(n + 1);
|
|
699
|
+
}
|
|
700
|
+
function Ie(e) {
|
|
701
|
+
let t = e.trim().match(/\S+/g);
|
|
702
|
+
return t ? t.length : 0;
|
|
703
|
+
}
|
|
704
|
+
function Le(e) {
|
|
705
|
+
if (!e || e <= 0) return "0";
|
|
706
|
+
if (e < 1e3) return String(e);
|
|
707
|
+
let t = e / 1e3;
|
|
708
|
+
return (t >= 10 ? Math.round(t) : Math.round(t * 10) / 10) + "k";
|
|
709
|
+
}
|
|
710
|
+
function Re(e) {
|
|
711
|
+
return typeof e == "object" && e && !Array.isArray(e) ? e : void 0;
|
|
712
|
+
}
|
|
713
|
+
var X = (e, t) => Object.prototype.hasOwnProperty.call(e, t);
|
|
714
|
+
function Z(e) {
|
|
715
|
+
return !!e.sourceEntryRef || X(e, "provenance") || !!e.usage || !!e.toolCalls?.some((e) => e.callEntryRef || e.resultEntryRef || e.usage || X(e, "callProvenance") || X(e, "resultProvenance"));
|
|
716
|
+
}
|
|
717
|
+
function ze(e, t, n) {
|
|
718
|
+
if (n !== "cursor" || e !== "user") return;
|
|
719
|
+
let r = G(t);
|
|
720
|
+
return r === t ? void 0 : r;
|
|
721
|
+
}
|
|
722
|
+
function Be(e, t) {
|
|
723
|
+
let n = new Map(t.filter((e) => e.displayContent !== void 0).map((e) => [e.index, e.displayContent]));
|
|
724
|
+
return n.size === 0 ? e : e.map((e) => {
|
|
725
|
+
let t = n.get(e.turnIndices?.[0]);
|
|
726
|
+
return t === void 0 ? e : {
|
|
727
|
+
...e,
|
|
728
|
+
displayPrompt: t
|
|
729
|
+
};
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function Ve(e) {
|
|
733
|
+
return X(e, "sourceEntryRef") && e.sourceEntryRef !== "" || X(e, "provenance") || X(e, "usage") || !!e.toolCalls?.some((e) => X(e, "callEntryRef") && e.callEntryRef !== "" || X(e, "resultEntryRef") && e.resultEntryRef !== "" || [
|
|
734
|
+
"callProvenance",
|
|
735
|
+
"resultProvenance",
|
|
736
|
+
"usage",
|
|
737
|
+
"namespace"
|
|
738
|
+
].some((t) => X(e, t)));
|
|
739
|
+
}
|
|
740
|
+
function Q(e) {
|
|
741
|
+
let t = Re(e);
|
|
742
|
+
if (t?.submissionRef === "") {
|
|
743
|
+
let { submissionRef: e, ...n } = t;
|
|
744
|
+
r.parse(n);
|
|
745
|
+
} else r.parse(e);
|
|
746
|
+
}
|
|
747
|
+
function He(e) {
|
|
748
|
+
e.forEach((e, t) => {
|
|
749
|
+
try {
|
|
750
|
+
X(e, "sourceEntryRef") && e.sourceEntryRef !== "" && o.parse(e.sourceEntryRef), X(e, "provenance") && Q(e.provenance);
|
|
751
|
+
for (let t of e.toolCalls ?? []) X(t, "callEntryRef") && t.callEntryRef !== "" && o.parse(t.callEntryRef), X(t, "resultEntryRef") && t.resultEntryRef !== "" && o.parse(t.resultEntryRef), X(t, "callProvenance") && Q(t.callProvenance), X(t, "resultProvenance") && Q(t.resultProvenance);
|
|
752
|
+
} catch (e) {
|
|
753
|
+
throw Object.assign(/* @__PURE__ */ TypeError(`Fairtrade prefilterTurns refused turn at position ${t} during evidence validation: a source reference or provenance field is malformed. No turns were filtered. Correct the producer using the canonical schema and retry.`), { cause: e });
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
var Ue = /^(custom-title|agent name|session title): \S/, We = /* @__PURE__ */ new Set(["agent renamed", "session title set"]);
|
|
758
|
+
function Ge(e, t) {
|
|
759
|
+
if (t !== "claude-code" || e.role !== "system" || (e.depth ?? 0) !== 0 || (e.toolCalls?.length ?? 0) > 0) return !1;
|
|
760
|
+
let n = (e.content ?? "").trim();
|
|
761
|
+
return n === "" || n.includes("\n") ? !1 : Ue.test(n) || We.has(n);
|
|
762
|
+
}
|
|
763
|
+
function Ke(t) {
|
|
764
|
+
if (t.timestamp === void 0 || t.timestamp === null || e(t.timestamp)) return t;
|
|
765
|
+
let { timestamp: n, ...r } = t;
|
|
766
|
+
return r;
|
|
767
|
+
}
|
|
768
|
+
function qe(e) {
|
|
769
|
+
He(e);
|
|
770
|
+
let t = e.filter((e) => {
|
|
771
|
+
if (Z(e)) return !0;
|
|
772
|
+
let t = !!e.content?.trim(), n = (e.toolCalls?.length ?? 0) > 0;
|
|
773
|
+
return !(!t && !n || e.role === "system" && !n && (!e.content || e.content.trim().length < 8));
|
|
774
|
+
}), n = [];
|
|
775
|
+
for (let e of t) {
|
|
776
|
+
let t = n[n.length - 1];
|
|
777
|
+
if (t && !Z(t) && !Z(e) && t.role === e.role && t.content === e.content && t.content.trim() !== "") {
|
|
778
|
+
let r = (t.toolCalls?.length ?? 0) > 0;
|
|
779
|
+
(e.toolCalls?.length ?? 0) > 0 && !r && (n[n.length - 1] = e);
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
n.push(e);
|
|
783
|
+
}
|
|
784
|
+
return n;
|
|
785
|
+
}
|
|
786
|
+
function Je(e) {
|
|
787
|
+
if (e.role !== "assistant") return;
|
|
788
|
+
let t = i.safeParse(e.observedModel);
|
|
789
|
+
return t.success ? t.data : void 0;
|
|
790
|
+
}
|
|
791
|
+
function Ye(e, t) {
|
|
792
|
+
let n = /* @__PURE__ */ new Map(), r = typeof t == "string" && t.length > 0 ? t : void 0;
|
|
793
|
+
for (let t of e) {
|
|
794
|
+
let e = t.depth ?? 0, i = Je(t);
|
|
795
|
+
if (t.role !== "assistant") {
|
|
796
|
+
n.set(t.index, {});
|
|
797
|
+
continue;
|
|
798
|
+
}
|
|
799
|
+
if (e > 0) {
|
|
800
|
+
n.set(t.index, i === void 0 ? {} : { effectiveModel: i });
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
let a = r;
|
|
804
|
+
i !== void 0 && (r = i);
|
|
805
|
+
let o = r === void 0 ? {} : { effectiveModel: r };
|
|
806
|
+
i !== void 0 && a !== void 0 && i !== a && (o.modelChangedFrom = a), n.set(t.index, o);
|
|
807
|
+
}
|
|
808
|
+
return n;
|
|
809
|
+
}
|
|
810
|
+
function Xe(e) {
|
|
811
|
+
if (e.toolKind) return e.toolKind;
|
|
812
|
+
let t = e.name.toLowerCase();
|
|
813
|
+
return t === "read" || t === "notebookread" ? "read" : t === "edit" || t === "multiedit" || t === "notebookedit" || t === "write" ? "edit" : t === "bash" || t === "runcommand" || t === "run_command" || t === "shell" ? "execute" : t === "grep" || t === "glob" || t === "globsearch" || t === "websearch" || t === "web_search" ? "search" : t === "webfetch" || t === "web_fetch" || t === "fetch" || t === "readwebsite" ? "fetch" : t === "delete" || t === "remove" ? "delete" : t === "move" || t === "rename" ? "move" : "other";
|
|
814
|
+
}
|
|
815
|
+
function Ze(e) {
|
|
816
|
+
let t = e.name.toLowerCase();
|
|
817
|
+
if (t === "read" || t === "notebookread") return "read";
|
|
818
|
+
if (t === "edit" || t === "multiedit" || t === "notebookedit" || t === "write") return "edits";
|
|
819
|
+
if (t === "bash" || t === "runcommand" || t === "run_command" || t === "shell") return "bash";
|
|
820
|
+
if (t === "grep" || t === "glob" || t === "globsearch" || t === "websearch" || t === "web_search") return "search";
|
|
821
|
+
if (t === "webfetch" || t === "web_fetch" || t === "fetch" || t === "readwebsite") return "fetch";
|
|
822
|
+
if (t === "task" || t === "taskcreate" || t === "taskupdate" || t === "task_create" || t === "task_update" || t === "todowrite" || t === "agent") return "tasks";
|
|
823
|
+
switch (e.toolKind) {
|
|
824
|
+
case "read": return "read";
|
|
825
|
+
case "edit": return "edits";
|
|
826
|
+
case "execute": return "bash";
|
|
827
|
+
case "search": return "search";
|
|
828
|
+
case "fetch": return "fetch";
|
|
829
|
+
default: return "other";
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function Qe(e) {
|
|
833
|
+
let t = Re(c(e.arguments)), n = e.filePath ?? (t && typeof t.file_path == "string" ? t.file_path : void 0);
|
|
834
|
+
if (n) return n;
|
|
835
|
+
if (!t) return Y(e.arguments, 80);
|
|
836
|
+
if (typeof t.command == "string") return Y(t.command, 100);
|
|
837
|
+
if (typeof t.pattern == "string") {
|
|
838
|
+
let n = typeof t.path == "string" ? t.path : typeof t.glob == "string" ? t.glob : void 0, r = l(e.result), i = Array.isArray(r) ? r.length : typeof r == "string" && r.trim() !== "" ? r.split("\n").filter((e) => e.trim() !== "").length : void 0;
|
|
839
|
+
return [
|
|
840
|
+
t.pattern,
|
|
841
|
+
n,
|
|
842
|
+
i == null ? void 0 : `${i} ${i === 1 ? "match" : "matches"}`
|
|
843
|
+
].filter(Boolean).join(", ");
|
|
844
|
+
}
|
|
845
|
+
if (typeof t.url == "string") return t.url;
|
|
846
|
+
if (typeof t.query == "string") return Y(t.query, 100);
|
|
847
|
+
let r = typeof t.subagent_type == "string" ? t.subagent_type : typeof t.subagent == "string" ? t.subagent : typeof t.agent == "string" ? t.agent : void 0;
|
|
848
|
+
return r && typeof t.description == "string" ? `${r}, ${t.description}` : typeof t.description == "string" ? Y(t.description, 100) : typeof t.subject == "string" ? Y(t.subject, 100) : typeof t.prompt == "string" ? Y(t.prompt, 100) : Y(e.arguments, 80);
|
|
849
|
+
}
|
|
850
|
+
function $e(e) {
|
|
851
|
+
let t = _(e);
|
|
852
|
+
if (t) return {
|
|
853
|
+
hunks: t.spans.map((e) => ({ lines: e })),
|
|
854
|
+
adds: t.adds,
|
|
855
|
+
dels: t.dels
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
function et(e) {
|
|
859
|
+
let t = {
|
|
860
|
+
id: e.id,
|
|
861
|
+
name: e.name,
|
|
862
|
+
kind: Xe(e),
|
|
863
|
+
group: Ze(e),
|
|
864
|
+
preview: Qe(e)
|
|
865
|
+
};
|
|
866
|
+
e.namespace !== void 0 && (t.namespace = e.namespace);
|
|
867
|
+
let n = c(e.arguments);
|
|
868
|
+
n !== void 0 && (t.args = n);
|
|
869
|
+
let r = l(e.result), i = r === void 0 && e.result !== "" ? e.result : r;
|
|
870
|
+
i !== void 0 && (t.output = i);
|
|
871
|
+
let a = f(e);
|
|
872
|
+
a && (t.filePath = a), e.durationMs != null && (t.durationMs = e.durationMs), e.exitCode != null && (t.exitCode = e.exitCode), e.isError && (t.isError = !0), e.usage && (t.usage = e.usage), e.callEntryRef && (t.callEntryRef = e.callEntryRef), e.resultEntryRef && (t.resultEntryRef = e.resultEntryRef), e.callProvenance && (t.callProvenance = e.callProvenance), e.resultProvenance && (t.resultProvenance = e.resultProvenance), e.callEntryRef && !e.resultEntryRef && (t.pending = !0);
|
|
873
|
+
let o = $e(e);
|
|
874
|
+
return o && (t.diff = o.hunks, t.adds = o.adds, t.dels = o.dels), t;
|
|
875
|
+
}
|
|
876
|
+
function tt(e) {
|
|
877
|
+
let t = e.hash, n = e.message.split("\n")[0], r = {
|
|
878
|
+
hash: t,
|
|
879
|
+
shortHash: t.slice(0, 7),
|
|
880
|
+
message: n
|
|
881
|
+
};
|
|
882
|
+
"authorName" in e && (r.author = e.authorName);
|
|
883
|
+
let i = "commitTime" in e ? Number(e.commitTime) : Date.parse(e.timestamp);
|
|
884
|
+
return Number.isFinite(i) && (r.commitTime = i), "session" in e && e.session === !0 && (r.session = !0), "insertions" in e && (r.adds = e.insertions), "deletions" in e && (r.dels = e.deletions), "filesChanged" in e && (r.files = e.filesChanged), r;
|
|
885
|
+
}
|
|
886
|
+
function nt(e, t) {
|
|
887
|
+
let n = t.map((e) => ({
|
|
888
|
+
index: e.index,
|
|
889
|
+
ms: e.timestamp ? Date.parse(e.timestamp) : NaN
|
|
890
|
+
})).filter((e) => Number.isFinite(e.ms)).sort((e, t) => e.ms - t.ms);
|
|
891
|
+
if (n.length !== 0) for (let t of e) {
|
|
892
|
+
if (typeof t.commitTime != "number") continue;
|
|
893
|
+
let e = n[0].index;
|
|
894
|
+
for (let r of n) if (r.ms <= t.commitTime) e = r.index;
|
|
895
|
+
else break;
|
|
896
|
+
t.turn = e;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
function rt(e) {
|
|
900
|
+
let t = e.gitContext, n = e.gitBranch ?? t?.branch ?? void 0, r = e.gitRemote ?? t?.remote ?? void 0, i = t?.user, a = Array.isArray(t?.commits) ? t.commits : [], o = [], s = 0, c = 0, l = 0;
|
|
901
|
+
for (let e of a) o.push(tt(e)), "filesChanged" in e && (s += e.filesChanged), "insertions" in e && (c += e.insertions), "deletions" in e && (l += e.deletions);
|
|
902
|
+
let u = {};
|
|
903
|
+
return n && (u.branch = n), r && (u.remote = r), i && (u.author = i), o.length && (u.commits = o), s > 0 && (u.filesChanged = s), c > 0 && (u.insertions = c), l > 0 && (u.deletions = l), Object.keys(u).length > 0 ? u : void 0;
|
|
904
|
+
}
|
|
905
|
+
function it(t, n) {
|
|
906
|
+
let r = {
|
|
907
|
+
id: t.id,
|
|
908
|
+
harness: t.harness,
|
|
909
|
+
startTime: e(t.startTime) ? t.startTime : "",
|
|
910
|
+
endTime: e(t.endTime) ? t.endTime : "",
|
|
911
|
+
durationMins: t.durationMins,
|
|
912
|
+
totalTokens: t.totalTokens,
|
|
913
|
+
tokensIn: t.tokensIn,
|
|
914
|
+
tokensOut: t.tokensOut,
|
|
915
|
+
turnCount: t.turnCount,
|
|
916
|
+
toolCallCount: t.toolCallCount
|
|
917
|
+
};
|
|
918
|
+
t.project && (r.project = t.project), t.model && (r.model = t.model), t.inputSubmissionCount !== void 0 && (r.inputSubmissionCount = t.inputSubmissionCount), t.purpose && (r.purpose = t.purpose), t.rootSessionId && (r.rootSessionId = t.rootSessionId), pt(t) && (r.hasNormalizedEvidence = !0);
|
|
919
|
+
let i = t.workingDirectory ?? t.gitContext?.workingDirectory;
|
|
920
|
+
return i && (r.workingDirectory = i), t.outcome && (r.outcome = t.outcome), t.scorecard !== void 0 && (r.scorecard = t.scorecard), n && (r.git = n), r;
|
|
921
|
+
}
|
|
922
|
+
function at(e) {
|
|
923
|
+
let t = [];
|
|
924
|
+
for (let n of e) {
|
|
925
|
+
if (n.targetEntryIndex == null) continue;
|
|
926
|
+
let e = {
|
|
927
|
+
id: n.id,
|
|
928
|
+
kind: n.typeName,
|
|
929
|
+
turn: n.targetEntryIndex,
|
|
930
|
+
label: n.value || n.typeName
|
|
931
|
+
};
|
|
932
|
+
n.isPrimary && (e.isPrimary = !0), t.push(e);
|
|
933
|
+
}
|
|
934
|
+
return t;
|
|
935
|
+
}
|
|
936
|
+
function ot(e, t) {
|
|
937
|
+
let n = {};
|
|
938
|
+
for (let t of e) {
|
|
939
|
+
let e = n[t.turn] ?? [];
|
|
940
|
+
e.push(t), n[t.turn] = e;
|
|
941
|
+
}
|
|
942
|
+
for (let e of t) {
|
|
943
|
+
let t = n[e.turn] ?? [];
|
|
944
|
+
t.push(e), n[e.turn] = t;
|
|
945
|
+
}
|
|
946
|
+
return n;
|
|
947
|
+
}
|
|
948
|
+
function st(e) {
|
|
949
|
+
let t = [];
|
|
950
|
+
for (let n of e) for (let e of n.toolCalls) {
|
|
951
|
+
if (!e.diff) continue;
|
|
952
|
+
let r = e.filePath ?? "(unknown)", i = {
|
|
953
|
+
path: r,
|
|
954
|
+
leaf: Fe(r) || r,
|
|
955
|
+
adds: e.adds ?? 0,
|
|
956
|
+
dels: e.dels ?? 0,
|
|
957
|
+
hunks: e.diff,
|
|
958
|
+
turn: n.index,
|
|
959
|
+
toolCallId: e.id
|
|
960
|
+
};
|
|
961
|
+
t.push(i);
|
|
962
|
+
}
|
|
963
|
+
return t;
|
|
964
|
+
}
|
|
965
|
+
function ct(e) {
|
|
966
|
+
let t = /* @__PURE__ */ new Map();
|
|
967
|
+
for (let n of e) for (let e of n.toolCalls) {
|
|
968
|
+
let r = e.filePath;
|
|
969
|
+
if (!r) continue;
|
|
970
|
+
let i = t.get(r);
|
|
971
|
+
i || (i = {
|
|
972
|
+
path: r,
|
|
973
|
+
leaf: Fe(r) || r,
|
|
974
|
+
reads: 0,
|
|
975
|
+
writes: 0,
|
|
976
|
+
edits: 0,
|
|
977
|
+
deletes: 0,
|
|
978
|
+
adds: 0,
|
|
979
|
+
dels: 0,
|
|
980
|
+
edited: !1,
|
|
981
|
+
turn: n.index
|
|
982
|
+
}, t.set(r, i));
|
|
983
|
+
let a = e.name.toLowerCase();
|
|
984
|
+
a === "read" || a === "notebookread" ? i.reads++ : a === "edit" || a === "multiedit" || a === "notebookedit" ? (i.edits++, i.adds += e.adds ?? 0, i.dels += e.dels ?? 0) : a === "write" ? (i.writes++, i.adds += e.adds ?? 0) : (a === "delete" || a === "remove") && i.deletes++;
|
|
985
|
+
}
|
|
986
|
+
let n = Array.from(t.values());
|
|
987
|
+
for (let e of n) e.edited = e.writes + e.edits > 0;
|
|
988
|
+
return n;
|
|
989
|
+
}
|
|
990
|
+
function lt(e, t, n) {
|
|
991
|
+
let r = [], i = e.find((e) => e.role === "user" && e.content.trim() !== "");
|
|
992
|
+
i && r.push({
|
|
993
|
+
id: "hl-request",
|
|
994
|
+
kind: "request",
|
|
995
|
+
turn: i.index,
|
|
996
|
+
icon: "request",
|
|
997
|
+
title: "initial request",
|
|
998
|
+
sub: Y(i.displayContent ?? i.content, 160)
|
|
999
|
+
}), t.slice(1).forEach((t, n) => {
|
|
1000
|
+
let i = e.find((e) => e.index === t.from), a = {
|
|
1001
|
+
id: `hl-phase-${n}`,
|
|
1002
|
+
kind: "phase",
|
|
1003
|
+
turn: t.from,
|
|
1004
|
+
icon: "phase",
|
|
1005
|
+
title: `${t.label} begins`,
|
|
1006
|
+
tag: t.label
|
|
1007
|
+
}, o = Y(i ? i.displayContent ?? i.content : "", 200);
|
|
1008
|
+
o && (a.sub = o), r.push(a);
|
|
1009
|
+
});
|
|
1010
|
+
let a = 0;
|
|
1011
|
+
for (let t of e) {
|
|
1012
|
+
if (a >= 3) break;
|
|
1013
|
+
let e = t.toolCalls.find((e) => e.isError);
|
|
1014
|
+
if (!t.isError && !e) continue;
|
|
1015
|
+
let n = {
|
|
1016
|
+
id: `hl-error-${t.index}`,
|
|
1017
|
+
kind: "error",
|
|
1018
|
+
turn: t.index,
|
|
1019
|
+
icon: "error",
|
|
1020
|
+
title: e ? `${e.name} failed` : "Error",
|
|
1021
|
+
err: !0
|
|
1022
|
+
}, i = Y(e && typeof e.output == "string" ? e.output : t.content, 200);
|
|
1023
|
+
i && (n.sub = i), r.push(n), a++;
|
|
1024
|
+
}
|
|
1025
|
+
let o = e[e.length - 1], s = o ? o.index : 0;
|
|
1026
|
+
for (let e of n?.commits ?? []) r.push({
|
|
1027
|
+
id: `hl-commit-${e.hash}`,
|
|
1028
|
+
kind: "checkpoint",
|
|
1029
|
+
turn: s,
|
|
1030
|
+
icon: "commit",
|
|
1031
|
+
title: e.shortHash || e.hash || "checkpoint",
|
|
1032
|
+
sub: e.message
|
|
1033
|
+
});
|
|
1034
|
+
let c = [...e].reverse().find((e) => e.role === "assistant" && e.depth === 0 && e.content.trim() !== "");
|
|
1035
|
+
if (c) {
|
|
1036
|
+
let e = {
|
|
1037
|
+
id: "hl-final",
|
|
1038
|
+
kind: "final",
|
|
1039
|
+
turn: c.index,
|
|
1040
|
+
icon: "final",
|
|
1041
|
+
title: "final response",
|
|
1042
|
+
sub: Y(c.content, 200)
|
|
1043
|
+
};
|
|
1044
|
+
c.tokens && (e.tokens = Le(c.tokens.in + c.tokens.out)), r.push(e);
|
|
1045
|
+
}
|
|
1046
|
+
return r;
|
|
1047
|
+
}
|
|
1048
|
+
function ut(e) {
|
|
1049
|
+
if (e === "error") return "errors";
|
|
1050
|
+
if (e === "retry") return "retries";
|
|
1051
|
+
if (e === "revert") return "re-edit";
|
|
1052
|
+
if (e === "subagent") return "subagent";
|
|
1053
|
+
}
|
|
1054
|
+
function dt(e, t) {
|
|
1055
|
+
let n = {
|
|
1056
|
+
edits: 0,
|
|
1057
|
+
bash: 0,
|
|
1058
|
+
read: 0,
|
|
1059
|
+
search: 0,
|
|
1060
|
+
fetch: 0,
|
|
1061
|
+
tasks: 0,
|
|
1062
|
+
other: 0
|
|
1063
|
+
};
|
|
1064
|
+
for (let t of e) for (let e of t.toolCalls) n[e.group]++;
|
|
1065
|
+
let r = {};
|
|
1066
|
+
for (let e of Object.keys(t)) {
|
|
1067
|
+
let n = t[e] ?? [], i = /* @__PURE__ */ new Set();
|
|
1068
|
+
for (let e of n) {
|
|
1069
|
+
let t = ut(e.kind);
|
|
1070
|
+
t && i.add(t);
|
|
1071
|
+
}
|
|
1072
|
+
for (let e of i) r[e] = (r[e] ?? 0) + 1;
|
|
1073
|
+
}
|
|
1074
|
+
return {
|
|
1075
|
+
toolGroupCounts: n,
|
|
1076
|
+
annotationsByTurn: t,
|
|
1077
|
+
tags: Object.keys(r),
|
|
1078
|
+
tagCounts: r,
|
|
1079
|
+
totalTurns: e.length
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
function ft(e, t, r, i) {
|
|
1083
|
+
let a = pt(e);
|
|
1084
|
+
if (a) try {
|
|
1085
|
+
e = {
|
|
1086
|
+
...n(e),
|
|
1087
|
+
...e.gitContext === void 0 ? {} : { gitContext: e.gitContext }
|
|
1088
|
+
};
|
|
1089
|
+
} catch (e) {
|
|
1090
|
+
throw Object.assign(/* @__PURE__ */ TypeError(`Fairtrade adaptTranscript refused the durable payload during main/earlier evidence validation: ${e instanceof Error ? e.message : "canonical validation failed"}. No transcript was cooked. Correct the producer using the canonical schema and retry.`), { cause: e });
|
|
1091
|
+
}
|
|
1092
|
+
let o = e.turns ?? [], { turns: s, toolCallsById: c, analytics: l, annotationsByTurn: u, filteredTurns: d } = $(e, o, e.nativeMetadata, "main", t, r, i?.visibleTurnIndices), f = rt(e);
|
|
1093
|
+
f?.commits && nt(f.commits, s);
|
|
1094
|
+
let p = l.phases ?? [], m = {
|
|
1095
|
+
session: it(e, f),
|
|
1096
|
+
turns: s,
|
|
1097
|
+
toolCallsById: c,
|
|
1098
|
+
diffs: st(s),
|
|
1099
|
+
files: ct(s),
|
|
1100
|
+
tasks: Be(l.taskGroups ?? B(d), s),
|
|
1101
|
+
highlights: lt(s, p, f),
|
|
1102
|
+
filterIndex: dt(s, u),
|
|
1103
|
+
analytics: l
|
|
1104
|
+
};
|
|
1105
|
+
return e.nativeMetadata && (m.nativeMetadata = e.nativeMetadata), a && (m.usageScopes = W(o)), m.relationships = mt(e.relationships ?? [], i?.relationshipNavigation), m.earlierHistory = (e.earlierHistory ?? []).map((t, n) => {
|
|
1106
|
+
let r = `earlier-${n}`, i = $(e, t.turns, t.nativeMetadata, r);
|
|
1107
|
+
return {
|
|
1108
|
+
id: r,
|
|
1109
|
+
state: t.state,
|
|
1110
|
+
explanation: "ownership of this earlier history is uncertain. it is retained here, separate from current turns and input submissions.",
|
|
1111
|
+
turns: i.turns,
|
|
1112
|
+
nativeMetadata: t.nativeMetadata,
|
|
1113
|
+
usageScopes: W(t.turns)
|
|
1114
|
+
};
|
|
1115
|
+
}), m;
|
|
1116
|
+
}
|
|
1117
|
+
function pt(e) {
|
|
1118
|
+
return e.harness === "pi" || [
|
|
1119
|
+
"nativeMetadata",
|
|
1120
|
+
"inputSubmissionCount",
|
|
1121
|
+
"rootSessionId",
|
|
1122
|
+
"purpose",
|
|
1123
|
+
"relationships",
|
|
1124
|
+
"earlierHistory"
|
|
1125
|
+
].some((t) => X(e, t)) || !!e.turns?.some(Ve);
|
|
1126
|
+
}
|
|
1127
|
+
function mt(e, t) {
|
|
1128
|
+
let n;
|
|
1129
|
+
try {
|
|
1130
|
+
n = a.array().parse(t === void 0 ? [] : t);
|
|
1131
|
+
} catch (e) {
|
|
1132
|
+
throw Object.assign(/* @__PURE__ */ TypeError(`Fairtrade adaptTranscript refused relationshipNavigation during read-metadata validation: ${e instanceof Error ? e.message : "canonical validation failed"}. No source links were cooked. Return schema-valid authorized read metadata separately from the durable payload and retry.`), { cause: e });
|
|
1133
|
+
}
|
|
1134
|
+
if (new Set(n.map((e) => e.kind)).size !== n.length) throw TypeError("Fairtrade adaptTranscript refused relationship navigation during cooking: duplicate relationship kinds make the authorized target ambiguous. No links were produced. Return one schema-valid read result per relationship kind and retry.");
|
|
1135
|
+
let r = e.find((e) => e.kind === "context_from"), i = e.find((e) => e.kind === "started_by"), o = [r, i].filter((e) => e !== void 0).filter((e) => e.targetState !== "explicit_none").map((e) => {
|
|
1136
|
+
let t = n.find((t) => t.kind === e.kind), r = e.targetState === "target_known" || e.targetState === "target_known_retained", i = t && (t.status === "resolved" || t.status === "general_link_only"), a = Number(!!t?.localId) + Number(!!t?.transcriptId), o = r && i && a === 1 && (!t.localId || t.localId === e.targetLocalId), s = {
|
|
1137
|
+
kind: e.kind,
|
|
1138
|
+
label: e.kind === "context_from" ? "context inherited from" : "started by",
|
|
1139
|
+
statusLabel: e.targetState === "conflicting_current_native_evidence" || t?.status === "conflicting" ? "conflicting source evidence" : !r || t?.status === "unknown" ? "unknown source" : t?.status === "inaccessible" ? "source inaccessible" : "source unavailable"
|
|
1140
|
+
};
|
|
1141
|
+
if (o && t) {
|
|
1142
|
+
s.statusLabel = "current session";
|
|
1143
|
+
let n = e.anchor, r = t.anchor, i = e.kind === "context_from" && t.status === "resolved" && n && r && n.kind !== "general_source_session" && n.kind === r.kind && n.sourceEntryRef === r.sourceEntryRef && n.sourceRevisionRef === r.sourceRevisionRef;
|
|
1144
|
+
s.navigation = {
|
|
1145
|
+
kind: t.kind,
|
|
1146
|
+
status: i ? "resolved" : "general_link_only",
|
|
1147
|
+
...t.localId ? { localId: t.localId } : { transcriptId: t.transcriptId },
|
|
1148
|
+
...i ? { anchor: r } : {}
|
|
1149
|
+
}, e.kind === "context_from" && (s.note = i ? "opens the current source at the recorded branch point. captured child history stays unchanged." : "opens the current source. the earlier source state is not verified; captured child history stays unchanged.");
|
|
1150
|
+
}
|
|
1151
|
+
return s;
|
|
1152
|
+
});
|
|
1153
|
+
return r?.targetLocalId && r.targetLocalId === i?.targetLocalId && o.length === 2 && o[0].statusLabel === o[1].statusLabel && o[0].navigation?.localId === o[1].navigation?.localId && o[0].navigation?.transcriptId === o[1].navigation?.transcriptId ? (o[0].label = "context inherited from and started by", [o[0]]) : o;
|
|
1154
|
+
}
|
|
1155
|
+
function $(e, t, n, r, i, a, o) {
|
|
1156
|
+
let s = Ye(t, e.model), c = (e.harness === "pi" ? t : qe(t)).filter((t) => !Ge(t, e.harness)).map(Ke), l = o === void 0 ? null : new Set(o), u = l === null ? c : c.filter((e) => l.has(e.index)), d = b(u), f = e.harness, p = a ?? V(u, { scorecard: e.scorecard ?? void 0 }), m = ot(p.patternAnnotations ?? [], at(i ?? [])), h = -1;
|
|
1157
|
+
for (let e = 0; e < u.length; e++) {
|
|
1158
|
+
let t = u[e];
|
|
1159
|
+
t.role === "assistant" && (t.depth ?? 0) === 0 && t.content?.trim() && (h = e);
|
|
1160
|
+
}
|
|
1161
|
+
let g = /* @__PURE__ */ new Map(), _ = [];
|
|
1162
|
+
for (let e = 0; e < u.length; e++) {
|
|
1163
|
+
let t = u[e], i = (t.toolCalls ?? []).map(et);
|
|
1164
|
+
for (let e of i) {
|
|
1165
|
+
e.partition = r;
|
|
1166
|
+
let i = n?.filter((n) => n.attachment?.turnIndex === t.index && n.attachment?.toolCallId === e.id);
|
|
1167
|
+
i?.length && (e.nativeMetadata = i);
|
|
1168
|
+
}
|
|
1169
|
+
for (let e of i) g.set(e.id, e);
|
|
1170
|
+
let a = t.content ?? "", o;
|
|
1171
|
+
if (t.entryType === "thinking" && (Z(t) || a.trim() !== "")) o = {
|
|
1172
|
+
text: a,
|
|
1173
|
+
words: Ie(a)
|
|
1174
|
+
}, a = "";
|
|
1175
|
+
else if (!Z(t)) {
|
|
1176
|
+
let e = a.match(/^\s*<thinking>([\s\S]*?)<\/thinking>\s*/);
|
|
1177
|
+
if (e) {
|
|
1178
|
+
let t = e[1].trim();
|
|
1179
|
+
t !== "" && (o = {
|
|
1180
|
+
text: t,
|
|
1181
|
+
words: Ie(t)
|
|
1182
|
+
}, a = a.slice(e[0].length));
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
let c = t.depth ?? 0, l = t.entryType === "error" || i.some((e) => e.isError), p = {
|
|
1186
|
+
index: t.index,
|
|
1187
|
+
identity: `${r}:${t.sourceEntryRef || t.index}`,
|
|
1188
|
+
partition: r,
|
|
1189
|
+
role: t.role,
|
|
1190
|
+
label: d[e] ?? String(e + 1),
|
|
1191
|
+
content: a,
|
|
1192
|
+
depth: c,
|
|
1193
|
+
toolCalls: i,
|
|
1194
|
+
annotations: m[t.index] ?? []
|
|
1195
|
+
};
|
|
1196
|
+
c === 0 && t.role === "assistant" && (p.provider = f), t.agentName && (p.agentName = t.agentName), o && (p.thinking = o);
|
|
1197
|
+
let v = ze(t.role, a, f);
|
|
1198
|
+
v !== void 0 && (p.displayContent = v), t.usage && (p.usage = t.usage), t.sourceEntryRef && (p.sourceEntryRef = t.sourceEntryRef), t.provenance && (p.provenance = t.provenance), t.entryType && (p.entryType = t.entryType), t.stopReason !== void 0 && t.stopReason !== null && (p.stopReason = t.stopReason), l && (p.isError = !0), e === h && (p.isFinal = !0), !t.usage && (t.tokensIn != null || t.tokensOut != null) && (p.tokens = {
|
|
1199
|
+
in: t.tokensIn ?? 0,
|
|
1200
|
+
out: t.tokensOut ?? 0
|
|
1201
|
+
}), t.timestamp && (p.timestamp = t.timestamp);
|
|
1202
|
+
let y = s.get(t.index);
|
|
1203
|
+
y?.effectiveModel !== void 0 && (p.effectiveModel = y.effectiveModel), y?.modelChangedFrom !== void 0 && (p.modelChangedFrom = y.modelChangedFrom), _.push(p);
|
|
1204
|
+
}
|
|
1205
|
+
return {
|
|
1206
|
+
turns: _,
|
|
1207
|
+
toolCallsById: g,
|
|
1208
|
+
analytics: p,
|
|
1209
|
+
annotationsByTurn: m,
|
|
1210
|
+
filteredTurns: u
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
//#endregion
|
|
1214
|
+
export { h as S, B as _, ke as a, E as b, Oe as c, H as d, x as f, ye as g, V as h, De as i, G as l, ne as m, Ge as n, J as o, R as p, qe as r, q as s, ft as t, U as u, y as v, S as x, b as y };
|