Demon1212122 commited on
Commit
fb14972
Β·
1 Parent(s): 481c54b

chore: reapply local updates

Browse files
scripts/deploy-to-hf.ts ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { execSync } from 'child_process';
2
+ import * as dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+
6
+ async function deploy() {
7
+ console.log('πŸš€ Starting deployment to Hugging Face...');
8
+
9
+ try {
10
+ // Configure git
11
+ execSync('git config --global user.email "deploy@wbes.com"');
12
+ execSync('git config --global user.name "WBES Deploy"');
13
+
14
+ // Add Hugging Face remote if it doesn't exist
15
+ try {
16
+ execSync('git remote get-url hf');
17
+ } catch {
18
+ execSync('git remote add hf https://huggingface.co/spaces/wbes/executive-suites');
19
+ }
20
+
21
+ // Push to Hugging Face
22
+ execSync('git push hf main', { stdio: 'inherit' });
23
+ console.log('βœ… Deployment successful!');
24
+
25
+ } catch (error) {
26
+ console.error('❌ Deployment failed:', error);
27
+ process.exit(1);
28
+ }
29
+ }
30
+
31
+ deploy();
scripts/e2e-test.ts ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fetch from 'node-fetch';
2
+ import * as dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+
6
+ const API_URL = process.env.API_URL || 'http://localhost:3000';
7
+
8
+ interface User {
9
+ id: string;
10
+ email: string;
11
+ name: string;
12
+ }
13
+
14
+ interface Conversation {
15
+ id: string;
16
+ userId: string;
17
+ }
18
+
19
+ async function e2eTest() {
20
+ console.log('πŸ§ͺ Starting end-to-end tests...');
21
+
22
+ try {
23
+ // Health check
24
+ const healthResponse = await fetch(`${API_URL}/api/health`);
25
+ if (!healthResponse.ok) {
26
+ throw new Error('Health check failed');
27
+ }
28
+ console.log('βœ… Health check passed');
29
+
30
+ // Test user creation
31
+ const userResponse = await fetch(`${API_URL}/api/users`, {
32
+ method: 'POST',
33
+ headers: { 'Content-Type': 'application/json' },
34
+ body: JSON.stringify({
35
+ email: 'test@example.com',
36
+ name: 'Test User'
37
+ })
38
+ });
39
+ if (!userResponse.ok) {
40
+ throw new Error('User creation failed');
41
+ }
42
+ const user = await userResponse.json() as User;
43
+ console.log('βœ… User creation passed');
44
+
45
+ // Test conversation creation
46
+ const conversationResponse = await fetch(`${API_URL}/api/conversations`, {
47
+ method: 'POST',
48
+ headers: { 'Content-Type': 'application/json' },
49
+ body: JSON.stringify({
50
+ userId: user.id
51
+ })
52
+ });
53
+ if (!conversationResponse.ok) {
54
+ throw new Error('Conversation creation failed');
55
+ }
56
+ const conversation = await conversationResponse.json() as Conversation;
57
+ console.log('βœ… Conversation creation passed');
58
+
59
+ // Test message creation
60
+ const messageResponse = await fetch(`${API_URL}/api/messages`, {
61
+ method: 'POST',
62
+ headers: { 'Content-Type': 'application/json' },
63
+ body: JSON.stringify({
64
+ conversationId: conversation.id,
65
+ sender: 'user',
66
+ content: 'Hello, world!'
67
+ })
68
+ });
69
+ if (!messageResponse.ok) {
70
+ throw new Error('Message creation failed');
71
+ }
72
+ console.log('βœ… Message creation passed');
73
+
74
+ // Test RAG query
75
+ const ragResponse = await fetch(`${API_URL}/api/rag/query`, {
76
+ method: 'POST',
77
+ headers: { 'Content-Type': 'application/json' },
78
+ body: JSON.stringify({
79
+ query: 'What are your office hours?'
80
+ })
81
+ });
82
+ if (!ragResponse.ok) {
83
+ throw new Error('RAG query failed');
84
+ }
85
+ console.log('βœ… RAG query passed');
86
+
87
+ console.log('βœ… All end-to-end tests passed!');
88
+ } catch (error) {
89
+ console.error('❌ End-to-end test failed:', error);
90
+ process.exit(1);
91
+ }
92
+ }
93
+
94
+ e2eTest();
scripts/setup-hf-secrets.ts ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fetch from 'node-fetch';
2
+ import * as dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+
6
+ const HF_TOKEN = process.env.HUGGINGFACE_TOKEN;
7
+ const SPACE_ID = 'wbes/executive-suites';
8
+
9
+ interface Secret {
10
+ key: string;
11
+ value: string;
12
+ }
13
+
14
+ async function setupSecrets() {
15
+ console.log('πŸ” Setting up Hugging Face secrets...');
16
+
17
+ if (!HF_TOKEN) {
18
+ throw new Error('HUGGINGFACE_TOKEN not found in environment');
19
+ }
20
+
21
+ const secrets: Secret[] = [
22
+ { key: 'DATABASE_URL', value: process.env.DATABASE_URL || '' },
23
+ { key: 'NEXTAUTH_SECRET', value: process.env.NEXTAUTH_SECRET || '' },
24
+ { key: 'NEXTAUTH_URL', value: process.env.NEXTAUTH_URL || '' }
25
+ ];
26
+
27
+ try {
28
+ for (const secret of secrets) {
29
+ if (!secret.value) {
30
+ console.warn(`⚠️ Warning: ${secret.key} is empty`);
31
+ continue;
32
+ }
33
+
34
+ const response = await fetch(
35
+ `https://huggingface.co/api/spaces/${SPACE_ID}/secrets/${secret.key}`,
36
+ {
37
+ method: 'PUT',
38
+ headers: {
39
+ 'Authorization': `Bearer ${HF_TOKEN}`,
40
+ 'Content-Type': 'application/json'
41
+ },
42
+ body: JSON.stringify({ value: secret.value })
43
+ }
44
+ );
45
+
46
+ if (!response.ok) {
47
+ throw new Error(`Failed to set ${secret.key}: ${response.statusText}`);
48
+ }
49
+
50
+ console.log(`βœ… Set ${secret.key}`);
51
+ }
52
+
53
+ console.log('βœ… All secrets configured successfully!');
54
+ } catch (error) {
55
+ console.error('❌ Failed to set secrets:', error);
56
+ process.exit(1);
57
+ }
58
+ }
59
+
60
+ setupSecrets();
scripts/smoke-test.ts ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PrismaClient } from '@prisma/client';
2
+ import * as dotenv from 'dotenv';
3
+
4
+ dotenv.config();
5
+
6
+ const prisma = new PrismaClient();
7
+
8
+ async function smokeTest() {
9
+ console.log('πŸ§ͺ Starting smoke test...');
10
+
11
+ try {
12
+ // Test user
13
+ const user = await prisma.user.findFirst();
14
+ if (!user) {
15
+ throw new Error('User not found');
16
+ }
17
+ console.log('βœ… User verified:', user.email);
18
+
19
+ // Test session
20
+ const session = await prisma.session.findFirst();
21
+ if (!session) {
22
+ throw new Error('Session not found');
23
+ }
24
+ console.log('βœ… Session verified');
25
+
26
+ // Test conversation and message
27
+ const conversation = await prisma.conversation.findFirst({
28
+ include: { messages: true }
29
+ });
30
+ if (!conversation || !conversation.messages.length) {
31
+ throw new Error('Conversation or messages not found');
32
+ }
33
+ console.log('βœ… Conversation and messages verified');
34
+
35
+ // Test suggestion
36
+ const suggestion = await prisma.suggestion.findFirst();
37
+ if (!suggestion) {
38
+ throw new Error('Suggestion not found');
39
+ }
40
+ console.log('βœ… Suggestion verified');
41
+
42
+ console.log('βœ… All smoke tests passed!');
43
+ } catch (error) {
44
+ console.error('❌ Smoke test failed:', error);
45
+ process.exit(1);
46
+ } finally {
47
+ await prisma.$disconnect();
48
+ }
49
+ }
50
+
51
+ smokeTest();
scripts/test-db-connection.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { PrismaClient } from '@prisma/client';
2
+
3
+ async function testConnection() {
4
+ console.log('πŸ”„ Testing database connection...');
5
+
6
+ try {
7
+ const prisma = new PrismaClient();
8
+ await prisma.$connect();
9
+
10
+ // Test query
11
+ const userCount = await prisma.user.count();
12
+ console.log(`βœ… Database connection successful! Found ${userCount} users.`);
13
+
14
+ await prisma.$disconnect();
15
+ } catch (error) {
16
+ console.error('❌ Database connection failed:', error);
17
+ process.exit(1);
18
+ }
19
+ }
20
+
21
+ testConnection();