CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (pull_request) Successful in 3s
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (pull_request) Successful in 22s
CI (SIAX Cloud) / security (push) Successful in 23s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 23s
CI (SIAX Cloud) / integration (pull_request) Successful in 30s
CI (SIAX Cloud) / quality (push) Successful in 45s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m18s
- DecisionOllamaGatewayClient calls the self-hosted Ollama on server-decision-01 (tailnet HTTP only for loopback/RFC1918/100.64-127), keeps the same local admission and reports providerKind=local. - createInf0Gateway prefers it over INF0/LiteLLM when configured. - Evidence is computed deterministically from values when a small model omits offsets; a value must occur exactly once in the source or the result goes to review. This makes a 9B local model usable without weakening verification. Tests: 4 new gateway cases + 2 evidence-derivation cases; full typecheck green.
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
/**
|
|
* Resolve the live INF0 inference path.
|
|
*
|
|
* Preference order:
|
|
* 1. DECISION_OLLAMA_URL + DECISION_OLLAMA_MODEL (self-hosted model on the
|
|
* SIAX decision server; interim path while the external model API is on
|
|
* hold — no provider key, no per-token cost, nothing leaves the fleet)
|
|
* 2. INF0_GATEWAY_LITELLM_KEY + INF0_GATEWAY_URL (live LiteLLM)
|
|
* 3. INF0_URL + INF0_API_TOKEN (native `/v1/inf0/*` surface, contract-only)
|
|
*
|
|
* Returns `undefined` when neither is configured, so the caller can fail
|
|
* closed with an explicit "not configured" response.
|
|
*/
|
|
import { DecisionOllamaGatewayClient } from './decision-ollama-client';
|
|
import { Inf0GatewayClient } from './inf0-gateway-client';
|
|
import { LiteLlmGatewayClient } from './litellm-gateway-client';
|
|
import { isTrustedHttpsUrl } from './runtime-config';
|
|
|
|
export interface Inf0Gateway {
|
|
complete(input: Parameters<Inf0GatewayClient['complete']>[0]): ReturnType<Inf0GatewayClient['complete']>;
|
|
}
|
|
|
|
export function createInf0Gateway(env: NodeJS.ProcessEnv = process.env): Inf0Gateway | undefined {
|
|
const decisionUrl = env.DECISION_OLLAMA_URL?.trim();
|
|
const decisionModel = env.DECISION_OLLAMA_MODEL?.trim();
|
|
if (decisionUrl && decisionModel) {
|
|
try {
|
|
return new DecisionOllamaGatewayClient({
|
|
baseUrl: decisionUrl,
|
|
model: decisionModel,
|
|
});
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
const litellmKey = env.INF0_GATEWAY_LITELLM_KEY?.trim();
|
|
const litellmUrl = env.INF0_GATEWAY_URL?.trim() || 'https://ai-gateway.siax.io/v1';
|
|
if (litellmKey && isTrustedHttpsUrl(litellmUrl)) {
|
|
try {
|
|
return new LiteLlmGatewayClient({
|
|
baseUrl: litellmUrl,
|
|
apiKey: litellmKey,
|
|
providerKind: env.INF0_GATEWAY_PROVIDER_KIND === 'local' ? 'local' : 'external',
|
|
});
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
const baseUrl = env.INF0_URL ?? env.INF0_API_URL;
|
|
const token = env.INF0_API_TOKEN ?? env.INF0_SERVICE_TOKEN;
|
|
if (isTrustedHttpsUrl(baseUrl) && token?.trim()) {
|
|
try {
|
|
return new Inf0GatewayClient({ baseUrl, serviceToken: token.trim() });
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|