opencode-anyrouter-auth 0.1.0 → 0.1.1

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/DESIGN.md CHANGED
@@ -163,9 +163,19 @@ midnight reset window.
163
163
 
164
164
  ## Models and request boundaries
165
165
 
166
- No model is enabled by default. The catalog starts from the account's discovered
167
- models. Public registry and pricing metadata may fill capabilities only for
168
- models already available to that account.
166
+ No model is enabled by default. Official AnyRouter endpoints discover models
167
+ through `https://anyrouter.top/api/pricing`, using `model_name` as the model ID,
168
+ without probing `/v1/models`. Discovery uses the account's site session or system
169
+ access token plus `New-Api-User` when available; API-key-only accounts read
170
+ anonymously. Inference keys are never sent to the pricing endpoint, and choosing
171
+ the alternate inference endpoint does not move site discovery there.
172
+
173
+ Pricing supplies catalog entries and their metadata, not a guarantee of API-key
174
+ permissions; actual inference still enforces those permissions. Public registry
175
+ metadata only enriches discovered or explicitly configured models. A pricing
176
+ failure preserves explicitly configured models with the host fallback marker,
177
+ without declaring the inference key expired. Custom non-official gateways retain
178
+ their `/models` discovery, with pricing used only for metadata enrichment.
169
179
 
170
180
  Protocol defaults:
171
181
 
package/README.md CHANGED
@@ -123,7 +123,7 @@ AnyRouter 的签到奖励会增加钱包余额,但不等于每天自动重置
123
123
  - `https://anyrouter.top`
124
124
  - `https://a-ocnfniawgw.cn-shanghai.fcapp.run`(备用 API)
125
125
 
126
- API 端点选择不会改变登录、会话导入、签到或余额查询地址。上述站点操作始终只访问 `anyrouter.top`,备用 API 域名只用于 `/v1` 或 `/v1beta` 模型请求和模型目录发现。
126
+ API 端点选择不会改变登录、会话导入、签到、余额查询或模型目录发现地址。上述站点操作始终只访问 `anyrouter.top`,备用 API 域名只用于 `/v1` 或 `/v1beta` 模型推理请求。
127
127
 
128
128
  每个账号在登录时选择一个模型 API 端点。插件重试会留在该账号所选端点内,不会在一次请求中自动切换到另一个 API 域名,以避免重复计费;跨账号切换仍由 Magpie 的原生故障转移负责。
129
129
 
@@ -133,7 +133,9 @@ API 端点选择不会改变登录、会话导入、签到或余额查询地址
133
133
 
134
134
  ## 模型与请求头
135
135
 
136
- **没有默认模型。** 模型目录按账号发现,公共注册表只补充已发现模型的能力和上限,不会仅凭公共定价表增加账号访问权限。
136
+ **没有默认模型。** 官方端点的模型目录从 `https://anyrouter.top/api/pricing` 获取,以返回条目的 `model_name` 作为模型 ID,不依赖 `/v1/models`。已有站点登录态时携带账号的 Cookie / 系统访问令牌和 `New-Api-User`;仅 API Key 模式尝试匿名读取,不会把推理 key 发给站点接口。
137
+
138
+ pricing 中的协议、能力和上限信息直接用于模型目录,公共注册表只补充元数据,不额外增加模型。目录展示不代表当前 API key 一定有权调用每个模型,实际权限仍由推理接口校验。读取失败时保留显式配置的模型并标记发现失败,不会把站点会话失效误报为推理 key 失效。自定义非官方网关仍使用其 `/models` 接口发现模型,pricing 仅补充已有模型的元数据。
137
139
 
138
140
  模型协议映射:
139
141
 
package/lib/catalog.mjs CHANGED
@@ -93,6 +93,11 @@ export function buildCatalog(rows, provider, account, explicit = {}, pricing = [
93
93
  }
94
94
 
95
95
  export function createCatalog({ site, explicit, compatibility, fetchImpl = (...args) => fetch(...args), loadRegistry = createModelRegistry({ fetchImpl }) }) {
96
+ const readPricing = (account, timeoutMs) => site.request(account, "/api/pricing", {
97
+ anonymous: !(account.userId && (account.session || account.accessToken)),
98
+ signal: AbortSignal.timeout(timeoutMs),
99
+ operation: "model catalog read"
100
+ });
96
101
  const fallback = (provider, failed = false) => {
97
102
  const models = Object.fromEntries(Object.keys(explicit().models ?? {}).filter(id => !explicit().models[id].disabled)
98
103
  .filter(id => provider.models?.[id]).map(id => {
@@ -109,6 +114,14 @@ export function createCatalog({ site, explicit, compatibility, fetchImpl = (...a
109
114
  const generatedSiteDefault = settings.api && isOfficialBase(settings.api);
110
115
  const base = account.apiBase || (generatedSiteDefault ? protocolBase(settings.api) : settings.api) ||
111
116
  protocolBase(account.siteURL);
117
+ if (isOfficialBase(base)) {
118
+ const { data: pricing } = await readPricing(account, 25000);
119
+ if (!Array.isArray(pricing)) return fallback(provider, true);
120
+ const rows = pricing.filter(row => typeof row?.model_name === "string" && row.model_name.trim())
121
+ .map(row => ({ ...row, id: row.model_name }));
122
+ if (pricing.length && !rows.length) return fallback(provider, true);
123
+ return buildCatalog(rows, provider, account, settings, [], await loadRegistry());
124
+ }
112
125
  const headers = inferenceHeaders(account, settings.headers, "responses", compatibility());
113
126
  const response = await fetchImpl(base + "/models", { headers, redirect: "error", signal: AbortSignal.timeout(25000) });
114
127
  const text = await readBoundedText(response);
@@ -120,15 +133,15 @@ export function createCatalog({ site, explicit, compatibility, fetchImpl = (...a
120
133
  }
121
134
  if (!response.ok) return fallback(provider, true);
122
135
  if (!Array.isArray(value?.data)) return fallback(provider, true);
123
- const publicMetadata = (async () => {
136
+ const siteMetadata = (async () => {
124
137
  if (!value.data.length) return [];
125
138
  try {
126
- const result = await site.request(account, "/api/pricing", { anonymous: true, signal: AbortSignal.timeout(5000), operation: "public model metadata read" });
139
+ const result = await readPricing(account, 5000);
127
140
  if (Array.isArray(result.data)) return result.data;
128
141
  } catch {}
129
142
  return [];
130
143
  })();
131
- const [pricing, registry] = await Promise.all([publicMetadata, loadRegistry()]);
144
+ const [pricing, registry] = await Promise.all([siteMetadata, loadRegistry()]);
132
145
  return buildCatalog(value.data, provider, account, settings, pricing, registry);
133
146
  } catch (error) {
134
147
  if (error.signIn) throw error;
@@ -311,7 +311,7 @@ export function createSiteClient({ fetchImpl = (...args) => fetch(...args), time
311
311
  throw new SiteError("credentials", "AnyRouter 登录和站点接口只支持 anyrouter.top。");
312
312
  }
313
313
  const headers = browserHeaders();
314
- headers.set("referer", account.siteURL + (navigation ? "/login" : "/"));
314
+ headers.set("referer", account.siteURL + (navigation ? "/login" : path === "/api/pricing" ? "/pricing" : "/"));
315
315
  if (navigation) {
316
316
  headers.set("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8");
317
317
  headers.set("cache-control", "max-age=0");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-anyrouter-auth",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "AnyRouter account login, session-based daily sign-in and native multi-account routing for Magpie, with conservative multi-protocol request protection.",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",