Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Kaapi CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-and-build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run Linting
run: npm run lint

- name: Build the Project
run: npm run build
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This is a thin frontend UI for [Kaapi backend](https://github.com/ProjectTech4De
- [Installation](#installation)
- [Start frontend server](#start-frontend-server)
- [Available Scripts](#available-scripts)
- [Pre-commit Hooks](#pre-commit-hooks)
- [Deploying Release on EC2 with CD](#deploying-release-on-ec2-with-cd)
- [Learn More](#learn-more)

Expand Down Expand Up @@ -91,11 +92,41 @@ Visit `http://localhost:3000` to open the app.
## Available Scripts

```bash
npm install # Install dependencies
npm install # Install dependencies (also sets up pre-commit hooks via husky)
npm run dev # Run app in development mode
npm run build # Create optimized production build
npm run start # Start the production server
npm run lint # Run ESLint
npm run lint # Run ESLint on the entire project
npm test # Run tests
npm run test:coverage # Run tests with coverage report
```

---

## Pre-commit Hooks

This project uses [Husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/lint-staged/lint-staged) to enforce code quality before every commit.

### What runs on commit

- **ESLint** is executed on all staged `*.ts`, `*.tsx`, `*.js`, and `*.jsx` files. Any lint errors must be fixed before the commit is accepted.

### Setup

Hooks are installed automatically when you run:

```bash
npm install
```

This works because the `prepare` script in `package.json` runs `husky` after every install.

### Skipping the hook (not recommended)

If you need to bypass the hook in exceptional cases:

```bash
git commit --no-verify -m "your message"
```

---
Expand Down
4 changes: 2 additions & 2 deletions app/api/assistant/[assistant_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export async function GET(
}

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
} catch (error: unknown) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
8 changes: 4 additions & 4 deletions app/api/collections/[collection_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export async function GET(
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ success: false, error: error instanceof Error ? error.message : String(error), data: null },
{ status: 500 }
);
}
Expand Down Expand Up @@ -77,9 +77,9 @@ export async function DELETE(
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ success: false, error: error instanceof Error ? error.message : String(error), data: null },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/collections/jobs/[job_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export async function GET(
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ success: false, error: error instanceof Error ? error.message : String(error), data: null },
{ status: 500 }
);
}
Expand Down
8 changes: 4 additions & 4 deletions app/api/collections/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export async function GET(request: Request) {
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ success: false, error: error instanceof Error ? error.message : String(error), data: null },
{ status: 500 }
);
}
Expand Down Expand Up @@ -74,10 +74,10 @@ export async function POST(request: NextRequest) {
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/api/configs/[config_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function GET(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch config', data: null },
{ status: 500 }
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function PATCH(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to update config', data: null },
{ status: 500 }
Expand All @@ -73,7 +73,7 @@ export async function DELETE(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to delete config', data: null },
{ status: 500 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function GET(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch version', data: null },
{ status: 500 }
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function DELETE(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to delete version', data: null },
{ status: 500 }
Expand Down
4 changes: 2 additions & 2 deletions app/api/configs/[config_id]/versions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function GET(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch versions', data: null },
{ status: 500 }
Expand Down Expand Up @@ -47,7 +47,7 @@ export async function POST(

const data = await response.json();
return NextResponse.json(data, { status: response.status });
} catch (error) {
} catch (_error) {
return NextResponse.json(
{ success: false, error: 'Failed to create version', data: null },
{ status: 500 }
Expand Down
8 changes: 4 additions & 4 deletions app/api/credentials/[provider]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export async function GET(
`/api/v1/credentials/provider/${provider}`,
);
return NextResponse.json(data, { status });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
}
}

Expand All @@ -33,7 +33,7 @@ export async function DELETE(
}

return NextResponse.json(data, { status });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
}
}
12 changes: 6 additions & 6 deletions app/api/credentials/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export async function GET(request: NextRequest) {
try {
const { status, data } = await apiClient(request, "/api/v1/credentials/");
return NextResponse.json(data, { status });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
}
}

Expand All @@ -18,8 +18,8 @@ export async function POST(request: NextRequest) {
body: JSON.stringify(body),
});
return NextResponse.json(data, { status });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
}
}

Expand All @@ -31,7 +31,7 @@ export async function PATCH(request: NextRequest) {
body: JSON.stringify(body),
});
return NextResponse.json(data, { status });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
} catch (e: unknown) {
return NextResponse.json({ error: e instanceof Error ? e.message : String(e) }, { status: 500 });
}
}
10 changes: 5 additions & 5 deletions app/api/document/[document_id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest, NextResponse } from 'next/server';
import { NextResponse } from 'next/server';


export async function GET(request: Request,
Expand Down Expand Up @@ -32,9 +32,9 @@ export async function GET(request: Request,
}

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
} catch (error: unknown) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ success: false, error: error instanceof Error ? error.message : String(error), data: null },
{ status: 500 }
);
}
Expand Down Expand Up @@ -71,10 +71,10 @@ export async function DELETE(request: Request,
}

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
} catch (error: unknown) {
console.error('Delete error:', error);
return NextResponse.json(
{ error: 'Failed to delete document', details: error.message },
{ error: 'Failed to delete document', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
8 changes: 4 additions & 4 deletions app/api/document/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export async function GET(request: Request) {
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ success: false, error: error instanceof Error ? error.message : String(error), data: null },
{ status: 500 }
);
}
Expand Down Expand Up @@ -74,10 +74,10 @@ export async function POST(request: NextRequest) {
}

return NextResponse.json(data, { status: response.status });
} catch (error: any) {
} catch (error: unknown) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/evaluations/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export async function GET(
}

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
} catch (error: unknown) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to fetch evaluation', details: error.message },
{ error: 'Failed to fetch evaluation', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
10 changes: 5 additions & 5 deletions app/api/evaluations/datasets/[dataset_id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export async function GET(
}

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
} catch (error: unknown) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function DELETE(
let data;
try {
data = await response.json();
} catch (e) {
} catch (_e) {
// If response is not JSON, just return success
data = { success: true };
}
Expand All @@ -103,10 +103,10 @@ export async function DELETE(
}

return NextResponse.json(data, { status: 200 });
} catch (error: any) {
} catch (error: unknown) {
console.error('Proxy error:', error);
return NextResponse.json(
{ error: 'Failed to forward request to backend', details: error.message },
{ error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : String(error) },
{ status: 500 }
);
}
Expand Down
Loading
Loading