@cesarus777/opencode-cgp 0.4.0 → 0.4.2
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/CHANGELOG.md +37 -0
- package/README.md +19 -11
- package/dist/cli.js +906 -237
- package/dist/core.js +88 -59
- package/dist/index.js +710 -166
- package/dist/tui.js +1416 -702
- package/dist/types/archive.d.ts +40 -0
- package/dist/types/core.d.ts +1 -1
- package/dist/types/dashboard/controller.d.ts +2 -0
- package/dist/types/dashboard/inventory.d.ts +1 -1
- package/dist/types/dashboard/terminal.d.ts +8 -0
- package/dist/types/dashboard/terminalview.d.ts +9 -2
- package/dist/types/dashboard/view.d.ts +4 -1
- package/dist/types/history.d.ts +39 -2
- package/dist/types/historyclient.d.ts +15 -0
- package/dist/types/historyserver.d.ts +2 -1
- package/dist/types/modelanalytics.d.ts +11 -0
- package/dist/types/modelanalyticsserver.d.ts +2 -1
- package/dist/types/tui/charts.d.ts +2 -3
- package/dist/types/tui/compactformat.d.ts +12 -3
- package/dist/types/tui/historystate.d.ts +49 -0
- package/dist/types/tui/inventory.d.ts +12 -0
- package/dist/types/tui/panelcontrols.d.ts +8 -0
- package/dist/types/tui/panelformat.d.ts +12 -0
- package/dist/types/tui/panelview.d.ts +22 -0
- package/dist/types/tui/quantity.d.ts +1 -0
- package/dist/types/tui/sidebar.d.ts +0 -5
- package/dist/types/tui/state.d.ts +3 -1
- package/dist/types/tui/statusformat.d.ts +19 -0
- package/package.json +2 -1
package/dist/core.js
CHANGED
|
@@ -173,6 +173,11 @@ function reconcile(a, b) {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
function analyzeModelRequests(records, options) {
|
|
176
|
+
const accumulator = createModelAccumulator(options);
|
|
177
|
+
accumulator.append(records);
|
|
178
|
+
return accumulator.result();
|
|
179
|
+
}
|
|
180
|
+
function createModelAccumulator(options) {
|
|
176
181
|
const maxRequests = options.maxRequests ?? 1e5;
|
|
177
182
|
if (!Number.isSafeInteger(maxRequests) || maxRequests < 1 || maxRequests > 1e6)
|
|
178
183
|
throw new Error("maxRequests must be an integer from 1 to 1000000");
|
|
@@ -183,7 +188,7 @@ function analyzeModelRequests(records, options) {
|
|
|
183
188
|
throw new Error("Invalid analytics timestamp");
|
|
184
189
|
if (options.from !== undefined && options.to !== undefined && options.from > options.to)
|
|
185
190
|
throw new Error("--from must precede --to");
|
|
186
|
-
const
|
|
191
|
+
const counters = {
|
|
187
192
|
source: "retained-request-records",
|
|
188
193
|
scannedRecords: 0,
|
|
189
194
|
unscannedRecords: 0,
|
|
@@ -197,74 +202,98 @@ function analyzeModelRequests(records, options) {
|
|
|
197
202
|
partial: false
|
|
198
203
|
};
|
|
199
204
|
const requests = new Map;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
if (record.type !== "request")
|
|
207
|
-
continue;
|
|
208
|
-
const fact = requestFact(record);
|
|
209
|
-
if (!fact) {
|
|
210
|
-
coverage.missingIdentityRecords++;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
fact.location = options.location;
|
|
214
|
-
const key = JSON.stringify([
|
|
215
|
-
fact.sessionId,
|
|
216
|
-
fact.requestId,
|
|
217
|
-
fact.startedAt
|
|
218
|
-
]);
|
|
219
|
-
const previous = requests.get(key);
|
|
220
|
-
if (previous) {
|
|
221
|
-
coverage.duplicateRecords++;
|
|
222
|
-
const merged = reconcile(previous.fact, fact);
|
|
223
|
-
if (!merged)
|
|
224
|
-
previous.conflict = true;
|
|
225
|
-
else
|
|
226
|
-
previous.fact = merged;
|
|
227
|
-
} else {
|
|
228
|
-
if (requests.size === maxRequests) {
|
|
229
|
-
coverage.scannedRecords--;
|
|
230
|
-
coverage.unscannedRecords = records.length - coverage.scannedRecords;
|
|
205
|
+
let totalRecords = 0, stopped = false;
|
|
206
|
+
function append(records) {
|
|
207
|
+
totalRecords += records.length;
|
|
208
|
+
for (const record of records) {
|
|
209
|
+
if (stopped)
|
|
231
210
|
break;
|
|
211
|
+
counters.scannedRecords++;
|
|
212
|
+
if (record.type === "gap") {
|
|
213
|
+
counters.gapRecords++;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (record.type !== "request")
|
|
217
|
+
continue;
|
|
218
|
+
const fact = requestFact(record);
|
|
219
|
+
if (!fact) {
|
|
220
|
+
counters.missingIdentityRecords++;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
fact.location = options.location;
|
|
224
|
+
const key = JSON.stringify([
|
|
225
|
+
fact.sessionId,
|
|
226
|
+
fact.requestId,
|
|
227
|
+
fact.startedAt
|
|
228
|
+
]);
|
|
229
|
+
const previous = requests.get(key);
|
|
230
|
+
if (previous) {
|
|
231
|
+
counters.duplicateRecords++;
|
|
232
|
+
const merged = reconcile(previous.fact, fact);
|
|
233
|
+
if (!merged)
|
|
234
|
+
previous.conflict = true;
|
|
235
|
+
else
|
|
236
|
+
previous.fact = merged;
|
|
237
|
+
} else {
|
|
238
|
+
if (requests.size === maxRequests) {
|
|
239
|
+
counters.scannedRecords--;
|
|
240
|
+
stopped = true;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
requests.set(key, { fact, conflict: false });
|
|
232
244
|
}
|
|
233
|
-
requests.set(key, { fact, conflict: false });
|
|
234
245
|
}
|
|
235
246
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
function* steps() {
|
|
248
|
+
const coverage = {
|
|
249
|
+
...counters,
|
|
250
|
+
unscannedRecords: totalRecords - counters.scannedRecords
|
|
251
|
+
};
|
|
252
|
+
const accepted = [];
|
|
253
|
+
for (const { fact: r, conflict } of requests.values()) {
|
|
254
|
+
yield;
|
|
255
|
+
if (conflict) {
|
|
256
|
+
coverage.conflictingRequests++;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (r.completedAt === undefined) {
|
|
260
|
+
coverage.incompleteRequests++;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const duration = r.completedAt - r.startedAt;
|
|
264
|
+
if (!nonnegative(r.completedAt) || !Number.isFinite(duration) || duration <= 0) {
|
|
265
|
+
coverage.invalidTimingRequests++;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (options.from !== undefined && r.completedAt < options.from || options.to !== undefined && r.completedAt >= options.to || options.model !== undefined && r.model !== options.model || options.agent !== undefined && r.agent !== options.agent)
|
|
269
|
+
continue;
|
|
270
|
+
accepted.push({ ...r, completedAt: r.completedAt });
|
|
250
271
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
272
|
+
const models = yield* summarizeModelRequestSteps(accepted);
|
|
273
|
+
coverage.partial = coverage.unscannedRecords > 0 || coverage.conflictingRequests > 0 || coverage.missingIdentityRecords > 0 || coverage.incompleteRequests > 0 || coverage.invalidTimingRequests > 0 || coverage.gapRecords > 0 || models.some((s) => s.partialRequests > 0 || s.legacyAttributionRequests > 0 || s.excludedTpsRequests > 0 || s.excludedTtftRequests > 0 || !s.model);
|
|
274
|
+
return {
|
|
275
|
+
schemaVersion: 1,
|
|
276
|
+
location: options.location,
|
|
277
|
+
models,
|
|
278
|
+
coverage,
|
|
279
|
+
requests: accepted
|
|
280
|
+
};
|
|
254
281
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
requests: accepted
|
|
263
|
-
};
|
|
282
|
+
return { append, steps, result: () => finishSteps(steps()) };
|
|
283
|
+
}
|
|
284
|
+
function finishSteps(steps) {
|
|
285
|
+
let step = steps.next();
|
|
286
|
+
while (!step.done)
|
|
287
|
+
step = steps.next();
|
|
288
|
+
return step.value;
|
|
264
289
|
}
|
|
265
290
|
function summarizeModelRequests(requests) {
|
|
291
|
+
return finishSteps(summarizeModelRequestSteps(requests));
|
|
292
|
+
}
|
|
293
|
+
function* summarizeModelRequestSteps(requests) {
|
|
266
294
|
const groups = new Map;
|
|
267
295
|
for (const r of requests) {
|
|
296
|
+
yield;
|
|
268
297
|
const duration = r.completedAt - r.startedAt;
|
|
269
298
|
let group = groups.get(r.model);
|
|
270
299
|
if (!group) {
|