@anthusai/papyrus 5.129.0 → 5.130.0-next.2
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/amplify/agents/admin-policy-grant.feature +20 -0
- package/amplify/agents/admin-policy-grant.js +31 -0
- package/amplify/agents/admin-policy-grant.ts +35 -0
- package/amplify/agents/pieces.js +11 -0
- package/amplify/agents/pieces.ts +13 -0
- package/amplify/agents/schedule-group.js +75 -0
- package/amplify/agents/schedule-group.ts +82 -0
- package/amplify/agents/stack.js +27 -0
- package/amplify/agents/stack.ts +53 -0
- package/amplify/agents/wake-queue.js +121 -0
- package/amplify/agents/wake-queue.ts +138 -0
- package/amplify/data/resource.js +25 -0
- package/amplify/data/resource.ts +25 -0
- package/amplify/data/schema.js +27 -1
- package/amplify/data/schema.ts +27 -1
- package/amplify/functions/announcements/schema.js +86 -0
- package/amplify/functions/announcements/schema.ts +86 -0
- package/amplify/functions/assignment-action/handler.ts +4 -0
- package/amplify/functions/automation-view/schema.js +8 -1
- package/amplify/functions/automation-view/schema.ts +8 -1
- package/amplify/functions/automation-view/wire.js +7 -11
- package/amplify/functions/automation-view/wire.ts +7 -14
- package/amplify/functions/localization-dispatch/handler.py +4 -3
- package/amplify/functions/localization-dispatch/wire.js +6 -5
- package/amplify/functions/localization-dispatch/wire.ts +6 -5
- package/amplify/functions/model-attachment-upload/handler.ts +4 -0
- package/amplify/functions/model-attachment-upload/rules.js +2 -0
- package/amplify/functions/model-attachment-upload/rules.ts +2 -0
- package/amplify/functions/procedure-action/handler.ts +44 -27
- package/amplify/functions/procedure-action/wake-key.js +48 -0
- package/amplify/functions/procedure-action/wake-key.ts +49 -0
- package/amplify/site-backend.js +12 -2
- package/amplify/site-backend.ts +16 -2
- package/components/automation-panel.tsx +6 -0
- package/components/automation-view.tsx +6 -4
- package/components/newsroom-ops-overview.tsx +2 -0
- package/components/today-panel.tsx +43 -0
- package/components/today-view.tsx +171 -0
- package/infra/agent-sync.test.js +34 -0
- package/infra/agent-sync.test.ts +35 -0
- package/infra/build-specs.js +21 -0
- package/infra/build-specs.ts +25 -0
- package/infra/ci-gate.test.js +1 -1
- package/infra/ci-gate.test.ts +1 -1
- package/infra/procedure-sync.test.js +48 -0
- package/infra/procedure-sync.test.ts +50 -0
- package/lib/automation-fixture.ts +14 -9
- package/lib/automation-overview.ts +18 -5
- package/lib/guidelines/writing-guidelines-admin.ts +1 -1
- package/lib/images/operations.generated.ts +72 -42
- package/lib/tenant-keys.js +1 -0
- package/lib/tenant-keys.ts +1 -0
- package/lib/today-client.ts +34 -0
- package/lib/today-fixture.ts +52 -0
- package/lib/today-overview.ts +111 -0
- package/package.json +6 -1
- package/routes.manifest.json +1 -1
|
@@ -4,7 +4,8 @@ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
|
4
4
|
import { Architecture, CfnEventSourceMapping, Function as LambdaFunction, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
5
5
|
import { pythonLambdaCode } from "../shared/python-bundle.js";
|
|
6
6
|
import { connectToSiteApi } from "../../site-api-access.js";
|
|
7
|
-
import { AUTOMATION_RUN_NOW_LEADING_KEYS, AUTOMATION_RUN_NOW_TABLE_ACTIONS
|
|
7
|
+
import { AUTOMATION_RUN_NOW_LEADING_KEYS, AUTOMATION_RUN_NOW_TABLE_ACTIONS } from "../automation-view/wire.js";
|
|
8
|
+
import { allowWakeSending } from "../../agents/wake-queue.js";
|
|
8
9
|
import { MONITORING_TABLE_PARAMETER, MONITORING_VIEW_TABLE_ACTIONS, monitoringViewParameterArn, monitoringViewTableArns } from "../monitoring-view/wire.js";
|
|
9
10
|
/**
|
|
10
11
|
* Translate on publish (docs/story-translation-procedure.md, "Translating on publish"): a DynamoDB Streams consumer on the LocalizationRequest table.
|
|
@@ -13,7 +14,7 @@ import { MONITORING_TABLE_PARAMETER, MONITORING_VIEW_TABLE_ACTIONS, monitoringVi
|
|
|
13
14
|
* run saved cleanly. It calls no model and publishes nothing itself.
|
|
14
15
|
*
|
|
15
16
|
* What it may do, and nothing else: read and update LocalizationRequest rows and read Automation records of its own site's API; read the monitoring
|
|
16
|
-
* table and write one Run now row in a monitor's partition (the automation-view grant);
|
|
17
|
+
* table and write one Run now row in a monitor's partition (the automation-view grant); put a wake on the site's own wake queue; invoke the content-actions function.
|
|
17
18
|
* A shared stack (one backend for several tenants) is not wired: its rows carry a tenant the dispatcher does not act for (docs/multi-tenancy.md).
|
|
18
19
|
*/
|
|
19
20
|
export const DISPATCH_API_FIELDS = [
|
|
@@ -42,7 +43,7 @@ function localizationRequestStream(backend) {
|
|
|
42
43
|
return found.attrStreamArn;
|
|
43
44
|
}
|
|
44
45
|
/** Wires the dispatcher, or nothing when the site's schema leaves out the localization models (`excludeModelGroups`: no table, nothing to dispatch). */
|
|
45
|
-
export function wireLocalizationDispatch(backend, contentActionsLambda) {
|
|
46
|
+
export function wireLocalizationDispatch(backend, contentActionsLambda, brandId) {
|
|
46
47
|
if (!backend.data.resources.tables.LocalizationRequest)
|
|
47
48
|
return undefined;
|
|
48
49
|
const streamArn = localizationRequestStream(backend);
|
|
@@ -66,7 +67,6 @@ export function wireLocalizationDispatch(backend, contentActionsLambda) {
|
|
|
66
67
|
});
|
|
67
68
|
connectToSiteApi(dispatcher, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
68
69
|
dispatcher.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
|
|
69
|
-
dispatcher.addEnvironment("PROCEDURE_RUNNER_FUNCTION", PROCEDURE_RUNNER_FUNCTION_NAME);
|
|
70
70
|
dispatcher.addEnvironment(CONTENT_ACTIONS_ENV, contentActionsLambda.functionName);
|
|
71
71
|
const apiId = backend.data.resources.graphqlApi.apiId;
|
|
72
72
|
const region = stack.region;
|
|
@@ -87,8 +87,9 @@ export function wireLocalizationDispatch(backend, contentActionsLambda) {
|
|
|
87
87
|
dispatcher.addToRolePolicy(new PolicyStatement({
|
|
88
88
|
effect: Effect.ALLOW,
|
|
89
89
|
actions: ["lambda:InvokeFunction"],
|
|
90
|
-
resources: [
|
|
90
|
+
resources: [contentActionsLambda.functionArn],
|
|
91
91
|
}));
|
|
92
|
+
allowWakeSending(dispatcher, brandId);
|
|
92
93
|
dispatcher.addToRolePolicy(new PolicyStatement({ effect: Effect.ALLOW, actions: STREAM_READ_ACTIONS, resources: [streamArn] }));
|
|
93
94
|
new CfnEventSourceMapping(stack, "LocalizationDispatcherStreamMapping", {
|
|
94
95
|
eventSourceArn: streamArn,
|
|
@@ -4,7 +4,8 @@ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
|
4
4
|
import { Architecture, CfnEventSourceMapping, Function as LambdaFunction, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
5
5
|
import { pythonLambdaCode } from "../shared/python-bundle";
|
|
6
6
|
import { connectToSiteApi } from "../../site-api-access";
|
|
7
|
-
import { AUTOMATION_RUN_NOW_LEADING_KEYS, AUTOMATION_RUN_NOW_TABLE_ACTIONS
|
|
7
|
+
import { AUTOMATION_RUN_NOW_LEADING_KEYS, AUTOMATION_RUN_NOW_TABLE_ACTIONS } from "../automation-view/wire";
|
|
8
|
+
import { allowWakeSending } from "../../agents/wake-queue";
|
|
8
9
|
import { MONITORING_TABLE_PARAMETER, MONITORING_VIEW_TABLE_ACTIONS, monitoringViewParameterArn, monitoringViewTableArns } from "../monitoring-view/wire";
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -14,7 +15,7 @@ import { MONITORING_TABLE_PARAMETER, MONITORING_VIEW_TABLE_ACTIONS, monitoringVi
|
|
|
14
15
|
* run saved cleanly. It calls no model and publishes nothing itself.
|
|
15
16
|
*
|
|
16
17
|
* What it may do, and nothing else: read and update LocalizationRequest rows and read Automation records of its own site's API; read the monitoring
|
|
17
|
-
* table and write one Run now row in a monitor's partition (the automation-view grant);
|
|
18
|
+
* table and write one Run now row in a monitor's partition (the automation-view grant); put a wake on the site's own wake queue; invoke the content-actions function.
|
|
18
19
|
* A shared stack (one backend for several tenants) is not wired: its rows carry a tenant the dispatcher does not act for (docs/multi-tenancy.md).
|
|
19
20
|
*/
|
|
20
21
|
export const DISPATCH_API_FIELDS = [
|
|
@@ -45,7 +46,7 @@ function localizationRequestStream(backend: any): string {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/** Wires the dispatcher, or nothing when the site's schema leaves out the localization models (`excludeModelGroups`: no table, nothing to dispatch). */
|
|
48
|
-
export function wireLocalizationDispatch(backend: any, contentActionsLambda: LambdaFunction): LambdaFunction | undefined {
|
|
49
|
+
export function wireLocalizationDispatch(backend: any, contentActionsLambda: LambdaFunction, brandId: string): LambdaFunction | undefined {
|
|
49
50
|
if (!backend.data.resources.tables.LocalizationRequest) return undefined;
|
|
50
51
|
const streamArn = localizationRequestStream(backend);
|
|
51
52
|
const stack = backend.createStack("localization-dispatch");
|
|
@@ -71,7 +72,6 @@ export function wireLocalizationDispatch(backend: any, contentActionsLambda: Lam
|
|
|
71
72
|
});
|
|
72
73
|
connectToSiteApi(dispatcher, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl as string);
|
|
73
74
|
dispatcher.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
|
|
74
|
-
dispatcher.addEnvironment("PROCEDURE_RUNNER_FUNCTION", PROCEDURE_RUNNER_FUNCTION_NAME);
|
|
75
75
|
dispatcher.addEnvironment(CONTENT_ACTIONS_ENV, contentActionsLambda.functionName);
|
|
76
76
|
const apiId = backend.data.resources.graphqlApi.apiId as string;
|
|
77
77
|
const region = stack.region;
|
|
@@ -97,9 +97,10 @@ export function wireLocalizationDispatch(backend: any, contentActionsLambda: Lam
|
|
|
97
97
|
new PolicyStatement({
|
|
98
98
|
effect: Effect.ALLOW,
|
|
99
99
|
actions: ["lambda:InvokeFunction"],
|
|
100
|
-
resources: [
|
|
100
|
+
resources: [contentActionsLambda.functionArn],
|
|
101
101
|
}),
|
|
102
102
|
);
|
|
103
|
+
allowWakeSending(dispatcher, brandId);
|
|
103
104
|
dispatcher.addToRolePolicy(new PolicyStatement({ effect: Effect.ALLOW, actions: STREAM_READ_ACTIONS, resources: [streamArn] }));
|
|
104
105
|
new CfnEventSourceMapping(stack, "LocalizationDispatcherStreamMapping", {
|
|
105
106
|
eventSourceArn: streamArn,
|
|
@@ -27,6 +27,7 @@ const ALLOWED_OWNER_KINDS = new Set([
|
|
|
27
27
|
"announcement",
|
|
28
28
|
"assignment",
|
|
29
29
|
"assignmentEvent",
|
|
30
|
+
"delivery",
|
|
30
31
|
"item",
|
|
31
32
|
"knowledgeRawPayload",
|
|
32
33
|
"message",
|
|
@@ -61,8 +62,10 @@ const ALLOWED_ROLES = new Set([
|
|
|
61
62
|
"image_record",
|
|
62
63
|
"image_candidate_file",
|
|
63
64
|
"announcement_document",
|
|
65
|
+
"delivery_text", // a Delivery's words, one file in S3 (src/papyrus_content/announcements/deliveries.py)
|
|
64
66
|
"doctrine_document",
|
|
65
67
|
"doctrine_asset",
|
|
68
|
+
"doctrine_files",
|
|
66
69
|
]);
|
|
67
70
|
const ALLOWED_MEDIA_TYPES = new Set([
|
|
68
71
|
"application/json",
|
|
@@ -293,6 +296,7 @@ function ownerModelName(ownerKind: string): string {
|
|
|
293
296
|
if (ownerKind === "announcement") return "Announcement";
|
|
294
297
|
if (ownerKind === "assignment") return "Assignment";
|
|
295
298
|
if (ownerKind === "assignmentEvent") return "AssignmentEvent";
|
|
299
|
+
if (ownerKind === "delivery") return "Delivery";
|
|
296
300
|
if (ownerKind === "item") return "Item";
|
|
297
301
|
if (ownerKind === "knowledgeRawPayload") return "KnowledgeRawPayload";
|
|
298
302
|
if (ownerKind === "message") return "Message";
|
|
@@ -13,6 +13,8 @@ export const CANDIDATE_PICTURE_ROLE = "image_candidate_file";
|
|
|
13
13
|
// a file the document names (a design system's font) is bytes of no declared type, so it takes application/octet-stream and nothing else.
|
|
14
14
|
export const DOCTRINE_DOCUMENT_ROLE = "doctrine_document";
|
|
15
15
|
export const DOCTRINE_ASSET_ROLE = "doctrine_asset";
|
|
16
|
+
// The writing guidelines are a set of guideline files, one Markdown file each (store.py FILES_ROLE): general text types, general cap.
|
|
17
|
+
export const DOCTRINE_FILES_ROLE = "doctrine_files";
|
|
16
18
|
export const OCTET_STREAM_ROLES = new Set([DOCTRINE_ASSET_ROLE]);
|
|
17
19
|
export const OCTET_STREAM_MEDIA_TYPE = "application/octet-stream";
|
|
18
20
|
export function isVisualRole(role) {
|
|
@@ -16,6 +16,8 @@ export const CANDIDATE_PICTURE_ROLE = "image_candidate_file";
|
|
|
16
16
|
// a file the document names (a design system's font) is bytes of no declared type, so it takes application/octet-stream and nothing else.
|
|
17
17
|
export const DOCTRINE_DOCUMENT_ROLE = "doctrine_document";
|
|
18
18
|
export const DOCTRINE_ASSET_ROLE = "doctrine_asset";
|
|
19
|
+
// The writing guidelines are a set of guideline files, one Markdown file each (store.py FILES_ROLE): general text types, general cap.
|
|
20
|
+
export const DOCTRINE_FILES_ROLE = "doctrine_files";
|
|
19
21
|
export const OCTET_STREAM_ROLES = new Set([DOCTRINE_ASSET_ROLE]);
|
|
20
22
|
export const OCTET_STREAM_MEDIA_TYPE = "application/octet-stream";
|
|
21
23
|
|
|
@@ -4,6 +4,7 @@ import { Amplify } from "aws-amplify";
|
|
|
4
4
|
import { generateClient } from "aws-amplify/data";
|
|
5
5
|
import type { Schema } from "../../data/resource";
|
|
6
6
|
import { claimGroups } from "../../../lib/staff-groups";
|
|
7
|
+
import { assertWakeKey, isAlreadyCreated, runIdForWakeKey } from "./wake-key";
|
|
7
8
|
|
|
8
9
|
type DataClient = ReturnType<typeof generateClient<Schema>>;
|
|
9
10
|
type DataClientErrors = Array<{ message?: string | null } | string | null> | null | undefined;
|
|
@@ -24,21 +25,28 @@ const LAMBDA_DATA_AUTH_MODE = "iam";
|
|
|
24
25
|
const IMMEDIATE_ASSIGNMENT_TYPES = new Set(["procedure.run"]);
|
|
25
26
|
let clientPromise: Promise<DataClient> | null = null;
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
/** The handler, built over a source of the data client so a test can supply a client of its own; `handler` is the one the function runs. */
|
|
29
|
+
export function createHandler(getClient: () => Promise<DataClient>) {
|
|
30
|
+
return async (event: ProcedureEvent) => dispatch(event, getClient);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const handler = createHandler(getDataClient);
|
|
34
|
+
|
|
35
|
+
async function dispatch(event: ProcedureEvent, getClient: () => Promise<DataClient>) {
|
|
28
36
|
const fieldName = normalizeRequiredString(event.info?.fieldName ?? event.fieldName, "fieldName");
|
|
29
|
-
if (fieldName === "listNewsroomProcedureDefinitions") return listProcedureDefinitions();
|
|
30
|
-
if (fieldName === "getNewsroomProcedureDefinition") return getProcedureDefinition(event.arguments);
|
|
31
|
-
if (fieldName === "saveNewsroomProcedureDefinition") return saveProcedureDefinition(event);
|
|
32
|
-
if (fieldName === "saveNewsroomProcedureVersionDraft") return saveProcedureVersionDraft(event);
|
|
33
|
-
if (fieldName === "publishNewsroomProcedureVersion") return publishProcedureVersion(event);
|
|
34
|
-
if (fieldName === "startNewsroomProcedureRun") return startProcedureRun(event);
|
|
35
|
-
if (fieldName === "getNewsroomProcedureRun") return getProcedureRun(event.arguments);
|
|
36
|
-
if (fieldName === "listNewsroomProcedureRunsByProcedure") return listProcedureRunsByProcedure(event.arguments);
|
|
37
|
+
if (fieldName === "listNewsroomProcedureDefinitions") return listProcedureDefinitions(getClient);
|
|
38
|
+
if (fieldName === "getNewsroomProcedureDefinition") return getProcedureDefinition(getClient, event.arguments);
|
|
39
|
+
if (fieldName === "saveNewsroomProcedureDefinition") return saveProcedureDefinition(getClient, event);
|
|
40
|
+
if (fieldName === "saveNewsroomProcedureVersionDraft") return saveProcedureVersionDraft(getClient, event);
|
|
41
|
+
if (fieldName === "publishNewsroomProcedureVersion") return publishProcedureVersion(getClient, event);
|
|
42
|
+
if (fieldName === "startNewsroomProcedureRun") return startProcedureRun(getClient, event);
|
|
43
|
+
if (fieldName === "getNewsroomProcedureRun") return getProcedureRun(getClient, event.arguments);
|
|
44
|
+
if (fieldName === "listNewsroomProcedureRunsByProcedure") return listProcedureRunsByProcedure(getClient, event.arguments);
|
|
37
45
|
throw new Error(`Unsupported procedure operation ${fieldName}.`);
|
|
38
46
|
};
|
|
39
47
|
|
|
40
|
-
async function listProcedureDefinitions() {
|
|
41
|
-
const client = await
|
|
48
|
+
async function listProcedureDefinitions(getClient: () => Promise<DataClient>) {
|
|
49
|
+
const client = await getClient();
|
|
42
50
|
const definitions = await listProcedureDefinitionsPage(client);
|
|
43
51
|
const versions = await listProcedureVersionsPage(client);
|
|
44
52
|
const runs = await listProcedureRunsPage(client);
|
|
@@ -63,8 +71,8 @@ async function listProcedureDefinitions() {
|
|
|
63
71
|
};
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
async function getProcedureDefinition(args: Record<string, unknown>) {
|
|
67
|
-
const client = await
|
|
74
|
+
async function getProcedureDefinition(getClient: () => Promise<DataClient>, args: Record<string, unknown>) {
|
|
75
|
+
const client = await getClient();
|
|
68
76
|
const id = normalizeOptionalString(args.id);
|
|
69
77
|
const procedureKey = normalizeOptionalString(args.procedureKey);
|
|
70
78
|
const definition = id
|
|
@@ -101,9 +109,9 @@ async function getProcedureDefinition(args: Record<string, unknown>) {
|
|
|
101
109
|
};
|
|
102
110
|
}
|
|
103
111
|
|
|
104
|
-
async function saveProcedureDefinition(event: ProcedureEvent) {
|
|
112
|
+
async function saveProcedureDefinition(getClient: () => Promise<DataClient>, event: ProcedureEvent) {
|
|
105
113
|
requireAdmin(event);
|
|
106
|
-
const client = await
|
|
114
|
+
const client = await getClient();
|
|
107
115
|
const now = new Date().toISOString();
|
|
108
116
|
const actor = getIdentityLabel(event) ?? "Papyrus admin";
|
|
109
117
|
const input = objectValue(event.arguments.input);
|
|
@@ -137,9 +145,9 @@ async function saveProcedureDefinition(event: ProcedureEvent) {
|
|
|
137
145
|
return { ok: true, definition: response.data };
|
|
138
146
|
}
|
|
139
147
|
|
|
140
|
-
async function saveProcedureVersionDraft(event: ProcedureEvent) {
|
|
148
|
+
async function saveProcedureVersionDraft(getClient: () => Promise<DataClient>, event: ProcedureEvent) {
|
|
141
149
|
requireAdmin(event);
|
|
142
|
-
const client = await
|
|
150
|
+
const client = await getClient();
|
|
143
151
|
const now = new Date().toISOString();
|
|
144
152
|
const actor = getIdentityLabel(event) ?? "Papyrus admin";
|
|
145
153
|
const input = objectValue(event.arguments.input);
|
|
@@ -188,9 +196,9 @@ async function saveProcedureVersionDraft(event: ProcedureEvent) {
|
|
|
188
196
|
return { ok: true, version: created.data };
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
async function publishProcedureVersion(event: ProcedureEvent) {
|
|
199
|
+
async function publishProcedureVersion(getClient: () => Promise<DataClient>, event: ProcedureEvent) {
|
|
192
200
|
requireAdmin(event);
|
|
193
|
-
const client = await
|
|
201
|
+
const client = await getClient();
|
|
194
202
|
const now = new Date().toISOString();
|
|
195
203
|
const actor = getIdentityLabel(event) ?? "Papyrus admin";
|
|
196
204
|
const versionId = normalizeRequiredString(event.arguments.versionId, "versionId");
|
|
@@ -220,8 +228,8 @@ async function publishProcedureVersion(event: ProcedureEvent) {
|
|
|
220
228
|
return { ok: true, procedureId: definition.id, versionId: version.id };
|
|
221
229
|
}
|
|
222
230
|
|
|
223
|
-
async function startProcedureRun(event: ProcedureEvent) {
|
|
224
|
-
const client = await
|
|
231
|
+
async function startProcedureRun(getClient: () => Promise<DataClient>, event: ProcedureEvent) {
|
|
232
|
+
const client = await getClient();
|
|
225
233
|
const now = new Date().toISOString();
|
|
226
234
|
const actorSub = getIdentitySub(event);
|
|
227
235
|
const actorLabel = normalizeOptionalString(event.arguments.actorLabel) ?? getIdentityLabel(event) ?? actorSub ?? "Papyrus newsroom";
|
|
@@ -244,7 +252,10 @@ async function startProcedureRun(event: ProcedureEvent) {
|
|
|
244
252
|
if (!validation.ok) throw new Error(`Procedure parameter validation failed: ${validation.error}`);
|
|
245
253
|
const normalizedInput = validation.normalizedInput;
|
|
246
254
|
const isExternalCliRun = executionMode === "external_cli";
|
|
247
|
-
|
|
255
|
+
// A run the runner executes is one wake: its id comes from the wake key and the record is created with a condition, so the same wake
|
|
256
|
+
// can never make a second record. A run queued for the Assignment worker is not a wake and keeps its own id.
|
|
257
|
+
const wakeKey = isExternalCliRun ? assertWakeKey(event.arguments.wakeKey) : null;
|
|
258
|
+
const runId = wakeKey ? runIdForWakeKey(wakeKey) : `procedure-run-${safeId(definition.procedureKey)}-${now.replace(/[^0-9TZ]/g, "")}-${randomUUID().slice(0, 8)}`;
|
|
248
259
|
const assignmentId = isExternalCliRun ? null : `assignment-procedure-run-${hashShort([runId, definition.id, version.id])}`;
|
|
249
260
|
const runResponse = await client.models.ProcedureRun.create({
|
|
250
261
|
id: runId,
|
|
@@ -253,7 +264,8 @@ async function startProcedureRun(event: ProcedureEvent) {
|
|
|
253
264
|
procedureVersionId: version.id,
|
|
254
265
|
procedureVersionNumber: Number(version.versionNumber ?? 1),
|
|
255
266
|
assignmentId,
|
|
256
|
-
runStatus: isExternalCliRun ? "
|
|
267
|
+
runStatus: isExternalCliRun ? "started" : "queued",
|
|
268
|
+
wakeKey,
|
|
257
269
|
requestedBy: actorLabel,
|
|
258
270
|
requestedAt: now,
|
|
259
271
|
startedAt: isExternalCliRun ? now : null,
|
|
@@ -267,6 +279,10 @@ async function startProcedureRun(event: ProcedureEvent) {
|
|
|
267
279
|
attempt: 1,
|
|
268
280
|
newsroomFeedKey: "procedures",
|
|
269
281
|
} as never, { authMode: LAMBDA_DATA_AUTH_MODE });
|
|
282
|
+
if (wakeKey && isAlreadyCreated(runResponse.errors)) {
|
|
283
|
+
const existing = await getRequiredRecord(client.models.ProcedureRun, runId, "ProcedureRun");
|
|
284
|
+
return { ok: true, duplicate: true, runId, runStatus: existing.runStatus, procedureKey: definition.procedureKey, executionMode };
|
|
285
|
+
}
|
|
270
286
|
assertNoDataErrors(runResponse.errors, "create ProcedureRun");
|
|
271
287
|
if (!runResponse.data) throw new Error("ProcedureRun create returned no data.");
|
|
272
288
|
if (isExternalCliRun) {
|
|
@@ -274,6 +290,7 @@ async function startProcedureRun(event: ProcedureEvent) {
|
|
|
274
290
|
ok: true,
|
|
275
291
|
assignmentId: null,
|
|
276
292
|
assignmentStatus: null,
|
|
293
|
+
duplicate: false,
|
|
277
294
|
runId,
|
|
278
295
|
procedureId: definition.id,
|
|
279
296
|
procedureKey: definition.procedureKey,
|
|
@@ -350,8 +367,8 @@ async function startProcedureRun(event: ProcedureEvent) {
|
|
|
350
367
|
};
|
|
351
368
|
}
|
|
352
369
|
|
|
353
|
-
async function getProcedureRun(args: Record<string, unknown>) {
|
|
354
|
-
const client = await
|
|
370
|
+
async function getProcedureRun(getClient: () => Promise<DataClient>, args: Record<string, unknown>) {
|
|
371
|
+
const client = await getClient();
|
|
355
372
|
const runId = normalizeRequiredString(args.id, "id");
|
|
356
373
|
const run = await getRequiredRecord(client.models.ProcedureRun, runId, "ProcedureRun");
|
|
357
374
|
const assignment = normalizeOptionalString(run.assignmentId)
|
|
@@ -360,8 +377,8 @@ async function getProcedureRun(args: Record<string, unknown>) {
|
|
|
360
377
|
return { ...run, assignment };
|
|
361
378
|
}
|
|
362
379
|
|
|
363
|
-
async function listProcedureRunsByProcedure(args: Record<string, unknown>) {
|
|
364
|
-
const client = await
|
|
380
|
+
async function listProcedureRunsByProcedure(getClient: () => Promise<DataClient>, args: Record<string, unknown>) {
|
|
381
|
+
const client = await getClient();
|
|
365
382
|
const procedureId = normalizeRequiredString(args.procedureId, "procedureId");
|
|
366
383
|
const runs = await listProcedureRunsByProcedureId(client, procedureId);
|
|
367
384
|
return {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/** Wake keys (docs/design/always-on-agents-architecture.md, slice A2). The run record's id is derived from the key, so one wake is one record. */
|
|
3
|
+
const SEPARATOR = "|";
|
|
4
|
+
const MAX_KEY_CHARACTERS = 1000;
|
|
5
|
+
export function assertWakeKey(value) {
|
|
6
|
+
if (typeof value !== "string" || !value)
|
|
7
|
+
throw new Error("A run needs a wake key.");
|
|
8
|
+
const parts = value.split(SEPARATOR);
|
|
9
|
+
if (value.length > MAX_KEY_CHARACTERS || (parts.length !== 3 && parts.length !== 4) || parts.some((part) => !part.trim())) {
|
|
10
|
+
throw new Error(`"${value}" is not a wake key.`);
|
|
11
|
+
}
|
|
12
|
+
if (parts.length === 3 && parts[1] !== "schedule" && parts[1] !== "manual") {
|
|
13
|
+
throw new Error(`"${value}" has three parts, so its second part must be "schedule" or "manual".`);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
export function runIdForWakeKey(wakeKey) {
|
|
18
|
+
return `procedure-run-wake-${createHash("sha256").update(assertWakeKey(wakeKey)).digest("hex").slice(0, 32)}`;
|
|
19
|
+
}
|
|
20
|
+
const CONDITIONAL_TYPE = /(^|[:.#\s])ConditionalCheckFailedException$/;
|
|
21
|
+
const CONDITIONAL_TEXT = /conditional request failed|ConditionalCheckFailed/i;
|
|
22
|
+
const TYPE_FIELDS = ["errorType", "name", "code", "__type"];
|
|
23
|
+
const NESTED_FIELDS = ["originalError", "cause", "extensions", "errorInfo", "errors"];
|
|
24
|
+
/**
|
|
25
|
+
* True when a create was refused because a record with that id already exists: any error in the answer, or nested inside one, whose type is
|
|
26
|
+
* DynamoDB's conditional-check failure (the data API names it `DynamoDB:ConditionalCheckFailedException` in `errorType`) or whose text says so.
|
|
27
|
+
* Any other error, or an error of a shape not listed here, is not a duplicate; the caller then throws it, so a miss is a false failure and
|
|
28
|
+
* never a second run.
|
|
29
|
+
*/
|
|
30
|
+
export function isAlreadyCreated(errors) {
|
|
31
|
+
return (errors ?? []).some((error) => isConditionalFailure(error, new Set()));
|
|
32
|
+
}
|
|
33
|
+
function isConditionalFailure(error, seen) {
|
|
34
|
+
if (typeof error === "string")
|
|
35
|
+
return CONDITIONAL_TEXT.test(error);
|
|
36
|
+
if (!error || typeof error !== "object" || seen.has(error))
|
|
37
|
+
return false;
|
|
38
|
+
seen.add(error);
|
|
39
|
+
const record = error;
|
|
40
|
+
if (typeof record.message === "string" && CONDITIONAL_TEXT.test(record.message))
|
|
41
|
+
return true;
|
|
42
|
+
if (TYPE_FIELDS.some((field) => typeof record[field] === "string" && CONDITIONAL_TYPE.test(record[field])))
|
|
43
|
+
return true;
|
|
44
|
+
return NESTED_FIELDS.some((field) => {
|
|
45
|
+
const nested = record[field];
|
|
46
|
+
return Array.isArray(nested) ? nested.some((entry) => isConditionalFailure(entry, seen)) : isConditionalFailure(nested, seen);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
/** Wake keys (docs/design/always-on-agents-architecture.md, slice A2). The run record's id is derived from the key, so one wake is one record. */
|
|
4
|
+
const SEPARATOR = "|";
|
|
5
|
+
const MAX_KEY_CHARACTERS = 1000;
|
|
6
|
+
|
|
7
|
+
export function assertWakeKey(value: unknown): string {
|
|
8
|
+
if (typeof value !== "string" || !value) throw new Error("A run needs a wake key.");
|
|
9
|
+
const parts = value.split(SEPARATOR);
|
|
10
|
+
if (value.length > MAX_KEY_CHARACTERS || (parts.length !== 3 && parts.length !== 4) || parts.some((part) => !part.trim())) {
|
|
11
|
+
throw new Error(`"${value}" is not a wake key.`);
|
|
12
|
+
}
|
|
13
|
+
if (parts.length === 3 && parts[1] !== "schedule" && parts[1] !== "manual") {
|
|
14
|
+
throw new Error(`"${value}" has three parts, so its second part must be "schedule" or "manual".`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function runIdForWakeKey(wakeKey: string): string {
|
|
20
|
+
return `procedure-run-wake-${createHash("sha256").update(assertWakeKey(wakeKey)).digest("hex").slice(0, 32)}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const CONDITIONAL_TYPE = /(^|[:.#\s])ConditionalCheckFailedException$/;
|
|
24
|
+
const CONDITIONAL_TEXT = /conditional request failed|ConditionalCheckFailed/i;
|
|
25
|
+
const TYPE_FIELDS = ["errorType", "name", "code", "__type"] as const;
|
|
26
|
+
const NESTED_FIELDS = ["originalError", "cause", "extensions", "errorInfo", "errors"] as const;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* True when a create was refused because a record with that id already exists: any error in the answer, or nested inside one, whose type is
|
|
30
|
+
* DynamoDB's conditional-check failure (the data API names it `DynamoDB:ConditionalCheckFailedException` in `errorType`) or whose text says so.
|
|
31
|
+
* Any other error, or an error of a shape not listed here, is not a duplicate; the caller then throws it, so a miss is a false failure and
|
|
32
|
+
* never a second run.
|
|
33
|
+
*/
|
|
34
|
+
export function isAlreadyCreated(errors: ReadonlyArray<unknown> | null | undefined): boolean {
|
|
35
|
+
return (errors ?? []).some((error) => isConditionalFailure(error, new Set()));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isConditionalFailure(error: unknown, seen: Set<unknown>): boolean {
|
|
39
|
+
if (typeof error === "string") return CONDITIONAL_TEXT.test(error);
|
|
40
|
+
if (!error || typeof error !== "object" || seen.has(error)) return false;
|
|
41
|
+
seen.add(error);
|
|
42
|
+
const record = error as Record<string, unknown>;
|
|
43
|
+
if (typeof record.message === "string" && CONDITIONAL_TEXT.test(record.message)) return true;
|
|
44
|
+
if (TYPE_FIELDS.some((field) => typeof record[field] === "string" && CONDITIONAL_TYPE.test(record[field] as string))) return true;
|
|
45
|
+
return NESTED_FIELDS.some((field) => {
|
|
46
|
+
const nested = record[field];
|
|
47
|
+
return Array.isArray(nested) ? nested.some((entry) => isConditionalFailure(entry, seen)) : isConditionalFailure(nested, seen);
|
|
48
|
+
});
|
|
49
|
+
}
|
package/amplify/site-backend.js
CHANGED
|
@@ -33,6 +33,9 @@ import { cliLoginBrokerCode, cliLoginPagesCode } from "./cli-login/bundle.js";
|
|
|
33
33
|
import { addCliRemoteLogin, planCliEnrollment, planCliRemoteLogin } from "./cli-login/remote-login.js";
|
|
34
34
|
import { cognitoAuthorizeEndpoint } from "./cli-login/cognito-endpoint.js";
|
|
35
35
|
import { defineSiteData } from "./data/resource.js";
|
|
36
|
+
import { agentPieces } from "./agents/pieces.js";
|
|
37
|
+
import { ADMIN_AGENT_POLICY_GRANT_STACK_NAME, ADMIN_AGENT_POLICY_GROUP, addAdminAgentPolicyGrant } from "./agents/admin-policy-grant.js";
|
|
38
|
+
import { addAgentsStack } from "./agents/stack.js";
|
|
36
39
|
import { isBootstrapStage, resolveExcludedModelGroups } from "./data/schema.js";
|
|
37
40
|
import { editorialChecks } from "./functions/editorial-checks/resource.js";
|
|
38
41
|
import { automationView } from "./functions/automation-view/resource.js";
|
|
@@ -770,10 +773,10 @@ export function defineSiteBackend(papyrusSite, options = {}) {
|
|
|
770
773
|
if (costAttribution && sharedTier)
|
|
771
774
|
applySiteBackendCostTags(backend.stack, costAttribution);
|
|
772
775
|
wireMonitoringView(backend, emailMonitorId);
|
|
773
|
-
wireAutomationView(backend);
|
|
776
|
+
wireAutomationView(backend, siteBackendIdentity.brandId);
|
|
774
777
|
// Translate on publish (languages.auto): a stream consumer on the LocalizationRequest records. A shared stack's rows carry a tenant it does not act for.
|
|
775
778
|
if (tenancyMode !== "shared")
|
|
776
|
-
wireLocalizationDispatch(backend, contentActionsLambda);
|
|
779
|
+
wireLocalizationDispatch(backend, contentActionsLambda, siteBackendIdentity.brandId);
|
|
777
780
|
// The names of concepts in each language: a stream consumer on the SemanticNode records writes every concept's primary-language label rows.
|
|
778
781
|
if (tenancyMode !== "shared")
|
|
779
782
|
wireEntityLabelSync(backend);
|
|
@@ -781,6 +784,13 @@ export function defineSiteBackend(papyrusSite, options = {}) {
|
|
|
781
784
|
wireProposalActions(backend);
|
|
782
785
|
// Announcements are off until the owner turns them on; the parameters and the lease are per site (the brand id names the site).
|
|
783
786
|
wireAnnouncements(backend, siteBackendIdentity.brandId);
|
|
787
|
+
// Every always-on agent resource is in the one `agents` stack, which the first deploy of a new site leaves out (amplify/agents/stack.ts).
|
|
788
|
+
addAgentsStack((name) => backend.createStack(name), agentPieces(siteBackendIdentity.brandId), isBootstrapStage(process.env));
|
|
789
|
+
// The signed-in admin may put and get the agent policy document's versions (`papyrus agents set-rung --apply`). A dedicated site only: the grant names every
|
|
790
|
+
// tenant's prefix, which a shared stack's admin must not hold.
|
|
791
|
+
if (tenancyMode !== "shared") {
|
|
792
|
+
addAdminAgentPolicyGrant(backend.createStack(ADMIN_AGENT_POLICY_GRANT_STACK_NAME), backend.auth.resources.groups[ADMIN_AGENT_POLICY_GROUP].role, storageBucket.bucketArn);
|
|
793
|
+
}
|
|
784
794
|
wirePlugins(backend, plugins, contentActionsLambda, s3ProjectionPublication !== undefined);
|
|
785
795
|
if (tenancyMode === "shared") {
|
|
786
796
|
// The loop at the top reaches the functions Amplify defines. A shared stack also has functions that wires and plugins make with `new Function`
|
package/amplify/site-backend.ts
CHANGED
|
@@ -40,6 +40,9 @@ import { cliLoginBrokerCode, cliLoginPagesCode } from "./cli-login/bundle";
|
|
|
40
40
|
import { addCliRemoteLogin, planCliEnrollment, planCliRemoteLogin } from "./cli-login/remote-login";
|
|
41
41
|
import { cognitoAuthorizeEndpoint } from "./cli-login/cognito-endpoint";
|
|
42
42
|
import { defineSiteData } from "./data/resource";
|
|
43
|
+
import { agentPieces } from "./agents/pieces";
|
|
44
|
+
import { ADMIN_AGENT_POLICY_GRANT_STACK_NAME, ADMIN_AGENT_POLICY_GROUP, addAdminAgentPolicyGrant } from "./agents/admin-policy-grant";
|
|
45
|
+
import { addAgentsStack } from "./agents/stack";
|
|
43
46
|
import { isBootstrapStage, resolveExcludedModelGroups } from "./data/schema";
|
|
44
47
|
import { editorialChecks } from "./functions/editorial-checks/resource";
|
|
45
48
|
import { automationView } from "./functions/automation-view/resource";
|
|
@@ -930,15 +933,26 @@ export function defineSiteBackend(papyrusSite: PapyrusSite, options: DefineSiteB
|
|
|
930
933
|
// The shared stack reports usage per tenant through Prospectus later (kanbus-f45f7f); until then its resources are only tagged.
|
|
931
934
|
if (costAttribution && sharedTier) applySiteBackendCostTags(backend.stack, costAttribution);
|
|
932
935
|
wireMonitoringView(backend, emailMonitorId);
|
|
933
|
-
wireAutomationView(backend);
|
|
936
|
+
wireAutomationView(backend, siteBackendIdentity.brandId);
|
|
934
937
|
// Translate on publish (languages.auto): a stream consumer on the LocalizationRequest records. A shared stack's rows carry a tenant it does not act for.
|
|
935
|
-
if (tenancyMode !== "shared") wireLocalizationDispatch(backend, contentActionsLambda);
|
|
938
|
+
if (tenancyMode !== "shared") wireLocalizationDispatch(backend, contentActionsLambda, siteBackendIdentity.brandId);
|
|
936
939
|
// The names of concepts in each language: a stream consumer on the SemanticNode records writes every concept's primary-language label rows.
|
|
937
940
|
if (tenancyMode !== "shared") wireEntityLabelSync(backend);
|
|
938
941
|
wireImageService(backend);
|
|
939
942
|
wireProposalActions(backend);
|
|
940
943
|
// Announcements are off until the owner turns them on; the parameters and the lease are per site (the brand id names the site).
|
|
941
944
|
wireAnnouncements(backend, siteBackendIdentity.brandId);
|
|
945
|
+
// Every always-on agent resource is in the one `agents` stack, which the first deploy of a new site leaves out (amplify/agents/stack.ts).
|
|
946
|
+
addAgentsStack((name) => backend.createStack(name), agentPieces(siteBackendIdentity.brandId), isBootstrapStage(process.env));
|
|
947
|
+
// The signed-in admin may put and get the agent policy document's versions (`papyrus agents set-rung --apply`). A dedicated site only: the grant names every
|
|
948
|
+
// tenant's prefix, which a shared stack's admin must not hold.
|
|
949
|
+
if (tenancyMode !== "shared") {
|
|
950
|
+
addAdminAgentPolicyGrant(
|
|
951
|
+
backend.createStack(ADMIN_AGENT_POLICY_GRANT_STACK_NAME),
|
|
952
|
+
backend.auth.resources.groups[ADMIN_AGENT_POLICY_GROUP].role,
|
|
953
|
+
storageBucket.bucketArn,
|
|
954
|
+
);
|
|
955
|
+
}
|
|
942
956
|
wirePlugins(backend, plugins, contentActionsLambda, s3ProjectionPublication !== undefined);
|
|
943
957
|
|
|
944
958
|
if (tenancyMode === "shared") {
|
|
@@ -13,6 +13,12 @@ export function AutomationPanel({ isDemo }: { isDemo: boolean }) {
|
|
|
13
13
|
const [result, setResult] = useState<AutomationResult | null>(null);
|
|
14
14
|
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
15
15
|
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
// A line on Today opens the runs of one automation: `?automation=<id>`.
|
|
18
|
+
const requested = new URLSearchParams(window.location.search).get("automation");
|
|
19
|
+
if (requested) setSelectedId(requested);
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
16
22
|
useEffect(() => {
|
|
17
23
|
if (isDemo) {
|
|
18
24
|
setResult(FIXTURE_AUTOMATION_OVERVIEW);
|
|
@@ -38,6 +38,7 @@ function RunLine({ run, demo }: { run: AutomationRun; demo: boolean }) {
|
|
|
38
38
|
<li data-automation-run={run.runId ?? run.sourceId ?? "unlinked"} data-run-status={run.status ?? "unknown"}>
|
|
39
39
|
<strong>{formatUtc(run.startedAt)}</strong>
|
|
40
40
|
<span><span aria-hidden="true">{statusMark(run.status)} </span>Status: {statusText(run.status)} · {durationText(run.durationSeconds)}</span>
|
|
41
|
+
<span data-automation-run-outcome={run.outcome ?? undefined}>Outcome: {run.outcomeShown}</span>
|
|
41
42
|
<span>{whoText(run)}</span>
|
|
42
43
|
{run.reason ? <span data-automation-run-reason>Reason: {run.reason}</span> : null}
|
|
43
44
|
{run.error ? <span data-automation-run-error>Error: {run.error}</span> : null}
|
|
@@ -63,6 +64,7 @@ function OutsideRunLine({ run, demo }: { run: AutomationOutsideRun; demo: boolea
|
|
|
63
64
|
<li data-automation-outside-run={run.runId ?? "unlinked"} data-run-status={run.status ?? "unknown"}>
|
|
64
65
|
<strong>{formatUtc(run.startedAt)}</strong>
|
|
65
66
|
<span><span aria-hidden="true">{statusMark(run.status)} </span>Status: {statusText(run.status)} · {durationText(run.durationSeconds)}</span>
|
|
67
|
+
<span data-automation-run-outcome={run.outcome ?? undefined}>Outcome: {run.outcomeShown}</span>
|
|
66
68
|
<span>Started by: {run.requestedBy ?? "unknown"}</span>
|
|
67
69
|
{run.error ? <span data-automation-run-error>Error: {run.error}</span> : null}
|
|
68
70
|
<span>{run.runId ? <>Run {run.runId} (<Link href={proceduresHref(demo)}>Procedures</Link>)</> : "No run id"}</span>
|
|
@@ -80,10 +82,10 @@ function Detail({ record, demo, onRunNow }: { record: AutomationRecord; demo: bo
|
|
|
80
82
|
<article className="news-desk-doctrine-card" data-automation-detail={record.id}>
|
|
81
83
|
<div className="news-desk-doctrine-card__header"><div><h3>{record.title}</h3><span>{record.description ?? record.id}</span></div></div>
|
|
82
84
|
<dl className="news-desk-monitoring__usage">
|
|
83
|
-
<div><dt>Trigger</dt><dd>{triggerText(record.trigger)}{record.supported ? "" : ` (${record.supportNote ?? "not yet supported"})`}</dd></div>
|
|
85
|
+
<div><dt>Trigger</dt><dd>{triggerText(record.trigger, record.schedule)}{record.supported ? "" : ` (${record.supportNote ?? "not yet supported"})`}</dd></div>
|
|
84
86
|
<div><dt>Procedure</dt><dd>{record.procedureKey}</dd></div>
|
|
85
87
|
<div><dt>Input</dt><dd>{Object.keys(record.inputTemplate).length ? Object.entries(record.inputTemplate).map(([name, template]) => `${name} = ${template}`).join("; ") : "none"}</dd></div>
|
|
86
|
-
<div><dt>Enabled</dt><dd>{enabledText(record)} ({
|
|
88
|
+
<div><dt>Enabled</dt><dd>{enabledText(record)} ({record.enabledNote})</dd></div>
|
|
87
89
|
<div><dt>Limits</dt><dd>timeout {record.limits.timeoutSeconds ?? "?"} s, {atATimeText(record.limits)}{record.limits.budgetUsdPerRun !== undefined ? `, about $${record.limits.budgetUsdPerRun} per run, advisory` : ""} ({record.limitsNote})</dd></div>
|
|
88
90
|
<div><dt>Router</dt><dd data-automation-link={record.link?.state ?? "unchecked"}>{linkText(record.link)}</dd></div>
|
|
89
91
|
</dl>
|
|
@@ -122,10 +124,10 @@ function ListItem({ record, selected, onSelect }: { record: AutomationRecord; se
|
|
|
122
124
|
<li data-automation={record.id}>
|
|
123
125
|
<div>
|
|
124
126
|
<strong>{record.title}</strong>
|
|
125
|
-
<span>{triggerText(record.trigger)}{record.supported ? "" : ` (${record.supportNote ?? "not yet supported"})`}</span>
|
|
127
|
+
<span>{triggerText(record.trigger, record.schedule)}{record.supported ? "" : ` (${record.supportNote ?? "not yet supported"})`}</span>
|
|
126
128
|
</div>
|
|
127
129
|
<span>Procedure: {record.procedureKey}</span>
|
|
128
|
-
<span>{enabledText(record)} ({
|
|
130
|
+
<span>{enabledText(record)} ({record.enabledNote})</span>
|
|
129
131
|
<span data-automation-last-run>
|
|
130
132
|
Last run: <span aria-hidden="true">{statusMark(last?.status)} </span>{statusText(last?.status)}{last ? `, ${formatUtc(last.startedAt)}` : ""}
|
|
131
133
|
</span>
|
|
@@ -21,6 +21,7 @@ import type { ReferenceRejectionReasonCode } from "../lib/reference-policy";
|
|
|
21
21
|
import { referencePreviewsByLineage, type ReferencePreview } from "../lib/reference-preview";
|
|
22
22
|
import type { NotificationFixture } from "./notification-center";
|
|
23
23
|
import { NotificationCenter } from "./notification-center";
|
|
24
|
+
import { TodayPanel } from "./today-panel";
|
|
24
25
|
import type { CorrectCaptureAction } from "./reference-capture-client";
|
|
25
26
|
import type { ReviewChoice } from "./reference-review-card";
|
|
26
27
|
|
|
@@ -104,6 +105,7 @@ export function NewsroomOpsOverview({
|
|
|
104
105
|
|
|
105
106
|
const below = (
|
|
106
107
|
<div className="space-y-12 pt-6" data-newsroom-overview-below {...FEED_SURFACE_PROPS}>
|
|
108
|
+
<TodayPanel isDemo={demo} />
|
|
107
109
|
{attentionAssignments.length ? (
|
|
108
110
|
<section aria-label="Open assignments" className="space-y-3">
|
|
109
111
|
<h2 className="text-sm font-medium text-muted-foreground">Open assignments</h2>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { FIXTURE_TODAY } from "../lib/today-fixture";
|
|
5
|
+
import { REFRESH_MILLISECONDS, type TodayResult } from "../lib/today-overview";
|
|
6
|
+
import { TodayView } from "./today-view";
|
|
7
|
+
|
|
8
|
+
/** Today on the newsroom home. It reads when it opens, when the tab comes back into focus, and every five minutes. No subscription. */
|
|
9
|
+
export function TodayPanel({ isDemo }: { isDemo: boolean }) {
|
|
10
|
+
const [result, setResult] = useState<TodayResult | null>(null);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isDemo) {
|
|
14
|
+
setResult(FIXTURE_TODAY);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let live = true;
|
|
18
|
+
const refresh = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const { loadTodayOverview } = await import("../lib/today-client");
|
|
21
|
+
const next = await loadTodayOverview();
|
|
22
|
+
if (live) setResult(next);
|
|
23
|
+
} catch {
|
|
24
|
+
if (live) setResult((current) => current ?? { state: "unavailable" }); // a failed refresh keeps what is shown
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const onVisible = () => {
|
|
28
|
+
if (document.visibilityState === "visible") void refresh();
|
|
29
|
+
};
|
|
30
|
+
void refresh();
|
|
31
|
+
const timer = window.setInterval(() => void refresh(), REFRESH_MILLISECONDS);
|
|
32
|
+
window.addEventListener("focus", onVisible);
|
|
33
|
+
document.addEventListener("visibilitychange", onVisible);
|
|
34
|
+
return () => {
|
|
35
|
+
live = false;
|
|
36
|
+
window.clearInterval(timer);
|
|
37
|
+
window.removeEventListener("focus", onVisible);
|
|
38
|
+
document.removeEventListener("visibilitychange", onVisible);
|
|
39
|
+
};
|
|
40
|
+
}, [isDemo]);
|
|
41
|
+
|
|
42
|
+
return <TodayView demo={isDemo} result={result} />;
|
|
43
|
+
}
|