Skip to content

Commit 149cb94

Browse files
Merge pull request Gerome-Elassaad#27 from Gerome-Elassaad/copilot/fix-26
Fix workflow API file errors and UI build issues
2 parents 5ff987f + ab30d00 commit 149cb94

File tree

14 files changed

+218
-114
lines changed

14 files changed

+218
-114
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/deployments/[id]/rollback/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function POST(
1010
{ params }: { params: { id: string } }
1111
) {
1212
try {
13-
const supabase = createServerClient()
13+
const supabase = createServerClient(true)
1414
const { data: { session } } = await supabase.auth.getSession()
1515

1616
if (!session?.user?.id) {

app/api/deployments/[id]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function GET(
1010
{ params }: { params: { id: string } }
1111
) {
1212
try {
13-
const supabase = createServerClient()
13+
const supabase = createServerClient(true)
1414
const { data: { session } } = await supabase.auth.getSession()
1515

1616
if (!session?.user?.id) {
@@ -42,7 +42,7 @@ export async function DELETE(
4242
{ params }: { params: { id: string } }
4343
) {
4444
try {
45-
const supabase = createServerClient()
45+
const supabase = createServerClient(true)
4646
const { data: { session } } = await supabase.auth.getSession()
4747

4848
if (!session?.user?.id) {

app/api/deployments/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const dynamic = 'force-dynamic'
88
// POST /api/deployments - Deploy fragment
99
export async function POST(request: NextRequest) {
1010
try {
11-
const supabase = createServerClient()
11+
const supabase = createServerClient(true)
1212
const { data: { session } } = await supabase.auth.getSession()
1313

1414
if (!session?.user?.id) {
@@ -50,7 +50,7 @@ export async function POST(request: NextRequest) {
5050
// GET /api/deployments - List deployments
5151
export async function GET(request: NextRequest) {
5252
try {
53-
const supabase = createServerClient()
53+
const supabase = createServerClient(true)
5454
const { data: { session } } = await supabase.auth.getSession()
5555

5656
if (!session?.user?.id) {

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: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,27 @@ 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')
41-
42-
if (!sandboxId) {
36+
if (!E2B_API_KEY) {
4337
return NextResponse.json(
44-
{ error: 'sandboxId is required' },
45-
{ status: 400 },
38+
{ error: 'E2B_API_KEY environment variable not found' },
39+
{ status: 500 },
4640
)
4741
}
48-
4942
try {
43+
const searchParams = request.nextUrl.searchParams
44+
const sandboxId = searchParams.get('sandboxId')
45+
46+
if (!sandboxId) {
47+
return NextResponse.json(
48+
{ error: 'sandboxId is required' },
49+
{ status: 400 },
50+
)
51+
}
52+
5053
// Connect to existing sandbox by ID
5154
const sandbox = await Sandbox.connect(sandboxId, {
5255
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)

0 commit comments

Comments
 (0)