@atolis-hq/wake 0.4.61 → 0.4.63

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 (65) 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/config/root-schema.d.ts +2 -2
  4. package/dist/src/bootstrap/integration-runtime.d.ts +4 -2
  5. package/dist/src/bootstrap/integration-runtime.js +74 -13
  6. package/dist/src/bootstrap/surface-api-applications.js +2 -0
  7. package/dist/src/bootstrap/surface-api-trigger-applications.d.ts +3 -0
  8. package/dist/src/bootstrap/surface-api-trigger-applications.js +79 -0
  9. package/dist/src/bootstrap/surface-api-work-applications.js +8 -0
  10. package/dist/src/bootstrap/trigger-checkpoint-store.d.ts +5 -5
  11. package/dist/src/bootstrap/trigger-checkpoint-store.js +15 -40
  12. package/dist/src/bootstrap/version.js +1 -1
  13. package/dist/src/control-plane/application/control-plane-projection.js +11 -1
  14. package/dist/src/control-plane/application/runner-pipeline.js +0 -2
  15. package/dist/src/control-plane/application/trigger-diagnostics.d.ts +33 -0
  16. package/dist/src/control-plane/application/trigger-diagnostics.js +38 -0
  17. package/dist/src/control-plane/application/trigger-facts.d.ts +11 -0
  18. package/dist/src/control-plane/application/trigger-facts.js +38 -0
  19. package/dist/src/control-plane/application/trigger-invocation-projection.d.ts +4 -0
  20. package/dist/src/control-plane/application/trigger-invocation-projection.js +32 -0
  21. package/dist/src/control-plane/application/trigger-projection.d.ts +24 -0
  22. package/dist/src/control-plane/application/trigger-projection.js +98 -0
  23. package/dist/src/control-plane/application/trigger-reactor.d.ts +4 -0
  24. package/dist/src/control-plane/application/trigger-reactor.js +30 -0
  25. package/dist/src/control-plane/application/trigger-recovery.d.ts +10 -0
  26. package/dist/src/control-plane/application/trigger-recovery.js +61 -0
  27. package/dist/src/control-plane/application/trigger-rules.d.ts +19 -0
  28. package/dist/src/control-plane/application/trigger-rules.js +38 -0
  29. package/dist/src/control-plane/application/trigger-service-ports.d.ts +21 -0
  30. package/dist/src/control-plane/application/trigger-service-ports.js +1 -0
  31. package/dist/src/control-plane/application/trigger-service.d.ts +29 -27
  32. package/dist/src/control-plane/application/trigger-service.js +188 -101
  33. package/dist/src/control-plane/application/trigger-source-cursor.d.ts +16 -0
  34. package/dist/src/control-plane/application/trigger-source-cursor.js +35 -0
  35. package/dist/src/control-plane/application/trigger-state-reader.d.ts +13 -0
  36. package/dist/src/control-plane/application/trigger-state-reader.js +34 -0
  37. package/dist/src/control-plane/application/trigger-workflow.d.ts +17 -0
  38. package/dist/src/control-plane/application/trigger-workflow.js +18 -0
  39. package/dist/src/control-plane/contracts/event-factory.js +10 -0
  40. package/dist/src/control-plane/contracts/events.d.ts +50 -3
  41. package/dist/src/control-plane/contracts/events.js +100 -4
  42. package/dist/src/control-plane/contracts/streams.d.ts +9 -2
  43. package/dist/src/control-plane/contracts/streams.js +13 -1
  44. package/dist/src/control-plane/contracts/trigger-diagnostics.d.ts +53 -0
  45. package/dist/src/control-plane/contracts/trigger-diagnostics.js +23 -0
  46. package/dist/src/control-plane/domain/cron-trigger-policy.d.ts +2 -1
  47. package/dist/src/control-plane/domain/cron-trigger-policy.js +14 -1
  48. package/dist/src/control-plane/index.d.ts +4 -0
  49. package/dist/src/control-plane/index.js +4 -0
  50. package/dist/src/orchestration/contracts/config.d.ts +2 -2
  51. package/dist/src/surfaces/api/contracts/index.d.ts +1 -0
  52. package/dist/src/surfaces/api/contracts/index.js +1 -0
  53. package/dist/src/surfaces/api/contracts/transport-values.d.ts +8 -0
  54. package/dist/src/surfaces/api/contracts/transport-values.js +23 -0
  55. package/dist/src/surfaces/api/contracts/triggers.d.ts +22 -0
  56. package/dist/src/surfaces/api/contracts/triggers.js +8 -0
  57. package/dist/src/surfaces/api/contracts/work.d.ts +1 -0
  58. package/dist/src/surfaces/api/contracts/workflow-diagram.d.ts +4 -4
  59. package/dist/src/surfaces/api/routes/applications.d.ts +7 -1
  60. package/dist/src/surfaces/api/routes/commands.js +10 -0
  61. package/dist/src/surfaces/api/routes/read.js +16 -0
  62. package/dist/src/surfaces/web-assets/assets/index-9IfrHvBo.js +1192 -0
  63. package/dist/src/surfaces/web-assets/index.html +1 -1
  64. package/package.json +1 -1
  65. package/dist/src/surfaces/web-assets/assets/index-CCvwzTeC.js +0 -1131
@@ -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
+ });
@@ -0,0 +1,53 @@
1
+ import { z } from 'zod';
2
+ import type { ValueOf } from '../../kernel/index.js';
3
+ export declare const TriggerSkipReason: {
4
+ readonly OwnScope: "own-scope";
5
+ readonly Paused: "paused";
6
+ readonly Removed: "removed";
7
+ readonly DispatchPaused: "dispatch-paused";
8
+ readonly Capacity: "capacity-unavailable";
9
+ readonly PendingLimit: "pending-source-limit";
10
+ };
11
+ export type TriggerSkipReason = ValueOf<typeof TriggerSkipReason>;
12
+ export declare const triggerSkipDiagnosticSchema: z.ZodObject<{
13
+ triggerId: z.ZodString;
14
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
+ kind: z.ZodLiteral<"event">;
16
+ eventId: z.ZodString;
17
+ eventType: z.ZodString;
18
+ }, z.core.$strict>, z.ZodObject<{
19
+ kind: z.ZodLiteral<"cron">;
20
+ slot: z.ZodString;
21
+ }, z.core.$strict>], "kind">;
22
+ occurredAt: z.ZodString;
23
+ reason: z.ZodEnum<{
24
+ readonly OwnScope: "own-scope";
25
+ readonly Paused: "paused";
26
+ readonly Removed: "removed";
27
+ readonly DispatchPaused: "dispatch-paused";
28
+ readonly Capacity: "capacity-unavailable";
29
+ readonly PendingLimit: "pending-source-limit";
30
+ }>;
31
+ }, z.core.$strict>;
32
+ export type TriggerSkipDiagnostic = z.infer<typeof triggerSkipDiagnosticSchema>;
33
+ export declare const maximumTriggerDiagnostics = 256;
34
+ export declare const triggerDiagnosticsSchema: z.ZodArray<z.ZodObject<{
35
+ triggerId: z.ZodString;
36
+ source: z.ZodDiscriminatedUnion<[z.ZodObject<{
37
+ kind: z.ZodLiteral<"event">;
38
+ eventId: z.ZodString;
39
+ eventType: z.ZodString;
40
+ }, z.core.$strict>, z.ZodObject<{
41
+ kind: z.ZodLiteral<"cron">;
42
+ slot: z.ZodString;
43
+ }, z.core.$strict>], "kind">;
44
+ occurredAt: z.ZodString;
45
+ reason: z.ZodEnum<{
46
+ readonly OwnScope: "own-scope";
47
+ readonly Paused: "paused";
48
+ readonly Removed: "removed";
49
+ readonly DispatchPaused: "dispatch-paused";
50
+ readonly Capacity: "capacity-unavailable";
51
+ readonly PendingLimit: "pending-source-limit";
52
+ }>;
53
+ }, z.core.$strict>>;
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import { triggerSourceSchema } from './events.js';
3
+ export const TriggerSkipReason = {
4
+ OwnScope: 'own-scope',
5
+ Paused: 'paused',
6
+ Removed: 'removed',
7
+ DispatchPaused: 'dispatch-paused',
8
+ Capacity: 'capacity-unavailable',
9
+ PendingLimit: 'pending-source-limit',
10
+ };
11
+ export const triggerSkipDiagnosticSchema = z
12
+ .object({
13
+ triggerId: z.string().min(1),
14
+ source: triggerSourceSchema,
15
+ occurredAt: z.string().datetime({ offset: true }),
16
+ reason: z.enum(TriggerSkipReason),
17
+ })
18
+ .strict();
19
+ // Operational diagnostics are bounded processor state, not occurrence history.
20
+ export const maximumTriggerDiagnostics = 256;
21
+ export const triggerDiagnosticsSchema = z
22
+ .array(triggerSkipDiagnosticSchema)
23
+ .max(maximumTriggerDiagnostics);
@@ -3,8 +3,9 @@ export interface CronTriggerSlot {
3
3
  readonly at: string;
4
4
  }
5
5
  export declare class CronTriggerPolicy {
6
+ nextOccurrence(cron: string, now: string): string;
6
7
  elapsedSlots(config: {
7
8
  readonly id: string;
8
9
  readonly cron: string;
9
- }, now: string, checkpoint: string | null): readonly CronTriggerSlot[];
10
+ }, now: string, checkpoint: string | null, maximumSlots?: number): readonly CronTriggerSlot[];
10
11
  }
@@ -1,6 +1,17 @@
1
1
  import { CronExpressionParser } from 'cron-parser';
2
2
  export class CronTriggerPolicy {
3
- elapsedSlots(config, now, checkpoint) {
3
+ nextOccurrence(cron, now) {
4
+ const fields = cron.trim().split(/\s+/);
5
+ const expression = CronExpressionParser.parse(cron, { currentDate: now, tz: 'UTC' });
6
+ const dayOfMonth = fieldExpression(fields, 2, 4);
7
+ const dayOfWeek = fieldExpression(fields, 4, 2);
8
+ while (true) {
9
+ const date = expression.next().toDate();
10
+ if (matchesDays(date, dayOfMonth, dayOfWeek))
11
+ return date.toISOString();
12
+ }
13
+ }
14
+ elapsedSlots(config, now, checkpoint, maximumSlots = Number.POSITIVE_INFINITY) {
4
15
  const end = minute(new Date(now));
5
16
  const start = checkpoint === null ? end : minute(new Date(new Date(checkpoint).getTime() + 60_000));
6
17
  if (start > end)
@@ -24,6 +35,8 @@ export class CronTriggerPolicy {
24
35
  continue;
25
36
  const at = date.toISOString();
26
37
  slots.push({ identity: `trigger:${config.id}:cron:${at}`, at });
38
+ if (slots.length >= maximumSlots)
39
+ break;
27
40
  }
28
41
  return slots;
29
42
  }
@@ -5,10 +5,12 @@ 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';
11
12
  export * from './application/work-cancellation-policy.js';
13
+ export * from './contracts/trigger-diagnostics.js';
12
14
  export * from './contracts/commands.js';
13
15
  export * from './contracts/config.js';
14
16
  export * from './contracts/events.js';
@@ -22,3 +24,5 @@ export * from './domain/cron-trigger-policy.js';
22
24
  export * from './infrastructure/intake-host.js';
23
25
  export * from './infrastructure/resident-host.js';
24
26
  export * from './infrastructure/tick-host.js';
27
+ export * from './application/trigger-invocation-projection.js';
28
+ export * from './application/trigger-projection.js';
@@ -4,10 +4,12 @@ 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';
10
11
  export * from './application/work-cancellation-policy.js';
12
+ export * from './contracts/trigger-diagnostics.js';
11
13
  export * from './contracts/commands.js';
12
14
  export * from './contracts/config.js';
13
15
  export * from './contracts/events.js';
@@ -21,3 +23,5 @@ export * from './domain/cron-trigger-policy.js';
21
23
  export * from './infrastructure/intake-host.js';
22
24
  export * from './infrastructure/resident-host.js';
23
25
  export * from './infrastructure/tick-host.js';
26
+ export * from './application/trigger-invocation-projection.js';
27
+ export * from './application/trigger-projection.js';
@@ -173,8 +173,8 @@ export declare const supplementalCommandConfigSchema: z.ZodObject<{
173
173
  with: z.ZodOptional<z.ZodUnknown>;
174
174
  allowedActors: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
175
175
  human: "human";
176
- watch: "watch";
177
176
  auto: "auto";
177
+ watch: "watch";
178
178
  }>>>;
179
179
  }, z.core.$strict>;
180
180
  export declare const workflowDefinitionConfigSchema: z.ZodObject<{
@@ -184,8 +184,8 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
184
184
  with: z.ZodOptional<z.ZodUnknown>;
185
185
  allowedActors: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
186
186
  human: "human";
187
- watch: "watch";
188
187
  auto: "auto";
188
+ watch: "watch";
189
189
  }>>>;
190
190
  }, z.core.$strict>>>;
191
191
  watches: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
@@ -10,5 +10,6 @@ export * from './resources.js';
10
10
  export * from './system.js';
11
11
  export * from './status.js';
12
12
  export * from './transport-values.js';
13
+ export * from './triggers.js';
13
14
  export * from './work.js';
14
15
  export * from './workflow-diagram.js';
@@ -10,5 +10,6 @@ export * from './resources.js';
10
10
  export * from './system.js';
11
11
  export * from './status.js';
12
12
  export * from './transport-values.js';
13
+ export * from './triggers.js';
13
14
  export * from './work.js';
14
15
  export * from './workflow-diagram.js';
@@ -1,4 +1,5 @@
1
1
  import type { ActivityOutcomeKind } from '../../../activities/index.js';
2
+ import type { TriggerRequestDisposition, TriggerSkipReason, TriggerSourceKind } from '../../../control-plane/index.js';
2
3
  import type { RunStatus } from '../../../execution/index.js';
3
4
  import type { ApiCommandStatus } from './control-plane.js';
4
5
  export declare const AcceptedCommandStatusValue: {
@@ -42,4 +43,11 @@ export declare const TranscriptGroupKindValue: {
42
43
  readonly Session: string;
43
44
  readonly Run: string;
44
45
  };
46
+ export declare const TriggerSourceKindValue: typeof TriggerSourceKind;
47
+ export declare const TriggerRequestDispositionValue: typeof TriggerRequestDisposition;
48
+ export declare const TriggerSkipReasonValue: typeof TriggerSkipReason;
49
+ export declare const TriggerFinishedStatusValue: {
50
+ readonly Completed: "completed" | "superseded";
51
+ readonly Superseded: "completed" | "superseded";
52
+ };
45
53
  export {};
@@ -58,3 +58,26 @@ export const TranscriptGroupKindValue = {
58
58
  Session: transcriptGroupKinds[0],
59
59
  Run: transcriptGroupKinds[1],
60
60
  };
61
+ // Trigger transport vocabulary avoids importing the server implementation into the browser.
62
+ export const TriggerSourceKindValue = {
63
+ Event: 'event',
64
+ Cron: 'cron',
65
+ };
66
+ export const TriggerRequestDispositionValue = {
67
+ Coalesced: 'coalesced',
68
+ Skipped: 'skipped',
69
+ };
70
+ export const TriggerSkipReasonValue = {
71
+ OwnScope: 'own-scope',
72
+ Paused: 'paused',
73
+ Removed: 'removed',
74
+ DispatchPaused: 'dispatch-paused',
75
+ Capacity: 'capacity-unavailable',
76
+ PendingLimit: 'pending-source-limit',
77
+ };
78
+ const triggerFinishedStatusShape = { completed: true, superseded: true };
79
+ const triggerFinishedStatuses = Object.keys(triggerFinishedStatusShape);
80
+ export const TriggerFinishedStatusValue = {
81
+ Completed: triggerFinishedStatuses[0],
82
+ Superseded: triggerFinishedStatuses[1],
83
+ };
@@ -0,0 +1,22 @@
1
+ import type { TriggerConfig, TriggerInvocationView, TriggerSkipDiagnostic, TriggerView } from '../../../control-plane/index.js';
2
+ import type { ValueOf } from '../../../kernel/index.js';
3
+ export declare const TriggerStatus: {
4
+ readonly Enabled: "running" | "paused" | "removed" | "enabled";
5
+ readonly Paused: "running" | "paused" | "removed" | "enabled";
6
+ readonly Running: "running" | "paused" | "removed" | "enabled";
7
+ readonly Removed: "running" | "paused" | "removed" | "enabled";
8
+ };
9
+ export type TriggerStatus = ValueOf<typeof TriggerStatus>;
10
+ export interface TriggerResponse {
11
+ readonly triggerId: string;
12
+ readonly status: TriggerStatus;
13
+ readonly definition: TriggerConfig | null;
14
+ readonly paused: boolean;
15
+ readonly pauseReason: string | null;
16
+ readonly nextOccurrence: string | null;
17
+ readonly pending: readonly TriggerView['coalesced'][string][];
18
+ readonly latestSkip: TriggerSkipDiagnostic | null;
19
+ readonly invocations: readonly (TriggerInvocationView & {
20
+ readonly workItemKey: string;
21
+ })[];
22
+ }
@@ -0,0 +1,8 @@
1
+ const triggerStatusShape = { enabled: true, paused: true, running: true, removed: true };
2
+ const triggerStatuses = Object.keys(triggerStatusShape);
3
+ export const TriggerStatus = {
4
+ Enabled: triggerStatuses[0],
5
+ Paused: triggerStatuses[1],
6
+ Running: triggerStatuses[2],
7
+ Removed: triggerStatuses[3],
8
+ };
@@ -19,6 +19,7 @@ export interface WorkItemResponse {
19
19
  readonly lastRunOutcome?: string;
20
20
  }
21
21
  export interface WorkDetailResponse {
22
+ readonly triggerOrigin?: string;
22
23
  readonly work: WorkItemResponse;
23
24
  readonly resources: readonly ResourceItemResponse[];
24
25
  readonly orchestration: {
@@ -7,10 +7,10 @@ export declare const WorkflowDiagramStatus: {
7
7
  };
8
8
  export type WorkflowDiagramStatus = ValueOf<typeof WorkflowDiagramStatus>;
9
9
  export declare const WorkflowDiagramChildKind: {
10
- readonly Activity: "activity" | "watch" | "watch-gate" | "reactor";
11
- readonly Watch: "activity" | "watch" | "watch-gate" | "reactor";
12
- readonly WatchGate: "activity" | "watch" | "watch-gate" | "reactor";
13
- readonly Reactor: "activity" | "watch" | "watch-gate" | "reactor";
10
+ readonly Activity: "activity" | "watch" | "reactor" | "watch-gate";
11
+ readonly Watch: "activity" | "watch" | "reactor" | "watch-gate";
12
+ readonly WatchGate: "activity" | "watch" | "reactor" | "watch-gate";
13
+ readonly Reactor: "activity" | "watch" | "reactor" | "watch-gate";
14
14
  };
15
15
  export type WorkflowDiagramChildKind = ValueOf<typeof WorkflowDiagramChildKind>;
16
16
  export interface WorkflowDiagramMetricsResponse {
@@ -1,6 +1,6 @@
1
1
  import type { RunStatus } from '../../../execution/index.js';
2
2
  import type { AnalyticsReport, ReportDescriptor, ReportWindowId } from '../../../kernel/index.js';
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';
3
+ import type { ApiCommandResult, AuditEventResponse, BoardCardResponse, BoardResponse, CommandsResponse, ConfigurationResponse, ControlPlaneStatusResponse, ConversationMessageRequest, HealthResponse, MetricsResponse, ResourceItemResponse, ResourceResponse, ResponseMeta, RunnerResponse, RunResponse, RunTranscriptResponse, StatusResponse, TriggerResponse, WebhookSetupResponse, WorkDetailResponse, WorkflowDiagramsResponse, WorkflowInstanceResponse, WorkItemResponse, WorkItemTranscriptResponse } from '../contracts/index.js';
4
4
  import type { AnalyticsSummaryResponse } from '../contracts/observability.js';
5
5
  export interface CollectionQuery {
6
6
  readonly cursor?: {
@@ -54,6 +54,12 @@ export interface ApiApplications {
54
54
  resumeDispatch?(command: ApiCommandRequest): Promise<ApiCommandResult>;
55
55
  clearMaintenance?(command: ApiClearMaintenanceRequest): Promise<ApiCommandResult>;
56
56
  };
57
+ readonly triggers?: {
58
+ list(): Promise<ApiResourceResult<readonly TriggerResponse[]>>;
59
+ detail(id: string): Promise<ApiResourceResult<TriggerResponse> | undefined>;
60
+ pause(id: string, command: ApiCommandRequest): Promise<ApiCommandResult>;
61
+ resume(id: string, command: ApiCommandRequest): Promise<ApiCommandResult>;
62
+ };
57
63
  readonly work: {
58
64
  list(query: CollectionQuery): Promise<ApiCollectionPage<WorkItemResponse>>;
59
65
  detail(key: string): Promise<ApiResourceResult<WorkDetailResponse> | undefined>;
@@ -16,6 +16,16 @@ export async function dispatchCommand(applications, url, body) {
16
16
  const request = commandRequest(body);
17
17
  if (isHttpResponse(request))
18
18
  return request;
19
+ const trigger = /^\/api\/v1\/triggers\/([^/]+)\/commands\/(pause|resume)$/.exec(url.pathname);
20
+ if (trigger !== null) {
21
+ const id = decodePathSegment(trigger[1]);
22
+ if (id instanceof ApiPathError)
23
+ return invalidPath(id.message);
24
+ if (applications.triggers === undefined)
25
+ return unavailable('triggers');
26
+ const operation = trigger[2] === 'pause' ? applications.triggers.pause : applications.triggers.resume;
27
+ return accepted(await operation(id, request), applications.now(), 200);
28
+ }
19
29
  const control = await dispatchControlCommand(applications, url.pathname, request);
20
30
  if (control !== undefined)
21
31
  return control;
@@ -16,6 +16,8 @@ export async function dispatchRead(applications, method, url, signal) {
16
16
  if (url.pathname === '/api/v1/observability/reports' ||
17
17
  url.pathname === '/api/v1/observability/summary')
18
18
  return readReports(applications, url, signal);
19
+ if (url.pathname === '/api/v1/triggers')
20
+ return noQuery(url, () => readTriggers(applications));
19
21
  const resource = await readSingleton(applications, url);
20
22
  if (resource !== undefined)
21
23
  return resource;
@@ -24,6 +26,15 @@ export async function dispatchRead(applications, method, url, signal) {
24
26
  return page;
25
27
  if (url.search !== '')
26
28
  return invalidQuery('This resource does not accept query parameters');
29
+ const trigger = /^\/api\/v1\/triggers\/([^/]+)$/.exec(url.pathname);
30
+ if (trigger !== null) {
31
+ const id = decodePathSegment(trigger[1]);
32
+ if (id instanceof ApiPathError)
33
+ return invalidPath(id.message);
34
+ return applications.triggers === undefined
35
+ ? unavailable('triggers')
36
+ : found(await applications.triggers.detail(id));
37
+ }
27
38
  return readDetail(applications, url.pathname);
28
39
  }
29
40
  async function readSingleton(applications, url) {
@@ -209,3 +220,8 @@ async function readReports(applications, url, signal) {
209
220
  return invalidQuery('Unknown report identifier', 'report');
210
221
  return ok(await reports.report(report, window, signal));
211
222
  }
223
+ async function readTriggers(applications) {
224
+ return applications.triggers === undefined
225
+ ? unavailable('triggers')
226
+ : ok(await applications.triggers.list());
227
+ }