forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-config.ts
More file actions
48 lines (42 loc) · 1.27 KB
/
Copy pathruntime-config.ts
File metadata and controls
48 lines (42 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Runtime configuration loader for aws-exports.json.
// Used by the CopilotKit integration (components/chat/CopilotKit/) to resolve
// the CopilotKit runtime URL at startup.
export type AwsExportsConfig = {
authority?: string;
client_id?: string;
redirect_uri?: string;
post_logout_redirect_uri?: string;
response_type?: string;
scope?: string;
automaticSilentRenew?: boolean;
agentRuntimeArn?: string;
awsRegion?: string;
feedbackApiUrl?: string;
copilotKitRuntimeUrl?: string;
agentPattern?: string;
};
let configCache: AwsExportsConfig | null = null;
let configPromise: Promise<AwsExportsConfig | null> | null = null;
export async function loadAwsConfig(): Promise<AwsExportsConfig | null> {
if (configCache) {
return configCache;
}
if (configPromise) {
return configPromise;
}
configPromise = (async () => {
try {
const response = await fetch("/aws-exports.json");
if (!response.ok) {
throw new Error(`Failed to load aws-exports.json: ${response.status}`);
}
const config = (await response.json()) as AwsExportsConfig;
configCache = config;
return config;
} catch (error) {
console.error("Failed to load aws-exports.json:", error);
throw error;
}
})();
return configPromise;
}