@atolis-hq/wake 0.4.90 → 0.4.91
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/version.js +1 -1
- package/dist/src/execution/application/run-duration.d.ts +1 -0
- package/dist/src/execution/application/run-duration.js +1 -1
- package/dist/src/execution/application/run-metrics.d.ts +3 -0
- package/dist/src/execution/application/run-metrics.js +22 -0
- package/dist/src/execution/application/run-reports.js +19 -12
- package/dist/src/kernel/contracts/reports.d.ts +6 -0
- package/dist/src/surfaces/web-assets/assets/{index-B0jIss24.js → index-s9CWgq-s.js} +2 -2
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
|
@@ -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.91";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type DurationReport, type ReportDescriptor, type ReportQuery, type TimeSeriesReport } from '../../kernel/index.js';
|
|
2
2
|
import type { RunView } from '../contracts/views.js';
|
|
3
|
+
export declare function runDuration(run: RunView): number | null;
|
|
3
4
|
export declare function collectDurations(query: ReportQuery, buckets: TimeSeriesReport['buckets'], dimensions: readonly {
|
|
4
5
|
readonly id: string;
|
|
5
6
|
readonly title: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { yieldScan } from '@atolis-hq/eventing';
|
|
2
2
|
import { median, } from '../../kernel/index.js';
|
|
3
3
|
import { RunReportValue } from '../contracts/run-report-value.js';
|
|
4
|
-
function runDuration(run) {
|
|
4
|
+
export function runDuration(run) {
|
|
5
5
|
if (run.finishedAt === undefined)
|
|
6
6
|
return null;
|
|
7
7
|
const duration = Date.parse(run.finishedAt) - Date.parse(run.startedAt);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { agentTokenUsage } from '../contracts/runner.js';
|
|
2
|
+
import { runDuration } from './run-duration.js';
|
|
3
|
+
export function runBreakdownMetrics(run) {
|
|
4
|
+
const usage = agentTokenUsage(run.agent?.metadata);
|
|
5
|
+
const metadata = run.agent?.metadata;
|
|
6
|
+
const hasFinite = (key) => typeof metadata?.[key] === 'number' && Number.isFinite(metadata[key]);
|
|
7
|
+
const duration = runDuration(run);
|
|
8
|
+
return {
|
|
9
|
+
count: 1,
|
|
10
|
+
tokens: finiteOrZero(usage.tokens),
|
|
11
|
+
costUsd: finiteOrZero(usage.costUsd),
|
|
12
|
+
durationMs: duration ?? 0,
|
|
13
|
+
tokenRuns: ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens'].some(hasFinite)
|
|
14
|
+
? 1
|
|
15
|
+
: 0,
|
|
16
|
+
costRuns: hasFinite('costUsd') ? 1 : 0,
|
|
17
|
+
durationRuns: duration === null ? 0 : 1,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function finiteOrZero(value) {
|
|
21
|
+
return Number.isFinite(value) ? value : 0;
|
|
22
|
+
}
|
|
@@ -3,10 +3,10 @@ import { ActivityOutcomeKind } from '../../activities/index.js';
|
|
|
3
3
|
import { defineClosedVocabulary, } from '../../kernel/index.js';
|
|
4
4
|
import { selectRunExecutionEvent } from '../contracts/events.js';
|
|
5
5
|
import { RunReportValue } from '../contracts/run-report-value.js';
|
|
6
|
-
import { agentTokenUsage } from '../contracts/runner.js';
|
|
7
6
|
import { RunStatus } from '../contracts/vocabulary.js';
|
|
8
7
|
import { foldRunEvent } from '../domain/run.js';
|
|
9
8
|
import { collectDurations } from './run-duration.js';
|
|
9
|
+
import { runBreakdownMetrics } from './run-metrics.js';
|
|
10
10
|
export const RunReportId = defineClosedVocabulary({
|
|
11
11
|
Duration: 'run-duration',
|
|
12
12
|
Outcomes: 'run-outcomes-over-time',
|
|
@@ -132,10 +132,9 @@ export async function queryRunAnalytics(journal, query, repositories) {
|
|
|
132
132
|
totals[outcome]++;
|
|
133
133
|
buckets[Math.floor((start - first) / query.window.bucketMs)].values[outcome]++;
|
|
134
134
|
runs++;
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const cost = finiteOrZero(usage.costUsd);
|
|
135
|
+
const metrics = runBreakdownMetrics(run);
|
|
136
|
+
const { tokens, costUsd: cost } = metrics;
|
|
137
|
+
countDimensions(run, counts, metrics, repositoryForRun);
|
|
139
138
|
totalTokens += tokens;
|
|
140
139
|
totalCostUsd += cost;
|
|
141
140
|
const bucket = usageBuckets[Math.floor((start - first) / query.window.bucketMs)];
|
|
@@ -173,9 +172,6 @@ export async function queryRunAnalytics(journal, query, repositories) {
|
|
|
173
172
|
},
|
|
174
173
|
};
|
|
175
174
|
}
|
|
176
|
-
function finiteOrZero(value) {
|
|
177
|
-
return Number.isFinite(value) ? value : 0;
|
|
178
|
-
}
|
|
179
175
|
async function readRuns(journal, query) {
|
|
180
176
|
const grouped = new Map();
|
|
181
177
|
for await (const event of scanJournal(journal, query.signal)) {
|
|
@@ -195,8 +191,8 @@ function runBreakdown(query, runs, counts) {
|
|
|
195
191
|
id,
|
|
196
192
|
title,
|
|
197
193
|
rows: [...counts[index].entries()]
|
|
198
|
-
.sort(([a, ac], [b, bc]) => bc - ac || (a < b ? -1 : a > b ? 1 : 0))
|
|
199
|
-
.map(([value,
|
|
194
|
+
.sort(([a, ac], [b, bc]) => bc.count - ac.count || (a < b ? -1 : a > b ? 1 : 0))
|
|
195
|
+
.map(([value, metrics]) => ({ value, ...metrics, share: metrics.count / runs })),
|
|
200
196
|
})),
|
|
201
197
|
};
|
|
202
198
|
}
|
|
@@ -210,12 +206,23 @@ function outcomeBuckets(first, to, bucketMs) {
|
|
|
210
206
|
});
|
|
211
207
|
return buckets;
|
|
212
208
|
}
|
|
213
|
-
function countDimensions(run, counts, repositoryForRun) {
|
|
209
|
+
function countDimensions(run, counts, metrics, repositoryForRun) {
|
|
214
210
|
dimensions.forEach((dimension, index) => {
|
|
215
211
|
const value = (dimension.id === RunReportDimension.Repository
|
|
216
212
|
? repositoryForRun?.(run)
|
|
217
213
|
: dimension.value(run)) ?? RunReportValue.Unknown;
|
|
218
214
|
const groups = counts[index];
|
|
219
|
-
|
|
215
|
+
const previous = groups.get(value);
|
|
216
|
+
groups.set(value, previous === undefined
|
|
217
|
+
? { ...metrics }
|
|
218
|
+
: {
|
|
219
|
+
count: previous.count + metrics.count,
|
|
220
|
+
tokens: previous.tokens + metrics.tokens,
|
|
221
|
+
costUsd: previous.costUsd + metrics.costUsd,
|
|
222
|
+
durationMs: previous.durationMs + metrics.durationMs,
|
|
223
|
+
tokenRuns: previous.tokenRuns + metrics.tokenRuns,
|
|
224
|
+
costRuns: previous.costRuns + metrics.costRuns,
|
|
225
|
+
durationRuns: previous.durationRuns + metrics.durationRuns,
|
|
226
|
+
});
|
|
220
227
|
});
|
|
221
228
|
}
|
|
@@ -50,6 +50,12 @@ export interface BreakdownReport {
|
|
|
50
50
|
readonly value: string;
|
|
51
51
|
readonly count: number;
|
|
52
52
|
readonly share: number;
|
|
53
|
+
readonly tokens: number;
|
|
54
|
+
readonly costUsd: number;
|
|
55
|
+
readonly durationMs: number;
|
|
56
|
+
readonly tokenRuns: number;
|
|
57
|
+
readonly costRuns: number;
|
|
58
|
+
readonly durationRuns: number;
|
|
53
59
|
}[];
|
|
54
60
|
})[];
|
|
55
61
|
}
|