@atolis-hq/wake 0.4.88 → 0.4.89
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/src/bootstrap/analytics-reports.js +2 -1
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/execution/application/run-reports.d.ts +4 -1
- package/dist/src/execution/application/run-reports.js +76 -9
- package/dist/src/kernel/contracts/reports.d.ts +20 -1
- package/dist/src/surfaces/api/contracts/observability.d.ts +1 -1
- package/dist/src/surfaces/web-assets/assets/index-B0jIss24.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-D4-8tZ5f.js +0 -1192
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRunBreakdownReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
|
|
1
|
+
import { createRunBreakdownReport, createRunDurationReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
|
|
2
2
|
import { reportWindow } from '../kernel/index.js';
|
|
3
3
|
import { createWorkThroughputReport, queryWorkCompletionSummary } from '../orchestration/index.js';
|
|
4
4
|
import { sampledMeta } from './surface-api-metadata.js';
|
|
@@ -8,6 +8,7 @@ export function createAnalyticsReports(journal, now) {
|
|
|
8
8
|
createRunBreakdownReport(journal),
|
|
9
9
|
createRunUsageReport(journal),
|
|
10
10
|
createWorkThroughputReport(journal),
|
|
11
|
+
createRunDurationReport(journal),
|
|
11
12
|
];
|
|
12
13
|
return {
|
|
13
14
|
catalogue: () => definitions.map(({ id, title }) => ({ id, title })),
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.89";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type EventJournal } from '@atolis-hq/eventing';
|
|
2
|
-
import { type BreakdownReport, type ReportDefinition, type ReportQuery, type TimeSeriesReport, type ValueOf } from '../../kernel/index.js';
|
|
2
|
+
import { type BreakdownReport, type DurationReport, type ReportDefinition, type ReportQuery, type TimeSeriesReport, type ValueOf } from '../../kernel/index.js';
|
|
3
3
|
import type { RunView } from '../contracts/views.js';
|
|
4
4
|
export declare const RunReportId: {
|
|
5
|
+
readonly Duration: "run-duration";
|
|
5
6
|
readonly Outcomes: "run-outcomes-over-time";
|
|
6
7
|
readonly Usage: "token-and-cost-usage";
|
|
7
8
|
readonly Breakdown: "run-breakdowns-by-dimension";
|
|
8
9
|
};
|
|
10
|
+
export declare function createRunDurationReport(journal: EventJournal): ReportDefinition;
|
|
9
11
|
export declare const RunUsageMeasure: {
|
|
10
12
|
readonly Tokens: "total-tokens";
|
|
11
13
|
readonly CostUsd: "total-cost-usd";
|
|
@@ -41,6 +43,7 @@ export interface RunSummary {
|
|
|
41
43
|
export declare function runReportOutcome(run: RunView): RunReportOutcome;
|
|
42
44
|
export declare function createRunOutcomesReport(journal: EventJournal): ReportDefinition;
|
|
43
45
|
export declare function queryRunAnalytics(journal: EventJournal, query: ReportQuery): Promise<{
|
|
46
|
+
duration: DurationReport;
|
|
44
47
|
report: TimeSeriesReport;
|
|
45
48
|
breakdown: BreakdownReport;
|
|
46
49
|
usage: TimeSeriesReport;
|
|
@@ -6,10 +6,18 @@ import { agentTokenUsage } from '../contracts/runner.js';
|
|
|
6
6
|
import { RunStatus } from '../contracts/vocabulary.js';
|
|
7
7
|
import { foldRunEvent } from '../domain/run.js';
|
|
8
8
|
export const RunReportId = defineClosedVocabulary({
|
|
9
|
+
Duration: 'run-duration',
|
|
9
10
|
Outcomes: 'run-outcomes-over-time',
|
|
10
11
|
Usage: 'token-and-cost-usage',
|
|
11
12
|
Breakdown: 'run-breakdowns-by-dimension',
|
|
12
13
|
});
|
|
14
|
+
const durationDescriptor = { id: RunReportId.Duration, title: 'Run duration' };
|
|
15
|
+
export function createRunDurationReport(journal) {
|
|
16
|
+
return {
|
|
17
|
+
...durationDescriptor,
|
|
18
|
+
query: async (query) => (await queryRunAnalytics(journal, query)).duration,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
13
21
|
export const RunUsageMeasure = defineClosedVocabulary({
|
|
14
22
|
Tokens: 'total-tokens',
|
|
15
23
|
CostUsd: 'total-cost-usd',
|
|
@@ -86,22 +94,20 @@ export function createRunOutcomesReport(journal) {
|
|
|
86
94
|
};
|
|
87
95
|
}
|
|
88
96
|
export async function queryRunAnalytics(journal, query) {
|
|
89
|
-
const grouped = await readRuns(journal, query);
|
|
90
97
|
const from = Date.parse(query.window.from);
|
|
91
98
|
const to = Date.parse(query.window.to);
|
|
92
99
|
const first = Math.floor(from / query.window.bucketMs) * query.window.bucketMs;
|
|
93
|
-
const zero = () => Object.fromEntries(series.map(({ id }) => [id, 0]));
|
|
94
100
|
const buckets = outcomeBuckets(first, to, query.window.bucketMs);
|
|
95
101
|
const usageBuckets = buckets.map(({ from, to }) => ({
|
|
96
102
|
from,
|
|
97
103
|
to,
|
|
98
104
|
values: { [RunUsageMeasure.Tokens]: 0, [RunUsageMeasure.CostUsd]: 0 },
|
|
99
105
|
}));
|
|
100
|
-
const totals =
|
|
101
|
-
const
|
|
106
|
+
const totals = Object.fromEntries(series.map(({ id }) => [id, 0]));
|
|
107
|
+
const durationData = collectDurations(query, buckets);
|
|
102
108
|
const counts = dimensions.map(() => new Map());
|
|
103
109
|
let runs = 0, totalTokens = 0, totalCostUsd = 0, processed = 0;
|
|
104
|
-
for (const run of
|
|
110
|
+
for (const run of (await readRuns(journal, query)).values()) {
|
|
105
111
|
if (processed++ % 100 === 0)
|
|
106
112
|
await yieldScan(query.signal);
|
|
107
113
|
const start = Date.parse(run.startedAt);
|
|
@@ -124,12 +130,12 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
124
130
|
const bucket = usageBuckets[Math.floor((start - first) / query.window.bucketMs)];
|
|
125
131
|
bucket.values[RunUsageMeasure.Tokens] += tokens;
|
|
126
132
|
bucket.values[RunUsageMeasure.CostUsd] += cost;
|
|
127
|
-
|
|
128
|
-
if (duration !== null)
|
|
129
|
-
durations.push(duration);
|
|
133
|
+
durationData.add(run, Math.floor((start - first) / query.window.bucketMs));
|
|
130
134
|
}
|
|
135
|
+
const duration = await durationData.report();
|
|
131
136
|
query.signal?.throwIfAborted();
|
|
132
137
|
return {
|
|
138
|
+
duration,
|
|
133
139
|
report: {
|
|
134
140
|
report: { id: RunReportId.Outcomes, title: 'Run outcomes over time' },
|
|
135
141
|
window: query.window,
|
|
@@ -152,7 +158,7 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
152
158
|
failed: totals[RunReportOutcome.Failed],
|
|
153
159
|
totalTokens,
|
|
154
160
|
totalCostUsd,
|
|
155
|
-
medianRunDurationMs:
|
|
161
|
+
medianRunDurationMs: duration.statistics.medianMs,
|
|
156
162
|
},
|
|
157
163
|
};
|
|
158
164
|
}
|
|
@@ -199,3 +205,64 @@ function outcomeBuckets(first, to, bucketMs) {
|
|
|
199
205
|
});
|
|
200
206
|
return buckets;
|
|
201
207
|
}
|
|
208
|
+
function collectDurations(query, buckets) {
|
|
209
|
+
const durations = [];
|
|
210
|
+
const durationBuckets = buckets.map(() => []);
|
|
211
|
+
const durationGroups = dimensions.slice(0, 2).map(() => new Map());
|
|
212
|
+
return {
|
|
213
|
+
add(run, bucketIndex) {
|
|
214
|
+
const duration = runDuration(run);
|
|
215
|
+
if (duration !== null) {
|
|
216
|
+
durations.push(duration);
|
|
217
|
+
durationBuckets[bucketIndex].push(duration);
|
|
218
|
+
dimensions.slice(0, 2).forEach((dimension, index) => {
|
|
219
|
+
const value = dimension.value(run) ?? RunReportValue.Unknown;
|
|
220
|
+
const groups = durationGroups[index];
|
|
221
|
+
const values = groups.get(value) ?? [];
|
|
222
|
+
values.push(duration);
|
|
223
|
+
groups.set(value, values);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
async report() {
|
|
228
|
+
const statistics = async (values) => {
|
|
229
|
+
let sum = 0;
|
|
230
|
+
for (const [index, value] of values.entries()) {
|
|
231
|
+
if (index % 1024 === 0)
|
|
232
|
+
await yieldScan(query.signal);
|
|
233
|
+
sum += value;
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
count: values.length,
|
|
237
|
+
medianMs: await median(values, () => yieldScan(query.signal)),
|
|
238
|
+
averageMs: values.length === 0 ? null : sum / values.length,
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
const groups = [];
|
|
242
|
+
for (const [index, dimension] of dimensions.slice(0, 2).entries()) {
|
|
243
|
+
const rows = [];
|
|
244
|
+
for (const [value, values] of durationGroups[index]) {
|
|
245
|
+
await yieldScan(query.signal);
|
|
246
|
+
rows.push({ value, ...(await statistics(values)) });
|
|
247
|
+
}
|
|
248
|
+
rows.sort((a, b) => b.count - a.count || (a.value < b.value ? -1 : a.value > b.value ? 1 : 0));
|
|
249
|
+
groups.push({ id: dimension.id, title: dimension.title, rows });
|
|
250
|
+
}
|
|
251
|
+
const durationSeries = [];
|
|
252
|
+
for (const [index, bucket] of buckets.entries()) {
|
|
253
|
+
durationSeries.push({
|
|
254
|
+
from: bucket.from,
|
|
255
|
+
to: bucket.to,
|
|
256
|
+
...(await statistics(durationBuckets[index])),
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
report: durationDescriptor,
|
|
261
|
+
window: query.window,
|
|
262
|
+
statistics: await statistics(durations),
|
|
263
|
+
groups,
|
|
264
|
+
buckets: durationSeries,
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -53,7 +53,26 @@ export interface BreakdownReport {
|
|
|
53
53
|
}[];
|
|
54
54
|
})[];
|
|
55
55
|
}
|
|
56
|
-
export
|
|
56
|
+
export interface DurationStatistics {
|
|
57
|
+
readonly count: number;
|
|
58
|
+
readonly medianMs: number | null;
|
|
59
|
+
readonly averageMs: number | null;
|
|
60
|
+
}
|
|
61
|
+
export interface DurationReport {
|
|
62
|
+
readonly report: ReportDescriptor;
|
|
63
|
+
readonly window: ReportWindow;
|
|
64
|
+
readonly statistics: DurationStatistics;
|
|
65
|
+
readonly groups: readonly (ReportDescriptor & {
|
|
66
|
+
readonly rows: readonly (DurationStatistics & {
|
|
67
|
+
readonly value: string;
|
|
68
|
+
})[];
|
|
69
|
+
})[];
|
|
70
|
+
readonly buckets: readonly (DurationStatistics & {
|
|
71
|
+
readonly from: string;
|
|
72
|
+
readonly to: string;
|
|
73
|
+
})[];
|
|
74
|
+
}
|
|
75
|
+
export type AnalyticsReport = TimeSeriesReport | BreakdownReport | DurationReport;
|
|
57
76
|
export interface ReportDefinition extends ReportDescriptor {
|
|
58
77
|
query(query: ReportQuery): Promise<AnalyticsReport>;
|
|
59
78
|
}
|
|
@@ -10,7 +10,7 @@ export interface MetricsResponse {
|
|
|
10
10
|
readonly values: Readonly<Record<string, number>>;
|
|
11
11
|
}
|
|
12
12
|
export { ReportWindowId } from '../../../kernel/index.js';
|
|
13
|
-
export type { AnalyticsReport, ReportWindowId as AnalyticsReportWindowId, BreakdownReport, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
|
|
13
|
+
export type { AnalyticsReport, ReportWindowId as AnalyticsReportWindowId, BreakdownReport, DurationReport, DurationStatistics, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
|
|
14
14
|
export interface AnalyticsSummaryResponse {
|
|
15
15
|
readonly window: ReportWindow;
|
|
16
16
|
readonly runs: number;
|