@x12i/ai-gateway 9.7.0 → 9.7.3

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 CHANGED
@@ -131,13 +131,27 @@ Defaults load from `defaults/model-config.json`, `instructions-blocks.json`, and
131
131
  | `MONGO_URI`, `MONGO_LOGS_DB` / `MONGO_DB` | Activix when no custom tracker |
132
132
  | `AI_GATEWAY_DEFAULT_MODEL` | Default model slug (`provider/model` or OpenRouter id) |
133
133
  | `mode` / `MODE` | Operational mode (`dev`, `debug`, `prod`) |
134
- | `AI_GATEWAY_LOGS_LEVEL` | Log level when using default logger (`AI_GATEWAY` prefix) |
134
+ | `AI_GATEWAY_LOGS_LEVEL` | Log threshold for gateway diagnostics (`AI_GATEWAY` prefix): `error` … `verbose` |
135
+ | `AI_GATEWAY_VERBOSE` | Full payload lines (still requires `AI_GATEWAY_LOGS_LEVEL=verbose`) |
136
+ | `LOGXER_PACKAGE_LEVELS` | Bulk stack levels, e.g. `AI_GATEWAY:info,AI_PROVIDER_ROUTER:debug` |
135
137
  | `FLEX_MD_MIN_COMPLIANCE_LEVEL` | `L0`–`L3` output-format validation (default `L0`) |
136
138
  | `OPENROUTER_API_KEY` | OpenRouter key; always wired when set (required for profile/OpenRouter routes) |
137
139
  | `USE_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 |
138
140
  | Other provider keys | `OPENAI_API_KEY`, `GROK_API_KEY`, etc. |
139
141
 
140
- Logging details: [Logger initialization](./docs/LOGGER_INITIALIZATION.md).
142
+ Logging details: [Logger initialization](./docs/LOGGER_INITIALIZATION.md). Package identity and audit checklist: [LOGXER_INTEGRATION_CHECKLIST.md](./docs/LOGXER_INTEGRATION_CHECKLIST.md).
143
+
144
+ ### Logxer identity
145
+
146
+ | Field | Value | Env / filter |
147
+ |-------|-------|----------------|
148
+ | `packageName` (log `package` column) | `AIGateway` | — |
149
+ | `envPrefix` | `AI_GATEWAY` | `AI_GATEWAY_LOGS_LEVEL`, `LOGXER_PACKAGE_LEVELS` |
150
+ | `debugNamespace` | `ai-gateway` | `DEBUG=ai-gateway` |
151
+
152
+ Console lines show **`app:`** (host app from cwd `package.json`) separately from **`package:`** (`AIGateway` for gateway code, host package for host code).
153
+
154
+ Exports: `GATEWAY_LOGXER_PACKAGE`, `GATEWAY_LOG_ENV_PREFIX`, `createGatewayLogger`, `resolveGatewayVerboseEnabled`.
141
155
 
142
156
  ---
143
157
 
@@ -251,11 +265,14 @@ Live tests use `LIVE_TEST_PROVIDER` / `LIVE_TEST_MODEL` (default `openrouter` +
251
265
  import { validateAIRequest, diagnoseRequest, formatDiagnostic } from '@x12i/ai-gateway';
252
266
  ```
253
267
 
254
- Enable request logging:
268
+ Enable gateway/router diagnostics:
255
269
 
256
270
  ```bash
257
- export AI_GATEWAY_DEBUG=true
258
- export AI_GATEWAY_DEBUG_REQUEST=true
271
+ export AI_GATEWAY_LOGS_LEVEL=debug
272
+ export AI_PROVIDER_ROUTER_LOGS_LEVEL=debug
273
+ # Optional full I/O payloads (requires _LOGS_LEVEL=verbose on the relevant package):
274
+ export AI_GATEWAY_VERBOSE=true
275
+ export AI_PROVIDER_ROUTER_VERBOSE=true
259
276
  export FLEX_MD_MIN_COMPLIANCE_LEVEL=L0
260
277
  ```
261
278
 
@@ -161,11 +161,11 @@ export function initializeGatewayComponents(config) {
161
161
  // Initialize logger FIRST (before other components that might need it)
162
162
  const logger = createGatewayLogger({
163
163
  enableLogging: config.enableLogging ?? true,
164
- packageName: config.packageName,
165
164
  customLogger: config.logger,
166
165
  logging: config.logging,
167
166
  packageLogLevels: config.packageLogLevels,
168
- logLevel: config.logLevel
167
+ logLevel: config.logLevel,
168
+ verbose: config.verbose
169
169
  });
170
170
  const { defaultModelConfig, defaultInstructionsBlocks, defaultTemplateRendering } = loadConfig(logger);
171
171
  logger.verbose('Gateway initializing', {
@@ -5,6 +5,15 @@
5
5
  import { type PackageLogLevelsConfig } from '@x12i/logxer';
6
6
  /** Stable ERC 2.0 env prefix — controls `AI_GATEWAY_LOGS_LEVEL`, etc. */
7
7
  export declare const GATEWAY_LOG_ENV_PREFIX = "AI_GATEWAY";
8
+ /**
9
+ * Stable logxer package identity for `@x12i/ai-gateway`.
10
+ * @see docs/LOGXER_INTEGRATION_CHECKLIST.md
11
+ */
12
+ export declare const GATEWAY_LOGXER_PACKAGE: {
13
+ readonly packageName: "AIGateway";
14
+ readonly envPrefix: "AI_GATEWAY";
15
+ readonly debugNamespace: "ai-gateway";
16
+ };
8
17
  /** Known `envPrefix` values in this package's dependency stack (for hosts / `.env`). */
9
18
  export declare const GATEWAY_STACK_LOG_PREFIXES: {
10
19
  readonly gateway: "AI_GATEWAY";
@@ -6,6 +6,15 @@ import { applyPackageLogLevelsFromEnv, mergePackageLogLevelsConfig } from '@x12i
6
6
  import { ROUTER_LOG_ENV_PREFIX } from '@x12i/ai-providers-router';
7
7
  /** Stable ERC 2.0 env prefix — controls `AI_GATEWAY_LOGS_LEVEL`, etc. */
8
8
  export const GATEWAY_LOG_ENV_PREFIX = 'AI_GATEWAY';
9
+ /**
10
+ * Stable logxer package identity for `@x12i/ai-gateway`.
11
+ * @see docs/LOGXER_INTEGRATION_CHECKLIST.md
12
+ */
13
+ export const GATEWAY_LOGXER_PACKAGE = {
14
+ packageName: 'AIGateway',
15
+ envPrefix: GATEWAY_LOG_ENV_PREFIX,
16
+ debugNamespace: 'ai-gateway'
17
+ };
9
18
  /** Known `envPrefix` values in this package's dependency stack (for hosts / `.env`). */
10
19
  export const GATEWAY_STACK_LOG_PREFIXES = {
11
20
  gateway: GATEWAY_LOG_ENV_PREFIX,
package/dist/index.d.ts CHANGED
@@ -35,8 +35,9 @@ export { ActivityManager, ensureGatewayRequestIdentity } from './activity-manage
35
35
  export { OptimixerManager } from './optimixer-manager.js';
36
36
  export type { ActivityIdentity } from './types.js';
37
37
  export { activityIdentityToLogContext, activityIdentityToLogMeta, withActivityIdentity, withGatewayLogContext, gatewayLogDebug } from './gateway-log-meta.js';
38
- export { createGatewayLogger } from './logger-factory.js';
39
- export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
38
+ export { createGatewayLogger, resolveGatewayVerboseEnabled } from './logger-factory.js';
39
+ export type { GatewayLoggerConfig } from './logger-factory.js';
40
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
40
41
  export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
41
42
  export type { GatewayLogCode as GatewayDiagnosticCode } from './gateway-log-diagnostics.js';
42
43
  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';
package/dist/index.js CHANGED
@@ -30,8 +30,8 @@ export { normalizeToActivixCostShape } from '@x12i/activix';
30
30
  export { ActivityManager, ensureGatewayRequestIdentity } from './activity-manager.js';
31
31
  export { OptimixerManager } from './optimixer-manager.js';
32
32
  export { activityIdentityToLogContext, activityIdentityToLogMeta, withActivityIdentity, withGatewayLogContext, gatewayLogDebug } from './gateway-log-meta.js';
33
- export { createGatewayLogger } from './logger-factory.js';
34
- export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
33
+ export { createGatewayLogger, resolveGatewayVerboseEnabled } from './logger-factory.js';
34
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
35
35
  export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
36
36
  // Re-export logging (@x12i/logxer)
37
37
  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';
@@ -4,24 +4,29 @@
4
4
  * Creates and configures logxer instances for the gateway
5
5
  */
6
6
  import { type LogLevel, type Logxer, type PackageLogLevelsConfig, type StackLoggingOptions } from '@x12i/logxer';
7
- import { GATEWAY_LOG_ENV_PREFIX } from './gateway-log-levels.js';
8
- export { GATEWAY_LOG_ENV_PREFIX };
7
+ import { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE } from './gateway-log-levels.js';
8
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE };
9
9
  /** True for the internal no-op logger when `enableLogging` is false. */
10
10
  export declare function isNoOpGatewayLogger(logger: Logxer): boolean;
11
- /**
12
- * Creates a logger instance based on configuration
13
- *
14
- * @param config - Logger configuration
15
- * @returns Configured logger or no-op logger if logging is disabled
16
- */
17
- export declare function createGatewayLogger(config: {
11
+ /** Payload verbose flag (`AI_GATEWAY_VERBOSE`) — separate from `{PREFIX}_LOGS_LEVEL` threshold. */
12
+ export declare function resolveGatewayVerboseEnabled(config?: {
13
+ verbose?: boolean;
14
+ }): boolean;
15
+ export interface GatewayLoggerConfig {
18
16
  enableLogging: boolean;
19
- packageName?: string;
17
+ /** Host Logxer — transports inherited; emit surface stays {@link GATEWAY_LOGXER_PACKAGE}. */
20
18
  customLogger?: Logxer;
21
- /** Parent/host pass-through (logxer ≥ 4.5). Forwarded as `createLogxer(..., { stack })`. */
19
+ /** Host pass-through (logxer ≥ 4.5). Forwarded as `createLogxer(..., { stack })`. */
22
20
  logging?: StackLoggingOptions;
23
21
  /** Merged into the process registry after `applyPackageLogLevelsFromEnv()`. */
24
22
  packageLogLevels?: PackageLogLevelsConfig;
25
23
  /** Explicit level for this gateway logger instance (wins over stack/registry/env). */
26
24
  logLevel?: LogLevel;
27
- }): Logxer;
25
+ /** Full payload logging (`AI_GATEWAY_VERBOSE`); still requires log threshold `verbose`. */
26
+ verbose?: boolean;
27
+ }
28
+ /**
29
+ * Creates a logger instance based on configuration.
30
+ * Prefer this over ad-hoc `createLogxer` in consumers.
31
+ */
32
+ export declare function createGatewayLogger(config: GatewayLoggerConfig): Logxer;
@@ -5,42 +5,100 @@
5
5
  */
6
6
  import { createLogxer, getStationRuntimeIdentity, mergeRuntimeIdentity } from '@x12i/logxer';
7
7
  import { resolveLogDiagnosticsCatalogPath } from './gateway-log-diagnostics.js';
8
- import { GATEWAY_LOG_ENV_PREFIX, initializeGatewayPackageLogLevels } from './gateway-log-levels.js';
9
- export { GATEWAY_LOG_ENV_PREFIX };
8
+ import { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, initializeGatewayPackageLogLevels } from './gateway-log-levels.js';
9
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE };
10
10
  const NOOP_GATEWAY_LOGGER = Symbol('noop-gateway-logger');
11
+ const DEFAULT_GATEWAY_LOGXER_OPTIONS = {
12
+ sanitization: {
13
+ enabled: true,
14
+ detectAPIKeys: true,
15
+ detectPasswords: true,
16
+ detectJWTs: true,
17
+ detectEmails: true
18
+ }
19
+ };
11
20
  /** True for the internal no-op logger when `enableLogging` is false. */
12
21
  export function isNoOpGatewayLogger(logger) {
13
22
  return logger[NOOP_GATEWAY_LOGGER] === true;
14
23
  }
15
- function resolveGatewayRuntimeIdentity(packageName) {
24
+ /** Payload verbose flag (`AI_GATEWAY_VERBOSE`) — separate from `{PREFIX}_LOGS_LEVEL` threshold. */
25
+ export function resolveGatewayVerboseEnabled(config) {
26
+ if (config?.verbose !== undefined) {
27
+ return config.verbose;
28
+ }
29
+ const env = process.env.AI_GATEWAY_VERBOSE ?? process.env[`${GATEWAY_LOG_ENV_PREFIX}_VERBOSE`];
30
+ if (env === undefined) {
31
+ return false;
32
+ }
33
+ return env === 'true' || env === '1';
34
+ }
35
+ function resolveGatewayRuntimeIdentity() {
16
36
  return mergeRuntimeIdentity(getStationRuntimeIdentity(), {
17
- service: process.env.AI_GATEWAY_LOG_SERVICE ?? packageName ?? GATEWAY_LOG_ENV_PREFIX,
37
+ service: process.env.AI_GATEWAY_LOG_SERVICE ?? 'ai-gateway',
18
38
  version: process.env.npm_package_version
19
39
  });
20
40
  }
41
+ /** Share host transport settings; gateway keeps its own `package` label (`AIGateway`). */
42
+ function inheritLoggingConfigFromHost(hostLogger) {
43
+ if (!hostLogger || typeof hostLogger.getConfig !== 'function') {
44
+ return {};
45
+ }
46
+ const hostConfig = hostLogger.getConfig();
47
+ if (!hostConfig || typeof hostConfig !== 'object') {
48
+ return {};
49
+ }
50
+ const inherited = {};
51
+ const pick = (key) => {
52
+ const value = hostConfig[key];
53
+ if (value !== undefined) {
54
+ inherited[key] = value;
55
+ }
56
+ };
57
+ pick('logToConsole');
58
+ pick('logToFile');
59
+ pick('logFilePath');
60
+ pick('logFormat');
61
+ pick('showFullTimestamp');
62
+ pick('enableUnifiedLogger');
63
+ pick('unifiedLogger');
64
+ pick('consolePackagesShow');
65
+ pick('consolePackagesHide');
66
+ pick('transports');
67
+ pick('tracing');
68
+ pick('trails');
69
+ pick('shadow');
70
+ pick('queryStore');
71
+ pick('queryCache');
72
+ pick('causalLogging');
73
+ // Gateway always sanitizes; merge host toggles when present.
74
+ if (hostConfig.sanitization) {
75
+ inherited.sanitization = {
76
+ ...DEFAULT_GATEWAY_LOGXER_OPTIONS.sanitization,
77
+ ...hostConfig.sanitization
78
+ };
79
+ }
80
+ if (hostConfig.runtimeIdentity) {
81
+ inherited.runtimeIdentity = mergeRuntimeIdentity(hostConfig.runtimeIdentity, resolveGatewayRuntimeIdentity());
82
+ }
83
+ return inherited;
84
+ }
21
85
  /**
22
- * Creates a logger instance based on configuration
23
- *
24
- * @param config - Logger configuration
25
- * @returns Configured logger or no-op logger if logging is disabled
86
+ * Creates a logger instance based on configuration.
87
+ * Prefer this over ad-hoc `createLogxer` in consumers.
26
88
  */
27
89
  export function createGatewayLogger(config) {
28
- if (config.customLogger) {
29
- return config.customLogger;
30
- }
31
90
  if (!config.enableLogging) {
32
91
  return createNoOpLogger();
33
92
  }
34
93
  initializeGatewayPackageLogLevels({ packageLogLevels: config.packageLogLevels });
35
94
  const catalogPath = resolveLogDiagnosticsCatalogPath();
36
- return createLogxer({
37
- packageName: config.packageName || GATEWAY_LOG_ENV_PREFIX,
38
- envPrefix: GATEWAY_LOG_ENV_PREFIX,
39
- debugNamespace: 'ai-gateway'
40
- }, {
41
- runtimeIdentity: resolveGatewayRuntimeIdentity(config.packageName),
95
+ const hostLogging = inheritLoggingConfigFromHost(config.customLogger);
96
+ return createLogxer(GATEWAY_LOGXER_PACKAGE, {
97
+ ...DEFAULT_GATEWAY_LOGXER_OPTIONS,
98
+ runtimeIdentity: resolveGatewayRuntimeIdentity(),
42
99
  stack: config.logging,
43
100
  ...(config.logLevel !== undefined ? { logLevel: config.logLevel } : {}),
101
+ ...hostLogging,
44
102
  ...(catalogPath
45
103
  ? {
46
104
  diagnostics: {
package/dist/types.d.ts CHANGED
@@ -357,18 +357,25 @@ export interface GatewayConfig extends Omit<RouterConfig, 'defaultEngine' | 'log
357
357
  */
358
358
  packageLogLevels?: PackageLogLevelsConfig;
359
359
  /**
360
- * Custom logger instance (optional)
360
+ * Host Logxer for shared transports and correlation context.
361
+ * The gateway always creates its own logger with log envelope `package: AIGateway`;
362
+ * the host logger is not used as the emit surface (so ai-skills logs stay ai-skills, gateway logs stay AIGateway).
361
363
  */
362
364
  logger?: Logxer;
363
365
  /**
364
- * Custom activity tracker instance (optional)
366
+ * @deprecated Ignored gateway logs always use {@link GATEWAY_LOGXER_PACKAGE} (`package: AIGateway`).
367
+ * Use `logging` / `packageLogLevels` for stack verbosity; pass `logger` to share transports.
365
368
  */
366
- activityTracker?: Activix;
369
+ packageName?: string;
367
370
  /**
368
- * Package name for logging
369
- * @default 'AI_GATEWAY'
371
+ * Full payload logging for gateway-owned verbose lines (`AI_GATEWAY_VERBOSE=true`).
372
+ * Separate from log threshold (`AI_GATEWAY_LOGS_LEVEL=verbose`). Router I/O payloads use the same flag via `RouterConfig.verbose`.
370
373
  */
371
- packageName?: string;
374
+ verbose?: boolean;
375
+ /**
376
+ * Custom activity tracker instance (optional)
377
+ */
378
+ activityTracker?: Activix;
372
379
  /**
373
380
  * Default engine (e.g., 'openai', 'anthropic')
374
381
  * Used only for provider routing when request doesn't specify provider
@@ -161,11 +161,11 @@ export function initializeGatewayComponents(config) {
161
161
  // Initialize logger FIRST (before other components that might need it)
162
162
  const logger = createGatewayLogger({
163
163
  enableLogging: config.enableLogging ?? true,
164
- packageName: config.packageName,
165
164
  customLogger: config.logger,
166
165
  logging: config.logging,
167
166
  packageLogLevels: config.packageLogLevels,
168
- logLevel: config.logLevel
167
+ logLevel: config.logLevel,
168
+ verbose: config.verbose
169
169
  });
170
170
  const { defaultModelConfig, defaultInstructionsBlocks, defaultTemplateRendering } = loadConfig(logger);
171
171
  logger.verbose('Gateway initializing', {
@@ -6,6 +6,15 @@ import { applyPackageLogLevelsFromEnv, mergePackageLogLevelsConfig } from '@x12i
6
6
  import { ROUTER_LOG_ENV_PREFIX } from '@x12i/ai-providers-router';
7
7
  /** Stable ERC 2.0 env prefix — controls `AI_GATEWAY_LOGS_LEVEL`, etc. */
8
8
  export const GATEWAY_LOG_ENV_PREFIX = 'AI_GATEWAY';
9
+ /**
10
+ * Stable logxer package identity for `@x12i/ai-gateway`.
11
+ * @see docs/LOGXER_INTEGRATION_CHECKLIST.md
12
+ */
13
+ export const GATEWAY_LOGXER_PACKAGE = {
14
+ packageName: 'AIGateway',
15
+ envPrefix: GATEWAY_LOG_ENV_PREFIX,
16
+ debugNamespace: 'ai-gateway'
17
+ };
9
18
  /** Known `envPrefix` values in this package's dependency stack (for hosts / `.env`). */
10
19
  export const GATEWAY_STACK_LOG_PREFIXES = {
11
20
  gateway: GATEWAY_LOG_ENV_PREFIX,
@@ -5,6 +5,15 @@
5
5
  import { type PackageLogLevelsConfig } from '@x12i/logxer';
6
6
  /** Stable ERC 2.0 env prefix — controls `AI_GATEWAY_LOGS_LEVEL`, etc. */
7
7
  export declare const GATEWAY_LOG_ENV_PREFIX = "AI_GATEWAY";
8
+ /**
9
+ * Stable logxer package identity for `@x12i/ai-gateway`.
10
+ * @see docs/LOGXER_INTEGRATION_CHECKLIST.md
11
+ */
12
+ export declare const GATEWAY_LOGXER_PACKAGE: {
13
+ readonly packageName: "AIGateway";
14
+ readonly envPrefix: "AI_GATEWAY";
15
+ readonly debugNamespace: "ai-gateway";
16
+ };
8
17
  /** Known `envPrefix` values in this package's dependency stack (for hosts / `.env`). */
9
18
  export declare const GATEWAY_STACK_LOG_PREFIXES: {
10
19
  readonly gateway: "AI_GATEWAY";
@@ -30,8 +30,8 @@ export { normalizeToActivixCostShape } from '@x12i/activix';
30
30
  export { ActivityManager, ensureGatewayRequestIdentity } from './activity-manager.js';
31
31
  export { OptimixerManager } from './optimixer-manager.js';
32
32
  export { activityIdentityToLogContext, activityIdentityToLogMeta, withActivityIdentity, withGatewayLogContext, gatewayLogDebug } from './gateway-log-meta.js';
33
- export { createGatewayLogger } from './logger-factory.js';
34
- export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
33
+ export { createGatewayLogger, resolveGatewayVerboseEnabled } from './logger-factory.js';
34
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
35
35
  export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
36
36
  // Re-export logging (@x12i/logxer)
37
37
  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';
@@ -35,8 +35,9 @@ export { ActivityManager, ensureGatewayRequestIdentity } from './activity-manage
35
35
  export { OptimixerManager } from './optimixer-manager.js';
36
36
  export type { ActivityIdentity } from './types.js';
37
37
  export { activityIdentityToLogContext, activityIdentityToLogMeta, withActivityIdentity, withGatewayLogContext, gatewayLogDebug } from './gateway-log-meta.js';
38
- export { createGatewayLogger } from './logger-factory.js';
39
- export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
38
+ export { createGatewayLogger, resolveGatewayVerboseEnabled } from './logger-factory.js';
39
+ export type { GatewayLoggerConfig } from './logger-factory.js';
40
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, GATEWAY_STACK_LOG_PREFIXES, initializeGatewayPackageLogLevels, resetGatewayPackageLogLevelsInit } from './gateway-log-levels.js';
40
41
  export { GatewayLogCode, gatewayErrorCode, gatewayInfoCode, gatewayWarnCode, gatewayAnomalyMeta, resolveLogDiagnosticsCatalogPath, exceptionEvidence, fieldEvidence } from './gateway-log-diagnostics.js';
41
42
  export type { GatewayLogCode as GatewayDiagnosticCode } from './gateway-log-diagnostics.js';
42
43
  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';
@@ -5,42 +5,100 @@
5
5
  */
6
6
  import { createLogxer, getStationRuntimeIdentity, mergeRuntimeIdentity } from '@x12i/logxer';
7
7
  import { resolveLogDiagnosticsCatalogPath } from './gateway-log-diagnostics.js';
8
- import { GATEWAY_LOG_ENV_PREFIX, initializeGatewayPackageLogLevels } from './gateway-log-levels.js';
9
- export { GATEWAY_LOG_ENV_PREFIX };
8
+ import { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE, initializeGatewayPackageLogLevels } from './gateway-log-levels.js';
9
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE };
10
10
  const NOOP_GATEWAY_LOGGER = Symbol('noop-gateway-logger');
11
+ const DEFAULT_GATEWAY_LOGXER_OPTIONS = {
12
+ sanitization: {
13
+ enabled: true,
14
+ detectAPIKeys: true,
15
+ detectPasswords: true,
16
+ detectJWTs: true,
17
+ detectEmails: true
18
+ }
19
+ };
11
20
  /** True for the internal no-op logger when `enableLogging` is false. */
12
21
  export function isNoOpGatewayLogger(logger) {
13
22
  return logger[NOOP_GATEWAY_LOGGER] === true;
14
23
  }
15
- function resolveGatewayRuntimeIdentity(packageName) {
24
+ /** Payload verbose flag (`AI_GATEWAY_VERBOSE`) — separate from `{PREFIX}_LOGS_LEVEL` threshold. */
25
+ export function resolveGatewayVerboseEnabled(config) {
26
+ if (config?.verbose !== undefined) {
27
+ return config.verbose;
28
+ }
29
+ const env = process.env.AI_GATEWAY_VERBOSE ?? process.env[`${GATEWAY_LOG_ENV_PREFIX}_VERBOSE`];
30
+ if (env === undefined) {
31
+ return false;
32
+ }
33
+ return env === 'true' || env === '1';
34
+ }
35
+ function resolveGatewayRuntimeIdentity() {
16
36
  return mergeRuntimeIdentity(getStationRuntimeIdentity(), {
17
- service: process.env.AI_GATEWAY_LOG_SERVICE ?? packageName ?? GATEWAY_LOG_ENV_PREFIX,
37
+ service: process.env.AI_GATEWAY_LOG_SERVICE ?? 'ai-gateway',
18
38
  version: process.env.npm_package_version
19
39
  });
20
40
  }
41
+ /** Share host transport settings; gateway keeps its own `package` label (`AIGateway`). */
42
+ function inheritLoggingConfigFromHost(hostLogger) {
43
+ if (!hostLogger || typeof hostLogger.getConfig !== 'function') {
44
+ return {};
45
+ }
46
+ const hostConfig = hostLogger.getConfig();
47
+ if (!hostConfig || typeof hostConfig !== 'object') {
48
+ return {};
49
+ }
50
+ const inherited = {};
51
+ const pick = (key) => {
52
+ const value = hostConfig[key];
53
+ if (value !== undefined) {
54
+ inherited[key] = value;
55
+ }
56
+ };
57
+ pick('logToConsole');
58
+ pick('logToFile');
59
+ pick('logFilePath');
60
+ pick('logFormat');
61
+ pick('showFullTimestamp');
62
+ pick('enableUnifiedLogger');
63
+ pick('unifiedLogger');
64
+ pick('consolePackagesShow');
65
+ pick('consolePackagesHide');
66
+ pick('transports');
67
+ pick('tracing');
68
+ pick('trails');
69
+ pick('shadow');
70
+ pick('queryStore');
71
+ pick('queryCache');
72
+ pick('causalLogging');
73
+ // Gateway always sanitizes; merge host toggles when present.
74
+ if (hostConfig.sanitization) {
75
+ inherited.sanitization = {
76
+ ...DEFAULT_GATEWAY_LOGXER_OPTIONS.sanitization,
77
+ ...hostConfig.sanitization
78
+ };
79
+ }
80
+ if (hostConfig.runtimeIdentity) {
81
+ inherited.runtimeIdentity = mergeRuntimeIdentity(hostConfig.runtimeIdentity, resolveGatewayRuntimeIdentity());
82
+ }
83
+ return inherited;
84
+ }
21
85
  /**
22
- * Creates a logger instance based on configuration
23
- *
24
- * @param config - Logger configuration
25
- * @returns Configured logger or no-op logger if logging is disabled
86
+ * Creates a logger instance based on configuration.
87
+ * Prefer this over ad-hoc `createLogxer` in consumers.
26
88
  */
27
89
  export function createGatewayLogger(config) {
28
- if (config.customLogger) {
29
- return config.customLogger;
30
- }
31
90
  if (!config.enableLogging) {
32
91
  return createNoOpLogger();
33
92
  }
34
93
  initializeGatewayPackageLogLevels({ packageLogLevels: config.packageLogLevels });
35
94
  const catalogPath = resolveLogDiagnosticsCatalogPath();
36
- return createLogxer({
37
- packageName: config.packageName || GATEWAY_LOG_ENV_PREFIX,
38
- envPrefix: GATEWAY_LOG_ENV_PREFIX,
39
- debugNamespace: 'ai-gateway'
40
- }, {
41
- runtimeIdentity: resolveGatewayRuntimeIdentity(config.packageName),
95
+ const hostLogging = inheritLoggingConfigFromHost(config.customLogger);
96
+ return createLogxer(GATEWAY_LOGXER_PACKAGE, {
97
+ ...DEFAULT_GATEWAY_LOGXER_OPTIONS,
98
+ runtimeIdentity: resolveGatewayRuntimeIdentity(),
42
99
  stack: config.logging,
43
100
  ...(config.logLevel !== undefined ? { logLevel: config.logLevel } : {}),
101
+ ...hostLogging,
44
102
  ...(catalogPath
45
103
  ? {
46
104
  diagnostics: {
@@ -4,24 +4,29 @@
4
4
  * Creates and configures logxer instances for the gateway
5
5
  */
6
6
  import { type LogLevel, type Logxer, type PackageLogLevelsConfig, type StackLoggingOptions } from '@x12i/logxer';
7
- import { GATEWAY_LOG_ENV_PREFIX } from './gateway-log-levels.js';
8
- export { GATEWAY_LOG_ENV_PREFIX };
7
+ import { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE } from './gateway-log-levels.js';
8
+ export { GATEWAY_LOG_ENV_PREFIX, GATEWAY_LOGXER_PACKAGE };
9
9
  /** True for the internal no-op logger when `enableLogging` is false. */
10
10
  export declare function isNoOpGatewayLogger(logger: Logxer): boolean;
11
- /**
12
- * Creates a logger instance based on configuration
13
- *
14
- * @param config - Logger configuration
15
- * @returns Configured logger or no-op logger if logging is disabled
16
- */
17
- export declare function createGatewayLogger(config: {
11
+ /** Payload verbose flag (`AI_GATEWAY_VERBOSE`) — separate from `{PREFIX}_LOGS_LEVEL` threshold. */
12
+ export declare function resolveGatewayVerboseEnabled(config?: {
13
+ verbose?: boolean;
14
+ }): boolean;
15
+ export interface GatewayLoggerConfig {
18
16
  enableLogging: boolean;
19
- packageName?: string;
17
+ /** Host Logxer — transports inherited; emit surface stays {@link GATEWAY_LOGXER_PACKAGE}. */
20
18
  customLogger?: Logxer;
21
- /** Parent/host pass-through (logxer ≥ 4.5). Forwarded as `createLogxer(..., { stack })`. */
19
+ /** Host pass-through (logxer ≥ 4.5). Forwarded as `createLogxer(..., { stack })`. */
22
20
  logging?: StackLoggingOptions;
23
21
  /** Merged into the process registry after `applyPackageLogLevelsFromEnv()`. */
24
22
  packageLogLevels?: PackageLogLevelsConfig;
25
23
  /** Explicit level for this gateway logger instance (wins over stack/registry/env). */
26
24
  logLevel?: LogLevel;
27
- }): Logxer;
25
+ /** Full payload logging (`AI_GATEWAY_VERBOSE`); still requires log threshold `verbose`. */
26
+ verbose?: boolean;
27
+ }
28
+ /**
29
+ * Creates a logger instance based on configuration.
30
+ * Prefer this over ad-hoc `createLogxer` in consumers.
31
+ */
32
+ export declare function createGatewayLogger(config: GatewayLoggerConfig): Logxer;
@@ -357,18 +357,25 @@ export interface GatewayConfig extends Omit<RouterConfig, 'defaultEngine' | 'log
357
357
  */
358
358
  packageLogLevels?: PackageLogLevelsConfig;
359
359
  /**
360
- * Custom logger instance (optional)
360
+ * Host Logxer for shared transports and correlation context.
361
+ * The gateway always creates its own logger with log envelope `package: AIGateway`;
362
+ * the host logger is not used as the emit surface (so ai-skills logs stay ai-skills, gateway logs stay AIGateway).
361
363
  */
362
364
  logger?: Logxer;
363
365
  /**
364
- * Custom activity tracker instance (optional)
366
+ * @deprecated Ignored gateway logs always use {@link GATEWAY_LOGXER_PACKAGE} (`package: AIGateway`).
367
+ * Use `logging` / `packageLogLevels` for stack verbosity; pass `logger` to share transports.
365
368
  */
366
- activityTracker?: Activix;
369
+ packageName?: string;
367
370
  /**
368
- * Package name for logging
369
- * @default 'AI_GATEWAY'
371
+ * Full payload logging for gateway-owned verbose lines (`AI_GATEWAY_VERBOSE=true`).
372
+ * Separate from log threshold (`AI_GATEWAY_LOGS_LEVEL=verbose`). Router I/O payloads use the same flag via `RouterConfig.verbose`.
370
373
  */
371
- packageName?: string;
374
+ verbose?: boolean;
375
+ /**
376
+ * Custom activity tracker instance (optional)
377
+ */
378
+ activityTracker?: Activix;
372
379
  /**
373
380
  * Default engine (e.g., 'openai', 'anthropic')
374
381
  * Used only for provider routing when request doesn't specify provider
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x12i/ai-gateway",
3
- "version": "9.7.0",
3
+ "version": "9.7.3",
4
4
  "description": "AI Gateway - Unified interface for LLM provider routing and management",
5
5
  "type": "module",
6
6
  "exports": {
@@ -42,8 +42,8 @@
42
42
  "license": "mit",
43
43
  "dependencies": {
44
44
  "@x12i/activix": "^8.3.1",
45
- "@x12i/ai-providers-router": "^4.9.0",
46
- "@x12i/ai-tools": "^2.1.3",
45
+ "@x12i/ai-providers-router": "^4.9.2",
46
+ "@x12i/ai-tools": "^2.1.5",
47
47
  "@x12i/flex-md": "^4.8.0",
48
48
  "@x12i/logxer": "^4.6.0",
49
49
  "@x12i/optimixer": "^2.4.4",