@atolis-hq/wake 0.4.87 → 0.4.88
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/kernel/contracts/reports.d.ts +8 -0
- package/dist/src/orchestration/application/work-completion-summary.d.ts +9 -1
- package/dist/src/orchestration/application/work-completion-summary.js +91 -5
- package/dist/src/surfaces/web-assets/assets/{index--h2bjD5B.js → index-D4-8tZ5f.js} +2 -2
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createRunBreakdownReport, createRunOutcomesReport, createRunUsageReport, queryRunAnalytics, } from '../execution/index.js';
|
|
2
2
|
import { reportWindow } from '../kernel/index.js';
|
|
3
|
-
import { queryWorkCompletionSummary } from '../orchestration/index.js';
|
|
3
|
+
import { createWorkThroughputReport, queryWorkCompletionSummary } from '../orchestration/index.js';
|
|
4
4
|
import { sampledMeta } from './surface-api-metadata.js';
|
|
5
5
|
export function createAnalyticsReports(journal, now) {
|
|
6
6
|
const definitions = [
|
|
7
7
|
createRunOutcomesReport(journal),
|
|
8
8
|
createRunBreakdownReport(journal),
|
|
9
9
|
createRunUsageReport(journal),
|
|
10
|
+
createWorkThroughputReport(journal),
|
|
10
11
|
];
|
|
11
12
|
return {
|
|
12
13
|
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.88";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -21,6 +21,14 @@ export interface ReportDescriptor {
|
|
|
21
21
|
readonly title: string;
|
|
22
22
|
}
|
|
23
23
|
export interface TimeSeriesReport {
|
|
24
|
+
readonly durationRows?: readonly {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
readonly title: string;
|
|
27
|
+
readonly createdAt: string;
|
|
28
|
+
readonly completedAt: string;
|
|
29
|
+
readonly durationMs: number;
|
|
30
|
+
}[];
|
|
31
|
+
readonly excludedDurationCount?: number;
|
|
24
32
|
readonly report: ReportDescriptor;
|
|
25
33
|
readonly window: ReportWindow;
|
|
26
34
|
readonly series: readonly (ReportDescriptor & {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { type EventJournal } from '@atolis-hq/eventing';
|
|
2
|
-
import { type ReportQuery } from '../../kernel/index.js';
|
|
2
|
+
import { type ReportDefinition, type ReportQuery, type TimeSeriesReport } from '../../kernel/index.js';
|
|
3
3
|
export declare function queryWorkCompletionSummary(journal: EventJournal, query: ReportQuery): Promise<{
|
|
4
4
|
workItemsDone: number;
|
|
5
5
|
medianEndToEndDurationMs: number | null;
|
|
6
6
|
}>;
|
|
7
|
+
export declare const WorkReportId: {
|
|
8
|
+
readonly Throughput: "work-item-throughput";
|
|
9
|
+
};
|
|
10
|
+
export declare const WorkReportMeasure: {
|
|
11
|
+
readonly Completed: "work-items-done";
|
|
12
|
+
};
|
|
13
|
+
export declare function createWorkThroughputReport(journal: EventJournal): ReportDefinition;
|
|
14
|
+
export declare function queryWorkThroughput(journal: EventJournal, query: ReportQuery): Promise<TimeSeriesReport>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { scanJournal, yieldScan } from '@atolis-hq/eventing';
|
|
2
|
-
import { median } from '../../kernel/index.js';
|
|
2
|
+
import { defineClosedVocabulary, median, } from '../../kernel/index.js';
|
|
3
3
|
import { selectWorkEvent, WorkEventType } from '../../work/index.js';
|
|
4
4
|
import { selectWorkflowOrchestrationEvent } from '../contracts/event-decoder.js';
|
|
5
5
|
import { OrchestrationEventType } from '../contracts/events.js';
|
|
6
6
|
export async function queryWorkCompletionSummary(journal, query) {
|
|
7
|
-
const facts =
|
|
8
|
-
for await (const event of scanJournal(journal, query.signal))
|
|
9
|
-
acceptFact(facts, event);
|
|
7
|
+
const facts = await readCompletionFacts(journal, query);
|
|
10
8
|
const from = Date.parse(query.window.from), to = Date.parse(query.window.to);
|
|
11
9
|
let workItemsDone = 0, processed = 0;
|
|
12
10
|
const durations = [];
|
|
@@ -27,8 +25,10 @@ export async function queryWorkCompletionSummary(journal, query) {
|
|
|
27
25
|
}
|
|
28
26
|
function acceptFact(facts, event) {
|
|
29
27
|
const work = selectWorkEvent(event);
|
|
30
|
-
if (work?.event.eventType === WorkEventType.ItemCreated)
|
|
28
|
+
if (work?.event.eventType === WorkEventType.ItemCreated) {
|
|
31
29
|
facts.created.set(work.stream.id, Date.parse(work.event.occurredAt));
|
|
30
|
+
facts.titles.set(work.stream.id, work.event.payload.objective);
|
|
31
|
+
}
|
|
32
32
|
const workflow = selectWorkflowOrchestrationEvent(event);
|
|
33
33
|
if (workflow === null)
|
|
34
34
|
return;
|
|
@@ -47,3 +47,89 @@ function acceptFact(facts, event) {
|
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
async function readCompletionFacts(journal, query) {
|
|
51
|
+
const facts = {
|
|
52
|
+
created: new Map(),
|
|
53
|
+
titles: new Map(),
|
|
54
|
+
instances: new Map(),
|
|
55
|
+
completed: new Map(),
|
|
56
|
+
};
|
|
57
|
+
for await (const event of scanJournal(journal, query.signal))
|
|
58
|
+
acceptFact(facts, event);
|
|
59
|
+
return facts;
|
|
60
|
+
}
|
|
61
|
+
export const WorkReportId = defineClosedVocabulary({ Throughput: 'work-item-throughput' });
|
|
62
|
+
export const WorkReportMeasure = defineClosedVocabulary({ Completed: 'work-items-done' });
|
|
63
|
+
const descriptor = { id: WorkReportId.Throughput, title: 'Work item throughput' };
|
|
64
|
+
export function createWorkThroughputReport(journal) {
|
|
65
|
+
return { ...descriptor, query: (query) => queryWorkThroughput(journal, query) };
|
|
66
|
+
}
|
|
67
|
+
export async function queryWorkThroughput(journal, query) {
|
|
68
|
+
const facts = await readCompletionFacts(journal, query);
|
|
69
|
+
const from = Date.parse(query.window.from), to = Date.parse(query.window.to);
|
|
70
|
+
const first = Math.floor(from / query.window.bucketMs) * query.window.bucketMs;
|
|
71
|
+
const key = WorkReportMeasure.Completed;
|
|
72
|
+
const buckets = [];
|
|
73
|
+
for (let start = first; start < to; start += query.window.bucketMs)
|
|
74
|
+
buckets.push({
|
|
75
|
+
from: new Date(start).toISOString(),
|
|
76
|
+
to: new Date(start + query.window.bucketMs).toISOString(),
|
|
77
|
+
values: { [key]: 0 },
|
|
78
|
+
});
|
|
79
|
+
const rows = [];
|
|
80
|
+
let total = 0, processed = 0;
|
|
81
|
+
for (const [id, end] of facts.completed) {
|
|
82
|
+
if (processed++ % 100 === 0)
|
|
83
|
+
await yieldScan(query.signal);
|
|
84
|
+
if (!(end >= from && end < to))
|
|
85
|
+
continue;
|
|
86
|
+
total++;
|
|
87
|
+
buckets[Math.floor((end - first) / query.window.bucketMs)].values[key]++;
|
|
88
|
+
const start = facts.created.get(id);
|
|
89
|
+
if (start === undefined || !Number.isFinite(start) || end < start)
|
|
90
|
+
continue;
|
|
91
|
+
rows.push({
|
|
92
|
+
id,
|
|
93
|
+
title: facts.titles.get(id) ?? id,
|
|
94
|
+
createdAt: new Date(start).toISOString(),
|
|
95
|
+
completedAt: new Date(end).toISOString(),
|
|
96
|
+
durationMs: end - start,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const sorted = await sortDurationRows(rows, query.signal);
|
|
100
|
+
const report = {
|
|
101
|
+
report: descriptor,
|
|
102
|
+
window: query.window,
|
|
103
|
+
series: [{ id: key, title: 'Work items done', unit: 'work items' }],
|
|
104
|
+
totals: { [key]: total },
|
|
105
|
+
buckets,
|
|
106
|
+
durationRows: sorted,
|
|
107
|
+
excludedDurationCount: total - rows.length,
|
|
108
|
+
};
|
|
109
|
+
return report;
|
|
110
|
+
}
|
|
111
|
+
async function sortDurationRows(rows, signal) {
|
|
112
|
+
// Sort bounded batches and yield during merging to keep large reports cancellable.
|
|
113
|
+
let sorted = [];
|
|
114
|
+
const compare = (a, b) => b.completedAt.localeCompare(a.completedAt) || a.id.localeCompare(b.id);
|
|
115
|
+
for (let offset = 0; offset < rows.length; offset += 1024) {
|
|
116
|
+
await yieldScan(signal);
|
|
117
|
+
sorted.push(...rows.slice(offset, offset + 1024).sort(compare));
|
|
118
|
+
}
|
|
119
|
+
for (let width = 1024; width < sorted.length; width *= 2) {
|
|
120
|
+
const merged = [];
|
|
121
|
+
for (let start = 0; start < sorted.length; start += width * 2) {
|
|
122
|
+
const middle = Math.min(start + width, sorted.length), end = Math.min(start + width * 2, sorted.length);
|
|
123
|
+
let left = start, right = middle;
|
|
124
|
+
while (left < middle || right < end) {
|
|
125
|
+
if (merged.length % 1024 === 0)
|
|
126
|
+
await yieldScan(signal);
|
|
127
|
+
merged.push(right === end || (left < middle && compare(sorted[left], sorted[right]) <= 0)
|
|
128
|
+
? sorted[left++]
|
|
129
|
+
: sorted[right++]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
sorted = merged;
|
|
133
|
+
}
|
|
134
|
+
return sorted;
|
|
135
|
+
}
|