mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
OmniRoute is an intelligent API gateway that unifies 20+ AI providers behind a single OpenAI-compatible endpoint. Features include intelligent routing with 6 strategies, multi-format translation (OpenAI/Claude/Gemini/Responses API), circuit breakers, semantic caching, combo fallback chains, real-time health monitoring, and a full dashboard with provider management, analytics, and CLI tool integration. Key highlights: - 20+ providers (Claude Code, Codex, Gemini CLI, GitHub Copilot, iFlow, Qwen, Kiro, etc.) - 6 routing strategies (Fill First, Round Robin, P2C, Random, Least Used, Cost Optimized) - Export/Import database backup with full archive support - Translator Playground with 4 modes (Playground, Chat Tester, Test Bench, Live Monitor) - 100% TypeScript across src/ and open-sse/ - Docker support with multi-stage builds - Comprehensive documentation and 9 dashboard screenshots
97 lines
3.6 KiB
JavaScript
97 lines
3.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const {
|
|
injectSystemPrompt,
|
|
setSystemPromptConfig,
|
|
getSystemPromptConfig,
|
|
} = await import("../../open-sse/services/systemPrompt.ts");
|
|
|
|
// ─── Config ─────────────────────────────────────────────────────────────────
|
|
|
|
test("default config: disabled", () => {
|
|
const config = getSystemPromptConfig();
|
|
assert.equal(config.enabled, false);
|
|
assert.equal(config.prompt, "");
|
|
});
|
|
|
|
// ─── Injection ──────────────────────────────────────────────────────────────
|
|
|
|
test("injectSystemPrompt: disabled → no change", () => {
|
|
setSystemPromptConfig({ enabled: false, prompt: "system" });
|
|
const body = { messages: [{ role: "user", content: "hi" }] };
|
|
const result = injectSystemPrompt(body);
|
|
assert.deepEqual(result, body);
|
|
});
|
|
|
|
test("injectSystemPrompt: adds system message when none exists", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "You are an AI assistant." });
|
|
const body = { messages: [{ role: "user", content: "hi" }] };
|
|
const result = injectSystemPrompt(body);
|
|
assert.equal(result.messages[0].role, "system");
|
|
assert.ok(result.messages[0].content.includes("You are an AI assistant."));
|
|
assert.equal(result.messages.length, 2);
|
|
});
|
|
|
|
test("injectSystemPrompt: prepends to existing system message", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "GLOBAL:" });
|
|
const body = {
|
|
messages: [
|
|
{ role: "system", content: "Original prompt" },
|
|
{ role: "user", content: "hi" },
|
|
],
|
|
};
|
|
const result = injectSystemPrompt(body);
|
|
assert.ok(result.messages[0].content.startsWith("GLOBAL:"));
|
|
assert.ok(result.messages[0].content.includes("Original prompt"));
|
|
assert.equal(result.messages.length, 2);
|
|
});
|
|
|
|
test("injectSystemPrompt: Claude body.system field", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "GLOBAL:" });
|
|
const body = {
|
|
system: "Claude prompt",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
};
|
|
const result = injectSystemPrompt(body);
|
|
assert.ok(result.system.startsWith("GLOBAL:"));
|
|
assert.ok(result.system.includes("Claude prompt"));
|
|
});
|
|
|
|
test("injectSystemPrompt: Claude array system field", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "GLOBAL:" });
|
|
const body = {
|
|
system: [{ type: "text", text: "Claude prompt" }],
|
|
messages: [{ role: "user", content: "hi" }],
|
|
};
|
|
const result = injectSystemPrompt(body);
|
|
assert.ok(Array.isArray(result.system));
|
|
assert.equal(result.system[0].text, "GLOBAL:");
|
|
assert.equal(result.system.length, 2);
|
|
});
|
|
|
|
test("injectSystemPrompt: _skipSystemPrompt bypasses", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "GLOBAL:" });
|
|
const body = {
|
|
_skipSystemPrompt: true,
|
|
messages: [{ role: "user", content: "hi" }],
|
|
};
|
|
const result = injectSystemPrompt(body);
|
|
assert.deepEqual(result, body);
|
|
});
|
|
|
|
test("injectSystemPrompt: with explicit promptText override", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "default" });
|
|
const body = { messages: [{ role: "user", content: "hi" }] };
|
|
const result = injectSystemPrompt(body, "custom override");
|
|
assert.ok(result.messages[0].content.includes("custom override"));
|
|
});
|
|
|
|
test("injectSystemPrompt: null body returns as-is", () => {
|
|
setSystemPromptConfig({ enabled: true, prompt: "test" });
|
|
assert.equal(injectSystemPrompt(null), null);
|
|
});
|
|
|
|
// Reset
|
|
test.after(() => setSystemPromptConfig({ enabled: false, prompt: "" }));
|