Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ bun run ./scripts/build.ts --feature=ULTRAPLAN --feature=ULTRATHINK
bun run ./scripts/build.ts --dev --feature-set=dev-full --feature=BRIDGE_MODE
```

### LLM Adapter Seam (`LLM_ADAPTER_SEAM`)

A provider-neutral seam (`src/services/llm/`) decouples the runtime from `@anthropic-ai/sdk`'s error layer. When this flag is on and the provider is `firstParty` or `fusionMlx`, requests bypass `anthropic.beta.messages.create` and POST `/v1/messages` directly via the seam (SSE→StreamChunk→SDK parts). Error handling uses duck-typing guards (`isApiErrorLike`/`isAbortError`) instead of `instanceof` SDK classes. Default off; in the `dev-full` set. See `docs/model-providers.md` § "LLM Adapter 接缝". Cloud providers (bedrock/vertex/foundry) still use the SDK client — full decoupling tracked in issues #63/#64/#65.

---

## Usage
Expand All @@ -433,6 +437,12 @@ Collect session trajectories and export training datasets (SFT/DPO/GRPO) for fus

See [docs/trajectory-pipeline.md](docs/trajectory-pipeline.md) for details.

### Production Acceptance

v0.4.18 核心特性生产验收 (13 项: 多供应商路由 / Feature Flags / MLX Tiering / 权限模式 / Slash Commands / Plugins / Context Management / Workflows / FUSION.rules / Context Hub / Agent Tools / Safe Mode / Telemetry):

See [docs/acceptance-report.md](docs/acceptance-report.md) for full report.

### Permission Modes

Press **Shift+Tab** to cycle modes:
Expand Down
31 changes: 31 additions & 0 deletions docs/div-anthropic-audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 去 Anthropic SDK 审计清单

> 分支 feat/div-anthropic 基线 (2026-08-15)
> typecheck/test/build 全绿 | 38 tests 0 fail | bundle 162650210 bytes

## 运行时 (value) import @anthropic-ai/sdk

src/components/agents/new-agent-creation/wizard-steps/GenerateStep.tsx
src/hooks/useCanUseTool.tsx
src/services/api/client.ts
src/services/api/errors.ts
src/services/api/logging.ts
src/services/api/withRetry.ts
src/services/compact/compact.ts
src/tools/BashTool/bashPermissions.ts
src/types/anthropic-protocol.ts
src/utils/permissions/permissions.ts

## 类型 (type-only) import @anthropic-ai/sdk

src/types/anthropic-protocol.ts

## anthropic-protocol.ts 垫片消费者数
103

## package.json @anthropic-ai/* 依赖
"@anthropic-ai/claude-agent-sdk": "^0.2.87",
"@anthropic-ai/foundry-sdk": "^0.2.3",
"@anthropic-ai/mcpb": "^2.1.2",
"@anthropic-ai/sandbox-runtime": "^0.0.44",
"@anthropic-ai/sdk": "^0.80.0",
37 changes: 37 additions & 0 deletions docs/model-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,43 @@ ANTHROPIC_VERTEX_PROJECT_ID=xxx \

注:当前 fork 中 vertex 分支已禁用,需恢复源码中 `if (false)` 分支才能使用。

## LLM Adapter 接缝 (div-anthropic Phase 1-5)

为去除对 `@anthropic-ai/sdk` 的运行时耦合,fusion-code 引入 provider 中立的 **LLM 接缝 (seam)**。分支 `feat/div-anthropic`,feature flag `LLM_ADAPTER_SEAM` 守护(默认关,`dev-full` feature-set 开启)。

### 架构

```
claude.ts queryModel()
└─ if (isSeamActive(model)) ← flag + provider∈{firstParty, fusionMlx}
streamViaSeam(params, signal, model) ← 接缝路径
├─ httpClient.postMessages() ← 裸 HTTP POST /v1/messages
├─ parseSseStream() → sseToChunk() ← SSE → StreamChunk (provider 中立)
└─ chunkStreamToSdkParts() ← StreamChunk → SDK part (喂下方既有 switch, 零改动)
else
anthropic.beta.messages.create({stream}) ← SDK 路径 (flag 关 / 云 provider)
```

flag 关时 `streamViaSeam` 经 Bun DCE 消除,回滚=关 flag。

### 错误层解耦 (Phase 5)

错误处理不再 `instanceof` SDK 错误类,改用鸭子类型桥 (`src/services/llm/errors.ts`),同时接受 SDK `APIError`(flag-off)与接缝 `LlmRequestError`(flag-on):

| 鸭子守卫 | 替代的 SDK 判定 | 判定依据 |
|----------|----------------|----------|
| `isApiErrorLike(e)` | `instanceof APIError` | `Error` + 有 `status`/`headers`/`requestID` 之一 |
| `isConnectionErrorLike(e)` | `instanceof APIConnectionError` | `LlmRequestError` code=TRANSPORT/TIMEOUT,或 `.name` 含 "Connection" |
| `isTimeoutErrorLike(e)` | `instanceof APIConnectionTimeoutError` | code=TIMEOUT,或 `.name` 含 "Timeout",或 message 含 "timeout" |
| `isAbortError(e)` | `instanceof APIUserAbortError` | `.name`∈{APIUserAbortError, AbortError},或 message="Request was aborted." |

`utils/errors.ts` 的 `isAbortError` 用 `.name`/`.message` 而非 `instanceof`,因 minified build 中 SDK 类名混淆为 `nJT` 且 SDK 不设 `.name`。

### 当前范围与遗留

- **已完成**:错误层 12 个文件脱 SDK 运行时;编译后二进制 0 处 `@anthropic-ai/sdk` 错误类引用;firstParty+fusionMlx 经接缝跑通(MLX smoke 200 OK)。
- **未完成(见 issue #63/#64/#65)**:`client.ts` 的 `new Anthropic(...)` 仍为云 provider(bedrock/vertex/foundry 签名)必需;`package.json` 的 SDK 依赖未移除。接缝当前只覆盖 firstParty+fusionMlx。

## 辅助函数

| 函数 | 文件 | 说明 |
Expand Down
1 change: 1 addition & 0 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const fullExperimentalFeatures = [
"EXTRACT_MEMORIES",
"HISTORY_PICKER",
"HOOK_PROMPTS",
"LLM_ADAPTER_SEAM",
"MCP_RICH_OUTPUT",
"MESSAGE_ACTIONS",
"NATIVE_CLIPBOARD_IMAGE",
Expand Down
Loading
Loading