pi-alibaba-token-plan 1.1.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
@@ -66,9 +66,11 @@ answer; its levels are `low`, `medium` and `xhigh` — ask for `:xhigh`, not `:h
66
66
  package for models those catalogs lag on.
67
67
  - Pi stores the resulting catalog in `~/.pi/agent/models-store.json`, which is what offline starts and
68
68
  `pi -p` use. The list is refreshed on interactive startup, at most once every 15 minutes.
69
- - **First run:** start `pi` interactively once. Until that first catalog fetch there is nothing stored,
70
- so `pi --list-models` and `pi -p` show no models for this provider. (`pi update --models` only
71
- 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.)
72
74
  - A failed or empty answer never wipes the catalog you already have.
73
75
 
74
76
  Only chat models are listed. The plan's image, video and audio models are filtered out.
package/README.ru.md CHANGED
@@ -66,7 +66,9 @@ Alibaba; выключить thinking нельзя. Контекст модели
66
66
  небольшой проверенной таблицы внутри пакета.
67
67
  - Полученный каталог pi хранит в `~/.pi/agent/models-store.json` — именно его используют офлайн-запуски
68
68
  и `pi -p`. Список обновляется при интерактивном запуске, не чаще раза в 15 минут.
69
- - **Первый запуск:** один раз запустите `pi` в терминале. До первой загрузки каталога хранить нечего,
69
+ - Логин обновляет его сразу, независимо от окна: `/login` (интерактивно) и `pi auth login`
70
+ запускают сетевой refresh сразу после сохранения ключа.
71
+ - **Первый запуск:** каталог загружается самим логином. До этой загрузки хранить нечего,
70
72
  поэтому `pi --list-models` и `pi -p` не показывают моделей этого провайдера. (`pi update --models`
71
73
  обновляет только встроенные каталоги pi, не провайдеры-расширения.)
72
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.1.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