@atolis-hq/wake 0.4.62 → 0.4.64
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/artifacts/application/artifact-context-service.d.ts +30 -0
- package/dist/src/artifacts/application/artifact-context-service.js +189 -0
- package/dist/src/artifacts/application/artifact-service.d.ts +12 -2
- package/dist/src/artifacts/application/artifact-service.js +44 -1
- package/dist/src/artifacts/contracts/context-event-factory.d.ts +6 -0
- package/dist/src/artifacts/contracts/context-event-factory.js +12 -0
- package/dist/src/artifacts/contracts/context-events.d.ts +23 -0
- package/dist/src/artifacts/contracts/context-events.js +64 -0
- package/dist/src/artifacts/contracts/context.d.ts +56 -0
- package/dist/src/artifacts/contracts/context.js +38 -0
- package/dist/src/artifacts/contracts/events.d.ts +1 -0
- package/dist/src/artifacts/contracts/events.js +2 -0
- package/dist/src/artifacts/contracts/streams.d.ts +3 -0
- package/dist/src/artifacts/contracts/streams.js +7 -1
- package/dist/src/artifacts/contracts/views.d.ts +1 -0
- package/dist/src/artifacts/domain/artifact-work-item.js +1 -0
- package/dist/src/artifacts/index.d.ts +4 -0
- package/dist/src/artifacts/index.js +4 -0
- package/dist/src/artifacts/infrastructure/mcp-server.d.ts +5 -1
- package/dist/src/artifacts/infrastructure/mcp-server.js +21 -6
- package/dist/src/artifacts/infrastructure/mcp-session-store.d.ts +4 -0
- package/dist/src/artifacts/infrastructure/mcp-session-store.js +15 -0
- package/dist/src/bootstrap/artifact-mcp.d.ts +6 -1
- package/dist/src/bootstrap/artifact-mcp.js +5 -7
- package/dist/src/bootstrap/artifact-trigger-context.d.ts +30 -0
- package/dist/src/bootstrap/artifact-trigger-context.js +99 -0
- package/dist/src/bootstrap/canonical-events.js +2 -1
- package/dist/src/bootstrap/composition-root.js +13 -1
- package/dist/src/bootstrap/config/root-schema.d.ts +3 -2
- package/dist/src/bootstrap/integration-runtime.d.ts +1 -0
- package/dist/src/bootstrap/integration-runtime.js +1 -0
- 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/version.js +1 -1
- 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-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 +10 -22
- package/dist/src/control-plane/application/trigger-service.js +25 -15
- package/dist/src/control-plane/contracts/config.d.ts +3 -0
- package/dist/src/control-plane/contracts/config.js +5 -0
- 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 +1 -0
- package/dist/src/control-plane/domain/cron-trigger-policy.js +11 -0
- package/dist/src/control-plane/index.d.ts +1 -0
- package/dist/src/control-plane/index.js +1 -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
|
@@ -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,21 @@
|
|
|
1
|
+
import type { EventEnvelope, EventJournal, ProcessorRunSerialiser, ProcessorStateStore } from '@atolis-hq/eventing';
|
|
2
|
+
import type { IdGenerator } from '../../kernel/index.js';
|
|
3
|
+
import type { TriggerConfig } from '../contracts/config.js';
|
|
4
|
+
import type { TriggerInvocationView } from './trigger-projection.js';
|
|
5
|
+
import type { TriggerCheckpointStore } from './trigger-source-cursor.js';
|
|
6
|
+
import type { TriggerWorkflowPorts } from './trigger-workflow.js';
|
|
7
|
+
export interface TriggerServiceDependencies extends TriggerWorkflowPorts {
|
|
8
|
+
readonly checkpoint: TriggerCheckpointStore;
|
|
9
|
+
readonly journal: EventJournal;
|
|
10
|
+
readonly state: ProcessorStateStore;
|
|
11
|
+
readonly history: () => Promise<readonly TriggerInvocationView[]>;
|
|
12
|
+
readonly invocationScope: (workItemId: string) => Promise<string | null>;
|
|
13
|
+
readonly serialise: ProcessorRunSerialiser;
|
|
14
|
+
readonly ids: IdGenerator;
|
|
15
|
+
readonly configurations: () => readonly TriggerConfig[];
|
|
16
|
+
readonly coordinationKey?: (config: TriggerConfig) => string;
|
|
17
|
+
readonly sourceWorkItem: (event: EventEnvelope) => Promise<string | null>;
|
|
18
|
+
readonly isDispatchPaused: () => Promise<boolean>;
|
|
19
|
+
readonly capacityAvailable: (config: TriggerConfig) => Promise<boolean>;
|
|
20
|
+
readonly now: () => string;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,35 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { IdGenerator } from '../../kernel/index.js';
|
|
1
|
+
import type { CommandContext, EventEnvelope } from '@atolis-hq/eventing';
|
|
3
2
|
import type { TriggerConfig } from '../contracts/config.js';
|
|
4
3
|
import { type TriggerSource } from '../contracts/events.js';
|
|
5
|
-
import { type
|
|
6
|
-
import { type
|
|
7
|
-
import type {
|
|
4
|
+
import { type TriggerSkipDiagnostic } from '../contracts/trigger-diagnostics.js';
|
|
5
|
+
import { type TriggerView } from './trigger-projection.js';
|
|
6
|
+
import type { TriggerServiceDependencies } from './trigger-service-ports.js';
|
|
7
|
+
export type { TriggerServiceDependencies } from './trigger-service-ports.js';
|
|
8
8
|
export type { TriggerCheckpointStore } from './trigger-source-cursor.js';
|
|
9
|
+
export type TriggerInspectionView = TriggerView & {
|
|
10
|
+
readonly diagnostics: readonly TriggerSkipDiagnostic[];
|
|
11
|
+
};
|
|
9
12
|
export declare const triggerCriticalSectionConsumer = "control-plane:trigger-coordination";
|
|
10
|
-
export interface TriggerServiceDependencies extends TriggerWorkflowPorts {
|
|
11
|
-
readonly checkpoint: TriggerCheckpointStore;
|
|
12
|
-
readonly journal: EventJournal;
|
|
13
|
-
readonly state: ProcessorStateStore;
|
|
14
|
-
readonly history: () => Promise<readonly TriggerInvocationView[]>;
|
|
15
|
-
readonly invocationScope: (workItemId: string) => Promise<string | null>;
|
|
16
|
-
readonly serialise: ProcessorRunSerialiser;
|
|
17
|
-
readonly ids: IdGenerator;
|
|
18
|
-
readonly configurations: () => readonly TriggerConfig[];
|
|
19
|
-
readonly coordinationKey?: (config: TriggerConfig) => string;
|
|
20
|
-
readonly sourceWorkItem: (event: EventEnvelope) => Promise<string | null>;
|
|
21
|
-
readonly isDispatchPaused: () => Promise<boolean>;
|
|
22
|
-
readonly capacityAvailable: (config: TriggerConfig) => Promise<boolean>;
|
|
23
|
-
readonly now: () => string;
|
|
24
|
-
}
|
|
25
13
|
/** Requests and claims are journal facts; the cron cursor is processor recovery state. */
|
|
26
14
|
export declare class TriggerService {
|
|
27
15
|
private readonly dependencies;
|
|
28
16
|
private readonly policy;
|
|
29
17
|
private readonly reader;
|
|
30
18
|
private readonly sourceCursor;
|
|
19
|
+
private readonly diagnostics;
|
|
31
20
|
constructor(dependencies: TriggerServiceDependencies);
|
|
32
|
-
get(): Promise<
|
|
21
|
+
get(): Promise<TriggerInspectionView>;
|
|
33
22
|
reconcile(context: CommandContext): Promise<void>;
|
|
34
23
|
pause(triggerId: string, reason: string, context: CommandContext): Promise<void>;
|
|
35
24
|
resume(triggerId: string, context: CommandContext): Promise<void>;
|
|
@@ -43,7 +32,6 @@ export declare class TriggerService {
|
|
|
43
32
|
private emit;
|
|
44
33
|
private request;
|
|
45
34
|
private suppressed;
|
|
46
|
-
private eligible;
|
|
47
35
|
private advanceCoalesced;
|
|
48
36
|
private recover;
|
|
49
37
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { artifactContextCoordinationKey } from '../contracts/config.js';
|
|
1
2
|
import { ControlEventType, TriggerRequestDisposition, TriggerSourceKind, } from '../contracts/events.js';
|
|
3
|
+
import { TriggerSkipReason } from '../contracts/trigger-diagnostics.js';
|
|
2
4
|
import { CronTriggerPolicy } from '../domain/cron-trigger-policy.js';
|
|
5
|
+
import { TriggerDiagnostics } from './trigger-diagnostics.js';
|
|
3
6
|
import { appendTriggerFact, sourceIdentity } from './trigger-facts.js';
|
|
4
|
-
import { maximumTriggerSources
|
|
7
|
+
import { maximumTriggerSources } from './trigger-projection.js';
|
|
5
8
|
import { recoverTriggerInvocation } from './trigger-recovery.js';
|
|
6
9
|
import { hasActiveInvocation, isOwnScopeSource } from './trigger-rules.js';
|
|
7
10
|
import { TriggerSourceCursor } from './trigger-source-cursor.js';
|
|
@@ -13,8 +16,10 @@ export class TriggerService {
|
|
|
13
16
|
policy = new CronTriggerPolicy();
|
|
14
17
|
reader;
|
|
15
18
|
sourceCursor;
|
|
19
|
+
diagnostics;
|
|
16
20
|
constructor(dependencies) {
|
|
17
21
|
this.dependencies = dependencies;
|
|
22
|
+
this.diagnostics = new TriggerDiagnostics(dependencies, triggerCriticalSectionConsumer);
|
|
18
23
|
this.reader = new TriggerStateReader(dependencies.journal);
|
|
19
24
|
this.sourceCursor = new TriggerSourceCursor(dependencies);
|
|
20
25
|
}
|
|
@@ -22,6 +27,7 @@ export class TriggerService {
|
|
|
22
27
|
return this.serialise(async () => ({
|
|
23
28
|
...(await this.view()),
|
|
24
29
|
invocations: await this.dependencies.history(),
|
|
30
|
+
diagnostics: await this.diagnostics.get(),
|
|
25
31
|
}));
|
|
26
32
|
}
|
|
27
33
|
async reconcile(context) {
|
|
@@ -82,7 +88,9 @@ export class TriggerService {
|
|
|
82
88
|
return this.dependencies.serialise(triggerCriticalSectionConsumer, new AbortController().signal, operation);
|
|
83
89
|
}
|
|
84
90
|
key(config) {
|
|
85
|
-
return
|
|
91
|
+
return config.contextScope === undefined
|
|
92
|
+
? (this.dependencies.coordinationKey?.(config) ?? config.id)
|
|
93
|
+
: artifactContextCoordinationKey(config.contextScope);
|
|
86
94
|
}
|
|
87
95
|
commandKey(triggerId) {
|
|
88
96
|
const config = this.configured(triggerId);
|
|
@@ -112,14 +120,21 @@ export class TriggerService {
|
|
|
112
120
|
const coordinationKey = this.key(config);
|
|
113
121
|
// The reactor checkpoint consumes suppressed sources. Emitting another trigger request
|
|
114
122
|
// here could itself become a source when subscribed to Control Plane events.
|
|
115
|
-
if (duplicate
|
|
123
|
+
if (duplicate) {
|
|
116
124
|
await this.sourceCursor.consume(config.id, source, event);
|
|
117
125
|
return false;
|
|
118
126
|
}
|
|
119
|
-
|
|
120
|
-
this.
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
if (await this.suppressed(view, config, coordinationKey, event)) {
|
|
128
|
+
await this.diagnostics.record(config.id, source, TriggerSkipReason.OwnScope);
|
|
129
|
+
await this.sourceCursor.consume(config.id, source, event);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const reason = await this.diagnostics.ineligibleReason(view, config.id, config, this.configured(config.id) !== undefined, hasActiveInvocation(view, coordinationKey));
|
|
133
|
+
const eligible = reason === undefined;
|
|
134
|
+
if (reason !== undefined)
|
|
135
|
+
await this.diagnostics.record(config.id, source, reason);
|
|
136
|
+
else if ((view.coalesced[coordinationKey]?.sources.length ?? 0) >= maximumTriggerSources)
|
|
137
|
+
await this.diagnostics.record(config.id, source, TriggerSkipReason.PendingLimit);
|
|
123
138
|
if (eligible && (view.coalesced[coordinationKey]?.sources.length ?? 0) < maximumTriggerSources)
|
|
124
139
|
await this.emit({
|
|
125
140
|
eventType: ControlEventType.TriggerRequestRecorded,
|
|
@@ -143,11 +158,6 @@ export class TriggerService {
|
|
|
143
158
|
invocationScope: this.dependencies.invocationScope,
|
|
144
159
|
});
|
|
145
160
|
}
|
|
146
|
-
async eligible(config) {
|
|
147
|
-
return (!(await this.dependencies.isDispatchPaused()) &&
|
|
148
|
-
(config.when?.capacityAvailable !== true ||
|
|
149
|
-
(await this.dependencies.capacityAvailable(config))));
|
|
150
|
-
}
|
|
151
161
|
async advanceCoalesced(context) {
|
|
152
162
|
const view = await this.view();
|
|
153
163
|
for (const request of Object.values(view.coalesced)) {
|
|
@@ -155,9 +165,9 @@ export class TriggerService {
|
|
|
155
165
|
continue;
|
|
156
166
|
const config = this.configured(request.triggerId);
|
|
157
167
|
const identity = `trigger:${request.triggerId}:${sourceIdentity(request.source)}`;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
const reason = await this.diagnostics.ineligibleReason(view, request.triggerId, config, config !== undefined);
|
|
169
|
+
if (reason !== undefined || config === undefined) {
|
|
170
|
+
await this.diagnostics.record(request.triggerId, request.source, reason ?? TriggerSkipReason.Removed);
|
|
161
171
|
// This recorded request was reconsidered and consumed; later eligibility is not a source.
|
|
162
172
|
await this.emit({
|
|
163
173
|
eventType: ControlEventType.TriggerRequestRecorded,
|
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
export interface TriggerConfig {
|
|
3
3
|
readonly id: string;
|
|
4
4
|
readonly workflow: string;
|
|
5
|
+
readonly contextScope?: string;
|
|
5
6
|
readonly on: {
|
|
6
7
|
readonly events?: readonly string[];
|
|
7
8
|
readonly cron?: string;
|
|
@@ -25,6 +26,7 @@ export declare const controlPlaneConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
25
26
|
triggers: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
26
27
|
id: z.ZodString;
|
|
27
28
|
workflow: z.ZodString;
|
|
29
|
+
contextScope: z.ZodOptional<z.ZodString>;
|
|
28
30
|
on: z.ZodObject<{
|
|
29
31
|
events: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
30
32
|
cron: z.ZodOptional<z.ZodString>;
|
|
@@ -38,3 +40,4 @@ export declare const controlPlaneConfigSchema: z.ZodDefault<z.ZodObject<{
|
|
|
38
40
|
maxPollBackoffMs: z.ZodOptional<z.ZodNumber>;
|
|
39
41
|
}, z.core.$strict>>;
|
|
40
42
|
}, z.core.$strict>>;
|
|
43
|
+
export declare function artifactContextCoordinationKey(contextScope: string): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { artifactSharedContextNameSchema } from '../../artifacts/index.js';
|
|
2
3
|
import { CronTriggerPolicy } from '../domain/cron-trigger-policy.js';
|
|
3
4
|
const triggerSchema = z
|
|
4
5
|
.object({
|
|
@@ -8,6 +9,7 @@ const triggerSchema = z
|
|
|
8
9
|
.min(1)
|
|
9
10
|
.refine((id) => !/[\\/]/.test(id), 'Trigger id must not contain path separators'),
|
|
10
11
|
workflow: z.string().trim().min(1),
|
|
12
|
+
contextScope: artifactSharedContextNameSchema.optional(),
|
|
11
13
|
on: z
|
|
12
14
|
.object({
|
|
13
15
|
events: z.array(z.string().trim().min(1)).min(1).optional(),
|
|
@@ -59,3 +61,6 @@ export const controlPlaneConfigSchema = z
|
|
|
59
61
|
triggers: [],
|
|
60
62
|
resident: { pollBackoffMs: 1000 },
|
|
61
63
|
});
|
|
64
|
+
export function artifactContextCoordinationKey(contextScope) {
|
|
65
|
+
return `context:${contextScope}`;
|
|
66
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ValueOf } from '../../kernel/index.js';
|
|
3
|
+
export declare const TriggerSkipReason: {
|
|
4
|
+
readonly OwnScope: "own-scope";
|
|
5
|
+
readonly Paused: "paused";
|
|
6
|
+
readonly Removed: "removed";
|
|
7
|
+
readonly DispatchPaused: "dispatch-paused";
|
|
8
|
+
readonly Capacity: "capacity-unavailable";
|
|
9
|
+
readonly PendingLimit: "pending-source-limit";
|
|
10
|
+
};
|
|
11
|
+
export type TriggerSkipReason = ValueOf<typeof TriggerSkipReason>;
|
|
12
|
+
export declare const triggerSkipDiagnosticSchema: z.ZodObject<{
|
|
13
|
+
triggerId: z.ZodString;
|
|
14
|
+
source: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
15
|
+
kind: z.ZodLiteral<"event">;
|
|
16
|
+
eventId: z.ZodString;
|
|
17
|
+
eventType: z.ZodString;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
kind: z.ZodLiteral<"cron">;
|
|
20
|
+
slot: z.ZodString;
|
|
21
|
+
}, z.core.$strict>], "kind">;
|
|
22
|
+
occurredAt: z.ZodString;
|
|
23
|
+
reason: z.ZodEnum<{
|
|
24
|
+
readonly OwnScope: "own-scope";
|
|
25
|
+
readonly Paused: "paused";
|
|
26
|
+
readonly Removed: "removed";
|
|
27
|
+
readonly DispatchPaused: "dispatch-paused";
|
|
28
|
+
readonly Capacity: "capacity-unavailable";
|
|
29
|
+
readonly PendingLimit: "pending-source-limit";
|
|
30
|
+
}>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type TriggerSkipDiagnostic = z.infer<typeof triggerSkipDiagnosticSchema>;
|
|
33
|
+
export declare const maximumTriggerDiagnostics = 256;
|
|
34
|
+
export declare const triggerDiagnosticsSchema: z.ZodArray<z.ZodObject<{
|
|
35
|
+
triggerId: z.ZodString;
|
|
36
|
+
source: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
37
|
+
kind: z.ZodLiteral<"event">;
|
|
38
|
+
eventId: z.ZodString;
|
|
39
|
+
eventType: z.ZodString;
|
|
40
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
41
|
+
kind: z.ZodLiteral<"cron">;
|
|
42
|
+
slot: z.ZodString;
|
|
43
|
+
}, z.core.$strict>], "kind">;
|
|
44
|
+
occurredAt: z.ZodString;
|
|
45
|
+
reason: z.ZodEnum<{
|
|
46
|
+
readonly OwnScope: "own-scope";
|
|
47
|
+
readonly Paused: "paused";
|
|
48
|
+
readonly Removed: "removed";
|
|
49
|
+
readonly DispatchPaused: "dispatch-paused";
|
|
50
|
+
readonly Capacity: "capacity-unavailable";
|
|
51
|
+
readonly PendingLimit: "pending-source-limit";
|
|
52
|
+
}>;
|
|
53
|
+
}, z.core.$strict>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { triggerSourceSchema } from './events.js';
|
|
3
|
+
export const TriggerSkipReason = {
|
|
4
|
+
OwnScope: 'own-scope',
|
|
5
|
+
Paused: 'paused',
|
|
6
|
+
Removed: 'removed',
|
|
7
|
+
DispatchPaused: 'dispatch-paused',
|
|
8
|
+
Capacity: 'capacity-unavailable',
|
|
9
|
+
PendingLimit: 'pending-source-limit',
|
|
10
|
+
};
|
|
11
|
+
export const triggerSkipDiagnosticSchema = z
|
|
12
|
+
.object({
|
|
13
|
+
triggerId: z.string().min(1),
|
|
14
|
+
source: triggerSourceSchema,
|
|
15
|
+
occurredAt: z.string().datetime({ offset: true }),
|
|
16
|
+
reason: z.enum(TriggerSkipReason),
|
|
17
|
+
})
|
|
18
|
+
.strict();
|
|
19
|
+
// Operational diagnostics are bounded processor state, not occurrence history.
|
|
20
|
+
export const maximumTriggerDiagnostics = 256;
|
|
21
|
+
export const triggerDiagnosticsSchema = z
|
|
22
|
+
.array(triggerSkipDiagnosticSchema)
|
|
23
|
+
.max(maximumTriggerDiagnostics);
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { CronExpressionParser } from 'cron-parser';
|
|
2
2
|
export class CronTriggerPolicy {
|
|
3
|
+
nextOccurrence(cron, now) {
|
|
4
|
+
const fields = cron.trim().split(/\s+/);
|
|
5
|
+
const expression = CronExpressionParser.parse(cron, { currentDate: now, tz: 'UTC' });
|
|
6
|
+
const dayOfMonth = fieldExpression(fields, 2, 4);
|
|
7
|
+
const dayOfWeek = fieldExpression(fields, 4, 2);
|
|
8
|
+
while (true) {
|
|
9
|
+
const date = expression.next().toDate();
|
|
10
|
+
if (matchesDays(date, dayOfMonth, dayOfWeek))
|
|
11
|
+
return date.toISOString();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
3
14
|
elapsedSlots(config, now, checkpoint, maximumSlots = Number.POSITIVE_INFINITY) {
|
|
4
15
|
const end = minute(new Date(now));
|
|
5
16
|
const start = checkpoint === null ? end : minute(new Date(new Date(checkpoint).getTime() + 60_000));
|
|
@@ -10,6 +10,7 @@ export * from './application/trigger-service.js';
|
|
|
10
10
|
export * from './application/intake-pipeline.js';
|
|
11
11
|
export * from './application/runner-pipeline.js';
|
|
12
12
|
export * from './application/work-cancellation-policy.js';
|
|
13
|
+
export * from './contracts/trigger-diagnostics.js';
|
|
13
14
|
export * from './contracts/commands.js';
|
|
14
15
|
export * from './contracts/config.js';
|
|
15
16
|
export * from './contracts/events.js';
|
|
@@ -9,6 +9,7 @@ export * from './application/trigger-service.js';
|
|
|
9
9
|
export * from './application/intake-pipeline.js';
|
|
10
10
|
export * from './application/runner-pipeline.js';
|
|
11
11
|
export * from './application/work-cancellation-policy.js';
|
|
12
|
+
export * from './contracts/trigger-diagnostics.js';
|
|
12
13
|
export * from './contracts/commands.js';
|
|
13
14
|
export * from './contracts/config.js';
|
|
14
15
|
export * from './contracts/events.js';
|
|
@@ -173,8 +173,8 @@ export declare const supplementalCommandConfigSchema: z.ZodObject<{
|
|
|
173
173
|
with: z.ZodOptional<z.ZodUnknown>;
|
|
174
174
|
allowedActors: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
175
175
|
human: "human";
|
|
176
|
-
watch: "watch";
|
|
177
176
|
auto: "auto";
|
|
177
|
+
watch: "watch";
|
|
178
178
|
}>>>;
|
|
179
179
|
}, z.core.$strict>;
|
|
180
180
|
export declare const workflowDefinitionConfigSchema: z.ZodObject<{
|
|
@@ -184,8 +184,8 @@ export declare const workflowDefinitionConfigSchema: z.ZodObject<{
|
|
|
184
184
|
with: z.ZodOptional<z.ZodUnknown>;
|
|
185
185
|
allowedActors: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
186
186
|
human: "human";
|
|
187
|
-
watch: "watch";
|
|
188
187
|
auto: "auto";
|
|
188
|
+
watch: "watch";
|
|
189
189
|
}>>>;
|
|
190
190
|
}, z.core.$strict>>>;
|
|
191
191
|
watches: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ActivityOutcomeKind } from '../../../activities/index.js';
|
|
2
|
+
import type { TriggerRequestDisposition, TriggerSkipReason, TriggerSourceKind } from '../../../control-plane/index.js';
|
|
2
3
|
import type { RunStatus } from '../../../execution/index.js';
|
|
3
4
|
import type { ApiCommandStatus } from './control-plane.js';
|
|
4
5
|
export declare const AcceptedCommandStatusValue: {
|
|
@@ -42,4 +43,11 @@ export declare const TranscriptGroupKindValue: {
|
|
|
42
43
|
readonly Session: string;
|
|
43
44
|
readonly Run: string;
|
|
44
45
|
};
|
|
46
|
+
export declare const TriggerSourceKindValue: typeof TriggerSourceKind;
|
|
47
|
+
export declare const TriggerRequestDispositionValue: typeof TriggerRequestDisposition;
|
|
48
|
+
export declare const TriggerSkipReasonValue: typeof TriggerSkipReason;
|
|
49
|
+
export declare const TriggerFinishedStatusValue: {
|
|
50
|
+
readonly Completed: "completed" | "superseded";
|
|
51
|
+
readonly Superseded: "completed" | "superseded";
|
|
52
|
+
};
|
|
45
53
|
export {};
|
|
@@ -58,3 +58,26 @@ export const TranscriptGroupKindValue = {
|
|
|
58
58
|
Session: transcriptGroupKinds[0],
|
|
59
59
|
Run: transcriptGroupKinds[1],
|
|
60
60
|
};
|
|
61
|
+
// Trigger transport vocabulary avoids importing the server implementation into the browser.
|
|
62
|
+
export const TriggerSourceKindValue = {
|
|
63
|
+
Event: 'event',
|
|
64
|
+
Cron: 'cron',
|
|
65
|
+
};
|
|
66
|
+
export const TriggerRequestDispositionValue = {
|
|
67
|
+
Coalesced: 'coalesced',
|
|
68
|
+
Skipped: 'skipped',
|
|
69
|
+
};
|
|
70
|
+
export const TriggerSkipReasonValue = {
|
|
71
|
+
OwnScope: 'own-scope',
|
|
72
|
+
Paused: 'paused',
|
|
73
|
+
Removed: 'removed',
|
|
74
|
+
DispatchPaused: 'dispatch-paused',
|
|
75
|
+
Capacity: 'capacity-unavailable',
|
|
76
|
+
PendingLimit: 'pending-source-limit',
|
|
77
|
+
};
|
|
78
|
+
const triggerFinishedStatusShape = { completed: true, superseded: true };
|
|
79
|
+
const triggerFinishedStatuses = Object.keys(triggerFinishedStatusShape);
|
|
80
|
+
export const TriggerFinishedStatusValue = {
|
|
81
|
+
Completed: triggerFinishedStatuses[0],
|
|
82
|
+
Superseded: triggerFinishedStatuses[1],
|
|
83
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TriggerConfig, TriggerInvocationView, TriggerSkipDiagnostic, TriggerView } from '../../../control-plane/index.js';
|
|
2
|
+
import type { ValueOf } from '../../../kernel/index.js';
|
|
3
|
+
export declare const TriggerStatus: {
|
|
4
|
+
readonly Enabled: "running" | "paused" | "removed" | "enabled";
|
|
5
|
+
readonly Paused: "running" | "paused" | "removed" | "enabled";
|
|
6
|
+
readonly Running: "running" | "paused" | "removed" | "enabled";
|
|
7
|
+
readonly Removed: "running" | "paused" | "removed" | "enabled";
|
|
8
|
+
};
|
|
9
|
+
export type TriggerStatus = ValueOf<typeof TriggerStatus>;
|
|
10
|
+
export interface TriggerResponse {
|
|
11
|
+
readonly triggerId: string;
|
|
12
|
+
readonly status: TriggerStatus;
|
|
13
|
+
readonly definition: TriggerConfig | null;
|
|
14
|
+
readonly paused: boolean;
|
|
15
|
+
readonly pauseReason: string | null;
|
|
16
|
+
readonly nextOccurrence: string | null;
|
|
17
|
+
readonly pending: readonly TriggerView['coalesced'][string][];
|
|
18
|
+
readonly latestSkip: TriggerSkipDiagnostic | null;
|
|
19
|
+
readonly invocations: readonly (TriggerInvocationView & {
|
|
20
|
+
readonly workItemKey: string;
|
|
21
|
+
})[];
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const triggerStatusShape = { enabled: true, paused: true, running: true, removed: true };
|
|
2
|
+
const triggerStatuses = Object.keys(triggerStatusShape);
|
|
3
|
+
export const TriggerStatus = {
|
|
4
|
+
Enabled: triggerStatuses[0],
|
|
5
|
+
Paused: triggerStatuses[1],
|
|
6
|
+
Running: triggerStatuses[2],
|
|
7
|
+
Removed: triggerStatuses[3],
|
|
8
|
+
};
|
|
@@ -19,6 +19,7 @@ export interface WorkItemResponse {
|
|
|
19
19
|
readonly lastRunOutcome?: string;
|
|
20
20
|
}
|
|
21
21
|
export interface WorkDetailResponse {
|
|
22
|
+
readonly triggerOrigin?: string;
|
|
22
23
|
readonly work: WorkItemResponse;
|
|
23
24
|
readonly resources: readonly ResourceItemResponse[];
|
|
24
25
|
readonly orchestration: {
|
|
@@ -7,10 +7,10 @@ export declare const WorkflowDiagramStatus: {
|
|
|
7
7
|
};
|
|
8
8
|
export type WorkflowDiagramStatus = ValueOf<typeof WorkflowDiagramStatus>;
|
|
9
9
|
export declare const WorkflowDiagramChildKind: {
|
|
10
|
-
readonly Activity: "activity" | "watch" | "
|
|
11
|
-
readonly Watch: "activity" | "watch" | "
|
|
12
|
-
readonly WatchGate: "activity" | "watch" | "
|
|
13
|
-
readonly Reactor: "activity" | "watch" | "
|
|
10
|
+
readonly Activity: "activity" | "watch" | "reactor" | "watch-gate";
|
|
11
|
+
readonly Watch: "activity" | "watch" | "reactor" | "watch-gate";
|
|
12
|
+
readonly WatchGate: "activity" | "watch" | "reactor" | "watch-gate";
|
|
13
|
+
readonly Reactor: "activity" | "watch" | "reactor" | "watch-gate";
|
|
14
14
|
};
|
|
15
15
|
export type WorkflowDiagramChildKind = ValueOf<typeof WorkflowDiagramChildKind>;
|
|
16
16
|
export interface WorkflowDiagramMetricsResponse {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RunStatus } from '../../../execution/index.js';
|
|
2
2
|
import type { AnalyticsReport, ReportDescriptor, ReportWindowId } from '../../../kernel/index.js';
|
|
3
|
-
import type { ApiCommandResult, AuditEventResponse, BoardCardResponse, BoardResponse, CommandsResponse, ConfigurationResponse, ControlPlaneStatusResponse, ConversationMessageRequest, HealthResponse, MetricsResponse, ResourceItemResponse, ResourceResponse, ResponseMeta, RunnerResponse, RunResponse, RunTranscriptResponse, StatusResponse, WebhookSetupResponse, WorkDetailResponse, WorkflowDiagramsResponse, WorkflowInstanceResponse, WorkItemResponse, WorkItemTranscriptResponse } from '../contracts/index.js';
|
|
3
|
+
import type { ApiCommandResult, AuditEventResponse, BoardCardResponse, BoardResponse, CommandsResponse, ConfigurationResponse, ControlPlaneStatusResponse, ConversationMessageRequest, HealthResponse, MetricsResponse, ResourceItemResponse, ResourceResponse, ResponseMeta, RunnerResponse, RunResponse, RunTranscriptResponse, StatusResponse, TriggerResponse, WebhookSetupResponse, WorkDetailResponse, WorkflowDiagramsResponse, WorkflowInstanceResponse, WorkItemResponse, WorkItemTranscriptResponse } from '../contracts/index.js';
|
|
4
4
|
import type { AnalyticsSummaryResponse } from '../contracts/observability.js';
|
|
5
5
|
export interface CollectionQuery {
|
|
6
6
|
readonly cursor?: {
|
|
@@ -54,6 +54,12 @@ export interface ApiApplications {
|
|
|
54
54
|
resumeDispatch?(command: ApiCommandRequest): Promise<ApiCommandResult>;
|
|
55
55
|
clearMaintenance?(command: ApiClearMaintenanceRequest): Promise<ApiCommandResult>;
|
|
56
56
|
};
|
|
57
|
+
readonly triggers?: {
|
|
58
|
+
list(): Promise<ApiResourceResult<readonly TriggerResponse[]>>;
|
|
59
|
+
detail(id: string): Promise<ApiResourceResult<TriggerResponse> | undefined>;
|
|
60
|
+
pause(id: string, command: ApiCommandRequest): Promise<ApiCommandResult>;
|
|
61
|
+
resume(id: string, command: ApiCommandRequest): Promise<ApiCommandResult>;
|
|
62
|
+
};
|
|
57
63
|
readonly work: {
|
|
58
64
|
list(query: CollectionQuery): Promise<ApiCollectionPage<WorkItemResponse>>;
|
|
59
65
|
detail(key: string): Promise<ApiResourceResult<WorkDetailResponse> | undefined>;
|
|
@@ -16,6 +16,16 @@ export async function dispatchCommand(applications, url, body) {
|
|
|
16
16
|
const request = commandRequest(body);
|
|
17
17
|
if (isHttpResponse(request))
|
|
18
18
|
return request;
|
|
19
|
+
const trigger = /^\/api\/v1\/triggers\/([^/]+)\/commands\/(pause|resume)$/.exec(url.pathname);
|
|
20
|
+
if (trigger !== null) {
|
|
21
|
+
const id = decodePathSegment(trigger[1]);
|
|
22
|
+
if (id instanceof ApiPathError)
|
|
23
|
+
return invalidPath(id.message);
|
|
24
|
+
if (applications.triggers === undefined)
|
|
25
|
+
return unavailable('triggers');
|
|
26
|
+
const operation = trigger[2] === 'pause' ? applications.triggers.pause : applications.triggers.resume;
|
|
27
|
+
return accepted(await operation(id, request), applications.now(), 200);
|
|
28
|
+
}
|
|
19
29
|
const control = await dispatchControlCommand(applications, url.pathname, request);
|
|
20
30
|
if (control !== undefined)
|
|
21
31
|
return control;
|
|
@@ -16,6 +16,8 @@ export async function dispatchRead(applications, method, url, signal) {
|
|
|
16
16
|
if (url.pathname === '/api/v1/observability/reports' ||
|
|
17
17
|
url.pathname === '/api/v1/observability/summary')
|
|
18
18
|
return readReports(applications, url, signal);
|
|
19
|
+
if (url.pathname === '/api/v1/triggers')
|
|
20
|
+
return noQuery(url, () => readTriggers(applications));
|
|
19
21
|
const resource = await readSingleton(applications, url);
|
|
20
22
|
if (resource !== undefined)
|
|
21
23
|
return resource;
|
|
@@ -24,6 +26,15 @@ export async function dispatchRead(applications, method, url, signal) {
|
|
|
24
26
|
return page;
|
|
25
27
|
if (url.search !== '')
|
|
26
28
|
return invalidQuery('This resource does not accept query parameters');
|
|
29
|
+
const trigger = /^\/api\/v1\/triggers\/([^/]+)$/.exec(url.pathname);
|
|
30
|
+
if (trigger !== null) {
|
|
31
|
+
const id = decodePathSegment(trigger[1]);
|
|
32
|
+
if (id instanceof ApiPathError)
|
|
33
|
+
return invalidPath(id.message);
|
|
34
|
+
return applications.triggers === undefined
|
|
35
|
+
? unavailable('triggers')
|
|
36
|
+
: found(await applications.triggers.detail(id));
|
|
37
|
+
}
|
|
27
38
|
return readDetail(applications, url.pathname);
|
|
28
39
|
}
|
|
29
40
|
async function readSingleton(applications, url) {
|
|
@@ -209,3 +220,8 @@ async function readReports(applications, url, signal) {
|
|
|
209
220
|
return invalidQuery('Unknown report identifier', 'report');
|
|
210
221
|
return ok(await reports.report(report, window, signal));
|
|
211
222
|
}
|
|
223
|
+
async function readTriggers(applications) {
|
|
224
|
+
return applications.triggers === undefined
|
|
225
|
+
? unavailable('triggers')
|
|
226
|
+
: ok(await applications.triggers.list());
|
|
227
|
+
}
|