@atolis-hq/wake 0.4.71 → 0.4.73

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 (27) hide show
  1. package/dist/src/bootstrap/surface-api-trigger-applications.js +22 -0
  2. package/dist/src/bootstrap/version.js +1 -1
  3. package/dist/src/control-plane/application/trigger-diagnostics.d.ts +4 -0
  4. package/dist/src/control-plane/application/trigger-facts.d.ts +7 -1
  5. package/dist/src/control-plane/application/trigger-facts.js +20 -2
  6. package/dist/src/control-plane/application/trigger-manual-request.d.ts +19 -0
  7. package/dist/src/control-plane/application/trigger-manual-request.js +125 -0
  8. package/dist/src/control-plane/application/trigger-projection.js +3 -1
  9. package/dist/src/control-plane/application/trigger-service.d.ts +5 -4
  10. package/dist/src/control-plane/application/trigger-service.js +31 -33
  11. package/dist/src/control-plane/contracts/events.d.ts +33 -0
  12. package/dist/src/control-plane/contracts/events.js +41 -2
  13. package/dist/src/control-plane/contracts/trigger-diagnostics.d.ts +9 -10
  14. package/dist/src/control-plane/contracts/trigger-diagnostics.js +2 -8
  15. package/dist/src/control-plane/contracts/trigger-skip-reason.d.ts +10 -0
  16. package/dist/src/control-plane/contracts/trigger-skip-reason.js +8 -0
  17. package/dist/src/surfaces/api/contracts/control-plane.d.ts +2 -0
  18. package/dist/src/surfaces/api/contracts/transport-values.d.ts +4 -1
  19. package/dist/src/surfaces/api/contracts/transport-values.js +15 -0
  20. package/dist/src/surfaces/api/contracts/triggers.d.ts +6 -0
  21. package/dist/src/surfaces/api/contracts/triggers.js +7 -0
  22. package/dist/src/surfaces/api/routes/applications.d.ts +1 -0
  23. package/dist/src/surfaces/api/routes/commands.js +9 -2
  24. package/dist/src/surfaces/web-assets/assets/index-CxURzTmR.js +1192 -0
  25. package/dist/src/surfaces/web-assets/index.html +1 -1
  26. package/package.json +1 -1
  27. package/dist/src/surfaces/web-assets/assets/index-DVapiQjj.js +0 -1192
@@ -146,6 +146,28 @@ export function createTriggerApplications(root, now) {
146
146
  status: ApiCommandStatus.Completed,
147
147
  };
148
148
  },
149
+ async run(id, request) {
150
+ if (!root.config.controlPlane.triggers.some((trigger) => trigger.id === id))
151
+ return {
152
+ conflict: true,
153
+ code: 'trigger-not-found',
154
+ detail: 'Trigger definition is unavailable',
155
+ };
156
+ const context = {
157
+ commandId: 'trigger:' + request.idempotencyKey,
158
+ correlationId: correlationId('trigger:' + request.idempotencyKey),
159
+ occurredAt: now(),
160
+ actor: { kind: EventActorKind.Operator, id: 'web' },
161
+ };
162
+ const triggerOutcome = await root.triggers.requestManual(id, context);
163
+ return {
164
+ commandId: context.commandId,
165
+ idempotencyKey: request.idempotencyKey,
166
+ acceptedAt: now(),
167
+ status: ApiCommandStatus.Completed,
168
+ triggerOutcome,
169
+ };
170
+ },
149
171
  pause: (id, request) => command(id, request, true),
150
172
  resume: (id, request) => command(id, request, false),
151
173
  };
@@ -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.71";
127
+ export const wakeVersion = "v0.4.73";
128
128
  /** The registry-installable version used by packaged sandbox images. */
129
129
  export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
@@ -17,6 +17,10 @@ export declare class TriggerDiagnostics {
17
17
  get(): Promise<{
18
18
  triggerId: string;
19
19
  source: {
20
+ kind: "manual";
21
+ commandId: string;
22
+ operator: string;
23
+ } | {
20
24
  kind: "event";
21
25
  eventId: string;
22
26
  eventType: string;
@@ -1,5 +1,6 @@
1
1
  import { type CommandContext, type EventJournal } from '@atolis-hq/eventing';
2
- import { type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
2
+ import { ControlEventType, type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
3
+ import type { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
3
4
  export type TriggerFactInput = {
4
5
  [Type in keyof ControlEventPayloads]: {
5
6
  readonly eventType: Type;
@@ -9,3 +10,8 @@ export type TriggerFactInput = {
9
10
  export declare function sourceIdentity(source: TriggerSource): string;
10
11
  /** Invocation/command appends check event IDs; source appends use the caught-up scope sequence. */
11
12
  export declare function appendTriggerFact(journal: EventJournal, occurredAt: string, input: TriggerFactInput, context: CommandContext, eventId: string, sequence?: number): Promise<void>;
13
+ export declare function hasTriggerRequest(requests: readonly {
14
+ readonly triggerId: string;
15
+ readonly source: TriggerSource;
16
+ }[], triggerId: string, source: TriggerSource): boolean;
17
+ export declare function consumedTriggerRequest(request: ControlEventPayloads[typeof ControlEventType.TriggerRequestRecorded], reason: TriggerSkipReason): TriggerFactInput;
@@ -1,9 +1,9 @@
1
1
  import { EventSourceKind, WrongExpectedSequenceError, } from '@atolis-hq/eventing';
2
2
  import { createControlPlaneEventData } from '../contracts/event-factory.js';
3
- import { TriggerSourceKind, } from '../contracts/events.js';
3
+ import { ControlEventType, ManualTriggerDisposition, TriggerRequestDisposition, TriggerSourceKind, } from '../contracts/events.js';
4
4
  import { triggerControlStream, triggerInvocationStream } from '../contracts/streams.js';
5
5
  export function sourceIdentity(source) {
6
- return `${source.kind}:${source.kind === TriggerSourceKind.Cron ? source.slot : source.eventId}`;
6
+ return `${source.kind}:${source.kind === TriggerSourceKind.Cron ? source.slot : source.kind === TriggerSourceKind.Manual ? source.commandId : source.eventId}`;
7
7
  }
8
8
  /** Invocation/command appends check event IDs; source appends use the caught-up scope sequence. */
9
9
  export async function appendTriggerFact(journal, occurredAt, input, context, eventId, sequence) {
@@ -36,3 +36,21 @@ export async function appendTriggerFact(journal, occurredAt, input, context, eve
36
36
  }
37
37
  }
38
38
  }
39
+ export function hasTriggerRequest(requests, triggerId, source) {
40
+ return requests.some((request) => request.triggerId === triggerId && sourceIdentity(request.source) === sourceIdentity(source));
41
+ }
42
+ export function consumedTriggerRequest(request, reason) {
43
+ return {
44
+ eventType: ControlEventType.TriggerRequestRecorded,
45
+ payload: {
46
+ triggerId: request.triggerId,
47
+ coordinationKey: request.coordinationKey,
48
+ source: request.source,
49
+ disposition: TriggerRequestDisposition.Skipped,
50
+ manualOutcome: request.manualOutcome !== undefined &&
51
+ request.manualOutcome.disposition !== ManualTriggerDisposition.Skipped
52
+ ? { disposition: ManualTriggerDisposition.Skipped, reason }
53
+ : request.manualOutcome,
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,19 @@
1
+ import type { CommandContext } from '@atolis-hq/eventing';
2
+ import type { TriggerConfig } from '../contracts/config.js';
3
+ import { type ManualTriggerOutcome } from '../contracts/events.js';
4
+ import type { TriggerDiagnostics } from './trigger-diagnostics.js';
5
+ import { type TriggerFactInput } from './trigger-facts.js';
6
+ import { type TriggerView } from './trigger-projection.js';
7
+ import type { TriggerServiceDependencies } from './trigger-service-ports.js';
8
+ interface ManualRequestPorts {
9
+ readonly dependencies: TriggerServiceDependencies;
10
+ readonly diagnostics: TriggerDiagnostics;
11
+ readonly config: TriggerConfig | undefined;
12
+ readonly coordinationKey: () => string;
13
+ readonly view: () => Promise<TriggerView>;
14
+ readonly recover: (context: CommandContext) => Promise<void>;
15
+ readonly advance: (context: CommandContext) => Promise<void>;
16
+ readonly emit: (input: TriggerFactInput, context: CommandContext, eventId: string) => Promise<void>;
17
+ }
18
+ export declare function requestManualTrigger(ports: ManualRequestPorts, triggerId: string, context: CommandContext): Promise<ManualTriggerOutcome>;
19
+ export {};
@@ -0,0 +1,125 @@
1
+ import { ControlEventType, ManualTriggerDisposition, selectControlEvent, TriggerRequestDisposition, TriggerSourceKind, } from '../contracts/events.js';
2
+ import { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
3
+ import { consumedTriggerRequest, sourceIdentity } from './trigger-facts.js';
4
+ import { maximumTriggerSources } from './trigger-projection.js';
5
+ import { hasActiveInvocation } from './trigger-rules.js';
6
+ export async function requestManualTrigger(ports, triggerId, context) {
7
+ await ports.view();
8
+ const coordinationKey = ports.coordinationKey();
9
+ const eventId = `trigger:request:${triggerId}:manual:${context.commandId}`;
10
+ const previous = await recoverManualOutcome(ports, triggerId, context);
11
+ if (previous !== undefined) {
12
+ await ports.recover(context);
13
+ await ports.advance(context);
14
+ return (await recoverManualOutcome(ports, triggerId, context)) ?? previous;
15
+ }
16
+ await ports.recover(context);
17
+ const view = await ports.view();
18
+ const config = ports.config;
19
+ const active = hasActiveInvocation(view, coordinationKey);
20
+ const reason = (await ports.diagnostics.ineligibleReason(view, triggerId, config, config !== undefined, active)) ??
21
+ ((view.coalesced[coordinationKey]?.sources.length ?? 0) >= maximumTriggerSources
22
+ ? TriggerSkipReason.PendingLimit
23
+ : undefined);
24
+ const outcome = reason === undefined
25
+ ? {
26
+ disposition: active
27
+ ? ManualTriggerDisposition.Coalesced
28
+ : ManualTriggerDisposition.Started,
29
+ ...activeWorkItem(view, coordinationKey),
30
+ }
31
+ : { disposition: ManualTriggerDisposition.Skipped, reason };
32
+ const source = {
33
+ kind: TriggerSourceKind.Manual,
34
+ commandId: context.commandId,
35
+ operator: context.actor.id,
36
+ };
37
+ await ports.emit({
38
+ eventType: ControlEventType.TriggerRequestRecorded,
39
+ payload: {
40
+ triggerId,
41
+ coordinationKey,
42
+ source,
43
+ manualOutcome: outcome,
44
+ disposition: reason === undefined
45
+ ? TriggerRequestDisposition.Coalesced
46
+ : TriggerRequestDisposition.Skipped,
47
+ },
48
+ }, context, eventId);
49
+ if (reason !== undefined)
50
+ await ports.diagnostics.record(triggerId, source, reason);
51
+ await ports.advance(context);
52
+ return (await recoverManualOutcome(ports, triggerId, context)) ?? outcome;
53
+ }
54
+ async function recoverManualOutcome(ports, triggerId, context) {
55
+ // Command identity survives changes to the configured coordination scope.
56
+ let position = 0;
57
+ let request;
58
+ let pauseCleared = false;
59
+ const latest = await ports.dependencies.journal.latestGlobalPosition();
60
+ while (position < latest) {
61
+ const batch = await ports.dependencies.journal.readAll(position, 256);
62
+ if (batch.length === 0)
63
+ throw new Error('Manual command journal cursor did not advance');
64
+ for (const envelope of batch) {
65
+ const event = selectControlEvent(envelope);
66
+ request = matchingManualRequest(event, triggerId, context.commandId) ?? request;
67
+ if (event?.event.eventType === ControlEventType.TriggerPaused &&
68
+ event.event.payload.coordinationKey === request?.coordinationKey)
69
+ pauseCleared = true;
70
+ position = envelope.globalPosition;
71
+ }
72
+ }
73
+ return resolvePausedRequest(ports, request, pauseCleared, context);
74
+ }
75
+ async function resolvePausedRequest(ports, request, pauseCleared, context) {
76
+ if (request?.manualOutcome === undefined)
77
+ return undefined;
78
+ if (settledManualOutcome(request.manualOutcome))
79
+ return request.manualOutcome;
80
+ const history = await ports.dependencies.history();
81
+ const invocation = history.find((invocation) => invocation.claim.triggerId === request.triggerId &&
82
+ invocation.claim.sources.some((source) => sourceIdentity(source) === sourceIdentity(request.source)));
83
+ if (request.manualOutcome.disposition === ManualTriggerDisposition.Coalesced &&
84
+ (!pauseCleared || invocation !== undefined))
85
+ return request.manualOutcome;
86
+ if (invocation?.startedAt !== undefined) {
87
+ const outcome = {
88
+ disposition: ManualTriggerDisposition.Started,
89
+ workItemId: invocation.claim.workItemId,
90
+ };
91
+ await ports.emit({
92
+ eventType: ControlEventType.TriggerRequestRecorded,
93
+ payload: {
94
+ ...request,
95
+ disposition: TriggerRequestDisposition.Started,
96
+ manualOutcome: outcome,
97
+ },
98
+ }, context, 'trigger:result:' + request.triggerId + ':' + sourceIdentity(request.source));
99
+ return outcome;
100
+ }
101
+ if (!pauseCleared || invocation !== undefined)
102
+ return request.manualOutcome;
103
+ // Pause clears unclaimed requests, but a committed claim still recovers normally.
104
+ const fact = consumedTriggerRequest(request, TriggerSkipReason.Paused);
105
+ await ports.emit(fact, context, 'trigger:consume:' + request.triggerId + ':' + sourceIdentity(request.source));
106
+ await ports.diagnostics.record(request.triggerId, request.source, TriggerSkipReason.Paused);
107
+ return { disposition: ManualTriggerDisposition.Skipped, reason: TriggerSkipReason.Paused };
108
+ }
109
+ function matchingManualRequest(event, triggerId, commandId) {
110
+ if (event?.event.eventType === ControlEventType.TriggerRequestRecorded &&
111
+ event.event.payload.triggerId === triggerId &&
112
+ event.event.payload.source.kind === TriggerSourceKind.Manual &&
113
+ event.event.payload.source.commandId === commandId &&
114
+ event.event.payload.manualOutcome !== undefined)
115
+ return event.event.payload;
116
+ return undefined;
117
+ }
118
+ function activeWorkItem(view, coordinationKey) {
119
+ const invocation = view.invocations.find((entry) => entry.claim.coordinationKey === coordinationKey && entry.result === undefined);
120
+ return invocation === undefined ? {} : { activeWorkItemId: invocation.claim.workItemId };
121
+ }
122
+ function settledManualOutcome(outcome) {
123
+ return (outcome.disposition === ManualTriggerDisposition.Skipped ||
124
+ (outcome.disposition === ManualTriggerDisposition.Started && outcome.workItemId !== undefined));
125
+ }
@@ -34,7 +34,9 @@ export const triggerProjection = {
34
34
  ].slice(0, maximumTriggerSources),
35
35
  },
36
36
  }
37
- : withoutCoalesced(previous.coalesced, request),
37
+ : request.disposition === TriggerRequestDisposition.Started
38
+ ? previous.coalesced
39
+ : withoutCoalesced(previous.coalesced, request),
38
40
  };
39
41
  }
40
42
  case ControlEventType.TriggerInvocationClaimed: {
@@ -1,6 +1,6 @@
1
1
  import type { CommandContext, EventEnvelope } from '@atolis-hq/eventing';
2
2
  import type { TriggerConfig } from '../contracts/config.js';
3
- import { type TriggerSource } from '../contracts/events.js';
3
+ import { TriggerSourceKind, type ManualTriggerOutcome, type TriggerSource } from '../contracts/events.js';
4
4
  import { type TriggerSkipDiagnostic } from '../contracts/trigger-diagnostics.js';
5
5
  import { type TriggerView } from './trigger-projection.js';
6
6
  import type { TriggerServiceDependencies } from './trigger-service-ports.js';
@@ -22,16 +22,17 @@ export declare class TriggerService {
22
22
  reconcile(context: CommandContext): Promise<void>;
23
23
  pause(triggerId: string, reason: string, context: CommandContext): Promise<void>;
24
24
  resume(triggerId: string, context: CommandContext): Promise<void>;
25
+ requestManual(triggerId: string, context: CommandContext): Promise<ManualTriggerOutcome>;
25
26
  run(config: TriggerConfig, context: CommandContext): Promise<readonly string[]>;
26
- start(config: TriggerConfig, source: TriggerSource, context: CommandContext, event?: EventEnvelope): Promise<boolean>;
27
+ start(config: TriggerConfig, source: Exclude<TriggerSource, {
28
+ kind: typeof TriggerSourceKind.Manual;
29
+ }>, context: CommandContext, event?: EventEnvelope): Promise<boolean>;
27
30
  private serialise;
28
31
  private key;
29
32
  private commandKey;
30
- private view;
31
33
  private configured;
32
34
  private emit;
33
35
  private request;
34
- private suppressed;
35
36
  private advanceCoalesced;
36
37
  private recover;
37
38
  }
@@ -3,7 +3,8 @@ import { ControlEventType, TriggerRequestDisposition, TriggerSourceKind, } from
3
3
  import { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
4
4
  import { CronTriggerPolicy } from '../domain/cron-trigger-policy.js';
5
5
  import { TriggerDiagnostics } from './trigger-diagnostics.js';
6
- import { appendTriggerFact, sourceIdentity } from './trigger-facts.js';
6
+ import { appendTriggerFact, consumedTriggerRequest, hasTriggerRequest, sourceIdentity, } from './trigger-facts.js';
7
+ import { requestManualTrigger } from './trigger-manual-request.js';
7
8
  import { maximumTriggerSources } from './trigger-projection.js';
8
9
  import { recoverTriggerInvocation } from './trigger-recovery.js';
9
10
  import { hasActiveInvocation, isOwnScopeSource } from './trigger-rules.js';
@@ -25,7 +26,7 @@ export class TriggerService {
25
26
  }
26
27
  async get() {
27
28
  return this.serialise(async () => ({
28
- ...(await this.view()),
29
+ ...(await this.reader.get()),
29
30
  invocations: await this.dependencies.history(),
30
31
  diagnostics: await this.diagnostics.get(),
31
32
  }));
@@ -38,7 +39,7 @@ export class TriggerService {
38
39
  }
39
40
  async pause(triggerId, reason, context) {
40
41
  await this.serialise(async () => {
41
- await this.view();
42
+ await this.reader.get();
42
43
  await this.emit({
43
44
  eventType: ControlEventType.TriggerPaused,
44
45
  payload: { triggerId, reason, coordinationKey: this.commandKey(triggerId) },
@@ -47,13 +48,25 @@ export class TriggerService {
47
48
  }
48
49
  async resume(triggerId, context) {
49
50
  await this.serialise(async () => {
50
- await this.view();
51
+ await this.reader.get();
51
52
  await this.emit({
52
53
  eventType: ControlEventType.TriggerResumed,
53
54
  payload: { triggerId, coordinationKey: this.commandKey(triggerId) },
54
55
  }, context, `trigger:resume:${triggerId}:${context.commandId}`);
55
56
  });
56
57
  }
58
+ async requestManual(triggerId, context) {
59
+ return this.serialise(() => requestManualTrigger({
60
+ dependencies: this.dependencies,
61
+ diagnostics: this.diagnostics,
62
+ config: this.configured(triggerId),
63
+ coordinationKey: () => this.commandKey(triggerId),
64
+ view: () => this.reader.get(),
65
+ recover: (command) => this.recover(command),
66
+ advance: (command) => this.advanceCoalesced(command),
67
+ emit: (input, command, id) => this.emit(input, command, id),
68
+ }, triggerId, context));
69
+ }
57
70
  async run(config, context) {
58
71
  return this.serialise(async () => {
59
72
  const accepted = [];
@@ -99,24 +112,20 @@ export class TriggerService {
99
112
  ?.coordinationKey ?? triggerId)
100
113
  : this.key(config);
101
114
  }
102
- view() {
103
- return this.reader.get();
104
- }
105
115
  configured(id) {
106
116
  return this.dependencies.configurations().find((config) => config.id === id);
107
117
  }
108
118
  async emit(input, context, eventId) {
109
- await this.view();
119
+ await this.reader.get();
110
120
  await appendTriggerFact(this.dependencies.journal, this.dependencies.now(), input, context, eventId, input.eventType === ControlEventType.TriggerRequestRecorded
111
121
  ? this.reader.sequence(input.payload.coordinationKey)
112
122
  : undefined);
113
123
  }
114
124
  async request(config, source, context, event) {
115
- const view = await this.view();
125
+ const view = await this.reader.get();
116
126
  if (await this.sourceCursor.isConsumed(config.id, source, event))
117
127
  return false;
118
- const duplicate = view.requests.some((request) => request.triggerId === config.id &&
119
- sourceIdentity(request.source) === sourceIdentity(source));
128
+ const duplicate = hasTriggerRequest(view.requests, config.id, source);
120
129
  const coordinationKey = this.key(config);
121
130
  // The reactor checkpoint consumes suppressed sources. Emitting another trigger request
122
131
  // here could itself become a source when subscribed to Control Plane events.
@@ -124,7 +133,14 @@ export class TriggerService {
124
133
  await this.sourceCursor.consume(config.id, source, event);
125
134
  return false;
126
135
  }
127
- if (await this.suppressed(view, config, coordinationKey, event)) {
136
+ if (await isOwnScopeSource(view, { triggerId: config.id, coordinationKey }, event, {
137
+ keyOf: (id) => {
138
+ const other = this.configured(id);
139
+ return other === undefined ? undefined : this.key(other);
140
+ },
141
+ sourceWorkItem: this.dependencies.sourceWorkItem,
142
+ invocationScope: this.dependencies.invocationScope,
143
+ })) {
128
144
  await this.diagnostics.record(config.id, source, TriggerSkipReason.OwnScope);
129
145
  await this.sourceCursor.consume(config.id, source, event);
130
146
  return false;
@@ -148,18 +164,8 @@ export class TriggerService {
148
164
  await this.sourceCursor.consume(config.id, source, event);
149
165
  return eligible;
150
166
  }
151
- suppressed(view, config, coordinationKey, event) {
152
- return isOwnScopeSource(view, { triggerId: config.id, coordinationKey }, event, {
153
- keyOf: (id) => {
154
- const other = this.configured(id);
155
- return other === undefined ? undefined : this.key(other);
156
- },
157
- sourceWorkItem: this.dependencies.sourceWorkItem,
158
- invocationScope: this.dependencies.invocationScope,
159
- });
160
- }
161
167
  async advanceCoalesced(context) {
162
- const view = await this.view();
168
+ const view = await this.reader.get();
163
169
  for (const request of Object.values(view.coalesced)) {
164
170
  if (hasActiveInvocation(view, request.coordinationKey))
165
171
  continue;
@@ -169,15 +175,7 @@ export class TriggerService {
169
175
  if (reason !== undefined || config === undefined) {
170
176
  await this.diagnostics.record(request.triggerId, request.source, reason ?? TriggerSkipReason.Removed);
171
177
  // This recorded request was reconsidered and consumed; later eligibility is not a source.
172
- await this.emit({
173
- eventType: ControlEventType.TriggerRequestRecorded,
174
- payload: {
175
- triggerId: request.triggerId,
176
- coordinationKey: request.coordinationKey,
177
- source: request.source,
178
- disposition: TriggerRequestDisposition.Skipped,
179
- },
180
- }, context, `trigger:consume:${request.triggerId}:${sourceIdentity(request.source)}`);
178
+ await this.emit(consumedTriggerRequest(request, reason ?? TriggerSkipReason.Removed), context, `trigger:consume:${request.triggerId}:${sourceIdentity(request.source)}`);
181
179
  continue;
182
180
  }
183
181
  await this.emit({
@@ -196,7 +194,7 @@ export class TriggerService {
196
194
  }
197
195
  }
198
196
  async recover(context) {
199
- for (const invocation of (await this.view()).invocations) {
197
+ for (const invocation of (await this.reader.get()).invocations) {
200
198
  if (invocation.result === undefined)
201
199
  await recoverTriggerInvocation({
202
200
  work: this.dependencies.work,
@@ -19,15 +19,47 @@ export declare const RunnerPauseCause: {
19
19
  readonly Quota: "quota";
20
20
  };
21
21
  export declare const ControlEventNamespace: "control-plane.";
22
+ declare const manualStartedShape: {
23
+ started: boolean;
24
+ };
22
25
  export declare const TriggerRequestDisposition: {
26
+ readonly Started: keyof typeof manualStartedShape;
23
27
  readonly Coalesced: "coalesced";
24
28
  readonly Skipped: "skipped";
25
29
  };
26
30
  export declare const TriggerSourceKind: {
27
31
  readonly Event: "event";
28
32
  readonly Cron: "cron";
33
+ readonly Manual: "manual";
34
+ };
35
+ export declare const ManualTriggerDisposition: {
36
+ readonly Started: keyof typeof manualStartedShape;
37
+ readonly Coalesced: "coalesced";
38
+ readonly Skipped: "skipped";
29
39
  };
40
+ export declare const manualTriggerOutcomeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
41
+ disposition: z.ZodLiteral<"started">;
42
+ workItemId: z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strict>, z.ZodObject<{
44
+ disposition: z.ZodLiteral<"coalesced">;
45
+ activeWorkItemId: z.ZodOptional<z.ZodString>;
46
+ }, z.core.$strict>, z.ZodObject<{
47
+ disposition: z.ZodLiteral<"skipped">;
48
+ reason: z.ZodEnum<{
49
+ readonly OwnScope: "own-scope";
50
+ readonly Paused: "paused";
51
+ readonly Removed: "removed";
52
+ readonly DispatchPaused: "dispatch-paused";
53
+ readonly Capacity: "capacity-unavailable";
54
+ readonly PendingLimit: "pending-source-limit";
55
+ }>;
56
+ }, z.core.$strict>], "disposition">;
57
+ export type ManualTriggerOutcome = z.infer<typeof manualTriggerOutcomeSchema>;
30
58
  export declare const triggerSourceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
59
+ kind: z.ZodLiteral<"manual">;
60
+ commandId: z.ZodString;
61
+ operator: z.ZodString;
62
+ }, z.core.$strict>, z.ZodObject<{
31
63
  kind: z.ZodLiteral<"event">;
32
64
  eventId: z.ZodString;
33
65
  eventType: z.ZodString;
@@ -41,6 +73,7 @@ export interface ControlEventPayloads {
41
73
  readonly triggerId: string;
42
74
  readonly coordinationKey: string;
43
75
  readonly source: TriggerSource;
76
+ readonly manualOutcome?: ManualTriggerOutcome | undefined;
44
77
  readonly disposition: (typeof TriggerRequestDisposition)[keyof typeof TriggerRequestDisposition];
45
78
  };
46
79
  readonly [ControlEventType.TriggerInvocationClaimed]: {
@@ -2,6 +2,7 @@ import { eventDataSchema, eventEnvelopeSchema, } from '@atolis-hq/eventing';
2
2
  import { z } from 'zod';
3
3
  import { WorkflowStatus } from '../../orchestration/index.js';
4
4
  import { ControlStreamKind, } from './streams.js';
5
+ import { TriggerSkipReason } from './trigger-skip-reason.js';
5
6
  export const ControlEventType = {
6
7
  TriggerRequestRecorded: 'control-plane.trigger-request-recorded',
7
8
  TriggerInvocationClaimed: 'control-plane.trigger-invocation-claimed',
@@ -16,9 +17,46 @@ export const ControlEventType = {
16
17
  };
17
18
  export const RunnerPauseCause = { Manual: 'manual', Quota: 'quota' };
18
19
  export const ControlEventNamespace = 'control-plane.';
19
- export const TriggerRequestDisposition = { Coalesced: 'coalesced', Skipped: 'skipped' };
20
- export const TriggerSourceKind = { Event: 'event', Cron: 'cron' };
20
+ const manualStartedShape = { started: true };
21
+ export const TriggerRequestDisposition = {
22
+ Started: Object.keys(manualStartedShape)[0],
23
+ Coalesced: 'coalesced',
24
+ Skipped: 'skipped',
25
+ };
26
+ export const TriggerSourceKind = { Event: 'event', Cron: 'cron', Manual: 'manual' };
27
+ export const ManualTriggerDisposition = {
28
+ Started: Object.keys(manualStartedShape)[0],
29
+ Coalesced: TriggerRequestDisposition.Coalesced,
30
+ Skipped: TriggerRequestDisposition.Skipped,
31
+ };
32
+ export const manualTriggerOutcomeSchema = z.discriminatedUnion('disposition', [
33
+ z
34
+ .object({
35
+ disposition: z.literal(ManualTriggerDisposition.Started),
36
+ workItemId: z.string().min(1).optional(),
37
+ })
38
+ .strict(),
39
+ z
40
+ .object({
41
+ disposition: z.literal(ManualTriggerDisposition.Coalesced),
42
+ activeWorkItemId: z.string().min(1).optional(),
43
+ })
44
+ .strict(),
45
+ z
46
+ .object({
47
+ disposition: z.literal(ManualTriggerDisposition.Skipped),
48
+ reason: z.enum(TriggerSkipReason),
49
+ })
50
+ .strict(),
51
+ ]);
21
52
  export const triggerSourceSchema = z.discriminatedUnion('kind', [
53
+ z
54
+ .object({
55
+ kind: z.literal(TriggerSourceKind.Manual),
56
+ commandId: z.string().min(1),
57
+ operator: z.string().min(1),
58
+ })
59
+ .strict(),
22
60
  z
23
61
  .object({
24
62
  kind: z.literal(TriggerSourceKind.Event),
@@ -52,6 +90,7 @@ const eventSchema = z.union([
52
90
  coordinationKey: z.string().min(1),
53
91
  source: triggerSourceSchema,
54
92
  disposition: z.enum(TriggerRequestDisposition),
93
+ manualOutcome: manualTriggerOutcomeSchema.optional(),
55
94
  })
56
95
  .strict(),
57
96
  }),
@@ -1,17 +1,12 @@
1
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>;
2
+ export { TriggerSkipReason } from './trigger-skip-reason.js';
12
3
  export declare const triggerSkipDiagnosticSchema: z.ZodObject<{
13
4
  triggerId: z.ZodString;
14
5
  source: z.ZodDiscriminatedUnion<[z.ZodObject<{
6
+ kind: z.ZodLiteral<"manual">;
7
+ commandId: z.ZodString;
8
+ operator: z.ZodString;
9
+ }, z.core.$strict>, z.ZodObject<{
15
10
  kind: z.ZodLiteral<"event">;
16
11
  eventId: z.ZodString;
17
12
  eventType: z.ZodString;
@@ -34,6 +29,10 @@ export declare const maximumTriggerDiagnostics = 256;
34
29
  export declare const triggerDiagnosticsSchema: z.ZodArray<z.ZodObject<{
35
30
  triggerId: z.ZodString;
36
31
  source: z.ZodDiscriminatedUnion<[z.ZodObject<{
32
+ kind: z.ZodLiteral<"manual">;
33
+ commandId: z.ZodString;
34
+ operator: z.ZodString;
35
+ }, z.core.$strict>, z.ZodObject<{
37
36
  kind: z.ZodLiteral<"event">;
38
37
  eventId: z.ZodString;
39
38
  eventType: z.ZodString;
@@ -1,13 +1,7 @@
1
1
  import { z } from 'zod';
2
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
- };
3
+ import { TriggerSkipReason } from './trigger-skip-reason.js';
4
+ export { TriggerSkipReason } from './trigger-skip-reason.js';
11
5
  export const triggerSkipDiagnosticSchema = z
12
6
  .object({
13
7
  triggerId: z.string().min(1),
@@ -0,0 +1,10 @@
1
+ import type { ValueOf } from '../../kernel/index.js';
2
+ export declare const TriggerSkipReason: {
3
+ readonly OwnScope: "own-scope";
4
+ readonly Paused: "paused";
5
+ readonly Removed: "removed";
6
+ readonly DispatchPaused: "dispatch-paused";
7
+ readonly Capacity: "capacity-unavailable";
8
+ readonly PendingLimit: "pending-source-limit";
9
+ };
10
+ export type TriggerSkipReason = ValueOf<typeof TriggerSkipReason>;
@@ -0,0 +1,8 @@
1
+ export const TriggerSkipReason = {
2
+ OwnScope: 'own-scope',
3
+ Paused: 'paused',
4
+ Removed: 'removed',
5
+ DispatchPaused: 'dispatch-paused',
6
+ Capacity: 'capacity-unavailable',
7
+ PendingLimit: 'pending-source-limit',
8
+ };
@@ -1,3 +1,4 @@
1
+ import type { ManualTriggerOutcome } from '../../../control-plane/index.js';
1
2
  import { type ValueOf } from '../../../kernel/index.js';
2
3
  export interface ControlPlaneStatusResponse {
3
4
  readonly dispatchPaused: boolean;
@@ -18,6 +19,7 @@ export interface ControlPlaneStatusResponse {
18
19
  };
19
20
  }
20
21
  export interface AcceptedCommandResponse {
22
+ readonly triggerOutcome?: ManualTriggerOutcome;
21
23
  readonly commandId: string;
22
24
  readonly idempotencyKey: string;
23
25
  readonly acceptedAt: string;
@@ -1,7 +1,8 @@
1
1
  import type { ActivityOutcomeKind } from '../../../activities/index.js';
2
- import type { TriggerRequestDisposition, TriggerSkipReason, TriggerSourceKind } from '../../../control-plane/index.js';
2
+ import type { ManualTriggerDisposition, TriggerRequestDisposition, TriggerSkipReason, TriggerSourceKind } from '../../../control-plane/index.js';
3
3
  import type { RunStatus } from '../../../execution/index.js';
4
4
  import type { ApiCommandStatus } from './control-plane.js';
5
+ import type { TriggerCommandName } from './triggers.js';
5
6
  export declare const AcceptedCommandStatusValue: {
6
7
  readonly Accepted: ApiCommandStatus;
7
8
  readonly Completed: ApiCommandStatus;
@@ -50,4 +51,6 @@ export declare const TriggerFinishedStatusValue: {
50
51
  readonly Completed: "completed" | "superseded";
51
52
  readonly Superseded: "completed" | "superseded";
52
53
  };
54
+ export declare const ManualTriggerDispositionValue: typeof ManualTriggerDisposition;
55
+ export declare const TriggerCommandNameValue: typeof TriggerCommandName;
53
56
  export {};