@anthusai/papyrus 5.134.0-next.1 → 5.134.0
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/change-feeds.js +2 -0
- package/amplify/agents/change-feeds.ts +4 -0
- package/amplify/agents/item-change-feed.js +2 -0
- package/amplify/agents/item-change-feed.ts +4 -0
- package/amplify/agents/model-key.js +17 -0
- package/amplify/agents/model-key.ts +19 -0
- package/amplify/site-backend-config.js +19 -0
- package/amplify/site-backend-config.ts +34 -0
- package/amplify/site-backend.js +4 -1
- package/amplify/site-backend.ts +4 -1
- package/package.json +1 -1
- package/routes.manifest.json +1 -1
|
@@ -6,6 +6,7 @@ import { connectToSiteApi } from "../site-api-access.js";
|
|
|
6
6
|
import { assertLiteralResourceName, sanitizeAwsName } from "../site-backend-names.js";
|
|
7
7
|
import { LISTENER_INDEX_KIND } from "./item-change-feed.js";
|
|
8
8
|
import { FEED_STREAM_VIEW, FEED_TABLES, tableStream } from "./stream-readers.js";
|
|
9
|
+
import { setModelKeyParameter } from "./model-key.js";
|
|
9
10
|
import { allowWakeSending } from "./wake-queue.js";
|
|
10
11
|
/**
|
|
11
12
|
* The change feeds for Reference, ReviewRequest, Message, LocalizationRequest and Delivery (docs/design/always-on-agents-architecture.md, slice B3, PPY-9b9e64):
|
|
@@ -101,6 +102,7 @@ export function changeFeedsPiece(brandId, source) {
|
|
|
101
102
|
feed.addEnvironment("PAPYRUS_AGENT_PUBLICATION_ID", brandId);
|
|
102
103
|
feed.addEnvironment("PAPYRUS_TENANT_ID", source.tenantId);
|
|
103
104
|
feed.addEnvironment("PAPYRUS_SITE_BUCKET", source.bucketName);
|
|
105
|
+
setModelKeyParameter(feed, source.openAiKeyParameter);
|
|
104
106
|
feed.addEnvironment(CHANGE_FEED_STREAMS_ENV, stack.toJsonString(tables.map((table) => ({ stream: source.streams[table], table }))));
|
|
105
107
|
feed.addToRolePolicy(new PolicyStatement({
|
|
106
108
|
effect: Effect.ALLOW,
|
|
@@ -7,6 +7,7 @@ import { connectToSiteApi } from "../site-api-access";
|
|
|
7
7
|
import { assertLiteralResourceName, sanitizeAwsName } from "../site-backend-names";
|
|
8
8
|
import { LISTENER_INDEX_KIND } from "./item-change-feed";
|
|
9
9
|
import { FEED_STREAM_VIEW, FEED_TABLES, tableStream, type FeedPlacement, type FeedTable, type StreamReaderId } from "./stream-readers";
|
|
10
|
+
import { setModelKeyParameter } from "./model-key";
|
|
10
11
|
import { allowWakeSending } from "./wake-queue";
|
|
11
12
|
import type { AgentPiece } from "./stack";
|
|
12
13
|
|
|
@@ -65,6 +66,8 @@ export type ChangeFeedsSource = {
|
|
|
65
66
|
tenantId: string;
|
|
66
67
|
bucketName: string;
|
|
67
68
|
bucketArn: string;
|
|
69
|
+
/** The NAME of the SSM parameter the runs this feed wakes read their model key from (`agents.openAiKeyParameter`; see `model-key.ts`). Unset: the wakes carry none. */
|
|
70
|
+
openAiKeyParameter?: string;
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
/** The streams of every feed table the schema has. The Reference, Message and LocalizationRequest streams are the readers' own where they exist; ReviewRequest and Delivery had none. */
|
|
@@ -128,6 +131,7 @@ export function changeFeedsPiece(brandId: string, source: ChangeFeedsSource): Ag
|
|
|
128
131
|
feed.addEnvironment("PAPYRUS_AGENT_PUBLICATION_ID", brandId);
|
|
129
132
|
feed.addEnvironment("PAPYRUS_TENANT_ID", source.tenantId);
|
|
130
133
|
feed.addEnvironment("PAPYRUS_SITE_BUCKET", source.bucketName);
|
|
134
|
+
setModelKeyParameter(feed, source.openAiKeyParameter);
|
|
131
135
|
feed.addEnvironment(CHANGE_FEED_STREAMS_ENV, stack.toJsonString(tables.map((table) => ({ stream: source.streams[table], table }))));
|
|
132
136
|
feed.addToRolePolicy(
|
|
133
137
|
new PolicyStatement({
|
|
@@ -5,6 +5,7 @@ import { Architecture, CfnEventSourceMapping, Function as LambdaFunction, Runtim
|
|
|
5
5
|
import { pythonLambdaCode } from "../functions/shared/python-bundle.js";
|
|
6
6
|
import { connectToSiteApi } from "../site-api-access.js";
|
|
7
7
|
import { tableStream } from "./stream-readers.js";
|
|
8
|
+
import { setModelKeyParameter } from "./model-key.js";
|
|
8
9
|
import { allowWakeSending } from "./wake-queue.js";
|
|
9
10
|
/**
|
|
10
11
|
* The Item change feed (docs/design/always-on-agents-architecture.md, slice B2, PPY-8a374e): a DynamoDB stream consumer on the Item table that turns each
|
|
@@ -57,6 +58,7 @@ export function itemChangeFeedPiece(brandId, source) {
|
|
|
57
58
|
feed.addEnvironment("PAPYRUS_AGENT_PUBLICATION_ID", brandId);
|
|
58
59
|
feed.addEnvironment("PAPYRUS_TENANT_ID", source.tenantId);
|
|
59
60
|
feed.addEnvironment("PAPYRUS_SITE_BUCKET", source.bucketName);
|
|
61
|
+
setModelKeyParameter(feed, source.openAiKeyParameter);
|
|
60
62
|
feed.addToRolePolicy(new PolicyStatement({
|
|
61
63
|
effect: Effect.ALLOW,
|
|
62
64
|
actions: ["appsync:GraphQL"],
|
|
@@ -6,6 +6,7 @@ import type { Construct } from "constructs";
|
|
|
6
6
|
import { pythonLambdaCode } from "../functions/shared/python-bundle";
|
|
7
7
|
import { connectToSiteApi } from "../site-api-access";
|
|
8
8
|
import { tableStream } from "./stream-readers";
|
|
9
|
+
import { setModelKeyParameter } from "./model-key";
|
|
9
10
|
import { allowWakeSending } from "./wake-queue";
|
|
10
11
|
import type { AgentPiece } from "./stack";
|
|
11
12
|
|
|
@@ -37,6 +38,8 @@ export type ItemChangeFeedSource = {
|
|
|
37
38
|
tenantId: string;
|
|
38
39
|
bucketName: string;
|
|
39
40
|
bucketArn: string;
|
|
41
|
+
/** The NAME of the SSM parameter the runs this feed wakes read their model key from (`agents.openAiKeyParameter`; see `model-key.ts`). Unset: the wakes carry none. */
|
|
42
|
+
openAiKeyParameter?: string;
|
|
40
43
|
};
|
|
41
44
|
|
|
42
45
|
/**
|
|
@@ -77,6 +80,7 @@ export function itemChangeFeedPiece(brandId: string, source: ItemChangeFeedSourc
|
|
|
77
80
|
feed.addEnvironment("PAPYRUS_AGENT_PUBLICATION_ID", brandId);
|
|
78
81
|
feed.addEnvironment("PAPYRUS_TENANT_ID", source.tenantId);
|
|
79
82
|
feed.addEnvironment("PAPYRUS_SITE_BUCKET", source.bucketName);
|
|
83
|
+
setModelKeyParameter(feed, source.openAiKeyParameter);
|
|
80
84
|
feed.addToRolePolicy(
|
|
81
85
|
new PolicyStatement({
|
|
82
86
|
effect: Effect.ALLOW,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model key of a site's agent runs (PPY-8a374e, note on PPY-6af46b).
|
|
3
|
+
*
|
|
4
|
+
* A change feed (`item-change-feed.ts`, `change-feeds.ts`) puts one wake on the site's wake queue for each agent that listens for a change, and the wake
|
|
5
|
+
* carries `openaiKeyParameter`, the NAME of the SSM parameter the run reads its model key from (`item_change_feed.Site`, `procedure_runner.validate_request`).
|
|
6
|
+
* The runner (the shared `papyrus-procedure-runner` Lambda, `infra/procedures/papyrus-procedure-runner.yaml`) is the one that reads the parameter, with its own role:
|
|
7
|
+
* a feed never reads, prints or stores the key, and holds no right to it. With no name set, a feed's wakes carry none and the run fails closed with
|
|
8
|
+
* `The run has no model key`: there is no fallback key.
|
|
9
|
+
*
|
|
10
|
+
* The name is a site setting, `agents.openAiKeyParameter` in the site's backend configuration (`PapyrusAgentsConfig`). A name is not a secret.
|
|
11
|
+
*/
|
|
12
|
+
export const MODEL_KEY_PARAMETER_ENV = "PAPYRUS_OPENAI_KEY_PARAMETER";
|
|
13
|
+
/** Names the model key's SSM parameter on a feed function, when the site sets one. Adds no resource and no permission. */
|
|
14
|
+
export function setModelKeyParameter(feed, parameterName) {
|
|
15
|
+
if (parameterName !== undefined)
|
|
16
|
+
feed.addEnvironment(MODEL_KEY_PARAMETER_ENV, parameterName);
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Function as LambdaFunction } from "aws-cdk-lib/aws-lambda";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The model key of a site's agent runs (PPY-8a374e, note on PPY-6af46b).
|
|
5
|
+
*
|
|
6
|
+
* A change feed (`item-change-feed.ts`, `change-feeds.ts`) puts one wake on the site's wake queue for each agent that listens for a change, and the wake
|
|
7
|
+
* carries `openaiKeyParameter`, the NAME of the SSM parameter the run reads its model key from (`item_change_feed.Site`, `procedure_runner.validate_request`).
|
|
8
|
+
* The runner (the shared `papyrus-procedure-runner` Lambda, `infra/procedures/papyrus-procedure-runner.yaml`) is the one that reads the parameter, with its own role:
|
|
9
|
+
* a feed never reads, prints or stores the key, and holds no right to it. With no name set, a feed's wakes carry none and the run fails closed with
|
|
10
|
+
* `The run has no model key`: there is no fallback key.
|
|
11
|
+
*
|
|
12
|
+
* The name is a site setting, `agents.openAiKeyParameter` in the site's backend configuration (`PapyrusAgentsConfig`). A name is not a secret.
|
|
13
|
+
*/
|
|
14
|
+
export const MODEL_KEY_PARAMETER_ENV = "PAPYRUS_OPENAI_KEY_PARAMETER";
|
|
15
|
+
|
|
16
|
+
/** Names the model key's SSM parameter on a feed function, when the site sets one. Adds no resource and no permission. */
|
|
17
|
+
export function setModelKeyParameter(feed: LambdaFunction, parameterName: string | undefined): void {
|
|
18
|
+
if (parameterName !== undefined) feed.addEnvironment(MODEL_KEY_PARAMETER_ENV, parameterName);
|
|
19
|
+
}
|
|
@@ -2,6 +2,25 @@ import { isSharedTier } from "./shared-stack/names.js";
|
|
|
2
2
|
export const MAXIMUM_HTML_S_MAXAGE_SECONDS = 86400;
|
|
3
3
|
/** The live lifetime is a few seconds by intent; a larger value is `htmlSMaxAgeSeconds` with extra steps. */
|
|
4
4
|
export const MAXIMUM_LIVE_S_MAXAGE_SECONDS = 60;
|
|
5
|
+
/** The same pattern the runner holds a request's parameter name to (`procedure_runner.SSM_PARAMETER`), and no trailing slash: a name, not a path. */
|
|
6
|
+
const AGENT_KEY_PARAMETER_PATTERN = /^\/[A-Za-z0-9_.\/-]{0,998}[A-Za-z0-9_.-]$/;
|
|
7
|
+
export function validateAgentsConfig(agents) {
|
|
8
|
+
if (agents === undefined)
|
|
9
|
+
return [];
|
|
10
|
+
if (typeof agents !== "object" || agents === null || Array.isArray(agents))
|
|
11
|
+
return ["agents must be an object"];
|
|
12
|
+
const config = agents;
|
|
13
|
+
if (config.openAiKeyParameter !== undefined
|
|
14
|
+
&& (typeof config.openAiKeyParameter !== "string" || !AGENT_KEY_PARAMETER_PATTERN.test(config.openAiKeyParameter))) {
|
|
15
|
+
return ["agents.openAiKeyParameter must be an SSM parameter name that starts with '/' (for example /papyrus/shipped/openai-api-key), not a key"];
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
export function assertValidAgentsConfig(agents) {
|
|
20
|
+
const problems = validateAgentsConfig(agents);
|
|
21
|
+
if (problems.length > 0)
|
|
22
|
+
throw new Error(`Invalid backend.agents: ${problems.join("; ")}`);
|
|
23
|
+
}
|
|
5
24
|
const MONITOR_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
6
25
|
export function validateMonitoringConfig(monitoring) {
|
|
7
26
|
if (monitoring === undefined)
|
|
@@ -66,6 +66,38 @@ export type PapyrusMonitoringConfig = {
|
|
|
66
66
|
emailMonitorId?: string;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* The always-on agents of this site (docs/design/always-on-agents-architecture.md).
|
|
71
|
+
*/
|
|
72
|
+
export type PapyrusAgentsConfig = {
|
|
73
|
+
/**
|
|
74
|
+
* The NAME of the SSM SecureString parameter that holds the model (OpenAI) key for runs the site's change feeds start, for example
|
|
75
|
+
* `/papyrus/shipped/openai-api-key`. A name is not a secret: the key's value is never read, printed or stored by the deploy. The feeds put this name on each wake; the
|
|
76
|
+
* procedure runner reads the parameter with its own role, which names each parameter it may read in `infra/procedures/papyrus-procedure-runner.yaml`. Unset: a feed's runs
|
|
77
|
+
* carry no key and fail closed with "The run has no model key" (there is no fallback key).
|
|
78
|
+
*/
|
|
79
|
+
openAiKeyParameter?: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** The same pattern the runner holds a request's parameter name to (`procedure_runner.SSM_PARAMETER`), and no trailing slash: a name, not a path. */
|
|
83
|
+
const AGENT_KEY_PARAMETER_PATTERN = /^\/[A-Za-z0-9_.\/-]{0,998}[A-Za-z0-9_.-]$/;
|
|
84
|
+
|
|
85
|
+
export function validateAgentsConfig(agents: unknown): string[] {
|
|
86
|
+
if (agents === undefined) return [];
|
|
87
|
+
if (typeof agents !== "object" || agents === null || Array.isArray(agents)) return ["agents must be an object"];
|
|
88
|
+
const config = agents as { openAiKeyParameter?: unknown };
|
|
89
|
+
if (config.openAiKeyParameter !== undefined
|
|
90
|
+
&& (typeof config.openAiKeyParameter !== "string" || !AGENT_KEY_PARAMETER_PATTERN.test(config.openAiKeyParameter))) {
|
|
91
|
+
return ["agents.openAiKeyParameter must be an SSM parameter name that starts with '/' (for example /papyrus/shipped/openai-api-key), not a key"];
|
|
92
|
+
}
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function assertValidAgentsConfig(agents: unknown): void {
|
|
97
|
+
const problems = validateAgentsConfig(agents);
|
|
98
|
+
if (problems.length > 0) throw new Error(`Invalid backend.agents: ${problems.join("; ")}`);
|
|
99
|
+
}
|
|
100
|
+
|
|
69
101
|
const MONITOR_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,62}$/;
|
|
70
102
|
|
|
71
103
|
export function validateMonitoringConfig(monitoring: unknown): string[] {
|
|
@@ -282,6 +314,8 @@ export type PapyrusSiteBackendConfig = {
|
|
|
282
314
|
auth?: PapyrusAuthConfig;
|
|
283
315
|
/** Shared Monitoring partition used by private email intake for this publication. */
|
|
284
316
|
monitoring?: PapyrusMonitoringConfig;
|
|
317
|
+
/** The site's always-on agents: today the name of the SSM parameter holding the model key their runs use. */
|
|
318
|
+
agents?: PapyrusAgentsConfig;
|
|
285
319
|
/**
|
|
286
320
|
* Maximum number of data model nested stacks CloudFormation creates at once.
|
|
287
321
|
* Stacks are chained in waves of this size so a new AWS account is not hit
|
package/amplify/site-backend.js
CHANGED
|
@@ -15,7 +15,7 @@ import { planRenditions } from "./publication/renditions-settings.js";
|
|
|
15
15
|
import { addProjectionLeaseAccess } from "./publication/projection-lease.js";
|
|
16
16
|
import { contentActionsPublicationWiring, planS3ProjectionBackend } from "./publication/s3-projection-settings.js";
|
|
17
17
|
import { rebuildTriggerSettings } from "./rebuild-trigger-settings.js";
|
|
18
|
-
import { assertValidMonitoringConfig, assertValidPublicationConfig, assertValidTenancyConfig, resolveTenancyMode, tenancyFunctionEnvironment } from "./site-backend-config.js";
|
|
18
|
+
import { assertValidAgentsConfig, assertValidMonitoringConfig, assertValidPublicationConfig, assertValidTenancyConfig, resolveTenancyMode, tenancyFunctionEnvironment } from "./site-backend-config.js";
|
|
19
19
|
import { revalidateSecretReadStatement } from "./revalidate-secret-policy.js";
|
|
20
20
|
import { revalidateDistributionEnvironment, revalidateInvalidationStatement, validateRevalidateDistributionIds, } from "./revalidate-invalidation-settings.js";
|
|
21
21
|
import { enablePointInTimeRecoveryOnDataTables } from "./data-table-recovery.js";
|
|
@@ -122,6 +122,7 @@ export function defineSiteBackend(papyrusSite, options = {}) {
|
|
|
122
122
|
if (publication !== undefined)
|
|
123
123
|
assertValidPublicationConfig(publication);
|
|
124
124
|
assertValidMonitoringConfig(site.monitoring);
|
|
125
|
+
assertValidAgentsConfig(site.agents);
|
|
125
126
|
assertValidTenancyConfig(site.tenancy);
|
|
126
127
|
const tenancyMode = resolveTenancyMode(site.tenancy);
|
|
127
128
|
// A shared stack is one of two fixed tiers (docs/shared-stack.md). Its settings (reserved concurrency, alarm thresholds) come from
|
|
@@ -816,6 +817,7 @@ export function defineSiteBackend(papyrusSite, options = {}) {
|
|
|
816
817
|
tenantId: backendTenantId,
|
|
817
818
|
bucketName: storageBucket.bucketName,
|
|
818
819
|
bucketArn: storageBucket.bucketArn,
|
|
820
|
+
openAiKeyParameter: site.agents?.openAiKeyParameter,
|
|
819
821
|
},
|
|
820
822
|
changeFeeds: feedStreams === undefined
|
|
821
823
|
? undefined
|
|
@@ -827,6 +829,7 @@ export function defineSiteBackend(papyrusSite, options = {}) {
|
|
|
827
829
|
tenantId: backendTenantId,
|
|
828
830
|
bucketName: storageBucket.bucketName,
|
|
829
831
|
bucketArn: storageBucket.bucketArn,
|
|
832
|
+
openAiKeyParameter: site.agents?.openAiKeyParameter,
|
|
830
833
|
},
|
|
831
834
|
}), bootstrapStage);
|
|
832
835
|
// 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
|
package/amplify/site-backend.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { planRenditions } from "./publication/renditions-settings";
|
|
|
18
18
|
import { addProjectionLeaseAccess } from "./publication/projection-lease";
|
|
19
19
|
import { contentActionsPublicationWiring, planS3ProjectionBackend } from "./publication/s3-projection-settings";
|
|
20
20
|
import { rebuildTriggerSettings } from "./rebuild-trigger-settings";
|
|
21
|
-
import { assertValidMonitoringConfig, assertValidPublicationConfig, assertValidTenancyConfig, resolveTenancyMode, tenancyFunctionEnvironment } from "./site-backend-config";
|
|
21
|
+
import { assertValidAgentsConfig, assertValidMonitoringConfig, assertValidPublicationConfig, assertValidTenancyConfig, resolveTenancyMode, tenancyFunctionEnvironment } from "./site-backend-config";
|
|
22
22
|
import { revalidateSecretReadStatement } from "./revalidate-secret-policy";
|
|
23
23
|
import {
|
|
24
24
|
revalidateDistributionEnvironment,
|
|
@@ -152,6 +152,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite, options: DefineSiteB
|
|
|
152
152
|
const publication = resolveSitePublication(site, activeBrand?.renderer?.kind);
|
|
153
153
|
if (publication !== undefined) assertValidPublicationConfig(publication);
|
|
154
154
|
assertValidMonitoringConfig(site.monitoring);
|
|
155
|
+
assertValidAgentsConfig(site.agents);
|
|
155
156
|
assertValidTenancyConfig(site.tenancy);
|
|
156
157
|
const tenancyMode = resolveTenancyMode(site.tenancy);
|
|
157
158
|
// A shared stack is one of two fixed tiers (docs/shared-stack.md). Its settings (reserved concurrency, alarm thresholds) come from
|
|
@@ -977,6 +978,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite, options: DefineSiteB
|
|
|
977
978
|
tenantId: backendTenantId,
|
|
978
979
|
bucketName: storageBucket.bucketName,
|
|
979
980
|
bucketArn: storageBucket.bucketArn,
|
|
981
|
+
openAiKeyParameter: site.agents?.openAiKeyParameter,
|
|
980
982
|
},
|
|
981
983
|
changeFeeds:
|
|
982
984
|
feedStreams === undefined
|
|
@@ -989,6 +991,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite, options: DefineSiteB
|
|
|
989
991
|
tenantId: backendTenantId,
|
|
990
992
|
bucketName: storageBucket.bucketName,
|
|
991
993
|
bucketArn: storageBucket.bucketArn,
|
|
994
|
+
openAiKeyParameter: site.agents?.openAiKeyParameter,
|
|
992
995
|
},
|
|
993
996
|
}),
|
|
994
997
|
bootstrapStage,
|
package/package.json
CHANGED
package/routes.manifest.json
CHANGED