Skip to content

[Bug]: VertexAI Provider Data Storage Architecture Flaw - Type Mismatch with Actual Storage #13194

@EurFelux

Description

@EurFelux

Note

This issue was translated by Claude.

Bug Description

The VertexAI Provider object stored in Redux has a fundamental type mismatch with the VertexProvider type definition! This leads to code relying on false type assertions and complex runtime mappings.

Problem Symptoms

  1. Type System Lies - The isVertexProvider() function only checks the type field but claims to return a VertexProvider type containing googleCredentials and project fields
  2. Scattered Data Storage - VertexAI configuration is stored in two places:
    • Provider object in llm.providers[] (basic configuration)
    • llm.settings.vertexai (sensitive configuration)
  3. Inconsistent Field Naming - Redux state uses serviceAccount/projectId, but type definitions expect googleCredentials/project
  4. Manual Mapping Required - All code using VertexAI must call createVertexProvider() for mapping, which is error-prone

Proof

The following code locations all require defensive checks or explicit mapping, indicating the type system is untrustworthy:

  • src/renderer/src/utils/provider.ts:159-161 - isVertexProvider() false type assertion
  • src/renderer/src/hooks/useVertexAI.ts:46-59 - Must call createVertexProvider() for mapping
  • src/renderer/src/aiCore/legacy/clients/gemini/VertexAPIClient.ts:26-30 - Needs to check if it's really a VertexProvider, otherwise manually map
  • src/renderer/src/aiCore/provider/providerConfig.ts:321-335 - Must call createVertexProvider() to get configuration

Redux Actual Storage

// Provider object in llm.providers[]:
{
  id: 'vertexai'
  type: 'vertexai'        
  apiKey: string          
  apiHost: string         
  // ❌ Missing googleCredentials, project, location
}

// Real configuration is in llm.settings.vertexai:
{
  serviceAccount: {           // ❌ Should be called googleCredentials
    privateKey: string
    clientEmail: string
  }
  projectId: string          // ❌ Should be called project
  location: string
}

Expected Behavior

VertexAI configuration should have a single source of truth, and the type system should accurately reflect the actual data structure!

Steps To Reproduce

  1. View the VertexProvider type definition in src/renderer/src/types/provider.ts
  2. View the storage structure in Redux state src/renderer/src/store/llm.ts
  3. Check the implementation of the isVertexProvider() function
  4. Trace all code paths using VertexAI configuration

Expected Behavior

  1. The type system should accurately reflect the runtime data structure
  2. VertexAI configuration should be stored in a single, consistent location
  3. No complex mapping functions and defensive checks are needed

Additional Context

This is an architectural design flaw, not a user-visible bug. But it leads to:

  • Difficult code maintenance
  • Easy to introduce bugs (type mismatch)
  • Runtime performance overhead (mapping functions)
  • Poor developer experience (type system cannot help developers)

Need to refactor the VertexAI Provider data storage architecture!


Original Content

Bug Description

Redux 中存储的 VertexAI Provider 对象与 VertexProvider 类型定义存在根本的类型不匹配喵!这导致代码依赖于虚假的类型断言和复杂的运行时映射喵。

问题症状喵

  1. 类型系统说谎 - isVertexProvider() 函数只检查 type 字段,但声称返回包含 googleCredentialsproject 字段的 VertexProvider 类型
  2. 数据分散存储 - VertexAI 配置被分散存储在两个地方:
    • llm.providers[] 中的 Provider 对象(基础配置)
    • llm.settings.vertexai 中(敏感配置)
  3. 字段命名不一致 - Redux 状态使用 serviceAccount/projectId,但类型定义期望 googleCredentials/project
  4. 必须手动映射 - 所有使用 VertexAI 的代码都必须调用 createVertexProvider() 进行映射,容易出错

证明喵

以下代码位置都需要防御性检查或显式映射,说明类型系统不可信喵:

  • src/renderer/src/utils/provider.ts:159-161 - isVertexProvider() 虚假的类型断言
  • src/renderer/src/hooks/useVertexAI.ts:46-59 - 必须调用 createVertexProvider() 进行映射
  • src/renderer/src/aiCore/legacy/clients/gemini/VertexAPIClient.ts:26-30 - 需要检查是否真的是 VertexProvider,否则手动映射
  • src/renderer/src/aiCore/provider/providerConfig.ts:321-335 - 必须调用 createVertexProvider() 来获取配置

Redux 实际存储喵

// llm.providers[] 中的 Provider 对象:
{
  id: 'vertexai'
  type: 'vertexai'        
  apiKey: string          
  apiHost: string         
  // ❌ 缺少 googleCredentials、project、location
}

// 真实配置在 llm.settings.vertexai 中:
{
  serviceAccount: {           // ❌ 应该叫 googleCredentials
    privateKey: string
    clientEmail: string
  }
  projectId: string          // ❌ 应该叫 project
  location: string
}

预期行为喵

VertexAI 配置应该有唯一的真实来源,类型系统应该能够准确反映实际的数据结构喵!

Steps To Reproduce

  1. 查看 src/renderer/src/types/provider.ts 中的 VertexProvider 类型定义
  2. 查看 Redux 状态 src/renderer/src/store/llm.ts 中的存储结构
  3. 检查 isVertexProvider() 函数的实现
  4. 追踪所有使用 VertexAI 配置的代码路径

Expected Behavior

  1. 类型系统应该准确反映运行时数据结构
  2. VertexAI 配置应该存储在一个单一的、一致的地方
  3. 不需要复杂的映射函数和防御性检查

Additional Context

这是一个架构设计缺陷,不是用户可见的 bug。但会导致:

  • 代码维护困难
  • 容易引入 bug(类型不匹配)
  • 运行时性能开销(映射函数)
  • 开发体验差(类型系统无法帮助开发者)

需要重构 VertexAI Provider 的数据存储架构喵!

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUGCategorizes issue or PR as related to a bugDataCategorizes an issue or PR as relevant to SIG DataP2Medium priority

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions