@atolis-hq/wake 0.4.60 → 0.4.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/bootstrap/canonical-events.d.ts +3 -0
- package/dist/src/bootstrap/canonical-events.js +32 -0
- package/dist/src/bootstrap/composition-root.d.ts +5 -2
- package/dist/src/bootstrap/composition-root.js +9 -3
- package/dist/src/bootstrap/config/root-schema.d.ts +8 -3
- package/dist/src/bootstrap/config/root-schema.js +29 -1
- package/dist/src/bootstrap/initialise.js +5 -0
- package/dist/src/bootstrap/integration-runtime.d.ts +9 -5
- package/dist/src/bootstrap/integration-runtime.js +113 -10
- package/dist/src/bootstrap/surface-cli-applications.js +1 -1
- package/dist/src/bootstrap/trigger-checkpoint-store.d.ts +9 -0
- package/dist/src/bootstrap/trigger-checkpoint-store.js +24 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/control-plane-projection.js +13 -1
- package/dist/src/control-plane/application/runner-pipeline.d.ts +2 -2
- package/dist/src/control-plane/application/runner-pipeline.js +2 -4
- 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.d.ts +49 -0
- package/dist/src/control-plane/application/trigger-service.js +198 -0
- 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/config.d.ts +18 -8
- package/dist/src/control-plane/contracts/config.js +35 -6
- package/dist/src/control-plane/contracts/event-factory.js +12 -0
- package/dist/src/control-plane/contracts/events.d.ts +72 -2
- package/dist/src/control-plane/contracts/events.js +130 -2
- 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/domain/cron-trigger-policy.d.ts +10 -0
- package/dist/src/control-plane/domain/{schedule-policy.js → cron-trigger-policy.js} +8 -6
- package/dist/src/control-plane/index.d.ts +5 -2
- package/dist/src/control-plane/index.js +5 -2
- package/package.json +1 -1
- package/dist/src/bootstrap/schedule-checkpoint-store.d.ts +0 -9
- package/dist/src/bootstrap/schedule-checkpoint-store.js +0 -49
- package/dist/src/control-plane/application/schedule-service.d.ts +0 -31
- package/dist/src/control-plane/application/schedule-service.js +0 -47
- package/dist/src/control-plane/domain/schedule-policy.d.ts +0 -8
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ActivityEventType, selectActivityEvent } from '../activities/index.js';
|
|
2
|
+
import { ArtifactEventType, selectArtifactEvent } from '../artifacts/index.js';
|
|
3
|
+
import { ControlEventType, selectControlEvent } from '../control-plane/index.js';
|
|
4
|
+
import { ConversationEventType, selectConversationEvent } from '../conversations/index.js';
|
|
5
|
+
import { ExecutionEventType, selectExecutionEvent } from '../execution/index.js';
|
|
6
|
+
import { GitHubEventType, selectGitHubAdapterEvent } from '../integrations/github/index.js';
|
|
7
|
+
import { DeliveryEventType, DeliveryIntentEventType, ArtifactEventType as IntegrationArtifactEventType, decodeArtifactEvent, selectDeliveryEvent, selectDeliveryIntentEvent, } from '../integrations/index.js';
|
|
8
|
+
import { OrchestrationEventType, selectOrchestrationEvent } from '../orchestration/index.js';
|
|
9
|
+
import { ResourceEventType, selectResourceEvent } from '../resources/index.js';
|
|
10
|
+
import { WorkEventType, selectWorkEvent } from '../work/index.js';
|
|
11
|
+
// Bootstrap registers the owning modules' public vocabularies and decoders together.
|
|
12
|
+
const registrations = [
|
|
13
|
+
{ types: Object.values(ActivityEventType), decode: selectActivityEvent },
|
|
14
|
+
{ types: Object.values(ArtifactEventType), decode: selectArtifactEvent },
|
|
15
|
+
{ types: Object.values(ControlEventType), decode: selectControlEvent },
|
|
16
|
+
{ types: Object.values(ConversationEventType), decode: selectConversationEvent },
|
|
17
|
+
{ types: Object.values(ExecutionEventType), decode: selectExecutionEvent },
|
|
18
|
+
{ types: Object.values(GitHubEventType), decode: selectGitHubAdapterEvent },
|
|
19
|
+
{ types: Object.values(IntegrationArtifactEventType), decode: decodeArtifactEvent },
|
|
20
|
+
{ types: Object.values(DeliveryEventType), decode: selectDeliveryEvent },
|
|
21
|
+
{ types: Object.values(DeliveryIntentEventType), decode: selectDeliveryIntentEvent },
|
|
22
|
+
{ types: Object.values(OrchestrationEventType), decode: selectOrchestrationEvent },
|
|
23
|
+
{ types: Object.values(ResourceEventType), decode: selectResourceEvent },
|
|
24
|
+
{ types: Object.values(WorkEventType), decode: selectWorkEvent },
|
|
25
|
+
];
|
|
26
|
+
export const canonicalEventTypes = new Set(registrations.flatMap(({ types }) => types));
|
|
27
|
+
export function decodeCanonicalEvent(event) {
|
|
28
|
+
const registration = registrations.find(({ types }) => types.includes(event.event.eventType));
|
|
29
|
+
if (registration === undefined)
|
|
30
|
+
throw new Error(`Unknown canonical event ${event.event.eventType}`);
|
|
31
|
+
registration.decode(event);
|
|
32
|
+
}
|
|
@@ -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
|
|
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';
|
|
@@ -32,13 +32,16 @@ export interface CompositionRootOptions {
|
|
|
32
32
|
readonly decorateProjections?: (projections: ProjectionStore) => ProjectionStore;
|
|
33
33
|
readonly decorateCheckpoints?: (checkpoints: CheckpointStore) => CheckpointStore;
|
|
34
34
|
readonly subscriptionRunSerialiser?: ProcessorRunSerialiser;
|
|
35
|
-
readonly
|
|
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;
|
|
@@ -20,8 +20,8 @@ import { resolveWakePaths } from './paths.js';
|
|
|
20
20
|
import { composePersistence } from './persistence-composition.js';
|
|
21
21
|
import { createRunnerQuotaReporter } from './runner-quota-reporter.js';
|
|
22
22
|
import { createRunnerRegistry } from './runner-registry.js';
|
|
23
|
-
import { FileScheduleCheckpointStore } from './schedule-checkpoint-store.js';
|
|
24
23
|
import { createTranscriptRetention } from './transcript-retention.js';
|
|
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,
|
|
@@ -85,10 +85,11 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
85
85
|
: options.decorateRunner === undefined
|
|
86
86
|
? profileDecorator
|
|
87
87
|
: (runner, name) => profileDecorator(options.decorateRunner(runner, name), name);
|
|
88
|
+
const runners = createRunnerRegistry(config.execution, fakeScenarios, decorateRunner);
|
|
88
89
|
const execution = createExecutionService(journal, activities, config.execution, {
|
|
89
90
|
clock,
|
|
90
91
|
ids,
|
|
91
|
-
runners
|
|
92
|
+
runners,
|
|
92
93
|
mcp: createArtifactMcpProvisioner({
|
|
93
94
|
artifacts,
|
|
94
95
|
orchestration,
|
|
@@ -171,7 +172,12 @@ export async function createCompositionRoot(wakeRoot, options = {}) {
|
|
|
171
172
|
wakeRoot,
|
|
172
173
|
subscriptionRunSerialiser,
|
|
173
174
|
processorRuntime,
|
|
174
|
-
|
|
175
|
+
activities,
|
|
176
|
+
runners,
|
|
177
|
+
triggerCheckpoints: options.triggerCheckpoints ?? new ProcessorTriggerCheckpointStore(processorState),
|
|
178
|
+
...(options.triggerCoordinationKey === undefined
|
|
179
|
+
? {}
|
|
180
|
+
: { triggerCoordinationKey: options.triggerCoordinationKey }),
|
|
175
181
|
...(options.decorateDeliveryAdapter === undefined
|
|
176
182
|
? {}
|
|
177
183
|
: { decorateDeliveryAdapter: options.decorateDeliveryAdapter }),
|
|
@@ -338,11 +338,16 @@ export declare const rootConfigSchema: z.ZodObject<{
|
|
|
338
338
|
controlPlane: z.ZodDefault<z.ZodObject<{
|
|
339
339
|
maxDispatches: z.ZodDefault<z.ZodNumber>;
|
|
340
340
|
maxConcurrentRuns: z.ZodDefault<z.ZodNumber>;
|
|
341
|
-
|
|
341
|
+
triggers: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
342
342
|
id: z.ZodString;
|
|
343
343
|
workflow: z.ZodString;
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
on: z.ZodObject<{
|
|
345
|
+
events: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
346
|
+
cron: z.ZodOptional<z.ZodString>;
|
|
347
|
+
}, z.core.$strict>;
|
|
348
|
+
when: z.ZodOptional<z.ZodObject<{
|
|
349
|
+
capacityAvailable: z.ZodLiteral<true>;
|
|
350
|
+
}, z.core.$strict>>;
|
|
346
351
|
}, z.core.$strict>>>;
|
|
347
352
|
resident: z.ZodDefault<z.ZodObject<{
|
|
348
353
|
pollBackoffMs: z.ZodDefault<z.ZodNumber>;
|
|
@@ -8,6 +8,7 @@ import { workflowDefinitionConfigSchema, workflowSelectorConfigSchema, } from '.
|
|
|
8
8
|
import { resourcesConfigSchema } from '../../resources/index.js';
|
|
9
9
|
import { surfacesConfigSchema } from '../../surfaces/index.js';
|
|
10
10
|
import { workConfigSchema } from '../../work/index.js';
|
|
11
|
+
import { canonicalEventTypes } from '../canonical-events.js';
|
|
11
12
|
const orchestrationConfigSchema = z
|
|
12
13
|
.object({
|
|
13
14
|
workflows: z.record(z.string().trim().min(1), workflowDefinitionConfigSchema).default({}),
|
|
@@ -151,7 +152,34 @@ export const rootConfigSchema = z
|
|
|
151
152
|
surfaces: surfacesConfigSchema,
|
|
152
153
|
host: hostConfigSchema,
|
|
153
154
|
})
|
|
154
|
-
.strict()
|
|
155
|
+
.strict()
|
|
156
|
+
.superRefine((value, context) => {
|
|
157
|
+
const ids = new Set();
|
|
158
|
+
for (const [index, trigger] of value.controlPlane.triggers.entries()) {
|
|
159
|
+
const path = ['controlPlane', 'triggers', index];
|
|
160
|
+
if (ids.has(trigger.id))
|
|
161
|
+
context.addIssue({
|
|
162
|
+
code: 'custom',
|
|
163
|
+
path: [...path, 'id'],
|
|
164
|
+
message: 'Trigger ids must be unique',
|
|
165
|
+
});
|
|
166
|
+
ids.add(trigger.id);
|
|
167
|
+
if (value.orchestration.workflows[trigger.workflow] === undefined)
|
|
168
|
+
context.addIssue({
|
|
169
|
+
code: 'custom',
|
|
170
|
+
path: [...path, 'workflow'],
|
|
171
|
+
message: 'Trigger workflow is not configured',
|
|
172
|
+
});
|
|
173
|
+
for (const [eventIndex, event] of (trigger.on.events ?? []).entries()) {
|
|
174
|
+
if (!canonicalEventTypes.has(event))
|
|
175
|
+
context.addIssue({
|
|
176
|
+
code: 'custom',
|
|
177
|
+
path: [...path, 'on', 'events', eventIndex],
|
|
178
|
+
message: 'Unknown canonical event',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
155
183
|
export function parseRootConfig(input) {
|
|
156
184
|
return rootConfigSchema.parse(input);
|
|
157
185
|
}
|
|
@@ -40,6 +40,11 @@ orchestration:
|
|
|
40
40
|
matchMode: all
|
|
41
41
|
workflow: approval
|
|
42
42
|
|
|
43
|
+
# Independent workflow invocations need an explicit event and/or UTC cron source.
|
|
44
|
+
# Activity prompts define their tasks. No triggers are enabled by default.
|
|
45
|
+
controlPlane:
|
|
46
|
+
triggers: []
|
|
47
|
+
|
|
43
48
|
# External providers Wake correlates inbound work with. Empty until you
|
|
44
49
|
# configure one — see SETUP.md.
|
|
45
50
|
integrations: {}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { type CheckpointStore, type EventJournal, type EventProcessor, type ProcessorRunSerialiser, type ProcessorStateStore, type ProjectionStore } from '@atolis-hq/eventing';
|
|
2
|
-
import type
|
|
3
|
-
import { type IntakePipeline, type RunnerPipeline, type
|
|
2
|
+
import { type ActivityRegistry, type createPullRequestService } from '../activities/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
|
-
import { type createExecutionService } from '../execution/index.js';
|
|
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[];
|
|
@@ -22,6 +23,8 @@ export interface IntegrationRuntime {
|
|
|
22
23
|
readonly requestImmediatePoll: (adapter: string) => void;
|
|
23
24
|
}
|
|
24
25
|
export interface IntegrationRuntimeInput {
|
|
26
|
+
readonly activities: ActivityRegistry;
|
|
27
|
+
readonly runners: RunnerRegistry;
|
|
25
28
|
readonly config: ResolvedWakeModulesConfig;
|
|
26
29
|
readonly journal: EventJournal;
|
|
27
30
|
readonly projections: ProjectionStore;
|
|
@@ -41,7 +44,8 @@ export interface IntegrationRuntimeInput {
|
|
|
41
44
|
readonly wakeRoot: string;
|
|
42
45
|
readonly subscriptionRunSerialiser: ProcessorRunSerialiser;
|
|
43
46
|
readonly processorRuntime: EventProcessorRuntime;
|
|
44
|
-
readonly
|
|
47
|
+
readonly triggerCheckpoints: TriggerCheckpointStore;
|
|
48
|
+
readonly triggerCoordinationKey?: (config: TriggerConfig) => string;
|
|
45
49
|
readonly decorateDeliveryAdapter?: (adapter: ExternalDeliveryAdapter, provider: ProviderInstance) => ExternalDeliveryAdapter;
|
|
46
50
|
readonly fakeDeliveryProvider?: DurableFakeDeliveryProvider;
|
|
47
51
|
readonly providerDefinitions: readonly ProviderDefinition[];
|
|
@@ -1,11 +1,15 @@
|
|
|
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 {
|
|
5
|
-
import {
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ActivityExecutionKind, activityName, } from '../activities/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';
|
|
6
8
|
import { AgentRunPublicationReactor, ArtifactRegistrationReactor, DeliveryOutcomeReactor, DeliveryService, IntegrationStreamKind, PollService, ProviderRegistry, deliveryProjectionDefinitions, fakeProviderDefinition, } from '../integrations/index.js';
|
|
7
|
-
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';
|
|
8
10
|
import { BuiltInResourceCapability, resourceId, } from '../resources/index.js';
|
|
11
|
+
import { isWorkItemStream } from '../work/index.js';
|
|
12
|
+
import { decodeCanonicalEvent } from './canonical-events.js';
|
|
9
13
|
import { hydrateFakeProviderEvidence } from './fake-provider-files.js';
|
|
10
14
|
import { createRuntimeProjectionSubscriptions, } from './projection-runtime.js';
|
|
11
15
|
import { createCapabilityResourceTransitionEvidence } from './resource-transition-evidence.js';
|
|
@@ -65,13 +69,104 @@ export async function composeIntegrationRuntime(input) {
|
|
|
65
69
|
},
|
|
66
70
|
now: () => input.clock.now().toISOString(),
|
|
67
71
|
});
|
|
68
|
-
const
|
|
69
|
-
|
|
72
|
+
const runnerIneligibility = createDurableRunnerIneligibility(input.journal, () => input.clock.now().toISOString());
|
|
73
|
+
const triggerRuns = new RunRepository(input.journal);
|
|
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
|
+
},
|
|
118
|
+
journal: input.journal,
|
|
119
|
+
capacityAvailable: async (trigger) => {
|
|
120
|
+
if (await input.isPaused())
|
|
121
|
+
return false;
|
|
122
|
+
const active = (await input.execution.list()).filter((run) => isActiveRunStatus(run.status));
|
|
123
|
+
if (active.length >= input.config.controlPlane.maxConcurrentRuns)
|
|
124
|
+
return false;
|
|
125
|
+
const workflow = input.config.orchestration.workflows[trigger.workflow];
|
|
126
|
+
const stage = workflow.stages[workflow.entry ?? Object.keys(workflow.stages)[0]];
|
|
127
|
+
const pool = stage.execution?.runnerPool ?? input.config.execution.defaultRunnerPool;
|
|
128
|
+
if (input.config.execution.runnerPools[pool] === undefined)
|
|
129
|
+
return false;
|
|
130
|
+
if (input.activities.describe(activityName(stage.activity)).executionKind !==
|
|
131
|
+
ActivityExecutionKind.Agent)
|
|
132
|
+
return true;
|
|
133
|
+
try {
|
|
134
|
+
input.runners.resolve(pool, await runnerIneligibility(), { ephemeralMcp: true });
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error instanceof NoEligibleRunnerError)
|
|
139
|
+
return false;
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
checkpoint: input.triggerCheckpoints,
|
|
70
144
|
ids: input.ids,
|
|
71
145
|
work: input.work,
|
|
72
146
|
orchestration: input.orchestration,
|
|
73
147
|
now: () => input.clock.now().toISOString(),
|
|
74
148
|
});
|
|
149
|
+
const triggerReactors = input.config.controlPlane.triggers.map((config) => createTriggerReactor(triggers, config, decodeCanonicalEvent));
|
|
150
|
+
// Registration starts at the current journal boundary; historical facts are not sources.
|
|
151
|
+
const registrationSchema = z.object({ position: z.number().int().nonnegative() }).strict();
|
|
152
|
+
for (const reactor of triggerReactors) {
|
|
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);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
75
170
|
const artifacts = new ArtifactRegistrationReactor({
|
|
76
171
|
journal: input.journal,
|
|
77
172
|
resources: input.resources,
|
|
@@ -136,11 +231,17 @@ export async function composeIntegrationRuntime(input) {
|
|
|
136
231
|
});
|
|
137
232
|
const runnerPipeline = createRunnerPipeline({
|
|
138
233
|
isPaused: input.isPaused,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
});
|
|
241
|
+
for (const trigger of input.config.controlPlane.triggers)
|
|
242
|
+
await triggers.run(trigger, {
|
|
142
243
|
commandId: input.ids.next('command'),
|
|
143
|
-
correlationId: '
|
|
244
|
+
correlationId: correlationId('trigger-tick'),
|
|
144
245
|
occurredAt: input.clock.now().toISOString(),
|
|
145
246
|
actor: { kind: EventActorKind.System, id: ControlStreamKind.Global },
|
|
146
247
|
});
|
|
@@ -166,9 +267,11 @@ export async function composeIntegrationRuntime(input) {
|
|
|
166
267
|
});
|
|
167
268
|
const requestImmediatePoll = createImmediatePollRequester(providers, input.journal, input.wakeRoot);
|
|
168
269
|
return {
|
|
270
|
+
triggers,
|
|
169
271
|
projectionSubscriptions,
|
|
170
272
|
processors: [
|
|
171
273
|
...projectionSubscriptions.processors,
|
|
274
|
+
...triggerReactors,
|
|
172
275
|
watch.processor,
|
|
173
276
|
resourceTransitions.processor,
|
|
174
277
|
artifacts.processor,
|
|
@@ -37,7 +37,7 @@ export function createSurfaceCliApplications(root, api, now) {
|
|
|
37
37
|
process.stderr.write(`Wake ${label} tick failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
38
38
|
};
|
|
39
39
|
// Intake owns provider polling, so only its resident loop backs off
|
|
40
|
-
// exponentially when idle. The runner loop owns
|
|
40
|
+
// exponentially when idle. The runner loop owns triggers, reconciliation,
|
|
41
41
|
// and delivery; it stays on a fast cadence when there is no local work.
|
|
42
42
|
// The independent durable subscriber owns activation scheduling. Delivery
|
|
43
43
|
// can still hit an external API, so consecutive errors back off
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ProcessorStateStore } from '@atolis-hq/eventing';
|
|
2
|
+
import type { TriggerCheckpointStore } from '../control-plane/index.js';
|
|
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);
|
|
7
|
+
load(triggerId: string): Promise<string | null>;
|
|
8
|
+
save(triggerId: string, slot: string): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
9
|
+
async load(triggerId) {
|
|
10
|
+
const stored = await this.state.read(`reactor:control-plane.trigger:${triggerId}`, 'cron');
|
|
11
|
+
return stored === null ? null : cursorSchema.parse(stored.value).slot;
|
|
12
|
+
}
|
|
13
|
+
async save(triggerId, slot) {
|
|
14
|
+
const value = cursorSchema.parse({ slot });
|
|
15
|
+
const existing = await this.load(triggerId);
|
|
16
|
+
if (existing !== null && Date.parse(slot) < Date.parse(existing))
|
|
17
|
+
throw new Error(`Trigger checkpoint regression: ${triggerId}`);
|
|
18
|
+
await this.state.write({
|
|
19
|
+
consumer: `reactor:control-plane.trigger:${triggerId}`,
|
|
20
|
+
key: 'cron',
|
|
21
|
+
value,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
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.62";
|
|
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,13 @@ 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:
|
|
43
|
+
case ControlEventType.TriggerInvocationStarted:
|
|
44
|
+
return previous;
|
|
35
45
|
case ControlEventType.DispatchPaused:
|
|
36
46
|
return {
|
|
37
47
|
...previous,
|
|
@@ -61,4 +71,6 @@ function withoutDispatchPause(previous) {
|
|
|
61
71
|
}
|
|
62
72
|
export const controlPlaneProjectionDefinitions = [
|
|
63
73
|
controlPlaneProjection,
|
|
74
|
+
triggerProjection,
|
|
75
|
+
triggerInvocationProjection,
|
|
64
76
|
];
|
|
@@ -4,7 +4,7 @@ export type RunnerPipelineResult = Extract<AdvanceResult, {
|
|
|
4
4
|
}>;
|
|
5
5
|
export interface RunnerPipelineStages {
|
|
6
6
|
readonly isPaused?: () => Promise<boolean>;
|
|
7
|
-
readonly
|
|
7
|
+
readonly runTriggers: () => Promise<void>;
|
|
8
8
|
readonly maintain?: () => Promise<void>;
|
|
9
9
|
readonly deliver: (signal: AbortSignal) => Promise<void>;
|
|
10
10
|
}
|
|
@@ -16,7 +16,7 @@ export interface RunnerPipeline {
|
|
|
16
16
|
run(options: AdvanceOptions, signal?: AbortSignal, beforeDelivery?: () => Promise<void>): Promise<RunnerPipelineResult>;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Runs the non-reactive internal half of a Wake tick:
|
|
19
|
+
* Runs the non-reactive internal half of a Wake tick: triggers, maintenance,
|
|
20
20
|
* and delivery. Processors are owned by the Eventing runtime. None of this touches a rate-limited external poll, so its
|
|
21
21
|
* host runs on a fast, un-backed-off cadence — see IntakePipeline for the
|
|
22
22
|
* half that does need backoff.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Runs the non-reactive internal half of a Wake tick:
|
|
2
|
+
* Runs the non-reactive internal half of a Wake tick: triggers, maintenance,
|
|
3
3
|
* and delivery. Processors are owned by the Eventing runtime. None of this touches a rate-limited external poll, so its
|
|
4
4
|
* host runs on a fast, un-backed-off cadence — see IntakePipeline for the
|
|
5
5
|
* half that does need backoff.
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
export function createRunnerPipeline(stages) {
|
|
8
8
|
const isPaused = async () => (await stages.isPaused?.()) ?? false;
|
|
9
9
|
const runOnce = async (options, signal, beforeDelivery) => {
|
|
10
|
-
|
|
11
|
-
return { kind: 'paused' };
|
|
12
|
-
await stages.runSchedules();
|
|
10
|
+
await stages.runTriggers();
|
|
13
11
|
if (await isPaused())
|
|
14
12
|
return { kind: 'paused' };
|
|
15
13
|
await stages.maintain?.();
|
|
@@ -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>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ControlEventType, selectControlEvent } from '../contracts/events.js';
|
|
2
|
+
import { ControlStreamKind } from '../contracts/streams.js';
|
|
3
|
+
/** One history document per top-level WorkItem, independent of operational scope state. */
|
|
4
|
+
export const triggerInvocationProjection = {
|
|
5
|
+
name: ControlStreamKind.TriggerInvocation,
|
|
6
|
+
select(envelope) {
|
|
7
|
+
const event = selectControlEvent(envelope);
|
|
8
|
+
return event?.stream.kind === ControlStreamKind.TriggerInvocation
|
|
9
|
+
? { key: event.stream.id }
|
|
10
|
+
: null;
|
|
11
|
+
},
|
|
12
|
+
initial: () => null,
|
|
13
|
+
project(previous, envelope) {
|
|
14
|
+
const event = selectControlEvent(envelope);
|
|
15
|
+
if (event === null)
|
|
16
|
+
return previous;
|
|
17
|
+
switch (event.event.eventType) {
|
|
18
|
+
case ControlEventType.TriggerInvocationClaimed:
|
|
19
|
+
return { claim: event.event.payload, claimedAt: event.event.occurredAt };
|
|
20
|
+
case ControlEventType.TriggerInvocationStarted:
|
|
21
|
+
if (previous === null)
|
|
22
|
+
throw new Error('Trigger start without invocation claim');
|
|
23
|
+
return { ...previous, startedAt: event.event.occurredAt };
|
|
24
|
+
case ControlEventType.TriggerInvocationFinished:
|
|
25
|
+
if (previous === null)
|
|
26
|
+
throw new Error('Trigger result without invocation claim');
|
|
27
|
+
return { ...previous, result: event.event.payload, finishedAt: event.event.occurredAt };
|
|
28
|
+
default:
|
|
29
|
+
return previous;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ProjectionDefinition } from '@atolis-hq/eventing';
|
|
2
|
+
import { ControlEventType, type ControlEventPayloads, type TriggerSource } from '../contracts/events.js';
|
|
3
|
+
export declare const triggerProjectionName = "control-plane-triggers";
|
|
4
|
+
export declare const maximumTriggerSources = 64;
|
|
5
|
+
export interface TriggerInvocationView {
|
|
6
|
+
readonly claim: ControlEventPayloads[typeof ControlEventType.TriggerInvocationClaimed];
|
|
7
|
+
readonly claimedAt: string;
|
|
8
|
+
readonly startedAt?: string;
|
|
9
|
+
readonly result?: ControlEventPayloads[typeof ControlEventType.TriggerInvocationFinished];
|
|
10
|
+
readonly finishedAt?: string;
|
|
11
|
+
readonly failureOutcomeCount?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface TriggerView {
|
|
14
|
+
readonly lastStarts: Readonly<Record<string, string>>;
|
|
15
|
+
readonly pauses: Readonly<Record<string, string>>;
|
|
16
|
+
/** Latest recorded request per trigger, rather than an occurrence history. */
|
|
17
|
+
readonly requests: readonly ControlEventPayloads[typeof ControlEventType.TriggerRequestRecorded][];
|
|
18
|
+
readonly coalesced: Readonly<Record<string, ControlEventPayloads[typeof ControlEventType.TriggerRequestRecorded] & {
|
|
19
|
+
readonly sources: readonly TriggerSource[];
|
|
20
|
+
}>>;
|
|
21
|
+
/** Operational projections contain only active claims; explicit service inspection includes history. */
|
|
22
|
+
readonly invocations: readonly TriggerInvocationView[];
|
|
23
|
+
}
|
|
24
|
+
export declare const triggerProjection: ProjectionDefinition<TriggerView>;
|