@linxiraos/pi-catalog 1.1.7 → 1.1.9

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 (308) hide show
  1. package/CHANGELOG.md +7 -8
  2. package/README.md +9 -8
  3. package/package.json +96 -100
  4. package/src/build.ts +165 -48
  5. package/src/cline-pass-model-id.ts +11 -0
  6. package/src/compat/anthropic.ts +15 -136
  7. package/src/compat/auth-ids.ts +157 -0
  8. package/src/compat/auth.ts +60 -0
  9. package/src/compat/axes.ts +301 -0
  10. package/src/compat/behavior.ts +207 -0
  11. package/src/compat/cascade.ts +230 -0
  12. package/src/{variant-collapse.ts → compat/collapse.ts} +381 -773
  13. package/src/compat/delegation.ts +37 -0
  14. package/src/compat/openai.ts +17 -848
  15. package/src/compat/resolve.ts +1231 -0
  16. package/src/compat/revision.ts +154 -0
  17. package/src/compat/rules/README.md +315 -0
  18. package/src/compat/rules/auth/_order.kdl +13 -0
  19. package/src/compat/rules/auth/abliteration.kdl +9 -0
  20. package/src/compat/rules/auth/aiand.kdl +9 -0
  21. package/src/compat/rules/auth/aimlapi.kdl +3 -0
  22. package/src/compat/rules/auth/alibaba-coding-plan.kdl +5 -0
  23. package/src/compat/rules/auth/alibaba-token-plan.kdl +11 -0
  24. package/src/compat/rules/auth/amazon-bedrock.kdl +5 -0
  25. package/src/compat/rules/auth/anthropic.kdl +53 -0
  26. package/src/compat/rules/auth/azure.kdl +3 -0
  27. package/src/compat/rules/auth/baseten.kdl +9 -0
  28. package/src/compat/rules/auth/bedrock-mantle.kdl +5 -0
  29. package/src/compat/rules/auth/cerebras.kdl +9 -0
  30. package/src/compat/rules/auth/cline-pass.kdl +12 -0
  31. package/src/compat/rules/auth/cloudflare-ai-gateway.kdl +4 -0
  32. package/src/compat/rules/auth/coreweave.kdl +9 -0
  33. package/src/compat/rules/auth/cursor.kdl +5 -0
  34. package/src/compat/rules/auth/deepinfra.kdl +11 -0
  35. package/src/compat/rules/auth/deepseek.kdl +10 -0
  36. package/src/compat/rules/auth/devin.kdl +28 -0
  37. package/src/compat/rules/auth/exa.kdl +9 -0
  38. package/src/compat/rules/auth/firepass.kdl +14 -0
  39. package/src/compat/rules/auth/fireworks.kdl +16 -0
  40. package/src/compat/rules/auth/github-copilot.kdl +7 -0
  41. package/src/compat/rules/auth/gitlab-duo-agent.kdl +23 -0
  42. package/src/compat/rules/auth/gitlab-duo.kdl +24 -0
  43. package/src/compat/rules/auth/gmi-cloud.kdl +9 -0
  44. package/src/compat/rules/auth/google-antigravity.kdl +28 -0
  45. package/src/compat/rules/auth/google-gemini-cli.kdl +26 -0
  46. package/src/compat/rules/auth/google-vertex.kdl +5 -0
  47. package/src/compat/rules/auth/google.kdl +3 -0
  48. package/src/compat/rules/auth/groq.kdl +3 -0
  49. package/src/compat/rules/auth/huggingface.kdl +9 -0
  50. package/src/compat/rules/auth/kagi.kdl +9 -0
  51. package/src/compat/rules/auth/kilo.kdl +4 -0
  52. package/src/compat/rules/auth/kimi-code.kdl +18 -0
  53. package/src/compat/rules/auth/litellm.kdl +8 -0
  54. package/src/compat/rules/auth/llama.cpp.kdl +10 -0
  55. package/src/compat/rules/auth/lm-studio.kdl +7 -0
  56. package/src/compat/rules/auth/meta.kdl +9 -0
  57. package/src/compat/rules/auth/minimax-code-cn.kdl +9 -0
  58. package/src/compat/rules/auth/minimax-code.kdl +9 -0
  59. package/src/compat/rules/auth/minimax.kdl +3 -0
  60. package/src/compat/rules/auth/mistral.kdl +3 -0
  61. package/src/compat/rules/auth/moonshot.kdl +9 -0
  62. package/src/compat/rules/auth/nanogpt.kdl +9 -0
  63. package/src/compat/rules/auth/novita.kdl +12 -0
  64. package/src/compat/rules/auth/nvidia.kdl +11 -0
  65. package/src/compat/rules/auth/ollama-cloud.kdl +8 -0
  66. package/src/compat/rules/auth/ollama.kdl +9 -0
  67. package/src/compat/rules/auth/openai-codex-device.kdl +20 -0
  68. package/src/compat/rules/auth/openai-codex.kdl +33 -0
  69. package/src/compat/rules/auth/openai.kdl +3 -0
  70. package/src/compat/rules/auth/opencode-go.kdl +10 -0
  71. package/src/compat/rules/auth/opencode-zen.kdl +9 -0
  72. package/src/compat/rules/auth/openrouter.kdl +32 -0
  73. package/src/compat/rules/auth/parallel.kdl +9 -0
  74. package/src/compat/rules/auth/perplexity.kdl +7 -0
  75. package/src/compat/rules/auth/qianfan.kdl +9 -0
  76. package/src/compat/rules/auth/qwen-portal.kdl +9 -0
  77. package/src/compat/rules/auth/sakana.kdl +9 -0
  78. package/src/compat/rules/auth/siliconflow-cn.kdl +9 -0
  79. package/src/compat/rules/auth/siliconflow.kdl +9 -0
  80. package/src/compat/rules/auth/synthetic.kdl +9 -0
  81. package/src/compat/rules/auth/tavily.kdl +9 -0
  82. package/src/compat/rules/auth/together.kdl +14 -0
  83. package/src/compat/rules/auth/umans.kdl +9 -0
  84. package/src/compat/rules/auth/venice.kdl +9 -0
  85. package/src/compat/rules/auth/vercel-ai-gateway.kdl +8 -0
  86. package/src/compat/rules/auth/vllm.kdl +9 -0
  87. package/src/compat/rules/auth/wafer-serverless.kdl +11 -0
  88. package/src/compat/rules/auth/xai-oauth.kdl +27 -0
  89. package/src/compat/rules/auth/xai.kdl +9 -0
  90. package/src/compat/rules/auth/xiaomi-token-plan-ams.kdl +9 -0
  91. package/src/compat/rules/auth/xiaomi-token-plan-cn.kdl +9 -0
  92. package/src/compat/rules/auth/xiaomi-token-plan-sgp.kdl +9 -0
  93. package/src/compat/rules/auth/xiaomi.kdl +6 -0
  94. package/src/compat/rules/auth/yolo-auto.kdl +11 -0
  95. package/src/compat/rules/auth/zai-coding-plan.kdl +33 -0
  96. package/src/compat/rules/auth/zai.kdl +9 -0
  97. package/src/compat/rules/auth/zenmux.kdl +9 -0
  98. package/src/compat/rules/auth/zhipu-coding-plan.kdl +9 -0
  99. package/src/compat/rules/classes/amazon.kdl +21 -0
  100. package/src/compat/rules/classes/anthropic.kdl +285 -0
  101. package/src/compat/rules/classes/baidu.kdl +9 -0
  102. package/src/compat/rules/classes/bytedance.kdl +9 -0
  103. package/src/compat/rules/classes/cohere.kdl +7 -0
  104. package/src/compat/rules/classes/deepseek.kdl +80 -0
  105. package/src/compat/rules/classes/gemini.kdl +107 -0
  106. package/src/compat/rules/classes/gemma.kdl +14 -0
  107. package/src/compat/rules/classes/glm.kdl +115 -0
  108. package/src/compat/rules/classes/gpt-oss.kdl +16 -0
  109. package/src/compat/rules/classes/kimi.kdl +113 -0
  110. package/src/compat/rules/classes/meta.kdl +15 -0
  111. package/src/compat/rules/classes/mimo.kdl +32 -0
  112. package/src/compat/rules/classes/minimax.kdl +79 -0
  113. package/src/compat/rules/classes/mistral.kdl +19 -0
  114. package/src/compat/rules/classes/openai.kdl +58 -0
  115. package/src/compat/rules/classes/qwen.kdl +72 -0
  116. package/src/compat/rules/classes/stepfun.kdl +10 -0
  117. package/src/compat/rules/classes/xai.kdl +45 -0
  118. package/src/compat/rules/providers/abliteration.kdl +8 -0
  119. package/src/compat/rules/providers/aiand.kdl +19 -0
  120. package/src/compat/rules/providers/aimlapi.kdl +24 -0
  121. package/src/compat/rules/providers/alibaba-coding-plan.kdl +20 -0
  122. package/src/compat/rules/providers/alibaba-token-plan.kdl +35 -0
  123. package/src/compat/rules/providers/amazon-bedrock.kdl +36 -0
  124. package/src/compat/rules/providers/anthropic.kdl +24 -0
  125. package/src/compat/rules/providers/azure.kdl +19 -0
  126. package/src/compat/rules/providers/baseten.kdl +19 -0
  127. package/src/compat/rules/providers/bedrock-mantle.kdl +15 -0
  128. package/src/compat/rules/providers/cerebras.kdl +19 -0
  129. package/src/compat/rules/providers/cline-pass.kdl +8 -0
  130. package/src/compat/rules/providers/cloudflare-ai-gateway.kdl +26 -0
  131. package/src/compat/rules/providers/coreweave.kdl +16 -0
  132. package/src/compat/rules/providers/cursor.kdl +52 -0
  133. package/src/compat/rules/providers/deepseek.kdl +21 -0
  134. package/src/compat/rules/providers/firepass.kdl +15 -0
  135. package/src/compat/rules/providers/fireworks.kdl +43 -0
  136. package/src/compat/rules/providers/github-copilot.kdl +62 -0
  137. package/src/compat/rules/providers/gitlab-duo.kdl +24 -0
  138. package/src/compat/rules/providers/gmi-cloud.kdl +8 -0
  139. package/src/compat/rules/providers/google-antigravity.kdl +59 -0
  140. package/src/compat/rules/providers/google-gemini-cli.kdl +12 -0
  141. package/src/compat/rules/providers/google-vertex.kdl +25 -0
  142. package/src/compat/rules/providers/google.kdl +17 -0
  143. package/src/compat/rules/providers/groq.kdl +8 -0
  144. package/src/compat/rules/providers/huggingface.kdl +24 -0
  145. package/src/compat/rules/providers/kilo.kdl +51 -0
  146. package/src/compat/rules/providers/kimi-code.kdl +37 -0
  147. package/src/compat/rules/providers/llama.cpp.kdl +6 -0
  148. package/src/compat/rules/providers/lm-studio.kdl +6 -0
  149. package/src/compat/rules/providers/meta.kdl +10 -0
  150. package/src/compat/rules/providers/minimax-code-cn.kdl +13 -0
  151. package/src/compat/rules/providers/minimax-code.kdl +13 -0
  152. package/src/compat/rules/providers/minimax.kdl +6 -0
  153. package/src/compat/rules/providers/mistral.kdl +8 -0
  154. package/src/compat/rules/providers/moonshot.kdl +36 -0
  155. package/src/compat/rules/providers/nanogpt.kdl +100 -0
  156. package/src/compat/rules/providers/novita.kdl +34 -0
  157. package/src/compat/rules/providers/nvidia.kdl +27 -0
  158. package/src/compat/rules/providers/ollama-cloud.kdl +20 -0
  159. package/src/compat/rules/providers/ollama.kdl +12 -0
  160. package/src/compat/rules/providers/openai-codex.kdl +121 -0
  161. package/src/compat/rules/providers/openai.kdl +82 -0
  162. package/src/compat/rules/providers/opencode-go.kdl +97 -0
  163. package/src/compat/rules/providers/opencode-zen.kdl +103 -0
  164. package/src/compat/rules/providers/openrouter.kdl +66 -0
  165. package/src/compat/rules/providers/qianfan.kdl +8 -0
  166. package/src/compat/rules/providers/sakana.kdl +10 -0
  167. package/src/compat/rules/providers/synthetic.kdl +16 -0
  168. package/src/compat/rules/providers/together.kdl +22 -0
  169. package/src/compat/rules/providers/umans.kdl +28 -0
  170. package/src/compat/rules/providers/venice.kdl +46 -0
  171. package/src/compat/rules/providers/vercel-ai-gateway.kdl +73 -0
  172. package/src/compat/rules/providers/vllm.kdl +8 -0
  173. package/src/compat/rules/providers/wafer-serverless.kdl +35 -0
  174. package/src/compat/rules/providers/xai-oauth.kdl +48 -0
  175. package/src/compat/rules/providers/xai.kdl +50 -0
  176. package/src/compat/rules/providers/xiaomi-token-plan-ams.kdl +9 -0
  177. package/src/compat/rules/providers/xiaomi-token-plan-cn.kdl +9 -0
  178. package/src/compat/rules/providers/xiaomi-token-plan-sgp.kdl +9 -0
  179. package/src/compat/rules/providers/xiaomi.kdl +22 -0
  180. package/src/compat/rules/providers/yolo-auto.kdl +16 -0
  181. package/src/compat/rules/providers/zai.kdl +36 -0
  182. package/src/compat/rules/providers/zenmux.kdl +108 -0
  183. package/src/compat/rules/providers/zhipu-coding-plan.kdl +49 -0
  184. package/src/compat/rules/runtime/behavior.kdl +254 -0
  185. package/src/compat/rules/taxonomy/_collapse.kdl +747 -0
  186. package/src/compat/rules/taxonomy/_discovery.kdl +60 -0
  187. package/src/compat/rules/taxonomy/ai21.kdl +6 -0
  188. package/src/compat/rules/taxonomy/amazon.kdl +8 -0
  189. package/src/compat/rules/taxonomy/anthropic.kdl +17 -0
  190. package/src/compat/rules/taxonomy/baidu.kdl +5 -0
  191. package/src/compat/rules/taxonomy/bytedance.kdl +5 -0
  192. package/src/compat/rules/taxonomy/cohere.kdl +6 -0
  193. package/src/compat/rules/taxonomy/deepseek.kdl +18 -0
  194. package/src/compat/rules/taxonomy/gemini.kdl +9 -0
  195. package/src/compat/rules/taxonomy/gemma.kdl +3 -0
  196. package/src/compat/rules/taxonomy/glm.kdl +17 -0
  197. package/src/compat/rules/taxonomy/gpt-oss.kdl +11 -0
  198. package/src/compat/rules/taxonomy/kimi.kdl +20 -0
  199. package/src/compat/rules/taxonomy/meta.kdl +10 -0
  200. package/src/compat/rules/taxonomy/mimo.kdl +7 -0
  201. package/src/compat/rules/taxonomy/minimax.kdl +9 -0
  202. package/src/compat/rules/taxonomy/mistral.kdl +7 -0
  203. package/src/compat/rules/taxonomy/openai.kdl +43 -0
  204. package/src/compat/rules/taxonomy/qwen.kdl +33 -0
  205. package/src/compat/rules/taxonomy/stepfun.kdl +5 -0
  206. package/src/compat/rules/taxonomy/unknown.kdl +3 -0
  207. package/src/compat/rules/taxonomy/xai.kdl +12 -0
  208. package/src/compat/rules.d.json.ts +5 -0
  209. package/src/compat/rules.json +16984 -0
  210. package/src/compat/taxonomy.ts +452 -0
  211. package/src/compat/types.ts +588 -0
  212. package/src/discovery/antigravity.ts +5 -6
  213. package/src/discovery/codex.ts +22 -7
  214. package/src/discovery/cursor-proto.ts +7 -7
  215. package/src/discovery/cursor.ts +47 -58
  216. package/src/discovery/devin-proto.ts +613 -0
  217. package/src/discovery/devin.ts +358 -52
  218. package/src/discovery/gemini-cli.ts +14 -11
  219. package/src/discovery/gemini.ts +2 -0
  220. package/src/identity/dialect.ts +2 -2
  221. package/src/identity/id.ts +12 -0
  222. package/src/identity/index.ts +3 -3
  223. package/src/identity/metrics.ts +165 -0
  224. package/src/identity/reference.ts +37 -5
  225. package/src/index.ts +1 -1
  226. package/src/model-manager.ts +19 -6
  227. package/src/model-thinking.ts +6 -810
  228. package/src/model-tokenizer.ts +37 -44
  229. package/src/models.json +89584 -22358
  230. package/src/models.ts +6 -1
  231. package/src/provider-models/bundled-references.ts +3 -1
  232. package/src/provider-models/cline-pass.ts +226 -0
  233. package/src/provider-models/descriptors.ts +18 -0
  234. package/src/provider-models/google.ts +14 -5
  235. package/src/provider-models/models-dev-policies.ts +4 -29
  236. package/src/provider-models/ollama.ts +15 -2
  237. package/src/provider-models/openai-compat.ts +798 -520
  238. package/src/provider-models/special.ts +211 -12
  239. package/src/types.ts +214 -11
  240. package/src/wire/cline-pass.ts +35 -0
  241. package/src/wire/codex.ts +23 -2
  242. package/src/wire/devin-proto.ts +30 -0
  243. package/src/wire/devin.ts +72 -0
  244. package/src/wire/github-copilot.ts +49 -7
  245. package/THIRD-PARTY-NOTICES.txt +0 -22909
  246. package/dist/types/build.d.ts +0 -19
  247. package/dist/types/compat/anthropic.d.ts +0 -18
  248. package/dist/types/compat/apply.d.ts +0 -7
  249. package/dist/types/compat/bedrock.d.ts +0 -3
  250. package/dist/types/compat/devin.d.ts +0 -9
  251. package/dist/types/compat/openai.d.ts +0 -28
  252. package/dist/types/discovery/antigravity.d.ts +0 -70
  253. package/dist/types/discovery/codex.d.ts +0 -36
  254. package/dist/types/discovery/cursor-proto.d.ts +0 -5368
  255. package/dist/types/discovery/cursor.d.ts +0 -29
  256. package/dist/types/discovery/devin-proto.d.ts +0 -1549
  257. package/dist/types/discovery/devin.d.ts +0 -24
  258. package/dist/types/discovery/gemini-cli.d.ts +0 -33
  259. package/dist/types/discovery/gemini.d.ts +0 -25
  260. package/dist/types/discovery/gitlab-duo-workflow.d.ts +0 -30
  261. package/dist/types/discovery/index.d.ts +0 -7
  262. package/dist/types/discovery/openai-compatible.d.ts +0 -89
  263. package/dist/types/discovery/protobuf.d.ts +0 -102
  264. package/dist/types/effort.d.ts +0 -10
  265. package/dist/types/fireworks-model-id.d.ts +0 -23
  266. package/dist/types/hosts.d.ts +0 -169
  267. package/dist/types/identity/bundled.d.ts +0 -3
  268. package/dist/types/identity/classify.d.ts +0 -69
  269. package/dist/types/identity/dialect.d.ts +0 -3
  270. package/dist/types/identity/family.d.ts +0 -243
  271. package/dist/types/identity/id.d.ts +0 -12
  272. package/dist/types/identity/index.d.ts +0 -8
  273. package/dist/types/identity/markers.d.ts +0 -4
  274. package/dist/types/identity/priority.d.ts +0 -1
  275. package/dist/types/identity/reference.d.ts +0 -29
  276. package/dist/types/index.d.ts +0 -19
  277. package/dist/types/model-cache.d.ts +0 -23
  278. package/dist/types/model-manager.d.ts +0 -93
  279. package/dist/types/model-thinking.d.ts +0 -81
  280. package/dist/types/model-tokenizer.d.ts +0 -8
  281. package/dist/types/models.d.ts +0 -17
  282. package/dist/types/openai-pricing.d.ts +0 -17
  283. package/dist/types/provider-models/bundled-references.d.ts +0 -13
  284. package/dist/types/provider-models/cache-provider-id.d.ts +0 -11
  285. package/dist/types/provider-models/descriptor-types.d.ts +0 -76
  286. package/dist/types/provider-models/descriptors.d.ts +0 -524
  287. package/dist/types/provider-models/google.d.ts +0 -29
  288. package/dist/types/provider-models/index.d.ts +0 -7
  289. package/dist/types/provider-models/models-dev-policies.d.ts +0 -8
  290. package/dist/types/provider-models/ollama.d.ts +0 -22
  291. package/dist/types/provider-models/openai-compat.d.ts +0 -703
  292. package/dist/types/provider-models/special.d.ts +0 -53
  293. package/dist/types/types.d.ts +0 -879
  294. package/dist/types/utils.d.ts +0 -20
  295. package/dist/types/variant-collapse.d.ts +0 -146
  296. package/dist/types/wire/alibaba-token-plan.d.ts +0 -22
  297. package/dist/types/wire/cloudflare-ai-gateway.d.ts +0 -18
  298. package/dist/types/wire/codex.d.ts +0 -66
  299. package/dist/types/wire/coreweave.d.ts +0 -12
  300. package/dist/types/wire/gemini-headers.d.ts +0 -62
  301. package/dist/types/wire/github-copilot.d.ts +0 -47
  302. package/dist/types/wire/image-fetchers.d.ts +0 -76
  303. package/src/compat/bedrock.ts +0 -153
  304. package/src/compat/devin.ts +0 -12
  305. package/src/identity/classify.ts +0 -242
  306. package/src/identity/family.ts +0 -496
  307. package/src/identity/markers.ts +0 -49
  308. package/src/openai-pricing.ts +0 -29
@@ -1,18 +1,11 @@
1
1
  /**
2
- * Anthropic-messages compat builder — the anthropic-side analogue of
3
- * `./openai`. Runs exactly once per model (from `buildModel`); detect-time
4
- * defaults come from provider ids, strict host checks, and model-id
5
- * classification, with explicit spec overrides assigned on top.
2
+ * Anthropic endpoint-shape predicates: which URLs are the official first-party
3
+ * API, and which non-official hosts enforce Anthropic's thinking-signature
4
+ * protocol on replay. Compat resolution (`./resolve`) and runtime routing in
5
+ * pi-ai both consume these; URL matching is the one detection surface that
6
+ * stays in code.
6
7
  */
7
- import { hostMatchesUrl, modelMatchesHost } from "../hosts";
8
- import {
9
- hasOpus47ApiRestrictions,
10
- isAnthropicFableOrMythosModel,
11
- isKimiK3ModelId,
12
- supportsMidConversationSystemMessages,
13
- } from "../identity/family";
14
- import type { ModelSpec, ResolvedAnthropicCompat } from "../types";
15
- import { applyCompatOverrides } from "./apply";
8
+ import { hostMatchesUrl } from "../hosts";
16
9
 
17
10
  const OFFICIAL_ANTHROPIC_URL = "https://api.anthropic.com";
18
11
 
@@ -29,75 +22,25 @@ export function isOfficialAnthropicApiUrl(baseUrl?: string): boolean {
29
22
  return lower === OFFICIAL_ANTHROPIC_URL || lower.startsWith(`${OFFICIAL_ANTHROPIC_URL}/`);
30
23
  }
31
24
 
32
- /**
33
- * Kimi models whose native endpoints (api.kimi.com, api.moonshot.ai) keep
34
- * thinking enabled server-side no matter what the request carries: they
35
- * reject disabled thinking (#3852) AND reject forced tool_choice
36
- * (`tool_choice 'specified' is incompatible with thinking enabled`), so compat
37
- * must keep thinking on and downgrade forced choices to `auto`. Covers the
38
- * K2.7 Code family — public id, its Highspeed variant, and the kimi-code
39
- * `kimi-for-coding[-highspeed]` aliases — plus K3 (`kimi-k3`, bare `k3` on
40
- * kimi-code). Broader than the `compat/openai.ts` mirror: the OpenAI surface
41
- * has its own per-dialect policies (K3 forced-choice guard, explicit disable
42
- * shapes), while this surface has no working way to force a tool.
43
- * Native-only host gating is the caller's responsibility.
44
- */
45
- const KIMI_K27_CODE_MODEL_PATTERN = /(?:^|\/)kimi[-._]?k2(?:[._-]?|p)7[-._]?code(?:[-._]?highspeed)?$/i;
46
-
47
- function matchesKimiMandatoryThinkingModel(spec: ModelSpec<"anthropic-messages">): boolean {
48
- if (KIMI_K27_CODE_MODEL_PATTERN.test(spec.id)) return true;
49
- if (spec.id === "kimi-for-coding" || spec.id === "kimi-for-coding-highspeed") return true;
50
- return isKimiK3ModelId(spec.id) || spec.id === "k3";
51
- }
52
-
53
25
  const CLOUDFLARE_ANTHROPIC_GATEWAY_URL_MARKER = /gateway\.ai\.cloudflare\.com\/.+\/anthropic(?:\/|$)/i;
54
26
  const VERTEX_ANTHROPIC_URL_MARKER = /aiplatform\.googleapis\.com\/.+\/publishers\/anthropic\//i;
55
27
  const BEDROCK_ANTHROPIC_URL_MARKER = /(?:^|\/\/|\.)bedrock-runtime\.[a-z0-9-]+\.amazonaws\.com/i;
56
28
  const AZURE_ANTHROPIC_URL_MARKER = /(?:^|\/\/|\.)[a-z0-9-]+\.(?:inference|services)\.ai\.azure\.com/i;
57
29
 
58
- /**
59
- * Cloudflare AI Gateway's `/anthropic` route forwards to signature-enforcing
60
- * Anthropic (same failure class as GitHub Copilot #2851 / ZenMux #4192).
61
- * Detection is by baseUrl marker rather than provider id: users routinely
62
- * declare `provider: "custom"` (or other free-form ids) in `models.yml` for
63
- * their own Cloudflare gateway account.
64
- */
65
- function isCloudflareAnthropicGateway(baseUrl?: string): boolean {
66
- return baseUrl !== undefined && CLOUDFLARE_ANTHROPIC_GATEWAY_URL_MARKER.test(baseUrl);
67
- }
68
-
69
- /**
70
- * Google Vertex's `publishers/anthropic/models/…:streamRawPredict` route
71
- * proxies Claude through Google's identity layer and returns full thinking
72
- * signatures, so it is a SIGNING endpoint.
73
- */
74
- function isVertexAnthropicRoute(baseUrl?: string): boolean {
75
- return baseUrl !== undefined && VERTEX_ANTHROPIC_URL_MARKER.test(baseUrl);
76
- }
77
-
78
- /**
79
- * AWS Bedrock's Anthropic route (`bedrock-runtime.<region>.amazonaws.com`)
80
- * forwards Claude requests through Anthropic's signature protocol. Users can
81
- * front Bedrock with a custom `anthropic-messages` provider entry in
82
- * `models.yml`; the URL marker makes those signing by default without
83
- * requiring a provider-id list.
84
- */
85
- function isBedrockAnthropicRoute(baseUrl?: string): boolean {
86
- return baseUrl !== undefined && BEDROCK_ANTHROPIC_URL_MARKER.test(baseUrl);
87
- }
88
-
89
30
  /**
90
31
  * Azure AI Inference / Foundry Anthropic route
91
32
  * (`<resource>.inference.ai.azure.com`, `<resource>.services.ai.azure.com`).
92
33
  * Fronts Claude behind Azure identity and enforces Anthropic signatures on
93
- * replay.
34
+ * replay; it also rejects the top-level `strict` tool field.
94
35
  */
95
- function isAzureAnthropicRoute(baseUrl?: string): boolean {
36
+ export function isAzureAnthropicRoute(baseUrl?: string): boolean {
96
37
  return baseUrl !== undefined && AZURE_ANTHROPIC_URL_MARKER.test(baseUrl);
97
38
  }
98
39
 
99
40
  /**
100
- * Known non-official URLs that enforce Anthropic thinking signatures on replay.
41
+ * Known non-official URLs that enforce Anthropic thinking signatures on replay
42
+ * (GitHub Copilot, ZenMux, Cloudflare AI Gateway `/anthropic`, Google Vertex
43
+ * `publishers/anthropic`, AWS Bedrock, Azure Foundry).
101
44
  *
102
45
  * Runtime routing calls this with the effective URL because a model's resolved
103
46
  * compat can be stale after Foundry or a provider base-URL override reroutes it.
@@ -106,74 +49,10 @@ export function isAnthropicSigningProxyUrl(baseUrl?: string): boolean {
106
49
  return (
107
50
  hostMatchesUrl(baseUrl, "githubCopilot") ||
108
51
  hostMatchesUrl(baseUrl, "zenmux") ||
109
- isCloudflareAnthropicGateway(baseUrl) ||
110
- isVertexAnthropicRoute(baseUrl) ||
111
- isBedrockAnthropicRoute(baseUrl) ||
52
+ (baseUrl !== undefined &&
53
+ (CLOUDFLARE_ANTHROPIC_GATEWAY_URL_MARKER.test(baseUrl) ||
54
+ VERTEX_ANTHROPIC_URL_MARKER.test(baseUrl) ||
55
+ BEDROCK_ANTHROPIC_URL_MARKER.test(baseUrl))) ||
112
56
  isAzureAnthropicRoute(baseUrl)
113
57
  );
114
58
  }
115
-
116
- /** Build the resolved anthropic-messages compat record for a model spec. */
117
- export function buildAnthropicCompat(spec: ModelSpec<"anthropic-messages">): ResolvedAnthropicCompat {
118
- const baseUrl = spec.baseUrl;
119
- const official = isOfficialAnthropicApiUrl(baseUrl);
120
- // Z.AI's Anthropic-compatible proxy lives at `api.z.ai/api/anthropic`.
121
- const isZai = modelMatchesHost(spec, "zai");
122
- // GitHub Copilot's `anthropic-messages` proxy (api.githubcopilot.com/v1/messages)
123
- // rejects the per-tool `eager_input_streaming` field with
124
- // `tools.0.custom.eager_input_streaming: Extra inputs are not permitted` and
125
- // doesn't whitelist the `fine-grained-tool-streaming-2025-05-14` beta either
126
- // (issue #2558), so eager tool-input streaming is unavailable on this host.
127
- const isCopilot = modelMatchesHost(spec, "githubCopilot");
128
- // ZenMux's `anthropic-messages` route (zenmux.ai/api/anthropic) forwards to
129
- // signature-enforcing Anthropic — same failure class as GitHub Copilot #2851
130
- // (issue #4192).
131
- const isZenmux = modelMatchesHost(spec, "zenmux");
132
- const requiresThinkingEnabled = modelMatchesHost(spec, "moonshotNative") && matchesKimiMandatoryThinkingModel(spec);
133
- const isAzure = isAzureAnthropicRoute(baseUrl);
134
- const signingEndpoint = official || isCopilot || isZenmux || isAnthropicSigningProxyUrl(baseUrl);
135
- const compat: ResolvedAnthropicCompat = {
136
- officialEndpoint: official,
137
- signingEndpoint,
138
- disableStrictTools: isAzure,
139
- disableAdaptiveThinking: false,
140
- allowAnthropicHeaderOverrides: false,
141
- supportsEagerToolInputStreaming: official,
142
- // Long cache retention is only sent to the official API by default;
143
- // proxies opt in explicitly via `compat.supportsLongCacheRetention: true`.
144
- supportsLongCacheRetention: official,
145
- // First-party Claude API only. Bedrock/Vertex/Foundry and other
146
- // Anthropic-compatible gateways reject mid-conversation system roles, so
147
- // detection requires the canonical api.anthropic.com host plus a
148
- // supported model id.
149
- supportsMidConversationSystem: official && supportsMidConversationSystemMessages(spec.id),
150
- supportsForcedToolChoice: !requiresThinkingEnabled && !isAnthropicFableOrMythosModel(spec.id),
151
- // Opus 4.7+ and Fable/Mythos reject temperature/top_p/top_k with a 400.
152
- supportsSamplingParams: !hasOpus47ApiRestrictions(spec.id),
153
- // Z.AI workaround (issue #814): its proxy deserializes tool_result blocks
154
- // into a class that reads `.id`.
155
- requiresToolResultId: isZai,
156
- requiresThinkingEnabled,
157
- // Official Anthropic and Anthropic-compatible signing proxies enforce
158
- // signature-based thinking-chain integrity, so unsigned thinking blocks
159
- // must stay text there. Every other `anthropic-messages` reasoning
160
- // endpoint replays unsigned thinking natively so the reasoning chain
161
- // survives continuation and doesn't destabilize the next tool-call
162
- // arguments (#2005, #2257, #2265, #3288, #3433, #3434). Opaque custom
163
- // signing proxies remain the reporter's responsibility to mark with
164
- // `compat.replayUnsignedThinking: false`; the transport surfaces a
165
- // pointed remediation the first time the signing 400 fires (#4297).
166
- //
167
- // Known signing Anthropic-messages hosts (Copilot, ZenMux, Cloudflare
168
- // AI Gateway `/anthropic`, Google Vertex `publishers/anthropic`, AWS
169
- // Bedrock `bedrock-runtime.<region>.amazonaws.com`, and Azure
170
- // AI Inference / Foundry `<res>.(inference|services).ai.azure.com`)
171
- // are excluded automatically because they can be recognised by provider
172
- // id or baseUrl marker.
173
- replayUnsignedThinking: !signingEndpoint && (Boolean(spec.reasoning) || modelMatchesHost(spec, "deepseekFamily")),
174
- escapeBuiltinToolNames: modelMatchesHost(spec, "umans"),
175
- streamIdleTimeoutMs: spec.compat?.streamIdleTimeoutMs,
176
- };
177
- applyCompatOverrides(compat, spec.compat);
178
- return compat;
179
- }
@@ -0,0 +1,157 @@
1
+ // Generated by `bun run gen:compat` from `src/compat/rules/auth/*.kdl`; do not edit.
2
+
3
+ /** Every provider with an `auth/<id>.kdl` policy. */
4
+ export type AuthProviderId =
5
+ | "abliteration"
6
+ | "aiand"
7
+ | "aimlapi"
8
+ | "alibaba-coding-plan"
9
+ | "alibaba-token-plan"
10
+ | "amazon-bedrock"
11
+ | "anthropic"
12
+ | "azure"
13
+ | "baseten"
14
+ | "bedrock-mantle"
15
+ | "cerebras"
16
+ | "cline-pass"
17
+ | "cloudflare-ai-gateway"
18
+ | "coreweave"
19
+ | "cursor"
20
+ | "deepinfra"
21
+ | "deepseek"
22
+ | "devin"
23
+ | "exa"
24
+ | "firepass"
25
+ | "fireworks"
26
+ | "github-copilot"
27
+ | "gitlab-duo"
28
+ | "gitlab-duo-agent"
29
+ | "gmi-cloud"
30
+ | "google"
31
+ | "google-antigravity"
32
+ | "google-gemini-cli"
33
+ | "google-vertex"
34
+ | "groq"
35
+ | "huggingface"
36
+ | "kagi"
37
+ | "kilo"
38
+ | "kimi-code"
39
+ | "litellm"
40
+ | "llama.cpp"
41
+ | "lm-studio"
42
+ | "meta"
43
+ | "minimax"
44
+ | "minimax-code"
45
+ | "minimax-code-cn"
46
+ | "mistral"
47
+ | "moonshot"
48
+ | "nanogpt"
49
+ | "novita"
50
+ | "nvidia"
51
+ | "ollama"
52
+ | "ollama-cloud"
53
+ | "openai"
54
+ | "openai-codex"
55
+ | "openai-codex-device"
56
+ | "opencode-go"
57
+ | "opencode-zen"
58
+ | "openrouter"
59
+ | "parallel"
60
+ | "perplexity"
61
+ | "qianfan"
62
+ | "qwen-portal"
63
+ | "sakana"
64
+ | "siliconflow"
65
+ | "siliconflow-cn"
66
+ | "synthetic"
67
+ | "tavily"
68
+ | "together"
69
+ | "umans"
70
+ | "venice"
71
+ | "vercel-ai-gateway"
72
+ | "vllm"
73
+ | "wafer-serverless"
74
+ | "xai"
75
+ | "xai-oauth"
76
+ | "xiaomi"
77
+ | "xiaomi-token-plan-ams"
78
+ | "xiaomi-token-plan-cn"
79
+ | "xiaomi-token-plan-sgp"
80
+ | "yolo-auto"
81
+ | "zai"
82
+ | "zai-coding-plan"
83
+ | "zenmux"
84
+ | "zhipu-coding-plan";
85
+
86
+ /** Providers whose policy declares a `login` flow (the `/login` roster). */
87
+ export type LoginProviderId =
88
+ | "abliteration"
89
+ | "aiand"
90
+ | "alibaba-coding-plan"
91
+ | "alibaba-token-plan"
92
+ | "anthropic"
93
+ | "baseten"
94
+ | "cerebras"
95
+ | "cline-pass"
96
+ | "cloudflare-ai-gateway"
97
+ | "coreweave"
98
+ | "cursor"
99
+ | "deepinfra"
100
+ | "deepseek"
101
+ | "devin"
102
+ | "exa"
103
+ | "firepass"
104
+ | "fireworks"
105
+ | "github-copilot"
106
+ | "gitlab-duo"
107
+ | "gitlab-duo-agent"
108
+ | "gmi-cloud"
109
+ | "google-antigravity"
110
+ | "google-gemini-cli"
111
+ | "huggingface"
112
+ | "kagi"
113
+ | "kilo"
114
+ | "kimi-code"
115
+ | "litellm"
116
+ | "llama.cpp"
117
+ | "lm-studio"
118
+ | "meta"
119
+ | "minimax-code"
120
+ | "minimax-code-cn"
121
+ | "moonshot"
122
+ | "nanogpt"
123
+ | "novita"
124
+ | "nvidia"
125
+ | "ollama"
126
+ | "ollama-cloud"
127
+ | "openai-codex"
128
+ | "openai-codex-device"
129
+ | "opencode-go"
130
+ | "opencode-zen"
131
+ | "openrouter"
132
+ | "parallel"
133
+ | "perplexity"
134
+ | "qianfan"
135
+ | "qwen-portal"
136
+ | "sakana"
137
+ | "siliconflow"
138
+ | "siliconflow-cn"
139
+ | "synthetic"
140
+ | "tavily"
141
+ | "together"
142
+ | "umans"
143
+ | "venice"
144
+ | "vercel-ai-gateway"
145
+ | "vllm"
146
+ | "wafer-serverless"
147
+ | "xai"
148
+ | "xai-oauth"
149
+ | "xiaomi"
150
+ | "xiaomi-token-plan-ams"
151
+ | "xiaomi-token-plan-cn"
152
+ | "xiaomi-token-plan-sgp"
153
+ | "yolo-auto"
154
+ | "zai"
155
+ | "zai-coding-plan"
156
+ | "zenmux"
157
+ | "zhipu-coding-plan";
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Typed accessors over the compiled auth stratum (`rules/auth/*.kdl`): per
3
+ * provider display metadata, env-var fallbacks and the declarative login /
4
+ * refresh flow that `@linxiraos/pi-ai`'s registry engines interpret.
5
+ */
6
+ import rules from "./rules.json";
7
+ import type { CompiledAuthProvider } from "./types";
8
+
9
+ const providers = rules.auth.providers as readonly CompiledAuthProvider[];
10
+ const byId: Record<string, CompiledAuthProvider> = Object.fromEntries(providers.map(p => [p.id, p]));
11
+
12
+ /** Every compiled auth provider in `/login` display order. */
13
+ export function authProviders(): readonly CompiledAuthProvider[] {
14
+ return providers;
15
+ }
16
+
17
+ /** The compiled auth policy for one provider id, if declared. */
18
+ export function authPolicyFor(provider: string): CompiledAuthProvider | undefined {
19
+ return byId[provider];
20
+ }
21
+
22
+ /** Every hook name referenced anywhere in the auth stratum, for registry completeness checks. */
23
+ export function authHookNames(): Record<string, string[]> {
24
+ const names: Record<string, string[]> = {};
25
+ const add = (kind: string, name: string | undefined) => {
26
+ if (!name) return;
27
+ // biome-ignore lint/suspicious/noAssignInExpressions: destructuring default with assignment inside the compiled stratum walker
28
+ (names[kind] ??= []).push(name);
29
+ };
30
+ for (const p of providers) {
31
+ if (p.env && "hook" in p.env) add("env", p.env.hook);
32
+ const login = p.login;
33
+ if (login?.kind === "custom") add("login", login.hook);
34
+ if (login?.kind === "api-key" && login.validate?.kind === "models-endpoint") {
35
+ add("headers", login.validate.headersHook);
36
+ }
37
+ if (login?.kind === "oauth-code") {
38
+ add("after-exchange", login.afterExchange);
39
+ add("value", login.clientId?.hook);
40
+ add("value", login.authorizeUrl.hook);
41
+ add("value", login.token.url.hook);
42
+ }
43
+ if (login?.kind === "device-code") {
44
+ add("after-exchange", login.afterExchange);
45
+ add("headers", login.headersHook);
46
+ add("value", login.clientId.hook);
47
+ add("value", login.baseUrl?.hook);
48
+ add("value", login.device.url.hook);
49
+ add("value", login.token.url.hook);
50
+ }
51
+ const refresh = p.refresh;
52
+ if (refresh?.kind === "hook") add("refresh", refresh.hook);
53
+ if (refresh?.kind === "request") {
54
+ add("after-exchange", refresh.afterRefresh);
55
+ add("headers", refresh.headersHook);
56
+ add("value", refresh.token.url.hook);
57
+ }
58
+ }
59
+ return names;
60
+ }