Skip to content

Commit be1d216

Browse files
Initial analysis and plan for fixing workflow API and UI build errors
Co-authored-by: Gerome-Elassaad <186273274+Gerome-Elassaad@users.noreply.github.com>
1 parent 6304e4c commit be1d216

File tree

9 files changed

+94
-44
lines changed

9 files changed

+94
-44
lines changed

app/api/chat/codeInterpreter.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import 'server-only';
2-
3-
import { Sandbox } from '@e2b/code-interpreter';
4-
1+
import 'server-only';
2+
3+
import { Sandbox } from '@e2b/code-interpreter';
4+
55
const E2B_API_KEY = process.env.E2B_API_KEY;
6-
if (!E2B_API_KEY) {
7-
throw new Error('E2B_API_KEY environment variable not found');
8-
}
96

107
const sandboxTimeout = 10 * 60 * 1000;
118

12-
export async function evaluateCode(
13-
sessionID: string,
14-
code: string,
15-
) {
9+
export async function evaluateCode(
10+
sessionID: string,
11+
code: string,
12+
) {
13+
if (!E2B_API_KEY) {
14+
throw new Error('E2B_API_KEY environment variable not found');
15+
}
16+
1617
const sandbox = await getSandbox(sessionID);
1718

1819
// Execute the code in a Jupyter Notebook in the sandbox.
@@ -34,7 +35,11 @@ export async function evaluateCode(
3435
}
3536

3637

37-
async function getSandbox(sessionID: string) {
38+
async function getSandbox(sessionID: string) {
39+
if (!E2B_API_KEY) {
40+
throw new Error('E2B_API_KEY environment variable not found');
41+
}
42+
3843
const sandboxes = await Sandbox.list();
3944

4045
const sandboxID = sandboxes.find(sandbox => sandbox.metadata?.sessionID === sessionID)?.sandboxId;

app/api/files/content/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { NextResponse } from 'next/server'
22
import { Sandbox } from '@e2b/code-interpreter'
33

44
const E2B_API_KEY = process.env.E2B_API_KEY
5-
if (!E2B_API_KEY) {
6-
throw new Error('E2B_API_KEY environment variable not found')
7-
}
85

96
const sandboxTimeout = 10 * 60 * 1000
107

@@ -22,6 +19,13 @@ async function getSandbox(sessionID: string, template?: string) {
2219

2320
export async function GET(req: Request) {
2421
try {
22+
if (!E2B_API_KEY) {
23+
return NextResponse.json(
24+
{ error: 'E2B_API_KEY environment variable not found' },
25+
{ status: 500 },
26+
)
27+
}
28+
2529
const { searchParams } = new URL(req.url)
2630
const sessionID = searchParams.get('sessionID')
2731
const path = searchParams.get('path')

app/api/files/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ async function listFilesRecursively(
2929
}
3030

3131
const E2B_API_KEY = process.env.E2B_API_KEY
32-
if (!E2B_API_KEY) {
33-
throw new Error('E2B_API_KEY environment variable not found')
34-
}
3532

3633
const sandboxTimeout = 10 * 60 * 1000
3734

3835
async function getSandbox(sessionID: string, template?: string) {
36+
if (!E2B_API_KEY) {
37+
throw new Error('E2B_API_KEY environment variable not found')
38+
}
39+
3940
const sandbox = await Sandbox.create(template || 'code-interpreter-v1', {
4041
apiKey: E2B_API_KEY,
4142
metadata: {

app/api/files/sandbox/list/route.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,28 @@ async function listFilesRecursively(
2929
}
3030

3131
const E2B_API_KEY = process.env.E2B_API_KEY
32-
if (!E2B_API_KEY) {
33-
throw new Error('E2B_API_KEY environment variable not found')
34-
}
3532

3633
const sandboxTimeout = 10 * 60 * 1000
3734

3835
export async function GET(request: NextRequest) {
39-
const searchParams = request.nextUrl.searchParams
40-
const sandboxId = searchParams.get('sandboxId')
36+
try {
37+
if (!E2B_API_KEY) {
38+
return NextResponse.json(
39+
{ error: 'E2B_API_KEY environment variable not found' },
40+
{ status: 500 },
41+
)
42+
}
4143

42-
if (!sandboxId) {
43-
return NextResponse.json(
44-
{ error: 'sandboxId is required' },
45-
{ status: 400 },
46-
)
47-
}
44+
const searchParams = request.nextUrl.searchParams
45+
const sandboxId = searchParams.get('sandboxId')
46+
47+
if (!sandboxId) {
48+
return NextResponse.json(
49+
{ error: 'sandboxId is required' },
50+
{ status: 400 },
51+
)
52+
}
4853

49-
try {
5054
// Connect to existing sandbox by ID
5155
const sandbox = await Sandbox.connect(sandboxId, {
5256
apiKey: E2B_API_KEY,

app/api/files/sandbox/route.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import { NextResponse } from 'next/server'
22
import { Sandbox } from '@e2b/code-interpreter'
33

44
const E2B_API_KEY = process.env.E2B_API_KEY
5-
if (!E2B_API_KEY) {
6-
throw new Error('E2B_API_KEY environment variable not found')
7-
}
85

96
const sandboxTimeout = 10 * 60 * 1000
107

118
export async function GET(req: Request) {
129
try {
10+
if (!E2B_API_KEY) {
11+
return NextResponse.json(
12+
{ error: 'E2B_API_KEY environment variable not found' },
13+
{ status: 500 },
14+
)
15+
}
16+
1317
const { searchParams } = new URL(req.url)
1418
const sandboxId = searchParams.get('sandboxId')
1519
const path = searchParams.get('path')

app/api/import-dataset/route.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ const DATASET = 'bigcode/the-stack';
77
const EMBEDDING_MODEL = 'Xenova/all-MiniLM-L6-v2';
88
const HUGGING_FACE_API_URL = 'https://huggingface.co/api/datasets';
99

10-
// Initialize Supabase client with the service role key for admin access
11-
const supabase = createClient(
12-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
13-
process.env.SUPABASE_SERVICE_ROLE_KEY!
14-
);
10+
// Initialize Supabase client with the service role key for admin access
11+
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
12+
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
13+
14+
// Check if Supabase is configured
15+
let supabase: any = null
16+
if (supabaseUrl && supabaseServiceKey) {
17+
supabase = createClient(supabaseUrl, supabaseServiceKey)
18+
} else {
19+
console.warn('Supabase configuration is incomplete. Import dataset feature is disabled.')
20+
}
1521

1622
// Function to process and embed a single file's content
1723
async function processAndEmbedFile(content: string, embeddingPipeline: any) {
@@ -80,8 +86,15 @@ async function importDataset(subset: string) {
8086
}
8187

8288
// The API Route Handler
83-
export async function POST(request: Request) {
84-
try {
89+
export async function POST(request: Request) {
90+
try {
91+
if (!supabase) {
92+
return NextResponse.json(
93+
{ error: 'Supabase is not configured. Import dataset feature is disabled.' },
94+
{ status: 503 }
95+
)
96+
}
97+
8598
const { subset } = await request.json();
8699

87100
if (!subset) {

app/deployments/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import {
2424
} from 'lucide-react'
2525
import { toast } from '@/components/ui/use-toast'
2626
import { useAuth } from '@/lib/auth'
27+
import { ViewType } from '@/components/auth'
2728

2829
export default function DeploymentsPage() {
29-
const { session } = useAuth(() => {}, () => {})
30+
const [authDialog, setAuthDialog] = useState(false)
31+
const [authView, setAuthView] = useState<ViewType>('sign_in')
32+
const { session } = useAuth(setAuthDialog, setAuthView)
3033
const [deployments, setDeployments] = useState<DeploymentResult[]>([])
3134
const [activeDeployments, setActiveDeployments] = useState<DeploymentStatus[]>([])
3235
const [selectedFragment, setSelectedFragment] = useState<FragmentSchema | null>(null)

app/workflows/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import { WorkflowSchema } from '@/lib/workflow-engine'
1111
import { Plus, Search, Play, Edit, Trash2, Copy, GitBranch } from 'lucide-react'
1212
import { toast } from '@/components/ui/use-toast'
1313
import { useAuth } from '@/lib/auth'
14+
import { ViewType } from '@/components/auth'
1415

1516
export default function WorkflowsPage() {
16-
const { session } = useAuth(() => {}, () => {})
17+
const [authDialog, setAuthDialog] = useState(false)
18+
const [authView, setAuthView] = useState<ViewType>('sign_in')
19+
const { session } = useAuth(setAuthDialog, setAuthView)
1720
const [workflows, setWorkflows] = useState<WorkflowSchema[]>([])
1821
const [selectedWorkflow, setSelectedWorkflow] = useState<WorkflowSchema | null>(null)
1922
const [searchTerm, setSearchTerm] = useState('')

lib/workflow-persistence.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,23 @@ export class WorkflowPersistence {
127127

128128
constructor() {
129129
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
130-
const supabaseServiceKey = process.env.NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY
130+
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
131131

132132
if (!supabaseUrl || !supabaseServiceKey) {
133-
throw new Error('Supabase URL and service key are required.')
133+
console.warn('Supabase configuration is incomplete. Some features may not work.')
134+
// Create a mock client to prevent build errors
135+
this.supabase = {
136+
from: () => ({
137+
select: () => ({ single: () => Promise.resolve({ data: null, error: new Error('Supabase not configured') }) }),
138+
insert: () => ({ select: () => ({ single: () => Promise.resolve({ data: null, error: new Error('Supabase not configured') }) }) }),
139+
update: () => ({ eq: () => ({ select: () => ({ single: () => Promise.resolve({ data: null, error: new Error('Supabase not configured') }) }) }) }),
140+
delete: () => ({ eq: () => Promise.resolve({ error: new Error('Supabase not configured') }) }),
141+
eq: () => ({ single: () => Promise.resolve({ data: null, error: new Error('Supabase not configured') }) }),
142+
order: () => ({ range: () => Promise.resolve({ data: [], error: new Error('Supabase not configured'), count: 0 }) }),
143+
range: () => Promise.resolve({ data: [], error: new Error('Supabase not configured'), count: 0 })
144+
})
145+
} as any
146+
return
134147
}
135148
this.supabase = createClient<Database>(supabaseUrl, supabaseServiceKey)
136149
}

0 commit comments

Comments
 (0)