pi-model-manager 0.4.7 → 0.4.8

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
@@ -205,7 +205,9 @@ Each provider can define:
205
205
 
206
206
  When adding a model, the extension attempts to fetch the upstream model list. The complete discovery flow shares one 10-second limit and can be cancelled with `Esc`. Discovery uses the same API root and configured credentials as chat, and distinguishes authentication failures, missing endpoints, rate limits, and upstream errors. You can still enter a model ID manually after failure or cancellation.
207
207
 
208
- Base URL represents the API root. Both OpenAI protocols and Anthropic append `/v1` to a bare domain, preserve explicit paths, and then append the protocol endpoint. For example, Anthropic with `https://gw.example.com/xxx` uses `/xxx/messages` for chat and `/xxx/models` for discovery. Google appends `/v1beta` to its official root and preserves custom paths. Base URLs cannot contain query parameters (`?`), fragments (`#`), or embedded credentials; parameters generated by the SDK remain supported.
208
+ Base URL represents the API root, to which the protocol endpoint is appended. For example, Anthropic with `https://gw.example.com/xxx` uses `/xxx/messages` for chat and `/xxx/models` for discovery. When entering a URL or switching protocols in the provider editor, a bare domain gets `/v1` for OpenAI / Anthropic or `/v1beta` for Gemini, including custom gateway domains. Gemini converts a final `/v1` path segment to `/v1beta`; switching from Gemini back to OpenAI / Anthropic converts a final `/v1beta` to `/v1`. The host, port, and path prefix are preserved, as are other explicit paths such as `/custom`, `/v1alpha`, and `/v2`.
209
+
210
+ The converted URL appears immediately in the form and, once saved, is shared by chat and model discovery. This version conversion only runs during those configuration actions: it does not migrate unedited URLs or rewrite model-specific endpoints or unmanaged native providers. Base URLs cannot contain query parameters (`?`), fragments (`#`), or embedded credentials; parameters generated by the SDK remain supported.
209
211
 
210
212
  Standard Anthropic endpoints are converted to Pi's native SDK representation in `models.json`, so they also work without the extension. Custom version paths use private `state.json` metadata and require the extension's transport adapter. Toggling the proxy changes only the transport route, preserving the final endpoint, application headers, and payload. Proxy failures are reported.
211
213
 
package/README.md CHANGED
@@ -207,7 +207,9 @@ pi install npm:pi-model-manager
207
207
 
208
208
  新建模型时,扩展会尝试从上游读取模型列表;整次发现共用一个 10 秒上限,可按 `Esc` 手动取消。列表与聊天使用同一 API 根地址和配置的认证信息,错误会区分认证失败、接口不存在、限流和上游异常。失败或取消后仍可手动输入模型 ID。
209
209
 
210
- Base URL 表示 API 根地址:OpenAI 两种协议和 Anthropic 只填域名时补 `/v1`,显式填写路径时保留该路径,再追加协议端点。例如 Anthropic 的 `https://gw.example.com/xxx` 请求 `/xxx/messages`,模型列表请求 `/xxx/models`。Google 在官方根地址上补 `/v1beta`,自定义路径保持原样。Base URL 不支持查询参数(`?`)、片段(`#`)或内嵌认证;SDK 正常生成的请求参数不受影响。
210
+ Base URL 表示 API 根地址,再追加协议端点。例如 Anthropic 的 `https://gw.example.com/xxx` 请求 `/xxx/messages`,模型列表请求 `/xxx/models`。在接入编辑器中输入地址或切换协议时,只填域名会按协议补 `/v1`(OpenAI / Anthropic)或 `/v1beta`(Gemini,包括自定义中转域名)。Gemini 会将末尾完整路径段 `/v1` 转为 `/v1beta`;从 Gemini 切回 OpenAI / Anthropic 时,末尾 `/v1beta` 转为 `/v1`。域名、端口和路径前缀保留,其他显式路径(如 `/custom`、`/v1alpha`、`/v2`)不改写。
211
+
212
+ 转换后的地址会立即显示在表单中,保存后统一用于聊天和模型列表。此版本转换只发生在上述配置操作中,不自动迁移未编辑的存量地址,也不改写模型级独立地址或未接管的原生接入。Base URL 不支持查询参数(`?`)、片段(`#`)或内嵌认证;SDK 正常生成的请求参数不受影响。
211
213
 
212
214
  Anthropic 标准端点在写入 `models.json` 时转换为 Pi 原生 SDK 所需形式,因此未加载扩展时也能使用;自定义版本路径通过 `state.json` 私有标记衔接,依赖扩展的发送适配。代理开关只改变传输路线,最终端点、业务请求头和 payload 保持一致;代理失败会报错。
213
215
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-model-manager",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "A TUI model and provider manager for Pi with native models.json persistence, request-header profiles, proxy routing, and protocol compatibility.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -1,7 +1,7 @@
1
1
  // 4 种 API 协议的默认预设。新建接入/模型时用,便于一键填好常用字段。
2
2
 
3
3
  import type { ApiKind, ModelInputKind, ProviderDraft } from "../types.ts";
4
- import { resolveRuntimeBaseUrl } from "../runtime-base-url.ts";
4
+ import { resolveProviderDraftBaseUrl } from "../runtime-base-url.ts";
5
5
 
6
6
  export interface ProviderPreset {
7
7
  api: ApiKind;
@@ -103,10 +103,9 @@ export function switchProviderDraftApiPreset(draft: ProviderDraft, nextApi: ApiK
103
103
  if (nextApi === "openai-completions" && draft.openAIChatCompatibilityMode === undefined) {
104
104
  draft.openAIChatCompatibilityMode = "standard";
105
105
  }
106
- // [喵喵喵]: 版本路径规则随协议而变(OpenAI 要 /v1、Anthropic 不要),
107
- // 保留的自定义地址必须按新协议重新归一化,否则切完协议就指向错误端点。
106
+ // [喵喵喵]: 自定义地址只在草稿阶段按目标协议转换版本后缀,避免运行时改写存量配置。
108
107
  try {
109
- draft.baseUrl = replaceBaseUrl ? nextPreset.baseUrl : resolveRuntimeBaseUrl(nextApi, draft.baseUrl);
108
+ draft.baseUrl = replaceBaseUrl ? nextPreset.baseUrl : resolveProviderDraftBaseUrl(nextApi, draft.baseUrl, previousPreset.api);
110
109
  } catch {
111
110
  draft.baseUrl = nextPreset.baseUrl;
112
111
  }
@@ -16,7 +16,7 @@ const OPENAI_THINKING_LEVEL_MAP: ThinkingLevelMap = {
16
16
  max: "max",
17
17
  };
18
18
 
19
- // [喵喵喵]: Gemini 原生 ThinkingLevel 只有 MINIMAL/LOW/MEDIUM/HIGH;pi 的 xhigh/max 必须显式禁用。(2026-07-10)
19
+ // Google 的 xhigh/max 默认关闭,具体模型可通过显式映射启用。
20
20
  const GOOGLE_GENERATIVE_AI_THINKING_LEVEL_MAP: ThinkingLevelMap = {
21
21
  minimal: "minimal",
22
22
  low: "low",
@@ -42,17 +42,6 @@ function buildThinkingLevelMap(api: ApiKind, reasoning: boolean): ThinkingLevelM
42
42
  return { ...EXTENDED_THINKING_LEVEL_MAP };
43
43
  }
44
44
 
45
- function applyProtocolThinkingLevelLimits(
46
- api: ApiKind,
47
- thinkingLevelMap: ThinkingLevelMap | undefined,
48
- ): ThinkingLevelMap | undefined {
49
- if (api === "google-generative-ai") {
50
- return { ...(thinkingLevelMap ?? {}), ...GOOGLE_GENERATIVE_AI_THINKING_LEVEL_MAP };
51
- }
52
- if (!thinkingLevelMap) return undefined;
53
- return { ...EXTENDED_THINKING_LEVEL_MAP, ...thinkingLevelMap };
54
- }
55
-
56
45
  function mergeThinkingLevelMap(
57
46
  defaultMap: ThinkingLevelMap | undefined,
58
47
  storedMap: ThinkingLevelMap | undefined,
@@ -69,5 +58,5 @@ export function normalizeThinkingLevelMap(
69
58
  if (!reasoning) return undefined;
70
59
  const defaultMap = buildThinkingLevelMap(api, true);
71
60
  if (storedMap && isLegacyShiftedMaxLadder(storedMap)) return defaultMap;
72
- return applyProtocolThinkingLevelLimits(api, mergeThinkingLevelMap(defaultMap, storedMap));
61
+ return mergeThinkingLevelMap(defaultMap, storedMap);
73
62
  }
@@ -39,6 +39,17 @@ export function resolveRuntimeBaseUrl(api: ApiKind, baseUrl: string): string {
39
39
  return formatUrl(url);
40
40
  }
41
41
 
42
+ /** 仅用于主动编辑地址或切换协议;运行时和启动迁移必须保留显式版本路径。 */
43
+ export function resolveProviderDraftBaseUrl(api: ApiKind, baseUrl: string, previousApi?: ApiKind): string {
44
+ const url = new URL(resolveRuntimeBaseUrl(api, baseUrl));
45
+ if (api === "google-generative-ai") {
46
+ url.pathname = url.pathname === "/" ? "/v1beta" : url.pathname.replace(/\/v1$/, "/v1beta");
47
+ } else if (previousApi === "google-generative-ai") {
48
+ url.pathname = url.pathname.replace(/\/v1beta$/, "/v1");
49
+ }
50
+ return formatUrl(url);
51
+ }
52
+
42
53
  /** 标准 Anthropic 根地址存成 SDK 原生形式,自定义版本路径由私有元数据标识。 */
43
54
  export function toNativeBaseUrl(api: string, baseUrl: string): { baseUrl: string; anthropicApiRoot?: true } {
44
55
  if (api !== "anthropic-messages") return { baseUrl };
@@ -8,7 +8,7 @@ import { hasStringRecordEntries } from "../common.ts";
8
8
  import { t } from "../i18n.ts";
9
9
  import { switchProviderDraftApiPreset } from "../presets/providers.ts";
10
10
  import { redactUrlForDisplay } from "../sensitive-redaction.ts";
11
- import { resolveRuntimeBaseUrl, validateRequestBaseUrl } from "../runtime-base-url.ts";
11
+ import { resolveProviderDraftBaseUrl, validateRequestBaseUrl } from "../runtime-base-url.ts";
12
12
  import {
13
13
  DEFAULT_PROVIDER_HTTP_PROXY_URL,
14
14
  type OpenAIChatCompatibilityMode,
@@ -296,7 +296,7 @@ async function editField(
296
296
  // [喵喵喵]: 当场校验并归一化成 SDK 可直接使用的根地址;若输入有误通过通知友好提示,避免未捕获异常导致 TUI 闪退丢失草稿
297
297
  try {
298
298
  validateRequestBaseUrl(trimmed);
299
- draft.baseUrl = resolveRuntimeBaseUrl(draft.api, trimmed);
299
+ draft.baseUrl = resolveProviderDraftBaseUrl(draft.api, trimmed);
300
300
  } catch (error) {
301
301
  const message = error instanceof Error ? error.message : String(error);
302
302
  ctx.ui.notify(t("Base URL 格式错误:{error}", { error: message }), "warning");