@easbot/llm 0.3.26 → 0.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -4,6 +4,9 @@ English | [中文](./README.md)
4
4
 
5
5
  `@easbot/llm` is the **AI model aggregation layer** of the EASBot ecosystem. It handles dynamic loading of multi-vendor SDKs, model routing, configuration management, and high-level Model Provider capability wrapping. It provides business packages (agent / codebase / memory / note / skills / gateway) with a unified LLM calling abstraction, avoiding the duplication of provider routing, auth management, and error normalization across every tool package.
6
6
 
7
+ ## Version
8
+
9
+ v0.3.28
7
10
  ## Current Status (after V4 refactor)
8
11
 
9
12
  This package has evolved from an early placeholder of `@easbot/types` into a production-grade AI gateway layer that hosts two core modules: `provider/*` and `model/*`:
@@ -113,7 +116,7 @@ const reranked = await RerankProvider.rerank({
113
116
 
114
117
  // Graph entity extraction
115
118
  const graph = await GraphProvider.generateGraph({
116
- chunks: ['chunk1...', 'chunk2...', '...'], // any-length array
119
+ chunks: ['chunk1...', 'chunk2...', '...'], // any-length array
117
120
  prompt: { maxChunks: 5, maxConcurrency: 3 }, // v0.8: per-call slicing + 3 concurrent
118
121
  });
119
122
  // graph.entities / relations / summary are directly ingestable
@@ -189,10 +192,7 @@ export {
189
192
  export { initModelsRefresh } from './provider/models';
190
193
 
191
194
  // Self-developed GitHub Copilot SDK
192
- export {
193
- createOpenaiCompatible,
194
- openaiCompatible,
195
- } from './provider/sdk/copilot';
195
+ export { createOpenaiCompatible, openaiCompatible } from './provider/sdk/copilot';
196
196
  export type {
197
197
  OpenaiCompatibleProvider,
198
198
  OpenaiCompatibleProviderSettings,
@@ -226,17 +226,14 @@ After the V4 refactor, the `Provider` / `ModelsDev` / `ProviderAuth` / `Provider
226
226
  The agent package calls `setAdapterRegistry(...)` once at startup, injecting all 4 Provider implementations:
227
227
 
228
228
  ```typescript
229
- import {
230
- setAdapterRegistry,
231
- type AdapterRegistry,
232
- } from '@easbot/llm';
229
+ import { setAdapterRegistry, type AdapterRegistry } from '@easbot/llm';
233
230
 
234
231
  // At the agent-package startup entry (e.g. before Instance.provide)
235
232
  setAdapterRegistry({
236
- config: Config, // IConfigProvider — get / provider
237
- instance: Instance, // IInstanceProvider — getDirectory / getWorktree
238
- global: Global.Path, // IGlobalPathProvider — cache / data / config
239
- installation: Installation, // IInstallationProvider — getVersion
233
+ config: Config, // IConfigProvider — get / provider
234
+ instance: Instance, // IInstanceProvider — getDirectory / getWorktree
235
+ global: Global.Path, // IGlobalPathProvider — cache / data / config
236
+ installation: Installation, // IInstallationProvider — getVersion
240
237
  // V4: Auth has moved to `@easbot/utils.Auth`, no longer injected via AdapterRegistry.
241
238
  // Internally the LLM package calls `import { Auth } from '@easbot/utils'` directly.
242
239
  } satisfies AdapterRegistry);
@@ -253,14 +250,15 @@ Call setAdapterRegistry({ config: ... }) before using LLM.
253
250
 
254
251
  ### 2. 4 Provider interface contracts
255
252
 
256
- | Interface | Methods | Original agent module | Purpose |
257
- |-----------|---------|----------------------|---------|
258
- | `IConfigProvider` | `get<T>(): Promise<T>` / `provider<T>(id): Promise<T \| undefined>` | `Config` | User `~/.config/easbot/config.json` llm block (whitelist / blacklist / variant override) |
259
- | `IInstanceProvider` | `getDirectory(): string` / `getWorktree(): string` | `Instance` | Instance directory + worktree paths |
260
- | `IGlobalPathProvider` | `cache: string` / `data: string` / `config: string` | `Global.Path` | Model snapshot cache / user data / global config directory |
261
- | `IInstallationProvider` | `getVersion(): string` | `Installation` | User-Agent / compatibility checks / version info |
253
+ | Interface | Methods | Original agent module | Purpose |
254
+ | ----------------------- | ------------------------------------------------------------------- | --------------------- | ---------------------------------------------------------------------------------------- |
255
+ | `IConfigProvider` | `get<T>(): Promise<T>` / `provider<T>(id): Promise<T \| undefined>` | `Config` | User `~/.config/easbot/config.json` llm block (whitelist / blacklist / variant override) |
256
+ | `IInstanceProvider` | `getDirectory(): string` / `getWorktree(): string` | `Instance` | Instance directory + worktree paths |
257
+ | `IGlobalPathProvider` | `cache: string` / `data: string` / `config: string` | `Global.Path` | Model snapshot cache / user data / global config directory |
258
+ | `IInstallationProvider` | `getVersion(): string` | `Installation` | User-Agent / compatibility checks / version info |
262
259
 
263
260
  > **V4 change**: `IInstanceProvider.state(init)` and `IPluginProvider` have been **decomposed** (ADR 0071).
261
+ >
264
262
  > - Provider internal state caching now uses `@easbot/utils.lazyAsync(init)` (per-process singleton + explicit reset)
265
263
  > - Plugin registration uses module-level `_pluginAuthRegistry: Map<providerId, methods[]>` + `ProviderAuth.registerPluginAuthProvider()` entry injection
266
264
 
@@ -274,7 +272,7 @@ The V3-new `src/config/` module mirrors `packages/gateway/src/config/`:
274
272
  ```typescript
275
273
  import { Config, LLMConfig } from '@easbot/llm';
276
274
 
277
- const cfg = await Config.get(); // injected or fallback loader
275
+ const cfg = await Config.get(); // injected or fallback loader
278
276
  const openaiCfg = await Config.provider('openai');
279
277
 
280
278
  // Schema validation (standalone)
@@ -295,27 +293,28 @@ const parsed = LLMConfig.parse({
295
293
 
296
294
  ```typescript
297
295
  import { Flag, readEnvString, readFlagBool } from '@easbot/llm';
298
- import { Env } from '@easbot/llm'; // equivalent to: import { Env } from '@easbot/utils'
296
+ import { Env } from '@easbot/llm'; // equivalent to: import { Env } from '@easbot/utils'
299
297
 
300
- Flag.EASBOT_OUTPUT_TOKEN_MAX; // numeric field, internally dynamic
301
- readEnvString('OPENAI_API_KEY'); // wraps process.env
298
+ Flag.EASBOT_OUTPUT_TOKEN_MAX; // numeric field, internally dynamic
299
+ readEnvString('OPENAI_API_KEY'); // wraps process.env
302
300
  ```
303
301
 
304
302
  ### 5. Call-site migration table
305
303
 
306
- | Module | Pre-V3 | V3 | V4 (this refactor) |
307
- |--------|--------|----|----------------------|
308
- | `provider/auth.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(init)` + module-level `_pluginAuthRegistry` |
309
- | `provider/auth.ts` | `Auth.set(providerId, info)` | `Auth.set(...)` calls `@easbot/utils.Auth` directly (moved to utils) | `Auth.set(...)` calls `@easbot/utils.Auth` directly (moved to utils) |
310
- | `provider/auth.ts` | `Plugin.definitions()` | `getIPluginProvider().definitions()` | dependency removed; replaced by `registerPluginAuthProvider()` entry injection |
311
- | `provider/provider.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)` (module-level per-process singleton) |
312
- | `config/loader.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)` (module-level per-process singleton) |
313
- | `provider/models.ts` | `Global.Path.cache` | `getIGlobalPathProvider().cache` | (same as V3) |
314
- | `config/index.ts` | `Config.get()` | `getIConfigProvider().get()` | (same as V3) |
304
+ | Module | Pre-V3 | V3 | V4 (this refactor) |
305
+ | ---------------------- | ---------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
306
+ | `provider/auth.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(init)` + module-level `_pluginAuthRegistry` |
307
+ | `provider/auth.ts` | `Auth.set(providerId, info)` | `Auth.set(...)` calls `@easbot/utils.Auth` directly (moved to utils) | `Auth.set(...)` calls `@easbot/utils.Auth` directly (moved to utils) |
308
+ | `provider/auth.ts` | `Plugin.definitions()` | `getIPluginProvider().definitions()` | dependency removed; replaced by `registerPluginAuthProvider()` entry injection |
309
+ | `provider/provider.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)` (module-level per-process singleton) |
310
+ | `config/loader.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)` (module-level per-process singleton) |
311
+ | `provider/models.ts` | `Global.Path.cache` | `getIGlobalPathProvider().cache` | (same as V3) |
312
+ | `config/index.ts` | `Config.get()` | `getIConfigProvider().get()` | (same as V3) |
315
313
 
316
314
  **V4 refactor motivation**: `IInstanceProvider.state(init)` couples "caching" with "Instance abstraction",
317
315
  but state caching is fundamentally a **per-process singleton with explicit reset** — independent of
318
316
  `Instance.directory`. After sinking to `@easbot/utils.lazyAsync()`:
317
+
319
318
  - **Decoupled**: `IInstanceProvider` shrinks to 2 methods (`getDirectory` / `getWorktree`), single responsibility
320
319
  - **Unified**: every subsystem needing state caching (skills / mcp / plugin / etc.) reuses the same utility
321
320
  - **Testable**: `lazyAsync().reset()` is more direct than mocking a state factory
@@ -355,16 +354,16 @@ Test files are in `tests/`:
355
354
 
356
355
  **All 75 tests currently green** (across 3 test files). Coverage breakdown:
357
356
 
358
- | Category | Case count | Validation |
359
- |----------|-----------|------------|
360
- | AdapterRegistry interfaces (V4 new) | 11 | 4 Provider interface contracts / `setAdapterRegistry` injection / `hasAdapterRegistry` boolean / fail-fast throw / static reader functions |
361
- | Provider constants | 11 | DEFAULT_ENABLED_PROVIDERS / CUSTOM_PROVIDER_DEFINITIONS / PROVIDER_DISPLAY_NAMES |
362
- | ProviderAuth lazyAsync behavior (V4 new) | 3 | `registerPluginAuthProvider` triggers `_state.reset()` / `clearPluginAuthProviders` resets cache / `ProviderAuth.resetState()` clears cache |
363
- | Model type export stability | 6 | RerankInput/Result/Response + Entity/Relation/GraphInput + Note/MemorySummary |
364
- | Env / Flag namespace static fields | 6 | Env mirrors process.env keys / Flag contains LLM-package internal flags / reader function signatures (empty string vs undefined) |
365
- | LLMConfig schema | 4 | Empty object passes / Complete fields pass / Invalid model rejected / Non-array enabled_providers rejected |
366
- | ProviderConfig schema | 3 | Minimal config passes / partial design (all fields optional) / options.apiKey type validation |
367
- | ProviderAuthMethod schema | 4 | api / oauth types pass / Invalid type rejected / Missing label rejected |
357
+ | Category | Case count | Validation |
358
+ | ---------------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
359
+ | AdapterRegistry interfaces (V4 new) | 11 | 4 Provider interface contracts / `setAdapterRegistry` injection / `hasAdapterRegistry` boolean / fail-fast throw / static reader functions |
360
+ | Provider constants | 11 | DEFAULT_ENABLED_PROVIDERS / CUSTOM_PROVIDER_DEFINITIONS / PROVIDER_DISPLAY_NAMES |
361
+ | ProviderAuth lazyAsync behavior (V4 new) | 3 | `registerPluginAuthProvider` triggers `_state.reset()` / `clearPluginAuthProviders` resets cache / `ProviderAuth.resetState()` clears cache |
362
+ | Model type export stability | 6 | RerankInput/Result/Response + Entity/Relation/GraphInput + Note/MemorySummary |
363
+ | Env / Flag namespace static fields | 6 | Env mirrors process.env keys / Flag contains LLM-package internal flags / reader function signatures (empty string vs undefined) |
364
+ | LLMConfig schema | 4 | Empty object passes / Complete fields pass / Invalid model rejected / Non-array enabled_providers rejected |
365
+ | ProviderConfig schema | 3 | Minimal config passes / partial design (all fields optional) / options.apiKey type validation |
366
+ | ProviderAuthMethod schema | 4 | api / oauth types pass / Invalid type rejected / Missing label rejected |
368
367
 
369
368
  **Full integration test boundary**: After the AdapterRegistry decoupling, the llm package can mock all 4 Providers independently, and a complete end-to-end flow of `Provider.list / getModel / parseModel` no longer depends on the agent package. Follow-up task: when the agent package switches LLM implementation, add cross-package integration tests (verifying that real injected Providers match the llm-package contract).
370
369
 
@@ -403,17 +402,19 @@ pnpm --filter @easbot/llm test:run
403
402
 
404
403
  ## Differences from Historical Versions
405
404
 
406
- | Version | Key Changes |
407
- |---------|-------------|
408
- | **Early placeholder (@easbot/types residue)** | Only a 5-line index.ts comment, no business capability |
409
- | **V3 (ADR 0070)** | Added `src/interfaces.ts` (6 Provider interfaces + AdapterRegistry) + `src/config/` three-file module; refactored provider/{auth,models,provider,transform}.ts to use AdapterRegistry throughout |
410
- | **V4 (ADR 0071)** | Removed `IInstanceProvider.state()` (decomposed to `@easbot/utils.lazyAsync()`) + removed `IPluginProvider` dependency (now module-level `_pluginAuthRegistry` + `ProviderAuth.registerPluginAuthProvider()` entry); Provider interfaces reduced from 6 to 5 |
405
+ | Version | Key Changes |
406
+ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
407
+ | **Early placeholder (@easbot/types residue)** | Only a 5-line index.ts comment, no business capability |
408
+ | **V3 (ADR 0070)** | Added `src/interfaces.ts` (6 Provider interfaces + AdapterRegistry) + `src/config/` three-file module; refactored provider/{auth,models,provider,transform}.ts to use AdapterRegistry throughout |
409
+ | **V4 (ADR 0071)** | Removed `IInstanceProvider.state()` (decomposed to `@easbot/utils.lazyAsync()`) + removed `IPluginProvider` dependency (now module-level `_pluginAuthRegistry` + `ProviderAuth.registerPluginAuthProvider()` entry); Provider interfaces reduced from 6 to 5 |
411
410
 
412
411
  **V3 → V4 refactor motivation**:
412
+
413
413
  - `IInstanceProvider.state()` couples "per-process singleton + explicit reset" with the `Instance.directory` abstraction, but state caching has nothing to do with Instance paths
414
414
  - After decomposition to `@easbot/utils.lazyAsync()`, `IInstanceProvider` shrinks to 2 methods (`getDirectory` / `getWorktree`), with clean responsibility
415
415
  - `ProviderAuth` no longer depends on `IPluginProvider`, instead uses a module-level list + registration entry, with clearer semantics (plugin registration = push to list)
416
416
 
417
417
  See:
418
+
418
419
  - [ADR 0070 llm-adapter-registry](../../docs/decisions/0070-llm-adapter-registry.md) — AdapterRegistry injection pattern
419
- - [ADR 0071 llm-instance-state-decompose](../../docs/decisions/0071-llm-instance-state-decompose.md) — state decomposition
420
+ - [ADR 0071 llm-instance-state-decompose](../../docs/decisions/0071-llm-instance-state-decompose.md) — state decomposition
package/README.md CHANGED
@@ -4,9 +4,12 @@
4
4
 
5
5
  `@easbot/llm` 是 EASBot 生态系统的 **AI 模型聚合层**,负责多厂商 SDK 的动态加载、模型路由、配置管理与高层 Model Provider 的能力封装。给业务包(agent / codebase / memory / note / skills / gateway)提供统一的 LLM 调用抽象,避免每个工具包重复实现 provider 路由、auth 管理和错误归一化。
6
6
 
7
+ ## 版本
8
+
9
+ v0.3.28
7
10
  ## 当前状态(V4 重构后)
8
11
 
9
- 本包已从 `@easbot/types` 的早期占位实现演化为承载 **provider/* + model/* 两套核心模块** 的生产级 AI 网关层:
12
+ 本包已从 `@easbot/types` 的早期占位实现演化为承载 _*provider/* + model/_ 两套核心模块** 的生产级 AI 网关层:
10
13
 
11
14
  - ✅ **`src/provider/`**(7 文件):完整的工业级 provider 抽象
12
15
  - `Provider` 命名空间 —— 25+ 内置 SDK(OpenAI / Anthropic / Azure / Bedrock / Vertex / OpenRouter / Copilot / Ollama / 本地模型等)的动态加载器、`ModelsDev` catalog 合并、模型缓存、SDK 实例池化
@@ -114,7 +117,7 @@ const reranked = await RerankProvider.rerank({
114
117
 
115
118
  // 图谱实体提取
116
119
  const graph = await GraphProvider.generateGraph({
117
- chunks: ['chunk1...', 'chunk2...', '...'], // 任意长度数组
120
+ chunks: ['chunk1...', 'chunk2...', '...'], // 任意长度数组
118
121
  prompt: { maxChunks: 5, maxConcurrency: 3 }, // v0.8:per-call 切片 + 3 并发
119
122
  });
120
123
  // graph.entities / relations / summary 直接入库
@@ -190,10 +193,7 @@ export {
190
193
  export { initModelsRefresh } from './provider/models';
191
194
 
192
195
  // 自研 GitHub Copilot SDK
193
- export {
194
- createOpenaiCompatible,
195
- openaiCompatible,
196
- } from './provider/sdk/copilot';
196
+ export { createOpenaiCompatible, openaiCompatible } from './provider/sdk/copilot';
197
197
  export type {
198
198
  OpenaiCompatibleProvider,
199
199
  OpenaiCompatibleProviderSettings,
@@ -227,17 +227,14 @@ V4 重构后,`Provider` / `ModelsDev` / `ProviderAuth` / `ProviderTransform` 命
227
227
  agent 包启动时调用一次 `setAdapterRegistry(...)`,注入 4 个 Provider 实现:
228
228
 
229
229
  ```typescript
230
- import {
231
- setAdapterRegistry,
232
- type AdapterRegistry,
233
- } from '@easbot/llm';
230
+ import { setAdapterRegistry, type AdapterRegistry } from '@easbot/llm';
234
231
 
235
232
  // 在 agent 包启动入口处(例如 Instance.provide 之前)
236
233
  setAdapterRegistry({
237
- config: Config, // IConfigProvider — get / provider
238
- instance: Instance, // IInstanceProvider — getDirectory / getWorktree
239
- global: Global.Path, // IGlobalPathProvider — cache / data / config
240
- installation: Installation, // IInstallationProvider — getVersion
234
+ config: Config, // IConfigProvider — get / provider
235
+ instance: Instance, // IInstanceProvider — getDirectory / getWorktree
236
+ global: Global.Path, // IGlobalPathProvider — cache / data / config
237
+ installation: Installation, // IInstallationProvider — getVersion
241
238
  // V4 起 Auth 已下沉到 `@easbot/utils.Auth`,不再通过 AdapterRegistry 注入。
242
239
  // LLM 包内部直接 `import { Auth } from '@easbot/utils'` 调用即可。
243
240
  } satisfies AdapterRegistry);
@@ -254,14 +251,15 @@ Call setAdapterRegistry({ config: ... }) before using LLM.
254
251
 
255
252
  ### 2. 4 个 Provider 接口契约
256
253
 
257
- | 接口 | 方法 | 原 agent 模块 | 用途 |
258
- |------|------|---------------|------|
259
- | `IConfigProvider` | `get<T>(): Promise<T>` / `provider<T>(id): Promise<T \| undefined>` | `Config` | 用户 `~/.config/easbot/config.json` 的 llm 块(whitelist / blacklist / variant override) |
260
- | `IInstanceProvider` | `getDirectory(): string` / `getWorktree(): string` | `Instance` | 实例路径与 worktree 信息 |
261
- | `IGlobalPathProvider` | `cache: string` / `data: string` / `config: string` | `Global.Path` | 模型快照缓存目录 / 用户数据目录 / 全局配置目录 |
262
- | `IInstallationProvider` | `getVersion(): string` | `Installation` | User-Agent / 兼容性检查 / 版本信息 |
254
+ | 接口 | 方法 | 原 agent 模块 | 用途 |
255
+ | ----------------------- | ------------------------------------------------------------------- | -------------- | --------------------------------------------------------------------------------------- |
256
+ | `IConfigProvider` | `get<T>(): Promise<T>` / `provider<T>(id): Promise<T \| undefined>` | `Config` | 用户 `~/.config/easbot/config.json` 的 llm 块(whitelist / blacklist / variant override) |
257
+ | `IInstanceProvider` | `getDirectory(): string` / `getWorktree(): string` | `Instance` | 实例路径与 worktree 信息 |
258
+ | `IGlobalPathProvider` | `cache: string` / `data: string` / `config: string` | `Global.Path` | 模型快照缓存目录 / 用户数据目录 / 全局配置目录 |
259
+ | `IInstallationProvider` | `getVersion(): string` | `Installation` | User-Agent / 兼容性检查 / 版本信息 |
263
260
 
264
261
  > **V4 变更**:`IInstanceProvider.state(init)` 与 `IPluginProvider` 已被**拆分下沉**(ADR 0071)。
262
+ >
265
263
  > - Provider 内部 state 缓存改用 `@easbot/utils.lazyAsync(init)`(per-process 单例 + 显式 reset)
266
264
  > - Plugin 注册通过模块级 `_pluginAuthRegistry: Map<providerId, methods[]>` + `ProviderAuth.registerPluginAuthProvider()` 入口注入
267
265
 
@@ -275,7 +273,7 @@ V3 新增 `src/config/` 模块,仿 `packages/gateway/src/config/` 模式:
275
273
  ```typescript
276
274
  import { Config, LLMConfig } from '@easbot/llm';
277
275
 
278
- const cfg = await Config.get(); // 走注入或 fallback loader
276
+ const cfg = await Config.get(); // 走注入或 fallback loader
279
277
  const openaiCfg = await Config.provider('openai');
280
278
 
281
279
  // Schema 校验(可单独使用)
@@ -296,27 +294,28 @@ const parsed = LLMConfig.parse({
296
294
 
297
295
  ```typescript
298
296
  import { Flag, readEnvString, readFlagBool } from '@easbot/llm';
299
- import { Env } from '@easbot/llm'; // 等价于 import { Env } from '@easbot/utils'
297
+ import { Env } from '@easbot/llm'; // 等价于 import { Env } from '@easbot/utils'
300
298
 
301
- Flag.EASBOT_OUTPUT_TOKEN_MAX; // 数值字段,内部动态计算
302
- readEnvString('OPENAI_API_KEY'); // 包装 process.env
299
+ Flag.EASBOT_OUTPUT_TOKEN_MAX; // 数值字段,内部动态计算
300
+ readEnvString('OPENAI_API_KEY'); // 包装 process.env
303
301
  ```
304
302
 
305
303
  ### 5. 调用点改造对照表
306
304
 
307
- | 模块 | V3 之前 | V3 | V4(本次重构) |
308
- |------|--------|----|----------------|
309
- | `provider/auth.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(init)` + `_pluginAuthRegistry` 模块级 list |
310
- | `provider/auth.ts` | `Auth.set(providerId, info)` | `Auth.set(...)` 直接调用 `@easbot/utils.Auth`(下沉到 utils) | `Auth.set(...)` 直接调用 `@easbot/utils.Auth`(下沉到 utils) |
311
- | `provider/auth.ts` | `Plugin.definitions()` | `getIPluginProvider().definitions()` | 删除依赖,改用 `registerPluginAuthProvider()` 入口注入 |
312
- | `provider/provider.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)`(模块级 per-process 单例) |
313
- | `config/loader.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)`(模块级 per-process 单例) |
314
- | `provider/models.ts` | `Global.Path.cache` | `getIGlobalPathProvider().cache` | (同 V3) |
315
- | `config/index.ts` | `Config.get()` | `getIConfigProvider().get()` | (同 V3) |
305
+ | 模块 | V3 之前 | V3 | V4(本次重构) |
306
+ | ---------------------- | ---------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- |
307
+ | `provider/auth.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(init)` + `_pluginAuthRegistry` 模块级 list |
308
+ | `provider/auth.ts` | `Auth.set(providerId, info)` | `Auth.set(...)` 直接调用 `@easbot/utils.Auth`(下沉到 utils) | `Auth.set(...)` 直接调用 `@easbot/utils.Auth`(下沉到 utils) |
309
+ | `provider/auth.ts` | `Plugin.definitions()` | `getIPluginProvider().definitions()` | 删除依赖,改用 `registerPluginAuthProvider()` 入口注入 |
310
+ | `provider/provider.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)`(模块级 per-process 单例) |
311
+ | `config/loader.ts` | `Instance.state(...)` | `getIInstanceProvider().state(init)` | `lazyAsync(createState)`(模块级 per-process 单例) |
312
+ | `provider/models.ts` | `Global.Path.cache` | `getIGlobalPathProvider().cache` | (同 V3) |
313
+ | `config/index.ts` | `Config.get()` | `getIConfigProvider().get()` | (同 V3) |
316
314
 
317
315
  **V4 重构动机**:`IInstanceProvider.state(init)` 把 "缓存" 与 "Instance 抽象" 耦合在一起,
318
316
  但 state 缓存本质上是 **per-process 单例 + 显式 reset**,与 Instance.directory 无关。
319
317
  下层到 `@easbot/utils.lazyAsync()` 后:
318
+
320
319
  - **解耦**:`IInstanceProvider` 只剩 2 个方法(getDirectory / getWorktree),职责清晰
321
320
  - **统一**:Project 所有需要 state 缓存的子系统(skills / mcp / plugin 等)复用同一工具
322
321
  - **可测**:`lazyAsync().reset()` 比 mock 一个 state factory 更直接
@@ -356,16 +355,16 @@ pnpm --filter @easbot/llm test:run
356
355
 
357
356
  **当前 75 个测试全绿**(3 test files)。覆盖范围:
358
357
 
359
- | 测试大类 | 覆盖 case 数 | 验证要点 |
360
- |---------|-------------|----------|
361
- | AdapterRegistry 接口(V4 新增) | 11 | 4 Provider 接口契约 / `setAdapterRegistry` 注入 / `hasAdapterRegistry` 布尔 / fail-fast 抛错 / 静态读取函数 |
362
- | Provider 常量纯函数 | 11 | DEFAULT_ENABLED_PROVIDERS / CUSTOM_PROVIDER_DEFINITIONS / PROVIDER_DISPLAY_NAMES |
363
- | ProviderAuth lazyAsync 行为(V4 新增) | 3 | `registerPluginAuthProvider` 触发 `_state.reset()` / `clearPluginAuthProviders` 重置缓存 / `ProviderAuth.resetState()` 清空缓存 |
364
- | 模型类型导出稳定性 | 6 | RerankInput/Result/Response + Entity/Relation/GraphInput + Note/MemorySummary |
365
- | Env / Flag namespace 静态字段 | 6 | Env 镜像 process.env / Flag 包含 LLM 包内部 flag / 读取函数签名(空字符串 vs undefined) |
366
- | LLMConfig schema | 4 | 空对象通过 / 完整字段通过 / 非法 model 拒绝 / 非数组 enabled_providers 拒绝 |
367
- | ProviderConfig schema | 3 | 最小 config 通过 / partial 设计(所有字段可选) / options.apiKey 类型校验 |
368
- | ProviderAuthMethod schema | 4 | api / oauth 类型通过 / 非法 type 拒绝 / 缺 label 拒绝 |
358
+ | 测试大类 | 覆盖 case 数 | 验证要点 |
359
+ | -------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------- |
360
+ | AdapterRegistry 接口(V4 新增) | 11 | 4 Provider 接口契约 / `setAdapterRegistry` 注入 / `hasAdapterRegistry` 布尔 / fail-fast 抛错 / 静态读取函数 |
361
+ | Provider 常量纯函数 | 11 | DEFAULT_ENABLED_PROVIDERS / CUSTOM_PROVIDER_DEFINITIONS / PROVIDER_DISPLAY_NAMES |
362
+ | ProviderAuth lazyAsync 行为(V4 新增) | 3 | `registerPluginAuthProvider` 触发 `_state.reset()` / `clearPluginAuthProviders` 重置缓存 / `ProviderAuth.resetState()` 清空缓存 |
363
+ | 模型类型导出稳定性 | 6 | RerankInput/Result/Response + Entity/Relation/GraphInput + Note/MemorySummary |
364
+ | Env / Flag namespace 静态字段 | 6 | Env 镜像 process.env / Flag 包含 LLM 包内部 flag / 读取函数签名(空字符串 vs undefined) |
365
+ | LLMConfig schema | 4 | 空对象通过 / 完整字段通过 / 非法 model 拒绝 / 非数组 enabled_providers 拒绝 |
366
+ | ProviderConfig schema | 3 | 最小 config 通过 / partial 设计(所有字段可选) / options.apiKey 类型校验 |
367
+ | ProviderAuthMethod schema | 4 | api / oauth 类型通过 / 非法 type 拒绝 / 缺 label 拒绝 |
369
368
 
370
369
  **完整集成测试边界**:AdapterRegistry 解耦后,llm 包可独立 mock 全部 4 个 Provider,完整跑 `Provider.list / getModel / parseModel` 的端到端流程不依赖 agent 包。后续任务:在 agent 包切换 LLM 实现时,补跨包集成测试(验证 setAdapterRegistry 真实注入的 Provider 与 llm 包契约匹配)。
371
370
 
@@ -404,17 +403,19 @@ pnpm --filter @easbot/llm test:run
404
403
 
405
404
  ## 与历史版本的差异
406
405
 
407
- | 版本 | 关键差异 |
408
- |------|----------|
409
- | **早期占位(@easbot/types 残留)** | 仅 5 行注释的 index.ts,无业务能力 |
410
- | **V3(ADR 0070)** | 新增 `src/interfaces.ts`(6 Provider 接口 + AdapterRegistry)+ `src/config/` 三文件模块;重构 provider/{auth,models,provider,transform}.ts 全部走 AdapterRegistry |
411
- | **V4(ADR 0071)** | 删除 `IInstanceProvider.state()`(下沉到 `@easbot/utils.lazyAsync()`)+ 删除 `IPluginProvider` 依赖(改用模块级 `_pluginAuthRegistry` + `ProviderAuth.registerPluginAuthProvider()` 入口);Provider 接口 6→5 个 |
406
+ | 版本 | 关键差异 |
407
+ | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
408
+ | **早期占位(@easbot/types 残留)** | 仅 5 行注释的 index.ts,无业务能力 |
409
+ | **V3(ADR 0070)** | 新增 `src/interfaces.ts`(6 Provider 接口 + AdapterRegistry)+ `src/config/` 三文件模块;重构 provider/{auth,models,provider,transform}.ts 全部走 AdapterRegistry |
410
+ | **V4(ADR 0071)** | 删除 `IInstanceProvider.state()`(下沉到 `@easbot/utils.lazyAsync()`)+ 删除 `IPluginProvider` 依赖(改用模块级 `_pluginAuthRegistry` + `ProviderAuth.registerPluginAuthProvider()` 入口);Provider 接口 6→5 个 |
412
411
 
413
412
  **V3 → V4 重构动机**:
413
+
414
414
  - `IInstanceProvider.state()` 把"per-process 单例 + 显式 reset"与 `Instance.directory` 抽象耦合在一起,但 state 缓存与 Instance 路径无关
415
415
  - 缓存下沉到 `@easbot/utils.lazyAsync()` 后,`IInstanceProvider` 收缩为 2 个方法(`getDirectory` / `getWorktree`),职责清晰
416
416
  - `ProviderAuth` 不再依赖 `IPluginProvider`,改用模块级 list + 注册入口,概念清晰化(plugin 注册 = 推入 list)
417
417
 
418
418
  详见:
419
+
419
420
  - [ADR 0070 llm-adapter-registry](../../docs/decisions/0070-llm-adapter-registry.md) —— AdapterRegistry 注入模式
420
- - [ADR 0071 llm-instance-state-decompose](../../docs/decisions/0071-llm-instance-state-decompose.md) —— state 拆分下沉
421
+ - [ADR 0071 llm-instance-state-decompose](../../docs/decisions/0071-llm-instance-state-decompose.md) —— state 拆分下沉