forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-integration-features.mjs
More file actions
124 lines (104 loc) · 4.03 KB
/
Copy pathgenerate-integration-features.mjs
File metadata and controls
124 lines (104 loc) · 4.03 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
118
119
120
121
122
123
124
#!/usr/bin/env node
/**
* Auto-generates integration feature mappings by scanning the filesystem.
*
* This script scans content/docs/integrations/ to detect which integrations
* have which feature pages (e.g., shared-state, generative-ui, etc.) and
* generates lib/integration-features.ts with type-safe mappings.
*
* Runs automatically:
* - Before every `pnpm dev` (via predev script)
* - Before every `pnpm build` (via prebuild script)
* - Manually via `pnpm generate`
*
* To add a feature to an integration, just create the directory/file:
* mkdir content/docs/integrations/my-framework/shared-state
* # Next build will auto-detect it!
*
* See docs/README.md for full documentation.
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const docsRoot = path.resolve(__dirname, '..');
const integrationsDir = path.join(docsRoot, 'content/docs/integrations');
// Features to check for (can be either directories or .mdx files)
// For each feature, we check for BOTH:
// 1. A directory with that name (e.g., shared-state/)
// 2. A file with that name (e.g., frontend-actions.mdx)
// The route is the same either way: /integration/feature-name
const FEATURES = [
'shared-state',
'generative-ui',
'generative-ui/render-only',
'generative-ui/tool-rendering',
'generative-ui/state-rendering',
'generative-ui/mcp-apps',
'generative-ui/a2ui',
'frontend-actions',
'human-in-the-loop',
'agentic-chat-ui',
'custom-look-and-feel',
];
// Valid integration IDs — must match INTEGRATION_ORDER in lib/integrations.ts
const VALID_INTEGRATIONS = new Set([
'direct-to-llm', 'langgraph', 'deepagents', 'adk', 'microsoft-agent-framework',
'aws-strands', 'mastra', 'pydantic-ai', 'crewai-flows', 'agno',
'ag2', 'agent-spec', 'llamaindex', 'a2a',
]);
function getIntegrations() {
return fs.readdirSync(integrationsDir, { withFileTypes: true })
.filter(dirent => dirent.isDirectory() && VALID_INTEGRATIONS.has(dirent.name))
.map(dirent => dirent.name);
}
function hasFeature(integrationId, featureName) {
const integrationPath = path.join(integrationsDir, integrationId);
// Check for directory (e.g., shared-state/)
const featureDir = path.join(integrationPath, featureName);
if (fs.existsSync(featureDir) && fs.statSync(featureDir).isDirectory()) {
return true;
}
// Check for file (e.g., frontend-actions.mdx)
const featureFile = path.join(integrationPath, `${featureName}.mdx`);
if (fs.existsSync(featureFile)) {
return true;
}
return false;
}
function generateFeatureMap() {
const integrations = getIntegrations();
const featureMap = {};
// For each feature, list which integrations have it
for (const featureName of FEATURES) {
featureMap[featureName] = integrations.filter(id =>
hasFeature(id, featureName)
);
}
return featureMap;
}
function main() {
const featureMap = generateFeatureMap();
const output = `// Auto-generated by scripts/generate-integration-features.mjs
// Do not edit manually - run: node scripts/generate-integration-features.mjs
import { IntegrationId } from './integrations';
/**
* Maps feature names to the list of integration IDs that have that feature.
* This is auto-generated at build time by scanning the content/docs/integrations directory.
*/
export const INTEGRATION_FEATURES: Record<string, IntegrationId[]> = ${JSON.stringify(featureMap, null, 2)};
/**
* Check if an integration has a specific feature page.
*/
export function hasIntegrationFeature(integrationId: IntegrationId, feature: string): boolean {
return INTEGRATION_FEATURES[feature]?.includes(integrationId) ?? false;
}
`;
const outputPath = path.join(docsRoot, 'lib/integration-features.ts');
fs.writeFileSync(outputPath, output);
console.log('✓ Generated lib/integration-features.ts');
console.log(` Features mapped: ${Object.keys(featureMap).length}`);
console.log(` Integrations scanned: ${getIntegrations().length}`);
}
main();