Skip to content

Commit d6c5006

Browse files
committed
chore: wip
1 parent 36cb880 commit d6c5006

File tree

3 files changed

+27
-56
lines changed

3 files changed

+27
-56
lines changed

storage/framework/core/cloud/src/cloud/ai.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface AiStackProps extends NestedCloudProps {
99

1010
export class AiStack {
1111
askAiUrl: lambda.FunctionUrl
12+
summarizeAiUrl: lambda.FunctionUrl
1213

1314
constructor(scope: Construct, props: AiStackProps) {
1415
// Define the Lambda Layer for aws-sdk
@@ -66,51 +67,20 @@ export class AiStack {
6667
timeout: Duration.seconds(30),
6768
})
6869

69-
const summarizeAiUrl = new lambda.FunctionUrl(scope, 'SummarizeAiFunctionUrl', {
70+
this.summarizeAiUrl = new lambda.FunctionUrl(scope, 'SummarizeAiFunctionUrl', {
7071
function: summarizeAi,
7172
authType: lambda.FunctionUrlAuthType.NONE,
7273
cors: {
7374
allowedOrigins: ['*'],
7475
},
7576
})
7677

77-
// const api = new RestApi(scope, 'AiRestApi', {
78-
// restApiName: `${props.slug}-${props.appEnv}-ai`,
79-
// description: 'Stacks AI API',
80-
// defaultCorsPreflightOptions: {
81-
// allowOrigins: Cors.ALL_ORIGINS,
82-
// allowMethods: Cors.ALL_METHODS,
83-
// },
84-
// })
85-
86-
// const askResource = api.root.addResource('ask')
87-
// const askIntegration = new LambdaIntegration(askAi)
88-
// askResource.addMethod('POST', askIntegration, {
89-
// operationName: 'Stacks AI Ask',
90-
// authorizationType: AuthorizationType.NONE,
91-
// })
92-
93-
// alias to ask
94-
// const promptResource = api.root.addResource('prompt')
95-
// const promptIntegration = new LambdaIntegration(askAi)
96-
// promptResource.addMethod('POST', promptIntegration, {
97-
// operationName: 'Stacks AI Ask',
98-
// authorizationType: AuthorizationType.NONE,
99-
// })
100-
101-
// const summarizeResource = api.root.addResource('summarize')
102-
// const summarizeIntegration = new LambdaIntegration(summarizeAi)
103-
// summarizeResource.addMethod('POST', summarizeIntegration, {
104-
// operationName: 'Stacks AI Summarize',
105-
// authorizationType: AuthorizationType.NONE,
106-
// })
107-
10878
new Output(scope, 'AiVanityAskApiUrl', {
10979
value: this.askAiUrl.url,
11080
})
11181

11282
new Output(scope, 'AiVanitySummarizeApiUrl', {
113-
value: summarizeAiUrl.url,
83+
value: this.summarizeAiUrl.url,
11484
})
11585

11686
new Output(scope, 'AiAskApiUrl', {

storage/framework/core/cloud/src/cloud/cdn.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface CdnStackProps extends NestedCloudProps {
2020
webServerUrl: lambda.FunctionUrl
2121
cliSetupUrl: lambda.FunctionUrl
2222
askAiUrl: lambda.FunctionUrl
23+
summarizeAiUrl: lambda.FunctionUrl
2324
}
2425

2526
export class CdnStack {
@@ -244,40 +245,39 @@ export class CdnStack {
244245

245246
aiBehaviorOptions(scope: Construct, props: CdnStackProps): Record<string, cloudfront.BehaviorOptions> {
246247
const hostname = Fn.select(2, Fn.split('/', props.askAiUrl.url))
248+
const summaryHostname = Fn.select(2, Fn.split('/', props.summarizeAiUrl.url))
249+
250+
const aiCachePolicy = new cloudfront.CachePolicy(scope, 'AiCachePolicy', {
251+
comment: 'Stacks AI Cache Policy',
252+
cachePolicyName: `${this.props.slug}-${this.props.appEnv}-ai-cache-policy`,
253+
defaultTtl: Duration.seconds(0),
254+
// minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
255+
cookieBehavior: cloudfront.CacheCookieBehavior.none(),
256+
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Accept', 'x-api-key', 'Authorization', 'Content-Type'),
257+
queryStringBehavior: cloudfront.CacheQueryStringBehavior.all(),
258+
})
259+
247260
return {
248261
'/ai/ask': {
249-
// origin: new origins.HttpOrigin('9qp44a2b7e.execute-api.us-east-1.amazonaws.com', {
250262
origin: new origins.HttpOrigin(hostname, {
251263
originPath: '/ai',
252264
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
253265
}),
254266
compress: false,
255267
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
256268
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
257-
cachePolicy: new cloudfront.CachePolicy(scope, 'AiCachePolicy', {
258-
comment: 'Stacks AI Cache Policy',
259-
cachePolicyName: `${this.props.slug}-${this.props.appEnv}-ai-cache-policy`,
260-
defaultTtl: Duration.seconds(0),
261-
// minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
262-
cookieBehavior: cloudfront.CacheCookieBehavior.none(),
263-
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Accept', 'x-api-key', 'Authorization', 'Content-Type'),
264-
queryStringBehavior: cloudfront.CacheQueryStringBehavior.all(),
269+
cachePolicy: aiCachePolicy,
270+
},
271+
'/ai/summary': {
272+
origin: new origins.HttpOrigin(summaryHostname, {
273+
originPath: '/ai',
274+
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
265275
}),
276+
compress: false,
277+
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
278+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
279+
cachePolicy: aiCachePolicy,
266280
},
267-
// '/ai/ask/*': {
268-
// origin,
269-
// compress: false,
270-
// allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
271-
// viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
272-
// cachePolicy: this.setApiCachePolicy(scope),
273-
// },
274-
// '/ai/summary': {
275-
// origin,
276-
// compress: false,
277-
// allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
278-
// viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
279-
// cachePolicy: this.setApiCachePolicy(scope),
280-
// },
281281
}
282282
}
283283

storage/framework/core/cloud/src/cloud/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class Cloud extends Stack {
8686
webServerUrl: api.apiServerUrl,
8787
cliSetupUrl: cli.cliSetupUrl,
8888
askAiUrl: ai.askAiUrl,
89+
summarizeAiUrl: ai.summarizeAiUrl,
8990
})
9091

9192
new DeploymentStack(this, {

0 commit comments

Comments
 (0)