mirror of
https://github.com/Heretek-AI/GDevelop-BYOK.git
synced 2026-07-01 18:48:04 -04:00
[GH-ISSUE #17] M001/S01/T01: Extract proxy core modules (callLLM, buildSystemPrompt, requestStore, errors) #16
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @BillyOutlast on GitHub (May 16, 2026).
Original GitHub issue: https://github.com/Heretek-AI/GDevelop-BYOK/issues/17
T01: Extract proxy core modules (callLLM, buildSystemPrompt, requestStore, errors)
The existing proxy/server.js has all AI logic embedded in an Express HTTP server. This task extracts four reusable modules that the IPC handler (T02) will wire together. (1) Create src/proxy/callLLM.js — export async function using native global fetch() (Node 18+, available in Electron 28+), single /v1/chat/completions HTTP POST, configurable via { endpoint, apiKey, model, timeout } object. Implement AbortController-based timeout: 60s for local/ollama endpoints (port-based detection), 30s for cloud providers. Normalize response to { content, usage: { prompt_tokens, completion_tokens } }. Throw ByokError on HTTP errors. (2) Create src/proxy/buildSystemPrompt.js — extract from server.js but remove CUSTOM_SYSTEM_PROMPT env var support. Export buildSystemPrompt(userRequest, projectContext) returning assembled string. (3) Create src/proxy/requestStore.js — in-memory Map with create(request) returning requestId, get(requestId), update(requestId, partial). 1-hour TTL per entry. setInterval cleanup every 5 minutes. (4) Create src/proxy/errors.js — ByokError extends Error with constructor(provider, code, userMessage). Provider-specific codes: INVALID_KEY (401), ENDPOINT_UNREACHABLE (connection/timeout), MODEL_NOT_FOUND (404), RATE_LIMITED (429). User-facing messages name the provider and fix.
Files
src/proxy/callLLM.jssrc/proxy/buildSystemPrompt.jssrc/proxy/requestStore.jssrc/proxy/errors.jstest/unit/proxy.test.jsVerification