forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-helper.ts
More file actions
117 lines (97 loc) · 2.75 KB
/
Copy pathconfig-helper.ts
File metadata and controls
117 lines (97 loc) · 2.75 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// lib/config-helper.ts
import configs from "../app-configs.json";
// Project name constants with type safety
export const PROJECT_NAMES = {
COAGENTS_RESEARCH_CANVAS: "coagents-research-canvas",
COAGENTS_QA_NATIVE: "coagents-qa-native",
COAGENTS_QA_TEXT: "coagents-qa-text",
COAGENTS_ROUTING: "coagents-routing",
COPILOTKIT_NEXT_OPENAI: "next-openai",
} as const;
export type ProjectName = (typeof PROJECT_NAMES)[keyof typeof PROJECT_NAMES];
export interface ConfigItem {
url: string;
description: string;
projectName: ProjectName;
lgcPythonDeploymentUrl?: string;
lgcJSDeploymentUrl?: string;
key?: string;
}
export interface ConfigMap {
[key: string]: ConfigItem;
}
export interface TestVariant {
name: string;
queryParams: string;
isCloud?: boolean;
}
export type TestVariants = TestVariant[];
/**
* Returns raw config map
*/
export const getConfigs = (): ConfigMap => {
return configs as ConfigMap;
};
/**
* Groups configuration items by project name and description
*/
export const groupConfigsByDescription = (
configs: ConfigMap
): Record<ProjectName, Record<string, ConfigItem[]>> => {
return Object.entries(configs).reduce((acc, [key, value]) => {
const { projectName, description } = value;
if (!acc[projectName]) {
acc[projectName] = {};
}
if (!acc[projectName][description]) {
acc[projectName][description] = [];
}
acc[projectName][description].push({ ...value, key });
return acc;
}, {} as Record<ProjectName, Record<string, ConfigItem[]>>);
};
/**
* Filter configs by project name
*/
export const filterConfigsByProject = (
configs: ConfigMap,
projectName: ProjectName
): ConfigMap => {
return Object.entries(configs).reduce((acc, [key, value]) => {
if (value.projectName === projectName) {
acc[key] = value;
}
return acc;
}, {} as ConfigMap);
};
export const appendLGCVariants = (
config: ConfigItem,
variants: any[],
skipLGC: boolean = false
) => {
let appendedVariants = [...variants];
if (skipLGC) {
return appendedVariants;
}
if (config.lgcPythonDeploymentUrl) {
const newVariants = variants.map((variant) => {
return {
...variant,
name: `${variant.name} (LGC Python)`,
queryParams: `${variant.queryParams}&lgcDeploymentUrl=${config.lgcPythonDeploymentUrl}`,
};
});
appendedVariants = [...appendedVariants, ...newVariants];
}
if (config.lgcJSDeploymentUrl) {
const newVariants = variants.map((variant) => {
return {
...variant,
name: `${variant.name} (LGC JS)`,
queryParams: `${variant.queryParams}&lgcDeploymentUrl=${config.lgcJSDeploymentUrl}`,
};
});
appendedVariants = [...appendedVariants, ...newVariants];
}
return appendedVariants;
};