[GH-ISSUE #17] M001/S01/T01: Extract proxy core modules (callLLM, buildSystemPrompt, requestStore, errors) #16

Open
opened 2026-06-04 14:29:26 -04:00 by yindo · 0 comments
Owner

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.js
  • src/proxy/buildSystemPrompt.js
  • src/proxy/requestStore.js
  • src/proxy/errors.js
  • test/unit/proxy.test.js

Verification

  • node --test test/unit/proxy.test.js
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.js` - `src/proxy/buildSystemPrompt.js` - `src/proxy/requestStore.js` - `src/proxy/errors.js` - `test/unit/proxy.test.js` ### Verification - [ ] node --test test/unit/proxy.test.js
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Heretek-AI/GDevelop-BYOK#16