@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.
- package/dist/src/bootstrap/composition-root.d.ts +4 -1
- package/dist/src/bootstrap/composition-root.js +5 -2
- package/dist/src/bootstrap/config/root-schema.d.ts +2 -2
- package/dist/src/bootstrap/integration-runtime.d.ts +4 -2
- package/dist/src/bootstrap/integration-runtime.js +74 -13
- package/dist/src/bootstrap/surface-api-applications.js +2 -0
- package/dist/src/bootstrap/surface-api-trigger-applications.d.ts +3 -0
- package/dist/src/bootstrap/surface-api-trigger-applications.js +79 -0
- package/dist/src/bootstrap/surface-api-work-applications.js +8 -0
- package/dist/src/bootstrap/trigger-checkpoint-store.d.ts +5 -5
- package/dist/src/bootstrap/trigger-checkpoint-store.js +15 -40
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/control-plane-projection.js +11 -1
- package/dist/src/control-plane/application/runner-pipeline.js +0 -2
- package/dist/src/control-plane/application/trigger-diagnostics.d.ts +33 -0
- package/dist/src/control-plane/application/trigger-diagnostics.js +38 -0
- package/dist/src/control-plane/application/trigger-facts.d.ts +11 -0
- package/dist/src/control-plane/application/trigger-facts.js +38 -0
- package/dist/src/control-plane/application/trigger-invocation-projection.d.ts +4 -0
- package/dist/src/control-plane/application/trigger-invocation-projection.js +32 -0
- package/dist/src/control-plane/application/trigger-projection.d.ts +24 -0
- package/dist/src/control-plane/application/trigger-projection.js +98 -0
- package/dist/src/control-plane/application/trigger-reactor.d.ts +4 -0
- package/dist/src/control-plane/application/trigger-reactor.js +30 -0
- package/dist/src/control-plane/application/trigger-recovery.d.ts +10 -0
- package/dist/src/control-plane/application/trigger-recovery.js +61 -0
- package/dist/src/control-plane/application/trigger-rules.d.ts +19 -0
- package/dist/src/control-plane/application/trigger-rules.js +38 -0
- package/dist/src/control-plane/application/trigger-service-ports.d.ts +21 -0
- package/dist/src/control-plane/application/trigger-service-ports.js +1 -0
- package/dist/src/control-plane/application/trigger-service.d.ts +29 -27
- package/dist/src/control-plane/application/trigger-service.js +188 -101
- package/dist/src/control-plane/application/trigger-source-cursor.d.ts +16 -0
- package/dist/src/control-plane/application/trigger-source-cursor.js +35 -0
- package/dist/src/control-plane/application/trigger-state-reader.d.ts +13 -0
- package/dist/src/control-plane/application/trigger-state-reader.js +34 -0
- package/dist/src/control-plane/application/trigger-workflow.d.ts +17 -0
- package/dist/src/control-plane/application/trigger-workflow.js +18 -0
- package/dist/src/control-plane/contracts/event-factory.js +10 -0
- package/dist/src/control-plane/contracts/events.d.ts +50 -3
- package/dist/src/control-plane/contracts/events.js +100 -4
- package/dist/src/control-plane/contracts/streams.d.ts +9 -2
- package/dist/src/control-plane/contracts/streams.js +13 -1
- package/dist/src/control-plane/contracts/trigger-diagnostics.d.ts +53 -0
- package/dist/src/control-plane/contracts/trigger-diagnostics.js +23 -0
- package/dist/src/control-plane/domain/cron-trigger-policy.d.ts +2 -1
- package/dist/src/control-plane/domain/cron-trigger-policy.js +14 -1
- package/dist/src/control-plane/index.d.ts +4 -0
- package/dist/src/control-plane/index.js +4 -0
- package/dist/src/orchestration/contracts/config.d.ts +2 -2
- package/dist/src/surfaces/api/contracts/index.d.ts +1 -0
- package/dist/src/surfaces/api/contracts/index.js +1 -0
- package/dist/src/surfaces/api/contracts/transport-values.d.ts +8 -0
- package/dist/src/surfaces/api/contracts/transport-values.js +23 -0
- package/dist/src/surfaces/api/contracts/triggers.d.ts +22 -0
- package/dist/src/surfaces/api/contracts/triggers.js +8 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +1 -0
- package/dist/src/surfaces/api/contracts/workflow-diagram.d.ts +4 -4
- package/dist/src/surfaces/api/routes/applications.d.ts +7 -1
- package/dist/src/surfaces/api/routes/commands.js +10 -0
- package/dist/src/surfaces/api/routes/read.js +16 -0
- package/dist/src/surfaces/web-assets/assets/index-9IfrHvBo.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-CCvwzTeC.js +0 -1131
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CheckpointStore, type EventJournal, type ProcessorRunSerialiser, type ProcessorStateStore, type ProjectionStore } from '@atolis-hq/eventing';
|
|
2
2
|
import { createPullRequestService, type ActivityRegistry } from '../activities/index.js';
|
|
3
3
|
import { createArtifactService } from '../artifacts/index.js';
|
|
4
|
-
import { createControlPlaneService, createRunnerControlService, type ActivationScheduler, type ActivationSchedulerSubscriber, type IntakePipeline, type RunnerPipeline, type TriggerCheckpointStore } from '../control-plane/index.js';
|
|
4
|
+
import { createControlPlaneService, createRunnerControlService, type ActivationScheduler, type ActivationSchedulerSubscriber, type IntakePipeline, type RunnerPipeline, type TriggerCheckpointStore, type TriggerConfig, type TriggerService } from '../control-plane/index.js';
|
|
5
5
|
import { createConversationService } from '../conversations/index.js';
|
|
6
6
|
import { RecoveryService, TranscriptStore, createExecutionService, type FakeScenarioResolver, type Runner } from '../execution/index.js';
|
|
7
7
|
import type { DeliveryService, DurableFakeDeliveryProvider, ExternalDeliveryAdapter, ProviderCompositionFailure, ProviderInstance } from '../integrations/index.js';
|
|
@@ -33,12 +33,15 @@ export interface CompositionRootOptions {
|
|
|
33
33
|
readonly decorateCheckpoints?: (checkpoints: CheckpointStore) => CheckpointStore;
|
|
34
34
|
readonly subscriptionRunSerialiser?: ProcessorRunSerialiser;
|
|
35
35
|
readonly triggerCheckpoints?: TriggerCheckpointStore;
|
|
36
|
+
/** Trusted context binding supplies a shared scope identity; absent bindings use the trigger ID. */
|
|
37
|
+
readonly triggerCoordinationKey?: (config: TriggerConfig) => string;
|
|
36
38
|
readonly decorateDeliveryAdapter?: (adapter: ExternalDeliveryAdapter, provider: ProviderInstance) => ExternalDeliveryAdapter;
|
|
37
39
|
readonly decorateRunner?: (runner: Runner, name: string) => Runner;
|
|
38
40
|
/** A real fake-provider adapter for deterministic composed integration evidence. */
|
|
39
41
|
readonly fakeDeliveryProvider?: DurableFakeDeliveryProvider;
|
|
40
42
|
}
|
|
41
43
|
export interface CompositionRoot {
|
|
44
|
+
readonly triggers: TriggerService;
|
|
42
45
|
readonly config: ResolvedWakeModulesConfig;
|
|
43
46
|
readonly fakeScenarios: FakeScenarioResolver;
|
|
44
47
|
readonly paths: WakePaths;
|
|
@@ -21,7 +21,7 @@ import { composePersistence } from './persistence-composition.js';
|
|
|
21
21
|
import { createRunnerQuotaReporter } from './runner-quota-reporter.js';
|
|
22
22
|
import { createRunnerRegistry } from './runner-registry.js';
|
|
23
23
|
import { createTranscriptRetention } from './transcript-retention.js';
|
|
24
|
-
import {
|
|
24
|
+
import { ProcessorTriggerCheckpointStore } from './trigger-checkpoint-store.js';
|
|
25
25
|
import { createUpdateMaintenanceLease, } from './update-maintenance-lease.js';
|
|
26
26
|
const resourceLinkResolvers = {
|
|
27
27
|
github: resolveGitHubResourceUrl,
|
|
@@ -174,7 +174,10 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
174
174
|
processorRuntime,
|
|
175
175
|
activities,
|
|
176
176
|
runners,
|
|
177
|
-
triggerCheckpoints: options.triggerCheckpoints ?? new
|
|
177
|
+
triggerCheckpoints: options.triggerCheckpoints ?? new ProcessorTriggerCheckpointStore(processorState),
|
|
178
|
+
...(options.triggerCoordinationKey === undefined
|
|
179
|
+
? {}
|
|
180
|
+
: { triggerCoordinationKey: options.triggerCoordinationKey }),
|
|
178
181
|
...(options.decorateDeliveryAdapter === undefined
|
|
179
182
|
? {}
|
|
180
183
|
: { decorateDeliveryAdapter: options.decorateDeliveryAdapter }),
|
|
@@ -15,8 +15,8 @@ declare const orchestrationConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
15
15
|
with: z.ZodOptional<z.ZodUnknown>;
|
|
16
16
|
allowedActors: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
17
17
|
human: "human";
|
|
18
|
-
watch: "watch";
|
|
19
18
|
auto: "auto";
|
|
19
|
+
watch: "watch";
|
|
20
20
|
}>>>;
|
|
21
21
|
}, z.core.$strict>>>;
|
|
22
22
|
watches: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
@@ -162,8 +162,8 @@ export declare const rootConfigSchema: z.ZodObject<{
|
|
|
162
162
|
with: z.ZodOptional<z.ZodUnknown>;
|
|
163
163
|
allowedActors: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
164
164
|
human: "human";
|
|
165
|
-
watch: "watch";
|
|
166
165
|
auto: "auto";
|
|
166
|
+
watch: "watch";
|
|
167
167
|
}>>>;
|
|
168
168
|
}, z.core.$strict>>>;
|
|
169
169
|
watches: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { type CheckpointStore, type EventJournal, type EventProcessor, type ProcessorRunSerialiser, type ProcessorStateStore, type ProjectionStore } from '@atolis-hq/eventing';
|
|
2
2
|
import { type ActivityRegistry, type createPullRequestService } from '../activities/index.js';
|
|
3
|
-
import { type IntakePipeline, type RunnerPipeline, type TriggerCheckpointStore, type createControlPlaneService } from '../control-plane/index.js';
|
|
3
|
+
import { TriggerService, type IntakePipeline, type RunnerPipeline, type TriggerCheckpointStore, type TriggerConfig, type createControlPlaneService } from '../control-plane/index.js';
|
|
4
4
|
import type { createConversationService } from '../conversations/index.js';
|
|
5
5
|
import { type RunnerRegistry, type createExecutionService } from '../execution/index.js';
|
|
6
6
|
import { DeliveryService, type DurableFakeDeliveryProvider, type ExternalDeliveryAdapter, type ProviderCompositionFailure, type ProviderDefinition, type ProviderInstance } from '../integrations/index.js';
|
|
7
7
|
import { type Clock, type UlidIdGenerator } from '../kernel/index.js';
|
|
8
8
|
import { type createOrchestrationService } from '../orchestration/index.js';
|
|
9
9
|
import { type createResourceLookup, type createResourceService } from '../resources/index.js';
|
|
10
|
-
import type
|
|
10
|
+
import { type createWorkService } from '../work/index.js';
|
|
11
11
|
import type { ResolvedWakeModulesConfig } from './config/load-config.js';
|
|
12
12
|
import type { EventProcessorRuntime } from './event-processor-runtime.js';
|
|
13
13
|
import { type RuntimeProjectionSubscriptions } from './projection-runtime.js';
|
|
14
14
|
export interface IntegrationRuntime {
|
|
15
|
+
readonly triggers: TriggerService;
|
|
15
16
|
readonly projectionSubscriptions: RuntimeProjectionSubscriptions;
|
|
16
17
|
readonly processors: readonly EventProcessor[];
|
|
17
18
|
readonly providers: readonly ProviderInstance[];
|
|
@@ -44,6 +45,7 @@ export interface IntegrationRuntimeInput {
|
|
|
44
45
|
readonly subscriptionRunSerialiser: ProcessorRunSerialiser;
|
|
45
46
|
readonly processorRuntime: EventProcessorRuntime;
|
|
46
47
|
readonly triggerCheckpoints: TriggerCheckpointStore;
|
|
48
|
+
readonly triggerCoordinationKey?: (config: TriggerConfig) => string;
|
|
47
49
|
readonly decorateDeliveryAdapter?: (adapter: ExternalDeliveryAdapter, provider: ProviderInstance) => ExternalDeliveryAdapter;
|
|
48
50
|
readonly fakeDeliveryProvider?: DurableFakeDeliveryProvider;
|
|
49
51
|
readonly providerDefinitions: readonly ProviderDefinition[];
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { EventActorKind, } from '@atolis-hq/eventing';
|
|
1
|
+
import { EventActorKind, correlationId, } from '@atolis-hq/eventing';
|
|
2
2
|
import { withFileLock } from '@atolis-hq/eventing-filesystem';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
import { ActivityExecutionKind, activityName, } from '../activities/index.js';
|
|
5
|
-
import { ControlStreamKind, TriggerService, createDurableRunnerIneligibility, createIntakePipeline, createRunnerPipeline, createTriggerReactor, createWorkCancellationPolicy, } from '../control-plane/index.js';
|
|
6
|
-
import { NoEligibleRunnerError, RunRepository, createRuntimeMemoryProfile, isActiveRunStatus, } from '../execution/index.js';
|
|
6
|
+
import { ControlEventType, ControlStreamKind, TriggerService, createDurableRunnerIneligibility, createIntakePipeline, createRunnerPipeline, createTriggerReactor, createWorkCancellationPolicy, selectControlEvent, triggerInvocationProjection, triggerInvocationStream, } from '../control-plane/index.js';
|
|
7
|
+
import { ExecutionStreamKind, NoEligibleRunnerError, RunRepository, createRuntimeMemoryProfile, decodeActivationExecutionEvent, isActiveRunStatus, isRunStream, runId, } from '../execution/index.js';
|
|
7
8
|
import { AgentRunPublicationReactor, ArtifactRegistrationReactor, DeliveryOutcomeReactor, DeliveryService, IntegrationStreamKind, PollService, ProviderRegistry, deliveryProjectionDefinitions, fakeProviderDefinition, } from '../integrations/index.js';
|
|
8
|
-
import { compileWorkflowSelectors, createConversationCommandReactor, createPullRequestTransitionEvidence, createResourceTransitionReactor, createWatchReactor, createWatchReconciler, selectWorkflow, workflowName, } from '../orchestration/index.js';
|
|
9
|
+
import { compileWorkflowSelectors, createConversationCommandReactor, createPullRequestTransitionEvidence, createResourceTransitionReactor, createWatchReactor, createWatchReconciler, isWorkflowInstanceStream, selectWorkflow, workflowInstanceId, workflowName, } from '../orchestration/index.js';
|
|
9
10
|
import { BuiltInResourceCapability, resourceId, } from '../resources/index.js';
|
|
11
|
+
import { isWorkItemStream } from '../work/index.js';
|
|
10
12
|
import { decodeCanonicalEvent } from './canonical-events.js';
|
|
11
13
|
import { hydrateFakeProviderEvidence } from './fake-provider-files.js';
|
|
12
14
|
import { createRuntimeProjectionSubscriptions, } from './projection-runtime.js';
|
|
@@ -68,7 +70,51 @@ export async function composeIntegrationRuntime(input) {
|
|
|
68
70
|
now: () => input.clock.now().toISOString(),
|
|
69
71
|
});
|
|
70
72
|
const runnerIneligibility = createDurableRunnerIneligibility(input.journal, () => input.clock.now().toISOString());
|
|
73
|
+
const triggerRuns = new RunRepository(input.journal);
|
|
71
74
|
const triggers = new TriggerService({
|
|
75
|
+
state: input.processorState,
|
|
76
|
+
history: async () => {
|
|
77
|
+
await projectionSubscriptions.catchUp(triggerInvocationProjection);
|
|
78
|
+
return (await input.projections.list(triggerInvocationProjection.name)).flatMap(({ value }) => (value === null ? [] : [value]));
|
|
79
|
+
},
|
|
80
|
+
invocationScope: async (item) => {
|
|
81
|
+
const claim = (await input.journal.readStream(triggerInvocationStream(item)))
|
|
82
|
+
.map(selectControlEvent)
|
|
83
|
+
.find((event) => event?.event.eventType === ControlEventType.TriggerInvocationClaimed);
|
|
84
|
+
return claim?.event.eventType === ControlEventType.TriggerInvocationClaimed
|
|
85
|
+
? claim.event.payload.coordinationKey
|
|
86
|
+
: null;
|
|
87
|
+
},
|
|
88
|
+
...(input.triggerCoordinationKey === undefined
|
|
89
|
+
? {}
|
|
90
|
+
: { coordinationKey: input.triggerCoordinationKey }),
|
|
91
|
+
serialise: input.subscriptionRunSerialiser,
|
|
92
|
+
configurations: () => input.config.controlPlane.triggers,
|
|
93
|
+
isDispatchPaused: input.isPaused,
|
|
94
|
+
sourceWorkItem: async (event) => {
|
|
95
|
+
if (isWorkItemStream(event.stream))
|
|
96
|
+
return event.stream.id;
|
|
97
|
+
let workflowId;
|
|
98
|
+
if (isWorkflowInstanceStream(event.stream))
|
|
99
|
+
workflowId = event.stream.id;
|
|
100
|
+
if (isRunStream(event.stream))
|
|
101
|
+
workflowId = (await triggerRuns.load(runId(event.stream.id))).view?.workflowInstanceId;
|
|
102
|
+
if (event.stream.kind === ExecutionStreamKind.Activation)
|
|
103
|
+
workflowId = (await triggerRuns.load(runId(decodeActivationExecutionEvent(event).event.payload.runId))).view?.workflowInstanceId;
|
|
104
|
+
if (workflowId === undefined)
|
|
105
|
+
return null;
|
|
106
|
+
const seen = new Set();
|
|
107
|
+
while (!seen.has(workflowId)) {
|
|
108
|
+
seen.add(workflowId);
|
|
109
|
+
const instance = await input.orchestration.get(workflowInstanceId(workflowId));
|
|
110
|
+
if (instance === null)
|
|
111
|
+
return null;
|
|
112
|
+
if (instance.parentWorkflowInstanceId === undefined)
|
|
113
|
+
return instance.workItemId;
|
|
114
|
+
workflowId = instance.parentWorkflowInstanceId;
|
|
115
|
+
}
|
|
116
|
+
throw new Error('Cyclic workflow provenance');
|
|
117
|
+
},
|
|
72
118
|
journal: input.journal,
|
|
73
119
|
capacityAvailable: async (trigger) => {
|
|
74
120
|
if (await input.isPaused())
|
|
@@ -102,15 +148,23 @@ export async function composeIntegrationRuntime(input) {
|
|
|
102
148
|
});
|
|
103
149
|
const triggerReactors = input.config.controlPlane.triggers.map((config) => createTriggerReactor(triggers, config, decodeCanonicalEvent));
|
|
104
150
|
// Registration starts at the current journal boundary; historical facts are not sources.
|
|
151
|
+
const registrationSchema = z.object({ position: z.number().int().nonnegative() }).strict();
|
|
105
152
|
for (const reactor of triggerReactors) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
153
|
+
await input.subscriptionRunSerialiser(reactor.consumer, new AbortController().signal, async () => {
|
|
154
|
+
const stored = await input.processorState.read(reactor.consumer, 'registration');
|
|
155
|
+
const position = stored === null
|
|
156
|
+
? await input.journal.latestGlobalPosition()
|
|
157
|
+
: registrationSchema.parse(stored.value).position;
|
|
158
|
+
if (stored === null)
|
|
159
|
+
await input.processorState.write({
|
|
160
|
+
consumer: reactor.consumer,
|
|
161
|
+
key: 'registration',
|
|
162
|
+
value: { position },
|
|
163
|
+
});
|
|
164
|
+
// The registration boundary is written first so an interrupted checkpoint save
|
|
165
|
+
// can recover that boundary without skipping sources observed in the meantime.
|
|
166
|
+
if ((await input.checkpoints.load(reactor.consumer)) < position)
|
|
167
|
+
await input.checkpoints.save(reactor.consumer, position);
|
|
114
168
|
});
|
|
115
169
|
}
|
|
116
170
|
const artifacts = new ArtifactRegistrationReactor({
|
|
@@ -178,10 +232,16 @@ export async function composeIntegrationRuntime(input) {
|
|
|
178
232
|
const runnerPipeline = createRunnerPipeline({
|
|
179
233
|
isPaused: input.isPaused,
|
|
180
234
|
runTriggers: () => observeMemory(memoryProfile, 'runner.triggers', async () => {
|
|
235
|
+
await triggers.reconcile({
|
|
236
|
+
commandId: input.ids.next('command'),
|
|
237
|
+
correlationId: correlationId('trigger-recovery'),
|
|
238
|
+
occurredAt: input.clock.now().toISOString(),
|
|
239
|
+
actor: { kind: EventActorKind.System, id: ControlStreamKind.Global },
|
|
240
|
+
});
|
|
181
241
|
for (const trigger of input.config.controlPlane.triggers)
|
|
182
242
|
await triggers.run(trigger, {
|
|
183
243
|
commandId: input.ids.next('command'),
|
|
184
|
-
correlationId: 'trigger-tick',
|
|
244
|
+
correlationId: correlationId('trigger-tick'),
|
|
185
245
|
occurredAt: input.clock.now().toISOString(),
|
|
186
246
|
actor: { kind: EventActorKind.System, id: ControlStreamKind.Global },
|
|
187
247
|
});
|
|
@@ -207,6 +267,7 @@ export async function composeIntegrationRuntime(input) {
|
|
|
207
267
|
});
|
|
208
268
|
const requestImmediatePoll = createImmediatePollRequester(providers, input.journal, input.wakeRoot);
|
|
209
269
|
return {
|
|
270
|
+
triggers,
|
|
210
271
|
projectionSubscriptions,
|
|
211
272
|
processors: [
|
|
212
273
|
...projectionSubscriptions.processors,
|
|
@@ -8,6 +8,7 @@ import { createSelfUpdateFailureLog, describeSelfUpdateFailure, } from './self-u
|
|
|
8
8
|
import { createExecutionApplications } from './surface-api-execution-applications.js';
|
|
9
9
|
import { projectionMeta, sampledMeta } from './surface-api-metadata.js';
|
|
10
10
|
import { projectionPage } from './surface-api-projection-pages.js';
|
|
11
|
+
import { createTriggerApplications } from './surface-api-trigger-applications.js';
|
|
11
12
|
import { createSurfaceWorkApplications } from './surface-api-work-applications.js';
|
|
12
13
|
import { createWorkflowDiagramApplications } from './surface-api-workflow-diagrams.js';
|
|
13
14
|
import { UpdateMaintenancePhase } from './update-maintenance-lease.js';
|
|
@@ -18,6 +19,7 @@ export function createSurfaceApiApplications(root, now) {
|
|
|
18
19
|
board: createBoardApplications(root, now),
|
|
19
20
|
status: createStatusApplications(root, now),
|
|
20
21
|
controlPlane: createControlPlaneApplications(root, now),
|
|
22
|
+
triggers: createTriggerApplications(root, now),
|
|
21
23
|
work: createSurfaceWorkApplications(root, now),
|
|
22
24
|
resources: createResourceApplications(root, now),
|
|
23
25
|
orchestration: createOrchestrationApplications(root, now),
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { correlationId, EventActorKind } from '@atolis-hq/eventing';
|
|
2
|
+
import { CronTriggerPolicy } from '../control-plane/index.js';
|
|
3
|
+
import { ApiCommandStatus, toWorkItemKey, TriggerStatus, } from '../surfaces/index.js';
|
|
4
|
+
export function createTriggerApplications(root, now) {
|
|
5
|
+
async function list() {
|
|
6
|
+
const view = await root.triggers.get();
|
|
7
|
+
const ids = new Set([
|
|
8
|
+
...root.config.controlPlane.triggers.map((config) => config.id),
|
|
9
|
+
...Object.keys(view.pauses),
|
|
10
|
+
...view.requests.map((request) => request.triggerId),
|
|
11
|
+
...view.invocations.map((entry) => entry.claim.triggerId),
|
|
12
|
+
...(view.diagnostics ?? []).map((entry) => entry.triggerId),
|
|
13
|
+
]);
|
|
14
|
+
const asOf = now();
|
|
15
|
+
return { data: [...ids].sort().map((id) => present(id, view, asOf)), meta: { asOf } };
|
|
16
|
+
}
|
|
17
|
+
function present(id, view, asOf) {
|
|
18
|
+
const definition = root.config.controlPlane.triggers.find((config) => config.id === id) ?? null;
|
|
19
|
+
const invocations = view.invocations
|
|
20
|
+
.filter((entry) => entry.claim.triggerId === id)
|
|
21
|
+
.sort((a, b) => b.claimedAt.localeCompare(a.claimedAt))
|
|
22
|
+
.map((entry) => ({ ...entry, workItemKey: toWorkItemKey(entry.claim.workItemId) }));
|
|
23
|
+
const pauseReason = view.pauses[id] ?? null;
|
|
24
|
+
const running = invocations.some((entry) => entry.result === undefined);
|
|
25
|
+
return {
|
|
26
|
+
triggerId: id,
|
|
27
|
+
definition,
|
|
28
|
+
paused: pauseReason !== null,
|
|
29
|
+
pauseReason,
|
|
30
|
+
status: definition === null
|
|
31
|
+
? TriggerStatus.Removed
|
|
32
|
+
: pauseReason !== null
|
|
33
|
+
? TriggerStatus.Paused
|
|
34
|
+
: running
|
|
35
|
+
? TriggerStatus.Running
|
|
36
|
+
: TriggerStatus.Enabled,
|
|
37
|
+
nextOccurrence: definition?.on.cron === undefined
|
|
38
|
+
? null
|
|
39
|
+
: new CronTriggerPolicy().nextOccurrence(definition.on.cron, asOf),
|
|
40
|
+
pending: Object.values(view.coalesced).filter((entry) => entry.triggerId === id),
|
|
41
|
+
latestSkip: view.diagnostics?.find((entry) => entry.triggerId === id) ?? null,
|
|
42
|
+
invocations,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function command(id, request, pause) {
|
|
46
|
+
if (!(await list()).data.some((entry) => entry.triggerId === id))
|
|
47
|
+
return {
|
|
48
|
+
conflict: true,
|
|
49
|
+
code: 'trigger-not-found',
|
|
50
|
+
detail: 'Trigger definition and history are unavailable',
|
|
51
|
+
};
|
|
52
|
+
const context = {
|
|
53
|
+
commandId: 'trigger:' + request.idempotencyKey,
|
|
54
|
+
correlationId: correlationId('trigger:' + request.idempotencyKey),
|
|
55
|
+
occurredAt: now(),
|
|
56
|
+
actor: { kind: EventActorKind.Operator, id: 'web' },
|
|
57
|
+
};
|
|
58
|
+
if (pause)
|
|
59
|
+
await root.triggers.pause(id, 'Operator pause', context);
|
|
60
|
+
else
|
|
61
|
+
await root.triggers.resume(id, context);
|
|
62
|
+
return {
|
|
63
|
+
commandId: context.commandId,
|
|
64
|
+
idempotencyKey: request.idempotencyKey,
|
|
65
|
+
acceptedAt: now(),
|
|
66
|
+
status: ApiCommandStatus.Completed,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
list,
|
|
71
|
+
async detail(id) {
|
|
72
|
+
const result = await list();
|
|
73
|
+
const data = result.data.find((entry) => entry.triggerId === id);
|
|
74
|
+
return data === undefined ? undefined : { data, meta: result.meta };
|
|
75
|
+
},
|
|
76
|
+
pause: (id, request) => command(id, request, true),
|
|
77
|
+
resume: (id, request) => command(id, request, false),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { correlationId, EventActorKind } from '@atolis-hq/eventing';
|
|
2
2
|
import { pullRequestProjection } from '../activities/index.js';
|
|
3
|
+
import { triggerInvocationProjection } from '../control-plane/index.js';
|
|
3
4
|
import { conversationIdForWorkItem, ConversationOriginKind, } from '../conversations/index.js';
|
|
4
5
|
import { executionProjection, runsByWorkflowInstanceProjection, } from '../execution/index.js';
|
|
5
6
|
import { ApprovalAuthorityKind, ConversationSurfaceCapability, GroupBudgetExtensionIneligibleError, isGroupBudgetExtensionEligible, OperatorRetryIneligibleError, orchestrationProjection, selectOperatorRetryTarget, workflowsByWorkItemProjection, } from '../orchestration/index.js';
|
|
@@ -198,6 +199,7 @@ async function workDetail(root, key, now) {
|
|
|
198
199
|
// the production root always composes Conversations.
|
|
199
200
|
const conversation = await conversationForWorkItem(root, id);
|
|
200
201
|
const data = {
|
|
202
|
+
...(await triggerOriginForWork(root, id)),
|
|
201
203
|
work: presentDetailWork(work, externalRef, runs),
|
|
202
204
|
resources: resources.map(presentResource(root.resolveResourceLink)),
|
|
203
205
|
orchestration: {
|
|
@@ -320,6 +322,7 @@ function presentPullRequest(value) {
|
|
|
320
322
|
async function contributingProjections(root, id, resources, workflows, runs) {
|
|
321
323
|
const records = await Promise.all([
|
|
322
324
|
root.projections.read('work', id),
|
|
325
|
+
root.projections.read(triggerInvocationProjection.name, id),
|
|
323
326
|
...resources.map((value) => root.projections.read('resources', value.resourceId)),
|
|
324
327
|
...workflows.map((value) => root.projections.read(orchestrationProjection.name, value.workflowInstanceId)),
|
|
325
328
|
...runs.map((value) => root.projections.read(executionProjection.name, value.runId)),
|
|
@@ -352,3 +355,8 @@ function retryIneligible(detail) {
|
|
|
352
355
|
function extendIneligible(detail) {
|
|
353
356
|
return { conflict: true, code: 'extend-ineligible', detail };
|
|
354
357
|
}
|
|
358
|
+
async function triggerOriginForWork(root, id) {
|
|
359
|
+
await root.projectionSubscriptions?.catchUp(triggerInvocationProjection);
|
|
360
|
+
const origin = await root.projections.read(triggerInvocationProjection.name, id);
|
|
361
|
+
return origin?.value == null ? {} : { triggerOrigin: origin.value.claim.triggerId };
|
|
362
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { ProcessorStateStore } from '@atolis-hq/eventing';
|
|
1
2
|
import type { TriggerCheckpointStore } from '../control-plane/index.js';
|
|
2
|
-
/**
|
|
3
|
-
export declare class
|
|
4
|
-
private readonly
|
|
5
|
-
constructor(
|
|
3
|
+
/** Cron watermarks are processor recovery state, separate from rebuildable projections. */
|
|
4
|
+
export declare class ProcessorTriggerCheckpointStore implements TriggerCheckpointStore {
|
|
5
|
+
private readonly state;
|
|
6
|
+
constructor(state: ProcessorStateStore);
|
|
6
7
|
load(triggerId: string): Promise<string | null>;
|
|
7
8
|
save(triggerId: string, slot: string): Promise<void>;
|
|
8
|
-
private path;
|
|
9
9
|
}
|
|
@@ -1,49 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
export class
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const cursorSchema = z.object({ slot: z.string().datetime({ offset: true }) }).strict();
|
|
3
|
+
/** Cron watermarks are processor recovery state, separate from rebuildable projections. */
|
|
4
|
+
export class ProcessorTriggerCheckpointStore {
|
|
5
|
+
state;
|
|
6
|
+
constructor(state) {
|
|
7
|
+
this.state = state;
|
|
8
8
|
}
|
|
9
9
|
async load(triggerId) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (parsed.triggerId !== triggerId || Number.isNaN(Date.parse(parsed.slot)))
|
|
13
|
-
throw new Error(`Invalid trigger checkpoint: ${triggerId}`);
|
|
14
|
-
return parsed.slot;
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
if (error.code === 'ENOENT')
|
|
18
|
-
return null;
|
|
19
|
-
throw error;
|
|
20
|
-
}
|
|
10
|
+
const stored = await this.state.read(`reactor:control-plane.trigger:${triggerId}`, 'cron');
|
|
11
|
+
return stored === null ? null : cursorSchema.parse(stored.value).slot;
|
|
21
12
|
}
|
|
22
13
|
async save(triggerId, slot) {
|
|
14
|
+
const value = cursorSchema.parse({ slot });
|
|
23
15
|
const existing = await this.load(triggerId);
|
|
24
16
|
if (existing !== null && Date.parse(slot) < Date.parse(existing))
|
|
25
17
|
throw new Error(`Trigger checkpoint regression: ${triggerId}`);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
await handle.writeFile(`${JSON.stringify({ triggerId, slot })}\n`, 'utf8');
|
|
33
|
-
await handle.sync();
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
await handle.close();
|
|
37
|
-
}
|
|
38
|
-
await rename(temporary, path);
|
|
39
|
-
}
|
|
40
|
-
finally {
|
|
41
|
-
await rm(temporary, { force: true });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
path(triggerId) {
|
|
45
|
-
if (triggerId.length === 0 || /[\\/]/.test(triggerId))
|
|
46
|
-
throw new Error('Trigger id must not contain path separators');
|
|
47
|
-
return join(this.dataRoot, 'trigger-checkpoints', `${encodeURIComponent(triggerId)}.json`);
|
|
18
|
+
await this.state.write({
|
|
19
|
+
consumer: `reactor:control-plane.trigger:${triggerId}`,
|
|
20
|
+
key: 'cron',
|
|
21
|
+
value,
|
|
22
|
+
});
|
|
48
23
|
}
|
|
49
24
|
}
|
|
@@ -124,6 +124,6 @@ export function resolveWakeVersion(options = {}) {
|
|
|
124
124
|
return `g${headHash.slice(0, 7)}`;
|
|
125
125
|
return '0.1.0-dev';
|
|
126
126
|
}
|
|
127
|
-
export const wakeVersion = "v0.4.
|
|
127
|
+
export const wakeVersion = "v0.4.63";
|
|
128
128
|
/** The registry-installable version used by packaged sandbox images. */
|
|
129
129
|
export const wakePackageVersion = packageVersion(defaultRepoRoot) ?? wakeVersion;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ControlEventType, selectControlEvent } from '../contracts/events.js';
|
|
2
2
|
import { ControlStreamKind, controlPlaneStream } from '../contracts/streams.js';
|
|
3
|
+
import { triggerInvocationProjection } from './trigger-invocation-projection.js';
|
|
4
|
+
import { triggerProjection } from './trigger-projection.js';
|
|
3
5
|
export function ineligibleRunners(view, now) {
|
|
4
6
|
const current = Date.parse(now);
|
|
5
7
|
return new Set(Object.entries(view.runnerPauses)
|
|
@@ -24,7 +26,8 @@ export function createDurableRunnerIneligibility(journal, now) {
|
|
|
24
26
|
export const controlPlaneProjection = {
|
|
25
27
|
name: ControlStreamKind.Global,
|
|
26
28
|
select(event) {
|
|
27
|
-
|
|
29
|
+
const control = selectControlEvent(event);
|
|
30
|
+
return control?.stream.kind === ControlStreamKind.Global ? { key: 'global' } : null;
|
|
28
31
|
},
|
|
29
32
|
initial: () => ({ dispatchPausedUntil: null, runnerPauses: {} }),
|
|
30
33
|
project(previous, envelope) {
|
|
@@ -32,6 +35,11 @@ export const controlPlaneProjection = {
|
|
|
32
35
|
if (event === null)
|
|
33
36
|
return previous;
|
|
34
37
|
switch (event.event.eventType) {
|
|
38
|
+
case ControlEventType.TriggerRequestRecorded:
|
|
39
|
+
case ControlEventType.TriggerInvocationClaimed:
|
|
40
|
+
case ControlEventType.TriggerPaused:
|
|
41
|
+
case ControlEventType.TriggerResumed:
|
|
42
|
+
case ControlEventType.TriggerInvocationFinished:
|
|
35
43
|
case ControlEventType.TriggerInvocationStarted:
|
|
36
44
|
return previous;
|
|
37
45
|
case ControlEventType.DispatchPaused:
|
|
@@ -63,4 +71,6 @@ function withoutDispatchPause(previous) {
|
|
|
63
71
|
}
|
|
64
72
|
export const controlPlaneProjectionDefinitions = [
|
|
65
73
|
controlPlaneProjection,
|
|
74
|
+
triggerProjection,
|
|
75
|
+
triggerInvocationProjection,
|
|
66
76
|
];
|
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
export function createRunnerPipeline(stages) {
|
|
8
8
|
const isPaused = async () => (await stages.isPaused?.()) ?? false;
|
|
9
9
|
const runOnce = async (options, signal, beforeDelivery) => {
|
|
10
|
-
if (await isPaused())
|
|
11
|
-
return { kind: 'paused' };
|
|
12
10
|
await stages.runTriggers();
|
|
13
11
|
if (await isPaused())
|
|
14
12
|
return { kind: 'paused' };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ProcessorStateStore } from '@atolis-hq/eventing';
|
|
2
|
+
import type { TriggerConfig } from '../contracts/config.js';
|
|
3
|
+
import type { TriggerSource } from '../contracts/events.js';
|
|
4
|
+
import { type TriggerSkipReason as SkipReason } from '../contracts/trigger-diagnostics.js';
|
|
5
|
+
import type { TriggerView } from './trigger-projection.js';
|
|
6
|
+
interface Dependencies {
|
|
7
|
+
readonly state: ProcessorStateStore;
|
|
8
|
+
readonly now: () => string;
|
|
9
|
+
readonly isDispatchPaused: () => Promise<boolean>;
|
|
10
|
+
readonly capacityAvailable: (config: TriggerConfig) => Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
/** Diagnostic writes never emit trigger sources or retain an unbounded occurrence history. */
|
|
13
|
+
export declare class TriggerDiagnostics {
|
|
14
|
+
private readonly dependencies;
|
|
15
|
+
private readonly consumer;
|
|
16
|
+
constructor(dependencies: Dependencies, consumer: string);
|
|
17
|
+
get(): Promise<{
|
|
18
|
+
triggerId: string;
|
|
19
|
+
source: {
|
|
20
|
+
kind: "event";
|
|
21
|
+
eventId: string;
|
|
22
|
+
eventType: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "cron";
|
|
25
|
+
slot: string;
|
|
26
|
+
};
|
|
27
|
+
occurredAt: string;
|
|
28
|
+
reason: "paused" | "own-scope" | "removed" | "dispatch-paused" | "capacity-unavailable" | "pending-source-limit";
|
|
29
|
+
}[]>;
|
|
30
|
+
record(triggerId: string, source: TriggerSource, reason: SkipReason): Promise<void>;
|
|
31
|
+
ineligibleReason(view: TriggerView, id: string, config: TriggerConfig | undefined, configured: boolean, active?: boolean): Promise<SkipReason | undefined>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TriggerSkipReason, maximumTriggerDiagnostics, triggerDiagnosticsSchema, } from '../contracts/trigger-diagnostics.js';
|
|
2
|
+
/** Diagnostic writes never emit trigger sources or retain an unbounded occurrence history. */
|
|
3
|
+
export class TriggerDiagnostics {
|
|
4
|
+
dependencies;
|
|
5
|
+
consumer;
|
|
6
|
+
constructor(dependencies, consumer) {
|
|
7
|
+
this.dependencies = dependencies;
|
|
8
|
+
this.consumer = consumer;
|
|
9
|
+
}
|
|
10
|
+
async get() {
|
|
11
|
+
const stored = await this.dependencies.state.read(this.consumer, 'skip-diagnostics');
|
|
12
|
+
return stored === null ? [] : triggerDiagnosticsSchema.parse(stored.value);
|
|
13
|
+
}
|
|
14
|
+
async record(triggerId, source, reason) {
|
|
15
|
+
const previous = await this.get();
|
|
16
|
+
await this.dependencies.state.write({
|
|
17
|
+
consumer: this.consumer,
|
|
18
|
+
key: 'skip-diagnostics',
|
|
19
|
+
value: [
|
|
20
|
+
...previous.filter((entry) => entry.triggerId !== triggerId),
|
|
21
|
+
{ triggerId, source, reason, occurredAt: this.dependencies.now() },
|
|
22
|
+
].slice(-maximumTriggerDiagnostics),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async ineligibleReason(view, id, config, configured, active = false) {
|
|
26
|
+
if (view.pauses[id] !== undefined)
|
|
27
|
+
return TriggerSkipReason.Paused;
|
|
28
|
+
if (config === undefined || !configured)
|
|
29
|
+
return TriggerSkipReason.Removed;
|
|
30
|
+
if (await this.dependencies.isDispatchPaused())
|
|
31
|
+
return TriggerSkipReason.DispatchPaused;
|
|
32
|
+
if (!active &&
|
|
33
|
+
config.when?.capacityAvailable === true &&
|
|
34
|
+
!(await this.dependencies.capacityAvailable(config)))
|
|
35
|
+
return TriggerSkipReason.Capacity;
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CommandContext, type EventJournal } from '@atolis-hq/eventing';
|
|
2
|
+
import { type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
|
|
3
|
+
export type TriggerFactInput = {
|
|
4
|
+
[Type in keyof ControlEventPayloads]: {
|
|
5
|
+
readonly eventType: Type;
|
|
6
|
+
readonly payload: ControlEventPayloads[Type];
|
|
7
|
+
};
|
|
8
|
+
}[keyof ControlEventPayloads];
|
|
9
|
+
export declare function sourceIdentity(source: TriggerSource): string;
|
|
10
|
+
/** Invocation/command appends check event IDs; source appends use the caught-up scope sequence. */
|
|
11
|
+
export declare function appendTriggerFact(journal: EventJournal, occurredAt: string, input: TriggerFactInput, context: CommandContext, eventId: string, sequence?: number): Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EventSourceKind, WrongExpectedSequenceError, } from '@atolis-hq/eventing';
|
|
2
|
+
import { createControlPlaneEventData } from '../contracts/event-factory.js';
|
|
3
|
+
import { TriggerSourceKind, } from '../contracts/events.js';
|
|
4
|
+
import { triggerControlStream, triggerInvocationStream } from '../contracts/streams.js';
|
|
5
|
+
export function sourceIdentity(source) {
|
|
6
|
+
return `${source.kind}:${source.kind === TriggerSourceKind.Cron ? source.slot : source.eventId}`;
|
|
7
|
+
}
|
|
8
|
+
/** Invocation/command appends check event IDs; source appends use the caught-up scope sequence. */
|
|
9
|
+
export async function appendTriggerFact(journal, occurredAt, input, context, eventId, sequence) {
|
|
10
|
+
if (!('coordinationKey' in input.payload))
|
|
11
|
+
throw new Error('Expected trigger fact');
|
|
12
|
+
const stream = 'workItemId' in input.payload
|
|
13
|
+
? triggerInvocationStream(input.payload.workItemId)
|
|
14
|
+
: triggerControlStream(input.payload.coordinationKey);
|
|
15
|
+
const draft = createControlPlaneEventData({
|
|
16
|
+
...input,
|
|
17
|
+
eventId,
|
|
18
|
+
occurredAt,
|
|
19
|
+
correlationId: context.correlationId,
|
|
20
|
+
causationId: context.commandId,
|
|
21
|
+
actor: context.actor,
|
|
22
|
+
source: { kind: EventSourceKind.Internal, id: stream.kind },
|
|
23
|
+
});
|
|
24
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
25
|
+
const events = sequence === undefined ? await journal.readStream(stream) : null;
|
|
26
|
+
if (events?.some((envelope) => envelope.event.eventId === eventId))
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
await journal.appendToStream(stream, sequence ?? events.length, [draft]);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!(error instanceof WrongExpectedSequenceError) || attempt === 7)
|
|
34
|
+
throw error;
|
|
35
|
+
sequence = undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProjectionDefinition } from '@atolis-hq/eventing';
|
|
2
|
+
import type { TriggerInvocationView } from './trigger-projection.js';
|
|
3
|
+
/** One history document per top-level WorkItem, independent of operational scope state. */
|
|
4
|
+
export declare const triggerInvocationProjection: ProjectionDefinition<TriggerInvocationView | null>;
|