Commit Graph

15 Commits

Author SHA1 Message Date
IronRookieCoder
b36e8e4ff2 fix(costrict): handle image input for model compatibility
## Bug 详情
CoStrict 在读取图片后会把图片放在 tool_result.content 中,OpenAI 兼容层只保留文本,导致模型没有收到真实图片内容。

非多模态模型收到图片请求时,后端会返回底层 400 错误,例如 not a multimodal model。

## 根因
OpenAI 消息转换逻辑没有处理 tool_result 中嵌套的 image block。

CoStrict 查询路径没有在发送请求前检查模型的图片输入能力,也没有归一化非多模态模型错误。

## 修复方案
将 tool_result 中的图片转换为后续 user 多模态消息,确保兼容层能传递 image_url。

在 CoStrict 模型元数据明确声明 supportsImages=false 时,提前返回英文错误提示;同时对后端非多模态错误做英文提示归一化。

## 变更要点
- Preserve image blocks nested in tool_result for OpenAI-compatible providers
- Add CoStrict image-capability gate based on supportsImages metadata
- Normalize non-multimodal backend errors to a clear English message
- Add regression tests for nested tool_result images and non-multimodal model handling

## 自测
- bun test src/costrict/provider/index.test.ts
- bun test packages/@ant/model-provider/src/shared/__tests__/openaiConvertMessages.test.ts
2026-05-19 11:38:16 +08:00
IronRookieCoder
62f4cb9daf fix: 修复 CoStrict provider 提前停止与 token override 问题 2026-05-13 16:24:34 +08:00
Askhz
158ead6cbe Merge branch 'main' into feat/costrict-max-tokens 2026-05-12 10:16:21 +08:00
Askhz
1970c698ea feat(costrict): 根据模型列表动态设置 max_tokens 参数
从 /ai-gateway/api/v1/models 返回的模型信息中读取 maxTokensKey
和 maxTokens 字段,发送请求时动态注入对应参数名和参数值。
maxTokensKey 缺失时默认使用 max_tokens,maxTokens 无值时不传该参数。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-11 21:23:28 +08:00
Askhz
4dcb3a2107 feat: add agent-type request header to CoStrict provider
在 CoStrict provider 的所有 API 请求中注入 agent-type header,
反映当前会话所使用的 agent 或 skill,默认值为 "build"。

- fetch.ts: createCoStrictFetch 接受可选 agentType 参数,PascalCase
  自动转 kebab-case(StrictSpec → strict-spec),注入 agent-type header
- index.ts: queryModelCoStrict 读取 getMainThreadAgentType()(--agent 启动)
  或 getActiveSkillName()(slash skill 触发)作为 agentType
- models.ts: /v1/models 请求添加 User-Agent: csc/{VERSION} header
- state.ts: 新增 activeSkillName 状态及 getter/setter
- processSlashCommand.tsx: inline skill 和 fork skill(context:fork)
  触发时均调用 setActiveSkillName 记录当前 skill/agent 名
- caches.ts: /clear 时调用 setActiveSkillName(undefined) 重置状态,
  避免新会话继承上一会话的 agent-type

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-11 11:17:02 +08:00
Askhz
307b025dea chore: 统一所有 provider 的 User-Agent 为 csc/${VERSION}
- getUserAgent() 简化为 csc/${VERSION},去除 USER_TYPE/entrypoint 等附加信息
- OpenAI/Grok client 通过 defaultHeaders 覆盖 SDK 自带的 User-Agent
- CoStrict 主查询和 sideQuery 的 OpenAI client 同步添加 defaultHeaders
- CoStrict fetch 的 X-Costrict-Version 同步更新为 csc/${VERSION} 格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 18:23:57 +08:00
Askhz
c28cd05d89 fix: handle reasoning_content for thinking mode in OpenAI compatibility layer
- Add reasoning_content field when thinking mode is enabled
- Set reasoning_content to empty string when no thinking content available
- Enable model auto-detection for kimi provider
- Add thinking mode support to costrict provider
2026-04-21 15:48:22 +08:00
geroge
83beec0b5e
Merge pull request #33 from Askhz/refactor/login-logic
refactor: 精简登录选项,保留 4 个主要登录方式
2026-04-21 09:39:06 +08:00
Askhz
d7bcf65968 feat: restore CoStrict login option in interactive login
- Added CoStrict option to the login Select component
- Implemented complete OAuth flow with browser opening and token polling
- Added costrict_waiting and costrict_model_select OAuth states
- Fixed TypeScript errors in fetch.ts and index.ts

The CoStrict login option was previously removed during login simplification.
This commit restores the full functionality including model selection after login.
2026-04-20 20:40:59 +08:00
yhangf
45575c4b18 Merge branch 'main' into dev 2026-04-20 20:09:58 +08:00
yhangf
d74321180f feat(costrict): enable StrictSpec workflow and refine strict skills 2026-04-20 15:17:36 +08:00
y574444354
fbeaf1395e fix: 修复 CoStrict provider 模型选择与 token 估算问题
- ConsoleOAuthFlow: 替换 ModelPicker 为直接 Select 组件,避免
  getAPIProvider() 竞态导致显示标准 Anthropic 模型列表
- modelOptions: 简化模型选项逻辑,CoStrict 凭证持有者统一走
  CoStrict 模型缓存路径,加载中显示提示而非标准模型列表
- provider/index: 回写 usage 和 stop_reason 到已 yield 的
  assistant messages,与 Anthropic 原生路径保持一致
- tokenEstimation: 非 Anthropic 原生 provider(costrict/openai/
  grok/gemini)统一使用粗略 token 估算
- 品牌文案: Claude → CoStrict 相关措辞修正
2026-04-16 19:12:01 +08:00
Ubuntu
88e2ce1e70 refactor: 重构 provider、agents、status 及相关工具模块 2026-04-14 14:21:21 +00:00
yhangf
51f597a3d2 feat(costrict): enable thinking mode in Anthropic-to-OpenAI message conversion 2026-04-09 16:40:45 +08:00
Askhz
d77963fb3f feat: add costrict login provider 2026-04-07 20:32:32 +08:00