From a227f6dcb9437085a30551d99f735d0b920bea9c Mon Sep 17 00:00:00 2001 From: MyPrototypeWhat <43230886+MyPrototypeWhat@users.noreply.github.com> Date: Thu, 4 Sep 2025 14:03:04 +0800 Subject: [PATCH] Feat/aisdk package (#7404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: enhance AI SDK middleware integration and support - Added AiSdkMiddlewareBuilder for dynamic middleware construction based on various conditions. - Updated ModernAiProvider to utilize new middleware configuration, improving flexibility in handling completions. - Refactored ApiService to pass middleware configuration during AI completions, enabling better control over processing. - Introduced new README documentation for the middleware builder, outlining usage and supported conditions. * feat: enhance AI core functionality with smoothStream integration - Added smoothStream to the middleware exports in index.ts for improved streaming capabilities. - Updated PluginEnabledAiClient to conditionally apply middlewares, removing the default simulateStreamingMiddleware. - Modified ModernAiProvider to utilize smoothStream in streamText, enhancing text processing with configurable chunking and delay options. * feat: enhance AI SDK documentation and client functionality - Added detailed usage examples for the native provider registry in the README.md, demonstrating how to create and utilize custom provider registries. - Updated ApiClientFactory to enforce type safety for model instances. - Refactored PluginEnabledAiClient methods to support both built-in logic and custom registry usage for text and object generation, improving flexibility and usability. * refactor: update AiSdkToChunkAdapter and middleware for improved chunk handling - Modified convertAndEmitChunk method to handle new chunk types and streamline processing. - Adjusted thinkingTimeMiddleware to remove unnecessary parameters and enhance clarity. - Updated middleware integration in AiSdkMiddlewareBuilder for better middleware management. * feat: add Cherry Studio transformation and settings plugins - Introduced cherryStudioTransformPlugin for converting Cherry Studio messages to AI SDK format, enhancing compatibility. - Added cherryStudioSettingsPlugin to manage Assistant settings like temperature and TopP. - Implemented createCherryStudioContext function for preparing context metadata for Cherry Studio calls. * fix: refine experimental_transform handling and improve chunking logic - Updated PluginEnabledAiClient to streamline the handling of experimental_transform parameters. - Adjusted ModernAiProvider's smoothStream configuration for better chunking of text, enhancing processing efficiency. - Re-enabled block updates in messageThunk for improved state management. * refactor: update ApiClientFactory and index_new for improved type handling and provider mapping - Changed the type of options in ClientConfig to 'any' for flexibility. - Overloaded createImageClient method to support different provider settings. - Added vertexai mapping to the provider type mapping in index_new.ts for enhanced compatibility. * feat: enhance AI SDK documentation and client functionality - Added detailed usage examples for the native provider registry in the README.md, demonstrating how to create and utilize custom provider registries. - Updated ApiClientFactory to enforce type safety for model instances. - Refactored PluginEnabledAiClient methods to support both built-in logic and custom registry usage for text and object generation, improving flexibility and usability. * feat: add openai-compatible provider and enhance provider configuration - Introduced the @ai-sdk/openai-compatible package to support compatibility with OpenAI. - Added a new ProviderConfigFactory and ProviderConfigBuilder for streamlined provider configuration. - Updated the provider registry to include the new Google Vertex AI import path. - Enhanced the index.ts to export new provider configuration utilities for better type safety and usability. - Refactored ApiService and middleware to integrate the new provider configurations effectively. * feat: enhance Vertex AI provider integration and configuration - Added support for Google Vertex AI credentials in the provider configuration. - Refactored the VertexAPIClient to handle both standard and VertexProvider types. - Implemented utility functions to check Vertex AI configuration completeness and create VertexProvider instances. - Updated provider mapping in index_new.ts to ensure proper handling of Vertex AI settings. * feat: enhance provider options and examples for AI SDK - Introduced new utility functions for creating and merging provider options, improving type safety and usability. - Added comprehensive examples for OpenAI, Anthropic, Google, and generic provider options to demonstrate usage. - Refactored existing code to streamline provider configuration and enhance clarity in the options management. - Updated the PluginEnabledAiClient to simplify the handling of model parameters and improve overall functionality. * feat: add patch for Google Vertex AI and enhance private key handling - Introduced a patch for the @ai-sdk/google-vertex package to improve URL handling based on region. - Added a new utility function to format private keys, ensuring correct PEM structure and validation. - Updated the ProviderConfigBuilder to utilize the new private key formatting function for Google credentials. - Created a pnpm workspace configuration to manage patched dependencies effectively. * feat: add OpenAI Compatible provider and enhance provider configuration - Introduced a new OpenAI Compatible provider to the AiProviderRegistry, allowing for integration with the @ai-sdk/openai-compatible package. - Updated provider configuration logic to support the new provider, including adjustments to API host formatting and options management. - Refactored middleware to streamline handling of OpenAI-specific configurations. * fix: enhance anthropic provider configuration and middleware handling - Updated providerToAiSdkConfig to support both OpenAI and Anthropic providers, improving flexibility in API host formatting. - Refactored thinkingTimeMiddleware to ensure all chunks are correctly enqueued, enhancing middleware functionality. - Corrected parameter naming in getAnthropicReasoningParams for consistency and clarity in configuration. * feat: enhance AI SDK chunk handling and tool call processing - Introduced ToolCallChunkHandler for managing tool call events and results, improving the handling of tool interactions. - Updated AiSdkToChunkAdapter to utilize the new handler, streamlining the processing of tool call chunks. - Refactored transformParameters to support dynamic tool integration and improved parameter handling. - Adjusted provider mapping in factory.ts to include new provider types, enhancing compatibility with various AI services. - Removed obsolete cherryStudioTransformPlugin to clean up the codebase and focus on more relevant functionality. * feat: enhance provider ID resolution in AI SDK - Updated getAiSdkProviderId function to include mapping for provider types, improving compatibility with third-party SDKs. - Refined return logic to ensure correct provider ID resolution, enhancing overall functionality and support for various providers. * refactor: restructure AI Core architecture and enhance client functionality - Updated the AI Core documentation to reflect the new architecture and design principles, emphasizing modularity and type safety. - Refactored the client structure by removing obsolete files and consolidating client creation logic into a more streamlined format. - Introduced a new core module for managing execution and middleware, improving the overall organization of the codebase. - Enhanced the orchestration layer to provide a clearer API for users, integrating the creation and execution processes more effectively. - Added comprehensive type definitions and utility functions for better type safety and usability across the SDK. * refactor: simplify AI Core architecture and enhance runtime execution - Restructured the AI Core documentation to reflect a simplified two-layer architecture, focusing on clear responsibilities between models and runtime layers. - Removed the orchestration layer and consolidated its functionality into the runtime layer, streamlining the API for users. - Introduced a new runtime executor for managing plugin-enhanced AI calls, improving the handling of execution and middleware. - Updated the core modules to enhance type safety and usability, including comprehensive type definitions for model creation and execution configurations. - Removed obsolete files and refactored existing code to improve organization and maintainability across the SDK. * feat: enhance AI Core runtime with advanced model handling and middleware support - Introduced new high-level APIs for model creation and configuration, improving usability for advanced users. - Enhanced the RuntimeExecutor to support both direct model usage and model ID resolution, allowing for more flexible execution options. - Updated existing methods to accept middleware configurations, streamlining the integration of custom processing logic. - Refactored the plugin system to better accommodate middleware, enhancing the overall extensibility of the AI Core. - Improved documentation to reflect the new capabilities and usage patterns for the runtime APIs. * feat: enhance plugin system with new reasoning and text plugins - Introduced `reasonPlugin` and `textPlugin` to improve chunk processing and handling of reasoning content. - Updated `transformStream` method signatures for better type safety and usability. - Enhanced `ThinkingTimeMiddleware` to accurately track thinking time using `performance.now()`. - Refactored `ThinkingBlock` component to utilize block thinking time directly, improving performance and clarity. - Added logging for middleware builder to assist in debugging and monitoring middleware configurations. * refactor: update RuntimeExecutor and introduce MCP Prompt Plugin - Changed `pluginClient` to `pluginEngine` in `RuntimeExecutor` for clarity and consistency. - Updated method calls in `RuntimeExecutor` to use the new `pluginEngine`. - Enhanced `AiSdkMiddlewareBuilder` to include `mcpTools` in the middleware configuration. - Added `MCPPromptPlugin` to support tool calls within prompts, enabling recursive processing and improved handling of tool interactions. - Updated `ApiService` to pass `mcpTools` during chat completion requests, enhancing integration with the new plugin system. * feat: enhance MCP Prompt plugin and recursive call capabilities - Updated `tsconfig.web.json` to support wildcard imports for `@cherrystudio/ai-core`. - Enhanced `package.json` to include type definitions and imports for built-in plugins. - Introduced recursive call functionality in `PluginManager` and `PluginEngine`, allowing for improved handling of tool interactions. - Added `MCPPromptPlugin` to facilitate tool calls within prompts, enabling recursive processing of tool results. - Refactored `transformStream` methods across plugins to accommodate new parameters and improve type safety. * :