Skip to content

consolidate configuration types to centralized types - #163

Closed
ghost wants to merge 1 commit into
juspay:releasefrom
RajuSudhar:refactor/config-module
Closed

ghost wants to merge 1 commit into
juspay:releasefrom
RajuSudhar:refactor/config-module

Conversation

@ghost

@ghost ghost commented Sep 10, 2025 •

Copy link
Copy Markdown
  • Move all configuration types from src/lib/config/types.ts to src/lib/types/configTypes.ts
  • Convert all 14 interfaces to types following established architecture pattern
  • Update imports in configManager.ts to use centralized types
  • Update toolUtils.ts import path for ToolConfig type
  • Add configTypes.ts to centralized type exports in index.ts
  • Remove old config/types.ts file entirely in favor of centralized approach
  • Fix crypto and path import issues in configManager.ts (use named imports)
  • Maintain full backward compatibility through proper type re-exports

Pull Request

Description

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test coverage improvement
  • 🔧 Build/CI configuration change

Related Issues

  • Fixes #
  • Related to #

Changes Made

AI Provider Impact

  • OpenAI
  • Anthropic
  • Google AI/Vertex
  • AWS Bedrock
  • Azure OpenAI
  • Hugging Face
  • Ollama
  • Mistral
  • All providers
  • No provider-specific changes

Component Impact

  • CLI
  • SDK
  • MCP Integration
  • Streaming
  • Tool Calling
  • Configuration
  • Documentation
  • Tests

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • E2E tests added/updated
  • Manual testing performed
  • All existing tests pass

Test Environment

  • OS:
  • Node.js version:
  • Package manager:

Performance Impact

  • No performance impact
  • Performance improvement
  • Minor performance impact (acceptable)
  • Significant performance impact (needs discussion)

Breaking Changes

Screenshots/Demo

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Summary by CodeRabbit

  • New Features

    • Publicly re-exported configuration types, making it easier for developers to consume and integrate typed configuration.
  • Refactor

    • Standardized utility imports and harmonized internal references for improved consistency and maintainability.
    • Converted configuration interfaces to type aliases for a more uniform and ergonomic type system.
    • Aligned utilities with the updated type structure; no runtime behavior changes.
  • Chores

    • Ensured configuration hashing, backup, and restore flows remain unchanged and fully compatible.

@coderabbitai

coderabbitai Bot commented Sep 10, 2025 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Refactors type locations and imports across config, types, and utils. Converts configuration interfaces to type aliases, updates import paths accordingly, and adds a public re-export for configuration types. Config manager switches to named imports for path/hash utilities without changing behavior.

Changes

Cohort / File(s) Summary of Changes
Config manager imports refactor
src/lib/config/configManager.ts
Switched to named imports (join, createHash); updated type/constant imports to ../types/configTypes.js; replaced path.join and crypto.createHash usages accordingly; logic and behavior unchanged.
Configuration types: interface → type alias
src/lib/types/configTypes.ts
Converted multiple export interface declarations to export type aliases with identical fields; no structural changes to properties; updated header comment.
Types index re-export
src/lib/types/index.ts
Added export * from "./configTypes.js" to expose configuration types publicly; no other changes.
Utils import path update
src/lib/utils/toolUtils.ts
Updated ToolConfig import path from ../config/types.js to ../types/configTypes.js; no logic changes to exported functions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary change of centralizing configuration type definitions into a shared location and directly references the consolidation effort, making its intent clear and aligned with the PR objectives without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

A rabbit taps keys with a gentle grin,
Types turn to aliases—same shape within.
Paths realigned, exports in tow,
Hashes still hum with a familiar glow.
Hop, hop—configs neatly in place,
Refactors done with tidy grace. 🐇✨

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/types/configTypes.ts (1)

22-35: ProviderConfig name collision with providers domain (will break the barrel).

This exported ProviderConfig conflicts with ProviderConfig already re-exported from ./providers.js via src/lib/types/index.ts. With export * from "./configTypes.js" plus existing provider exports, the barrel will export two distinct symbols with the same name, causing a compile-time duplicate export error.

Fix at the barrel by exporting config types explicitly and aliasing this one to avoid collision.

Apply in src/lib/types/index.ts:

-// Configuration types
-export * from "./configTypes.js";
+// Configuration types (explicit to avoid ProviderConfig name collision)
+export {
+  NeuroLinkConfig,
+  PerformanceConfig,
+  CacheConfig,
+  FallbackConfig,
+  RetryConfig,
+  AnalyticsConfig,
+  ToolConfig,
+  BackupInfo,
+  BackupMetadata,
+  ConfigValidationResult,
+  ConfigUpdateOptions,
+  DEFAULT_CONFIG,
+  ProviderConfig as ConfigProviderConfig, // alias to avoid clash with providers' ProviderConfig
+} from "./configTypes.js";
🧹 Nitpick comments (6)
src/lib/types/configTypes.ts (1)

33-34: Tighten feature literals to prevent typos.

Constrain features to a union instead of plain string[].

+export type ProviderFeature = "streaming" | "functionCalling" | "vision";
 export type ProviderConfig = {
@@
-  features?: string[]; // ['streaming', 'functionCalling', 'vision']
+  features?: ProviderFeature[]; // ['streaming', 'functionCalling', 'vision']
src/lib/types/index.ts (1)

11-13: Redundant provider re-exports.

You already export * from "./providers.js"; the later export type { …, ProviderConfig } from "./providers.js"; is redundant and increases confusion around the two ProviderConfigs.

-export type { AISDKModel, ProviderError, ProviderConfig } from "./providers.js";
+// Already exported via wildcard above. If you need type-only, drop the wildcard instead.
+// export type { AISDKModel, ProviderError, ProviderConfig } from "./providers.js";

Alternatively, remove the wildcard and keep the type-only export if that was intentional for tree-shaking.

Also applies to: 46-46

src/lib/utils/toolUtils.ts (2)

22-24: Normalize boolean env parsing to handle case/whitespace.

Current checks only match "true". Accept common truthy variants to reduce operator error.

+function envTrue(name: string, defaultValue = false): boolean {
+  const v = process.env[name];
+  if (v == null) return defaultValue;
+  return /^(1|true|yes|on)$/i.test(v.trim());
+}
@@
-  return process.env.NEUROLINK_DISABLE_BUILTIN_TOOLS === "true";
+  return envTrue("NEUROLINK_DISABLE_BUILTIN_TOOLS");
@@
-  return process.env.NEUROLINK_DISABLE_CUSTOM_TOOLS !== "true";
+  return !envTrue("NEUROLINK_DISABLE_CUSTOM_TOOLS");
@@
-  return process.env.NEUROLINK_DISABLE_MCP_TOOLS !== "true";
+  return !envTrue("NEUROLINK_DISABLE_MCP_TOOLS");

Also applies to: 36-37, 49-50


62-70: Parse max value more strictly.

parseInt will accept prefixes like 100abc. Use Number() and validate integer/finiteness.

-  const envMax = process.env.NEUROLINK_MAX_TOOLS_PER_PROVIDER;
-  if (envMax) {
-    const parsed = parseInt(envMax, 10);
-    if (!isNaN(parsed) && parsed > 0) {
-      return parsed;
-    }
-  }
+  const raw = process.env.NEUROLINK_MAX_TOOLS_PER_PROVIDER?.trim();
+  if (raw) {
+    const parsed = Number(raw);
+    if (Number.isInteger(parsed) && parsed > 0) {
+      return parsed;
+    }
+  }
src/lib/config/configManager.ts (2)

7-8: Use Node built-in specifiers for clarity (optional).

The switch to named imports is good. Consider node: specifiers to avoid polyfill collisions in bundlers.

-import { join } from "path";
-import { createHash } from "crypto";
+import { join } from "node:path";
+import { createHash } from "node:crypto";

375-381: Make config hashing deterministic for nested objects.

JSON.stringify(config, Object.keys(config).sort()) only sorts top-level keys; nested objects can change order and produce different hashes for equivalent configs.

Apply:

-    const configString = JSON.stringify(config, Object.keys(config).sort());
-    return createHash("sha256")
+    const configString = this.stableStringify(config);
+    return createHash("sha256")
       .update(configString)
       .digest("hex")
       .substring(0, 8);

Add this helper inside the class:

private stableStringify(value: unknown): string {
  return JSON.stringify(value, (_k, v) => {
    if (v && typeof v === "object" && !Array.isArray(v)) {
      const obj = v as Record<string, unknown>;
      return Object.keys(obj).sort().reduce((acc, key) => {
        (acc as Record<string, unknown>)[key] = obj[key];
        return acc;
      }, {} as Record<string, unknown>);
    }
    return v;
  });
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75d0c6d and f9160df.

📒 Files selected for processing (4)
  • src/lib/config/configManager.ts (6 hunks)
  • src/lib/types/configTypes.ts (4 hunks)
  • src/lib/types/index.ts (1 hunks)
  • src/lib/utils/toolUtils.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/lib/types/configTypes.ts (1)
src/lib/types/index.ts (1)
  • ProviderConfig (46-46)
🔇 Additional comments (3)
src/lib/types/configTypes.ts (1)

163-205: DEFAULT_CONFIG looks consistent with utils.

Defaults align with toolUtils behavior (e.g., maxToolsPerProvider: 100). No issues spotted.

src/lib/utils/toolUtils.ts (1)

7-7: Import path update looks good.

Centralizing on ../types/configTypes.js aligns with the new layout.

src/lib/config/configManager.ts (1)

111-111: Path joins updated — LGTM.

Consistent join(...) usage improves portability and readability.

Also applies to: 153-153, 185-185

Comment on lines +17 to 19
} from "../types/configTypes.js";
import { DEFAULT_CONFIG } from "../types/configTypes.js";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify TS ESM settings for .js-suffixed imports.

Importing ../types/configTypes.js from a .ts file typically requires moduleResolution: "NodeNext" | "Bundler" and verbatimModuleSyntax: true (or equivalent). Please confirm repo settings and that the new central types re-export is in place.


🏁 Script executed:

#!/bin/bash
# Check tsconfig module + resolution
fd -a 'tsconfig*.json' | while read -r f; do
  echo "== $f =="; rg -n -C2 '"module"\s*:' "$f"; rg -n -C2 '"moduleResolution"\s*:' "$f"; rg -n -C2 '"verbatimModuleSyntax"\s*:' "$f"
done

# Ensure DEFAULT_CONFIG is exported from the new location
rg -nC2 'export\s+const\s+DEFAULT_CONFIG' src/lib/types/configTypes.ts

# Ensure public re-export exists
rg -nC2 'export\s+\*\s+from\s+"\.\/configTypes\.js"' src/lib/types/index.ts src/lib/types/index.tsx 2>/dev/null || true

Length of output: 476


Add public re‐export for configTypes.js
There’s no export * from './configTypes.js' in src/lib/types/index.ts—add it to centralize your type exports.

🤖 Prompt for AI Agents
In src/lib/config/configManager.ts around lines 17-19: the project lacks a
public re-export for configTypes.js in src/lib/types/index.ts, so add export *
from './configTypes.js' to src/lib/types/index.ts to centralize and expose those
types; after adding the re-export, update any imports if necessary to import
from src/lib/types (or the package's types index) and run a build/type-check to
confirm there are no unresolved import errors.

Comment thread src/lib/types/index.ts
Comment on lines +20 to +34
// Configuration types
export * from "./configTypes.js";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Barrel currently exports duplicate ProviderConfig symbols.

  • You do export * from "./configTypes.js" (which includes a ProviderConfig).
  • You also export ProviderConfig from ./providers.js.
    This collides and will fail type-checking.

Resolve by explicitly exporting config types and aliasing ProviderConfig from configTypes to ConfigProviderConfig (keeping the providers’ ProviderConfig intact).

Apply:

-// Configuration types
-export * from "./configTypes.js";
+// Configuration types (explicit, with alias to avoid name clash)
+export {
+  NeuroLinkConfig,
+  PerformanceConfig,
+  CacheConfig,
+  FallbackConfig,
+  RetryConfig,
+  AnalyticsConfig,
+  ToolConfig,
+  BackupInfo,
+  BackupMetadata,
+  ConfigValidationResult,
+  ConfigUpdateOptions,
+  DEFAULT_CONFIG,
+  ProviderConfig as ConfigProviderConfig,
+} from "./configTypes.js";

Also applies to: 46-46

🤖 Prompt for AI Agents
In src/lib/types/index.ts around lines 20-22 and also at line 46, the barrel
export re-exports ProviderConfig twice (once via export * from
"./configTypes.js" and again from "./providers.js"), causing a type collision;
fix by changing the wildcard re-export of configTypes to an explicit list that
re-exports all needed config types but renames ProviderConfig to
ConfigProviderConfig (i.e., import or export ProviderConfig from
./configTypes.js under the alias ConfigProviderConfig) while leaving the
providers.js export of ProviderConfig untouched so only the aliased config
version is exposed from this barrel.

💡 Verification agent

🧩 Analysis chain

Sanity check for breaking API.

If consumers imported ProviderConfig from the barrel intending the config shape, they’ll now need ConfigProviderConfig. Consider a deprecation period by also re-exporting:

export type { ProviderConfig as ProviderConfig_Deprecated_Config } from "./configTypes.js";

Run to find external/internal imports relying on the config-shaped ProviderConfig from the barrel:


🏁 Script executed:

#!/bin/bash
# Identify barrel imports of ProviderConfig
rg -nP -C2 'from\s+["'\'']\.\/types\/index\.js["'\''].*\{[^}]*ProviderConfig[^}]*\}'
# Identify direct imports of config ProviderConfig (safe)
rg -nP -C2 'from\s+["'\'']\.\/types\/configTypes\.js["'\''].*\{[^}]*ProviderConfig[^}]*\}'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for any import or export references to ProviderConfig in .ts and .js files
rg -nP '(import|export)\s+.*\bProviderConfig\b' -g '*.ts' -g '*.js'

Length of output: 853


Export a deprecated alias for the original ProviderConfig
Add the following below the wildcard export to preserve the old config‐shape type before removing it in a future release:

export type { ProviderConfig as DeprecatedProviderConfig } from "./configTypes.js";

This ensures any consumers importing ProviderConfig from the barrel keep the config‐shape type and can migrate on the deprecation schedule.

🤖 Prompt for AI Agents
In src/lib/types/index.ts around lines 20 to 22, the barrel export currently
re-exports configTypes but does not provide a deprecated alias for the previous
ProviderConfig; add a named type re-export below the existing wildcard export to
preserve the old type shape for consumers, specifically add a line exporting
ProviderConfig as DeprecatedProviderConfig from "./configTypes.js" so downstream
code can continue to import the legacy name during the deprecation window.

@ghost
ghost force-pushed the refactor/config-module branch from f9160df to 5fab24c Compare September 11, 2025 09:26
… system

- Move all configuration types from src/lib/config/types.ts to src/lib/types/configTypes.ts
- Convert all 14 interfaces to types following established architecture pattern
- Update imports in configManager.ts to use centralized types
- Update toolUtils.ts import path for ToolConfig type
- Add configTypes.ts to centralized type exports in index.ts
- Remove old config/types.ts file entirely in favor of centralized approach
- Fix crypto and path import issues in configManager.ts (use named imports)
- Maintain full backward compatibility through proper type re-exports
@RajuSudhar
RajuSudhar force-pushed the refactor/config-module branch from 5fab24c to f0d6bef Compare September 11, 2025 10:02
@murdore murdore closed this Sep 16, 2025
@RajuSudhar
RajuSudhar deleted the refactor/config-module branch September 17, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants