Skip to content

Commit 73a460d

Browse files
claude-code-bestclaudesolthxchengzifeng
authored
feat: 重构供应商层次 (claude-code-best#286)
* refactor: 创建 @anthropic-ai/model-provider 包骨架与类型定义 - 新建 workspace 包 packages/@anthropic-ai/model-provider - 定义 ModelProviderHooks 接口(依赖注入:分析、成本、日志等) - 定义 ClientFactories 接口(Anthropic/OpenAI/Gemini/Grok 客户端工厂) - 搬入核心类型:Message 体系、NonNullableUsage、EMPTY_USAGE、SystemPrompt、错误常量 - 主项目 src/types/message.ts 等改为 re-export,保持向后兼容 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 提升 OpenAI 转换器和模型映射到 model-provider 包 - 搬入 OpenAI 消息转换(convertMessages)、工具转换(convertTools)、流适配(streamAdapter) - 搬入 OpenAI 和 Grok 模型映射(resolveOpenAIModel、resolveGrokModel) - 主项目文件改为 thin re-export proxy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 搬入 Gemini 兼容层到 model-provider 包 - 搬入 Gemini 类型定义、消息转换、工具转换、流适配、模型映射 - 主项目 gemini/ 目录下文件改为 thin re-export proxy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 搬入 errorUtils 并迁移消费者导入到 model-provider - 搬入 formatAPIError、extractConnectionErrorDetails 等 errorUtils - 迁移 10 个消费者文件直接从 @anthropic-ai/model-provider 导入 - 更新 emptyUsage、sdkUtilityTypes、systemPromptType 为 re-export proxy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: compact 模型降级为 -1 模式(Opus→Sonnet, Sonnet→Haiku) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: 添加 agent-loop 绘图 * Revert "feat: compact 模型降级为 -1 模式(Opus→Sonnet, Sonnet→Haiku)" This reverts commit e458d63. * docs: 添加简化版 agent loop * fix: 修复 n 快捷键导致关闭的问题 * fix: 修复 node 下 ws 没打包问题 * docs: 修复链接 * test: 添加测试支持 * fix: 修复类型问题(claude-code-best#267) (claude-code-best#271) * fix: 修复 Bun 的 polyfill 问题 * fix: 类型修复完成 * feat: 统一所有包的类型文件 * fix: 修复构建问题 * test: 修复类型校验 (claude-code-best#279) * fix: 修复 Bun 的 polyfill 问题 * fix: 类型修复完成 * feat: 统一所有包的类型文件 * fix: 修复构建问题 * fix(remote-control): harden self-hosted session flows (claude-code-best#278) Co-authored-by: chengzifeng <chengzifeng@meituan.com> * docs: update contributors * build: 新增 vite 构建流程 * feat: 添加环境变量支持以覆盖 max_tokens 设置 * feat(langfuse): LLM generation 记录工具定义 将 Anthropic 格式的工具定义转换为 Langfuse 兼容的 OpenAI 格式, 并在 generation 的 input 中以 { messages, tools } 结构传入, 以便在 Langfuse UI 中查看完整的工具定义信息。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: 添加对 ACP 协议的支持 (claude-code-best#284) * feat: 适配 zed acp 协议 * docs: 完善 acp 文档 * chore: 1.4.0 * conflict: 解决冲突 * feat: 添加测试覆盖率上报 * style: 改名加移动文件夹位置 * refactor: 移动测试用例及实现 * test: 修复测试用例完成 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Cheng Zi Feng <1154238323@qq.com> Co-authored-by: chengzifeng <chengzifeng@meituan.com> Co-authored-by: claude-code-best <272536312+claude-code-best@users.noreply.github.com>
1 parent 3312446 commit 73a460d

86 files changed

Lines changed: 1661 additions & 1766 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ jobs:
2323
- name: Type check
2424
run: bunx tsc --noEmit
2525

26-
- name: Test
27-
run: bun test
26+
- name: Test with Coverage
27+
run: bun test --coverage --coverage-reporter=lcov
28+
29+
- name: Upload coverage to Codecov
30+
uses: codecov/codecov-action@v5
31+
with:
32+
token: ${{ secrets.CODECOV_TOKEN }}
2833

2934
- name: Build
3035
run: bun run build:vite

bun.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
flowchart TB
2+
START((输入)) --> CTX["Context 管理"]
3+
CTX --> LLM["LLM 流式输出"]
4+
LLM --> TC{tool_use?}
5+
6+
TC --> || EXEC["执行工具"]
7+
EXEC --> CTX
8+
9+
TC --> || DONE((完成))
10+
11+
classDef proc fill:#eef,stroke:#66c,color:#224
12+
classDef decision fill:#fee,stroke:#c66,color:#422
13+
classDef io fill:#eff,stroke:#6cc,color:#244
14+
15+
class CTX,LLM,EXEC proc
16+
class TC decision
17+
class START,DONE io

docs/diagrams/agent-loop.mmd

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
flowchart TB
2+
START((输入)) --> CTX["Context 管理"]
3+
CTX --> PRE["Pre-sampling Hook"]
4+
PRE --> LLM["LLM 流式输出"]
5+
LLM --> TC{tool_use?}
6+
7+
TC --> || PERM{需权限?}
8+
PERM --> || USER["👤 用户审批"]
9+
USER --> |allow| TOOL_PRE
10+
USER --> |deny| DENIED["拒绝"]
11+
PERM --> || TOOL_PRE["Pre-tool Hook"]
12+
TOOL_PRE --> EXEC["并发执行工具"]
13+
EXEC --> TOOL_POST["Post-tool Hook"]
14+
TOOL_POST --> CTX
15+
DENIED --> CTX
16+
17+
TC --> || POST["Post-sampling Hook"]
18+
POST --> STOP{"Stop Hook"}
19+
STOP --> |不通过| CTX
20+
STOP --> |通过| BUDGET{"Token Budget"}
21+
BUDGET --> |继续| CTX
22+
BUDGET --> |完成| DONE((完成))
23+
24+
subgraph SUB["子 Agent"]
25+
FORK["AgentTool"] --> RECURSE["递归调用"]
26+
end
27+
28+
EXEC -.-> FORK
29+
30+
classDef proc fill:#eef,stroke:#66c,color:#224
31+
classDef decision fill:#fee,stroke:#c66,color:#422
32+
classDef hook fill:#ffe,stroke:#cc6,color:#442
33+
classDef io fill:#eff,stroke:#6cc,color:#244
34+
classDef sub fill:#efe,stroke:#6a6,color:#242
35+
36+
class CTX,LLM,EXEC proc
37+
class TC,PERM,STOP,BUDGET decision
38+
class PRE,TOOL_PRE,TOOL_POST,POST hook
39+
class START,DONE,USER,DENIED io
40+
class FORK,RECURSE sub

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
},
3232
"workspaces": [
3333
"packages/*",
34-
"packages/@ant/*"
34+
"packages/@ant/*",
35+
"packages/@anthropic-ai/*"
3536
],
3637
"files": [
3738
"dist",
@@ -65,6 +66,7 @@
6566
},
6667
"devDependencies": {
6768
"@alcalzone/ansi-tokenize": "^0.3.0",
69+
"@ant/model-provider": "workspace:*",
6870
"@ant/claude-for-chrome-mcp": "workspace:*",
6971
"@ant/computer-use-input": "workspace:*",
7072
"@ant/computer-use-mcp": "workspace:*",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.json",
2+
"extends": "../../../tsconfig.base.json",
33
"include": ["src/**/*.ts"],
44
"exclude": ["node_modules", "dist"]
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.json",
2+
"extends": "../../../tsconfig.base.json",
33
"include": ["src/**/*.ts"],
44
"exclude": ["node_modules", "dist"]
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.json",
2+
"extends": "../../../tsconfig.base.json",
33
"include": ["src/**/*.ts"],
44
"exclude": ["node_modules", "dist"]
55
}

packages/@ant/ink/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "../../../tsconfig.json",
2+
"extends": "../../../tsconfig.base.json",
33
"include": ["src/**/*.ts", "src/**/*.tsx"],
44
"exclude": ["node_modules", "dist"]
55
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@ant/model-provider",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"main": "./src/index.ts",
7+
"types": "./src/index.ts",
8+
"exports": {
9+
".": "./src/index.ts",
10+
"./types": "./src/types/index.ts",
11+
"./hooks": "./src/hooks/index.ts",
12+
"./client": "./src/client/index.ts"
13+
},
14+
"dependencies": {
15+
"@anthropic-ai/sdk": "^0.80.0",
16+
"openai": "^6.33.0"
17+
}
18+
}

0 commit comments

Comments
 (0)