pi-alibaba-token-plan 1.0.0 → 1.2.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/README.md CHANGED
@@ -52,9 +52,11 @@ export ALIBABA_TOKEN_PLAN_REGION=sg # sg (default) or cn
52
52
  pi --model alibaba-openai/qwen4-max-preview:xhigh
53
53
  ```
54
54
 
55
- Thinking levels for the Qwen models are `low`, `medium` and `xhigh` — ask for `:xhigh`, not `:high`.
55
+ Thinking levels for `qwen4-max` are `low`, `high` and `xhigh` — only the values Alibaba documents,
56
+ and thinking cannot be turned off. The model has a 1M context and a 262,144-token output budget.
56
57
  `qwen4-max-preview` has a 1M context and a 393,216-token output budget shared by thinking and the
57
- answer. It is a **preview**: Alibaba retires it after 2026-11-25.
58
+ answer; its levels are `low`, `medium` and `xhigh` — ask for `:xhigh`, not `:high`. It is a
59
+ **preview**: Alibaba retires it after 2026-11-25.
58
60
 
59
61
  ## How the model list works
60
62
 
@@ -64,9 +66,11 @@ answer. It is a **preview**: Alibaba retires it after 2026-11-25.
64
66
  package for models those catalogs lag on.
65
67
  - Pi stores the resulting catalog in `~/.pi/agent/models-store.json`, which is what offline starts and
66
68
  `pi -p` use. The list is refreshed on interactive startup, at most once every 15 minutes.
67
- - **First run:** start `pi` interactively once. Until that first catalog fetch there is nothing stored,
68
- so `pi --list-models` and `pi -p` show no models for this provider. (`pi update --models` only
69
- refreshes Pi's built-in catalogs, not provider extensions.)
69
+ - A login always refetches it immediately, inside that window or not: `/login` (interactive) and
70
+ `pi auth login` both run a network refresh right after the credential is saved.
71
+ - **First run:** the login itself fetches the catalog. Until that fetch completes there is nothing
72
+ stored, so `pi --list-models` and `pi -p` show no models for this provider. (`pi update --models`
73
+ only refreshes Pi's built-in catalogs, not provider extensions.)
70
74
  - A failed or empty answer never wipes the catalog you already have.
71
75
 
72
76
  Only chat models are listed. The plan's image, video and audio models are filtered out.
package/README.ru.md CHANGED
@@ -52,9 +52,11 @@ export ALIBABA_TOKEN_PLAN_REGION=sg # sg (по умолчанию) или cn
52
52
  pi --model alibaba-openai/qwen4-max-preview:xhigh
53
53
  ```
54
54
 
55
- Уровни thinking у моделей Qwen — `low`, `medium` и `xhigh`: просите `:xhigh`, а не `:high`.
56
- У `qwen4-max-preview` контекст 1M и бюджет вывода 393 216 токенов, общий для thinking и ответа.
57
- Это **превью**: Alibaba отключает модель после 25.11.2026.
55
+ Уровни thinking у `qwen4-max` — `low`, `high` и `xhigh`: только значения, которые документирует
56
+ Alibaba; выключить thinking нельзя. Контекст модели — 1M, бюджет вывода — 262 144 токена.
57
+ У `qwen4-max-preview` контекст 1M и бюджет вывода 393 216 токенов, общий для thinking и ответа;
58
+ уровни — `low`, `medium` и `xhigh`: просите `:xhigh`, а не `:high`. Это **превью**: Alibaba
59
+ отключает модель после 25.11.2026.
58
60
 
59
61
  ## Как устроен список моделей
60
62
 
@@ -64,7 +66,9 @@ pi --model alibaba-openai/qwen4-max-preview:xhigh
64
66
  небольшой проверенной таблицы внутри пакета.
65
67
  - Полученный каталог pi хранит в `~/.pi/agent/models-store.json` — именно его используют офлайн-запуски
66
68
  и `pi -p`. Список обновляется при интерактивном запуске, не чаще раза в 15 минут.
67
- - **Первый запуск:** один раз запустите `pi` в терминале. До первой загрузки каталога хранить нечего,
69
+ - Логин обновляет его сразу, независимо от окна: `/login` (интерактивно) и `pi auth login`
70
+ запускают сетевой refresh сразу после сохранения ключа.
71
+ - **Первый запуск:** каталог загружается самим логином. До этой загрузки хранить нечего,
68
72
  поэтому `pi --list-models` и `pi -p` не показывают моделей этого провайдера. (`pi update --models`
69
73
  обновляет только встроенные каталоги pi, не провайдеры-расширения.)
70
74
  - Неудачный или пустой ответ никогда не стирает уже имеющийся каталог.
@@ -36,21 +36,27 @@ export default function register(pi, { fetchImpl = fetch, agentDir = join(homedi
36
36
  });
37
37
  }
38
38
 
39
+ let refreshAfterLogin = false;
40
+
39
41
  const provider = createProvider({
40
42
  id: PROVIDER_ID,
41
43
  name: "Alibaba Token Plan",
42
44
  baseUrl: baseUrlFor(DEFAULT_REGION),
43
- auth: { apiKey: createApiKeyAuth({ fetchImpl }) },
45
+ auth: { apiKey: createApiKeyAuth({ fetchImpl, onLogin: () => (refreshAfterLogin = true) }) },
44
46
  models: [],
45
47
  fetchModels,
46
48
  api: openAICompletionsApi(),
47
49
  });
48
50
 
49
51
  // Freshness policy: within the interval, ask pi for a restore-only pass so a
50
- // startup does not refetch. `force` (pi update --models) always goes to the network.
52
+ // startup does not refetch. A saved login and `force` (pi update --models)
53
+ // always go to the network, like the built-in providers after an OAuth login.
51
54
  const refresh = provider.refreshModels;
52
- provider.refreshModels = (context) =>
53
- refresh(isFresh(context.stored) && !context.force ? { ...context, allowNetwork: false } : context);
55
+ provider.refreshModels = (context) => {
56
+ const afterLogin = refreshAfterLogin && context.allowNetwork !== false;
57
+ if (afterLogin) refreshAfterLogin = false;
58
+ return refresh(isFresh(context.stored) && !context.force && !afterLogin ? { ...context, allowNetwork: false } : context);
59
+ };
54
60
 
55
61
  pi.registerProvider(provider);
56
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-alibaba-token-plan",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "description": "Alibaba Model Studio Token Plan provider for Pi: /login with region selection and a live model catalog",
6
6
  "license": "MIT",
package/src/auth.js CHANGED
@@ -9,7 +9,7 @@ const REQUEST_TIMEOUT_MS = 6000;
9
9
  * region is chosen at login and stored with the credential; request auth then
10
10
  * carries the matching baseUrl.
11
11
  */
12
- export function createApiKeyAuth({ fetchImpl = fetch, timeoutMs = REQUEST_TIMEOUT_MS } = {}) {
12
+ export function createApiKeyAuth({ fetchImpl = fetch, timeoutMs = REQUEST_TIMEOUT_MS, onLogin } = {}) {
13
13
  async function readKeyAndRegion({ ctx, credential }) {
14
14
  const storedKey = credential?.type === "api_key" ? credential.key : undefined;
15
15
  const key = storedKey ?? (await ctx.env(API_KEY_ENV));
@@ -45,6 +45,9 @@ export function createApiKeyAuth({ fetchImpl = fetch, timeoutMs = REQUEST_TIMEOU
45
45
  }
46
46
  if (!response.ok) throw new Error(`Token Plan key check failed with HTTP ${response.status}`);
47
47
 
48
+ // A saved credential invalidates the catalog cache, so Pi's post-login
49
+ // refresh must not be downgraded to a restore-only pass.
50
+ onLogin?.();
48
51
  return { type: "api_key", key, env: { [REGION_ENV]: region } };
49
52
  },
50
53
 
package/src/catalog.js CHANGED
@@ -29,6 +29,18 @@ const NON_CHAT_ID = /(^wan|image|audio|tts|asr|realtime|video|embed|rerank|ocr)/
29
29
  // Models the plan serves but the catalogs do not describe yet. Specs come from
30
30
  // https://docs.modelstudio.console.alibabacloud.com/en/model-studio/<model-id>.
31
31
  export const VERIFIED_OVERRIDES = {
32
+ // Alias: qwen4.0-max. Thinking on by default (high).
33
+ "qwen4-max": {
34
+ name: "Qwen4 Max",
35
+ reasoning: true,
36
+ input: ["text", "image"],
37
+ contextWindow: 1_000_000,
38
+ // Thinking output cap.
39
+ maxTokens: 262_144,
40
+ // Docs: reasoning_effort accepts low|high|xhigh only; thinking cannot be turned off.
41
+ thinkingLevelMap: { off: null, minimal: null, low: "low", medium: null, high: "high", xhigh: "xhigh", max: null },
42
+ compat: { thinkingFormat: "qwen", supportsReasoningEffort: true, supportsStrictMode: true },
43
+ },
32
44
  // Preview until 2026-11-25. Alias: qwen4.0-max-preview. Thinking on by default (xhigh).
33
45
  "qwen4-max-preview": {
34
46
  name: "Qwen4 Max Preview",