@x12i/ai-gateway 10.2.0 → 10.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/ai-tools-client.d.ts +1 -1
- package/dist/ai-tools-client.js +4 -4
- package/dist/gateway-config.d.ts +1 -1
- package/dist/gateway-config.js +5 -5
- package/dist/gateway-utils.d.ts +1 -1
- package/dist/gateway-utils.js +3 -3
- package/dist/gateway.d.ts +1 -1
- package/dist/gateway.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/invoke-model-ingress.d.ts +1 -1
- package/dist/invoke-model-ingress.js +2 -2
- package/dist/openrouter-routing.d.ts +5 -9
- package/dist/openrouter-routing.js +8 -20
- package/dist/types.d.ts +2 -3
- package/dist-cjs/ai-tools-client.cjs +4 -4
- package/dist-cjs/ai-tools-client.d.ts +1 -1
- package/dist-cjs/gateway-config.cjs +5 -5
- package/dist-cjs/gateway-config.d.ts +1 -1
- package/dist-cjs/gateway-utils.cjs +3 -3
- package/dist-cjs/gateway-utils.d.ts +1 -1
- package/dist-cjs/gateway.cjs +4 -4
- package/dist-cjs/gateway.d.ts +1 -1
- package/dist-cjs/index.cjs +1 -1
- package/dist-cjs/index.d.ts +1 -1
- package/dist-cjs/invoke-model-ingress.cjs +2 -2
- package/dist-cjs/invoke-model-ingress.d.ts +1 -1
- package/dist-cjs/openrouter-routing.cjs +8 -20
- package/dist-cjs/openrouter-routing.d.ts +5 -9
- package/dist-cjs/types.d.ts +2 -3
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ console.log(response.content, response.metadata?.costUsd, response.metadata?.tok
|
|
|
88
88
|
### Providers without manual `register()`
|
|
89
89
|
|
|
90
90
|
- **OpenRouter:** Set **`OPENROUTER_API_KEY`** in `.env`. The gateway always passes this key to the router when set. **By default, OpenRouter is preferred** for routing (including when you also have direct keys such as `OPENAI_API_KEY`). **`@x12i/ai-tools`** resolves concrete model ids + provider via `resolveInvokeModel()` (catalog normalization, OpenRouter vs direct transport, router proxy flags). Pass catalog model ids such as `openai/gpt-4o-mini` or `{ provider: 'openrouter', model: 'deepseek/deepseek-v4-pro' }`. Composite display slugs like `openrouter/deepseek/deepseek-v4-pro` are split at ingress (see **Invoke model ingress** below). Profile/choice aliases (`cheap/default`, …) must be resolved upstream (ai-tasks / `resolveAIProfile`) — the gateway rejects them with **`GATEWAY_ALIAS_MODEL_REJECTED`**.
|
|
91
|
-
- **`
|
|
91
|
+
- **`PREFER_OPENROUTER=false`:** Do **not** prefer OpenRouter when a direct provider API key exists — use the direct provider instead. OpenRouter is **still** used as **fallback** when the request targets a provider without a direct key (e.g. `anthropic` without `ANTHROPIC_API_KEY`). It does not disable OpenRouter while `OPENROUTER_API_KEY` is set.
|
|
92
92
|
- **Direct providers:** Set `OPENAI_API_KEY`, `GROK_API_KEY`, etc. Registered lazily on first invoke.
|
|
93
93
|
|
|
94
94
|
Details: [OpenRouter env](./docs/OPENROUTER_ENV.md).
|
|
@@ -191,7 +191,7 @@ Instructions must be **complete caller text** — the gateway no longer injects
|
|
|
191
191
|
| `AI_GATEWAY_VERBOSE` | Full payload lines (still requires `AI_GATEWAY_LOGS_LEVEL=verbose`) |
|
|
192
192
|
| `LOGXER_PACKAGE_LEVELS` | Bulk stack levels, e.g. `AI_GATEWAY:info,AI_PROVIDER_ROUTER:debug` |
|
|
193
193
|
| `OPENROUTER_API_KEY` | OpenRouter key; always wired when set (required for OpenRouter transport) |
|
|
194
|
-
| `
|
|
194
|
+
| `PREFER_OPENROUTER` | Optional; default **prefer** OpenRouter when key is set. `false` = use direct provider keys when present; OpenRouter still used as fallback when a provider has no key |
|
|
195
195
|
| Other provider keys | `OPENAI_API_KEY`, `GROK_API_KEY`, etc. |
|
|
196
196
|
|
|
197
197
|
Logging details: [Logger initialization](./docs/LOGGER_INITIALIZATION.md). Package identity and audit checklist: [LOGXER_INTEGRATION_CHECKLIST.md](./docs/LOGXER_INTEGRATION_CHECKLIST.md).
|
|
@@ -256,7 +256,7 @@ Implemented in **`resolveCostCompletionWithAiTools`** only ( **`CostCalculator.c
|
|
|
256
256
|
|
|
257
257
|
- **No Catalox / Firestore** — catalogs come from ai-tools open-assets JSON (optional **`bundledOnly`**).
|
|
258
258
|
|
|
259
|
-
Gateway exports the model orchestrator from `@x12i/ai-tools` ≥ **3.
|
|
259
|
+
Gateway exports the model orchestrator from `@x12i/ai-tools` ≥ **3.3.0** (`resolveInvokeModel`, `preferOpenRouter`, …). Profile/choice keys (`cheap/default`, …) must be resolved **before** invoke — the gateway does not run alias resolution. Shortcuts like `cheapest` / bare `cheap` are rejected at ingress or catalog resolution.
|
|
260
260
|
|
|
261
261
|
Gateway billing helpers (exported for tests/integrators): `resolveCostCompletionWithAiTools`, `buildGatewayPricingRecord`, `catalogPricingSucceeded`, `buildTraceUsageSummary`, `enrichTraceAttemptsWithBilling`.
|
|
262
262
|
|
|
@@ -358,7 +358,7 @@ Full index: **[docs/README.md](./docs/README.md)**. Upstream gaps: **[docs/upstr
|
|
|
358
358
|
|----------|--------|
|
|
359
359
|
| [AI_GATEWAY_INVOKE_EXECUTION_METADATA.md](./docs/AI_GATEWAY_INVOKE_EXECUTION_METADATA.md) | Metadata, cost, trace, Activix completion |
|
|
360
360
|
| [IDENTITY_OBJECT_CONTRACT.md](./docs/IDENTITY_OBJECT_CONTRACT.md) | Identity / `runContext` |
|
|
361
|
-
| [OPENROUTER_ENV.md](./docs/OPENROUTER_ENV.md) | `OPENROUTER_API_KEY` and `
|
|
361
|
+
| [OPENROUTER_ENV.md](./docs/OPENROUTER_ENV.md) | `OPENROUTER_API_KEY` and `PREFER_OPENROUTER` |
|
|
362
362
|
| [UPSTREAM_PROFILE_RESOLUTION_AND_OPENROUTER_FALLBACK.md](./docs/UPSTREAM_PROFILE_RESOLUTION_AND_OPENROUTER_FALLBACK.md) | Profile routing + OpenRouter fallback |
|
|
363
363
|
| [UPSTREAM_TEMPLATE_RENDERING_AND_PARSER_V4.md](./docs/UPSTREAM_TEMPLATE_RENDERING_AND_PARSER_V4.md) | Parser v4 + `template-rendering.json` |
|
|
364
364
|
| [GRAPH_EXECUTION_SUPPORT.md](./docs/GRAPH_EXECUTION_SUPPORT.md) | Graph / node identity |
|
|
@@ -9,7 +9,7 @@ export type AiToolsClientBundle = AiToolsInvokeClient;
|
|
|
9
9
|
export { resolveInvokeModel, applyOpenRouterInvokeRouting, buildInvokeModelResolverOptions, enrichModelResolutionError, mapResolutionToRouterConfig, ModelProfileUnroutableError, ModelProfileInputRejectedError, MODEL_PROFILE_UNROUTABLE, getAiToolsInvokeClient, resetAiToolsInvokeClientForTests as resetAiToolsInvokeClientForTestsUpstream, createAiToolsInvokeClient, } from '@x12i/ai-tools';
|
|
10
10
|
/** @deprecated Use `applyOpenRouterInvokeRouting` (ai-tools v3). */
|
|
11
11
|
export { applyOpenRouterInvokeRouting as applyOpenRouterInvokePolicy } from '@x12i/ai-tools';
|
|
12
|
-
export { resolveOpenRouterApiKey,
|
|
12
|
+
export { resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, } from './openrouter-routing.js';
|
|
13
13
|
export type { InvokeModelResolutionDiagnostics, InvokeModelResolutionInput, InvokeModelResolutionOptions, InvokeModelResolutionResult, InvokeRouterConfigSlice, AiToolsInvokeClient, } from '@x12i/ai-tools';
|
|
14
14
|
/** @deprecated Use buildInvokeModelResolverOptions */
|
|
15
15
|
export declare function buildModelResolverOptions(config: GatewayConfig, routingEnv?: OpenRouterRoutingConfig): import("@x12i/ai-tools").ModelResolverOptions;
|
package/dist/ai-tools-client.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { getAiToolsInvokeClient, resetAiToolsInvokeClientForTests as resetAiToolsInvokeClientForTestsUpstream, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, CostCalculator, } from '@x12i/ai-tools';
|
|
6
6
|
import { gatewayLogDebug, withActivityIdentity } from './gateway-log-meta.js';
|
|
7
|
-
import {
|
|
7
|
+
import { resolvePreferOpenRouter } from './openrouter-routing.js';
|
|
8
8
|
export { resolveInvokeModel, applyOpenRouterInvokeRouting, buildInvokeModelResolverOptions, enrichModelResolutionError, mapResolutionToRouterConfig, ModelProfileUnroutableError, ModelProfileInputRejectedError, MODEL_PROFILE_UNROUTABLE, getAiToolsInvokeClient, resetAiToolsInvokeClientForTests as resetAiToolsInvokeClientForTestsUpstream, createAiToolsInvokeClient, } from '@x12i/ai-tools';
|
|
9
9
|
/** @deprecated Use `applyOpenRouterInvokeRouting` (ai-tools v3). */
|
|
10
10
|
export { applyOpenRouterInvokeRouting as applyOpenRouterInvokePolicy } from '@x12i/ai-tools';
|
|
11
|
-
export { resolveOpenRouterApiKey,
|
|
11
|
+
export { resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, } from './openrouter-routing.js';
|
|
12
12
|
let bootstrapFailedLogged = false;
|
|
13
13
|
function invokeClientOptions(config) {
|
|
14
14
|
return {
|
|
@@ -29,7 +29,7 @@ function withCatalogLaneCalculator(client, config) {
|
|
|
29
29
|
resolverOptions: buildInvokeModelResolverOptions({
|
|
30
30
|
routingEnv: client.routingEnv,
|
|
31
31
|
catalogLane: lane,
|
|
32
|
-
|
|
32
|
+
preferOpenRouter: resolvePreferOpenRouter(config),
|
|
33
33
|
})
|
|
34
34
|
})
|
|
35
35
|
};
|
|
@@ -38,7 +38,7 @@ function withCatalogLaneCalculator(client, config) {
|
|
|
38
38
|
export function buildModelResolverOptions(config, routingEnv) {
|
|
39
39
|
return buildInvokeModelResolverOptions({
|
|
40
40
|
routingEnv,
|
|
41
|
-
|
|
41
|
+
preferOpenRouter: resolvePreferOpenRouter(config),
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
/**
|
package/dist/gateway-config.d.ts
CHANGED
|
@@ -37,6 +37,6 @@ export declare function initializeGatewayComponents(config: GatewayConfig): {
|
|
|
37
37
|
activityManager: ActivityManager;
|
|
38
38
|
usageTracker: UsageTracker;
|
|
39
39
|
messageBuilderConfig: MessageBuilderConfig;
|
|
40
|
-
|
|
40
|
+
preferOpenRouter: boolean;
|
|
41
41
|
openRouterApiKey?: string;
|
|
42
42
|
};
|
package/dist/gateway-config.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
|
-
import { resolveOpenRouterApiKey,
|
|
8
|
+
import { resolveOpenRouterApiKey, resolvePreferOpenRouter, } from './openrouter-routing.js';
|
|
9
9
|
import { LLMProviderRouter } from '@x12i/ai-providers-router';
|
|
10
10
|
import { createGatewayLogger } from './logger-factory.js';
|
|
11
11
|
import { ActivityManager } from './activity-manager.js';
|
|
@@ -154,14 +154,14 @@ export function initializeGatewayComponents(config) {
|
|
|
154
154
|
if (config.logging !== undefined)
|
|
155
155
|
routerConfig.logging = config.logging;
|
|
156
156
|
const openRouterKey = resolveOpenRouterApiKey(config);
|
|
157
|
-
const
|
|
157
|
+
const preferOpenRouter = resolvePreferOpenRouter(config);
|
|
158
158
|
if (openRouterKey) {
|
|
159
159
|
routerConfig.openrouter = { apiKey: openRouterKey };
|
|
160
160
|
routerConfig.openRouter = {
|
|
161
161
|
enabled: true,
|
|
162
|
-
prefer:
|
|
162
|
+
prefer: preferOpenRouter,
|
|
163
163
|
};
|
|
164
|
-
if (
|
|
164
|
+
if (preferOpenRouter) {
|
|
165
165
|
routerConfig.defaultMode = 'openrouter';
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -190,7 +190,7 @@ export function initializeGatewayComponents(config) {
|
|
|
190
190
|
activityManager,
|
|
191
191
|
usageTracker,
|
|
192
192
|
messageBuilderConfig,
|
|
193
|
-
|
|
193
|
+
preferOpenRouter,
|
|
194
194
|
openRouterApiKey: openRouterKey,
|
|
195
195
|
};
|
|
196
196
|
}
|
package/dist/gateway-utils.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type MergeConfigOptions = {
|
|
|
17
17
|
catalog?: AiModelsCatalogClient | null;
|
|
18
18
|
routingEnv?: OpenRouterRoutingConfig;
|
|
19
19
|
openRouterApiKey?: string;
|
|
20
|
-
|
|
20
|
+
preferOpenRouter?: boolean;
|
|
21
21
|
};
|
|
22
22
|
export { MODEL_PROFILE_UNROUTABLE, ModelProfileUnroutableError, ModelProfileInputRejectedError, } from '@x12i/ai-tools';
|
|
23
23
|
/**
|
package/dist/gateway-utils.js
CHANGED
|
@@ -100,7 +100,7 @@ export async function mergeConfig(request, config, logger, mergeOptions) {
|
|
|
100
100
|
throw new ModelRequiredError();
|
|
101
101
|
}
|
|
102
102
|
const ingress = normalizeInvokeModelAtIngress(merged.provider, explicitModel, {
|
|
103
|
-
|
|
103
|
+
preferOpenRouter: mergeOptions?.preferOpenRouter,
|
|
104
104
|
});
|
|
105
105
|
if (ingress.changed) {
|
|
106
106
|
logger.verbose('Invoke model normalized at ingress', {
|
|
@@ -121,7 +121,7 @@ export async function mergeConfig(request, config, logger, mergeOptions) {
|
|
|
121
121
|
catalog: mergeOptions.catalog,
|
|
122
122
|
routingEnv: mergeOptions.routingEnv,
|
|
123
123
|
openRouterApiKey: mergeOptions.openRouterApiKey,
|
|
124
|
-
|
|
124
|
+
preferOpenRouter: mergeOptions.preferOpenRouter,
|
|
125
125
|
defaultProvider: config.defaultEngine,
|
|
126
126
|
resolveModels: true,
|
|
127
127
|
modelsOnly: config.aiTools?.modelsOnly !== false,
|
|
@@ -163,7 +163,7 @@ export async function mergeConfig(request, config, logger, mergeOptions) {
|
|
|
163
163
|
resolveModels: false,
|
|
164
164
|
routingEnv: mergeOptions.routingEnv,
|
|
165
165
|
openRouterApiKey: mergeOptions.openRouterApiKey,
|
|
166
|
-
|
|
166
|
+
preferOpenRouter: mergeOptions.preferOpenRouter,
|
|
167
167
|
defaultProvider: config.defaultEngine,
|
|
168
168
|
});
|
|
169
169
|
merged.provider = resolved.router.provider;
|
package/dist/gateway.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class AIGateway {
|
|
|
18
18
|
private messageBuilderConfig?;
|
|
19
19
|
private _autoRegisterDone;
|
|
20
20
|
private _aiToolsClient;
|
|
21
|
-
private readonly
|
|
21
|
+
private readonly preferOpenRouter;
|
|
22
22
|
private readonly openRouterApiKey?;
|
|
23
23
|
constructor(config?: GatewayConfig, activityManager?: ActivityManager);
|
|
24
24
|
/**
|
package/dist/gateway.js
CHANGED
|
@@ -59,7 +59,7 @@ export class AIGateway {
|
|
|
59
59
|
messageBuilderConfig;
|
|
60
60
|
_autoRegisterDone = false;
|
|
61
61
|
_aiToolsClient = null;
|
|
62
|
-
|
|
62
|
+
preferOpenRouter;
|
|
63
63
|
openRouterApiKey;
|
|
64
64
|
constructor(config = {}, activityManager) {
|
|
65
65
|
this.config = config;
|
|
@@ -69,7 +69,7 @@ export class AIGateway {
|
|
|
69
69
|
this.router = components.router;
|
|
70
70
|
this.activityManager = components.activityManager;
|
|
71
71
|
this.messageBuilderConfig = components.messageBuilderConfig;
|
|
72
|
-
this.
|
|
72
|
+
this.preferOpenRouter = components.preferOpenRouter;
|
|
73
73
|
this.openRouterApiKey = components.openRouterApiKey;
|
|
74
74
|
setGatewayRuntimeClients({
|
|
75
75
|
activix: this.activityManager?.getTracker(),
|
|
@@ -100,7 +100,7 @@ export class AIGateway {
|
|
|
100
100
|
catalog: aiTools?.catalog ?? null,
|
|
101
101
|
routingEnv: aiTools?.routingEnv,
|
|
102
102
|
openRouterApiKey: this.openRouterApiKey,
|
|
103
|
-
|
|
103
|
+
preferOpenRouter: this.preferOpenRouter,
|
|
104
104
|
});
|
|
105
105
|
// Activix start snapshot must match what the router receives (modelConfig-only callers omit request.config.model).
|
|
106
106
|
request._mergedRouterConfig = mergedConfig;
|
|
@@ -288,7 +288,7 @@ export class AIGateway {
|
|
|
288
288
|
catalog: aiTools?.catalog ?? null,
|
|
289
289
|
routingEnv: aiTools?.routingEnv,
|
|
290
290
|
openRouterApiKey: this.openRouterApiKey,
|
|
291
|
-
|
|
291
|
+
preferOpenRouter: this.preferOpenRouter,
|
|
292
292
|
});
|
|
293
293
|
request._mergedRouterConfig = mergedConfig;
|
|
294
294
|
logResolvedModelRouting(this.logger, request, mergedConfig);
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFI
|
|
|
42
42
|
export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
|
|
43
43
|
export type { GatewayLogCode as GatewayDiagnosticCode } from './gateway-log-diagnostics.js';
|
|
44
44
|
/** Re-export @x12i/ai-tools invoke orchestrator (≥ 3.0.0) for engine callers. */
|
|
45
|
-
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey,
|
|
45
|
+
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, getAiToolsInvokeClient, createAiToolsInvokeClient, } from './ai-tools-client.js';
|
|
46
46
|
export type { AiToolsClientBundle, AiToolsInvokeClient, InvokeModelResolutionDiagnostics, InvokeModelResolutionInput, InvokeModelResolutionOptions, InvokeModelResolutionResult, InvokeRouterConfigSlice, } from './ai-tools-client.js';
|
|
47
47
|
export { createLogxer, DebugLogAbstract, runWithLogContext, getStationRuntimeIdentity, mergeRuntimeIdentity, conditionEvidence, sourceEvidence, logReferenceEvidence, readAgentLoggingInstructions, resolveAgentLoggingInstructionsPath, applyPackageLogLevelsFromEnv, configurePackageLogLevels, mergePackageLogLevelsConfig, setPackageLogLevel, resolveStackLogLevelForPrefix, resolvePackageLogsLevel, parseLogxerPackageLevelsEnv, LOGXER_PACKAGE_LEVELS_ENV, LOGXER_PACKAGE_LOGS_DEFAULT_ENV } from '@x12i/logxer';
|
|
48
48
|
export { ROUTER_LOG_ENV_PREFIX } from '@x12i/ai-providers-router';
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ export { createGatewayLogger, resolveGatewayVerboseEnabled } from './logger-fact
|
|
|
35
35
|
export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
|
|
36
36
|
export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
|
|
37
37
|
/** Re-export @x12i/ai-tools invoke orchestrator (≥ 3.0.0) for engine callers. */
|
|
38
|
-
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey,
|
|
38
|
+
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, getAiToolsInvokeClient, createAiToolsInvokeClient, } from './ai-tools-client.js';
|
|
39
39
|
// Re-export logging (@x12i/logxer)
|
|
40
40
|
export { createLogxer, DebugLogAbstract, runWithLogContext, getStationRuntimeIdentity, mergeRuntimeIdentity, conditionEvidence, sourceEvidence, logReferenceEvidence, readAgentLoggingInstructions, resolveAgentLoggingInstructionsPath, applyPackageLogLevelsFromEnv, configurePackageLogLevels, mergePackageLogLevelsConfig, setPackageLogLevel, resolveStackLogLevelForPrefix, resolvePackageLogsLevel, parseLogxerPackageLevelsEnv, LOGXER_PACKAGE_LEVELS_ENV, LOGXER_PACKAGE_LOGS_DEFAULT_ENV } from '@x12i/logxer';
|
|
41
41
|
export { ROUTER_LOG_ENV_PREFIX } from '@x12i/ai-providers-router';
|
|
@@ -33,8 +33,8 @@ export function normalizeInvokeModelAtIngress(provider, model, options = {}) {
|
|
|
33
33
|
model: inputModel,
|
|
34
34
|
provider: inputProvider,
|
|
35
35
|
routing: 'auto',
|
|
36
|
-
|
|
37
|
-
}, {
|
|
36
|
+
preferOpenRouter: options.preferOpenRouter,
|
|
37
|
+
}, { preferOpenRouter: options.preferOpenRouter });
|
|
38
38
|
const changed = normalized.provider !== (inputProvider?.toLowerCase() ?? inputProvider) ||
|
|
39
39
|
normalized.model !== inputModel;
|
|
40
40
|
return {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gateway-level OpenRouter key +
|
|
2
|
+
* Gateway-level OpenRouter key + PREFER_OPENROUTER flags mapped to @x12i/ai-tools invoke helpers.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { readPreferOpenRouterFromEnv } from '@x12i/ai-profiles';
|
|
5
5
|
import type { GatewayConfig } from './types.js';
|
|
6
|
-
export {
|
|
6
|
+
export { readPreferOpenRouterFromEnv };
|
|
7
7
|
export declare function resolveOpenRouterApiKey(config?: GatewayConfig): string | undefined;
|
|
8
8
|
/**
|
|
9
|
-
* Effective OpenRouter preference for invoke-time routing (ai-tools `
|
|
10
|
-
* Constructor `openRouter.prefer`
|
|
9
|
+
* Effective OpenRouter preference for invoke-time routing (ai-tools `preferOpenRouter`).
|
|
10
|
+
* Constructor `openRouter.prefer` overrides env `PREFER_OPENROUTER`.
|
|
11
11
|
*/
|
|
12
|
-
export declare function resolveUseOpenRouter(config?: GatewayConfig): boolean;
|
|
13
|
-
/** @deprecated Use {@link resolveUseOpenRouter} (ai-tools v3 renamed prefer → useOpenRouter). */
|
|
14
12
|
export declare function resolvePreferOpenRouter(config?: GatewayConfig): boolean;
|
|
15
|
-
/** @deprecated Use {@link readUseOpenRouterFromEnv} from `@x12i/ai-profiles`. */
|
|
16
|
-
export declare function readPreferOpenRouterFromEnv(): boolean;
|
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gateway-level OpenRouter key +
|
|
2
|
+
* Gateway-level OpenRouter key + PREFER_OPENROUTER flags mapped to @x12i/ai-tools invoke helpers.
|
|
3
3
|
*/
|
|
4
|
-
import { resolveOpenRouterApiKey as resolveOpenRouterApiKeyFromTools,
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
4
|
+
import { resolveOpenRouterApiKey as resolveOpenRouterApiKeyFromTools, resolvePreferOpenRouterPreference, } from '@x12i/ai-tools';
|
|
5
|
+
import { readPreferOpenRouterFromEnv } from '@x12i/ai-profiles';
|
|
6
|
+
export { readPreferOpenRouterFromEnv };
|
|
7
7
|
export function resolveOpenRouterApiKey(config = {}) {
|
|
8
8
|
return resolveOpenRouterApiKeyFromTools(config.openrouter?.apiKey);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Effective OpenRouter preference for invoke-time routing (ai-tools `
|
|
12
|
-
* Constructor `openRouter.prefer`
|
|
11
|
+
* Effective OpenRouter preference for invoke-time routing (ai-tools `preferOpenRouter`).
|
|
12
|
+
* Constructor `openRouter.prefer` overrides env `PREFER_OPENROUTER`.
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
14
|
+
export function resolvePreferOpenRouter(config = {}) {
|
|
15
15
|
if (config.openRouter?.prefer === true)
|
|
16
16
|
return true;
|
|
17
17
|
if (config.openRouter?.prefer === false)
|
|
18
18
|
return false;
|
|
19
|
-
|
|
20
|
-
return true;
|
|
21
|
-
if (config.openRouter?.enabled === false)
|
|
22
|
-
return false;
|
|
23
|
-
return resolveUseOpenRouterPreference();
|
|
24
|
-
}
|
|
25
|
-
/** @deprecated Use {@link resolveUseOpenRouter} (ai-tools v3 renamed prefer → useOpenRouter). */
|
|
26
|
-
export function resolvePreferOpenRouter(config = {}) {
|
|
27
|
-
return resolveUseOpenRouter(config);
|
|
28
|
-
}
|
|
29
|
-
/** @deprecated Use {@link readUseOpenRouterFromEnv} from `@x12i/ai-profiles`. */
|
|
30
|
-
export function readPreferOpenRouterFromEnv() {
|
|
31
|
-
return readUseOpenRouterFromEnv() ?? true;
|
|
19
|
+
return resolvePreferOpenRouterPreference();
|
|
32
20
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -391,11 +391,10 @@ export interface GatewayConfig extends Omit<RouterConfig, 'defaultEngine' | 'log
|
|
|
391
391
|
};
|
|
392
392
|
/**
|
|
393
393
|
* OpenRouter preference (not a hard off-switch when {@link openrouter}.apiKey or OPENROUTER_API_KEY is set).
|
|
394
|
-
* - `prefer: true`
|
|
395
|
-
* - `prefer: false`
|
|
394
|
+
* - `prefer: true` or omitted env (default true): prefer OpenRouter when OPENROUTER_API_KEY is present.
|
|
395
|
+
* - `prefer: false` or PREFER_OPENROUTER=false: use direct providers when their API keys exist; OpenRouter still used as fallback when a requested provider has no key.
|
|
396
396
|
*/
|
|
397
397
|
openRouter?: {
|
|
398
|
-
enabled?: boolean;
|
|
399
398
|
prefer?: boolean;
|
|
400
399
|
};
|
|
401
400
|
/**
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { getAiToolsInvokeClient, resetAiToolsInvokeClientForTests as resetAiToolsInvokeClientForTestsUpstream, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, CostCalculator, } from '@x12i/ai-tools';
|
|
6
6
|
import { gatewayLogDebug, withActivityIdentity } from './gateway-log-meta.js';
|
|
7
|
-
import {
|
|
7
|
+
import { resolvePreferOpenRouter } from './openrouter-routing.js';
|
|
8
8
|
export { resolveInvokeModel, applyOpenRouterInvokeRouting, buildInvokeModelResolverOptions, enrichModelResolutionError, mapResolutionToRouterConfig, ModelProfileUnroutableError, ModelProfileInputRejectedError, MODEL_PROFILE_UNROUTABLE, getAiToolsInvokeClient, resetAiToolsInvokeClientForTests as resetAiToolsInvokeClientForTestsUpstream, createAiToolsInvokeClient, } from '@x12i/ai-tools';
|
|
9
9
|
/** @deprecated Use `applyOpenRouterInvokeRouting` (ai-tools v3). */
|
|
10
10
|
export { applyOpenRouterInvokeRouting as applyOpenRouterInvokePolicy } from '@x12i/ai-tools';
|
|
11
|
-
export { resolveOpenRouterApiKey,
|
|
11
|
+
export { resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, } from './openrouter-routing.js';
|
|
12
12
|
let bootstrapFailedLogged = false;
|
|
13
13
|
function invokeClientOptions(config) {
|
|
14
14
|
return {
|
|
@@ -29,7 +29,7 @@ function withCatalogLaneCalculator(client, config) {
|
|
|
29
29
|
resolverOptions: buildInvokeModelResolverOptions({
|
|
30
30
|
routingEnv: client.routingEnv,
|
|
31
31
|
catalogLane: lane,
|
|
32
|
-
|
|
32
|
+
preferOpenRouter: resolvePreferOpenRouter(config),
|
|
33
33
|
})
|
|
34
34
|
})
|
|
35
35
|
};
|
|
@@ -38,7 +38,7 @@ function withCatalogLaneCalculator(client, config) {
|
|
|
38
38
|
export function buildModelResolverOptions(config, routingEnv) {
|
|
39
39
|
return buildInvokeModelResolverOptions({
|
|
40
40
|
routingEnv,
|
|
41
|
-
|
|
41
|
+
preferOpenRouter: resolvePreferOpenRouter(config),
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
@@ -9,7 +9,7 @@ export type AiToolsClientBundle = AiToolsInvokeClient;
|
|
|
9
9
|
export { resolveInvokeModel, applyOpenRouterInvokeRouting, buildInvokeModelResolverOptions, enrichModelResolutionError, mapResolutionToRouterConfig, ModelProfileUnroutableError, ModelProfileInputRejectedError, MODEL_PROFILE_UNROUTABLE, getAiToolsInvokeClient, resetAiToolsInvokeClientForTests as resetAiToolsInvokeClientForTestsUpstream, createAiToolsInvokeClient, } from '@x12i/ai-tools';
|
|
10
10
|
/** @deprecated Use `applyOpenRouterInvokeRouting` (ai-tools v3). */
|
|
11
11
|
export { applyOpenRouterInvokeRouting as applyOpenRouterInvokePolicy } from '@x12i/ai-tools';
|
|
12
|
-
export { resolveOpenRouterApiKey,
|
|
12
|
+
export { resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, } from './openrouter-routing.js';
|
|
13
13
|
export type { InvokeModelResolutionDiagnostics, InvokeModelResolutionInput, InvokeModelResolutionOptions, InvokeModelResolutionResult, InvokeRouterConfigSlice, AiToolsInvokeClient, } from '@x12i/ai-tools';
|
|
14
14
|
/** @deprecated Use buildInvokeModelResolverOptions */
|
|
15
15
|
export declare function buildModelResolverOptions(config: GatewayConfig, routingEnv?: OpenRouterRoutingConfig): import("@x12i/ai-tools").ModelResolverOptions;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
|
-
import { resolveOpenRouterApiKey,
|
|
8
|
+
import { resolveOpenRouterApiKey, resolvePreferOpenRouter, } from './openrouter-routing.js';
|
|
9
9
|
import { LLMProviderRouter } from '@x12i/ai-providers-router';
|
|
10
10
|
import { createGatewayLogger } from './logger-factory.js';
|
|
11
11
|
import { ActivityManager } from './activity-manager.js';
|
|
@@ -154,14 +154,14 @@ export function initializeGatewayComponents(config) {
|
|
|
154
154
|
if (config.logging !== undefined)
|
|
155
155
|
routerConfig.logging = config.logging;
|
|
156
156
|
const openRouterKey = resolveOpenRouterApiKey(config);
|
|
157
|
-
const
|
|
157
|
+
const preferOpenRouter = resolvePreferOpenRouter(config);
|
|
158
158
|
if (openRouterKey) {
|
|
159
159
|
routerConfig.openrouter = { apiKey: openRouterKey };
|
|
160
160
|
routerConfig.openRouter = {
|
|
161
161
|
enabled: true,
|
|
162
|
-
prefer:
|
|
162
|
+
prefer: preferOpenRouter,
|
|
163
163
|
};
|
|
164
|
-
if (
|
|
164
|
+
if (preferOpenRouter) {
|
|
165
165
|
routerConfig.defaultMode = 'openrouter';
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -190,7 +190,7 @@ export function initializeGatewayComponents(config) {
|
|
|
190
190
|
activityManager,
|
|
191
191
|
usageTracker,
|
|
192
192
|
messageBuilderConfig,
|
|
193
|
-
|
|
193
|
+
preferOpenRouter,
|
|
194
194
|
openRouterApiKey: openRouterKey,
|
|
195
195
|
};
|
|
196
196
|
}
|
|
@@ -37,6 +37,6 @@ export declare function initializeGatewayComponents(config: GatewayConfig): {
|
|
|
37
37
|
activityManager: ActivityManager;
|
|
38
38
|
usageTracker: UsageTracker;
|
|
39
39
|
messageBuilderConfig: MessageBuilderConfig;
|
|
40
|
-
|
|
40
|
+
preferOpenRouter: boolean;
|
|
41
41
|
openRouterApiKey?: string;
|
|
42
42
|
};
|
|
@@ -100,7 +100,7 @@ export async function mergeConfig(request, config, logger, mergeOptions) {
|
|
|
100
100
|
throw new ModelRequiredError();
|
|
101
101
|
}
|
|
102
102
|
const ingress = normalizeInvokeModelAtIngress(merged.provider, explicitModel, {
|
|
103
|
-
|
|
103
|
+
preferOpenRouter: mergeOptions?.preferOpenRouter,
|
|
104
104
|
});
|
|
105
105
|
if (ingress.changed) {
|
|
106
106
|
logger.verbose('Invoke model normalized at ingress', {
|
|
@@ -121,7 +121,7 @@ export async function mergeConfig(request, config, logger, mergeOptions) {
|
|
|
121
121
|
catalog: mergeOptions.catalog,
|
|
122
122
|
routingEnv: mergeOptions.routingEnv,
|
|
123
123
|
openRouterApiKey: mergeOptions.openRouterApiKey,
|
|
124
|
-
|
|
124
|
+
preferOpenRouter: mergeOptions.preferOpenRouter,
|
|
125
125
|
defaultProvider: config.defaultEngine,
|
|
126
126
|
resolveModels: true,
|
|
127
127
|
modelsOnly: config.aiTools?.modelsOnly !== false,
|
|
@@ -163,7 +163,7 @@ export async function mergeConfig(request, config, logger, mergeOptions) {
|
|
|
163
163
|
resolveModels: false,
|
|
164
164
|
routingEnv: mergeOptions.routingEnv,
|
|
165
165
|
openRouterApiKey: mergeOptions.openRouterApiKey,
|
|
166
|
-
|
|
166
|
+
preferOpenRouter: mergeOptions.preferOpenRouter,
|
|
167
167
|
defaultProvider: config.defaultEngine,
|
|
168
168
|
});
|
|
169
169
|
merged.provider = resolved.router.provider;
|
|
@@ -17,7 +17,7 @@ export type MergeConfigOptions = {
|
|
|
17
17
|
catalog?: AiModelsCatalogClient | null;
|
|
18
18
|
routingEnv?: OpenRouterRoutingConfig;
|
|
19
19
|
openRouterApiKey?: string;
|
|
20
|
-
|
|
20
|
+
preferOpenRouter?: boolean;
|
|
21
21
|
};
|
|
22
22
|
export { MODEL_PROFILE_UNROUTABLE, ModelProfileUnroutableError, ModelProfileInputRejectedError, } from '@x12i/ai-tools';
|
|
23
23
|
/**
|
package/dist-cjs/gateway.cjs
CHANGED
|
@@ -59,7 +59,7 @@ export class AIGateway {
|
|
|
59
59
|
messageBuilderConfig;
|
|
60
60
|
_autoRegisterDone = false;
|
|
61
61
|
_aiToolsClient = null;
|
|
62
|
-
|
|
62
|
+
preferOpenRouter;
|
|
63
63
|
openRouterApiKey;
|
|
64
64
|
constructor(config = {}, activityManager) {
|
|
65
65
|
this.config = config;
|
|
@@ -69,7 +69,7 @@ export class AIGateway {
|
|
|
69
69
|
this.router = components.router;
|
|
70
70
|
this.activityManager = components.activityManager;
|
|
71
71
|
this.messageBuilderConfig = components.messageBuilderConfig;
|
|
72
|
-
this.
|
|
72
|
+
this.preferOpenRouter = components.preferOpenRouter;
|
|
73
73
|
this.openRouterApiKey = components.openRouterApiKey;
|
|
74
74
|
setGatewayRuntimeClients({
|
|
75
75
|
activix: this.activityManager?.getTracker(),
|
|
@@ -100,7 +100,7 @@ export class AIGateway {
|
|
|
100
100
|
catalog: aiTools?.catalog ?? null,
|
|
101
101
|
routingEnv: aiTools?.routingEnv,
|
|
102
102
|
openRouterApiKey: this.openRouterApiKey,
|
|
103
|
-
|
|
103
|
+
preferOpenRouter: this.preferOpenRouter,
|
|
104
104
|
});
|
|
105
105
|
// Activix start snapshot must match what the router receives (modelConfig-only callers omit request.config.model).
|
|
106
106
|
request._mergedRouterConfig = mergedConfig;
|
|
@@ -288,7 +288,7 @@ export class AIGateway {
|
|
|
288
288
|
catalog: aiTools?.catalog ?? null,
|
|
289
289
|
routingEnv: aiTools?.routingEnv,
|
|
290
290
|
openRouterApiKey: this.openRouterApiKey,
|
|
291
|
-
|
|
291
|
+
preferOpenRouter: this.preferOpenRouter,
|
|
292
292
|
});
|
|
293
293
|
request._mergedRouterConfig = mergedConfig;
|
|
294
294
|
logResolvedModelRouting(this.logger, request, mergedConfig);
|
package/dist-cjs/gateway.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class AIGateway {
|
|
|
18
18
|
private messageBuilderConfig?;
|
|
19
19
|
private _autoRegisterDone;
|
|
20
20
|
private _aiToolsClient;
|
|
21
|
-
private readonly
|
|
21
|
+
private readonly preferOpenRouter;
|
|
22
22
|
private readonly openRouterApiKey?;
|
|
23
23
|
constructor(config?: GatewayConfig, activityManager?: ActivityManager);
|
|
24
24
|
/**
|
package/dist-cjs/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ export { createGatewayLogger, resolveGatewayVerboseEnabled } from './logger-fact
|
|
|
35
35
|
export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
|
|
36
36
|
export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
|
|
37
37
|
/** Re-export @x12i/ai-tools invoke orchestrator (≥ 3.0.0) for engine callers. */
|
|
38
|
-
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey,
|
|
38
|
+
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, getAiToolsInvokeClient, createAiToolsInvokeClient, } from './ai-tools-client.js';
|
|
39
39
|
// Re-export logging (@x12i/logxer)
|
|
40
40
|
export { createLogxer, DebugLogAbstract, runWithLogContext, getStationRuntimeIdentity, mergeRuntimeIdentity, conditionEvidence, sourceEvidence, logReferenceEvidence, readAgentLoggingInstructions, resolveAgentLoggingInstructionsPath, applyPackageLogLevelsFromEnv, configurePackageLogLevels, mergePackageLogLevelsConfig, setPackageLogLevel, resolveStackLogLevelForPrefix, resolvePackageLogsLevel, parseLogxerPackageLevelsEnv, LOGXER_PACKAGE_LEVELS_ENV, LOGXER_PACKAGE_LOGS_DEFAULT_ENV } from '@x12i/logxer';
|
|
41
41
|
export { ROUTER_LOG_ENV_PREFIX } from '@x12i/ai-providers-router';
|
package/dist-cjs/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFI
|
|
|
42
42
|
export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
|
|
43
43
|
export type { GatewayLogCode as GatewayDiagnosticCode } from './gateway-log-diagnostics.js';
|
|
44
44
|
/** Re-export @x12i/ai-tools invoke orchestrator (≥ 3.0.0) for engine callers. */
|
|
45
|
-
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey,
|
|
45
|
+
export { resolveInvokeModel, applyModelResolution, applyOpenRouterInvokeRouting, applyOpenRouterInvokePolicy, mapResolutionToRouterConfig, buildInvokeModelResolverOptions, buildModelResolverOptions, enrichModelResolutionError, getAiToolsClient, resetAiToolsClientForTests, resolveOpenRouterApiKey, resolvePreferOpenRouter, readPreferOpenRouterFromEnv, getAiToolsInvokeClient, createAiToolsInvokeClient, } from './ai-tools-client.js';
|
|
46
46
|
export type { AiToolsClientBundle, AiToolsInvokeClient, InvokeModelResolutionDiagnostics, InvokeModelResolutionInput, InvokeModelResolutionOptions, InvokeModelResolutionResult, InvokeRouterConfigSlice, } from './ai-tools-client.js';
|
|
47
47
|
export { createLogxer, DebugLogAbstract, runWithLogContext, getStationRuntimeIdentity, mergeRuntimeIdentity, conditionEvidence, sourceEvidence, logReferenceEvidence, readAgentLoggingInstructions, resolveAgentLoggingInstructionsPath, applyPackageLogLevelsFromEnv, configurePackageLogLevels, mergePackageLogLevelsConfig, setPackageLogLevel, resolveStackLogLevelForPrefix, resolvePackageLogsLevel, parseLogxerPackageLevelsEnv, LOGXER_PACKAGE_LEVELS_ENV, LOGXER_PACKAGE_LOGS_DEFAULT_ENV } from '@x12i/logxer';
|
|
48
48
|
export { ROUTER_LOG_ENV_PREFIX } from '@x12i/ai-providers-router';
|
|
@@ -33,8 +33,8 @@ export function normalizeInvokeModelAtIngress(provider, model, options = {}) {
|
|
|
33
33
|
model: inputModel,
|
|
34
34
|
provider: inputProvider,
|
|
35
35
|
routing: 'auto',
|
|
36
|
-
|
|
37
|
-
}, {
|
|
36
|
+
preferOpenRouter: options.preferOpenRouter,
|
|
37
|
+
}, { preferOpenRouter: options.preferOpenRouter });
|
|
38
38
|
const changed = normalized.provider !== (inputProvider?.toLowerCase() ?? inputProvider) ||
|
|
39
39
|
normalized.model !== inputModel;
|
|
40
40
|
return {
|
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gateway-level OpenRouter key +
|
|
2
|
+
* Gateway-level OpenRouter key + PREFER_OPENROUTER flags mapped to @x12i/ai-tools invoke helpers.
|
|
3
3
|
*/
|
|
4
|
-
import { resolveOpenRouterApiKey as resolveOpenRouterApiKeyFromTools,
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
4
|
+
import { resolveOpenRouterApiKey as resolveOpenRouterApiKeyFromTools, resolvePreferOpenRouterPreference, } from '@x12i/ai-tools';
|
|
5
|
+
import { readPreferOpenRouterFromEnv } from '@x12i/ai-profiles';
|
|
6
|
+
export { readPreferOpenRouterFromEnv };
|
|
7
7
|
export function resolveOpenRouterApiKey(config = {}) {
|
|
8
8
|
return resolveOpenRouterApiKeyFromTools(config.openrouter?.apiKey);
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Effective OpenRouter preference for invoke-time routing (ai-tools `
|
|
12
|
-
* Constructor `openRouter.prefer`
|
|
11
|
+
* Effective OpenRouter preference for invoke-time routing (ai-tools `preferOpenRouter`).
|
|
12
|
+
* Constructor `openRouter.prefer` overrides env `PREFER_OPENROUTER`.
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
14
|
+
export function resolvePreferOpenRouter(config = {}) {
|
|
15
15
|
if (config.openRouter?.prefer === true)
|
|
16
16
|
return true;
|
|
17
17
|
if (config.openRouter?.prefer === false)
|
|
18
18
|
return false;
|
|
19
|
-
|
|
20
|
-
return true;
|
|
21
|
-
if (config.openRouter?.enabled === false)
|
|
22
|
-
return false;
|
|
23
|
-
return resolveUseOpenRouterPreference();
|
|
24
|
-
}
|
|
25
|
-
/** @deprecated Use {@link resolveUseOpenRouter} (ai-tools v3 renamed prefer → useOpenRouter). */
|
|
26
|
-
export function resolvePreferOpenRouter(config = {}) {
|
|
27
|
-
return resolveUseOpenRouter(config);
|
|
28
|
-
}
|
|
29
|
-
/** @deprecated Use {@link readUseOpenRouterFromEnv} from `@x12i/ai-profiles`. */
|
|
30
|
-
export function readPreferOpenRouterFromEnv() {
|
|
31
|
-
return readUseOpenRouterFromEnv() ?? true;
|
|
19
|
+
return resolvePreferOpenRouterPreference();
|
|
32
20
|
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gateway-level OpenRouter key +
|
|
2
|
+
* Gateway-level OpenRouter key + PREFER_OPENROUTER flags mapped to @x12i/ai-tools invoke helpers.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { readPreferOpenRouterFromEnv } from '@x12i/ai-profiles';
|
|
5
5
|
import type { GatewayConfig } from './types.js';
|
|
6
|
-
export {
|
|
6
|
+
export { readPreferOpenRouterFromEnv };
|
|
7
7
|
export declare function resolveOpenRouterApiKey(config?: GatewayConfig): string | undefined;
|
|
8
8
|
/**
|
|
9
|
-
* Effective OpenRouter preference for invoke-time routing (ai-tools `
|
|
10
|
-
* Constructor `openRouter.prefer`
|
|
9
|
+
* Effective OpenRouter preference for invoke-time routing (ai-tools `preferOpenRouter`).
|
|
10
|
+
* Constructor `openRouter.prefer` overrides env `PREFER_OPENROUTER`.
|
|
11
11
|
*/
|
|
12
|
-
export declare function resolveUseOpenRouter(config?: GatewayConfig): boolean;
|
|
13
|
-
/** @deprecated Use {@link resolveUseOpenRouter} (ai-tools v3 renamed prefer → useOpenRouter). */
|
|
14
12
|
export declare function resolvePreferOpenRouter(config?: GatewayConfig): boolean;
|
|
15
|
-
/** @deprecated Use {@link readUseOpenRouterFromEnv} from `@x12i/ai-profiles`. */
|
|
16
|
-
export declare function readPreferOpenRouterFromEnv(): boolean;
|
package/dist-cjs/types.d.ts
CHANGED
|
@@ -391,11 +391,10 @@ export interface GatewayConfig extends Omit<RouterConfig, 'defaultEngine' | 'log
|
|
|
391
391
|
};
|
|
392
392
|
/**
|
|
393
393
|
* OpenRouter preference (not a hard off-switch when {@link openrouter}.apiKey or OPENROUTER_API_KEY is set).
|
|
394
|
-
* - `prefer: true`
|
|
395
|
-
* - `prefer: false`
|
|
394
|
+
* - `prefer: true` or omitted env (default true): prefer OpenRouter when OPENROUTER_API_KEY is present.
|
|
395
|
+
* - `prefer: false` or PREFER_OPENROUTER=false: use direct providers when their API keys exist; OpenRouter still used as fallback when a requested provider has no key.
|
|
396
396
|
*/
|
|
397
397
|
openRouter?: {
|
|
398
|
-
enabled?: boolean;
|
|
399
398
|
prefer?: boolean;
|
|
400
399
|
};
|
|
401
400
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x12i/ai-gateway",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.2",
|
|
4
4
|
"description": "AI Gateway - Unified interface for LLM provider routing and management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"author": "x12i",
|
|
42
42
|
"license": "mit",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@x12i/activix": "^8.6.
|
|
45
|
-
"@x12i/ai-profiles": "^3.
|
|
44
|
+
"@x12i/activix": "^8.6.2",
|
|
45
|
+
"@x12i/ai-profiles": "^3.4.0",
|
|
46
46
|
"@x12i/ai-providers-router": "^4.9.2",
|
|
47
|
-
"@x12i/ai-tools": "^3.
|
|
47
|
+
"@x12i/ai-tools": "^3.3.3",
|
|
48
48
|
"@x12i/flex-md": "^4.8.0",
|
|
49
49
|
"@x12i/logxer": "^4.6.0",
|
|
50
50
|
"@x12i/rendrix": "^4.3.0"
|