@anthusai/papyrus 1.0.0-next.31 → 1.0.0-next.33
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/data/resource.js +2 -0
- package/amplify/data/resource.ts +2 -0
- package/amplify/data/schema.js +2 -0
- package/amplify/data/schema.ts +2 -0
- package/amplify/functions/category-action/handler.ts +5 -3
- package/amplify/functions/shared/reference-curation-metadata.ts +29 -0
- package/amplify/inbound-email/ses-intake.js +86 -0
- package/amplify/inbound-email/ses-intake.ts +110 -0
- package/amplify/site-backend-config.ts +11 -0
- package/amplify/site-backend-names.js +88 -0
- package/amplify/site-backend-names.ts +147 -0
- package/amplify/site-backend.js +45 -143
- package/amplify/site-backend.ts +62 -161
- package/amplify/storage-backups/construct.js +31 -0
- package/amplify/storage-backups/construct.ts +47 -0
- package/app/newsroom/layout.tsx +2 -0
- package/components/news-desk-taxonomy-client.ts +51 -0
- package/components/newsroom-references-view.tsx +83 -8
- package/components/reference-cyclotron-status.tsx +109 -0
- package/components/reference-relevance-review.tsx +75 -0
- package/components/topic-steering-workspace.tsx +48 -1
- package/lib/category-repository.ts +41 -0
- package/lib/reference-policy.ts +5 -0
- package/lib/relevance-decisions.ts +103 -0
- package/lib/relevance-status.ts +63 -0
- package/lib/semantic-graph.ts +2 -0
- package/package.json +6 -1
- package/routes.manifest.json +1 -1
package/amplify/site-backend.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { defineBackend, secret } from "@aws-amplify/backend";
|
|
2
|
-
import {
|
|
3
|
-
import * as backup from "aws-cdk-lib/aws-backup";
|
|
4
|
-
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from "aws-cdk-lib/custom-resources";
|
|
2
|
+
import { Stack } from "aws-cdk-lib";
|
|
5
3
|
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
|
|
6
|
-
import * as events from "aws-cdk-lib/aws-events";
|
|
7
|
-
import * as route53 from "aws-cdk-lib/aws-route53";
|
|
8
|
-
import * as ses from "aws-cdk-lib/aws-ses";
|
|
9
|
-
import * as sesActions from "aws-cdk-lib/aws-ses-actions";
|
|
10
4
|
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
11
5
|
import { CfnEventSourceMapping, FunctionUrlAuthType } from "aws-cdk-lib/aws-lambda";
|
|
12
6
|
import { CfnIndex, CfnVectorBucket, CfnVectorBucketPolicy } from "aws-cdk-lib/aws-s3vectors";
|
|
@@ -29,7 +23,10 @@ import { emailSubmissionProcessor } from "./functions/email-submission-processor
|
|
|
29
23
|
import { sesInboundReceive } from "./functions/ses-inbound-receive/resource.js";
|
|
30
24
|
import { slackDelivery } from "./functions/slack-delivery/resource.js";
|
|
31
25
|
import { slackEvents } from "./functions/slack-events/resource.js";
|
|
26
|
+
import { addInboundEmailSesIntake } from "./inbound-email/ses-intake.js";
|
|
32
27
|
import { InboundEmailStack } from "./inbound-email/stack.js";
|
|
28
|
+
import { deriveKnowledgeVectorIndexName, deriveReceiptRuleName, deriveReceiptRuleSetName, deriveStorageBackupVaultName, isLegacyProductionPipeline, planInboundEmailSes, resolveSiteBackendFeatureFlags, } from "./site-backend-names.js";
|
|
29
|
+
import { addStorageBackups } from "./storage-backups/construct.js";
|
|
33
30
|
import { storage } from "./storage/resource.js";
|
|
34
31
|
export function defineSiteBackend(papyrusSite) {
|
|
35
32
|
// `papyrus.config.ts`'s default export. Backend options live under `backend`;
|
|
@@ -39,43 +36,24 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
39
36
|
const knowledgeEmbeddingModel = "text-embedding-3-small";
|
|
40
37
|
const amplifyBranch = (process.env.AWS_BRANCH ?? "").trim();
|
|
41
38
|
const amplifyAppId = (process.env.AWS_APP_ID ?? "").trim();
|
|
42
|
-
// Amplify app id whose `main` branch is
|
|
43
|
-
//
|
|
39
|
+
// Amplify app id whose `main` branch is the original p.apyr.us backend; only
|
|
40
|
+
// that app keeps the historical account-global names (see site-backend-names.ts).
|
|
44
41
|
const productionAppId = (site.productionAppId ?? "").trim();
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.slice(0, maxLength);
|
|
61
|
-
}
|
|
62
|
-
// S3 Vectors index names are account-global. Keep the original name for the
|
|
63
|
-
// p.apyr.us production app so its existing index + data are not orphaned;
|
|
64
|
-
// namespace every other app's index by site brand so a second CMS app can
|
|
65
|
-
// deploy into the same account without colliding.
|
|
66
|
-
const papyrusSiteBrand = (site.brandId
|
|
67
|
-
?? process.env.PAPYRUS_SITE_BRAND
|
|
68
|
-
?? process.env.NEXT_PUBLIC_PAPYRUS_SITE_BRAND
|
|
69
|
-
?? "papyrus").trim().toLowerCase();
|
|
70
|
-
const knowledgeVectorIndexName = productionAppId !== "" && amplifyAppId === productionAppId
|
|
71
|
-
? "papyrus-knowledge"
|
|
72
|
-
: `papyrus-knowledge-${sanitizeAwsName(papyrusSiteBrand, 40)}`;
|
|
73
|
-
// SES active receipt rule sets and shared backup vault names are account-global.
|
|
74
|
-
// Keep them on the production pipeline only unless explicitly opted in.
|
|
75
|
-
// A feature flag in the site config wins over the environment.
|
|
76
|
-
const enableInboundEmail = site.features?.inboundEmail ?? readEnvFlag("PAPYRUS_ENABLE_INBOUND_EMAIL", isAmplifyProductionPipeline);
|
|
77
|
-
const enableSlackAgent = site.features?.slack ?? readEnvFlag("PAPYRUS_ENABLE_SLACK", false);
|
|
78
|
-
const enableStorageBackups = site.features?.storageBackups ?? readEnvFlag("PAPYRUS_ENABLE_STORAGE_BACKUPS", isAmplifyProductionPipeline);
|
|
42
|
+
const siteBackendIdentity = {
|
|
43
|
+
brandId: (site.brandId
|
|
44
|
+
?? process.env.PAPYRUS_SITE_BRAND
|
|
45
|
+
?? process.env.NEXT_PUBLIC_PAPYRUS_SITE_BRAND
|
|
46
|
+
?? "papyrus").trim().toLowerCase(),
|
|
47
|
+
amplifyAppId,
|
|
48
|
+
amplifyBranch,
|
|
49
|
+
productionAppId,
|
|
50
|
+
};
|
|
51
|
+
const isAmplifyProductionPipeline = isLegacyProductionPipeline(siteBackendIdentity);
|
|
52
|
+
const knowledgeVectorIndexName = deriveKnowledgeVectorIndexName(siteBackendIdentity);
|
|
53
|
+
const featureFlags = resolveSiteBackendFeatureFlags(site.features, process.env, siteBackendIdentity);
|
|
54
|
+
const enableInboundEmail = featureFlags.inboundEmail;
|
|
55
|
+
const enableSlackAgent = featureFlags.slack;
|
|
56
|
+
const enableStorageBackups = featureFlags.storageBackups;
|
|
79
57
|
const authConfig = site.auth ?? authConfigFromEnv();
|
|
80
58
|
const backend = defineBackend({
|
|
81
59
|
assignmentAction,
|
|
@@ -104,7 +82,7 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
104
82
|
const amplifyBackendDir = dirname(fileURLToPath(import.meta.url));
|
|
105
83
|
// Repo root in a Papyrus checkout; package root when installed from npm.
|
|
106
84
|
const projectRoot = resolve(amplifyBackendDir, "..");
|
|
107
|
-
const enableConsoleResponder =
|
|
85
|
+
const enableConsoleResponder = featureFlags.consoleResponder;
|
|
108
86
|
if (enableConsoleResponder
|
|
109
87
|
&& !process.env.PAPYRUS_CONSOLE_RESPONDER_IMAGE_URI?.trim()
|
|
110
88
|
&& !process.env.PAPYRUS_CONSOLE_RESPONDER_ALLOW_LOCAL_BUILD?.trim()
|
|
@@ -237,31 +215,13 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
237
215
|
}
|
|
238
216
|
if (enableStorageBackups) {
|
|
239
217
|
const storageBackupsStack = backend.createStack("storage-backups");
|
|
240
|
-
const storageBackupVaultName =
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
: `papyrus-${sanitizeAwsName(storageBackupsStack.stackName, 32)}-media-vault`));
|
|
244
|
-
storageBackupVault = new backup.BackupVault(storageBackupsStack, "PapyrusStorageBackupVault", {
|
|
218
|
+
const storageBackupVaultName = deriveStorageBackupVaultName(siteBackendIdentity, storageBackupsStack.stackName, process.env.PAPYRUS_STORAGE_BACKUP_VAULT_NAME);
|
|
219
|
+
const storageBackups = addStorageBackups(storageBackupsStack, {
|
|
220
|
+
storageBucket,
|
|
245
221
|
backupVaultName: storageBackupVaultName,
|
|
246
|
-
removalPolicy: RemovalPolicy.RETAIN,
|
|
247
|
-
});
|
|
248
|
-
storageBackupPlan = new backup.BackupPlan(storageBackupsStack, "PapyrusStorageBackupPlan", {
|
|
249
|
-
backupVault: storageBackupVault,
|
|
250
|
-
});
|
|
251
|
-
storageBackupPlan.addRule(new backup.BackupPlanRule({
|
|
252
|
-
ruleName: "papyrus-storage-pitr-35d",
|
|
253
|
-
enableContinuousBackup: true,
|
|
254
|
-
deleteAfter: Duration.days(35),
|
|
255
|
-
}));
|
|
256
|
-
storageBackupPlan.addRule(new backup.BackupPlanRule({
|
|
257
|
-
ruleName: "papyrus-storage-daily-365d",
|
|
258
|
-
scheduleExpression: events.Schedule.cron({ minute: "0", hour: "5" }),
|
|
259
|
-
deleteAfter: Duration.days(365),
|
|
260
|
-
}));
|
|
261
|
-
storageBackupPlan.addSelection("PapyrusStorageBackupSelection", {
|
|
262
|
-
allowRestores: true,
|
|
263
|
-
resources: [backup.BackupResource.fromArn(storageBucket.bucketArn)],
|
|
264
222
|
});
|
|
223
|
+
storageBackupVault = storageBackups.vault;
|
|
224
|
+
storageBackupPlan = storageBackups.plan;
|
|
265
225
|
}
|
|
266
226
|
// Grant S3 access on Lambda roles only (not storage bucket policies) to avoid
|
|
267
227
|
// storage ↔ data nested-stack circular dependencies from allow.resource().
|
|
@@ -412,83 +372,25 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
412
372
|
resources: ["*"],
|
|
413
373
|
}));
|
|
414
374
|
const inboundEventStack = Stack.of(receiveLambda);
|
|
415
|
-
// SES receipt rule
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const verifyInboundEmailDomain = new AwsCustomResource(storageStack, "VerifyInboundEmailDomain", {
|
|
422
|
-
onCreate: {
|
|
423
|
-
service: "SES",
|
|
424
|
-
action: "verifyDomainIdentity",
|
|
425
|
-
parameters: {
|
|
426
|
-
Domain: inboundEmailDomain,
|
|
427
|
-
},
|
|
428
|
-
physicalResourceId: PhysicalResourceId.of(`ses-domain-verify-${inboundEmailDomain}`),
|
|
429
|
-
},
|
|
430
|
-
onUpdate: {
|
|
431
|
-
service: "SES",
|
|
432
|
-
action: "verifyDomainIdentity",
|
|
433
|
-
parameters: {
|
|
434
|
-
Domain: inboundEmailDomain,
|
|
435
|
-
},
|
|
436
|
-
physicalResourceId: PhysicalResourceId.of(`ses-domain-verify-${inboundEmailDomain}`),
|
|
437
|
-
},
|
|
438
|
-
policy: AwsCustomResourcePolicy.fromSdkCalls({
|
|
439
|
-
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
|
|
440
|
-
}),
|
|
441
|
-
timeout: Duration.minutes(2),
|
|
442
|
-
});
|
|
443
|
-
new route53.TxtRecord(storageStack, "PapyrusInboundEmailDomainVerification", {
|
|
444
|
-
zone: inboundDnsZone,
|
|
445
|
-
recordName: `_amazonses.${inboundDnsRecordName}`,
|
|
446
|
-
ttl: Duration.minutes(5),
|
|
447
|
-
values: [verifyInboundEmailDomain.getResponseField("VerificationToken")],
|
|
448
|
-
});
|
|
449
|
-
const inboundRuleSet = new ses.ReceiptRuleSet(storageStack, "PapyrusInboundEmailRuleSet", {
|
|
450
|
-
receiptRuleSetName: `papyrus-inbound-${inboundEmailDomain.replace(/\./g, "-")}`,
|
|
451
|
-
});
|
|
452
|
-
inboundRuleSet.addRule("PapyrusInboundSubmissions", {
|
|
375
|
+
// SES allows one active receipt rule set per region, so a non-legacy site
|
|
376
|
+
// creates its own brand-named rule set and never activates it here.
|
|
377
|
+
const inboundSesPlan = planInboundEmailSes(siteBackendIdentity, enableInboundEmail, site.inboundEmailSes);
|
|
378
|
+
if (inboundSesPlan.createReceiptRules) {
|
|
379
|
+
addInboundEmailSesIntake(storageStack, {
|
|
380
|
+
storageBucket,
|
|
453
381
|
recipients: inboundRecipients,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
service: "SES",
|
|
467
|
-
action: "setActiveReceiptRuleSet",
|
|
468
|
-
parameters: {
|
|
469
|
-
RuleSetName: inboundRuleSet.receiptRuleSetName,
|
|
470
|
-
},
|
|
471
|
-
physicalResourceId: PhysicalResourceId.of(`activate-${inboundRuleSet.receiptRuleSetName}`),
|
|
472
|
-
},
|
|
473
|
-
onUpdate: {
|
|
474
|
-
service: "SES",
|
|
475
|
-
action: "setActiveReceiptRuleSet",
|
|
476
|
-
parameters: {
|
|
477
|
-
RuleSetName: inboundRuleSet.receiptRuleSetName,
|
|
478
|
-
},
|
|
479
|
-
physicalResourceId: PhysicalResourceId.of(`activate-${inboundRuleSet.receiptRuleSetName}`),
|
|
480
|
-
},
|
|
481
|
-
onDelete: {
|
|
482
|
-
service: "SES",
|
|
483
|
-
action: "setActiveReceiptRuleSet",
|
|
484
|
-
parameters: {
|
|
485
|
-
RuleSetName: null,
|
|
486
|
-
},
|
|
487
|
-
},
|
|
488
|
-
policy: AwsCustomResourcePolicy.fromSdkCalls({
|
|
489
|
-
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
|
|
490
|
-
}),
|
|
491
|
-
timeout: Duration.minutes(2),
|
|
382
|
+
ruleSetName: deriveReceiptRuleSetName(siteBackendIdentity, inboundEmailDomain),
|
|
383
|
+
existingRuleSetName: site.inboundEmailSes?.existingReceiptRuleSetName,
|
|
384
|
+
ruleName: deriveReceiptRuleName(siteBackendIdentity),
|
|
385
|
+
activateRuleSet: inboundSesPlan.activateReceiptRuleSet,
|
|
386
|
+
domainIdentity: inboundSesPlan.manageDomainIdentity
|
|
387
|
+
? {
|
|
388
|
+
domain: inboundEmailDomain,
|
|
389
|
+
hostedZoneId: inboundDnsZoneId,
|
|
390
|
+
hostedZoneName: inboundDnsZoneName,
|
|
391
|
+
recordName: inboundDnsRecordName,
|
|
392
|
+
}
|
|
393
|
+
: undefined,
|
|
492
394
|
});
|
|
493
395
|
}
|
|
494
396
|
new InboundEmailStack(inboundEventStack, "InboundEmail", {
|
package/amplify/site-backend.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { defineBackend, secret } from "@aws-amplify/backend";
|
|
2
|
-
import {
|
|
3
|
-
import * as backup from "aws-cdk-lib/aws-backup";
|
|
4
|
-
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from "aws-cdk-lib/custom-resources";
|
|
2
|
+
import { Stack } from "aws-cdk-lib";
|
|
3
|
+
import type * as backup from "aws-cdk-lib/aws-backup";
|
|
5
4
|
import * as dynamodb from "aws-cdk-lib/aws-dynamodb";
|
|
6
|
-
import * as events from "aws-cdk-lib/aws-events";
|
|
7
|
-
import * as route53 from "aws-cdk-lib/aws-route53";
|
|
8
|
-
import * as ses from "aws-cdk-lib/aws-ses";
|
|
9
|
-
import * as sesActions from "aws-cdk-lib/aws-ses-actions";
|
|
10
5
|
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
|
|
11
6
|
import { CfnEventSourceMapping, Function as LambdaFunction, FunctionUrlAuthType } from "aws-cdk-lib/aws-lambda";
|
|
12
7
|
import * as s3 from "aws-cdk-lib/aws-s3";
|
|
@@ -30,7 +25,19 @@ import { emailSubmissionProcessor } from "./functions/email-submission-processor
|
|
|
30
25
|
import { sesInboundReceive } from "./functions/ses-inbound-receive/resource";
|
|
31
26
|
import { slackDelivery } from "./functions/slack-delivery/resource";
|
|
32
27
|
import { slackEvents } from "./functions/slack-events/resource";
|
|
28
|
+
import { addInboundEmailSesIntake } from "./inbound-email/ses-intake";
|
|
33
29
|
import { InboundEmailStack } from "./inbound-email/stack";
|
|
30
|
+
import {
|
|
31
|
+
deriveKnowledgeVectorIndexName,
|
|
32
|
+
deriveReceiptRuleName,
|
|
33
|
+
deriveReceiptRuleSetName,
|
|
34
|
+
deriveStorageBackupVaultName,
|
|
35
|
+
isLegacyProductionPipeline,
|
|
36
|
+
planInboundEmailSes,
|
|
37
|
+
resolveSiteBackendFeatureFlags,
|
|
38
|
+
type SiteBackendIdentity,
|
|
39
|
+
} from "./site-backend-names";
|
|
40
|
+
import { addStorageBackups } from "./storage-backups/construct";
|
|
34
41
|
import { storage } from "./storage/resource";
|
|
35
42
|
import type { PapyrusSite } from "../lib/define-site";
|
|
36
43
|
|
|
@@ -43,49 +50,26 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
43
50
|
|
|
44
51
|
const amplifyBranch = (process.env.AWS_BRANCH ?? "").trim();
|
|
45
52
|
const amplifyAppId = (process.env.AWS_APP_ID ?? "").trim();
|
|
46
|
-
// Amplify app id whose `main` branch is
|
|
47
|
-
//
|
|
53
|
+
// Amplify app id whose `main` branch is the original p.apyr.us backend; only
|
|
54
|
+
// that app keeps the historical account-global names (see site-backend-names.ts).
|
|
48
55
|
const productionAppId = (site.productionAppId ?? "").trim();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// S3 Vectors index names are account-global. Keep the original name for the
|
|
69
|
-
// p.apyr.us production app so its existing index + data are not orphaned;
|
|
70
|
-
// namespace every other app's index by site brand so a second CMS app can
|
|
71
|
-
// deploy into the same account without colliding.
|
|
72
|
-
const papyrusSiteBrand = (
|
|
73
|
-
site.brandId
|
|
74
|
-
?? process.env.PAPYRUS_SITE_BRAND
|
|
75
|
-
?? process.env.NEXT_PUBLIC_PAPYRUS_SITE_BRAND
|
|
76
|
-
?? "papyrus"
|
|
77
|
-
).trim().toLowerCase();
|
|
78
|
-
const knowledgeVectorIndexName =
|
|
79
|
-
productionAppId !== "" && amplifyAppId === productionAppId
|
|
80
|
-
? "papyrus-knowledge"
|
|
81
|
-
: `papyrus-knowledge-${sanitizeAwsName(papyrusSiteBrand, 40)}`;
|
|
82
|
-
|
|
83
|
-
// SES active receipt rule sets and shared backup vault names are account-global.
|
|
84
|
-
// Keep them on the production pipeline only unless explicitly opted in.
|
|
85
|
-
// A feature flag in the site config wins over the environment.
|
|
86
|
-
const enableInboundEmail = site.features?.inboundEmail ?? readEnvFlag("PAPYRUS_ENABLE_INBOUND_EMAIL", isAmplifyProductionPipeline);
|
|
87
|
-
const enableSlackAgent = site.features?.slack ?? readEnvFlag("PAPYRUS_ENABLE_SLACK", false);
|
|
88
|
-
const enableStorageBackups = site.features?.storageBackups ?? readEnvFlag("PAPYRUS_ENABLE_STORAGE_BACKUPS", isAmplifyProductionPipeline);
|
|
56
|
+
const siteBackendIdentity: SiteBackendIdentity = {
|
|
57
|
+
brandId: (
|
|
58
|
+
site.brandId
|
|
59
|
+
?? process.env.PAPYRUS_SITE_BRAND
|
|
60
|
+
?? process.env.NEXT_PUBLIC_PAPYRUS_SITE_BRAND
|
|
61
|
+
?? "papyrus"
|
|
62
|
+
).trim().toLowerCase(),
|
|
63
|
+
amplifyAppId,
|
|
64
|
+
amplifyBranch,
|
|
65
|
+
productionAppId,
|
|
66
|
+
};
|
|
67
|
+
const isAmplifyProductionPipeline = isLegacyProductionPipeline(siteBackendIdentity);
|
|
68
|
+
const knowledgeVectorIndexName = deriveKnowledgeVectorIndexName(siteBackendIdentity);
|
|
69
|
+
const featureFlags = resolveSiteBackendFeatureFlags(site.features, process.env, siteBackendIdentity);
|
|
70
|
+
const enableInboundEmail = featureFlags.inboundEmail;
|
|
71
|
+
const enableSlackAgent = featureFlags.slack;
|
|
72
|
+
const enableStorageBackups = featureFlags.storageBackups;
|
|
89
73
|
|
|
90
74
|
const authConfig = site.auth ?? authConfigFromEnv();
|
|
91
75
|
const backend = defineBackend({
|
|
@@ -119,7 +103,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
119
103
|
const amplifyBackendDir = dirname(fileURLToPath(import.meta.url));
|
|
120
104
|
// Repo root in a Papyrus checkout; package root when installed from npm.
|
|
121
105
|
const projectRoot = resolve(amplifyBackendDir, "..");
|
|
122
|
-
const enableConsoleResponder =
|
|
106
|
+
const enableConsoleResponder = featureFlags.consoleResponder;
|
|
123
107
|
|
|
124
108
|
if (
|
|
125
109
|
enableConsoleResponder
|
|
@@ -291,41 +275,18 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
291
275
|
|
|
292
276
|
if (enableStorageBackups) {
|
|
293
277
|
const storageBackupsStack = backend.createStack("storage-backups");
|
|
294
|
-
const storageBackupVaultName =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
: `papyrus-${sanitizeAwsName(storageBackupsStack.stackName, 32)}-media-vault`),
|
|
278
|
+
const storageBackupVaultName = deriveStorageBackupVaultName(
|
|
279
|
+
siteBackendIdentity,
|
|
280
|
+
storageBackupsStack.stackName,
|
|
281
|
+
process.env.PAPYRUS_STORAGE_BACKUP_VAULT_NAME,
|
|
299
282
|
);
|
|
300
283
|
|
|
301
|
-
|
|
284
|
+
const storageBackups = addStorageBackups(storageBackupsStack, {
|
|
285
|
+
storageBucket,
|
|
302
286
|
backupVaultName: storageBackupVaultName,
|
|
303
|
-
removalPolicy: RemovalPolicy.RETAIN,
|
|
304
|
-
});
|
|
305
|
-
storageBackupPlan = new backup.BackupPlan(storageBackupsStack, "PapyrusStorageBackupPlan", {
|
|
306
|
-
backupVault: storageBackupVault,
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
storageBackupPlan.addRule(
|
|
310
|
-
new backup.BackupPlanRule({
|
|
311
|
-
ruleName: "papyrus-storage-pitr-35d",
|
|
312
|
-
enableContinuousBackup: true,
|
|
313
|
-
deleteAfter: Duration.days(35),
|
|
314
|
-
}),
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
storageBackupPlan.addRule(
|
|
318
|
-
new backup.BackupPlanRule({
|
|
319
|
-
ruleName: "papyrus-storage-daily-365d",
|
|
320
|
-
scheduleExpression: events.Schedule.cron({ minute: "0", hour: "5" }),
|
|
321
|
-
deleteAfter: Duration.days(365),
|
|
322
|
-
}),
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
storageBackupPlan.addSelection("PapyrusStorageBackupSelection", {
|
|
326
|
-
allowRestores: true,
|
|
327
|
-
resources: [backup.BackupResource.fromArn(storageBucket.bucketArn)],
|
|
328
287
|
});
|
|
288
|
+
storageBackupVault = storageBackups.vault;
|
|
289
|
+
storageBackupPlan = storageBackups.plan;
|
|
329
290
|
}
|
|
330
291
|
|
|
331
292
|
// Grant S3 access on Lambda roles only (not storage bucket policies) to avoid
|
|
@@ -524,86 +485,26 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
524
485
|
|
|
525
486
|
const inboundEventStack = Stack.of(receiveLambda);
|
|
526
487
|
|
|
527
|
-
// SES receipt rule
|
|
528
|
-
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
},
|
|
548
|
-
physicalResourceId: PhysicalResourceId.of(`ses-domain-verify-${inboundEmailDomain}`),
|
|
549
|
-
},
|
|
550
|
-
policy: AwsCustomResourcePolicy.fromSdkCalls({
|
|
551
|
-
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
|
|
552
|
-
}),
|
|
553
|
-
timeout: Duration.minutes(2),
|
|
554
|
-
});
|
|
555
|
-
new route53.TxtRecord(storageStack, "PapyrusInboundEmailDomainVerification", {
|
|
556
|
-
zone: inboundDnsZone,
|
|
557
|
-
recordName: `_amazonses.${inboundDnsRecordName}`,
|
|
558
|
-
ttl: Duration.minutes(5),
|
|
559
|
-
values: [verifyInboundEmailDomain.getResponseField("VerificationToken")],
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
const inboundRuleSet = new ses.ReceiptRuleSet(storageStack, "PapyrusInboundEmailRuleSet", {
|
|
563
|
-
receiptRuleSetName: `papyrus-inbound-${inboundEmailDomain.replace(/\./g, "-")}`,
|
|
564
|
-
});
|
|
565
|
-
inboundRuleSet.addRule("PapyrusInboundSubmissions", {
|
|
566
|
-
recipients: inboundRecipients,
|
|
567
|
-
enabled: true,
|
|
568
|
-
scanEnabled: true,
|
|
569
|
-
tlsPolicy: ses.TlsPolicy.REQUIRE,
|
|
570
|
-
actions: [
|
|
571
|
-
new sesActions.S3({
|
|
572
|
-
bucket: storageBucket,
|
|
573
|
-
objectKeyPrefix: "inbound-email/",
|
|
574
|
-
}),
|
|
575
|
-
],
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
new AwsCustomResource(storageStack, "ActivateInboundEmailRuleSet", {
|
|
579
|
-
onCreate: {
|
|
580
|
-
service: "SES",
|
|
581
|
-
action: "setActiveReceiptRuleSet",
|
|
582
|
-
parameters: {
|
|
583
|
-
RuleSetName: inboundRuleSet.receiptRuleSetName,
|
|
584
|
-
},
|
|
585
|
-
physicalResourceId: PhysicalResourceId.of(`activate-${inboundRuleSet.receiptRuleSetName}`),
|
|
586
|
-
},
|
|
587
|
-
onUpdate: {
|
|
588
|
-
service: "SES",
|
|
589
|
-
action: "setActiveReceiptRuleSet",
|
|
590
|
-
parameters: {
|
|
591
|
-
RuleSetName: inboundRuleSet.receiptRuleSetName,
|
|
592
|
-
},
|
|
593
|
-
physicalResourceId: PhysicalResourceId.of(`activate-${inboundRuleSet.receiptRuleSetName}`),
|
|
594
|
-
},
|
|
595
|
-
onDelete: {
|
|
596
|
-
service: "SES",
|
|
597
|
-
action: "setActiveReceiptRuleSet",
|
|
598
|
-
parameters: {
|
|
599
|
-
RuleSetName: null,
|
|
600
|
-
},
|
|
601
|
-
},
|
|
602
|
-
policy: AwsCustomResourcePolicy.fromSdkCalls({
|
|
603
|
-
resources: AwsCustomResourcePolicy.ANY_RESOURCE,
|
|
604
|
-
}),
|
|
605
|
-
timeout: Duration.minutes(2),
|
|
606
|
-
});
|
|
488
|
+
// SES allows one active receipt rule set per region, so a non-legacy site
|
|
489
|
+
// creates its own brand-named rule set and never activates it here.
|
|
490
|
+
const inboundSesPlan = planInboundEmailSes(siteBackendIdentity, enableInboundEmail, site.inboundEmailSes);
|
|
491
|
+
if (inboundSesPlan.createReceiptRules) {
|
|
492
|
+
addInboundEmailSesIntake(storageStack, {
|
|
493
|
+
storageBucket,
|
|
494
|
+
recipients: inboundRecipients,
|
|
495
|
+
ruleSetName: deriveReceiptRuleSetName(siteBackendIdentity, inboundEmailDomain),
|
|
496
|
+
existingRuleSetName: site.inboundEmailSes?.existingReceiptRuleSetName,
|
|
497
|
+
ruleName: deriveReceiptRuleName(siteBackendIdentity),
|
|
498
|
+
activateRuleSet: inboundSesPlan.activateReceiptRuleSet,
|
|
499
|
+
domainIdentity: inboundSesPlan.manageDomainIdentity
|
|
500
|
+
? {
|
|
501
|
+
domain: inboundEmailDomain,
|
|
502
|
+
hostedZoneId: inboundDnsZoneId,
|
|
503
|
+
hostedZoneName: inboundDnsZoneName,
|
|
504
|
+
recordName: inboundDnsRecordName,
|
|
505
|
+
}
|
|
506
|
+
: undefined,
|
|
507
|
+
});
|
|
607
508
|
}
|
|
608
509
|
|
|
609
510
|
new InboundEmailStack(inboundEventStack, "InboundEmail", {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Duration, RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import * as backup from "aws-cdk-lib/aws-backup";
|
|
3
|
+
import * as events from "aws-cdk-lib/aws-events";
|
|
4
|
+
/**
|
|
5
|
+
* Adds the resources directly to `scope` (no wrapper construct) so the logical
|
|
6
|
+
* ids of the live p.apyr.us backup stack stay unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export function addStorageBackups(scope, props) {
|
|
9
|
+
const vault = new backup.BackupVault(scope, "PapyrusStorageBackupVault", {
|
|
10
|
+
backupVaultName: props.backupVaultName,
|
|
11
|
+
removalPolicy: RemovalPolicy.RETAIN,
|
|
12
|
+
});
|
|
13
|
+
const plan = new backup.BackupPlan(scope, "PapyrusStorageBackupPlan", {
|
|
14
|
+
backupVault: vault,
|
|
15
|
+
});
|
|
16
|
+
plan.addRule(new backup.BackupPlanRule({
|
|
17
|
+
ruleName: "papyrus-storage-pitr-35d",
|
|
18
|
+
enableContinuousBackup: true,
|
|
19
|
+
deleteAfter: Duration.days(35),
|
|
20
|
+
}));
|
|
21
|
+
plan.addRule(new backup.BackupPlanRule({
|
|
22
|
+
ruleName: "papyrus-storage-daily-365d",
|
|
23
|
+
scheduleExpression: events.Schedule.cron({ minute: "0", hour: "5" }),
|
|
24
|
+
deleteAfter: Duration.days(365),
|
|
25
|
+
}));
|
|
26
|
+
plan.addSelection("PapyrusStorageBackupSelection", {
|
|
27
|
+
allowRestores: true,
|
|
28
|
+
resources: [backup.BackupResource.fromArn(props.storageBucket.bucketArn)],
|
|
29
|
+
});
|
|
30
|
+
return { plan, vault };
|
|
31
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Duration, RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import * as backup from "aws-cdk-lib/aws-backup";
|
|
3
|
+
import * as events from "aws-cdk-lib/aws-events";
|
|
4
|
+
import type * as s3 from "aws-cdk-lib/aws-s3";
|
|
5
|
+
import type { Construct } from "constructs";
|
|
6
|
+
|
|
7
|
+
export type StorageBackupsProps = {
|
|
8
|
+
storageBucket: s3.IBucket;
|
|
9
|
+
backupVaultName: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Adds the resources directly to `scope` (no wrapper construct) so the logical
|
|
14
|
+
* ids of the live p.apyr.us backup stack stay unchanged.
|
|
15
|
+
*/
|
|
16
|
+
export function addStorageBackups(scope: Construct, props: StorageBackupsProps) {
|
|
17
|
+
const vault = new backup.BackupVault(scope, "PapyrusStorageBackupVault", {
|
|
18
|
+
backupVaultName: props.backupVaultName,
|
|
19
|
+
removalPolicy: RemovalPolicy.RETAIN,
|
|
20
|
+
});
|
|
21
|
+
const plan = new backup.BackupPlan(scope, "PapyrusStorageBackupPlan", {
|
|
22
|
+
backupVault: vault,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
plan.addRule(
|
|
26
|
+
new backup.BackupPlanRule({
|
|
27
|
+
ruleName: "papyrus-storage-pitr-35d",
|
|
28
|
+
enableContinuousBackup: true,
|
|
29
|
+
deleteAfter: Duration.days(35),
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
plan.addRule(
|
|
34
|
+
new backup.BackupPlanRule({
|
|
35
|
+
ruleName: "papyrus-storage-daily-365d",
|
|
36
|
+
scheduleExpression: events.Schedule.cron({ minute: "0", hour: "5" }),
|
|
37
|
+
deleteAfter: Duration.days(365),
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
plan.addSelection("PapyrusStorageBackupSelection", {
|
|
42
|
+
allowRestores: true,
|
|
43
|
+
resources: [backup.BackupResource.fromArn(props.storageBucket.bucketArn)],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return { plan, vault };
|
|
47
|
+
}
|
package/app/newsroom/layout.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Component rules only (no reset, no theme): the Cyclotron review control and status widget.
|
|
2
|
+
import "cyclotron/styles/components.css";
|
|
1
3
|
import { NewsroomClientShell } from "../../components/newsroom-client-shell";
|
|
2
4
|
|
|
3
5
|
export default function NewsroomLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
|
@@ -3682,3 +3682,54 @@ function normalizeUnknownErrorMessage(error: unknown, fallback: string): string
|
|
|
3682
3682
|
return fallback;
|
|
3683
3683
|
}
|
|
3684
3684
|
}
|
|
3685
|
+
|
|
3686
|
+
const CREATE_KNOWLEDGE_RAW_PAYLOAD_MUTATION = `
|
|
3687
|
+
mutation CreateKnowledgeRawPayload($input: CreateKnowledgeRawPayloadInput!) {
|
|
3688
|
+
createKnowledgeRawPayload(input: $input) { id }
|
|
3689
|
+
}
|
|
3690
|
+
`;
|
|
3691
|
+
|
|
3692
|
+
const GET_KNOWLEDGE_RAW_PAYLOAD_QUERY = `
|
|
3693
|
+
query GetKnowledgeRawPayload($id: ID!) {
|
|
3694
|
+
getKnowledgeRawPayload(id: $id) { id }
|
|
3695
|
+
}
|
|
3696
|
+
`;
|
|
3697
|
+
|
|
3698
|
+
/** The relevance cyclotron's latest cyclotron-status/v1 snapshot, as the sweep recorded it. */
|
|
3699
|
+
export async function loadCyclotronStatus(cyclotronId: string): Promise<import("cyclotron/cyclotron-status").CyclotronStatus | null> {
|
|
3700
|
+
const { cyclotronStatusPayloadId, latestCyclotronStatus } = await import("../lib/relevance-status");
|
|
3701
|
+
const payloads = await loadModelPayloadsForOwner("knowledgeRawPayload", cyclotronStatusPayloadId(cyclotronId), ["raw_payload"]);
|
|
3702
|
+
return latestCyclotronStatus(payloads.map((payload) => ({ json: payload.json, updatedAt: payload.attachment.updatedAt })));
|
|
3703
|
+
}
|
|
3704
|
+
|
|
3705
|
+
/** Ask the next decide-relevance sweep to set or clear a manual review rate. */
|
|
3706
|
+
export async function requestCyclotronReviewRate(
|
|
3707
|
+
cyclotronId: string,
|
|
3708
|
+
request: import("../lib/relevance-status").ReviewRateRequest,
|
|
3709
|
+
): Promise<void> {
|
|
3710
|
+
const { reviewRateRequestPayloadId, safeId } = await import("../lib/relevance-status");
|
|
3711
|
+
const id = reviewRateRequestPayloadId(cyclotronId);
|
|
3712
|
+
const existing = await runGraphql<{ getKnowledgeRawPayload?: { id: string } | null }>(GET_KNOWLEDGE_RAW_PAYLOAD_QUERY, { id });
|
|
3713
|
+
if (!existing.getKnowledgeRawPayload) {
|
|
3714
|
+
await runGraphql(CREATE_KNOWLEDGE_RAW_PAYLOAD_MUTATION, {
|
|
3715
|
+
input: {
|
|
3716
|
+
id,
|
|
3717
|
+
ownerType: "cyclotron",
|
|
3718
|
+
ownerId: safeId(cyclotronId),
|
|
3719
|
+
payloadKind: "cyclotron-review-rate-request",
|
|
3720
|
+
createdAt: request.requestedAt,
|
|
3721
|
+
updatedAt: request.requestedAt,
|
|
3722
|
+
},
|
|
3723
|
+
});
|
|
3724
|
+
}
|
|
3725
|
+
await uploadModelPayloadForOwner({
|
|
3726
|
+
ownerKind: "knowledgeRawPayload",
|
|
3727
|
+
ownerId: id,
|
|
3728
|
+
ownerLineageId: id,
|
|
3729
|
+
role: "raw_payload",
|
|
3730
|
+
sortKey: `review-rate-request-${request.requestedAt}`,
|
|
3731
|
+
filename: "review-rate-request.json",
|
|
3732
|
+
mediaType: "application/json",
|
|
3733
|
+
content: JSON.stringify(request),
|
|
3734
|
+
});
|
|
3735
|
+
}
|