Fix vercel (#241)

* use static imports for prebuilt cards

* fixed s3 env variables
This commit is contained in:
arkml 2025-09-11 21:39:47 +05:30 committed by GitHub
parent 5efdee18eb
commit ad7a0d313b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 53 deletions

View file

@ -1,19 +1,13 @@
import { WorkflowTemplate } from "./types/workflow_types";
import { z } from 'zod';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { prebuiltTemplates } from './prebuilt-cards';
const DEFAULT_MODEL = process.env.PROVIDER_DEFAULT_MODEL || "gpt-4.1";
// Function to load prebuilt cards from JSON files
function loadTemplatesFromFiles(): { [key: string]: z.infer<typeof WorkflowTemplate> } {
const templatesDir = path.join(__dirname, 'prebuilt-cards');
// Build templates object using static imports so Vercel bundles them
function buildTemplates(): { [key: string]: z.infer<typeof WorkflowTemplate> } {
const templates: { [key: string]: z.infer<typeof WorkflowTemplate> } = {};
// Add default template
templates['default'] = {
name: 'Blank Template',
@ -51,41 +45,19 @@ function loadTemplatesFromFiles(): { [key: string]: z.infer<typeof WorkflowTempl
},
],
};
try {
// Check if prebuilt cards directory exists
if (fs.existsSync(templatesDir)) {
const files = fs.readdirSync(templatesDir);
// Load each JSON file
files.forEach(file => {
if (path.extname(file) === '.json') {
try {
const filePath = path.join(templatesDir, file);
const fileContent = fs.readFileSync(filePath, 'utf-8');
const templateData = JSON.parse(fileContent);
// Use filename without extension as template key
const templateKey = path.basename(file, '.json');
// Validate template structure (optional - you can add more validation)
if (templateData.agents && Array.isArray(templateData.agents)) {
templates[templateKey] = templateData;
}
} catch (error) {
console.warn(`Failed to load prebuilt card ${file}:`, error);
}
}
});
// Merge static prebuilt templates
Object.entries(prebuiltTemplates).forEach(([key, tpl]) => {
// Basic guard to avoid bad entries
if ((tpl as any)?.agents && Array.isArray((tpl as any).agents)) {
templates[key] = tpl as z.infer<typeof WorkflowTemplate>;
}
} catch (error) {
console.warn('Failed to load prebuilt cards from directory:', error);
}
});
return templates;
}
export const templates: { [key: string]: z.infer<typeof WorkflowTemplate> } = loadTemplatesFromFiles();
export const templates: { [key: string]: z.infer<typeof WorkflowTemplate> } = buildTemplates();
// Note: Prebuilt cards are now loaded from app/lib/prebuilt-cards/ directory
// starting_copilot_prompts has been removed as it was unused