@atolis-hq/wake 0.4.61 → 0.4.62

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.
Files changed (39) hide show
  1. package/dist/src/bootstrap/composition-root.d.ts +4 -1
  2. package/dist/src/bootstrap/composition-root.js +5 -2
  3. package/dist/src/bootstrap/integration-runtime.d.ts +4 -2
  4. package/dist/src/bootstrap/integration-runtime.js +74 -13
  5. package/dist/src/bootstrap/trigger-checkpoint-store.d.ts +5 -5
  6. package/dist/src/bootstrap/trigger-checkpoint-store.js +15 -40
  7. package/dist/src/bootstrap/version.js +1 -1
  8. package/dist/src/control-plane/application/control-plane-projection.js +11 -1
  9. package/dist/src/control-plane/application/runner-pipeline.js +0 -2
  10. package/dist/src/control-plane/application/trigger-facts.d.ts +11 -0
  11. package/dist/src/control-plane/application/trigger-facts.js +38 -0
  12. package/dist/src/control-plane/application/trigger-invocation-projection.d.ts +4 -0
  13. package/dist/src/control-plane/application/trigger-invocation-projection.js +32 -0
  14. package/dist/src/control-plane/application/trigger-projection.d.ts +24 -0
  15. package/dist/src/control-plane/application/trigger-projection.js +98 -0
  16. package/dist/src/control-plane/application/trigger-reactor.d.ts +4 -0
  17. package/dist/src/control-plane/application/trigger-reactor.js +30 -0
  18. package/dist/src/control-plane/application/trigger-recovery.d.ts +10 -0
  19. package/dist/src/control-plane/application/trigger-recovery.js +61 -0
  20. package/dist/src/control-plane/application/trigger-rules.d.ts +19 -0
  21. package/dist/src/control-plane/application/trigger-rules.js +38 -0
  22. package/dist/src/control-plane/application/trigger-service.d.ts +34 -20
  23. package/dist/src/control-plane/application/trigger-service.js +182 -102
  24. package/dist/src/control-plane/application/trigger-source-cursor.d.ts +16 -0
  25. package/dist/src/control-plane/application/trigger-source-cursor.js +35 -0
  26. package/dist/src/control-plane/application/trigger-state-reader.d.ts +13 -0
  27. package/dist/src/control-plane/application/trigger-state-reader.js +34 -0
  28. package/dist/src/control-plane/application/trigger-workflow.d.ts +17 -0
  29. package/dist/src/control-plane/application/trigger-workflow.js +18 -0
  30. package/dist/src/control-plane/contracts/event-factory.js +10 -0
  31. package/dist/src/control-plane/contracts/events.d.ts +50 -3
  32. package/dist/src/control-plane/contracts/events.js +100 -4
  33. package/dist/src/control-plane/contracts/streams.d.ts +9 -2
  34. package/dist/src/control-plane/contracts/streams.js +13 -1
  35. package/dist/src/control-plane/domain/cron-trigger-policy.d.ts +1 -1
  36. package/dist/src/control-plane/domain/cron-trigger-policy.js +3 -1
  37. package/dist/src/control-plane/index.d.ts +3 -0
  38. package/dist/src/control-plane/index.js +3 -0
  39. package/package.json +1 -1
@@ -2,6 +2,16 @@ 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.TriggerRequestRecorded:
6
+ return createEventData(input);
7
+ case ControlEventType.TriggerInvocationClaimed:
8
+ return createEventData(input);
9
+ case ControlEventType.TriggerPaused:
10
+ return createEventData(input);
11
+ case ControlEventType.TriggerResumed:
12
+ return createEventData(input);
13
+ case ControlEventType.TriggerInvocationFinished:
14
+ return createEventData(input);
5
15
  case ControlEventType.TriggerInvocationStarted:
6
16
  return createEventData(input);
7
17
  case ControlEventType.DispatchPaused:
@@ -1,7 +1,13 @@
1
1
  import { type EventDataUnion, type EventEnvelope, type EventUnion } from '@atolis-hq/eventing';
2
2
  import { z } from 'zod';
3
- import { type ControlStreamRef } from './streams.js';
3
+ import { WorkflowStatus } from '../../orchestration/index.js';
4
+ import { type GlobalControlStreamRef, type TriggerControlStreamRef, type TriggerInvocationStreamRef } from './streams.js';
4
5
  export declare const ControlEventType: {
6
+ readonly TriggerRequestRecorded: "control-plane.trigger-request-recorded";
7
+ readonly TriggerInvocationClaimed: "control-plane.trigger-invocation-claimed";
8
+ readonly TriggerPaused: "control-plane.trigger-paused";
9
+ readonly TriggerResumed: "control-plane.trigger-resumed";
10
+ readonly TriggerInvocationFinished: "control-plane.trigger-invocation-finished";
5
11
  readonly TriggerInvocationStarted: "control-plane.trigger-invocation-started";
6
12
  readonly DispatchPaused: "control-plane.dispatch-paused";
7
13
  readonly DispatchResumed: "control-plane.dispatch-resumed";
@@ -13,11 +19,15 @@ export declare const RunnerPauseCause: {
13
19
  readonly Quota: "quota";
14
20
  };
15
21
  export declare const ControlEventNamespace: "control-plane.";
22
+ export declare const TriggerRequestDisposition: {
23
+ readonly Coalesced: "coalesced";
24
+ readonly Skipped: "skipped";
25
+ };
16
26
  export declare const TriggerSourceKind: {
17
27
  readonly Event: "event";
18
28
  readonly Cron: "cron";
19
29
  };
20
- declare const triggerSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ export declare const triggerSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
21
31
  kind: z.ZodLiteral<"event">;
22
32
  eventId: z.ZodString;
23
33
  eventType: z.ZodString;
@@ -27,8 +37,43 @@ declare const triggerSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
27
37
  }, z.core.$strict>], "kind">;
28
38
  export type TriggerSource = z.infer<typeof triggerSourceSchema>;
29
39
  export interface ControlEventPayloads {
40
+ readonly [ControlEventType.TriggerRequestRecorded]: {
41
+ readonly triggerId: string;
42
+ readonly coordinationKey: string;
43
+ readonly source: TriggerSource;
44
+ readonly disposition: (typeof TriggerRequestDisposition)[keyof typeof TriggerRequestDisposition];
45
+ };
46
+ readonly [ControlEventType.TriggerInvocationClaimed]: {
47
+ readonly triggerId: string;
48
+ readonly coordinationKey: string;
49
+ readonly source: TriggerSource;
50
+ readonly sources: readonly TriggerSource[];
51
+ readonly workItemId: string;
52
+ readonly workflowInstanceId: string;
53
+ readonly workflowName: string;
54
+ };
55
+ readonly [ControlEventType.TriggerPaused]: {
56
+ readonly triggerId: string;
57
+ readonly reason: string;
58
+ readonly coordinationKey: string;
59
+ readonly workflowInstanceId?: string | undefined;
60
+ readonly outcomeCount?: number | undefined;
61
+ };
62
+ readonly [ControlEventType.TriggerResumed]: {
63
+ readonly triggerId: string;
64
+ readonly coordinationKey: string;
65
+ };
66
+ readonly [ControlEventType.TriggerInvocationFinished]: {
67
+ readonly triggerId: string;
68
+ readonly workflowInstanceId: string;
69
+ readonly workItemId: string;
70
+ readonly coordinationKey: string;
71
+ readonly status: typeof WorkflowStatus.Completed | typeof WorkflowStatus.Superseded;
72
+ readonly reason?: string | undefined;
73
+ };
30
74
  readonly [ControlEventType.TriggerInvocationStarted]: {
31
75
  readonly triggerId: string;
76
+ readonly coordinationKey: string;
32
77
  readonly source: TriggerSource;
33
78
  readonly workItemId: string;
34
79
  readonly workflowInstanceId: string;
@@ -52,7 +97,9 @@ export interface ControlEventPayloads {
52
97
  readonly resumedAt: string;
53
98
  };
54
99
  }
55
- export type ControlEvent = EventUnion<ControlEventPayloads, ControlStreamRef>;
100
+ type InvocationEventType = typeof ControlEventType.TriggerInvocationClaimed | typeof ControlEventType.TriggerInvocationStarted | typeof ControlEventType.TriggerInvocationFinished;
101
+ type TriggerEventType = typeof ControlEventType.TriggerRequestRecorded | typeof ControlEventType.TriggerPaused | typeof ControlEventType.TriggerResumed;
102
+ export type ControlEvent = EventUnion<Pick<ControlEventPayloads, InvocationEventType>, TriggerInvocationStreamRef> | EventUnion<Pick<ControlEventPayloads, TriggerEventType>, TriggerControlStreamRef> | EventUnion<Omit<ControlEventPayloads, InvocationEventType | TriggerEventType>, GlobalControlStreamRef>;
56
103
  export type ControlEventData = EventDataUnion<ControlEventPayloads>;
57
104
  export declare function decodeControlEvent(event: EventEnvelope): ControlEvent;
58
105
  export declare function selectControlEvent(event: EventEnvelope): ControlEvent | null;
@@ -1,7 +1,13 @@
1
1
  import { eventDataSchema, eventEnvelopeSchema, } from '@atolis-hq/eventing';
2
2
  import { z } from 'zod';
3
- import { ControlStreamKind } from './streams.js';
3
+ import { WorkflowStatus } from '../../orchestration/index.js';
4
+ import { ControlStreamKind, } from './streams.js';
4
5
  export const ControlEventType = {
6
+ TriggerRequestRecorded: 'control-plane.trigger-request-recorded',
7
+ TriggerInvocationClaimed: 'control-plane.trigger-invocation-claimed',
8
+ TriggerPaused: 'control-plane.trigger-paused',
9
+ TriggerResumed: 'control-plane.trigger-resumed',
10
+ TriggerInvocationFinished: 'control-plane.trigger-invocation-finished',
5
11
  TriggerInvocationStarted: 'control-plane.trigger-invocation-started',
6
12
  DispatchPaused: 'control-plane.dispatch-paused',
7
13
  DispatchResumed: 'control-plane.dispatch-resumed',
@@ -10,8 +16,9 @@ export const ControlEventType = {
10
16
  };
11
17
  export const RunnerPauseCause = { Manual: 'manual', Quota: 'quota' };
12
18
  export const ControlEventNamespace = 'control-plane.';
19
+ export const TriggerRequestDisposition = { Coalesced: 'coalesced', Skipped: 'skipped' };
13
20
  export const TriggerSourceKind = { Event: 'event', Cron: 'cron' };
14
- const triggerSourceSchema = z.discriminatedUnion('kind', [
21
+ export const triggerSourceSchema = z.discriminatedUnion('kind', [
15
22
  z
16
23
  .object({
17
24
  kind: z.literal(TriggerSourceKind.Event),
@@ -29,13 +36,94 @@ const triggerSourceSchema = z.discriminatedUnion('kind', [
29
36
  const streamSchema = z
30
37
  .object({ kind: z.literal(ControlStreamKind.Global), id: z.literal('global') })
31
38
  .strict();
39
+ const triggerStreamSchema = z
40
+ .object({ kind: z.literal(ControlStreamKind.Trigger), id: z.string().min(1) })
41
+ .strict();
42
+ const invocationStreamSchema = z
43
+ .object({ kind: z.literal(ControlStreamKind.TriggerInvocation), id: z.string().min(1) })
44
+ .strict();
32
45
  const eventSchema = z.union([
46
+ eventEnvelopeSchema.extend({
47
+ event: eventDataSchema.extend({
48
+ eventType: z.literal(ControlEventType.TriggerRequestRecorded),
49
+ payload: z
50
+ .object({
51
+ triggerId: z.string().min(1),
52
+ coordinationKey: z.string().min(1),
53
+ source: triggerSourceSchema,
54
+ disposition: z.enum(TriggerRequestDisposition),
55
+ })
56
+ .strict(),
57
+ }),
58
+ stream: triggerStreamSchema,
59
+ }),
60
+ eventEnvelopeSchema.extend({
61
+ event: eventDataSchema.extend({
62
+ eventType: z.literal(ControlEventType.TriggerInvocationClaimed),
63
+ payload: z
64
+ .object({
65
+ triggerId: z.string().min(1),
66
+ coordinationKey: z.string().min(1),
67
+ source: triggerSourceSchema,
68
+ sources: z.array(triggerSourceSchema).min(1),
69
+ workItemId: z.string().min(1),
70
+ workflowInstanceId: z.string().min(1),
71
+ workflowName: z.string().min(1),
72
+ })
73
+ .strict(),
74
+ }),
75
+ stream: invocationStreamSchema,
76
+ }),
77
+ eventEnvelopeSchema.extend({
78
+ event: eventDataSchema.extend({
79
+ eventType: z.literal(ControlEventType.TriggerPaused),
80
+ payload: z
81
+ .object({
82
+ triggerId: z.string().min(1),
83
+ coordinationKey: z.string().min(1),
84
+ reason: z.string().min(1),
85
+ workflowInstanceId: z.string().min(1).optional(),
86
+ outcomeCount: z.number().int().nonnegative().optional(),
87
+ })
88
+ .strict()
89
+ .refine((value) => (value.workflowInstanceId === undefined) === (value.outcomeCount === undefined), {
90
+ message: 'Failure pause requires both workflow identity and outcome count',
91
+ }),
92
+ }),
93
+ stream: triggerStreamSchema,
94
+ }),
95
+ eventEnvelopeSchema.extend({
96
+ event: eventDataSchema.extend({
97
+ eventType: z.literal(ControlEventType.TriggerResumed),
98
+ payload: z
99
+ .object({ triggerId: z.string().min(1), coordinationKey: z.string().min(1) })
100
+ .strict(),
101
+ }),
102
+ stream: triggerStreamSchema,
103
+ }),
104
+ eventEnvelopeSchema.extend({
105
+ event: eventDataSchema.extend({
106
+ eventType: z.literal(ControlEventType.TriggerInvocationFinished),
107
+ payload: z
108
+ .object({
109
+ triggerId: z.string().min(1),
110
+ workflowInstanceId: z.string().min(1),
111
+ workItemId: z.string().min(1),
112
+ coordinationKey: z.string().min(1),
113
+ status: z.enum([WorkflowStatus.Completed, WorkflowStatus.Superseded]),
114
+ reason: z.string().optional(),
115
+ })
116
+ .strict(),
117
+ }),
118
+ stream: invocationStreamSchema,
119
+ }),
33
120
  eventEnvelopeSchema.extend({
34
121
  event: eventDataSchema.extend({
35
122
  eventType: z.literal(ControlEventType.TriggerInvocationStarted),
36
123
  payload: z
37
124
  .object({
38
125
  triggerId: z.string().min(1),
126
+ coordinationKey: z.string().min(1),
39
127
  source: triggerSourceSchema,
40
128
  workItemId: z.string().min(1),
41
129
  workflowInstanceId: z.string().min(1),
@@ -43,7 +131,7 @@ const eventSchema = z.union([
43
131
  })
44
132
  .strict(),
45
133
  }),
46
- stream: streamSchema,
134
+ stream: invocationStreamSchema,
47
135
  }),
48
136
  eventEnvelopeSchema.extend({
49
137
  event: eventDataSchema.extend({
@@ -101,7 +189,15 @@ export function decodeControlEvent(event) {
101
189
  throw new Error(`Invalid Control Plane event ${event.event.eventId}: ${result.error.message}`, {
102
190
  cause: result.error,
103
191
  });
104
- return result.data;
192
+ const decoded = result.data;
193
+ if ('workItemId' in decoded.event.payload &&
194
+ decoded.stream.id !== decoded.event.payload.workItemId)
195
+ throw new Error(`Invalid Control Plane event ${event.event.eventId}: invocation stream identity mismatch`);
196
+ if (decoded.stream.kind === ControlStreamKind.Trigger &&
197
+ 'coordinationKey' in decoded.event.payload &&
198
+ decoded.stream.id !== decoded.event.payload.coordinationKey)
199
+ throw new Error(`Invalid Control Plane event ${event.event.eventId}: coordination stream identity mismatch`);
200
+ return decoded;
105
201
  }
106
202
  export function selectControlEvent(event) {
107
203
  return event.event.eventType.startsWith(ControlEventNamespace) ? decodeControlEvent(event) : null;
@@ -1,6 +1,13 @@
1
1
  import type { EntityRef } from '../../kernel/index.js';
2
2
  export declare const ControlStreamKind: {
3
3
  readonly Global: "control-plane";
4
+ readonly Trigger: "control-plane-trigger";
5
+ readonly TriggerInvocation: "control-plane-trigger-invocation";
4
6
  };
5
- export type ControlStreamRef = EntityRef<typeof ControlStreamKind.Global, 'global'>;
6
- export declare const controlPlaneStream: () => ControlStreamRef;
7
+ export type GlobalControlStreamRef = EntityRef<typeof ControlStreamKind.Global, 'global'>;
8
+ export type TriggerControlStreamRef = EntityRef<typeof ControlStreamKind.Trigger>;
9
+ export type TriggerInvocationStreamRef = EntityRef<typeof ControlStreamKind.TriggerInvocation>;
10
+ export type ControlStreamRef = GlobalControlStreamRef | TriggerControlStreamRef | TriggerInvocationStreamRef;
11
+ export declare const controlPlaneStream: () => GlobalControlStreamRef;
12
+ export declare const triggerControlStream: (coordinationKey: string) => TriggerControlStreamRef;
13
+ export declare const triggerInvocationStream: (workItemId: string) => TriggerInvocationStreamRef;
@@ -1,5 +1,17 @@
1
- export const ControlStreamKind = { Global: 'control-plane' };
1
+ export const ControlStreamKind = {
2
+ Global: 'control-plane',
3
+ Trigger: 'control-plane-trigger',
4
+ TriggerInvocation: 'control-plane-trigger-invocation',
5
+ };
2
6
  export const controlPlaneStream = () => ({
3
7
  kind: ControlStreamKind.Global,
4
8
  id: 'global',
5
9
  });
10
+ export const triggerControlStream = (coordinationKey) => ({
11
+ kind: ControlStreamKind.Trigger,
12
+ id: coordinationKey,
13
+ });
14
+ export const triggerInvocationStream = (workItemId) => ({
15
+ kind: ControlStreamKind.TriggerInvocation,
16
+ id: workItemId,
17
+ });
@@ -6,5 +6,5 @@ export declare class CronTriggerPolicy {
6
6
  elapsedSlots(config: {
7
7
  readonly id: string;
8
8
  readonly cron: string;
9
- }, now: string, checkpoint: string | null): readonly CronTriggerSlot[];
9
+ }, now: string, checkpoint: string | null, maximumSlots?: number): readonly CronTriggerSlot[];
10
10
  }
@@ -1,6 +1,6 @@
1
1
  import { CronExpressionParser } from 'cron-parser';
2
2
  export class CronTriggerPolicy {
3
- elapsedSlots(config, now, checkpoint) {
3
+ elapsedSlots(config, now, checkpoint, maximumSlots = Number.POSITIVE_INFINITY) {
4
4
  const end = minute(new Date(now));
5
5
  const start = checkpoint === null ? end : minute(new Date(new Date(checkpoint).getTime() + 60_000));
6
6
  if (start > end)
@@ -24,6 +24,8 @@ export class CronTriggerPolicy {
24
24
  continue;
25
25
  const at = date.toISOString();
26
26
  slots.push({ identity: `trigger:${config.id}:cron:${at}`, at });
27
+ if (slots.length >= maximumSlots)
28
+ break;
27
29
  }
28
30
  return slots;
29
31
  }
@@ -5,6 +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/trigger-reactor.js';
8
9
  export * from './application/trigger-service.js';
9
10
  export * from './application/intake-pipeline.js';
10
11
  export * from './application/runner-pipeline.js';
@@ -22,3 +23,5 @@ export * from './domain/cron-trigger-policy.js';
22
23
  export * from './infrastructure/intake-host.js';
23
24
  export * from './infrastructure/resident-host.js';
24
25
  export * from './infrastructure/tick-host.js';
26
+ export * from './application/trigger-invocation-projection.js';
27
+ export * from './application/trigger-projection.js';
@@ -4,6 +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/trigger-reactor.js';
7
8
  export * from './application/trigger-service.js';
8
9
  export * from './application/intake-pipeline.js';
9
10
  export * from './application/runner-pipeline.js';
@@ -21,3 +22,5 @@ export * from './domain/cron-trigger-policy.js';
21
22
  export * from './infrastructure/intake-host.js';
22
23
  export * from './infrastructure/resident-host.js';
23
24
  export * from './infrastructure/tick-host.js';
25
+ export * from './application/trigger-invocation-projection.js';
26
+ export * from './application/trigger-projection.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/wake",
3
- "version": "0.4.61",
3
+ "version": "0.4.62",
4
4
  "description": "Local autonomous agent control plane for software development",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {