Skip to content

refactor: Refactor AI SDK and MCP provider types, add utility functions and constants#32

Open
harshpreet931 wants to merge 1 commit intomainfrom
refactor/providers-type-safety
Open

refactor: Refactor AI SDK and MCP provider types, add utility functions and constants#32
harshpreet931 wants to merge 1 commit intomainfrom
refactor/providers-type-safety

Conversation

@harshpreet931
Copy link
Contributor

This pull request introduces a significant refactor and modularization of type definitions and utility functions for AI model providers, particularly for the AI SDK and MCP (Model Context Protocol) integrations. The main changes involve moving type definitions into dedicated files, improving type safety, and standardizing schema conversions. This will make the codebase easier to maintain, extend, and use in other parts of the project or externally.

Type Definitions Modularization and Exports:

  • Created new files ai-sdk-types.ts and mcp-types.ts to hold all type definitions for the AI SDK and MCP providers, respectively, and updated imports/exports throughout the provider modules to use these centralized types. This enhances maintainability and reusability. [1] [2] [3] [4] [5]

AI SDK Provider Improvements:

  • Refactored the AI SDK provider to use the new type definitions, improving type safety and clarity. Removed inline type definitions in favor of imports from ai-sdk-types.ts.
  • Improved the generateObject logic to use strongly typed options and results, and cleaned up schema conversion.

MCP Provider Improvements:

  • Refactored the MCP provider to use types from mcp-types.ts, improving type safety for tool definitions, content items, and client interfaces.
  • Improved JSON schema to Zod schema conversion, ensuring correct typing and handling of enums and arrays. [1] [2] [3] [4]
  • Standardized handling of tool responses and tool listing across all MCP client implementations (STDIO, SSE, HTTP). [1] [2] [3] [4] [5] [6] [7]

Provider Utility and Constants Improvements:

  • Added a new constants.ts file for shared model provider constants, such as vision model cache TTL, API timeout, and known vision models.
  • Updated model.ts to use shared proxy and utility functions, removing redundant proxy agent code and improving clarity. [1] [2]

Exports for External Use:

  • Updated provider module exports to make all relevant types available for external use, improving integration and type sharing across the codebase.

These changes collectively improve code organization, type safety, and extensibility for AI model provider integrations.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive refactor of AI model provider types and utilities, moving from inline type definitions to centralized, reusable modules. The main goal is to improve maintainability, type safety, and modularity across the AI SDK and MCP provider integrations.

  • Extracts type definitions into dedicated files (ai-sdk-types.ts, mcp-types.ts, types.ts) for better organization
  • Consolidates utility functions and constants into shared modules (utils.ts, constants.ts)
  • Improves type safety throughout provider implementations with stronger typing

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/providers/utils.ts New utility module with proxy agent creation, vision model detection, and Zod schema conversion functions
src/providers/types.ts New shared type definitions for common provider interfaces and configurations
src/providers/model.ts Refactored to use shared utilities and types, removing duplicate code
src/providers/mcp.ts Updated to use centralized MCP types and improved type safety
src/providers/mcp-types.ts New MCP-specific type definitions module
src/providers/index.ts Added exports for all new type definitions for external consumption
src/providers/constants.ts New constants module for vision model configuration
src/providers/ai-sdk.ts Refactored to use centralized AI SDK types with improved type casting
src/providers/ai-sdk-types.ts New AI SDK-specific type definitions module

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@xynehq xynehq deleted a comment from Copilot AI Sep 25, 2025
@xynehq xynehq deleted a comment from Copilot AI Sep 25, 2025
@harshpreet931 harshpreet931 force-pushed the refactor/providers-type-safety branch from 0debc0d to 3b69dc0 Compare September 25, 2025 12:36
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.

1 participant