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