@atolis-hq/wake 0.4.59 → 0.4.61
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.d.ts +1 -1
- package/dist/src/bootstrap/analytics-reports.js +5 -2
- package/dist/src/bootstrap/canonical-events.d.ts +3 -0
- package/dist/src/bootstrap/canonical-events.js +32 -0
- package/dist/src/bootstrap/composition-root.d.ts +2 -2
- package/dist/src/bootstrap/composition-root.js +6 -3
- package/dist/src/bootstrap/config/root-schema.d.ts +8 -3
- package/dist/src/bootstrap/config/root-schema.js +29 -1
- package/dist/src/bootstrap/initialise.js +5 -0
- package/dist/src/bootstrap/integration-runtime.d.ts +6 -4
- package/dist/src/bootstrap/integration-runtime.js +50 -8
- package/dist/src/bootstrap/surface-cli-applications.js +1 -1
- package/dist/src/bootstrap/trigger-checkpoint-store.d.ts +9 -0
- package/dist/src/bootstrap/trigger-checkpoint-store.js +49 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/control-plane-projection.js +2 -0
- package/dist/src/control-plane/application/runner-pipeline.d.ts +2 -2
- package/dist/src/control-plane/application/runner-pipeline.js +2 -2
- package/dist/src/control-plane/application/trigger-service.d.ts +35 -0
- package/dist/src/control-plane/application/trigger-service.js +118 -0
- package/dist/src/control-plane/contracts/config.d.ts +18 -8
- package/dist/src/control-plane/contracts/config.js +35 -6
- package/dist/src/control-plane/contracts/event-factory.js +2 -0
- package/dist/src/control-plane/contracts/events.d.ts +23 -0
- package/dist/src/control-plane/contracts/events.js +32 -0
- package/dist/src/control-plane/domain/cron-trigger-policy.d.ts +10 -0
- package/dist/src/control-plane/domain/{schedule-policy.js → cron-trigger-policy.js} +5 -5
- package/dist/src/control-plane/index.d.ts +2 -2
- package/dist/src/control-plane/index.js +2 -2
- package/dist/src/execution/application/run-reports.d.ts +13 -1
- package/dist/src/execution/application/run-reports.js +42 -1
- package/dist/src/kernel/contracts/reports.d.ts +14 -1
- package/dist/src/surfaces/api/contracts/observability.d.ts +1 -1
- package/dist/src/surfaces/api/routes/applications.d.ts +2 -2
- package/dist/src/surfaces/web-assets/assets/index-CCvwzTeC.js +1131 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/bootstrap/schedule-checkpoint-store.d.ts +0 -9
- package/dist/src/bootstrap/schedule-checkpoint-store.js +0 -49
- package/dist/src/control-plane/application/schedule-service.d.ts +0 -31
- package/dist/src/control-plane/application/schedule-service.js +0 -47
- package/dist/src/control-plane/domain/schedule-policy.d.ts +0 -8
- package/dist/src/surfaces/web-assets/assets/index-CC1TIxyc.js +0 -1131
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export interface TriggerConfig {
|
|
2
3
|
readonly id: string;
|
|
3
4
|
readonly workflow: string;
|
|
4
|
-
readonly
|
|
5
|
-
|
|
5
|
+
readonly on: {
|
|
6
|
+
readonly events?: readonly string[];
|
|
7
|
+
readonly cron?: string;
|
|
8
|
+
};
|
|
9
|
+
readonly when?: {
|
|
10
|
+
readonly capacityAvailable: true;
|
|
11
|
+
};
|
|
6
12
|
}
|
|
7
13
|
export interface ControlPlaneConfig {
|
|
8
14
|
readonly maxDispatches: number;
|
|
9
15
|
readonly maxConcurrentRuns: number;
|
|
10
|
-
readonly
|
|
16
|
+
readonly triggers: readonly TriggerConfig[];
|
|
11
17
|
readonly resident?: {
|
|
12
18
|
readonly pollBackoffMs: number;
|
|
13
19
|
readonly maxPollBackoffMs?: number;
|
|
14
20
|
};
|
|
15
21
|
}
|
|
16
|
-
import { z } from 'zod';
|
|
17
22
|
export declare const controlPlaneConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
18
23
|
maxDispatches: z.ZodDefault<z.ZodNumber>;
|
|
19
24
|
maxConcurrentRuns: z.ZodDefault<z.ZodNumber>;
|
|
20
|
-
|
|
25
|
+
triggers: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
21
26
|
id: z.ZodString;
|
|
22
27
|
workflow: z.ZodString;
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
on: z.ZodObject<{
|
|
29
|
+
events: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
30
|
+
cron: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
when: z.ZodOptional<z.ZodObject<{
|
|
33
|
+
capacityAvailable: z.ZodLiteral<true>;
|
|
34
|
+
}, z.core.$strict>>;
|
|
25
35
|
}, z.core.$strict>>>;
|
|
26
36
|
resident: z.ZodDefault<z.ZodObject<{
|
|
27
37
|
pollBackoffMs: z.ZodDefault<z.ZodNumber>;
|
|
@@ -1,17 +1,46 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { CronTriggerPolicy } from '../domain/cron-trigger-policy.js';
|
|
3
|
+
const triggerSchema = z
|
|
3
4
|
.object({
|
|
4
|
-
id: z
|
|
5
|
+
id: z
|
|
6
|
+
.string()
|
|
7
|
+
.trim()
|
|
8
|
+
.min(1)
|
|
9
|
+
.refine((id) => !/[\\/]/.test(id), 'Trigger id must not contain path separators'),
|
|
5
10
|
workflow: z.string().trim().min(1),
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
on: z
|
|
12
|
+
.object({
|
|
13
|
+
events: z.array(z.string().trim().min(1)).min(1).optional(),
|
|
14
|
+
cron: z
|
|
15
|
+
.string()
|
|
16
|
+
.trim()
|
|
17
|
+
.min(1)
|
|
18
|
+
.superRefine((cron, context) => {
|
|
19
|
+
try {
|
|
20
|
+
new CronTriggerPolicy().elapsedSlots({ id: 'validation', cron }, '2026-01-01T00:00:00.000Z', null);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
context.addIssue({
|
|
24
|
+
code: 'custom',
|
|
25
|
+
message: error instanceof Error ? error.message : 'Invalid cron',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.optional(),
|
|
30
|
+
})
|
|
31
|
+
.strict()
|
|
32
|
+
.refine((on) => on.events !== undefined || on.cron !== undefined, 'At least one trigger source is required'),
|
|
33
|
+
when: z
|
|
34
|
+
.object({ capacityAvailable: z.literal(true) })
|
|
35
|
+
.strict()
|
|
36
|
+
.optional(),
|
|
8
37
|
})
|
|
9
38
|
.strict();
|
|
10
39
|
export const controlPlaneConfigSchema = z
|
|
11
40
|
.object({
|
|
12
41
|
maxDispatches: z.number().int().positive().default(1),
|
|
13
42
|
maxConcurrentRuns: z.number().int().positive().default(1),
|
|
14
|
-
|
|
43
|
+
triggers: z.array(triggerSchema).default([]),
|
|
15
44
|
resident: z
|
|
16
45
|
.object({
|
|
17
46
|
// Backoff for the resident loop's own retry cadence when idle or
|
|
@@ -27,6 +56,6 @@ export const controlPlaneConfigSchema = z
|
|
|
27
56
|
.default({
|
|
28
57
|
maxDispatches: 1,
|
|
29
58
|
maxConcurrentRuns: 1,
|
|
30
|
-
|
|
59
|
+
triggers: [],
|
|
31
60
|
resident: { pollBackoffMs: 1000 },
|
|
32
61
|
});
|
|
@@ -2,6 +2,8 @@ import { createEventData } from '@atolis-hq/eventing';
|
|
|
2
2
|
import { ControlEventType } from './events.js';
|
|
3
3
|
export function createControlPlaneEventData(input) {
|
|
4
4
|
switch (input.eventType) {
|
|
5
|
+
case ControlEventType.TriggerInvocationStarted:
|
|
6
|
+
return createEventData(input);
|
|
5
7
|
case ControlEventType.DispatchPaused:
|
|
6
8
|
return createEventData(input);
|
|
7
9
|
case ControlEventType.DispatchResumed:
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type EventDataUnion, type EventEnvelope, type EventUnion } from '@atolis-hq/eventing';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { type ControlStreamRef } from './streams.js';
|
|
3
4
|
export declare const ControlEventType: {
|
|
5
|
+
readonly TriggerInvocationStarted: "control-plane.trigger-invocation-started";
|
|
4
6
|
readonly DispatchPaused: "control-plane.dispatch-paused";
|
|
5
7
|
readonly DispatchResumed: "control-plane.dispatch-resumed";
|
|
6
8
|
readonly RunnerPaused: "control-plane.runner-paused";
|
|
@@ -11,7 +13,27 @@ export declare const RunnerPauseCause: {
|
|
|
11
13
|
readonly Quota: "quota";
|
|
12
14
|
};
|
|
13
15
|
export declare const ControlEventNamespace: "control-plane.";
|
|
16
|
+
export declare const TriggerSourceKind: {
|
|
17
|
+
readonly Event: "event";
|
|
18
|
+
readonly Cron: "cron";
|
|
19
|
+
};
|
|
20
|
+
declare const triggerSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
21
|
+
kind: z.ZodLiteral<"event">;
|
|
22
|
+
eventId: z.ZodString;
|
|
23
|
+
eventType: z.ZodString;
|
|
24
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
25
|
+
kind: z.ZodLiteral<"cron">;
|
|
26
|
+
slot: z.ZodString;
|
|
27
|
+
}, z.core.$strict>], "kind">;
|
|
28
|
+
export type TriggerSource = z.infer<typeof triggerSourceSchema>;
|
|
14
29
|
export interface ControlEventPayloads {
|
|
30
|
+
readonly [ControlEventType.TriggerInvocationStarted]: {
|
|
31
|
+
readonly triggerId: string;
|
|
32
|
+
readonly source: TriggerSource;
|
|
33
|
+
readonly workItemId: string;
|
|
34
|
+
readonly workflowInstanceId: string;
|
|
35
|
+
readonly workflowName: string;
|
|
36
|
+
};
|
|
15
37
|
readonly [ControlEventType.DispatchPaused]: {
|
|
16
38
|
readonly resumeAt: string;
|
|
17
39
|
readonly reason: string;
|
|
@@ -34,3 +56,4 @@ export type ControlEvent = EventUnion<ControlEventPayloads, ControlStreamRef>;
|
|
|
34
56
|
export type ControlEventData = EventDataUnion<ControlEventPayloads>;
|
|
35
57
|
export declare function decodeControlEvent(event: EventEnvelope): ControlEvent;
|
|
36
58
|
export declare function selectControlEvent(event: EventEnvelope): ControlEvent | null;
|
|
59
|
+
export {};
|
|
@@ -2,6 +2,7 @@ import { eventDataSchema, eventEnvelopeSchema, } from '@atolis-hq/eventing';
|
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { ControlStreamKind } from './streams.js';
|
|
4
4
|
export const ControlEventType = {
|
|
5
|
+
TriggerInvocationStarted: 'control-plane.trigger-invocation-started',
|
|
5
6
|
DispatchPaused: 'control-plane.dispatch-paused',
|
|
6
7
|
DispatchResumed: 'control-plane.dispatch-resumed',
|
|
7
8
|
RunnerPaused: 'control-plane.runner-paused',
|
|
@@ -9,10 +10,41 @@ export const ControlEventType = {
|
|
|
9
10
|
};
|
|
10
11
|
export const RunnerPauseCause = { Manual: 'manual', Quota: 'quota' };
|
|
11
12
|
export const ControlEventNamespace = 'control-plane.';
|
|
13
|
+
export const TriggerSourceKind = { Event: 'event', Cron: 'cron' };
|
|
14
|
+
const triggerSourceSchema = z.discriminatedUnion('kind', [
|
|
15
|
+
z
|
|
16
|
+
.object({
|
|
17
|
+
kind: z.literal(TriggerSourceKind.Event),
|
|
18
|
+
eventId: z.string().min(1),
|
|
19
|
+
eventType: z.string().min(1),
|
|
20
|
+
})
|
|
21
|
+
.strict(),
|
|
22
|
+
z
|
|
23
|
+
.object({
|
|
24
|
+
kind: z.literal(TriggerSourceKind.Cron),
|
|
25
|
+
slot: z.string().datetime({ offset: true }),
|
|
26
|
+
})
|
|
27
|
+
.strict(),
|
|
28
|
+
]);
|
|
12
29
|
const streamSchema = z
|
|
13
30
|
.object({ kind: z.literal(ControlStreamKind.Global), id: z.literal('global') })
|
|
14
31
|
.strict();
|
|
15
32
|
const eventSchema = z.union([
|
|
33
|
+
eventEnvelopeSchema.extend({
|
|
34
|
+
event: eventDataSchema.extend({
|
|
35
|
+
eventType: z.literal(ControlEventType.TriggerInvocationStarted),
|
|
36
|
+
payload: z
|
|
37
|
+
.object({
|
|
38
|
+
triggerId: z.string().min(1),
|
|
39
|
+
source: triggerSourceSchema,
|
|
40
|
+
workItemId: z.string().min(1),
|
|
41
|
+
workflowInstanceId: z.string().min(1),
|
|
42
|
+
workflowName: z.string().min(1),
|
|
43
|
+
})
|
|
44
|
+
.strict(),
|
|
45
|
+
}),
|
|
46
|
+
stream: streamSchema,
|
|
47
|
+
}),
|
|
16
48
|
eventEnvelopeSchema.extend({
|
|
17
49
|
event: eventDataSchema.extend({
|
|
18
50
|
eventType: z.literal(ControlEventType.DispatchPaused),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CronTriggerSlot {
|
|
2
|
+
readonly identity: string;
|
|
3
|
+
readonly at: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class CronTriggerPolicy {
|
|
6
|
+
elapsedSlots(config: {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly cron: string;
|
|
9
|
+
}, now: string, checkpoint: string | null): readonly CronTriggerSlot[];
|
|
10
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CronExpressionParser } from 'cron-parser';
|
|
2
|
-
export class
|
|
2
|
+
export class CronTriggerPolicy {
|
|
3
3
|
elapsedSlots(config, now, checkpoint) {
|
|
4
4
|
const end = minute(new Date(now));
|
|
5
5
|
const start = checkpoint === null ? end : minute(new Date(new Date(checkpoint).getTime() + 60_000));
|
|
@@ -7,9 +7,9 @@ export class SchedulePolicy {
|
|
|
7
7
|
return [];
|
|
8
8
|
const fields = config.cron.trim().split(/\s+/);
|
|
9
9
|
if (fields.length !== 5)
|
|
10
|
-
throw new Error(`
|
|
10
|
+
throw new Error(`Trigger ${config.id} must use a five-field cron expression`);
|
|
11
11
|
if (fields.some(hasUnsupportedSyntax))
|
|
12
|
-
throw new Error(`
|
|
12
|
+
throw new Error(`Trigger ${config.id} uses unsupported cron syntax`);
|
|
13
13
|
const expression = CronExpressionParser.parse(config.cron, {
|
|
14
14
|
currentDate: new Date(start - 1),
|
|
15
15
|
endDate: new Date(end),
|
|
@@ -23,14 +23,14 @@ export class SchedulePolicy {
|
|
|
23
23
|
if (!matchesDays(date, dayOfMonth, dayOfWeek))
|
|
24
24
|
continue;
|
|
25
25
|
const at = date.toISOString();
|
|
26
|
-
slots.push({ identity: `
|
|
26
|
+
slots.push({ identity: `trigger:${config.id}:cron:${at}`, at });
|
|
27
27
|
}
|
|
28
28
|
return slots;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
function minute(value) {
|
|
32
32
|
if (Number.isNaN(value.getTime()))
|
|
33
|
-
throw new Error('
|
|
33
|
+
throw new Error('Trigger timestamps must be valid dates');
|
|
34
34
|
return Math.floor(value.getTime() / 60_000) * 60_000;
|
|
35
35
|
}
|
|
36
36
|
function hasUnsupportedSyntax(field) {
|
|
@@ -5,7 +5,7 @@ export type * from './application/activation-scheduler-ports.js';
|
|
|
5
5
|
export * from './application/control-plane-projection.js';
|
|
6
6
|
export * from './application/control-plane-service.js';
|
|
7
7
|
export * from './application/runner-control-service.js';
|
|
8
|
-
export * from './application/
|
|
8
|
+
export * from './application/trigger-service.js';
|
|
9
9
|
export * from './application/intake-pipeline.js';
|
|
10
10
|
export * from './application/runner-pipeline.js';
|
|
11
11
|
export * from './application/work-cancellation-policy.js';
|
|
@@ -18,7 +18,7 @@ export * from './contracts/views.js';
|
|
|
18
18
|
export * from './domain/dispatch-policy.js';
|
|
19
19
|
export * from './domain/quota-policy.js';
|
|
20
20
|
export * from './domain/runner-quota.js';
|
|
21
|
-
export * from './domain/
|
|
21
|
+
export * from './domain/cron-trigger-policy.js';
|
|
22
22
|
export * from './infrastructure/intake-host.js';
|
|
23
23
|
export * from './infrastructure/resident-host.js';
|
|
24
24
|
export * from './infrastructure/tick-host.js';
|
|
@@ -4,7 +4,7 @@ export * from './application/activation-scheduler-subscriber.js';
|
|
|
4
4
|
export * from './application/control-plane-projection.js';
|
|
5
5
|
export * from './application/control-plane-service.js';
|
|
6
6
|
export * from './application/runner-control-service.js';
|
|
7
|
-
export * from './application/
|
|
7
|
+
export * from './application/trigger-service.js';
|
|
8
8
|
export * from './application/intake-pipeline.js';
|
|
9
9
|
export * from './application/runner-pipeline.js';
|
|
10
10
|
export * from './application/work-cancellation-policy.js';
|
|
@@ -17,7 +17,7 @@ export * from './contracts/views.js';
|
|
|
17
17
|
export * from './domain/dispatch-policy.js';
|
|
18
18
|
export * from './domain/quota-policy.js';
|
|
19
19
|
export * from './domain/runner-quota.js';
|
|
20
|
-
export * from './domain/
|
|
20
|
+
export * from './domain/cron-trigger-policy.js';
|
|
21
21
|
export * from './infrastructure/intake-host.js';
|
|
22
22
|
export * from './infrastructure/resident-host.js';
|
|
23
23
|
export * from './infrastructure/tick-host.js';
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { type EventJournal } from '@atolis-hq/eventing';
|
|
2
|
-
import { type ReportDefinition, type ReportQuery, type TimeSeriesReport, type ValueOf } from '../../kernel/index.js';
|
|
2
|
+
import { type BreakdownReport, 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
5
|
readonly Outcomes: "run-outcomes-over-time";
|
|
6
|
+
readonly Breakdown: "run-breakdowns-by-dimension";
|
|
6
7
|
};
|
|
8
|
+
export declare const RunReportDimension: {
|
|
9
|
+
readonly Action: "run-action";
|
|
10
|
+
readonly Stage: "run-stage";
|
|
11
|
+
readonly Runner: "run-runner";
|
|
12
|
+
readonly Model: "run-model";
|
|
13
|
+
};
|
|
14
|
+
export declare const RunReportValue: {
|
|
15
|
+
readonly Unknown: "unknown";
|
|
16
|
+
};
|
|
17
|
+
export declare function createRunBreakdownReport(journal: EventJournal): ReportDefinition;
|
|
7
18
|
export declare const RunReportOutcome: {
|
|
8
19
|
readonly Completed: "completed";
|
|
9
20
|
readonly Blocked: "blocked";
|
|
@@ -25,5 +36,6 @@ export declare function runReportOutcome(run: RunView): RunReportOutcome;
|
|
|
25
36
|
export declare function createRunOutcomesReport(journal: EventJournal): ReportDefinition;
|
|
26
37
|
export declare function queryRunAnalytics(journal: EventJournal, query: ReportQuery): Promise<{
|
|
27
38
|
report: TimeSeriesReport;
|
|
39
|
+
breakdown: BreakdownReport;
|
|
28
40
|
summary: RunSummary;
|
|
29
41
|
}>;
|
|
@@ -5,7 +5,30 @@ import { selectRunExecutionEvent } from '../contracts/events.js';
|
|
|
5
5
|
import { agentTokenUsage } from '../contracts/runner.js';
|
|
6
6
|
import { RunStatus } from '../contracts/vocabulary.js';
|
|
7
7
|
import { foldRunEvent } from '../domain/run.js';
|
|
8
|
-
export const RunReportId = defineClosedVocabulary({
|
|
8
|
+
export const RunReportId = defineClosedVocabulary({
|
|
9
|
+
Outcomes: 'run-outcomes-over-time',
|
|
10
|
+
Breakdown: 'run-breakdowns-by-dimension',
|
|
11
|
+
});
|
|
12
|
+
export const RunReportDimension = defineClosedVocabulary({
|
|
13
|
+
Action: 'run-action',
|
|
14
|
+
Stage: 'run-stage',
|
|
15
|
+
Runner: 'run-runner',
|
|
16
|
+
Model: 'run-model',
|
|
17
|
+
});
|
|
18
|
+
export const RunReportValue = defineClosedVocabulary({ Unknown: 'unknown' });
|
|
19
|
+
const dimensions = [
|
|
20
|
+
{ id: RunReportDimension.Action, title: 'Action', value: (run) => run.activity },
|
|
21
|
+
{ id: RunReportDimension.Stage, title: 'Stage', value: (run) => run.stage },
|
|
22
|
+
{ id: RunReportDimension.Runner, title: 'Runner', value: (run) => run.runner?.name },
|
|
23
|
+
{ id: RunReportDimension.Model, title: 'Model', value: (run) => run.runner?.model },
|
|
24
|
+
];
|
|
25
|
+
export function createRunBreakdownReport(journal) {
|
|
26
|
+
return {
|
|
27
|
+
id: RunReportId.Breakdown,
|
|
28
|
+
title: 'Run breakdowns by dimension',
|
|
29
|
+
query: async (query) => (await queryRunAnalytics(journal, query)).breakdown,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
9
32
|
export const RunReportOutcome = defineClosedVocabulary({
|
|
10
33
|
Completed: 'completed',
|
|
11
34
|
Blocked: 'blocked',
|
|
@@ -67,6 +90,7 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
67
90
|
});
|
|
68
91
|
const totals = zero();
|
|
69
92
|
const durations = [];
|
|
93
|
+
const counts = dimensions.map(() => new Map());
|
|
70
94
|
let runs = 0, totalTokens = 0, totalCostUsd = 0, processed = 0;
|
|
71
95
|
for (const run of grouped.values()) {
|
|
72
96
|
if (processed++ % 100 === 0)
|
|
@@ -78,6 +102,11 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
78
102
|
totals[outcome]++;
|
|
79
103
|
buckets[Math.floor((start - first) / query.window.bucketMs)].values[outcome]++;
|
|
80
104
|
runs++;
|
|
105
|
+
dimensions.forEach((dimension, index) => {
|
|
106
|
+
const value = dimension.value(run) ?? RunReportValue.Unknown;
|
|
107
|
+
const groups = counts[index];
|
|
108
|
+
groups.set(value, (groups.get(value) ?? 0) + 1);
|
|
109
|
+
});
|
|
81
110
|
const usage = agentTokenUsage(run.agent?.metadata);
|
|
82
111
|
totalTokens += finiteOrZero(usage.tokens);
|
|
83
112
|
totalCostUsd += finiteOrZero(usage.costUsd);
|
|
@@ -94,6 +123,18 @@ export async function queryRunAnalytics(journal, query) {
|
|
|
94
123
|
totals,
|
|
95
124
|
buckets,
|
|
96
125
|
},
|
|
126
|
+
breakdown: {
|
|
127
|
+
report: { id: RunReportId.Breakdown, title: 'Run breakdowns by dimension' },
|
|
128
|
+
window: query.window,
|
|
129
|
+
total: runs,
|
|
130
|
+
dimensions: dimensions.map(({ id, title }, index) => ({
|
|
131
|
+
id,
|
|
132
|
+
title,
|
|
133
|
+
rows: [...counts[index].entries()]
|
|
134
|
+
.sort(([a, ac], [b, bc]) => bc - ac || (a < b ? -1 : a > b ? 1 : 0))
|
|
135
|
+
.map(([value, count]) => ({ value, count, share: count / runs })),
|
|
136
|
+
})),
|
|
137
|
+
},
|
|
97
138
|
summary: {
|
|
98
139
|
runs,
|
|
99
140
|
completed: totals[RunReportOutcome.Completed],
|
|
@@ -31,8 +31,21 @@ export interface TimeSeriesReport {
|
|
|
31
31
|
readonly values: Readonly<Record<string, number>>;
|
|
32
32
|
}[];
|
|
33
33
|
}
|
|
34
|
+
export interface BreakdownReport {
|
|
35
|
+
readonly report: ReportDescriptor;
|
|
36
|
+
readonly window: ReportWindow;
|
|
37
|
+
readonly total: number;
|
|
38
|
+
readonly dimensions: readonly (ReportDescriptor & {
|
|
39
|
+
readonly rows: readonly {
|
|
40
|
+
readonly value: string;
|
|
41
|
+
readonly count: number;
|
|
42
|
+
readonly share: number;
|
|
43
|
+
}[];
|
|
44
|
+
})[];
|
|
45
|
+
}
|
|
46
|
+
export type AnalyticsReport = TimeSeriesReport | BreakdownReport;
|
|
34
47
|
export interface ReportDefinition extends ReportDescriptor {
|
|
35
|
-
query(query: ReportQuery): Promise<
|
|
48
|
+
query(query: ReportQuery): Promise<AnalyticsReport>;
|
|
36
49
|
}
|
|
37
50
|
export declare function reportWindow(id: ReportWindowId, now: string): ReportWindow;
|
|
38
51
|
/** Exact median with bounded sorting/merging work between caller-supplied pauses. */
|
|
@@ -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 { ReportWindowId as AnalyticsReportWindowId, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
|
|
13
|
+
export type { AnalyticsReport, ReportWindowId as AnalyticsReportWindowId, BreakdownReport, ReportDescriptor, ReportWindow, TimeSeriesReport, } from '../../../kernel/index.js';
|
|
14
14
|
export interface AnalyticsSummaryResponse {
|
|
15
15
|
readonly window: ReportWindow;
|
|
16
16
|
readonly runs: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunStatus } from '../../../execution/index.js';
|
|
2
|
-
import type { ReportDescriptor, ReportWindowId
|
|
2
|
+
import type { AnalyticsReport, ReportDescriptor, ReportWindowId } from '../../../kernel/index.js';
|
|
3
3
|
import type { ApiCommandResult, AuditEventResponse, BoardCardResponse, BoardResponse, CommandsResponse, ConfigurationResponse, ControlPlaneStatusResponse, ConversationMessageRequest, HealthResponse, MetricsResponse, ResourceItemResponse, ResourceResponse, ResponseMeta, RunnerResponse, RunResponse, RunTranscriptResponse, StatusResponse, WebhookSetupResponse, WorkDetailResponse, WorkflowDiagramsResponse, WorkflowInstanceResponse, WorkItemResponse, WorkItemTranscriptResponse } from '../contracts/index.js';
|
|
4
4
|
import type { AnalyticsSummaryResponse } from '../contracts/observability.js';
|
|
5
5
|
export interface CollectionQuery {
|
|
@@ -94,7 +94,7 @@ export interface ApiApplications {
|
|
|
94
94
|
readonly observability: {
|
|
95
95
|
readonly reports?: {
|
|
96
96
|
catalogue(): readonly ReportDescriptor[];
|
|
97
|
-
report(id: string, window: ReportWindowId, signal?: AbortSignal): Promise<ApiResourceResult<
|
|
97
|
+
report(id: string, window: ReportWindowId, signal?: AbortSignal): Promise<ApiResourceResult<AnalyticsReport>>;
|
|
98
98
|
summary(window: ReportWindowId, signal?: AbortSignal): Promise<ApiResourceResult<AnalyticsSummaryResponse>>;
|
|
99
99
|
};
|
|
100
100
|
metrics(query?: {
|