Skip to content

feat(adapter-gemini): 支持 camelCase 媒体字段配置#892

Open
Sor85 wants to merge 1 commit into
ChatLunaLab:v1-devfrom
Sor85:feat/gemini-camelcase-media-fields
Open

feat(adapter-gemini): 支持 camelCase 媒体字段配置#892
Sor85 wants to merge 1 commit into
ChatLunaLab:v1-devfrom
Sor85:feat/gemini-camelcase-media-fields

Conversation

@Sor85
Copy link
Copy Markdown

@Sor85 Sor85 commented May 29, 2026

摘要

  • 为 Gemini 适配器增加对 inlineDatamimeType 字段的驼峰命名(camelCase)选项支持。
  • 默认禁用上述两项配置。
  • 为 zh-CN 和 en-US 补充模式标签(Schema labels)。

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 387f841c-0a6d-4eb4-9da8-42d0582c36be

📥 Commits

Reviewing files that changed from the base of the PR and between 2229393 and f96fbaf.

⛔ Files ignored due to path filters (2)
  • packages/adapter-gemini/src/locales/en-US.schema.yml is excluded by !**/*.yml
  • packages/adapter-gemini/src/locales/zh-CN.schema.yml is excluded by !**/*.yml
📒 Files selected for processing (2)
  • packages/adapter-gemini/src/index.ts
  • packages/adapter-gemini/src/utils.ts

总览

该PR为 Gemini 适配器添加配置选项以支持内联数据字段的不同命名风格(camelCase 或 snake_case),并重构内容处理逻辑以统一通过新工具函数生成内联数据部分。

变更

Gemini 适配器内联数据命名约定支持

层级 / 文件 摘要
配置接口与模式定义
packages/adapter-gemini/src/index.ts
Config 接口新增 useCamelCaseInlineDatauseCamelCaseMimeType 布尔字段,对应的 Schema 添加校验与默认值(均为 false)。
内联数据工具函数与类型
packages/adapter-gemini/src/utils.ts
新增 GeminiInlineDataContent 类型定义与 isGeminiInlineDataContent 类型保护函数;实现 createGeminiInlineDataPart 工具函数以根据配置选择字段命名风格;图片内容处理改为调用统一生成器。
消息部分内联数据检测与标准化
packages/adapter-gemini/src/utils.ts
在消息内容 part 映射时新增对已存在 inline_data/inlineData 字段的检测分支,提取数据与 MIME 类型后通过统一工具函数标准化返回。

📊 代码审查工作量估算

🎯 2 (简单) | ⏱️ ~10 分钟

兔兔来报喜,API 字段名重构奏,

camelCase 与 snake 皆可用,配置灵活妙,

内联数据统一生成,代码更清爽!🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确概括了主要变更内容,即为 Gemini 适配器添加 camelCase 媒体字段配置选项,与文件修改内容完全对应。
Description check ✅ Passed 描述清晰地说明了改动的核心目标,包括新增 camelCase 配置选项、默认禁用以及标签补充,与实际代码变更内容相符。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces two new configuration options, useCamelCaseInlineData and useCamelCaseMimeType, to the Gemini adapter, allowing the system to toggle between camelCase and snake_case for inline data and mime type fields. It refactors the content processing logic in utils.ts to utilize these options and adds corresponding schema definitions and translations. The review feedback highlights a potential runtime error in utils.ts due to a lack of null-safety checks when processing inline data, and suggests correcting the Chinese translation in zh-CN.schema.yml to accurately refer to 'camelCase' as '驼峰式' instead of '大写' (uppercase).

Comment on lines +327 to +334
if (isGeminiInlineDataContent(part)) {
const inline = part.inline_data ?? part.inlineData
return createGeminiInlineDataPart(
plugin,
inline.data,
inline.mime_type ?? inline.mimeType
)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

isGeminiInlineDataContent(part) 返回 true 时,part.inline_datapart.inlineData 仍有可能为 undefined(例如属性存在但值为 undefined)。此外,如果 inline.data 缺失,直接访问 inline.data 会导致运行时错误,且不符合 createGeminiInlineDataPart 的参数类型要求。建议在调用前进行空值安全检查。

            if (isGeminiInlineDataContent(part)) {
                const inline = part.inline_data ?? part.inlineData
                if (inline?.data != null) {
                    return createGeminiInlineDataPart(
                        plugin,
                        inline.data,
                        inline.mime_type ?? inline.mimeType ?? 'image/jpeg'
                    )
                }
            }

Comment on lines +25 to +26
useCamelCaseInlineData: 使用大写的 inlineData 而不是小写的 inline_data
useCamelCaseMimeType: 使用大写的 mimeType 而不是小写的 mime_type
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

这里的翻译使用了“大写”,但实际上 inlineDatamimeType 是驼峰命名(camelCase)而非全大写(UPPERCASE)。建议将其修改为“驼峰式”,以保证描述的准确性。

      useCamelCaseInlineData: 使用驼峰式的 inlineData 而不是小写的 inline_data
      useCamelCaseMimeType: 使用驼峰式的 mimeType 而不是小写的 mime_type

Copy link
Copy Markdown
Member

@dingyi222666 dingyi222666 left a comment

Choose a reason for hiding this comment

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

你让 codex 化简实现,byd 一个小功能怎么要加这么多行代码和类型

@dingyi222666
Copy link
Copy Markdown
Member

还有你的的 commit 记得签名,让 codex 去 git rebase 给你签名了,不弄我就 ntr 了

@dingyi222666
Copy link
Copy Markdown
Member

还有,两个开关直接合并成一个而不是两个

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