Compare commits
12 Commits
3938d1a2b9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| b9736293d3 | |||
| d0543544f8 | |||
| a860bb8921 | |||
| e3748f7e96 | |||
| 20a5dc4b95 | |||
| 83b1cb397d | |||
| 76cdb9654e | |||
| 3e09b03753 | |||
| 36e405a9a8 | |||
| 794e314fa7 | |||
| afff091457 | |||
| 510abaa358 |
11
.dockerignore
Normal file
11
.dockerignore
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
**/.git
|
||||||
|
**/.github
|
||||||
|
**/.claude
|
||||||
|
**/.gitea
|
||||||
|
**/bin
|
||||||
|
**/obj
|
||||||
|
**/.cache
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
node_modules
|
||||||
|
appsettings.Development.json
|
||||||
89
.gitea/workflows/mindforge-api.yaml
Normal file
89
.gitea/workflows/mindforge-api.yaml
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
name: Mindforge API Build and Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "Mindforge.API/**"
|
||||||
|
- ".gitea/workflows/**"
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY_HOST: git.ivanch.me
|
||||||
|
REGISTRY_USERNAME: ivanch
|
||||||
|
IMAGE_API: ${{ env.REGISTRY_HOST }}/ivanch/mindforge-api
|
||||||
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_mindforge_api:
|
||||||
|
name: Build Mindforge API Image
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Log in to Container Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_PASSWORD }}" \
|
||||||
|
| docker login "${{ env.REGISTRY_HOST }}" \
|
||||||
|
-u "${{ env.REGISTRY_USERNAME }}" \
|
||||||
|
--password-stdin
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build and Push Multi-Arch Image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
context: Mindforge.API
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
tags: |
|
||||||
|
${{ env.IMAGE_API }}:latest
|
||||||
|
|
||||||
|
deploy_mindforge_api:
|
||||||
|
name: Deploy Mindforge API (internal)
|
||||||
|
runs-on: ubuntu-amd64
|
||||||
|
needs: build_mindforge_api
|
||||||
|
steps:
|
||||||
|
- name: Check KUBE_CONFIG validity
|
||||||
|
run: |
|
||||||
|
if [ -z "${KUBE_CONFIG}" ] || [ "${KUBE_CONFIG}" = "" ] || [ "${KUBE_CONFIG// }" = "" ]; then
|
||||||
|
echo "KUBE_CONFIG is not set or is empty."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Download and install dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update -y
|
||||||
|
apt-get install -y curl
|
||||||
|
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||||
|
install -m 0755 kubectl /usr/local/bin/kubectl
|
||||||
|
kubectl version --client
|
||||||
|
|
||||||
|
- name: Set up kubeconfig
|
||||||
|
run: |
|
||||||
|
cd Mindforge.API/deploy
|
||||||
|
echo "$KUBE_CONFIG" > kubeconfig.yaml
|
||||||
|
env:
|
||||||
|
KUBE_CONFIG: ${{ env.KUBE_CONFIG }}
|
||||||
|
|
||||||
|
- name: Check connection to cluster
|
||||||
|
run: |
|
||||||
|
cd Mindforge.API/deploy
|
||||||
|
kubectl --kubeconfig=kubeconfig.yaml cluster-info
|
||||||
|
|
||||||
|
- name: Apply mindforge-api deployment
|
||||||
|
run: |
|
||||||
|
cd Mindforge.API/deploy
|
||||||
|
kubectl --kubeconfig=kubeconfig.yaml apply -f mindforge-api.yaml
|
||||||
|
|
||||||
|
- name: Rollout restart
|
||||||
|
run: |
|
||||||
|
cd Mindforge.API/deploy
|
||||||
|
kubectl --kubeconfig=kubeconfig.yaml rollout restart deployment mindforge-api -n mindforge
|
||||||
92
.gitea/workflows/mindforge-web.yaml
Normal file
92
.gitea/workflows/mindforge-web.yaml
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
name: Mindforge Web Build and Deploy (internal)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "Mindforge.Web/**"
|
||||||
|
- ".gitea/workflows/**"
|
||||||
|
workflow_dispatch: {}
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY_HOST: git.ivanch.me
|
||||||
|
REGISTRY_USERNAME: ivanch
|
||||||
|
IMAGE_WEB: ${{ env.REGISTRY_HOST }}/ivanch/mindforge-web
|
||||||
|
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
VITE_API_BASE_URL: http://api.mindforge.haven
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_mindforge_web:
|
||||||
|
name: Build Mindforge Web Image
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Log in to Container Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.REGISTRY_PASSWORD }}" \
|
||||||
|
| docker login "${{ env.REGISTRY_HOST }}" \
|
||||||
|
-u "${{ env.REGISTRY_USERNAME }}" \
|
||||||
|
--password-stdin
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build and Push Multi-Arch Image
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
context: Mindforge.Web
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
VITE_API_BASE_URL=${{ env.VITE_API_BASE_URL }}
|
||||||
|
tags: |
|
||||||
|
${{ env.IMAGE_WEB }}:latest
|
||||||
|
|
||||||
|
deploy_mindforge_web:
|
||||||
|
name: Deploy Mindforge Web (internal)
|
||||||
|
runs-on: ubuntu-amd64
|
||||||
|
needs: build_mindforge_web
|
||||||
|
steps:
|
||||||
|
- name: Check KUBE_CONFIG validity
|
||||||
|
run: |
|
||||||
|
if [ -z "${KUBE_CONFIG}" ] || [ "${KUBE_CONFIG}" = "" ] || [ "${KUBE_CONFIG// }" = "" ]; then
|
||||||
|
echo "KUBE_CONFIG is not set or is empty."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Download and install dependencies
|
||||||
|
run: |
|
||||||
|
apt-get update -y
|
||||||
|
apt-get install -y curl
|
||||||
|
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||||
|
install -m 0755 kubectl /usr/local/bin/kubectl
|
||||||
|
kubectl version --client
|
||||||
|
|
||||||
|
- name: Set up kubeconfig
|
||||||
|
run: |
|
||||||
|
cd Mindforge.Web/deploy
|
||||||
|
echo "$KUBE_CONFIG" > kubeconfig.yaml
|
||||||
|
env:
|
||||||
|
KUBE_CONFIG: ${{ env.KUBE_CONFIG }}
|
||||||
|
|
||||||
|
- name: Check connection to cluster
|
||||||
|
run: |
|
||||||
|
cd Mindforge.Web/deploy
|
||||||
|
kubectl --kubeconfig=kubeconfig.yaml cluster-info
|
||||||
|
|
||||||
|
- name: Apply mindforge-web deployment
|
||||||
|
run: |
|
||||||
|
cd Mindforge.Web/deploy
|
||||||
|
kubectl --kubeconfig=kubeconfig.yaml apply -f mindforge-web.yaml
|
||||||
|
|
||||||
|
- name: Rollout restart
|
||||||
|
run: |
|
||||||
|
cd Mindforge.Web/deploy
|
||||||
|
kubectl --kubeconfig=kubeconfig.yaml rollout restart deployment mindforge-web -n mindforge
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
.claude/
|
||||||
|
_bmad*
|
||||||
11
Mindforge.API/.dockerignore
Normal file
11
Mindforge.API/.dockerignore
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
**/.git
|
||||||
|
**/.github
|
||||||
|
**/.claude
|
||||||
|
**/.gitea
|
||||||
|
**/bin
|
||||||
|
**/obj
|
||||||
|
**/.cache
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
node_modules
|
||||||
|
appsettings.Development.json
|
||||||
3
Mindforge.API/.gitignore
vendored
Normal file
3
Mindforge.API/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
bin
|
||||||
|
obj
|
||||||
|
appsettings.Development.json
|
||||||
43
Mindforge.API/Controllers/FileController.cs
Normal file
43
Mindforge.API/Controllers/FileController.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Mindforge.API.Exceptions;
|
||||||
|
using Mindforge.API.Models.Requests;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/v1/file")]
|
||||||
|
public class FileController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IFileService _fileService;
|
||||||
|
|
||||||
|
public FileController(IFileService fileService)
|
||||||
|
{
|
||||||
|
_fileService = fileService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("check")]
|
||||||
|
public async Task<IActionResult> CheckFile([FromBody] FileCheckRequest request)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(request.FileContent) || string.IsNullOrWhiteSpace(request.CheckType))
|
||||||
|
{
|
||||||
|
throw new UserException("FileContent and CheckType are required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var base64Bytes = Convert.FromBase64String(request.FileContent);
|
||||||
|
request.FileContent = System.Text.Encoding.UTF8.GetString(base64Bytes);
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
throw new UserException("FileContent must be a valid base64 string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await _fileService.CheckFileAsync(request);
|
||||||
|
return Ok(new { result = response });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Mindforge.API/Controllers/FlashcardController.cs
Normal file
43
Mindforge.API/Controllers/FlashcardController.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Mindforge.API.Exceptions;
|
||||||
|
using Mindforge.API.Models.Requests;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/v1/flashcard")]
|
||||||
|
public class FlashcardController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IFlashcardService _flashcardService;
|
||||||
|
|
||||||
|
public FlashcardController(IFlashcardService flashcardService)
|
||||||
|
{
|
||||||
|
_flashcardService = flashcardService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("generate")]
|
||||||
|
public async Task<IActionResult> Generate([FromBody] FlashcardGenerateRequest request)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(request.FileContent) || request.Amount <= 0)
|
||||||
|
{
|
||||||
|
throw new UserException("FileContent is required and Amount must be greater than 0.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var base64Bytes = Convert.FromBase64String(request.FileContent);
|
||||||
|
request.FileContent = System.Text.Encoding.UTF8.GetString(base64Bytes);
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
throw new UserException("FileContent must be a valid base64 string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await _flashcardService.GenerateFlashcardsAsync(request);
|
||||||
|
return Ok(new { result = response });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
Mindforge.API/Controllers/RepositoryController.cs
Normal file
40
Mindforge.API/Controllers/RepositoryController.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/v1/repository")]
|
||||||
|
public class RepositoryController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IGiteaService _giteaService;
|
||||||
|
|
||||||
|
public RepositoryController(IGiteaService giteaService)
|
||||||
|
{
|
||||||
|
_giteaService = giteaService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("info")]
|
||||||
|
public IActionResult GetInfo()
|
||||||
|
{
|
||||||
|
return Ok(new { name = _giteaService.GetRepositoryName() });
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("tree")]
|
||||||
|
public async Task<IActionResult> GetTree()
|
||||||
|
{
|
||||||
|
var tree = await _giteaService.GetFileTreeAsync();
|
||||||
|
return Ok(tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("file")]
|
||||||
|
public async Task<IActionResult> GetFile([FromQuery] string path)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
|
return BadRequest(new { error = "path query parameter is required." });
|
||||||
|
|
||||||
|
var content = await _giteaService.GetFileContentAsync(path);
|
||||||
|
return Ok(new { path, content });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Mindforge.API/Dockerfile
Normal file
21
Mindforge.API/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS builder
|
||||||
|
|
||||||
|
ARG TARGETARCH
|
||||||
|
ARG TARGETOS
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY Mindforge.API.csproj ./
|
||||||
|
RUN dotnet restore -a $TARGETARCH
|
||||||
|
COPY . .
|
||||||
|
RUN dotnet publish -c Release -a $TARGETARCH --no-restore -o /app/publish
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=builder /app/publish .
|
||||||
|
|
||||||
|
ENV ASPNETCORE_URLS=http://+:8080
|
||||||
|
ENV OPENAI_API_KEY=""
|
||||||
|
ENV GEMINI_API_KEY=""
|
||||||
|
|
||||||
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT ["dotnet", "Mindforge.API.dll"]
|
||||||
11
Mindforge.API/Exceptions/UserException.cs
Normal file
11
Mindforge.API/Exceptions/UserException.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Exceptions
|
||||||
|
{
|
||||||
|
public class UserException : Exception
|
||||||
|
{
|
||||||
|
public UserException(string message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
Mindforge.API/Middlewares/ExceptionHandlingMiddleware.cs
Normal file
47
Mindforge.API/Middlewares/ExceptionHandlingMiddleware.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Mindforge.API.Exceptions;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Middlewares
|
||||||
|
{
|
||||||
|
public class ExceptionHandlingMiddleware
|
||||||
|
{
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
private readonly ILogger<ExceptionHandlingMiddleware> _logger;
|
||||||
|
|
||||||
|
public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger)
|
||||||
|
{
|
||||||
|
_next = next;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task InvokeAsync(HttpContext context)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _next(context);
|
||||||
|
}
|
||||||
|
catch (UserException ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "User error");
|
||||||
|
await HandleExceptionAsync(context, StatusCodes.Status400BadRequest, ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Internal server error");
|
||||||
|
await HandleExceptionAsync(context, StatusCodes.Status500InternalServerError, $"Internal server error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string message)
|
||||||
|
{
|
||||||
|
context.Response.ContentType = "application/json";
|
||||||
|
context.Response.StatusCode = statusCode;
|
||||||
|
|
||||||
|
var result = JsonSerializer.Serialize(new { error = message });
|
||||||
|
return context.Response.WriteAsync(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Mindforge.API/Mindforge.API.csproj
Normal file
13
Mindforge.API/Mindforge.API.csproj
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.12" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
6
Mindforge.API/Mindforge.API.http
Normal file
6
Mindforge.API/Mindforge.API.http
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@Mindforge.API_HostAddress = http://localhost:5123
|
||||||
|
|
||||||
|
GET {{Mindforge.API_HostAddress}}/weatherforecast/
|
||||||
|
Accept: application/json
|
||||||
|
|
||||||
|
###
|
||||||
10
Mindforge.API/Models/FileTreeNode.cs
Normal file
10
Mindforge.API/Models/FileTreeNode.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Mindforge.API.Models
|
||||||
|
{
|
||||||
|
public class FileTreeNode
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
public string Path { get; set; } = "";
|
||||||
|
public string Type { get; set; } = ""; // "file" | "folder"
|
||||||
|
public List<FileTreeNode>? Children { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Mindforge.API/Models/Requests/FileCheckRequest.cs
Normal file
13
Mindforge.API/Models/Requests/FileCheckRequest.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Mindforge.API.Models.Requests
|
||||||
|
{
|
||||||
|
public class FileCheckRequest
|
||||||
|
{
|
||||||
|
public string FileContent { get; set; } = string.Empty;
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Expected values: "language" or "content"
|
||||||
|
/// </summary>
|
||||||
|
public string CheckType { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Mindforge.API/Models/Requests/FlashcardGenerateRequest.cs
Normal file
21
Mindforge.API/Models/Requests/FlashcardGenerateRequest.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Models.Requests
|
||||||
|
{
|
||||||
|
public class FlashcardGenerateRequest
|
||||||
|
{
|
||||||
|
public string FileContent { get; set; } = string.Empty;
|
||||||
|
public string FileName { get; set; } = string.Empty;
|
||||||
|
public int Amount { get; set; }
|
||||||
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||||
|
public FlashcardMode? Mode { get; set; } = FlashcardMode.Simple;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum FlashcardMode
|
||||||
|
{
|
||||||
|
Basic,
|
||||||
|
Simple,
|
||||||
|
Detailed,
|
||||||
|
Hyper
|
||||||
|
}
|
||||||
|
}
|
||||||
83
Mindforge.API/Program.cs
Normal file
83
Mindforge.API/Program.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Mindforge.API.Providers;
|
||||||
|
using Mindforge.API.Services;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Ensure environment variables are loaded into IConfiguration
|
||||||
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.Logging.AddConsole();
|
||||||
|
builder.Logging.AddDebug();
|
||||||
|
|
||||||
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
|
builder.Services.AddOpenApi();
|
||||||
|
|
||||||
|
// Configure CORS
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowAll", policy =>
|
||||||
|
{
|
||||||
|
policy.AllowAnyOrigin()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register HttpClient for providers
|
||||||
|
builder.Services.AddHttpClient();
|
||||||
|
|
||||||
|
// Register Providers
|
||||||
|
builder.Services.AddScoped<ILlmApiProvider, OpenAIApiProvider>();
|
||||||
|
|
||||||
|
// Register Services
|
||||||
|
builder.Services.AddScoped<IAgentService, AgentService>();
|
||||||
|
builder.Services.AddScoped<IFileService, FileService>();
|
||||||
|
builder.Services.AddScoped<IFlashcardService, FlashcardService>();
|
||||||
|
builder.Services.AddScoped<IGiteaService, GiteaService>();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.UseCors("AllowAll");
|
||||||
|
|
||||||
|
app.UseMiddleware<Mindforge.API.Middlewares.ExceptionHandlingMiddleware>();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.MapOpenApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
// Check for env vars
|
||||||
|
var openAiApiUrl = builder.Configuration["OPENAI_API_URL"];
|
||||||
|
var openAiToken = builder.Configuration["OPENAI_TOKEN"];
|
||||||
|
var openAiModel = builder.Configuration["OPENAI_MODEL"];
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(openAiApiUrl))
|
||||||
|
app.Logger.LogWarning("OPENAI_API_URL not found in configuration.");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(openAiToken))
|
||||||
|
app.Logger.LogWarning("OPENAI_TOKEN not found in configuration.");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(openAiModel))
|
||||||
|
app.Logger.LogWarning("OPENAI_MODEL not found in configuration.");
|
||||||
|
|
||||||
|
var giteaRepoUrl = builder.Configuration["GITEA_REPO_URL"];
|
||||||
|
var giteaAccessToken = builder.Configuration["GITEA_ACCESS_TOKEN"];
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(giteaRepoUrl))
|
||||||
|
app.Logger.LogWarning("GITEA_REPO_URL not found in configuration. Repository features will not work.");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(giteaAccessToken))
|
||||||
|
app.Logger.LogWarning("GITEA_ACCESS_TOKEN not found in configuration. Repository features will not work.");
|
||||||
|
|
||||||
|
app.Run();
|
||||||
23
Mindforge.API/Properties/launchSettings.json
Normal file
23
Mindforge.API/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5123",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "https://localhost:7116;http://localhost:5123",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Mindforge.API/Providers/ILlmApiProvider.cs
Normal file
9
Mindforge.API/Providers/ILlmApiProvider.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Providers
|
||||||
|
{
|
||||||
|
public interface ILlmApiProvider
|
||||||
|
{
|
||||||
|
Task<string> SendRequestAsync(string systemPrompt, string userPrompt);
|
||||||
|
}
|
||||||
|
}
|
||||||
94
Mindforge.API/Providers/OpenAIApiProvider.cs
Normal file
94
Mindforge.API/Providers/OpenAIApiProvider.cs
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Providers
|
||||||
|
{
|
||||||
|
public class OpenAIApiProvider : ILlmApiProvider
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly ILogger<OpenAIApiProvider> _logger;
|
||||||
|
|
||||||
|
public OpenAIApiProvider(HttpClient httpClient, IConfiguration configuration, ILogger<OpenAIApiProvider> logger)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
_httpClient.Timeout = TimeSpan.FromMinutes(5);
|
||||||
|
_configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> SendRequestAsync(string systemPrompt, string userPrompt)
|
||||||
|
{
|
||||||
|
var apiUrl = _configuration["OPENAI_API_URL"];
|
||||||
|
if (string.IsNullOrEmpty(apiUrl))
|
||||||
|
throw new Exception("OPENAI_API_URL not found in configuration.");
|
||||||
|
|
||||||
|
var token = _configuration["OPENAI_TOKEN"];
|
||||||
|
if (string.IsNullOrEmpty(token))
|
||||||
|
throw new Exception("OPENAI_TOKEN not found in configuration.");
|
||||||
|
|
||||||
|
var model = _configuration["OPENAI_MODEL"];
|
||||||
|
if (string.IsNullOrEmpty(model))
|
||||||
|
throw new Exception("OPENAI_MODEL not found in configuration.");
|
||||||
|
|
||||||
|
var url = $"{apiUrl.TrimEnd('/')}/chat/completions";
|
||||||
|
|
||||||
|
var reqBody = new
|
||||||
|
{
|
||||||
|
model = model,
|
||||||
|
messages = new[]
|
||||||
|
{
|
||||||
|
new { role = "system", content = systemPrompt },
|
||||||
|
new { role = "user", content = userPrompt }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var jsonBody = JsonSerializer.Serialize(reqBody);
|
||||||
|
|
||||||
|
Exception? lastErr = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
using var request = new HttpRequestMessage(HttpMethod.Post, url);
|
||||||
|
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await _httpClient.SendAsync(request);
|
||||||
|
var responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
if (!response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
lastErr = new Exception($"API error status {(int)response.StatusCode}: {responseBody}");
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(1 << i));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = JsonSerializer.Deserialize<JsonElement>(responseBody);
|
||||||
|
if (result.TryGetProperty("choices", out var choices) && choices.GetArrayLength() > 0)
|
||||||
|
{
|
||||||
|
var message = choices[0].GetProperty("message");
|
||||||
|
return message.GetProperty("content").GetString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogWarning("API raw response: {responseBody}", responseBody);
|
||||||
|
throw new Exception("Empty response from API.");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error in API request");
|
||||||
|
lastErr = ex;
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(1 << i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception($"Failed to get response after 5 attempts. Last error: {lastErr?.Message}", lastErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Mindforge.API/Services/AgentService.cs
Normal file
21
Mindforge.API/Services/AgentService.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Mindforge.API.Providers;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services
|
||||||
|
{
|
||||||
|
public class AgentService : IAgentService
|
||||||
|
{
|
||||||
|
private readonly ILlmApiProvider _provider;
|
||||||
|
|
||||||
|
public AgentService(ILlmApiProvider provider)
|
||||||
|
{
|
||||||
|
_provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<string> ProcessRequestAsync(string systemPrompt, string userPrompt)
|
||||||
|
{
|
||||||
|
return _provider.SendRequestAsync(systemPrompt, userPrompt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
56
Mindforge.API/Services/FileService.cs
Normal file
56
Mindforge.API/Services/FileService.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Mindforge.API.Models.Requests;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
using Mindforge.API.Exceptions;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services
|
||||||
|
{
|
||||||
|
public class FileService : IFileService
|
||||||
|
{
|
||||||
|
private readonly IAgentService _agentService;
|
||||||
|
|
||||||
|
public FileService(IAgentService agentService)
|
||||||
|
{
|
||||||
|
_agentService = agentService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> CheckFileAsync(FileCheckRequest request)
|
||||||
|
{
|
||||||
|
string systemPrompt;
|
||||||
|
|
||||||
|
if (request.CheckType.ToLower() == "language")
|
||||||
|
{
|
||||||
|
systemPrompt = $@"Você é um revisor de textos sênior e especialista em língua portuguesa do Brasil.
|
||||||
|
Sua tarefa é analisar o texto fornecido e corrigir rigorosamente todos os erros gramaticais, de concordância, pontuação, garantindo clareza, coesão e fluidez.
|
||||||
|
Por favor, siga esta estrutura:
|
||||||
|
1. Retorne o texto completamente revisado e polido.
|
||||||
|
2. Não adicione nenhum texto adicional, apenas o texto revisado.
|
||||||
|
3. Não altere o sentido do texto, mantenha a mesma ideia. Apenas corrija os erros gramaticais, de concordância e pontuação.
|
||||||
|
Responda única e exclusivamente em português do Brasil.
|
||||||
|
Foque em textos de concursos públicos, principalmente para a banca Cebraspe.";
|
||||||
|
}
|
||||||
|
else if (request.CheckType.ToLower() == "content")
|
||||||
|
{
|
||||||
|
systemPrompt = $@"Você é um analista de conteúdo experiente, especializado em revisão crítica e verificação de fatos.
|
||||||
|
Sua tarefa é realizar uma análise rigorosa do texto fornecido, identificando erros lógicos, imprecisões de conteúdo, contradições internas e inconsistências argumentativas.
|
||||||
|
Por favor, siga esta estrutura:
|
||||||
|
1. Destaque cada problema encontrado no texto original.
|
||||||
|
2. Explique detalhadamente por que é um erro ou inconsistência.
|
||||||
|
3. Apresente sugestões claras e embasadas para reescrever ou corrigir os trechos problemáticos, melhorando a coerência e a lógica e a clareza do conteúdo.
|
||||||
|
Responda única e exclusivamente em português do Brasil e mantenha um tom analítico e construtivo.
|
||||||
|
|
||||||
|
Responda em tópicos para ser apresentados ao usuário, sendo sucinto e não extremamente detalhado.
|
||||||
|
Os resumos serão utilizados para concursos públicos, principalmente para a banca Cebraspe.
|
||||||
|
";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new UserException("Tipo de verificação inválido. Use 'language' ou 'content'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
string userPrompt = $"Arquivo: {request.FileName}\nConteúdo:\n{request.FileContent}";
|
||||||
|
|
||||||
|
return await _agentService.ProcessRequestAsync(systemPrompt, userPrompt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
Mindforge.API/Services/FlashcardService.cs
Normal file
65
Mindforge.API/Services/FlashcardService.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Mindforge.API.Models.Requests;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services
|
||||||
|
{
|
||||||
|
public class FlashcardService : IFlashcardService
|
||||||
|
{
|
||||||
|
private readonly IAgentService _agentService;
|
||||||
|
private readonly ILogger<FlashcardService> _logger;
|
||||||
|
|
||||||
|
public FlashcardService(IAgentService agentService, ILogger<FlashcardService> logger)
|
||||||
|
{
|
||||||
|
_agentService = agentService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GenerateFlashcardsAsync(FlashcardGenerateRequest request)
|
||||||
|
{
|
||||||
|
var extraPrompt = request.Mode switch
|
||||||
|
{
|
||||||
|
FlashcardMode.Detailed => "Crie flashcards mais detalhados.",
|
||||||
|
FlashcardMode.Hyper => "Adicione também pequenas questões para fixação, para que o usuário possa testar seus conhecimentos. As questões devem ser curtas e objetivas, como se fosse cobradas em prova mesmo.",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
|
||||||
|
string systemPrompt = $@"Você é um assistente educacional especializado em criar flashcards para o Anki.
|
||||||
|
Baseado no texto fornecido, crie exatamente {request.Amount} flashcards que focam nos conceitos mais importantes e difíceis.
|
||||||
|
A resposta FINAL deve ser APENAS no formato CSV, pronto para importação no Anki, sem nenhum texto adicional antes ou depois.
|
||||||
|
O formato CSV deve ter duas colunas: a frente da carta (pergunta/conceito) e o verso (resposta/explicação). Use ponto e vírgula (;) como separador. Não adicione o cabeçalho.
|
||||||
|
As perguntas e respostas devem estar estritamente em Português do Brasil.
|
||||||
|
|
||||||
|
Exemplo de saída:
|
||||||
|
""Qual é a capital do Brasil?"";""Brasília""
|
||||||
|
""Qual é a maior cidade do Brasil?"";""São Paulo""
|
||||||
|
|
||||||
|
Com base no arquivo fornecido, crie exatamente {request.Amount} flashcards que focam nos conceitos mais importantes e difíceis.
|
||||||
|
{extraPrompt}
|
||||||
|
";
|
||||||
|
|
||||||
|
string userPrompt = $"Arquivo: {request.FileName}\nConteúdo:\n{request.FileContent}";
|
||||||
|
|
||||||
|
var result = await _agentService.ProcessRequestAsync(systemPrompt, userPrompt);
|
||||||
|
|
||||||
|
var lines = result.Split('\n');
|
||||||
|
|
||||||
|
if (lines.Length == 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Nenhum flashcard gerado.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines.Length > request.Amount)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Quantidade de flashcards excede o limite.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lines.Length < request.Amount)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Quantidade de flashcards abaixo do limite.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
165
Mindforge.API/Services/GiteaService.cs
Normal file
165
Mindforge.API/Services/GiteaService.cs
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Mindforge.API.Exceptions;
|
||||||
|
using Mindforge.API.Models;
|
||||||
|
using Mindforge.API.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services
|
||||||
|
{
|
||||||
|
public class GiteaService : IGiteaService
|
||||||
|
{
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly string _baseUrl;
|
||||||
|
private readonly string _owner;
|
||||||
|
private readonly string _repo;
|
||||||
|
private readonly string _token;
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
||||||
|
{
|
||||||
|
PropertyNameCaseInsensitive = true
|
||||||
|
};
|
||||||
|
|
||||||
|
public GiteaService(HttpClient httpClient, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
|
||||||
|
var repoUrl = configuration["GITEA_REPO_URL"];
|
||||||
|
if (string.IsNullOrEmpty(repoUrl))
|
||||||
|
throw new InvalidOperationException("GITEA_REPO_URL is not set in configuration.");
|
||||||
|
|
||||||
|
_token = configuration["GITEA_ACCESS_TOKEN"]
|
||||||
|
?? throw new InvalidOperationException("GITEA_ACCESS_TOKEN is not set in configuration.");
|
||||||
|
|
||||||
|
// Parse: https://host/owner/repo or https://host/owner/repo.git
|
||||||
|
var normalizedUrl = repoUrl.TrimEnd('/').TrimEnd(".git".ToCharArray());
|
||||||
|
var uri = new Uri(normalizedUrl);
|
||||||
|
_baseUrl = $"{uri.Scheme}://{uri.Host}{(uri.IsDefaultPort ? "" : $":{uri.Port}")}";
|
||||||
|
var parts = uri.AbsolutePath.Trim('/').Split('/');
|
||||||
|
_owner = parts[0];
|
||||||
|
_repo = parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetRepositoryName() => _repo;
|
||||||
|
|
||||||
|
public async Task<List<FileTreeNode>> GetFileTreeAsync()
|
||||||
|
{
|
||||||
|
// Get the master branch to obtain the latest commit SHA
|
||||||
|
var branchJson = await GetApiAsync($"/api/v1/repos/{_owner}/{_repo}/branches/master");
|
||||||
|
var branch = JsonSerializer.Deserialize<GiteaBranch>(branchJson, JsonOptions)
|
||||||
|
?? throw new InvalidOperationException("Failed to parse branch response from Gitea.");
|
||||||
|
|
||||||
|
var treeSha = branch.Commit.Id;
|
||||||
|
|
||||||
|
// Fetch the full recursive tree
|
||||||
|
var treeJson = await GetApiAsync($"/api/v1/repos/{_owner}/{_repo}/git/trees/{treeSha}?recursive=true");
|
||||||
|
var treeResponse = JsonSerializer.Deserialize<GiteaTreeResponse>(treeJson, JsonOptions)
|
||||||
|
?? throw new InvalidOperationException("Failed to parse tree response from Gitea.");
|
||||||
|
|
||||||
|
return BuildTree(treeResponse.Tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetFileContentAsync(string path)
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get,
|
||||||
|
$"{_baseUrl}/api/v1/repos/{_owner}/{_repo}/raw/{path}?ref=master");
|
||||||
|
request.Headers.Add("Authorization", $"token {_token}");
|
||||||
|
|
||||||
|
var response = await _httpClient.SendAsync(request);
|
||||||
|
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
|
||||||
|
throw new UserException($"File not found in repository: {path}");
|
||||||
|
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
return await response.Content.ReadAsStringAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetApiAsync(string endpoint)
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get, $"{_baseUrl}{endpoint}");
|
||||||
|
request.Headers.Add("Authorization", $"token {_token}");
|
||||||
|
var response = await _httpClient.SendAsync(request);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
return await response.Content.ReadAsStringAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<FileTreeNode> BuildTree(List<GiteaTreeItem> items)
|
||||||
|
{
|
||||||
|
var root = new List<FileTreeNode>();
|
||||||
|
var folderMap = new Dictionary<string, FileTreeNode>();
|
||||||
|
|
||||||
|
// Only include .md files and their parent folders
|
||||||
|
var mdFiles = items.Where(i => i.Type == "blob" && i.Path.EndsWith(".md")).ToList();
|
||||||
|
var neededFolders = new HashSet<string>();
|
||||||
|
foreach (var file in mdFiles)
|
||||||
|
{
|
||||||
|
var dir = System.IO.Path.GetDirectoryName(file.Path)?.Replace('\\', '/');
|
||||||
|
while (!string.IsNullOrEmpty(dir))
|
||||||
|
{
|
||||||
|
neededFolders.Add(dir);
|
||||||
|
dir = System.IO.Path.GetDirectoryName(dir)?.Replace('\\', '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create folder nodes
|
||||||
|
foreach (var item in items.Where(i => i.Type == "tree" && neededFolders.Contains(i.Path)).OrderBy(i => i.Path))
|
||||||
|
{
|
||||||
|
var node = new FileTreeNode
|
||||||
|
{
|
||||||
|
Name = System.IO.Path.GetFileName(item.Path),
|
||||||
|
Path = item.Path,
|
||||||
|
Type = "folder",
|
||||||
|
Children = []
|
||||||
|
};
|
||||||
|
folderMap[item.Path] = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place file and folder nodes into parent
|
||||||
|
var allNodes = mdFiles.Select(i => new FileTreeNode
|
||||||
|
{
|
||||||
|
Name = System.IO.Path.GetFileName(i.Path),
|
||||||
|
Path = i.Path,
|
||||||
|
Type = "file"
|
||||||
|
}).Concat(folderMap.Values).OrderBy(n => n.Path);
|
||||||
|
|
||||||
|
foreach (var node in allNodes)
|
||||||
|
{
|
||||||
|
var parentPath = System.IO.Path.GetDirectoryName(node.Path)?.Replace('\\', '/');
|
||||||
|
if (string.IsNullOrEmpty(parentPath))
|
||||||
|
root.Add(node);
|
||||||
|
else if (folderMap.TryGetValue(parentPath, out var parent))
|
||||||
|
parent.Children!.Add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Gitea API DTOs ----
|
||||||
|
|
||||||
|
private class GiteaBranch
|
||||||
|
{
|
||||||
|
[JsonPropertyName("commit")]
|
||||||
|
public GiteaCommit Commit { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GiteaCommit
|
||||||
|
{
|
||||||
|
[JsonPropertyName("id")]
|
||||||
|
public string Id { get; set; } = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GiteaTreeResponse
|
||||||
|
{
|
||||||
|
[JsonPropertyName("tree")]
|
||||||
|
public List<GiteaTreeItem> Tree { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GiteaTreeItem
|
||||||
|
{
|
||||||
|
[JsonPropertyName("path")]
|
||||||
|
public string Path { get; set; } = "";
|
||||||
|
|
||||||
|
[JsonPropertyName("type")]
|
||||||
|
public string Type { get; set; } = ""; // "blob" | "tree"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Mindforge.API/Services/Interfaces/IAgentService.cs
Normal file
9
Mindforge.API/Services/Interfaces/IAgentService.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IAgentService
|
||||||
|
{
|
||||||
|
Task<string> ProcessRequestAsync(string systemPrompt, string userPrompt);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Mindforge.API/Services/Interfaces/IFileService.cs
Normal file
10
Mindforge.API/Services/Interfaces/IFileService.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Mindforge.API.Models.Requests;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IFileService
|
||||||
|
{
|
||||||
|
Task<string> CheckFileAsync(FileCheckRequest request);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
Mindforge.API/Services/Interfaces/IFlashcardService.cs
Normal file
10
Mindforge.API/Services/Interfaces/IFlashcardService.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using Mindforge.API.Models.Requests;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IFlashcardService
|
||||||
|
{
|
||||||
|
Task<string> GenerateFlashcardsAsync(FlashcardGenerateRequest request);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Mindforge.API/Services/Interfaces/IGiteaService.cs
Normal file
11
Mindforge.API/Services/Interfaces/IGiteaService.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using Mindforge.API.Models;
|
||||||
|
|
||||||
|
namespace Mindforge.API.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IGiteaService
|
||||||
|
{
|
||||||
|
Task<List<FileTreeNode>> GetFileTreeAsync();
|
||||||
|
Task<string> GetFileContentAsync(string path);
|
||||||
|
string GetRepositoryName();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Mindforge.API/appsettings.json
Normal file
14
Mindforge.API/appsettings.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"OPENAI_API_URL": "https://openrouter.ai/api/v1",
|
||||||
|
"OPENAI_TOKEN": "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",
|
||||||
|
"OPENAI_MODEL": "openai/gpt-5.4-mini",
|
||||||
|
"GITEA_REPO_URL": "",
|
||||||
|
"GITEA_ACCESS_TOKEN": ""
|
||||||
|
}
|
||||||
81
Mindforge.API/deploy/mindforge-api.yaml
Normal file
81
Mindforge.API/deploy/mindforge-api.yaml
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: mindforge-api
|
||||||
|
namespace: mindforge
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mindforge-api
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: mindforge-api
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: mindforge-api
|
||||||
|
image: git.ivanch.me/ivanch/mindforge-api:latest
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: OPENAI_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: mindforge-secrets
|
||||||
|
key: OPENAI_TOKEN
|
||||||
|
- name: OPENAI_API_URL
|
||||||
|
value: https://openrouter.ai/api/v1
|
||||||
|
- name: OPENAI_MODEL
|
||||||
|
value: openai/gpt-5.4-mini
|
||||||
|
- name: GITEA_REPO_URL
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: mindforge-secrets
|
||||||
|
key: GITEA_REPO_URL
|
||||||
|
- name: GITEA_ACCESS_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: mindforge-secrets
|
||||||
|
key: GITEA_ACCESS_TOKEN
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "250m"
|
||||||
|
limits:
|
||||||
|
memory: "512Mi"
|
||||||
|
cpu: "1"
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: mindforge-api
|
||||||
|
namespace: mindforge
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: mindforge-api
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 8080
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: mindforge-api
|
||||||
|
namespace: mindforge
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: mindforge-api
|
||||||
|
spec:
|
||||||
|
ingressClassName: nginx
|
||||||
|
rules:
|
||||||
|
- host: "api.mindforge.haven"
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: "/"
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: mindforge-api
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
11
Mindforge.Web/.dockerignore
Normal file
11
Mindforge.Web/.dockerignore
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
**/.git
|
||||||
|
**/.github
|
||||||
|
**/.claude
|
||||||
|
**/.gitea
|
||||||
|
**/bin
|
||||||
|
**/obj
|
||||||
|
**/.cache
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
node_modules
|
||||||
|
appsettings.Development.json
|
||||||
1
Mindforge.Web/.env
Normal file
1
Mindforge.Web/.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_BASE_URL=http://localhost:5123
|
||||||
1
Mindforge.Web/.env.dev
Normal file
1
Mindforge.Web/.env.dev
Normal file
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_BASE_URL=http://localhost:5123
|
||||||
24
Mindforge.Web/.gitignore
vendored
Normal file
24
Mindforge.Web/.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
15
Mindforge.Web/Dockerfile
Normal file
15
Mindforge.Web/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM node:22-alpine AS builder
|
||||||
|
|
||||||
|
ARG VITE_API_BASE_URL
|
||||||
|
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
FROM nginx:alpine
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
EXPOSE 80
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
61
Mindforge.Web/deploy/mindforge-web.yaml
Normal file
61
Mindforge.Web/deploy/mindforge-web.yaml
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: mindforge-web
|
||||||
|
namespace: mindforge
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mindforge-web
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: mindforge-web
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: mindforge-web
|
||||||
|
image: git.ivanch.me/ivanch/mindforge-web:latest
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "32Mi"
|
||||||
|
cpu: "100m"
|
||||||
|
limits:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "250m"
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: mindforge-web
|
||||||
|
namespace: mindforge
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: mindforge-web
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 80
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: mindforge-web
|
||||||
|
namespace: mindforge
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: mindforge-web
|
||||||
|
spec:
|
||||||
|
ingressClassName: nginx
|
||||||
|
rules:
|
||||||
|
- host: "mindforge.haven"
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: "/"
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: mindforge-web
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
16
Mindforge.Web/index.html
Normal file
16
Mindforge.Web/index.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Mindforge</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
1897
Mindforge.Web/package-lock.json
generated
Normal file
1897
Mindforge.Web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
Mindforge.Web/package.json
Normal file
24
Mindforge.Web/package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "mindforge-web",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/marked": "^5.0.2",
|
||||||
|
"diff": "^8.0.3",
|
||||||
|
"marked": "^17.0.4",
|
||||||
|
"preact": "^10.29.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@preact/preset-vite": "^2.10.4",
|
||||||
|
"@types/diff": "^7.0.2",
|
||||||
|
"@types/node": "^24.12.0",
|
||||||
|
"typescript": "~5.9.3",
|
||||||
|
"vite": "^8.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Mindforge.Web/public/assets/mindforge-banner.png
Normal file
BIN
Mindforge.Web/public/assets/mindforge-banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
BIN
Mindforge.Web/public/assets/mindforge.png
Normal file
BIN
Mindforge.Web/public/assets/mindforge.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 534 KiB |
BIN
Mindforge.Web/public/favicon.ico
Normal file
BIN
Mindforge.Web/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
62
Mindforge.Web/src/app.css
Normal file
62
Mindforge.Web/src/app.css
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
.home-hero {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
animation: fadeIn 0.8s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-title {
|
||||||
|
font-size: 4rem;
|
||||||
|
font-weight: 700;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
text-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
||||||
|
background: linear-gradient(90deg, #f4f5f5, #00b4d8);
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hero-subtitle {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: rgba(244, 245, 245, 0.8);
|
||||||
|
font-weight: 300;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-content {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
animation: slideUp 0.5s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtitle {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
color: rgba(244, 245, 245, 0.8);
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder-box {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
border: 1px dashed rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 4rem 2rem;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: rgba(244, 245, 245, 0.5);
|
||||||
|
text-align: center;
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
-webkit-backdrop-filter: blur(4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from { opacity: 0; }
|
||||||
|
to { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes slideUp {
|
||||||
|
from { opacity: 0; transform: translateY(20px); }
|
||||||
|
to { opacity: 1; transform: translateY(0); }
|
||||||
|
}
|
||||||
34
Mindforge.Web/src/app.tsx
Normal file
34
Mindforge.Web/src/app.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { useState } from 'preact/hooks';
|
||||||
|
import './app.css';
|
||||||
|
import { Header } from './components/Header';
|
||||||
|
import { Sidebar } from './components/Sidebar';
|
||||||
|
import { VerificadorComponent } from './components/VerificadorComponent';
|
||||||
|
import { FlashcardComponent } from './components/FlashcardComponent';
|
||||||
|
|
||||||
|
export function App() {
|
||||||
|
const [activeModule, setActiveModule] = useState<'home' | 'verificador' | 'flashcards'>('home');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header onGoHome={() => setActiveModule('home')} />
|
||||||
|
<div class="main-layout">
|
||||||
|
<Sidebar activeModule={activeModule} onModuleChange={setActiveModule} />
|
||||||
|
<main class="content-area">
|
||||||
|
<div style={{ display: activeModule === 'home' || !activeModule ? 'block' : 'none' }}>
|
||||||
|
<div class="home-hero">
|
||||||
|
<img src="/assets/mindforge-banner.png" alt="Mindforge Banner" style={{ maxWidth: '100%', height: 'auto', marginBottom: '2rem', borderRadius: '12px', boxShadow: '0 4px 15px rgba(0,0,0,0.5)', zIndex: -10 }} />
|
||||||
|
<h1 class="hero-title">Mindforge! - STAY HARD!</h1>
|
||||||
|
<p class="hero-subtitle">Sua ferramenta de forja mental e estudos.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style={{ display: activeModule === 'verificador' ? 'block' : 'none', height: '100%', width: '100%' }}>
|
||||||
|
<VerificadorComponent />
|
||||||
|
</div>
|
||||||
|
<div style={{ display: activeModule === 'flashcards' ? 'block' : 'none', height: '100%', width: '100%' }}>
|
||||||
|
<FlashcardComponent />
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
41
Mindforge.Web/src/components/Button.css
Normal file
41
Mindforge.Web/src/components/Button.css
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
.btn {
|
||||||
|
font-family: var(--font-main);
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 1rem;
|
||||||
|
padding: 0.8rem 1.5rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
-webkit-backdrop-filter: blur(8px);
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.2);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
22
Mindforge.Web/src/components/Button.tsx
Normal file
22
Mindforge.Web/src/components/Button.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import type { ComponentChildren } from 'preact';
|
||||||
|
import './Button.css';
|
||||||
|
|
||||||
|
interface ButtonProps extends preact.JSX.HTMLAttributes<HTMLButtonElement> {
|
||||||
|
children: ComponentChildren;
|
||||||
|
variant?: 'primary' | 'secondary';
|
||||||
|
className?: string;
|
||||||
|
onClick?: (e?: any) => any;
|
||||||
|
disabled?: boolean;
|
||||||
|
style?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Button({ children, variant = 'primary', className = '', ...props }: ButtonProps) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className={`btn btn-${variant} ${className}`}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
89
Mindforge.Web/src/components/FileTreeComponent.css
Normal file
89
Mindforge.Web/src/components/FileTreeComponent.css
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
.file-tree {
|
||||||
|
background: rgba(255, 255, 255, 0.04);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0.75rem;
|
||||||
|
max-height: 380px;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-folder {
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-folder-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
color: rgba(255, 255, 255, 0.85);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-folder-header:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.07);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-folder-arrow {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
width: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-folder-name {
|
||||||
|
color: rgba(255, 255, 255, 0.85);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-folder-children {
|
||||||
|
padding-left: 18px;
|
||||||
|
border-left: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
margin-left: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-file {
|
||||||
|
margin-bottom: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-file-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 4px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: rgba(255, 255, 255, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-file-label:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.06);
|
||||||
|
color: rgba(255, 255, 255, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-file-label input[type="checkbox"] {
|
||||||
|
accent-color: #7c6fcd;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-file-name {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-loading,
|
||||||
|
.tree-error,
|
||||||
|
.tree-empty {
|
||||||
|
padding: 1rem;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-error {
|
||||||
|
color: #ff7b72;
|
||||||
|
}
|
||||||
82
Mindforge.Web/src/components/FileTreeComponent.tsx
Normal file
82
Mindforge.Web/src/components/FileTreeComponent.tsx
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import { useState, useEffect } from 'preact/hooks';
|
||||||
|
import { MindforgeApiService, type FileTreeNode } from '../services/MindforgeApiService';
|
||||||
|
import './FileTreeComponent.css';
|
||||||
|
|
||||||
|
interface FileTreeComponentProps {
|
||||||
|
selectedPaths: string[];
|
||||||
|
onSelectionChange: (paths: string[]) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FolderNodeProps {
|
||||||
|
node: FileTreeNode;
|
||||||
|
selectedPaths: string[];
|
||||||
|
onToggle: (path: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function FolderNode({ node, selectedPaths, onToggle }: FolderNodeProps) {
|
||||||
|
const [expanded, setExpanded] = useState(true);
|
||||||
|
|
||||||
|
if (node.type === 'file') {
|
||||||
|
return (
|
||||||
|
<div className="tree-file">
|
||||||
|
<label className="tree-file-label">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={selectedPaths.includes(node.path)}
|
||||||
|
onChange={() => onToggle(node.path)}
|
||||||
|
/>
|
||||||
|
<span className="tree-file-name">{node.name}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="tree-folder">
|
||||||
|
<div className="tree-folder-header" onClick={() => setExpanded(e => !e)}>
|
||||||
|
<span className="tree-folder-arrow">{expanded ? '▾' : '▸'}</span>
|
||||||
|
<span className="tree-folder-name">{node.name}</span>
|
||||||
|
</div>
|
||||||
|
{expanded && node.children && (
|
||||||
|
<div className="tree-folder-children">
|
||||||
|
{node.children.map(child => (
|
||||||
|
<FolderNode key={child.path} node={child} selectedPaths={selectedPaths} onToggle={onToggle} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FileTreeComponent({ selectedPaths, onSelectionChange }: FileTreeComponentProps) {
|
||||||
|
const [tree, setTree] = useState<FileTreeNode[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
MindforgeApiService.getRepositoryTree()
|
||||||
|
.then(setTree)
|
||||||
|
.catch(err => setError(err.message))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const togglePath = (path: string) => {
|
||||||
|
if (selectedPaths.includes(path)) {
|
||||||
|
onSelectionChange(selectedPaths.filter(p => p !== path));
|
||||||
|
} else {
|
||||||
|
onSelectionChange([...selectedPaths, path]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loading) return <div className="tree-loading">Carregando repositório...</div>;
|
||||||
|
if (error) return <div className="tree-error">Erro ao carregar repositório: {error}</div>;
|
||||||
|
if (tree.length === 0) return <div className="tree-empty">Nenhum arquivo encontrado no repositório.</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="file-tree">
|
||||||
|
{tree.map(node => (
|
||||||
|
<FolderNode key={node.path} node={node} selectedPaths={selectedPaths} onToggle={togglePath} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
207
Mindforge.Web/src/components/FlashcardComponent.css
Normal file
207
Mindforge.Web/src/components/FlashcardComponent.css
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
.flashcard-container {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
animation: slideUp 0.5s ease-out;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flashcard-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.2rem;
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.8rem;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group label {
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-area {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 200px;
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 1rem;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-area:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input-label {
|
||||||
|
background: var(--color-sidebar);
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
padding: 0.6rem 1.2rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input-label:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border-color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-input {
|
||||||
|
flex: 1;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
width: 100%;
|
||||||
|
height: 8px;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
border-radius: 4px;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-input::-webkit-slider-thumb {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--color-accent);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-input::-webkit-slider-thumb:hover {
|
||||||
|
transform: scale(1.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount-display {
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-accent);
|
||||||
|
min-width: 40px;
|
||||||
|
text-align: right;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Spinner */
|
||||||
|
.spinner-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 3rem 0;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
border: 4px solid rgba(255, 255, 255, 0.1);
|
||||||
|
border-left-color: var(--color-accent);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg); }
|
||||||
|
100% { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.success-message {
|
||||||
|
color: #7ee787;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-top: 1rem;
|
||||||
|
animation: fadeIn 0.5s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
padding: 4px;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
width: fit-content;
|
||||||
|
overflow: hidden;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-item {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-item input[type="radio"] {
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 0.8rem 1.2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: rgba(255, 255, 255, 0.6);
|
||||||
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-item input[type="radio"]:checked + .radio-label {
|
||||||
|
background: var(--color-accent);
|
||||||
|
color: #000;
|
||||||
|
box-shadow: 0 4px 12px rgba(var(--color-accent-rgb), 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-item:hover .radio-label:not(.radio-item input[type="radio"]:checked + .radio-label) {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animations for selection */
|
||||||
|
.radio-item input[type="radio"]:checked + .radio-label {
|
||||||
|
animation: selectBounce 0.3s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes selectBounce {
|
||||||
|
0% { transform: scale(0.95); }
|
||||||
|
50% { transform: scale(1.02); }
|
||||||
|
100% { transform: scale(1); }
|
||||||
|
}
|
||||||
183
Mindforge.Web/src/components/FlashcardComponent.tsx
Normal file
183
Mindforge.Web/src/components/FlashcardComponent.tsx
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
import { useState } from 'preact/hooks';
|
||||||
|
import { MindforgeApiService, type FlashcardMode } from '../services/MindforgeApiService';
|
||||||
|
import { FileTreeComponent } from './FileTreeComponent';
|
||||||
|
import { Button } from './Button';
|
||||||
|
import './FlashcardComponent.css';
|
||||||
|
|
||||||
|
// Mapping of flashcard mode to its maximum allowed amount
|
||||||
|
const modeMax: Record<FlashcardMode, number> = {
|
||||||
|
Basic: 25,
|
||||||
|
Simple: 30,
|
||||||
|
Detailed: 70,
|
||||||
|
Hyper: 130,
|
||||||
|
};
|
||||||
|
|
||||||
|
function utf8ToBase64(str: string): string {
|
||||||
|
const bytes = new TextEncoder().encode(str);
|
||||||
|
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
|
||||||
|
return window.btoa(binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FlashcardComponent() {
|
||||||
|
const [selectedPaths, setSelectedPaths] = useState<string[]>([]);
|
||||||
|
const [amount, setAmount] = useState<number>(20);
|
||||||
|
const [mode, setMode] = useState<FlashcardMode>('Simple');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [success, setSuccess] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const handleModeChange = (newMode: FlashcardMode) => {
|
||||||
|
setMode(newMode);
|
||||||
|
setAmount(20);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGenerate = async () => {
|
||||||
|
if (selectedPaths.length === 0) {
|
||||||
|
setError('Selecione pelo menos um arquivo do repositório para gerar os flashcards.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
setSuccess(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Fetch all selected files and merge their content
|
||||||
|
const fileContents = await Promise.all(
|
||||||
|
selectedPaths.map(path => MindforgeApiService.getFileContent(path))
|
||||||
|
);
|
||||||
|
|
||||||
|
const mergedContent = fileContents.map(f => f.content).join('\n\n---\n\n');
|
||||||
|
const mergedFileName = selectedPaths.length === 1
|
||||||
|
? (selectedPaths[0].split('/').pop() ?? 'merged.md')
|
||||||
|
: 'merged.md';
|
||||||
|
|
||||||
|
const base64Content = utf8ToBase64(mergedContent);
|
||||||
|
const res = await MindforgeApiService.generateFlashcards({
|
||||||
|
fileContent: base64Content,
|
||||||
|
fileName: mergedFileName,
|
||||||
|
amount,
|
||||||
|
mode,
|
||||||
|
});
|
||||||
|
|
||||||
|
downloadCSV(res.result);
|
||||||
|
setSuccess(true);
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.message || 'Ocorreu um erro ao gerar os flashcards.');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadCSV = (content: string) => {
|
||||||
|
const bom = new Uint8Array([0xEF, 0xBB, 0xBF]);
|
||||||
|
const blob = new Blob([bom, content], { type: 'text/csv;charset=utf-8;' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.setAttribute('download', `flashcards_${Date.now()}.csv`);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flashcard-container">
|
||||||
|
<h2 className="title" style={{ fontSize: '2.5rem' }}>Gerador de Flashcards</h2>
|
||||||
|
<p className="subtitle">Selecione os arquivos do repositório para gerar flashcards. Múltiplos arquivos serão combinados.</p>
|
||||||
|
|
||||||
|
<div className="flashcard-form">
|
||||||
|
<div className="input-group">
|
||||||
|
<label>Arquivos do Repositório</label>
|
||||||
|
<FileTreeComponent selectedPaths={selectedPaths} onSelectionChange={setSelectedPaths} />
|
||||||
|
{selectedPaths.length > 0 && (
|
||||||
|
<div style={{ fontSize: '0.85rem', color: 'rgba(255,255,255,0.5)', marginTop: '0.4rem' }}>
|
||||||
|
{selectedPaths.length} arquivo{selectedPaths.length !== 1 ? 's' : ''} selecionado{selectedPaths.length !== 1 ? 's' : ''}
|
||||||
|
{selectedPaths.length > 1 ? ' — conteúdo será combinado' : ''}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="input-group">
|
||||||
|
<label>Quantidade Estimada de Flashcards (10 - {modeMax[mode]})</label>
|
||||||
|
<div className="slider-wrapper">
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
className="slider-input"
|
||||||
|
min="10"
|
||||||
|
max={modeMax[mode]}
|
||||||
|
value={amount}
|
||||||
|
onInput={(e) => setAmount(parseInt((e.target as HTMLInputElement).value))}
|
||||||
|
/>
|
||||||
|
<span className="amount-display">{amount}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="input-group">
|
||||||
|
<label>Modo de Geração</label>
|
||||||
|
<div className="radio-group">
|
||||||
|
<div className="radio-item">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
id="mode-basic"
|
||||||
|
name="mode"
|
||||||
|
value="Basic"
|
||||||
|
checked={mode === 'Basic'}
|
||||||
|
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="mode-basic" className="radio-label" title="Modo básico, rápido e simples. Geralmente conteúdos simples e repetíveis">Básico</label>
|
||||||
|
</div>
|
||||||
|
<div className="radio-item">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
id="mode-simple"
|
||||||
|
name="mode"
|
||||||
|
value="Simple"
|
||||||
|
checked={mode === 'Simple'}
|
||||||
|
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="mode-simple" className="radio-label" title="Modo rápido e simples, possui uma melhor compreensão">Simples</label>
|
||||||
|
</div>
|
||||||
|
<div className="radio-item">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
id="mode-detailed"
|
||||||
|
name="mode"
|
||||||
|
value="Detailed"
|
||||||
|
checked={mode === 'Detailed'}
|
||||||
|
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="mode-detailed" className="radio-label" title="Modelo avançado, maior gama de detalhes">Detalhado</label>
|
||||||
|
</div>
|
||||||
|
<div className="radio-item">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
id="mode-hyper"
|
||||||
|
name="mode"
|
||||||
|
value="Hyper"
|
||||||
|
checked={mode === 'Hyper'}
|
||||||
|
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="mode-hyper" className="radio-label" title="Modelo Pro, complexo e com perguntas adicionais">Hiper</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button variant="primary" onClick={handleGenerate} disabled={loading} style={{ marginTop: '1rem' }}>
|
||||||
|
{loading ? 'Gerando...' : 'Gerar Flashcards e Baixar (CSV)'}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{error && <div style={{ color: '#ff7b72', marginTop: '1rem' }}>{error}</div>}
|
||||||
|
{success && <div className="success-message">Flashcards gerados com sucesso! O download deve ter começado.</div>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{loading && (
|
||||||
|
<div className="spinner-container">
|
||||||
|
<div className="spinner"></div>
|
||||||
|
<p>Extraindo os melhores conceitos para os seus flashcards. Aguarde...</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
61
Mindforge.Web/src/components/Header.css
Normal file
61
Mindforge.Web/src/components/Header.css
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
.header {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 70px;
|
||||||
|
background-color: var(--color-header);
|
||||||
|
/* Imposing black with glassy effect */
|
||||||
|
background: rgba(15, 15, 15, 0.85);
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
-webkit-backdrop-filter: blur(12px);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 1000;
|
||||||
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-content {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-repo {
|
||||||
|
position: absolute;
|
||||||
|
right: 24px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
background: rgba(255, 255, 255, 0.06);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-repo-icon {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-repo-name {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: rgba(255, 255, 255, 0.65);
|
||||||
|
font-family: var(--font-main);
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title {
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
font-family: var(--font-main);
|
||||||
|
font-size: 1.8rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
margin: 0;
|
||||||
|
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
34
Mindforge.Web/src/components/Header.tsx
Normal file
34
Mindforge.Web/src/components/Header.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { useState, useEffect } from 'preact/hooks';
|
||||||
|
import { MindforgeApiService } from '../services/MindforgeApiService';
|
||||||
|
import './Header.css';
|
||||||
|
|
||||||
|
interface HeaderProps {
|
||||||
|
onGoHome?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Header({ onGoHome }: HeaderProps) {
|
||||||
|
const [repoName, setRepoName] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
MindforgeApiService.getRepositoryInfo()
|
||||||
|
.then(info => setRepoName(info.name))
|
||||||
|
.catch(() => setRepoName(null));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header class="header">
|
||||||
|
<div class="header-content">
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }} onClick={onGoHome}>
|
||||||
|
<img src="/assets/mindforge.png" alt="Mindforge" width="55" height="55" style={{ marginRight: '10px' }} />
|
||||||
|
<h1 class="header-title">Mindforge</h1>
|
||||||
|
</div>
|
||||||
|
{repoName && (
|
||||||
|
<div class="header-repo">
|
||||||
|
<span class="header-repo-icon">⎇</span>
|
||||||
|
<span class="header-repo-name">{repoName}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
41
Mindforge.Web/src/components/Sidebar.css
Normal file
41
Mindforge.Web/src/components/Sidebar.css
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
.sidebar {
|
||||||
|
width: 240px;
|
||||||
|
background-color: var(--color-sidebar);
|
||||||
|
border-right: 1px solid rgba(255, 255, 255, 0.05);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 2rem 1.5rem;
|
||||||
|
box-shadow: 4px 0 15px rgba(0, 0, 0, 0.2);
|
||||||
|
/* Ensure it fits cleanly below the header or is independent */
|
||||||
|
height: calc(100vh - 70px);
|
||||||
|
position: sticky;
|
||||||
|
top: 70px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-header {
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-title {
|
||||||
|
color: rgba(244, 245, 245, 0.6);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-nav {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-btn {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
padding: 1rem 1.2rem;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
}
|
||||||
33
Mindforge.Web/src/components/Sidebar.tsx
Normal file
33
Mindforge.Web/src/components/Sidebar.tsx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { Button } from './Button';
|
||||||
|
import './Sidebar.css';
|
||||||
|
|
||||||
|
interface SidebarProps {
|
||||||
|
onModuleChange: (module: 'home' | 'verificador' | 'flashcards') => void;
|
||||||
|
activeModule: 'home' | 'verificador' | 'flashcards';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Sidebar({ onModuleChange, activeModule }: SidebarProps) {
|
||||||
|
return (
|
||||||
|
<aside class="sidebar">
|
||||||
|
<div class="sidebar-header">
|
||||||
|
<h2 class="sidebar-title">Módulos</h2>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-nav">
|
||||||
|
<Button
|
||||||
|
variant={activeModule === 'verificador' ? 'primary' : 'secondary'}
|
||||||
|
onClick={() => onModuleChange('verificador')}
|
||||||
|
className="sidebar-btn"
|
||||||
|
>
|
||||||
|
Verificador
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant={activeModule === 'flashcards' ? 'primary' : 'secondary'}
|
||||||
|
onClick={() => onModuleChange('flashcards')}
|
||||||
|
className="sidebar-btn"
|
||||||
|
>
|
||||||
|
Flashcards
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
);
|
||||||
|
}
|
||||||
199
Mindforge.Web/src/components/VerificadorComponent.css
Normal file
199
Mindforge.Web/src/components/VerificadorComponent.css
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
.verificador-container {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 1000px;
|
||||||
|
margin: 0 auto;
|
||||||
|
animation: slideUp 0.5s ease-out;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-result-block {
|
||||||
|
background: rgba(255, 255, 255, 0.03);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-result-title {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: rgba(255, 255, 255, 0.6);
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.verificador-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.2rem;
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group label {
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-area {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 200px;
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 1rem;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-area:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input-label {
|
||||||
|
background: var(--color-sidebar);
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
padding: 0.6rem 1.2rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input-label:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border-color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-input {
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
padding: 0.8rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-input option {
|
||||||
|
background: var(--color-bg);
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Response Section */
|
||||||
|
.response-section {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.response-content {
|
||||||
|
text-align: left;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
padding: 1.5rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-view {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-added {
|
||||||
|
background-color: rgba(46, 160, 67, 0.3);
|
||||||
|
color: #7ee787;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-removed {
|
||||||
|
background-color: rgba(248, 81, 73, 0.3);
|
||||||
|
color: #ff7b72;
|
||||||
|
text-decoration: line-through;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.side-by-side {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.side-pane {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pane-title {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
text-align: center;
|
||||||
|
color: var(--color-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Spinner */
|
||||||
|
.spinner-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 3rem 0;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
border: 4px solid rgba(255, 255, 255, 0.1);
|
||||||
|
border-left-color: var(--color-accent);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg); }
|
||||||
|
100% { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
194
Mindforge.Web/src/components/VerificadorComponent.tsx
Normal file
194
Mindforge.Web/src/components/VerificadorComponent.tsx
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
import { useState } from 'preact/hooks';
|
||||||
|
import { MindforgeApiService } from '../services/MindforgeApiService';
|
||||||
|
import { FileTreeComponent } from './FileTreeComponent';
|
||||||
|
import { Button } from './Button';
|
||||||
|
import * as diff from 'diff';
|
||||||
|
import { marked } from 'marked';
|
||||||
|
import './VerificadorComponent.css';
|
||||||
|
|
||||||
|
function utf8ToBase64(str: string): string {
|
||||||
|
const bytes = new TextEncoder().encode(str);
|
||||||
|
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
|
||||||
|
return window.btoa(binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckTypeEnum = 'language' | 'content' | 'both';
|
||||||
|
|
||||||
|
interface FileResult {
|
||||||
|
path: string;
|
||||||
|
fileName: string;
|
||||||
|
originalContent: string;
|
||||||
|
languageResult: string | null;
|
||||||
|
contentResult: string | null;
|
||||||
|
error: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VerificadorComponent() {
|
||||||
|
const [selectedPaths, setSelectedPaths] = useState<string[]>([]);
|
||||||
|
const [checkType, setCheckType] = useState<CheckTypeEnum>('language');
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [results, setResults] = useState<FileResult[]>([]);
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (selectedPaths.length === 0) {
|
||||||
|
setError('Selecione pelo menos um arquivo do repositório.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
setResults([]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const fileResults = await Promise.all(
|
||||||
|
selectedPaths.map(async (path): Promise<FileResult> => {
|
||||||
|
const fileName = path.split('/').pop() ?? path;
|
||||||
|
try {
|
||||||
|
const { content } = await MindforgeApiService.getFileContent(path);
|
||||||
|
const base64Content = utf8ToBase64(content);
|
||||||
|
|
||||||
|
let languageResult: string | null = null;
|
||||||
|
let contentResult: string | null = null;
|
||||||
|
|
||||||
|
if (checkType === 'both') {
|
||||||
|
const [langRes, contRes] = await Promise.all([
|
||||||
|
MindforgeApiService.checkFile({ fileContent: base64Content, fileName, checkType: 'language' }),
|
||||||
|
MindforgeApiService.checkFile({ fileContent: base64Content, fileName, checkType: 'content' }),
|
||||||
|
]);
|
||||||
|
languageResult = langRes.result;
|
||||||
|
contentResult = contRes.result;
|
||||||
|
} else {
|
||||||
|
const res = await MindforgeApiService.checkFile({ fileContent: base64Content, fileName, checkType });
|
||||||
|
if (checkType === 'language') languageResult = res.result;
|
||||||
|
else contentResult = res.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { path, fileName, originalContent: content, languageResult, contentResult, error: null };
|
||||||
|
} catch (err: any) {
|
||||||
|
return { path, fileName, originalContent: '', languageResult: null, contentResult: null, error: err.message };
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
setResults(fileResults);
|
||||||
|
} catch (err: any) {
|
||||||
|
setError(err.message || 'Ocorreu um erro ao processar os arquivos.');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderDiff = (original: string, updated: string) => {
|
||||||
|
const diffResult = diff.diffWordsWithSpace(original, updated);
|
||||||
|
return (
|
||||||
|
<div className="diff-view">
|
||||||
|
{diffResult.map((part, index) => {
|
||||||
|
const className = part.added ? 'diff-added' : part.removed ? 'diff-removed' : '';
|
||||||
|
return (
|
||||||
|
<span key={index} className={className}>
|
||||||
|
{part.value}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="verificador-container">
|
||||||
|
<h2 className="title" style={{ fontSize: '2.5rem' }}>Verificador de Arquivos</h2>
|
||||||
|
<p className="subtitle">Selecione os arquivos do repositório para validação de linguagem ou conteúdo.</p>
|
||||||
|
|
||||||
|
<div className="verificador-form">
|
||||||
|
<div className="input-group">
|
||||||
|
<label>Arquivos do Repositório</label>
|
||||||
|
<FileTreeComponent selectedPaths={selectedPaths} onSelectionChange={setSelectedPaths} />
|
||||||
|
{selectedPaths.length > 0 && (
|
||||||
|
<div style={{ fontSize: '0.85rem', color: 'rgba(255,255,255,0.5)', marginTop: '0.4rem' }}>
|
||||||
|
{selectedPaths.length} arquivo{selectedPaths.length !== 1 ? 's' : ''} selecionado{selectedPaths.length !== 1 ? 's' : ''}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="input-group">
|
||||||
|
<label>Tipo de Verificação</label>
|
||||||
|
<select
|
||||||
|
className="select-input"
|
||||||
|
value={checkType}
|
||||||
|
onChange={(e) => setCheckType((e.target as HTMLSelectElement).value as CheckTypeEnum)}
|
||||||
|
>
|
||||||
|
<option value="language">Linguagem</option>
|
||||||
|
<option value="content">Conteúdo</option>
|
||||||
|
<option value="both">Linguagem e Conteúdo</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button variant="primary" onClick={handleSubmit} disabled={loading} style={{ marginTop: '1rem' }}>
|
||||||
|
{loading ? 'Processando...' : 'Verificar'}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{error && <div style={{ color: '#ff7b72', marginTop: '1rem' }}>{error}</div>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{loading && (
|
||||||
|
<div className="spinner-container">
|
||||||
|
<div className="spinner"></div>
|
||||||
|
<p>Analisando sua forja mental...</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!loading && results.length > 0 && (
|
||||||
|
<div className="response-section">
|
||||||
|
{results.map((fileResult) => (
|
||||||
|
<div key={fileResult.path} className="file-result-block">
|
||||||
|
<div className="file-result-title">{fileResult.fileName}</div>
|
||||||
|
|
||||||
|
{fileResult.error && (
|
||||||
|
<div style={{ color: '#ff7b72', padding: '0.5rem' }}>{fileResult.error}</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!fileResult.error && checkType === 'language' && fileResult.languageResult && (
|
||||||
|
<div className="side-pane">
|
||||||
|
<div className="pane-title">Linguagem (Diff)</div>
|
||||||
|
<div className="response-content">
|
||||||
|
{renderDiff(fileResult.originalContent, fileResult.languageResult)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!fileResult.error && checkType === 'content' && fileResult.contentResult && (
|
||||||
|
<div className="side-pane">
|
||||||
|
<div className="pane-title">Conteúdo</div>
|
||||||
|
<div
|
||||||
|
className="response-content markdown-body"
|
||||||
|
dangerouslySetInnerHTML={{ __html: marked.parse(fileResult.contentResult) as string }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!fileResult.error && checkType === 'both' && fileResult.languageResult && fileResult.contentResult && (
|
||||||
|
<div className="side-by-side">
|
||||||
|
<div className="side-pane">
|
||||||
|
<div className="pane-title">Linguagem (Diff)</div>
|
||||||
|
<div className="response-content" style={{ minHeight: '200px' }}>
|
||||||
|
{renderDiff(fileResult.originalContent, fileResult.languageResult)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="side-pane">
|
||||||
|
<div className="pane-title">Conteúdo</div>
|
||||||
|
<div
|
||||||
|
className="response-content markdown-body"
|
||||||
|
style={{ minHeight: '200px' }}
|
||||||
|
dangerouslySetInnerHTML={{ __html: marked.parse(fileResult.contentResult) as string }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
57
Mindforge.Web/src/index.css
Normal file
57
Mindforge.Web/src/index.css
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap');
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--color-bg: #005873;
|
||||||
|
--color-header: #0f0f0f;
|
||||||
|
--color-sidebar: #013a4c;
|
||||||
|
--color-text-creamy: #f4f5f5;
|
||||||
|
--color-accent: #00b4d8;
|
||||||
|
--color-accent-rgb: 0, 180, 216;
|
||||||
|
--color-accent-hover: #0096c7;
|
||||||
|
|
||||||
|
--font-main: 'Lato', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: var(--font-main);
|
||||||
|
background-color: var(--color-bg);
|
||||||
|
color: var(--color-text-creamy);
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
#app {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-layout {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
margin-top: 70px; /* offset for fixed header */
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-area {
|
||||||
|
flex: 1;
|
||||||
|
padding: 2rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 3rem;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
text-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
5
Mindforge.Web/src/main.tsx
Normal file
5
Mindforge.Web/src/main.tsx
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { render } from 'preact'
|
||||||
|
import './index.css'
|
||||||
|
import { App } from './app.tsx'
|
||||||
|
|
||||||
|
render(<App />, document.getElementById('app')!)
|
||||||
90
Mindforge.Web/src/services/MindforgeApiService.ts
Normal file
90
Mindforge.Web/src/services/MindforgeApiService.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5123';
|
||||||
|
|
||||||
|
export interface FileTreeNode {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
type: 'file' | 'folder';
|
||||||
|
children?: FileTreeNode[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RepositoryInfo {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileContentResponse {
|
||||||
|
path: string;
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CheckFileRequest {
|
||||||
|
fileContent: string;
|
||||||
|
fileName: string;
|
||||||
|
checkType: 'language' | 'content';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CheckFileResponse {
|
||||||
|
result: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GenerateFlashcardsRequest {
|
||||||
|
fileContent: string;
|
||||||
|
fileName: string;
|
||||||
|
amount: number;
|
||||||
|
mode: FlashcardMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FlashcardMode = 'Basic' | 'Simple' | 'Detailed' | 'Hyper';
|
||||||
|
|
||||||
|
export interface GenerateFlashcardsResponse {
|
||||||
|
result: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MindforgeApiService = {
|
||||||
|
async checkFile(data: CheckFileRequest): Promise<CheckFileResponse> {
|
||||||
|
const response = await fetch(`${BASE_URL}/api/v1/file/check`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Error checking file: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
|
|
||||||
|
async generateFlashcards(data: GenerateFlashcardsRequest): Promise<GenerateFlashcardsResponse> {
|
||||||
|
const response = await fetch(`${BASE_URL}/api/v1/flashcard/generate`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Error generating flashcards: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
|
|
||||||
|
async getRepositoryInfo(): Promise<RepositoryInfo> {
|
||||||
|
const response = await fetch(`${BASE_URL}/api/v1/repository/info`);
|
||||||
|
if (!response.ok) throw new Error(`Error fetching repository info: ${response.statusText}`);
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
|
|
||||||
|
async getRepositoryTree(): Promise<FileTreeNode[]> {
|
||||||
|
const response = await fetch(`${BASE_URL}/api/v1/repository/tree`);
|
||||||
|
if (!response.ok) throw new Error(`Error fetching repository tree: ${response.statusText}`);
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
|
|
||||||
|
async getFileContent(path: string): Promise<FileContentResponse> {
|
||||||
|
const response = await fetch(`${BASE_URL}/api/v1/repository/file?path=${encodeURIComponent(path)}`);
|
||||||
|
if (!response.ok) throw new Error(`Error fetching file ${path}: ${response.statusText}`);
|
||||||
|
return response.json();
|
||||||
|
},
|
||||||
|
};
|
||||||
33
Mindforge.Web/tsconfig.app.json
Normal file
33
Mindforge.Web/tsconfig.app.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "ES2023",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"module": "ESNext",
|
||||||
|
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"paths": {
|
||||||
|
"react": ["./node_modules/preact/compat/"],
|
||||||
|
"react-dom": ["./node_modules/preact/compat/"]
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
||||||
7
Mindforge.Web/tsconfig.json
Normal file
7
Mindforge.Web/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
26
Mindforge.Web/tsconfig.node.json
Normal file
26
Mindforge.Web/tsconfig.node.json
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "ES2023",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"types": ["node"],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"erasableSyntaxOnly": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
7
Mindforge.Web/vite.config.ts
Normal file
7
Mindforge.Web/vite.config.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import preact from '@preact/preset-vite'
|
||||||
|
|
||||||
|
// https://vite.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [preact()],
|
||||||
|
})
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
## Mindforge Architecture
|
||||||
|
|
||||||
|
This is a project that will be used to aid the user in making notes and studying for hard exams and tests.
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
GIT_REPOSITORY=https://git.url/user/repo.git
|
GIT_REPOSITORY=https://git.url/user/repo.git
|
||||||
OPENAI_API_KEY=openai_api_key
|
|
||||||
GEMINI_API_KEY=gemini_api_key
|
|
||||||
DISCORD_WEBHOOK_URL=discord_webhook_channel_url
|
DISCORD_WEBHOOK_URL=discord_webhook_channel_url
|
||||||
|
|
||||||
# LLM provider per agent function ("openai" or "gemini", defaults to "openai")
|
# OpenAI-compatible provider (e.g. OpenRouter)
|
||||||
SUMMARY_CREATOR_PROVIDER=gemini
|
OPENAI_API_URL=https://openrouter.ai/api/v1
|
||||||
SUMMARY_FORMATTER_PROVIDER=openai
|
OPENAI_TOKEN=your_token_here
|
||||||
|
OPENAI_MODEL=openai/gpt-5.4-mini
|
||||||
|
|
||||||
# LLM models
|
TOP_N_FILES=10
|
||||||
GEMINI_MODEL=gemini-3-flash-preview
|
|
||||||
OPENAI_MODEL=gpt-5-mini
|
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"mindforge.cronjob/internal/agent"
|
"mindforge.cronjob/internal/agent"
|
||||||
@@ -27,6 +28,14 @@ func main() {
|
|||||||
// Initialize services
|
// Initialize services
|
||||||
gitService := git.NewGitService()
|
gitService := git.NewGitService()
|
||||||
|
|
||||||
|
// Resolve how many top files to return (TOP_N_FILES env var, default 10)
|
||||||
|
topN := 10
|
||||||
|
if v := os.Getenv("TOP_N_FILES"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||||
|
topN = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get modifications
|
// Get modifications
|
||||||
var modifications map[string]string
|
var modifications map[string]string
|
||||||
error := gitService.FetchContents(gitRepo)
|
error := gitService.FetchContents(gitRepo)
|
||||||
@@ -34,7 +43,15 @@ func main() {
|
|||||||
log.Println("ERROR: Failed to fetch contents:", error)
|
log.Println("ERROR: Failed to fetch contents:", error)
|
||||||
}
|
}
|
||||||
|
|
||||||
modifications, error = gitService.GetModifications(7)
|
// Resolve how many days to look back (LAST_N_DAYS env var, default 7)
|
||||||
|
days := 7
|
||||||
|
if v := os.Getenv("LAST_N_DAYS"); v != "" {
|
||||||
|
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||||
|
days = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
modifications, error = gitService.GetModifications(days, topN)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
log.Println("ERROR: Failed to get modifications:", error)
|
log.Println("ERROR: Failed to get modifications:", error)
|
||||||
}
|
}
|
||||||
@@ -42,7 +59,7 @@ func main() {
|
|||||||
fmt.Printf("Found %d modifications\n", len(modifications))
|
fmt.Printf("Found %d modifications\n", len(modifications))
|
||||||
|
|
||||||
for file, content := range modifications {
|
for file, content := range modifications {
|
||||||
fmt.Printf("File: %s\n", file)
|
fmt.Printf("Processing file: %s\n", file)
|
||||||
|
|
||||||
raw_summary, err := agent.SummaryCreatorAgent(file, content)
|
raw_summary, err := agent.SummaryCreatorAgent(file, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -22,16 +22,15 @@ spec:
|
|||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: mindforge-secrets
|
name: mindforge-secrets
|
||||||
key: GIT_REPOSITORY
|
key: GIT_REPOSITORY
|
||||||
- name: GEMINI_API_KEY
|
- name: OPENAI_TOKEN
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: mindforge-secrets
|
name: mindforge-secrets
|
||||||
key: GEMINI_API_KEY
|
key: OPENAI_TOKEN
|
||||||
- name: OPENAI_API_KEY
|
- name: OPENAI_API_URL
|
||||||
valueFrom:
|
value: https://openrouter.ai/api/v1
|
||||||
secretKeyRef:
|
- name: OPENAI_MODEL
|
||||||
name: mindforge-secrets
|
value: openai/gpt-5.4-mini
|
||||||
key: OPENAI_API_KEY
|
|
||||||
- name: DISCORD_WEBHOOK_URL
|
- name: DISCORD_WEBHOOK_URL
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
@@ -42,14 +41,10 @@ spec:
|
|||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: mindforge-secrets
|
name: mindforge-secrets
|
||||||
key: HAVEN_NOTIFY_URL
|
key: HAVEN_NOTIFY_URL
|
||||||
- name: SUMMARY_CREATOR_PROVIDER
|
- name: TOP_N_FILES
|
||||||
value: gemini
|
value: "10"
|
||||||
- name: SUMMARY_FORMATTER_PROVIDER
|
- name: LAST_N_DAYS
|
||||||
value: openai
|
value: "7"
|
||||||
- name: GEMINI_MODEL
|
|
||||||
value: gemini-3-flash-preview
|
|
||||||
- name: OPENAI_MODEL
|
|
||||||
value: gpt-5-mini
|
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
memory: "256Mi"
|
memory: "256Mi"
|
||||||
|
|||||||
@@ -2,50 +2,11 @@ package agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"mindforge.cronjob/internal/llm"
|
"mindforge.cronjob/internal/llm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents the LLM provider to use.
|
|
||||||
type Provider string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ProviderOpenAI Provider = "openai"
|
|
||||||
ProviderGemini Provider = "gemini"
|
|
||||||
)
|
|
||||||
|
|
||||||
// providerFromEnv reads the provider for a given agent from an env var,
|
|
||||||
// defaulting to OpenAI if not set or unrecognised.
|
|
||||||
func providerFromEnv(envKey string) Provider {
|
|
||||||
val := strings.ToLower(strings.TrimSpace(os.Getenv(envKey)))
|
|
||||||
if val == string(ProviderGemini) {
|
|
||||||
return ProviderGemini
|
|
||||||
}
|
|
||||||
return ProviderOpenAI
|
|
||||||
}
|
|
||||||
|
|
||||||
// send routes the request to the given LLM provider.
|
|
||||||
func send(provider Provider, systemPrompt, userPrompt string) (string, error) {
|
|
||||||
llmService := llm.NewLLMService()
|
|
||||||
switch provider {
|
|
||||||
case ProviderGemini:
|
|
||||||
geminiModel := os.Getenv("GEMINI_MODEL")
|
|
||||||
if geminiModel == "" {
|
|
||||||
geminiModel = "gemini-3.1-flash-lite-preview"
|
|
||||||
}
|
|
||||||
return llmService.SendGeminiRequest(systemPrompt, userPrompt, geminiModel)
|
|
||||||
default:
|
|
||||||
openaiModel := os.Getenv("OPENAI_MODEL")
|
|
||||||
if openaiModel == "" {
|
|
||||||
openaiModel = "gpt-5-mini"
|
|
||||||
}
|
|
||||||
return llmService.SendOpenAIRequest(systemPrompt, userPrompt, openaiModel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SummaryCreatorAgent creates a summary of the git diff for a specific file.
|
// SummaryCreatorAgent creates a summary of the git diff for a specific file.
|
||||||
func SummaryCreatorAgent(filePath, gitDiff string) (string, error) {
|
func SummaryCreatorAgent(filePath, gitDiff string) (string, error) {
|
||||||
fileName := filepath.Base(filePath)
|
fileName := filepath.Base(filePath)
|
||||||
@@ -66,7 +27,7 @@ Responda sempre em Português do Brasil (pt-BR).`
|
|||||||
|
|
||||||
userPrompt := fmt.Sprintf("Caminho do arquivo: %s\nPasta (Assunto Principal): %s\nArquivo (Assunto Específico): %s\n\nGit Diff:\n%s", filePath, folderName, fileName, gitDiff)
|
userPrompt := fmt.Sprintf("Caminho do arquivo: %s\nPasta (Assunto Principal): %s\nArquivo (Assunto Específico): %s\n\nGit Diff:\n%s", filePath, folderName, fileName, gitDiff)
|
||||||
|
|
||||||
return send(providerFromEnv("SUMMARY_CREATOR_PROVIDER"), systemPrompt, userPrompt)
|
return llm.NewLLMService().Send(systemPrompt, userPrompt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SummaryFormatterAgent formats a plain text summary into Markdown.
|
// SummaryFormatterAgent formats a plain text summary into Markdown.
|
||||||
@@ -82,5 +43,5 @@ Regras de formatação:
|
|||||||
|
|
||||||
Responda sempre em Português do Brasil (pt-BR).`
|
Responda sempre em Português do Brasil (pt-BR).`
|
||||||
|
|
||||||
return send(providerFromEnv("SUMMARY_FORMATTER_PROVIDER"), systemPrompt, summary)
|
return llm.NewLLMService().Send(systemPrompt, summary)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -13,7 +14,10 @@ import (
|
|||||||
type Service interface {
|
type Service interface {
|
||||||
CheckConnection(url string) error
|
CheckConnection(url string) error
|
||||||
FetchContents(url string) error
|
FetchContents(url string) error
|
||||||
GetModifications(days int) (map[string]string, error)
|
// GetModifications returns the diffs of the top-N most-changed files (by lines
|
||||||
|
// added/removed) modified within the last 'days' days. Files with 4 or fewer
|
||||||
|
// changed lines are always excluded. Pass topN <= 0 to return all qualifying files.
|
||||||
|
GetModifications(days int, topN int) (map[string]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type gitService struct {
|
type gitService struct {
|
||||||
@@ -85,7 +89,7 @@ func (s *gitService) FetchContents(url string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *gitService) GetModifications(days int) (map[string]string, error) {
|
func (s *gitService) GetModifications(days int, topN int) (map[string]string, error) {
|
||||||
mods := make(map[string]string)
|
mods := make(map[string]string)
|
||||||
|
|
||||||
// Determine the commit to diff against (the latest commit *before* 'days' ago)
|
// Determine the commit to diff against (the latest commit *before* 'days' ago)
|
||||||
@@ -103,7 +107,7 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the list of modified files between the base commit and HEAD
|
// Get the list of modified files between the base commit and HEAD
|
||||||
cmdFiles := exec.Command("git", "diff", "--name-only", baseCommit, "HEAD")
|
cmdFiles := exec.Command("git", "-c", "core.quotePath=false", "diff", "--name-only", baseCommit, "HEAD")
|
||||||
cmdFiles.Dir = s.repoDir
|
cmdFiles.Dir = s.repoDir
|
||||||
filesOut, err := cmdFiles.Output()
|
filesOut, err := cmdFiles.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -112,6 +116,8 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
|
|||||||
|
|
||||||
files := strings.Split(strings.TrimSpace(string(filesOut)), "\n")
|
files := strings.Split(strings.TrimSpace(string(filesOut)), "\n")
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
fmt.Printf("Processing file: %s\n", file)
|
||||||
|
|
||||||
if file == "" {
|
if file == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -121,6 +127,11 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip files with "Conteúdos.md" in the path
|
||||||
|
if strings.Contains(file, "Conteúdos.md") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
originalFile := file
|
originalFile := file
|
||||||
|
|
||||||
// Remove first folder from file path
|
// Remove first folder from file path
|
||||||
@@ -135,7 +146,7 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
|
|||||||
rangeStr = baseCommit + "..HEAD"
|
rangeStr = baseCommit + "..HEAD"
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdDiff := exec.Command("git", "log", "-p", "-i", "--invert-grep", "--grep=refactor", rangeStr, "--", originalFile)
|
cmdDiff := exec.Command("git", "-c", "core.quotePath=false", "log", "-p", "-i", "--invert-grep", "--grep=refactor", rangeStr, "--", originalFile)
|
||||||
cmdDiff.Dir = s.repoDir
|
cmdDiff.Dir = s.repoDir
|
||||||
diffOut, err := cmdDiff.Output()
|
diffOut, err := cmdDiff.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -147,5 +158,44 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mods, nil
|
// Count the number of changed lines (additions + deletions) per file.
|
||||||
|
// Lines starting with '+' or '-' are changed lines; lines starting with '+++'
|
||||||
|
// or '---' are the diff file headers and must be excluded.
|
||||||
|
type fileScore struct {
|
||||||
|
name string
|
||||||
|
score int
|
||||||
|
}
|
||||||
|
scores := make([]fileScore, 0, len(mods))
|
||||||
|
for name, diff := range mods {
|
||||||
|
count := 0
|
||||||
|
for _, line := range strings.Split(diff, "\n") {
|
||||||
|
if (strings.HasPrefix(line, "+") || strings.HasPrefix(line, "-")) &&
|
||||||
|
!strings.HasPrefix(line, "++") && !strings.HasPrefix(line, "--") {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Ignore files with 4 or fewer lines changed
|
||||||
|
if count <= 4 {
|
||||||
|
fmt.Printf("Ignoring file %s: %d lines changed\n", name, count)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
scores = append(scores, fileScore{name: name, score: count})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort descending by number of changed lines
|
||||||
|
sort.Slice(scores, func(i, j int) bool {
|
||||||
|
return scores[i].score > scores[j].score
|
||||||
|
})
|
||||||
|
|
||||||
|
// Keep only the top-N entries (if topN <= 0, keep all qualifying files)
|
||||||
|
if topN > 0 && len(scores) > topN {
|
||||||
|
scores = scores[:topN]
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(map[string]string, len(scores))
|
||||||
|
for _, fs := range scores {
|
||||||
|
result[fs.name] = mods[fs.name]
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
package llm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *llmService) SendGeminiRequest(systemPrompt string, userPrompt string, model string) (string, error) {
|
|
||||||
apiKey := getEnvConfig("GEMINI_API_KEY")
|
|
||||||
if apiKey == "" {
|
|
||||||
return "", errors.New("GEMINI_API_KEY not found in .env or environment")
|
|
||||||
}
|
|
||||||
|
|
||||||
apiBase := "https://generativelanguage.googleapis.com/v1beta"
|
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/models/%s:generateContent?key=%s", strings.TrimRight(apiBase, "/"), model, apiKey)
|
|
||||||
|
|
||||||
reqBody := map[string]interface{}{}
|
|
||||||
if systemPrompt != "" {
|
|
||||||
reqBody["system_instruction"] = map[string]interface{}{
|
|
||||||
"parts": []map[string]string{
|
|
||||||
{"text": systemPrompt},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reqBody["contents"] = []map[string]interface{}{
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"parts": []map[string]string{
|
|
||||||
{"text": userPrompt},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonBody, err := json.Marshal(reqBody)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
client := &http.Client{Timeout: 120 * time.Second}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return "", fmt.Errorf("Gemini API error status %d: %s", resp.StatusCode, string(bodyBytes))
|
|
||||||
}
|
|
||||||
|
|
||||||
var result struct {
|
|
||||||
Candidates []struct {
|
|
||||||
Content struct {
|
|
||||||
Parts []struct {
|
|
||||||
Text string `json:"text"`
|
|
||||||
} `json:"parts"`
|
|
||||||
} `json:"content"`
|
|
||||||
} `json:"candidates"`
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(bodyBytes, &result); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(result.Candidates) > 0 && len(result.Candidates[0].Content.Parts) > 0 {
|
|
||||||
return result.Candidates[0].Content.Parts[0].Text, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("empty response from Gemini API")
|
|
||||||
}
|
|
||||||
@@ -6,8 +6,7 @@ import (
|
|||||||
|
|
||||||
// Service defines the interface for connecting to LLMs
|
// Service defines the interface for connecting to LLMs
|
||||||
type Service interface {
|
type Service interface {
|
||||||
SendOpenAIRequest(systemPrompt string, userPrompt string, model string) (string, error)
|
Send(systemPrompt string, userPrompt string) (string, error)
|
||||||
SendGeminiRequest(systemPrompt string, userPrompt string, model string) (string, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type llmService struct{}
|
type llmService struct{}
|
||||||
|
|||||||
@@ -11,15 +11,23 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *llmService) SendOpenAIRequest(systemPrompt string, userPrompt string, model string) (string, error) {
|
func (s *llmService) Send(systemPrompt string, userPrompt string) (string, error) {
|
||||||
apiKey := getEnvConfig("OPENAI_API_KEY")
|
apiURL := getEnvConfig("OPENAI_API_URL")
|
||||||
if apiKey == "" {
|
if apiURL == "" {
|
||||||
return "", errors.New("OPENAI_API_KEY not found in .env or environment")
|
return "", errors.New("OPENAI_API_URL not found in environment")
|
||||||
}
|
}
|
||||||
|
|
||||||
apiBase := "https://api.openai.com/v1"
|
token := getEnvConfig("OPENAI_TOKEN")
|
||||||
|
if token == "" {
|
||||||
|
return "", errors.New("OPENAI_TOKEN not found in environment")
|
||||||
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/chat/completions", strings.TrimRight(apiBase, "/"))
|
model := getEnvConfig("OPENAI_MODEL")
|
||||||
|
if model == "" {
|
||||||
|
return "", errors.New("OPENAI_MODEL not found in environment")
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/chat/completions", strings.TrimRight(apiURL, "/"))
|
||||||
|
|
||||||
reqBody := map[string]interface{}{
|
reqBody := map[string]interface{}{
|
||||||
"model": model,
|
"model": model,
|
||||||
@@ -42,7 +50,7 @@ func (s *llmService) SendOpenAIRequest(systemPrompt string, userPrompt string, m
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
|
||||||
client := &http.Client{Timeout: 120 * time.Second}
|
client := &http.Client{Timeout: 120 * time.Second}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
@@ -62,7 +70,7 @@ func (s *llmService) SendOpenAIRequest(systemPrompt string, userPrompt string, m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
lastErr = fmt.Errorf("OpenAI API error status %d: %s", resp.StatusCode, string(bodyBytes))
|
lastErr = fmt.Errorf("API error status %d: %s", resp.StatusCode, string(bodyBytes))
|
||||||
time.Sleep(time.Second * time.Duration(1<<i))
|
time.Sleep(time.Second * time.Duration(1<<i))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -81,8 +89,8 @@ func (s *llmService) SendOpenAIRequest(systemPrompt string, userPrompt string, m
|
|||||||
if len(result.Choices) > 0 {
|
if len(result.Choices) > 0 {
|
||||||
return result.Choices[0].Message.Content, nil
|
return result.Choices[0].Message.Content, nil
|
||||||
}
|
}
|
||||||
return "", errors.New("empty response from OpenAI API")
|
return "", errors.New("empty response from API")
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("failed to get OpenAI response after 5 attempts. Last error: %v", lastErr)
|
return "", fmt.Errorf("failed to get response after 5 attempts. Last error: %v", lastErr)
|
||||||
}
|
}
|
||||||
|
|||||||
24
mindforge.sln
Normal file
24
mindforge.sln
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.2.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mindforge.API", "Mindforge.API\Mindforge.API.csproj", "{038E2A68-9556-09E2-3A91-52464940A286}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{038E2A68-9556-09E2-3A91-52464940A286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{038E2A68-9556-09E2-3A91-52464940A286}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{038E2A68-9556-09E2-3A91-52464940A286}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{038E2A68-9556-09E2-3A91-52464940A286}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {3765D3A9-6691-44E4-8741-710E14090009}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user