@zhushanwen/pi-llm-shared 0.3.1 → 0.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-llm-shared",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Shared LLM invocation library for Pi extensions — model resolution (ref exact only), LLM calling (completeSimple), and config read/write with mtime caching. Shared library, not a Pi extension.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -21,8 +21,8 @@
21
21
  "@zhushanwen/pi-file-lock": "0.1.1"
22
22
  },
23
23
  "peerDependencies": {
24
- "@earendil-works/pi-ai": "*",
25
- "@earendil-works/pi-coding-agent": "*"
24
+ "@earendil-works/pi-ai": "^0.84.1",
25
+ "@earendil-works/pi-coding-agent": "^0.84.1"
26
26
  },
27
27
  "peerDependenciesMeta": {
28
28
  "@earendil-works/pi-ai": {
@@ -33,8 +33,8 @@
33
33
  }
34
34
  },
35
35
  "devDependencies": {
36
- "@earendil-works/pi-ai": "*",
37
- "@earendil-works/pi-coding-agent": "*",
36
+ "@earendil-works/pi-ai": "^0.84.2",
37
+ "@earendil-works/pi-coding-agent": "^0.84.2",
38
38
  "@vitest/coverage-v8": "^4.1.9",
39
39
  "vitest": "^4.1.8"
40
40
  },
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // resolve: 模型解析(仅 ref 精确指定)
3
3
  // call: LLM 调用(completeSimple + 凭证 + 文本提取)
4
4
  // config: 泛型配置读写(mtime 缓存 + 原子写)
5
- export { resolveModel, type ModelSelector } from "./resolve.ts";
5
+ export { resolveModel, getCurrentModelId, type ModelSelector } from "./resolve.ts";
6
6
  export { callLLM, extractText, type CallLLMOptions, type CallLLMResult } from "./call.ts";
7
7
  export { getConfigPath, loadConfig, saveConfig, clearConfigCache } from "./config.ts";
8
8
  export { migrateLegacyConfig, type MigrationResult } from "./migrate.ts";
package/src/resolve.ts CHANGED
@@ -44,3 +44,9 @@ function resolveRef(ctx: ExtensionContext, ref: string): Model<Api> | null {
44
44
  export function resolveModel(ctx: ExtensionContext, selector: ModelSelector): Model<Api> | null {
45
45
  return resolveRef(ctx, selector.ref);
46
46
  }
47
+
48
+ /** 当前模型的 "provider/modelId" 复合串(model 缺失返回空串)——smart-context / model-switch 共用口径。 */
49
+ export function getCurrentModelId(model: { provider?: string; id?: string } | undefined | null): string {
50
+ if (!model) return "";
51
+ return `${model.provider ?? ""}/${model.id ?? ""}`;
52
+ }