@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.
Files changed (57) hide show
  1. package/amplify/agents/admin-policy-grant.feature +20 -0
  2. package/amplify/agents/admin-policy-grant.js +31 -0
  3. package/amplify/agents/admin-policy-grant.ts +35 -0
  4. package/amplify/agents/pieces.js +11 -0
  5. package/amplify/agents/pieces.ts +13 -0
  6. package/amplify/agents/schedule-group.js +75 -0
  7. package/amplify/agents/schedule-group.ts +82 -0
  8. package/amplify/agents/stack.js +27 -0
  9. package/amplify/agents/stack.ts +53 -0
  10. package/amplify/agents/wake-queue.js +121 -0
  11. package/amplify/agents/wake-queue.ts +138 -0
  12. package/amplify/data/resource.js +25 -0
  13. package/amplify/data/resource.ts +25 -0
  14. package/amplify/data/schema.js +27 -1
  15. package/amplify/data/schema.ts +27 -1
  16. package/amplify/functions/announcements/schema.js +86 -0
  17. package/amplify/functions/announcements/schema.ts +86 -0
  18. package/amplify/functions/assignment-action/handler.ts +4 -0
  19. package/amplify/functions/automation-view/schema.js +8 -1
  20. package/amplify/functions/automation-view/schema.ts +8 -1
  21. package/amplify/functions/automation-view/wire.js +7 -11
  22. package/amplify/functions/automation-view/wire.ts +7 -14
  23. package/amplify/functions/localization-dispatch/handler.py +4 -3
  24. package/amplify/functions/localization-dispatch/wire.js +6 -5
  25. package/amplify/functions/localization-dispatch/wire.ts +6 -5
  26. package/amplify/functions/model-attachment-upload/handler.ts +4 -0
  27. package/amplify/functions/model-attachment-upload/rules.js +2 -0
  28. package/amplify/functions/model-attachment-upload/rules.ts +2 -0
  29. package/amplify/functions/procedure-action/handler.ts +44 -27
  30. package/amplify/functions/procedure-action/wake-key.js +48 -0
  31. package/amplify/functions/procedure-action/wake-key.ts +49 -0
  32. package/amplify/site-backend.js +12 -2
  33. package/amplify/site-backend.ts +16 -2
  34. package/components/automation-panel.tsx +6 -0
  35. package/components/automation-view.tsx +6 -4
  36. package/components/newsroom-ops-overview.tsx +2 -0
  37. package/components/today-panel.tsx +43 -0
  38. package/components/today-view.tsx +171 -0
  39. package/infra/agent-sync.test.js +34 -0
  40. package/infra/agent-sync.test.ts +35 -0
  41. package/infra/build-specs.js +21 -0
  42. package/infra/build-specs.ts +25 -0
  43. package/infra/ci-gate.test.js +1 -1
  44. package/infra/ci-gate.test.ts +1 -1
  45. package/infra/procedure-sync.test.js +48 -0
  46. package/infra/procedure-sync.test.ts +50 -0
  47. package/lib/automation-fixture.ts +14 -9
  48. package/lib/automation-overview.ts +18 -5
  49. package/lib/guidelines/writing-guidelines-admin.ts +1 -1
  50. package/lib/images/operations.generated.ts +72 -42
  51. package/lib/tenant-keys.js +1 -0
  52. package/lib/tenant-keys.ts +1 -0
  53. package/lib/today-client.ts +34 -0
  54. package/lib/today-fixture.ts +52 -0
  55. package/lib/today-overview.ts +111 -0
  56. package/package.json +6 -1
  57. package/routes.manifest.json +1 -1
@@ -1241,6 +1241,7 @@ const schema = a.schema({
1241
1241
  procedureId: a.id(),
1242
1242
  procedureKey: a.string(),
1243
1243
  procedureVersionId: a.id(),
1244
+ wakeKey: a.string(),
1244
1245
  title: a.string(),
1245
1246
  summary: a.string(),
1246
1247
  input: a.json(),
@@ -1402,6 +1403,21 @@ const schema = a.schema({
1402
1403
  procedureVersionNumber: a.integer(),
1403
1404
  assignmentId: a.id(),
1404
1405
  runStatus: a.string().required(),
1406
+ /** What came of a finished run: acted, nothing, asked, failed or unknown. Set only when the run finishes or is settled; a run recorded before outcomes has none. */
1407
+ outcome: a.string(),
1408
+ /** A short lower-case code for why: required for `nothing` and `asked`, such as no_new_filing. */
1409
+ outcomeReason: a.string(),
1410
+ automationId: a.string(),
1411
+ responsibility: a.string(),
1412
+ subjectKind: a.string(),
1413
+ subjectId: a.string(),
1414
+ subjectVersion: a.string(),
1415
+ /** The wake that started the run (docs/design/always-on-agents-architecture.md A2). The run's id is derived from it, so one wake is one run. Runs recorded before wake keys have none. */
1416
+ wakeKey: a.string(),
1417
+ /** The rung the run was decided under (off, observe, propose, draft, prepare, publish_soft, publish_auto). Written by the runner from the site's agent policy; a person's own run has none. */
1418
+ rung: a.string(),
1419
+ /** The version of the site's agent policy document the run was decided under (PPY-c8175e). */
1420
+ policyVersion: a.integer(),
1405
1421
  requestedBy: a.string(),
1406
1422
  requestedAt: a.datetime().required(),
1407
1423
  startedAt: a.datetime(),
@@ -1436,6 +1452,15 @@ const schema = a.schema({
1436
1452
  enabled: a.boolean().required(),
1437
1453
  trigger: a.json().required(),
1438
1454
  procedureKey: a.string().required(),
1455
+ /** The standing responsibility this automation fills (a key of the agent catalog). Set by `papyrus automations adopt`, never inferred. An automation with none starts no run (PPY-c8175e). */
1456
+ responsibility: a.string(),
1457
+ /** The registered copy of the agent definition this automation runs (PPY-fba046): its id, the registered version (1, then one higher for each changed digest), the digest of the effective definition and the definition as registered. The runner and Today read this, not Git. Set only by registering a definition. */
1458
+ definitionId: a.string(),
1459
+ definitionVersion: a.integer(),
1460
+ definitionDigest: a.string(),
1461
+ definition: a.json(),
1462
+ /** When the release found this agent's definition gone from Git and retired it (PPY-df3e74); empty while the definition is in Git. A retired agent is disabled and names no schedule; its registered copy stays as history. */
1463
+ definitionRetiredAt: a.datetime(),
1439
1464
  inputTemplate: a.json(),
1440
1465
  limits: a.json(),
1441
1466
  createdBy: a.string(),
@@ -1359,6 +1359,7 @@ const schema = a.schema({
1359
1359
  procedureId: a.id(),
1360
1360
  procedureKey: a.string(),
1361
1361
  procedureVersionId: a.id(),
1362
+ wakeKey: a.string(),
1362
1363
  title: a.string(),
1363
1364
  summary: a.string(),
1364
1365
  input: a.json(),
@@ -1527,6 +1528,21 @@ const schema = a.schema({
1527
1528
  procedureVersionNumber: a.integer(),
1528
1529
  assignmentId: a.id(),
1529
1530
  runStatus: a.string().required(),
1531
+ /** What came of a finished run: acted, nothing, asked, failed or unknown. Set only when the run finishes or is settled; a run recorded before outcomes has none. */
1532
+ outcome: a.string(),
1533
+ /** A short lower-case code for why: required for `nothing` and `asked`, such as no_new_filing. */
1534
+ outcomeReason: a.string(),
1535
+ automationId: a.string(),
1536
+ responsibility: a.string(),
1537
+ subjectKind: a.string(),
1538
+ subjectId: a.string(),
1539
+ subjectVersion: a.string(),
1540
+ /** The wake that started the run (docs/design/always-on-agents-architecture.md A2). The run's id is derived from it, so one wake is one run. Runs recorded before wake keys have none. */
1541
+ wakeKey: a.string(),
1542
+ /** The rung the run was decided under (off, observe, propose, draft, prepare, publish_soft, publish_auto). Written by the runner from the site's agent policy; a person's own run has none. */
1543
+ rung: a.string(),
1544
+ /** The version of the site's agent policy document the run was decided under (PPY-c8175e). */
1545
+ policyVersion: a.integer(),
1530
1546
  requestedBy: a.string(),
1531
1547
  requestedAt: a.datetime().required(),
1532
1548
  startedAt: a.datetime(),
@@ -1562,6 +1578,15 @@ const schema = a.schema({
1562
1578
  enabled: a.boolean().required(),
1563
1579
  trigger: a.json().required(),
1564
1580
  procedureKey: a.string().required(),
1581
+ /** The standing responsibility this automation fills (a key of the agent catalog). Set by `papyrus automations adopt`, never inferred. An automation with none starts no run (PPY-c8175e). */
1582
+ responsibility: a.string(),
1583
+ /** The registered copy of the agent definition this automation runs (PPY-fba046): its id, the registered version (1, then one higher for each changed digest), the digest of the effective definition and the definition as registered. The runner and Today read this, not Git. Set only by registering a definition. */
1584
+ definitionId: a.string(),
1585
+ definitionVersion: a.integer(),
1586
+ definitionDigest: a.string(),
1587
+ definition: a.json(),
1588
+ /** When the release found this agent's definition gone from Git and retired it (PPY-df3e74); empty while the definition is in Git. A retired agent is disabled and names no schedule; its registered copy stays as history. */
1589
+ definitionRetiredAt: a.datetime(),
1565
1590
  inputTemplate: a.json(),
1566
1591
  limits: a.json(),
1567
1592
  createdBy: a.string(),
@@ -52,6 +52,7 @@ export const OPTIONAL_MODEL_GROUPS = {
52
52
  variations: ["StoryVariation"],
53
53
  tenancy: ["Tenant", "TenantMembership", "TenantSelection", "TenantDomain", "SiteDocument", "SiteDocumentVersion"],
54
54
  localization: ["LocalizationRequest"],
55
+ announcements: ["AnnouncementDecision", "Delivery"],
55
56
  };
56
57
  /**
57
58
  * The groups a bootstrap deploy leaves out (`PAPYRUS_BOOTSTRAP_STAGE=1`, docs/site-hosting.md). Every group is deferred,
@@ -1219,6 +1220,7 @@ function buildBaseDefinitions(excludedGroups = []) {
1219
1220
  procedureId: a.id(),
1220
1221
  procedureKey: a.string(),
1221
1222
  procedureVersionId: a.id(),
1223
+ wakeKey: a.string(),
1222
1224
  title: a.string(),
1223
1225
  summary: a.string(),
1224
1226
  input: a.json(),
@@ -1374,6 +1376,21 @@ function buildBaseDefinitions(excludedGroups = []) {
1374
1376
  procedureVersionNumber: a.integer(),
1375
1377
  assignmentId: a.id(),
1376
1378
  runStatus: a.string().required(),
1379
+ /** What came of a finished run: acted, nothing, asked, failed or unknown. Set only when the run finishes or is settled; a run recorded before outcomes has none. */
1380
+ outcome: a.string(),
1381
+ /** A short lower-case code for why: required for `nothing` and `asked`, such as no_new_filing. */
1382
+ outcomeReason: a.string(),
1383
+ automationId: a.string(),
1384
+ responsibility: a.string(),
1385
+ subjectKind: a.string(),
1386
+ subjectId: a.string(),
1387
+ subjectVersion: a.string(),
1388
+ /** The wake that started the run (docs/design/always-on-agents-architecture.md A2). The run's id is derived from it, so one wake is one run. Runs recorded before wake keys have none. */
1389
+ wakeKey: a.string(),
1390
+ /** The rung the run was decided under (off, observe, propose, draft, prepare, publish_soft, publish_auto). Written by the runner from the site's agent policy; a person's own run has none. */
1391
+ rung: a.string(),
1392
+ /** The version of the site's agent policy document the run was decided under (PPY-c8175e). */
1393
+ policyVersion: a.integer(),
1377
1394
  requestedBy: a.string(),
1378
1395
  requestedAt: a.datetime().required(),
1379
1396
  startedAt: a.datetime(),
@@ -1408,6 +1425,15 @@ function buildBaseDefinitions(excludedGroups = []) {
1408
1425
  enabled: a.boolean().required(),
1409
1426
  trigger: a.json().required(),
1410
1427
  procedureKey: a.string().required(),
1428
+ /** The standing responsibility this automation fills (a key of the agent catalog). Set by `papyrus automations adopt`, never inferred. An automation with none starts no run (PPY-c8175e). */
1429
+ responsibility: a.string(),
1430
+ /** The registered copy of the agent definition this automation runs (PPY-fba046): its id, the registered version (1, then one higher for each changed digest), the digest of the effective definition and the definition as registered. The runner and Today read this, not Git. Set only by registering a definition. */
1431
+ definitionId: a.string(),
1432
+ definitionVersion: a.integer(),
1433
+ definitionDigest: a.string(),
1434
+ definition: a.json(),
1435
+ /** When the release found this agent's definition gone from Git and retired it (PPY-df3e74); empty while the definition is in Git. A retired agent is disabled and names no schedule; its registered copy stays as history. */
1436
+ definitionRetiredAt: a.datetime(),
1411
1437
  inputTemplate: a.json(),
1412
1438
  limits: a.json(),
1413
1439
  createdBy: a.string(),
@@ -2772,7 +2798,7 @@ function buildBaseDefinitions(excludedGroups = []) {
2772
2798
  allow.group(adminGroup),
2773
2799
  allow.ownerDefinedIn("tenantId").identityClaim("papyrus_tenant_admin").to(["read"]),
2774
2800
  ]),
2775
- /** The catalogue row of one site document (kind: site | brand | nav); id = "<tenant>#<kind>". The body lives in S3 (PPY-c020ce). Group "tenancy". */
2801
+ /** The catalogue row of one site document (kind: site | brand | nav | agents); id = "<tenant>#<kind>". The body lives in S3 (PPY-c020ce). Group "tenancy". */
2776
2802
  SiteDocument: modelWithoutSubscriptions({
2777
2803
  id: a.id().required(),
2778
2804
  tenantId: a.string().required(),
@@ -55,6 +55,7 @@ export const OPTIONAL_MODEL_GROUPS = {
55
55
  variations: ["StoryVariation"],
56
56
  tenancy: ["Tenant", "TenantMembership", "TenantSelection", "TenantDomain", "SiteDocument", "SiteDocumentVersion"],
57
57
  localization: ["LocalizationRequest"],
58
+ announcements: ["AnnouncementDecision", "Delivery"],
58
59
  } as const;
59
60
 
60
61
  /**
@@ -1340,6 +1341,7 @@ const definitions = {
1340
1341
  procedureId: a.id(),
1341
1342
  procedureKey: a.string(),
1342
1343
  procedureVersionId: a.id(),
1344
+ wakeKey: a.string(),
1343
1345
  title: a.string(),
1344
1346
  summary: a.string(),
1345
1347
  input: a.json(),
@@ -1502,6 +1504,21 @@ const definitions = {
1502
1504
  procedureVersionNumber: a.integer(),
1503
1505
  assignmentId: a.id(),
1504
1506
  runStatus: a.string().required(),
1507
+ /** What came of a finished run: acted, nothing, asked, failed or unknown. Set only when the run finishes or is settled; a run recorded before outcomes has none. */
1508
+ outcome: a.string(),
1509
+ /** A short lower-case code for why: required for `nothing` and `asked`, such as no_new_filing. */
1510
+ outcomeReason: a.string(),
1511
+ automationId: a.string(),
1512
+ responsibility: a.string(),
1513
+ subjectKind: a.string(),
1514
+ subjectId: a.string(),
1515
+ subjectVersion: a.string(),
1516
+ /** The wake that started the run (docs/design/always-on-agents-architecture.md A2). The run's id is derived from it, so one wake is one run. Runs recorded before wake keys have none. */
1517
+ wakeKey: a.string(),
1518
+ /** The rung the run was decided under (off, observe, propose, draft, prepare, publish_soft, publish_auto). Written by the runner from the site's agent policy; a person's own run has none. */
1519
+ rung: a.string(),
1520
+ /** The version of the site's agent policy document the run was decided under (PPY-c8175e). */
1521
+ policyVersion: a.integer(),
1505
1522
  requestedBy: a.string(),
1506
1523
  requestedAt: a.datetime().required(),
1507
1524
  startedAt: a.datetime(),
@@ -1537,6 +1554,15 @@ const definitions = {
1537
1554
  enabled: a.boolean().required(),
1538
1555
  trigger: a.json().required(),
1539
1556
  procedureKey: a.string().required(),
1557
+ /** The standing responsibility this automation fills (a key of the agent catalog). Set by `papyrus automations adopt`, never inferred. An automation with none starts no run (PPY-c8175e). */
1558
+ responsibility: a.string(),
1559
+ /** The registered copy of the agent definition this automation runs (PPY-fba046): its id, the registered version (1, then one higher for each changed digest), the digest of the effective definition and the definition as registered. The runner and Today read this, not Git. Set only by registering a definition. */
1560
+ definitionId: a.string(),
1561
+ definitionVersion: a.integer(),
1562
+ definitionDigest: a.string(),
1563
+ definition: a.json(),
1564
+ /** When the release found this agent's definition gone from Git and retired it (PPY-df3e74); empty while the definition is in Git. A retired agent is disabled and names no schedule; its registered copy stays as history. */
1565
+ definitionRetiredAt: a.datetime(),
1540
1566
  inputTemplate: a.json(),
1541
1567
  limits: a.json(),
1542
1568
  createdBy: a.string(),
@@ -2943,7 +2969,7 @@ const definitions = {
2943
2969
  allow.ownerDefinedIn("tenantId").identityClaim("papyrus_tenant_admin").to(["read"]),
2944
2970
  ]),
2945
2971
 
2946
- /** The catalogue row of one site document (kind: site | brand | nav); id = "<tenant>#<kind>". The body lives in S3 (PPY-c020ce). Group "tenancy". */
2972
+ /** The catalogue row of one site document (kind: site | brand | nav | agents); id = "<tenant>#<kind>". The body lives in S3 (PPY-c020ce). Group "tenancy". */
2947
2973
  SiteDocument: modelWithoutSubscriptions({
2948
2974
  id: a.id().required(),
2949
2975
  tenantId: a.string().required(),
@@ -59,6 +59,92 @@ export const announcementsSchemaDefinitions = {
59
59
  ])
60
60
  .disableOperations(["subscriptions"])
61
61
  .authorization((allow) => [allow.groups(editors).to(["read"])]),
62
+ /**
63
+ * An Announcement: the decision to say something about one or more Stories (docs/announcement-records.md). It knows nothing about channels and holds no approval;
64
+ * a Delivery holds both. id is made from the once-only key (dedupeKey), and created with a condition, so a decision is made once. The Stories it is about are
65
+ * `announces` relations, with the version looked at. Short fields only: no text. Named for what it is because the model `Announcement` is the X row shape that
66
+ * PPY-efd06c deletes. Editors and admins read; the announcement pipeline writes.
67
+ */
68
+ AnnouncementDecision: a
69
+ .model({
70
+ id: a.id().required(),
71
+ tenantId: a.string(),
72
+ dedupeKey: a.string().required(),
73
+ kind: a.string().required(),
74
+ state: a.string().required(),
75
+ releaseAt: a.datetime().required(),
76
+ createdBy: a.string().required(),
77
+ trigger: a.string(),
78
+ history: a.json(),
79
+ revision: a.integer().required(),
80
+ createdAt: a.datetime().required(),
81
+ updatedAt: a.datetime().required(),
82
+ })
83
+ .secondaryIndexes((index) => [
84
+ index("tenantId").sortKeys(["id"]).queryField("listAnnouncementDecisionsByTenant"),
85
+ index("dedupeKey").sortKeys(["createdAt"]).queryField("listAnnouncementDecisionsByDedupeKeyAndCreatedAt"),
86
+ index("state").sortKeys(["releaseAt"]).queryField("listAnnouncementDecisionsByStateAndReleaseAt"),
87
+ ])
88
+ .disableOperations(["subscriptions"])
89
+ .authorization((allow) => [allow.groups(editors).to(["read"])]),
90
+ /**
91
+ * A Delivery: one channel's version of an Announcement (docs/announcement-records.md). The words and any picture are files in S3 (textKey, imageKey, contentHash);
92
+ * the row never holds text. id is `<announcement>#<channel>#<account>#g<generation>`, created with a condition: one live Delivery for each Announcement, channel and
93
+ * account, and a correction is the next generation, written with `supersedes`. Approval lives here, per Delivery. Every wait is a named time (releaseAt, lockAt,
94
+ * nextAttemptAt with waitingFor); dueAt is the earliest of them and, with dueKey, is present only while one is pending, so the due index is sparse.
95
+ */
96
+ Delivery: a
97
+ .model({
98
+ id: a.id().required(),
99
+ tenantId: a.string(),
100
+ announcementId: a.string().required(),
101
+ channel: a.string().required(),
102
+ accountId: a.string().required(),
103
+ accountKey: a.string().required(),
104
+ audience: a.string().array(),
105
+ mode: a.string().required(),
106
+ state: a.string().required(),
107
+ blockedReason: a.string(),
108
+ generation: a.integer().required(),
109
+ version: a.integer().required(),
110
+ textKey: a.string(),
111
+ imageKey: a.string(),
112
+ contentHash: a.string(),
113
+ draftedBy: a.string(),
114
+ checks: a.json(),
115
+ approval: a.string().required(),
116
+ approvalPolicy: a.string().required(),
117
+ approvedVersion: a.integer(),
118
+ approvedBy: a.string(),
119
+ approvedAt: a.datetime(),
120
+ releaseAt: a.datetime().required(),
121
+ lockAt: a.datetime().required(),
122
+ lockedAt: a.datetime(),
123
+ lockedVersion: a.integer(),
124
+ nextAttemptAt: a.datetime(),
125
+ waitingFor: a.string(),
126
+ dueAt: a.datetime(),
127
+ dueKey: a.string(),
128
+ resultUrl: a.string(),
129
+ providerId: a.string(),
130
+ cost: a.string(),
131
+ counts: a.json(),
132
+ attempts: a.json(),
133
+ supersedes: a.string(),
134
+ supersededBy: a.string(),
135
+ history: a.json(),
136
+ revision: a.integer().required(),
137
+ createdAt: a.datetime().required(),
138
+ updatedAt: a.datetime().required(),
139
+ })
140
+ .secondaryIndexes((index) => [
141
+ index("tenantId").sortKeys(["id"]).queryField("listDeliveriesByTenant"),
142
+ index("announcementId").sortKeys(["createdAt"]).queryField("listDeliveriesByAnnouncementAndCreatedAt"),
143
+ index("accountKey").sortKeys(["createdAt"]).queryField("listDeliveriesByAccountKeyAndCreatedAt"),
144
+ index("dueKey").sortKeys(["dueAt"]).queryField("listDeliveriesByDueKeyAndDueAt"),
145
+ ])
146
+ .disableOperations(["subscriptions"])
147
+ .authorization((allow) => [allow.groups(editors).to(["read"])]),
62
148
  /** What an account spent on X in one billing cycle: id = "<accountId>#<cycle start date>", raised once for every charge Caducus records. */
63
149
  AnnouncementSpend: a
64
150
  .model({
@@ -62,6 +62,92 @@ export const announcementsSchemaDefinitions = {
62
62
  ])
63
63
  .disableOperations(["subscriptions"])
64
64
  .authorization((allow) => [allow.groups(editors).to(["read"])]),
65
+ /**
66
+ * An Announcement: the decision to say something about one or more Stories (docs/announcement-records.md). It knows nothing about channels and holds no approval;
67
+ * a Delivery holds both. id is made from the once-only key (dedupeKey), and created with a condition, so a decision is made once. The Stories it is about are
68
+ * `announces` relations, with the version looked at. Short fields only: no text. Named for what it is because the model `Announcement` is the X row shape that
69
+ * PPY-efd06c deletes. Editors and admins read; the announcement pipeline writes.
70
+ */
71
+ AnnouncementDecision: a
72
+ .model({
73
+ id: a.id().required(),
74
+ tenantId: a.string(),
75
+ dedupeKey: a.string().required(),
76
+ kind: a.string().required(),
77
+ state: a.string().required(),
78
+ releaseAt: a.datetime().required(),
79
+ createdBy: a.string().required(),
80
+ trigger: a.string(),
81
+ history: a.json(),
82
+ revision: a.integer().required(),
83
+ createdAt: a.datetime().required(),
84
+ updatedAt: a.datetime().required(),
85
+ })
86
+ .secondaryIndexes((index) => [
87
+ index("tenantId").sortKeys(["id"]).queryField("listAnnouncementDecisionsByTenant"),
88
+ index("dedupeKey").sortKeys(["createdAt"]).queryField("listAnnouncementDecisionsByDedupeKeyAndCreatedAt"),
89
+ index("state").sortKeys(["releaseAt"]).queryField("listAnnouncementDecisionsByStateAndReleaseAt"),
90
+ ])
91
+ .disableOperations(["subscriptions"])
92
+ .authorization((allow) => [allow.groups(editors).to(["read"])]),
93
+ /**
94
+ * A Delivery: one channel's version of an Announcement (docs/announcement-records.md). The words and any picture are files in S3 (textKey, imageKey, contentHash);
95
+ * the row never holds text. id is `<announcement>#<channel>#<account>#g<generation>`, created with a condition: one live Delivery for each Announcement, channel and
96
+ * account, and a correction is the next generation, written with `supersedes`. Approval lives here, per Delivery. Every wait is a named time (releaseAt, lockAt,
97
+ * nextAttemptAt with waitingFor); dueAt is the earliest of them and, with dueKey, is present only while one is pending, so the due index is sparse.
98
+ */
99
+ Delivery: a
100
+ .model({
101
+ id: a.id().required(),
102
+ tenantId: a.string(),
103
+ announcementId: a.string().required(),
104
+ channel: a.string().required(),
105
+ accountId: a.string().required(),
106
+ accountKey: a.string().required(),
107
+ audience: a.string().array(),
108
+ mode: a.string().required(),
109
+ state: a.string().required(),
110
+ blockedReason: a.string(),
111
+ generation: a.integer().required(),
112
+ version: a.integer().required(),
113
+ textKey: a.string(),
114
+ imageKey: a.string(),
115
+ contentHash: a.string(),
116
+ draftedBy: a.string(),
117
+ checks: a.json(),
118
+ approval: a.string().required(),
119
+ approvalPolicy: a.string().required(),
120
+ approvedVersion: a.integer(),
121
+ approvedBy: a.string(),
122
+ approvedAt: a.datetime(),
123
+ releaseAt: a.datetime().required(),
124
+ lockAt: a.datetime().required(),
125
+ lockedAt: a.datetime(),
126
+ lockedVersion: a.integer(),
127
+ nextAttemptAt: a.datetime(),
128
+ waitingFor: a.string(),
129
+ dueAt: a.datetime(),
130
+ dueKey: a.string(),
131
+ resultUrl: a.string(),
132
+ providerId: a.string(),
133
+ cost: a.string(),
134
+ counts: a.json(),
135
+ attempts: a.json(),
136
+ supersedes: a.string(),
137
+ supersededBy: a.string(),
138
+ history: a.json(),
139
+ revision: a.integer().required(),
140
+ createdAt: a.datetime().required(),
141
+ updatedAt: a.datetime().required(),
142
+ })
143
+ .secondaryIndexes((index) => [
144
+ index("tenantId").sortKeys(["id"]).queryField("listDeliveriesByTenant"),
145
+ index("announcementId").sortKeys(["createdAt"]).queryField("listDeliveriesByAnnouncementAndCreatedAt"),
146
+ index("accountKey").sortKeys(["createdAt"]).queryField("listDeliveriesByAccountKeyAndCreatedAt"),
147
+ index("dueKey").sortKeys(["dueAt"]).queryField("listDeliveriesByDueKeyAndDueAt"),
148
+ ])
149
+ .disableOperations(["subscriptions"])
150
+ .authorization((allow) => [allow.groups(editors).to(["read"])]),
65
151
  /** What an account spent on X in one billing cycle: id = "<accountId>#<cycle start date>", raised once for every charge Caducus records. */
66
152
  AnnouncementSpend: a
67
153
  .model({
@@ -656,6 +656,8 @@ async function executeImmediateProcedureRun(client: DataClient, assignment: any,
656
656
  await requireDataResult((client.models as any).ProcedureRun.update({
657
657
  id: run.id,
658
658
  runStatus: "completed",
659
+ outcome: "acted",
660
+ outcomeReason: null,
659
661
  startedAt,
660
662
  finishedAt,
661
663
  resultSummary: `Completed immediate run for ${definition.procedureKey} v${version.versionNumber}.`,
@@ -675,6 +677,8 @@ async function executeImmediateProcedureRun(client: DataClient, assignment: any,
675
677
  await requireDataResult((client.models as any).ProcedureRun.update({
676
678
  id: run.id,
677
679
  runStatus: "failed",
680
+ outcome: "failed",
681
+ outcomeReason: "procedure_error",
678
682
  startedAt,
679
683
  finishedAt,
680
684
  resultSummary: null,
@@ -5,7 +5,7 @@ const editors = ["editor", "admin"];
5
5
  /**
6
6
  * Core to every site's data API. The Automation page reads the automation records, the monitoring
7
7
  * trigger rows they link to, and the procedure runs through `automationOverview`, and starts a run
8
- * through `runAutomation`. Both admit editors and admins. AppSync also lets an IAM principal call the
8
+ * through `runAutomation`. Today reads the day's runs through `todayOverview`. Both admit editors and admins. AppSync also lets an IAM principal call the
9
9
  * query when its own policy allows the field (every operation in this schema accepts IAM callers for
10
10
  * the functions that call it); the function reads only for an IAM principal of its own account and refuses
11
11
  * every IAM caller on `runAutomation`.
@@ -17,6 +17,13 @@ export const automationViewSchemaDefinitions = {
17
17
  .returns(a.json())
18
18
  .authorization((allow) => [allow.groups(editors)])
19
19
  .handler(functionHandler("automationView", automationView)),
20
+ /** Today (PPY-5bcf42): what ran in one day, what it decided to do nothing about, what it cost. Shares the function above; reads by index. */
21
+ todayOverview: a
22
+ .query()
23
+ .arguments({ day: a.string(), timeZone: a.string() })
24
+ .returns(a.json())
25
+ .authorization((allow) => [allow.groups(editors)])
26
+ .handler(functionHandler("automationView", automationView)),
20
27
  runAutomation: a
21
28
  .mutation()
22
29
  .arguments({ automationId: a.string().required(), input: a.json() })
@@ -7,7 +7,7 @@ const editors = ["editor", "admin"];
7
7
  /**
8
8
  * Core to every site's data API. The Automation page reads the automation records, the monitoring
9
9
  * trigger rows they link to, and the procedure runs through `automationOverview`, and starts a run
10
- * through `runAutomation`. Both admit editors and admins. AppSync also lets an IAM principal call the
10
+ * through `runAutomation`. Today reads the day's runs through `todayOverview`. Both admit editors and admins. AppSync also lets an IAM principal call the
11
11
  * query when its own policy allows the field (every operation in this schema accepts IAM callers for
12
12
  * the functions that call it); the function reads only for an IAM principal of its own account and refuses
13
13
  * every IAM caller on `runAutomation`.
@@ -19,6 +19,13 @@ export const automationViewSchemaDefinitions = {
19
19
  .returns(a.json())
20
20
  .authorization((allow) => [allow.groups(editors)])
21
21
  .handler(functionHandler("automationView", automationView)),
22
+ /** Today (PPY-5bcf42): what ran in one day, what it decided to do nothing about, what it cost. Shares the function above; reads by index. */
23
+ todayOverview: a
24
+ .query()
25
+ .arguments({ day: a.string(), timeZone: a.string() })
26
+ .returns(a.json())
27
+ .authorization((allow) => [allow.groups(editors)])
28
+ .handler(functionHandler("automationView", automationView)),
22
29
  runAutomation: a
23
30
  .mutation()
24
31
  .arguments({ automationId: a.string().required(), input: a.json() })
@@ -2,31 +2,31 @@ import { Stack } from "aws-cdk-lib";
2
2
  import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
3
3
  import { MONITORING_TABLE_PARAMETER, MONITORING_VIEW_TABLE_ACTIONS, monitoringViewParameterArn, monitoringViewTableArns, } from "../monitoring-view/wire.js";
4
4
  import { connectToSiteApi } from "../../site-api-access.js";
5
- /** The reads the function makes of its own site's API with its own role. It writes nothing there. */
5
+ import { allowWakeSending } from "../../agents/wake-queue.js";
6
+ /** The reads the function makes of its own site's API with its own role. It writes nothing there. Today reads the day's runs through the status index and the agents through the tenant index. */
6
7
  export const AUTOMATION_VIEW_FUNCTION_FIELDS = [
7
8
  "Query/fields/getAutomation",
8
9
  "Query/fields/getNewsroomProcedureDefinition",
9
10
  "Query/fields/getProcedureRun",
10
11
  "Query/fields/listAutomations",
12
+ "Query/fields/listAutomationsByTenant",
11
13
  "Query/fields/listProcedureRunsByProcedureAndRequestedAt",
14
+ "Query/fields/listProcedureRunsByStatusAndRequestedAt",
12
15
  ];
13
- /** The procedure runner stack's function (infra/procedures/papyrus-procedure-runner.yaml); Run now starts it asynchronously. */
14
- export const PROCEDURE_RUNNER_FUNCTION_NAME = "papyrus-procedure-runner";
15
16
  /** Run now writes one row of its own to the monitoring table, in a monitor's partition (`MONITOR#<id>`), and nothing else. */
16
17
  export const AUTOMATION_RUN_NOW_TABLE_ACTIONS = ["dynamodb:PutItem"];
17
18
  export const AUTOMATION_RUN_NOW_LEADING_KEYS = ["MONITOR#*"];
18
19
  /**
19
20
  * Environment and least-privilege IAM for the automation-view function: a few read fields of the site's own API,
20
21
  * the same read-only grant on the monitoring table that the Monitoring page has, one PutItem for Run now's row,
21
- * and permission to start the procedure runner. A site outside the
22
+ * and permission to put a wake on the site's own wake queue (Run now). A site outside the
22
23
  * monitoring account finds no parameter and the page lists its records without runs.
23
24
  */
24
- export function wireAutomationView(backend) {
25
+ export function wireAutomationView(backend, brandId) {
25
26
  const lambda = backend.automationView.resources.lambda;
26
27
  const stack = Stack.of(lambda);
27
28
  connectToSiteApi(lambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
28
29
  lambda.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
29
- lambda.addEnvironment("PROCEDURE_RUNNER_FUNCTION", PROCEDURE_RUNNER_FUNCTION_NAME);
30
30
  const apiId = backend.data.resources.graphqlApi.apiId;
31
31
  lambda.addToRolePolicy(new PolicyStatement({
32
32
  effect: Effect.ALLOW,
@@ -49,9 +49,5 @@ export function wireAutomationView(backend) {
49
49
  resources: monitoringViewTableArns(stack.region, stack.account).slice(0, 1),
50
50
  conditions: { "ForAllValues:StringLike": { "dynamodb:LeadingKeys": AUTOMATION_RUN_NOW_LEADING_KEYS } },
51
51
  }));
52
- lambda.addToRolePolicy(new PolicyStatement({
53
- effect: Effect.ALLOW,
54
- actions: ["lambda:InvokeFunction"],
55
- resources: [`arn:aws:lambda:${stack.region}:${stack.account}:function:${PROCEDURE_RUNNER_FUNCTION_NAME}`],
56
- }));
52
+ allowWakeSending(lambda, brandId);
57
53
  }
@@ -8,19 +8,19 @@ import {
8
8
  monitoringViewTableArns,
9
9
  } from "../monitoring-view/wire";
10
10
  import { connectToSiteApi } from "../../site-api-access";
11
+ import { allowWakeSending } from "../../agents/wake-queue";
11
12
 
12
- /** The reads the function makes of its own site's API with its own role. It writes nothing there. */
13
+ /** The reads the function makes of its own site's API with its own role. It writes nothing there. Today reads the day's runs through the status index and the agents through the tenant index. */
13
14
  export const AUTOMATION_VIEW_FUNCTION_FIELDS = [
14
15
  "Query/fields/getAutomation",
15
16
  "Query/fields/getNewsroomProcedureDefinition",
16
17
  "Query/fields/getProcedureRun",
17
18
  "Query/fields/listAutomations",
19
+ "Query/fields/listAutomationsByTenant",
18
20
  "Query/fields/listProcedureRunsByProcedureAndRequestedAt",
21
+ "Query/fields/listProcedureRunsByStatusAndRequestedAt",
19
22
  ];
20
23
 
21
- /** The procedure runner stack's function (infra/procedures/papyrus-procedure-runner.yaml); Run now starts it asynchronously. */
22
- export const PROCEDURE_RUNNER_FUNCTION_NAME = "papyrus-procedure-runner";
23
-
24
24
  /** Run now writes one row of its own to the monitoring table, in a monitor's partition (`MONITOR#<id>`), and nothing else. */
25
25
  export const AUTOMATION_RUN_NOW_TABLE_ACTIONS = ["dynamodb:PutItem"];
26
26
  export const AUTOMATION_RUN_NOW_LEADING_KEYS = ["MONITOR#*"];
@@ -28,15 +28,14 @@ export const AUTOMATION_RUN_NOW_LEADING_KEYS = ["MONITOR#*"];
28
28
  /**
29
29
  * Environment and least-privilege IAM for the automation-view function: a few read fields of the site's own API,
30
30
  * the same read-only grant on the monitoring table that the Monitoring page has, one PutItem for Run now's row,
31
- * and permission to start the procedure runner. A site outside the
31
+ * and permission to put a wake on the site's own wake queue (Run now). A site outside the
32
32
  * monitoring account finds no parameter and the page lists its records without runs.
33
33
  */
34
- export function wireAutomationView(backend: any): void {
34
+ export function wireAutomationView(backend: any, brandId: string): void {
35
35
  const lambda = backend.automationView.resources.lambda as LambdaFunction;
36
36
  const stack = Stack.of(lambda);
37
37
  connectToSiteApi(lambda, backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl as string);
38
38
  lambda.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
39
- lambda.addEnvironment("PROCEDURE_RUNNER_FUNCTION", PROCEDURE_RUNNER_FUNCTION_NAME);
40
39
  const apiId = backend.data.resources.graphqlApi.apiId as string;
41
40
  lambda.addToRolePolicy(
42
41
  new PolicyStatement({
@@ -67,11 +66,5 @@ export function wireAutomationView(backend: any): void {
67
66
  conditions: { "ForAllValues:StringLike": { "dynamodb:LeadingKeys": AUTOMATION_RUN_NOW_LEADING_KEYS } },
68
67
  }),
69
68
  );
70
- lambda.addToRolePolicy(
71
- new PolicyStatement({
72
- effect: Effect.ALLOW,
73
- actions: ["lambda:InvokeFunction"],
74
- resources: [`arn:aws:lambda:${stack.region}:${stack.account}:function:${PROCEDURE_RUNNER_FUNCTION_NAME}`],
75
- }),
76
- );
69
+ allowWakeSending(lambda, brandId);
77
70
  }
@@ -1,7 +1,7 @@
1
1
  """The translate-on-publish dispatcher: a DynamoDB stream consumer on the LocalizationRequest table (docs/story-translation-procedure.md).
2
2
 
3
3
  All the logic is ``papyrus_content.localize.dispatch``; this file decodes the stream records and builds the collaborators with the function's own role:
4
- the site's authoring client, the monitoring table (as the automation-view function reads and writes it), the procedure runner and the content-actions
4
+ the site's authoring client, the monitoring table (as the automation-view function reads and writes it), the site's wake queue (where a procedure start is put) and the content-actions
5
5
  function. A batch whose handling fails reports every record as failed, so Lambda retries it (the stream's retry limit and the function's dead letter queue
6
6
  follow); the work itself is idempotent (a claim per record, a publish that finds the translation live).
7
7
  """
@@ -24,7 +24,8 @@ def invoke_content_actions(task: dict[str, Any]) -> None:
24
24
 
25
25
 
26
26
  def handler(event: dict[str, Any], context: Any = None, *, client=None, table=None, runner=None, publisher=None) -> dict[str, Any]:
27
- from papyrus_content.automations import MonitoringReader, MonitoringWriter, lambda_invoker, monitoring_table_from_environment
27
+ from papyrus_content.automations import MonitoringReader, MonitoringWriter, monitoring_table_from_environment
28
+ from papyrus_content.agent_wakes import wake_sender
28
29
  from papyrus_content.graphql_authoring import PapyrusGraphQLAuthoringClient
29
30
 
30
31
  images = [{"old": decode_image(record["dynamodb"].get("OldImage")), "new": decode_image(record["dynamodb"].get("NewImage"))}
@@ -37,7 +38,7 @@ def handler(event: dict[str, Any], context: Any = None, *, client=None, table=No
37
38
  try:
38
39
  handle_changes(images, client or PapyrusGraphQLAuthoringClient(endpoint=endpoint),
39
40
  reader=MonitoringReader(table) if table is not None else None, writer=MonitoringWriter(table) if table is not None else None,
40
- invoke=runner or lambda_invoker(os.environ.get("PROCEDURE_RUNNER_FUNCTION")), invoke_publish=publisher or invoke_content_actions,
41
+ invoke=runner or wake_sender(), invoke_publish=publisher or invoke_content_actions,
41
42
  site_endpoint=endpoint)
42
43
  except Exception as error:
43
44
  print(json.dumps({"event": "papyrus_localization_dispatch_failed", "error": f"{type(error).__name__}: {error}"[:500]}))