@linxiraos/pi-catalog 1.4.4 → 1.4.7

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +3 -3
  3. package/dist/types/build.d.ts +12 -4
  4. package/dist/types/compat/anthropic.d.ts +20 -0
  5. package/dist/types/compat/behavior.d.ts +2 -0
  6. package/dist/types/compat/catalog-policy.d.ts +2 -2
  7. package/dist/types/compat/collapse.d.ts +10 -0
  8. package/dist/types/compat/factory-droid.d.ts +2 -0
  9. package/dist/types/compat/resolve.d.ts +2 -2
  10. package/dist/types/compat/types.d.ts +5 -1
  11. package/dist/types/discovery/antigravity.d.ts +7 -2
  12. package/dist/types/discovery/codex.d.ts +4 -5
  13. package/dist/types/discovery/devin.d.ts +1 -1
  14. package/dist/types/model-cache.d.ts +8 -0
  15. package/dist/types/model-catalog-format.d.ts +37 -0
  16. package/dist/types/models.d.ts +6 -3
  17. package/dist/types/provider-models/google.d.ts +2 -0
  18. package/dist/types/provider-models/openai-compat.d.ts +16 -3
  19. package/dist/types/types.d.ts +58 -3
  20. package/dist/types/wire/codex.d.ts +1 -1
  21. package/dist/types/wire/devin.d.ts +2 -2
  22. package/dist/types/wire/gemini-headers.d.ts +41 -22
  23. package/dist/types/wire/xiaomi-token-plan.d.ts +2 -0
  24. package/package.json +6 -10
  25. package/src/build.d.ts +12 -4
  26. package/src/build.ts +97 -4
  27. package/src/compat/anthropic.d.ts +20 -0
  28. package/src/compat/anthropic.ts +47 -0
  29. package/src/compat/axes.ts +16 -3
  30. package/src/compat/behavior.d.ts +2 -0
  31. package/src/compat/behavior.ts +5 -0
  32. package/src/compat/catalog-policy.ts +10 -8
  33. package/src/compat/collapse.d.ts +10 -0
  34. package/src/compat/collapse.ts +63 -2
  35. package/src/compat/factory-droid.d.ts +2 -0
  36. package/src/compat/factory-droid.ts +3 -0
  37. package/src/compat/resolve.d.ts +2 -2
  38. package/src/compat/resolve.ts +7 -5
  39. package/src/compat/rules/README.md +24 -16
  40. package/src/compat/rules/auth/google-antigravity.kdl +2 -1
  41. package/src/compat/rules/auth/llama.cpp.kdl +1 -1
  42. package/src/compat/rules/auth/typesafe.kdl +2 -1
  43. package/src/compat/rules/auth/xiaomi-token-plan-ams.kdl +1 -1
  44. package/src/compat/rules/auth/xiaomi-token-plan-cn.kdl +1 -1
  45. package/src/compat/rules/auth/xiaomi-token-plan-sgp.kdl +1 -1
  46. package/src/compat/rules/classes/anthropic.kdl +6 -1
  47. package/src/compat/rules/classes/deepseek.kdl +2 -1
  48. package/src/compat/rules/classes/minimax.kdl +10 -0
  49. package/src/compat/rules/classes/openai.kdl +2 -2
  50. package/src/compat/rules/providers/anthropic.kdl +15 -1
  51. package/src/compat/rules/providers/deepseek.kdl +13 -10
  52. package/src/compat/rules/providers/factory-droid.kdl +72 -0
  53. package/src/compat/rules/providers/google-antigravity.kdl +7 -0
  54. package/src/compat/rules/providers/google-vertex.kdl +3 -0
  55. package/src/compat/rules/providers/kimi-code.kdl +26 -0
  56. package/src/compat/rules/providers/mistral.kdl +8 -0
  57. package/src/compat/rules/providers/moonshot.kdl +25 -0
  58. package/src/compat/rules/providers/muse-code.kdl +1 -1
  59. package/src/compat/rules/providers/openai-codex.kdl +17 -4
  60. package/src/compat/rules/providers/openai.kdl +23 -2
  61. package/src/compat/rules/providers/opencode-go.kdl +38 -3
  62. package/src/compat/rules/providers/opencode-zen.kdl +7 -0
  63. package/src/compat/rules/providers/xiaomi-token-plan-ams.kdl +1 -1
  64. package/src/compat/rules/providers/xiaomi-token-plan-cn.kdl +1 -1
  65. package/src/compat/rules/providers/xiaomi-token-plan-sgp.kdl +1 -1
  66. package/src/compat/rules/providers/xiaomi.kdl +1 -1
  67. package/src/compat/rules/runtime/behavior.kdl +39 -20
  68. package/src/compat/rules/taxonomy/kimi.kdl +7 -0
  69. package/src/compat/rules.json +1 -1
  70. package/src/compat/types.d.ts +5 -1
  71. package/src/compat/types.ts +5 -1
  72. package/src/discovery/antigravity.d.ts +7 -2
  73. package/src/discovery/antigravity.ts +41 -6
  74. package/src/discovery/codex.d.ts +4 -5
  75. package/src/discovery/codex.ts +5 -6
  76. package/src/discovery/cursor.ts +0 -6
  77. package/src/discovery/devin.d.ts +1 -1
  78. package/src/discovery/devin.ts +9 -3
  79. package/src/discovery/factory-droid.ts +38 -6
  80. package/src/model-cache.d.ts +8 -0
  81. package/src/model-cache.ts +55 -5
  82. package/src/model-catalog-format.d.ts +37 -0
  83. package/src/model-catalog-format.ts +299 -0
  84. package/src/models.d.ts +6 -3
  85. package/src/models.json +1 -1
  86. package/src/models.ts +16 -10
  87. package/src/provider-models/cache-provider-id.ts +26 -6
  88. package/src/provider-models/google.d.ts +2 -0
  89. package/src/provider-models/google.ts +13 -1
  90. package/src/provider-models/openai-compat.d.ts +16 -3
  91. package/src/provider-models/openai-compat.ts +207 -58
  92. package/src/provider-models/special.ts +5 -6
  93. package/src/types.d.ts +58 -3
  94. package/src/types.ts +63 -1
  95. package/src/wire/codex.d.ts +1 -1
  96. package/src/wire/codex.ts +1 -1
  97. package/src/wire/devin.d.ts +2 -2
  98. package/src/wire/devin.ts +2 -2
  99. package/src/wire/gemini-headers.d.ts +41 -22
  100. package/src/wire/gemini-headers.ts +68 -24
  101. package/src/wire/xiaomi-token-plan.d.ts +2 -0
  102. package/src/wire/xiaomi-token-plan.ts +4 -0
  103. package/src/models.json.d.ts +0 -9
@@ -10,6 +10,7 @@ import {
10
10
  isLikelyOpenAIResponsesId,
11
11
  modelLimitsFor,
12
12
  } from "../compat/behavior";
13
+ import { resolveAnthropicApiVersion } from "../compat/anthropic";
13
14
  import { xaiResponsesReasoningEffortMap } from "../compat/openai";
14
15
  import { hasModelScopedEffortLadder, resolveModelPolicy } from "../compat/resolve";
15
16
  import { compareRevision, parseRevision } from "../compat/revision";
@@ -40,6 +41,7 @@ import {
40
41
  type Provider,
41
42
  type ThinkingConfig,
42
43
  type TokenCost,
44
+ runnerApiKind,
43
45
  } from "../types";
44
46
  import {
45
47
  discoveryFetch,
@@ -69,6 +71,7 @@ import {
69
71
  SINGULARITYAPI_TECH_API_BASE_URL,
70
72
  normalizeSingularityApiBaseUrl,
71
73
  } from "../wire/singularityapi";
74
+ import { isXiaomiTokenPlanKey } from "../wire/xiaomi-token-plan";
72
75
  import { createBundledReferenceMap, createReferenceResolver, toModelSpec } from "./bundled-references";
73
76
  import { getDefaultModelDiscoveryBaseUrl, resolveModelCacheProviderId } from "./cache-provider-id";
74
77
  import { getClinePassModelMetadata } from "./cline-pass";
@@ -499,10 +502,10 @@ function mapAnthropicModelsDev(payload: unknown, baseUrl: string): ModelSpec<"an
499
502
  return models;
500
503
  }
501
504
 
502
- function buildAnthropicDiscoveryHeaders(apiKey: string): Record<string, string> {
505
+ function buildAnthropicDiscoveryHeaders(apiKey: string, baseUrl: string): Record<string, string> {
503
506
  const oauthToken = isAnthropicOAuthToken(apiKey);
504
507
  const headers: Record<string, string> = {
505
- "anthropic-version": "2023-06-01",
508
+ "anthropic-version": resolveAnthropicApiVersion(baseUrl),
506
509
  "anthropic-dangerous-direct-browser-access": "true",
507
510
  "anthropic-beta": ANTHROPIC_OAUTH_BETA,
508
511
  };
@@ -913,7 +916,7 @@ function createSimpleAnthropicProviderOptions(
913
916
  api: "anthropic-messages",
914
917
  provider: providerId,
915
918
  baseUrl: discoveryBaseUrl,
916
- headers: buildAnthropicDiscoveryHeaders(apiKey),
919
+ headers: buildAnthropicDiscoveryHeaders(apiKey, discoveryBaseUrl),
917
920
  mapModel: (entry, defaults) => {
918
921
  const reference = references.get(defaults.id);
919
922
  const model = mapWithBundledReference(entry, defaults, reference);
@@ -4219,9 +4222,11 @@ export function kimiCodeModelManagerOptions(
4219
4222
  config?: KimiCodeModelManagerConfig,
4220
4223
  ): ModelManagerOptions<"openai-completions"> {
4221
4224
  const apiKey = config?.apiKey;
4222
- const baseUrl = config?.baseUrl ?? "https://api.kimi.com/coding/v1";
4225
+ const baseUrl = config?.baseUrl ?? getDefaultModelDiscoveryBaseUrl("kimi-code")!;
4223
4226
  return {
4224
4227
  providerId: "kimi-code",
4228
+ cacheProviderId: resolveModelCacheProviderId("kimi-code", { apiKey, baseUrl }),
4229
+ dynamicModelsAuthoritative: true,
4225
4230
  ...(apiKey && {
4226
4231
  fetchDynamicModels: () =>
4227
4232
  fetchOpenAICompatibleModels({
@@ -4269,10 +4274,15 @@ export function kimiCodeModelManagerOptions(
4269
4274
  // 12.5. LM Studio
4270
4275
  // ---------------------------------------------------------------------------
4271
4276
 
4272
- /** Native LM Studio metadata keyed by model id from `/api/v0/models`. */
4277
+ /** Native LM Studio metadata keyed by model id from `/api/v0/models` and `/api/v1/models`. */
4273
4278
  export interface LmStudioNativeModelMetadata {
4274
4279
  input: ("text" | "image")[];
4275
4280
  contextWindow?: number;
4281
+ /**
4282
+ * LM Studio reports a decision model (`type: "decision"`): it answers typed
4283
+ * questions on `/v1/decisions` and rejects chat completions.
4284
+ */
4285
+ decision?: true;
4276
4286
  }
4277
4287
 
4278
4288
  /** Options for LM Studio's optional native metadata probe. */
@@ -4296,13 +4306,56 @@ function getLmStudioCapabilityNames(value: unknown): string[] {
4296
4306
  return value.flatMap(item => (typeof item === "string" ? [item.toLowerCase()] : []));
4297
4307
  }
4298
4308
 
4309
+ function getLmStudioModelType(entry: Record<string, unknown>): string {
4310
+ return typeof entry.type === "string" ? entry.type.toLowerCase() : "";
4311
+ }
4312
+
4299
4313
  function getLmStudioNativeInput(entry: Record<string, unknown>): ("text" | "image")[] {
4300
- const modelType = typeof entry.type === "string" ? entry.type.toLowerCase() : "";
4314
+ const modelType = getLmStudioModelType(entry);
4315
+ // A decision model stays `type: "decision"` when it reads images; LM Studio
4316
+ // says so through `has_vision_adapter` instead.
4317
+ if (modelType === "decision") {
4318
+ return entry.has_vision_adapter === true ? ["text", "image"] : ["text"];
4319
+ }
4301
4320
  const capabilities = getLmStudioCapabilityNames(entry.capabilities);
4302
4321
  const supportsImage = modelType === "vlm" || capabilities.includes("vision") || capabilities.includes("image");
4303
4322
  return supportsImage ? ["text", "image"] : ["text"];
4304
4323
  }
4305
4324
 
4325
+ /**
4326
+ * Decision models from LM Studio's v1 listing (`GET /api/v1/models`), keyed by
4327
+ * model key and by every loaded instance id. The v0 listing predates decision
4328
+ * models, so this is where `type: "decision"` is reported.
4329
+ */
4330
+ function getLmStudioV1DecisionModels(payload: unknown): Map<string, LmStudioNativeModelMetadata> {
4331
+ const metadata = new Map<string, LmStudioNativeModelMetadata>();
4332
+ if (!isRecord(payload) || !Array.isArray(payload.models)) {
4333
+ return metadata;
4334
+ }
4335
+ for (const entry of payload.models) {
4336
+ if (!isRecord(entry) || getLmStudioModelType(entry) !== "decision") {
4337
+ continue;
4338
+ }
4339
+ const instances = Array.isArray(entry.loaded_instances) ? entry.loaded_instances.filter(isRecord) : [];
4340
+ const loadedContextWindow = instances
4341
+ .map(instance => (isRecord(instance.config) ? toPositiveNumber(instance.config.context_length, null) : null))
4342
+ .find(window => window !== null);
4343
+ const contextWindow = loadedContextWindow ?? toPositiveNumber(entry.max_context_length, null) ?? undefined;
4344
+ const model: LmStudioNativeModelMetadata = {
4345
+ input: getLmStudioNativeInput(entry),
4346
+ ...(contextWindow === undefined ? {} : { contextWindow }),
4347
+ decision: true,
4348
+ };
4349
+ const ids = [entry.key, ...instances.map(instance => instance.id)];
4350
+ for (const id of ids) {
4351
+ if (typeof id === "string" && id.length > 0) {
4352
+ metadata.set(id, model);
4353
+ }
4354
+ }
4355
+ }
4356
+ return metadata;
4357
+ }
4358
+
4306
4359
  function getLmStudioNativeContextWindow(entry: Record<string, unknown>): number | undefined {
4307
4360
  // LM Studio serves `loaded_context_length` (the window the running instance
4308
4361
  // actually accepts) alongside `max_context_length` (the architectural
@@ -4321,43 +4374,52 @@ function getLmStudioNativeContextWindow(entry: Record<string, unknown>): number
4321
4374
  );
4322
4375
  }
4323
4376
 
4324
- /** Fetches LM Studio native model metadata used to mark VLM models as image-capable. */
4377
+ /**
4378
+ * Fetches LM Studio native model metadata used to mark VLM models as
4379
+ * image-capable and decision models as judges.
4380
+ */
4325
4381
  export async function fetchLmStudioNativeModelMetadata(
4326
4382
  baseUrl: string,
4327
4383
  fetchImpl: FetchImpl = fetch,
4328
4384
  options?: LmStudioNativeModelMetadataOptions,
4329
4385
  ): Promise<Map<string, LmStudioNativeModelMetadata> | null> {
4330
4386
  const nativeBaseUrl = toLmStudioNativeBaseUrl(baseUrl);
4331
- const fetchMetadata = async (signal?: AbortSignal): Promise<Map<string, LmStudioNativeModelMetadata> | null> => {
4387
+ const fetchJson = async (path: string, signal?: AbortSignal): Promise<unknown> => {
4332
4388
  try {
4333
- const response = await fetchImpl(`${nativeBaseUrl}/api/v0/models`, {
4389
+ const response = await fetchImpl(`${nativeBaseUrl}${path}`, {
4334
4390
  method: "GET",
4335
4391
  headers: { Accept: "application/json", ...options?.headers },
4336
4392
  signal,
4337
4393
  });
4338
- if (!response.ok) {
4339
- return null;
4340
- }
4341
- const payload = await response.json();
4342
- if (!isRecord(payload) || !Array.isArray(payload.data)) {
4343
- return null;
4344
- }
4345
- const metadata = new Map<string, LmStudioNativeModelMetadata>();
4346
- for (const entry of payload.data) {
4347
- if (!isRecord(entry) || typeof entry.id !== "string" || entry.id.length === 0) {
4348
- continue;
4349
- }
4350
- const contextWindow = getLmStudioNativeContextWindow(entry);
4351
- metadata.set(entry.id, {
4352
- input: getLmStudioNativeInput(entry),
4353
- ...(contextWindow === undefined ? {} : { contextWindow }),
4354
- });
4355
- }
4356
- return metadata;
4394
+ return response.ok ? await response.json() : null;
4357
4395
  } catch {
4358
4396
  return null;
4359
4397
  }
4360
4398
  };
4399
+ const fetchMetadata = async (signal?: AbortSignal): Promise<Map<string, LmStudioNativeModelMetadata> | null> => {
4400
+ // Builds without the v1 listing answer 404 there and keep v0 metadata alone.
4401
+ const [v0, v1] = await Promise.all([fetchJson("/api/v0/models", signal), fetchJson("/api/v1/models", signal)]);
4402
+ const decisions = getLmStudioV1DecisionModels(v1);
4403
+ if ((!isRecord(v0) || !Array.isArray(v0.data)) && decisions.size === 0) {
4404
+ return null;
4405
+ }
4406
+ const metadata = new Map<string, LmStudioNativeModelMetadata>();
4407
+ for (const entry of isRecord(v0) && Array.isArray(v0.data) ? v0.data : []) {
4408
+ if (!isRecord(entry) || typeof entry.id !== "string" || entry.id.length === 0) {
4409
+ continue;
4410
+ }
4411
+ const contextWindow = getLmStudioNativeContextWindow(entry);
4412
+ metadata.set(entry.id, {
4413
+ input: getLmStudioNativeInput(entry),
4414
+ ...(contextWindow === undefined ? {} : { contextWindow }),
4415
+ ...(getLmStudioModelType(entry) === "decision" ? { decision: true as const } : {}),
4416
+ });
4417
+ }
4418
+ for (const [id, model] of decisions) {
4419
+ metadata.set(id, model);
4420
+ }
4421
+ return metadata;
4422
+ };
4361
4423
  if (options?.signal !== undefined) {
4362
4424
  return fetchMetadata(options.signal);
4363
4425
  }
@@ -4370,9 +4432,7 @@ export interface LmStudioModelManagerConfig {
4370
4432
  fetch?: FetchImpl;
4371
4433
  }
4372
4434
 
4373
- export function lmStudioModelManagerOptions(
4374
- config?: LmStudioModelManagerConfig,
4375
- ): ModelManagerOptions<"openai-completions"> {
4435
+ export function lmStudioModelManagerOptions(config?: LmStudioModelManagerConfig): ModelManagerOptions<Api> {
4376
4436
  const apiKey = config?.apiKey;
4377
4437
  const baseUrl = config?.baseUrl ?? Bun.env.LM_STUDIO_BASE_URL ?? "http://127.0.0.1:1234/v1";
4378
4438
  const references = createBundledReferenceMap<"openai-completions">("lm-studio" as any);
@@ -4400,13 +4460,17 @@ export function lmStudioModelManagerOptions(
4400
4460
  if (!nativeMetadata) {
4401
4461
  return models;
4402
4462
  }
4403
- return models.map(model => {
4463
+ return models.map((model): ModelSpec<Api> => {
4404
4464
  const metadata = nativeMetadata.get(model.id);
4405
4465
  if (!metadata) {
4406
4466
  return model;
4407
4467
  }
4408
4468
  return {
4409
4469
  ...model,
4470
+ // Decision models answer only on `/v1/decisions` (OpenAI's Decisions API).
4471
+ ...(metadata.decision
4472
+ ? { api: "openai-decisions", kind: "judge", reasoning: false, supportsTools: false }
4473
+ : {}),
4410
4474
  input: metadata.input,
4411
4475
  contextWindow: metadata.contextWindow ?? model.contextWindow,
4412
4476
  };
@@ -5532,7 +5596,7 @@ export function xiaomiModelManagerOptions(
5532
5596
  : XIAOMI_TOKEN_PLAN_FALLBACK_BASE_URLS;
5533
5597
  const XIAOMI_STANDARD_BASE_URL = "https://api.xiaomimimo.com/v1";
5534
5598
  const isTokenPlanProvider = config?.tokenPlanRegion !== undefined || providerId.startsWith("xiaomi-token-plan-");
5535
- const isTokenPlanKey = isTokenPlanProvider || apiKey?.startsWith("tp-");
5599
+ const isTokenPlanKey = isTokenPlanProvider || (apiKey !== undefined && isXiaomiTokenPlanKey(apiKey));
5536
5600
  // Token-plan keys always use a TP cluster; config?.baseUrl (from catalog)
5537
5601
  // would incorrectly pin to the standard endpoint (api.xiaomimimo.com).
5538
5602
  const baseUrl = isTokenPlanKey ? tokenPlanBaseUrls[0] : (config?.baseUrl ?? XIAOMI_STANDARD_BASE_URL);
@@ -5611,11 +5675,13 @@ type LiteLLMRichEndpointModel<TApi extends Api> = {
5611
5675
  hasToolMetadata: boolean;
5612
5676
  hasSupportedOpenAIParams: boolean;
5613
5677
  hasCost: boolean;
5678
+ /** Whether an endpoint reported a string `mode`, the only signal that selects a runner api. */
5679
+ hasMode: boolean;
5614
5680
  reportedCost: Partial<ModelSpec<Api>["cost"]>;
5615
5681
  };
5616
5682
  type LiteLLMRichEndpointFailure = {
5617
5683
  endpoint: string;
5618
- reason: "http-status" | "invalid-json" | "network-error";
5684
+ reason: "http-status" | "invalid-json" | "invalid-pagination" | "network-error";
5619
5685
  status?: number;
5620
5686
  error?: unknown;
5621
5687
  };
@@ -5628,6 +5694,8 @@ type LiteLLMRichEndpointResult<TApi extends Api> =
5628
5694
  | { failure: LiteLLMRichEndpointFailure };
5629
5695
 
5630
5696
  const LITELLM_RICH_ENDPOINTS = ["/model_group/info", "/v2/model/info", "/model/info", "/v1/model/info"] as const;
5697
+ // Bound paginated management responses before trusting their advertised page count.
5698
+ const LITELLM_MAX_RICH_PAGES = 100;
5631
5699
  export const OPENAI_COMPAT_DISCOVERY_DEFAULT_CONTEXT_WINDOW = 128_000;
5632
5700
  export const OPENAI_COMPAT_DISCOVERY_DEFAULT_MAX_TOKENS = 32_768;
5633
5701
  const UNKNOWN_PROXY_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } as const;
@@ -5703,9 +5771,11 @@ function mapLiteLLMOpenAICompatibleModel(
5703
5771
  return null;
5704
5772
  }
5705
5773
  const model = mapWithBundledReference(entry, defaults, reference);
5774
+ const api = resolveLiteLLMApi(entry, model.id);
5706
5775
  return {
5707
5776
  ...model,
5708
- api: resolveLiteLLMApi(undefined, model.id),
5777
+ api,
5778
+ ...liteLLMRunnerKind(api),
5709
5779
  name: stripLiteLLMResellerUsageSuffix(model.name),
5710
5780
  };
5711
5781
  }
@@ -5839,14 +5909,28 @@ function classifyLiteLLMApiRoute(entry: LiteLLMRichModelEntry | undefined, id: s
5839
5909
  return isLikelyOpenAIResponsesModelId(modelId) ? "openai" : "unknown";
5840
5910
  }
5841
5911
 
5912
+ /**
5913
+ * Transport for a LiteLLM model group: `mode: "decisions"` answers only on the
5914
+ * proxy's `/v1/decisions` route, OpenAI-backed groups use Responses, and every
5915
+ * other group uses `fallbackApi`.
5916
+ */
5842
5917
  export function resolveLiteLLMApi(
5843
5918
  entry: Record<string, unknown> | undefined,
5844
5919
  id: string,
5845
5920
  fallbackApi: Api = "openai-completions",
5846
5921
  ): Api {
5922
+ if (entry && getLiteLLMMetadataValue(entry, "mode") === "decisions") {
5923
+ return "openai-decisions";
5924
+ }
5847
5925
  return classifyLiteLLMApiRoute(entry, id) === "openai" ? "openai-responses" : fallbackApi;
5848
5926
  }
5849
5927
 
5928
+ /** `kind` a LiteLLM row takes on `api`: runner apis (Decisions → judge) leave the chat roster; chat transports add nothing. */
5929
+ function liteLLMRunnerKind(api: Api): { kind?: ModelKind } {
5930
+ const kind = runnerApiKind(api);
5931
+ return kind ? { kind } : {};
5932
+ }
5933
+
5850
5934
  function isLiteLLMUnusableSentinelPlaceholder(entry: LiteLLMRichModelEntry): boolean {
5851
5935
  const modelGroup = toNonEmptyString(entry.model_group);
5852
5936
  const id = toNonEmptyString(entry.id);
@@ -5969,10 +6053,12 @@ function mapLiteLLMRichEntry<TApi extends Api>(
5969
6053
  // compat merge (issue #11982).
5970
6054
  ...(supportsVision === true ? { stripImageInput: false } : {}),
5971
6055
  };
6056
+ const api = options.resolveApi?.(entry, id) ?? options.api;
5972
6057
  return {
5973
6058
  id,
5974
6059
  name: toLiteLLMDisplayName(modelName, reference?.name, id),
5975
- api: options.resolveApi?.(entry, id) ?? options.api,
6060
+ api,
6061
+ ...liteLLMRunnerKind(api),
5976
6062
  provider: options.provider,
5977
6063
  baseUrl: runtimeBaseUrl,
5978
6064
  contextWindow,
@@ -6038,10 +6124,14 @@ function mergeLiteLLMRichEndpointModels<TApi extends Api>(
6038
6124
  : existing.apiRoute === "openai" || next.apiRoute === "openai"
6039
6125
  ? "openai"
6040
6126
  : "unknown";
6041
- const api = next.apiRoute === apiRoute ? next.model.api : existing.model.api;
6127
+ // Only a group's `mode` selects a runner api, and an endpoint omitting the
6128
+ // mode carries no news for it, so a runner api reported by either side wins.
6129
+ const runnerApi = [next.model.api, existing.model.api].find(api => runnerApiKind(api) !== undefined);
6130
+ const api = runnerApi ?? (next.apiRoute === apiRoute ? next.model.api : existing.model.api);
6042
6131
  const model: ModelSpec<TApi> = {
6043
6132
  ...existing.model,
6044
6133
  api,
6134
+ ...liteLLMRunnerKind(api),
6045
6135
  name: next.model.name === next.model.id ? existing.model.name : next.model.name,
6046
6136
  contextWindow: next.hasContextWindow ? next.model.contextWindow : existing.model.contextWindow,
6047
6137
  maxTokens: next.hasMaxTokens ? next.model.maxTokens : existing.model.maxTokens,
@@ -6066,6 +6156,7 @@ function mergeLiteLLMRichEndpointModels<TApi extends Api>(
6066
6156
  hasToolMetadata: existing.hasToolMetadata || next.hasToolMetadata,
6067
6157
  hasSupportedOpenAIParams: existing.hasSupportedOpenAIParams || next.hasSupportedOpenAIParams,
6068
6158
  hasCost: existing.hasCost || next.hasCost,
6159
+ hasMode: existing.hasMode || next.hasMode,
6069
6160
  };
6070
6161
  }
6071
6162
 
@@ -6084,29 +6175,83 @@ async function fetchLiteLLMRichEndpoint<TApi extends Api>(
6084
6175
  if (options.apiKey) {
6085
6176
  requestHeaders.Authorization = `Bearer ${options.apiKey}`;
6086
6177
  }
6087
- let response: Response;
6088
- try {
6089
- response = await fetchImpl(`${managementBaseUrl}${endpoint}`, {
6090
- method: "GET",
6091
- headers: requestHeaders,
6092
- signal,
6093
- });
6094
- } catch (error) {
6095
- return { failure: { endpoint, reason: "network-error", error } };
6096
- }
6097
- if (!response.ok) {
6098
- return response.status === 404 ? null : { failure: { endpoint, reason: "http-status", status: response.status } };
6099
- }
6100
- let payload: unknown;
6101
- try {
6102
- payload = await response.json();
6103
- } catch (error) {
6104
- return { failure: { endpoint, reason: "invalid-json", status: response.status, error } };
6178
+ const fetchPage = async (
6179
+ page?: number,
6180
+ ): Promise<{ payload: unknown; status: number } | { failure: LiteLLMRichEndpointFailure } | null> => {
6181
+ let response: Response;
6182
+ try {
6183
+ response = await fetchImpl(`${managementBaseUrl}${endpoint}${page === undefined ? "" : `?page=${page}`}`, {
6184
+ method: "GET",
6185
+ headers: requestHeaders,
6186
+ signal,
6187
+ });
6188
+ } catch (error) {
6189
+ return { failure: { endpoint, reason: "network-error", error } };
6190
+ }
6191
+ if (!response.ok) {
6192
+ return response.status === 404 && page === undefined
6193
+ ? null
6194
+ : { failure: { endpoint, reason: "http-status", status: response.status } };
6195
+ }
6196
+ try {
6197
+ return { payload: await response.json(), status: response.status };
6198
+ } catch (error) {
6199
+ return { failure: { endpoint, reason: "invalid-json", status: response.status, error } };
6200
+ }
6201
+ };
6202
+ const firstPage = await fetchPage();
6203
+ if (!firstPage || "failure" in firstPage) {
6204
+ return firstPage;
6105
6205
  }
6106
- const entries = extractLiteLLMRichEntries(payload);
6206
+ const entries = extractLiteLLMRichEntries(firstPage.payload);
6107
6207
  if (!entries || entries.length === 0) {
6108
6208
  return null;
6109
6209
  }
6210
+ // /v2/model/info returns {current_page, total_pages, data}; older
6211
+ // endpoints and unpaginated /v2 proxies must keep their existing behavior.
6212
+ if (
6213
+ endpoint === "/v2/model/info" &&
6214
+ isRecord(firstPage.payload) &&
6215
+ ("current_page" in firstPage.payload || "total_pages" in firstPage.payload)
6216
+ ) {
6217
+ const { current_page: currentPage, total_pages: totalPages, total_count: totalCount } = firstPage.payload;
6218
+ const invalidPage = (status: number): LiteLLMRichEndpointResult<TApi> => ({
6219
+ failure: { endpoint, reason: "invalid-pagination", status },
6220
+ });
6221
+ if (
6222
+ currentPage !== 1 ||
6223
+ typeof totalPages !== "number" ||
6224
+ !Number.isSafeInteger(totalPages) ||
6225
+ totalPages < 1 ||
6226
+ totalPages > LITELLM_MAX_RICH_PAGES ||
6227
+ (totalCount !== undefined &&
6228
+ (typeof totalCount !== "number" || !Number.isSafeInteger(totalCount) || totalCount < entries.length))
6229
+ ) {
6230
+ return invalidPage(firstPage.status);
6231
+ }
6232
+ const remainingPages = await Promise.all(
6233
+ Array.from({ length: totalPages - 1 }, (_, index) => fetchPage(index + 2)),
6234
+ );
6235
+ for (const [index, nextPage] of remainingPages.entries()) {
6236
+ if (!nextPage || "failure" in nextPage) {
6237
+ return nextPage ?? invalidPage(firstPage.status);
6238
+ }
6239
+ const nextEntries = extractLiteLLMRichEntries(nextPage.payload);
6240
+ if (
6241
+ !isRecord(nextPage.payload) ||
6242
+ nextPage.payload.current_page !== index + 2 ||
6243
+ nextPage.payload.total_pages !== totalPages ||
6244
+ (totalCount !== undefined && nextPage.payload.total_count !== totalCount) ||
6245
+ !nextEntries?.length
6246
+ ) {
6247
+ return invalidPage(nextPage.status);
6248
+ }
6249
+ entries.push(...nextEntries);
6250
+ }
6251
+ if (totalCount !== undefined && entries.length !== totalCount) {
6252
+ return invalidPage(firstPage.status);
6253
+ }
6254
+ }
6110
6255
  const deduped = new Map<string, LiteLLMRichEndpointModel<TApi>>();
6111
6256
  const excludedModelIds = new Set<string>();
6112
6257
  for (const entry of entries) {
@@ -6143,6 +6288,7 @@ async function fetchLiteLLMRichEndpoint<TApi extends Api>(
6143
6288
  supportedOpenAIParams !== undefined,
6144
6289
  hasSupportedOpenAIParams: supportedOpenAIParams !== undefined,
6145
6290
  hasCost: getLiteLLMCost(entry) !== undefined,
6291
+ hasMode: typeof getLiteLLMMetadataValue(entry, "mode") === "string",
6146
6292
  reportedCost: getLiteLLMReportedCost(entry),
6147
6293
  };
6148
6294
  const existing = deduped.get(model.id);
@@ -6217,7 +6363,7 @@ async function fetchLiteLLMRichModelsInternal<TApi extends Api>(
6217
6363
  for (const entry of deduped.values()) {
6218
6364
  if (
6219
6365
  (entry.supportsVision !== true && entry.supportsVision !== false) ||
6220
- (options.resolveApi !== undefined && entry.apiRoute === "unknown") ||
6366
+ (options.resolveApi !== undefined && (entry.apiRoute === "unknown" || !entry.hasMode)) ||
6221
6367
  (Object.keys(entry.reportedCost).length > 0 &&
6222
6368
  (entry.reportedCost.input === undefined ||
6223
6369
  entry.reportedCost.output === undefined ||
@@ -6262,6 +6408,9 @@ export function litellmModelManagerOptions(config?: LiteLLMModelManagerConfig):
6262
6408
  const baseUrl = config?.baseUrl ?? getDefaultModelDiscoveryBaseUrl("litellm")!;
6263
6409
  return {
6264
6410
  providerId: "litellm",
6411
+ // rich-v14 fetches all /v2/model/info pages so cached proxy rosters
6412
+ // include models beyond page one. rich-v13 routes `mode: decisions`
6413
+ // groups to the Decisions runner as judge rows.
6265
6414
  // rich-v12 invalidates namespaced proxy ids that missed bare catalog
6266
6415
  // references. rich-v11 excluded ClinePass gateway metadata (issue #10932).
6267
6416
  // rich-v10 filtered known non-conversational LiteLLM modes, keyed the
@@ -6854,7 +7003,7 @@ export function anthropicModelManagerOptions(
6854
7003
  api: "anthropic-messages",
6855
7004
  provider: "anthropic",
6856
7005
  baseUrl: discoveryBaseUrl,
6857
- headers: buildAnthropicDiscoveryHeaders(apiKey),
7006
+ headers: buildAnthropicDiscoveryHeaders(apiKey, discoveryBaseUrl),
6858
7007
  mapModel: (
6859
7008
  entry: OpenAICompatibleModelRecord,
6860
7009
  defaults: ModelSpec<"anthropic-messages">,
@@ -94,11 +94,10 @@ export function openaiCodexModelManagerOptions(
94
94
  * {@link unionAccountCatalogs}.
95
95
  *
96
96
  * Returns `null` when any account's fetch failed transiently, so a partial list
97
- * cannot replace the previous or bundled authoritative catalog. An account
98
- * whose credential the backend rejected outright (401/403 — revoked or
99
- * deauthorized) contributes nothing and is skipped instead: it would otherwise
100
- * veto every sibling account's models until the user removes it. If no account
101
- * produced a catalog, discovery aborts the same way.
97
+ * cannot replace the previous or bundled authoritative catalog. A definitive
98
+ * account denial (401/403 auth or 402 payment) contributes nothing and is skipped
99
+ * instead: it would otherwise veto every sibling account's models until the
100
+ * account recovers. If no account produced a catalog, discovery aborts.
102
101
  */
103
102
  function unionCodexModels(
104
103
  results: readonly { accountId: string | undefined; result: CodexModelDiscoveryResult | null }[],
@@ -107,7 +106,7 @@ function unionCodexModels(
107
106
  for (const { accountId, result } of results) {
108
107
  if (!result) return null;
109
108
  if (result.rejectedStatus !== undefined) {
110
- logger.warn("Codex model discovery skipped an account whose credential was rejected", {
109
+ logger.warn("Codex model discovery skipped an account denied by the backend", {
111
110
  accountId,
112
111
  status: result.rejectedStatus,
113
112
  });
package/src/types.d.ts CHANGED
@@ -20,12 +20,12 @@ export declare const RUNNER_API_KINDS: Record<Exclude<(typeof RUNNER_APIS)[numbe
20
20
  /** Kind a runner API serves; `undefined` for chat transports and multi-kind `local-inference`. */
21
21
  export declare function runnerApiKind(api: Api): ModelKind | undefined;
22
22
  /** Catalog APIs `generate_image` runs through a pi-ai image client; the hosted Responses pair needs a carrier model. */
23
- export declare const IMAGE_GENERATION_APIS: readonly ["openai-images", "openrouter-images", "google-generative-ai", "google-gemini-cli", "openai-responses", "openai-codex-responses"];
23
+ export declare const IMAGE_GENERATION_APIS: readonly ["openai-images", "openrouter-images", "google-generative-ai", "google-gemini-cli", "openai-responses", "openai-codex-responses", "factory-droid-agent"];
24
24
  export type ImageGenerationApi = (typeof IMAGE_GENERATION_APIS)[number];
25
25
  /**
26
26
  * Kinds a model on `api` may declare: a runner api serves its own kind; a chat
27
27
  * transport serves `chat` and `tiny`, plus `image` when `generate_image` runs it
28
- * (hosted Responses image tool, Gemini image models). `undefined` for
28
+ * (hosted Responses image tool, Gemini and Factory Droid image models). `undefined` for
29
29
  * `local-inference`, which hosts several kinds chosen by the model itself.
30
30
  */
31
31
  export declare function servedKinds(api: Api): readonly ModelKind[] | undefined;
@@ -550,6 +550,8 @@ export interface AnthropicCompat {
550
550
  supportsEagerToolInputStreaming?: boolean;
551
551
  /** Whether long prompt-cache retention (`ttl: "1h"`) is supported. Default: true for canonical Anthropic API. */
552
552
  supportsLongCacheRetention?: boolean;
553
+ /** Whether a `ttl: "1h"` breakpoint on API-key requests adds the `extended-cache-ttl-2025-04-11` beta. Unset: true (Vertex rawPredict URLs never send it). */
554
+ extendedCacheTtlBeta?: boolean;
553
555
  /**
554
556
  * Whether mid-conversation `role: "system"` messages are accepted in the
555
557
  * `messages` array. When unset, auto-detected from model and deployment policy.
@@ -608,6 +610,21 @@ export interface AnthropicCompat {
608
610
  * Default: auto-detected from provider/baseUrl and `model.reasoning`.
609
611
  */
610
612
  replayUnsignedThinking?: boolean;
613
+ /**
614
+ * Whether a thinking-mode history must carry a `thinking` block on EVERY
615
+ * assistant turn of the current turn. DeepSeek's Anthropic endpoint rejects
616
+ * the whole request (`The content[].thinking in the thinking mode must be
617
+ * passed back to the API.`) when any assistant turn after the last user text
618
+ * lacks one, including turns another upstream in the same gateway model group
619
+ * produced without reasoning. Presence is all it validates (the block text may
620
+ * be a placeholder, the signature may be empty), and only `thinking` counts —
621
+ * `redacted_thinking` does not, and that endpoint rejects the block outright.
622
+ * A model group that may fail over to such an endpoint must set this: the
623
+ * stricter member defines the replay contract for the group.
624
+ * Default: false (official Anthropic and lax proxies tolerate a turn without
625
+ * thinking and the block is not invented for them).
626
+ */
627
+ requiresThinkingPresence?: boolean;
611
628
  /**
612
629
  * Whether the endpoint requires `thinking.type: "enabled"` whenever the
613
630
  * model reasons. Use for models that reject omitted or disabled thinking.
@@ -975,9 +992,11 @@ export interface ResolvedOpenAIResponsesCompat extends ResolvedOpenAISharedCompa
975
992
  */
976
993
  export type ResolvedOpenRouterCompat = ResolvedOpenAICompat & ResolvedOpenAIResponsesCompat;
977
994
  /** Fully-resolved anthropic-messages compat view (same contract as `ResolvedOpenAICompat`). */
978
- export type ResolvedAnthropicCompat = Required<Omit<AnthropicCompat, "streamIdleTimeoutMs" | "thinkingLoopGuard" | "bedrockMessagesApi" | "effortBeta" | "disabledThinking" | "betweenToolsEffort" | "stripThinkingHistory" | "fastMode" | "maxImageDimension" | "maxImagePayloadBytes">> & {
995
+ export type ResolvedAnthropicCompat = Required<Omit<AnthropicCompat, "streamIdleTimeoutMs" | "thinkingLoopGuard" | "bedrockMessagesApi" | "effortBeta" | "extendedCacheTtlBeta" | "disabledThinking" | "betweenToolsEffort" | "stripThinkingHistory" | "fastMode" | "maxImageDimension" | "maxImagePayloadBytes">> & {
979
996
  /** Effort-beta override; undefined keeps the transport's legacy heuristic. */
980
997
  effortBeta?: AnthropicCompat["effortBeta"];
998
+ /** Extended-cache-ttl beta opt-out; undefined sends it where a 1h breakpoint needs it. */
999
+ extendedCacheTtlBeta?: AnthropicCompat["extendedCacheTtlBeta"];
981
1000
  /** Disabled-thinking wire form; undefined keeps the direct-provider behavior. */
982
1001
  disabledThinking?: AnthropicCompat["disabledThinking"];
983
1002
  /** Effort pinned on `between_tools` turns; undefined leaves effort untouched. */
@@ -1204,6 +1223,13 @@ export interface ModelAccountAccess {
1204
1223
  * Absent when the backend reported no program metadata.
1205
1224
  */
1206
1225
  cyberPrograms?: readonly string[];
1226
+ /**
1227
+ * Antigravity request constants this account's `fetchAvailableModels`
1228
+ * roster advertised, keyed by upstream SKU id. Takes precedence over
1229
+ * {@link Model.antigravityWireProfiles}, which keeps only the first
1230
+ * account's values when multi-account rosters are unioned.
1231
+ */
1232
+ antigravityWireProfiles?: Readonly<Record<string, AntigravityModelWireProfile>>;
1207
1233
  }
1208
1234
  /** One Cursor `RequestedModel.parameters` entry recovered from rich discovery. */
1209
1235
  export interface CursorModelParameter {
@@ -1216,6 +1242,20 @@ export interface CursorModelRoute {
1216
1242
  parameters: readonly CursorModelParameter[];
1217
1243
  maxMode?: boolean;
1218
1244
  }
1245
+ /**
1246
+ * Antigravity Cloud Code Assist request constants for one upstream SKU, as the
1247
+ * native client sends them; see {@link Model.antigravityWireProfiles}.
1248
+ */
1249
+ export interface AntigravityModelWireProfile {
1250
+ /** Opaque `labels.model_enum` token (`fetchAvailableModels` `model`). */
1251
+ modelEnum?: string;
1252
+ /** Fixed `generationConfig.maxOutputTokens` the client always sends. */
1253
+ maxOutputTokens?: number;
1254
+ /** SKU thinking level; the native client sends it in preference to a budget. */
1255
+ thinkingLevel?: "LOW" | "MEDIUM" | "HIGH";
1256
+ /** SKU thinking budget (`-1` is dynamic), sent when no level is advertised. */
1257
+ thinkingBudget?: number;
1258
+ }
1219
1259
  export interface Model<TApi extends Api = Api> {
1220
1260
  id: string;
1221
1261
  /** Role-specific runner capability; omitted for ordinary chat models. */
@@ -1329,6 +1369,13 @@ export interface Model<TApi extends Api = Api> {
1329
1369
  * their single wire id) and on bundled snapshots that predate discovery.
1330
1370
  */
1331
1371
  cursorMaxModeRoutes?: Readonly<Record<string, boolean>>;
1372
+ /**
1373
+ * Per-wire-id Antigravity request constants recorded from the account's
1374
+ * `fetchAvailableModels` roster, keyed by upstream SKU id. A collapsed row
1375
+ * carries one entry per member it routes to; a raw row carries its own.
1376
+ * Absent on bundled snapshots that predate discovery.
1377
+ */
1378
+ antigravityWireProfiles?: Readonly<Record<string, AntigravityModelWireProfile>>;
1332
1379
  /**
1333
1380
  * Per-account availability recorded by multi-account discovery: provider
1334
1381
  * account key (Codex: ChatGPT `chatgpt_account_id`; Antigravity: login
@@ -1525,3 +1572,11 @@ export interface ModelSpec<TApi extends Api = Api> extends Omit<Model<TApi>, "co
1525
1572
  /** Sparse compatibility overrides; resolved into `Model.compat` by `buildModel`. */
1526
1573
  compat?: CompatConfigOf<TApi>;
1527
1574
  }
1575
+ /**
1576
+ * The model facts the catalog policy cascade reads: the resolve-target inputs
1577
+ * (`providerType ?? provider`, the request adapter, the wire model id, the
1578
+ * reasoning flag) plus the unverified-thinking correction applied before the
1579
+ * cascade. Callers holding a reduced model view — request adapters that only
1580
+ * need policy — supply exactly these instead of asserting a full `Model`.
1581
+ */
1582
+ export type CatalogPolicyInputs = Pick<ModelSpec<Api>, "provider" | "providerType" | "api" | "id" | "reasoning" | "requestModelId" | "thinking">;