linshenkx/prompt-optimizer · error · ImageModelManagerError

CONFIG_INVALID

CONFIG_INVALID

Error message

Missing provider/model identity

What it means

Thrown by ImageModelManager.getConfigIdentity when a config carries neither providerId/provider.id nor modelId/model.id. The manager needs a (providerId, modelId) pair to key, deduplicate, and persist configs, and ensureSelfContained calls this during import/registration to verify the identity is present.

Source

Thrown at packages/core/src/services/image-model/manager.ts:410

    }

    // 合并 customParamOverrides 到 paramOverrides
    return {
      ...config,
      paramOverrides: {
        ...(config.paramOverrides || {}),
        ...(config.customParamOverrides || {})
      }
      // 保留 customParamOverrides 字段以防版本回退,但新代码不再使用
    }
  }

  private getConfigIdentity(config: ImageModelConfigInput): { providerId: string, modelId: string } {
    const providerId = config.providerId || config.provider?.id || config.model?.providerId
    const modelId = config.modelId || config.model?.id

    if (!providerId || !modelId) {
      throw new ImageModelManagerError(
        IMAGE_ERROR_CODES.CONFIG_INVALID,
        'Missing provider/model identity',
        { details: 'Missing providerId/modelId' },
      )
    }

    return { providerId, modelId }
  }

  // 确保配置是自包含的(包含完整的provider和model信息)
  private ensureSelfContained(config: ImageModelConfigInput): ImageModelConfig {
    let identity: { providerId: string, modelId: string }

    try {
      identity = this.getConfigIdentity(config)
    } catch (error) {
      console.warn(`[ImageModelManager] Cannot infer identity for config ${config.id}, marking as disabled:`, error)
      identity = {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Set providerId (or provider.id) and modelId (or model.id) explicitly on the config before calling the API.
  2. If building from partial data, look up the provider id first and merge it into the config.
  3. Add a pre-flight check/zod schema requiring both fields so the error surfaces at the boundary.

Example fix

// before
await manager.addModel({ modelId: 'qwen-image', /* no provider info */ } as any)

// after
await manager.addModel({
  providerId: 'dashscope',
  modelId: 'qwen-image',
} as any)
Defensive patterns

Strategy: type-guard

Validate before calling

const providerId = cfg.providerId ?? cfg.provider?.id
const modelId = cfg.modelId ?? cfg.model?.id
if (!providerId || !modelId) throw new Error('config lacks identity')

Type guard

const hasIdentity = (c: any): c is ImageModelConfigInput & { providerId: string, modelId: string } =>
  Boolean(c?.providerId || c?.provider?.id) && Boolean(c?.modelId || c?.model?.id)

Prevention

When it happens

Trigger: Passing a config where providerId and provider?.id are both falsy, or modelId and model?.id are both falsy — e.g. { modelId: 'x' } with no provider fields, or { provider: { name: 'openai' } } with an id-less provider object.

Common situations: Building a config from a UI form where the provider select was left empty; partial configs from external sources that carry only a model name; refactors that renamed id fields.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/79cc23e3b65cd081. Report an issue: GitHub.