@copilotkit/aimock 1.45.0 → 1.46.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.
Files changed (426) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +24 -0
  4. package/README.md +7 -1
  5. package/dist/agui-mock.cjs +25 -25
  6. package/dist/agui-mock.cjs.map +1 -1
  7. package/dist/agui-mock.d.cts.map +1 -1
  8. package/dist/agui-mock.d.ts.map +1 -1
  9. package/dist/agui-mock.js +25 -25
  10. package/dist/agui-mock.js.map +1 -1
  11. package/dist/agui-types.d.ts.map +1 -1
  12. package/dist/aimock-cli.cjs +15 -1
  13. package/dist/aimock-cli.cjs.map +1 -1
  14. package/dist/aimock-cli.d.cts.map +1 -1
  15. package/dist/aimock-cli.d.ts.map +1 -1
  16. package/dist/aimock-cli.js +16 -2
  17. package/dist/aimock-cli.js.map +1 -1
  18. package/dist/api-key-auth.cjs +10 -9
  19. package/dist/api-key-auth.cjs.map +1 -1
  20. package/dist/api-key-auth.d.cts.map +1 -1
  21. package/dist/api-key-auth.d.ts.map +1 -1
  22. package/dist/api-key-auth.js +11 -10
  23. package/dist/api-key-auth.js.map +1 -1
  24. package/dist/batches.cjs +2 -4
  25. package/dist/batches.cjs.map +1 -1
  26. package/dist/batches.d.cts.map +1 -1
  27. package/dist/batches.d.ts.map +1 -1
  28. package/dist/batches.js +2 -4
  29. package/dist/batches.js.map +1 -1
  30. package/dist/bedrock-converse.cjs +61 -80
  31. package/dist/bedrock-converse.cjs.map +1 -1
  32. package/dist/bedrock-converse.d.cts.map +1 -1
  33. package/dist/bedrock-converse.d.ts.map +1 -1
  34. package/dist/bedrock-converse.js +58 -77
  35. package/dist/bedrock-converse.js.map +1 -1
  36. package/dist/bedrock.cjs +65 -97
  37. package/dist/bedrock.cjs.map +1 -1
  38. package/dist/bedrock.d.cts.map +1 -1
  39. package/dist/bedrock.d.ts.map +1 -1
  40. package/dist/bedrock.js +62 -94
  41. package/dist/bedrock.js.map +1 -1
  42. package/dist/byteplus-video.cjs +11 -10
  43. package/dist/byteplus-video.cjs.map +1 -1
  44. package/dist/byteplus-video.d.cts.map +1 -1
  45. package/dist/byteplus-video.d.ts.map +1 -1
  46. package/dist/byteplus-video.js +5 -4
  47. package/dist/byteplus-video.js.map +1 -1
  48. package/dist/chaos.cjs +5 -4
  49. package/dist/chaos.cjs.map +1 -1
  50. package/dist/chaos.d.cts.map +1 -1
  51. package/dist/chaos.d.ts.map +1 -1
  52. package/dist/chaos.js +5 -4
  53. package/dist/chaos.js.map +1 -1
  54. package/dist/cli.cjs +15 -0
  55. package/dist/cli.cjs.map +1 -1
  56. package/dist/cli.js +15 -0
  57. package/dist/cli.js.map +1 -1
  58. package/dist/cohere.cjs +49 -74
  59. package/dist/cohere.cjs.map +1 -1
  60. package/dist/cohere.d.cts.map +1 -1
  61. package/dist/cohere.d.ts.map +1 -1
  62. package/dist/cohere.js +47 -72
  63. package/dist/cohere.js.map +1 -1
  64. package/dist/config-loader.cjs +29 -1
  65. package/dist/config-loader.cjs.map +1 -1
  66. package/dist/config-loader.d.cts +7 -1
  67. package/dist/config-loader.d.cts.map +1 -1
  68. package/dist/config-loader.d.ts +7 -1
  69. package/dist/config-loader.d.ts.map +1 -1
  70. package/dist/config-loader.js +29 -2
  71. package/dist/config-loader.js.map +1 -1
  72. package/dist/count-tokens.cjs +146 -0
  73. package/dist/count-tokens.cjs.map +1 -0
  74. package/dist/count-tokens.js +146 -0
  75. package/dist/count-tokens.js.map +1 -0
  76. package/dist/elevenlabs-audio.cjs +36 -34
  77. package/dist/elevenlabs-audio.cjs.map +1 -1
  78. package/dist/elevenlabs-audio.d.cts.map +1 -1
  79. package/dist/elevenlabs-audio.d.ts.map +1 -1
  80. package/dist/elevenlabs-audio.js +33 -31
  81. package/dist/elevenlabs-audio.js.map +1 -1
  82. package/dist/elevenlabs-voice.cjs +38 -37
  83. package/dist/elevenlabs-voice.cjs.map +1 -1
  84. package/dist/elevenlabs-voice.d.cts.map +1 -1
  85. package/dist/elevenlabs-voice.d.ts.map +1 -1
  86. package/dist/elevenlabs-voice.js +33 -32
  87. package/dist/elevenlabs-voice.js.map +1 -1
  88. package/dist/embedding-request.cjs +16 -0
  89. package/dist/embedding-request.cjs.map +1 -0
  90. package/dist/embedding-request.js +14 -0
  91. package/dist/embedding-request.js.map +1 -0
  92. package/dist/embeddings.cjs +30 -20
  93. package/dist/embeddings.cjs.map +1 -1
  94. package/dist/embeddings.d.cts.map +1 -1
  95. package/dist/embeddings.d.ts.map +1 -1
  96. package/dist/embeddings.js +30 -20
  97. package/dist/embeddings.js.map +1 -1
  98. package/dist/fal-audio.cjs +45 -43
  99. package/dist/fal-audio.cjs.map +1 -1
  100. package/dist/fal-audio.d.cts.map +1 -1
  101. package/dist/fal-audio.d.ts.map +1 -1
  102. package/dist/fal-audio.js +42 -40
  103. package/dist/fal-audio.js.map +1 -1
  104. package/dist/fal.cjs +17 -15
  105. package/dist/fal.cjs.map +1 -1
  106. package/dist/fal.js +16 -14
  107. package/dist/fal.js.map +1 -1
  108. package/dist/files.cjs +2 -4
  109. package/dist/files.cjs.map +1 -1
  110. package/dist/files.d.cts.map +1 -1
  111. package/dist/files.d.ts.map +1 -1
  112. package/dist/files.js +2 -4
  113. package/dist/files.js.map +1 -1
  114. package/dist/fine-tuning.cjs +2 -4
  115. package/dist/fine-tuning.cjs.map +1 -1
  116. package/dist/fine-tuning.d.cts.map +1 -1
  117. package/dist/fine-tuning.d.ts.map +1 -1
  118. package/dist/fine-tuning.js +2 -4
  119. package/dist/fine-tuning.js.map +1 -1
  120. package/dist/fixture-loader.cjs +37 -42
  121. package/dist/fixture-loader.cjs.map +1 -1
  122. package/dist/fixture-loader.d.cts.map +1 -1
  123. package/dist/fixture-loader.d.ts.map +1 -1
  124. package/dist/fixture-loader.js +37 -42
  125. package/dist/fixture-loader.js.map +1 -1
  126. package/dist/gemini-embeddings.cjs +26 -24
  127. package/dist/gemini-embeddings.cjs.map +1 -1
  128. package/dist/gemini-embeddings.js +26 -24
  129. package/dist/gemini-embeddings.js.map +1 -1
  130. package/dist/gemini-interactions.cjs +50 -35
  131. package/dist/gemini-interactions.cjs.map +1 -1
  132. package/dist/gemini-interactions.d.cts +0 -1
  133. package/dist/gemini-interactions.d.cts.map +1 -1
  134. package/dist/gemini-interactions.d.ts +0 -1
  135. package/dist/gemini-interactions.d.ts.map +1 -1
  136. package/dist/gemini-interactions.js +49 -34
  137. package/dist/gemini-interactions.js.map +1 -1
  138. package/dist/gemini.cjs +57 -67
  139. package/dist/gemini.cjs.map +1 -1
  140. package/dist/gemini.d.cts.map +1 -1
  141. package/dist/gemini.d.ts.map +1 -1
  142. package/dist/gemini.js +56 -67
  143. package/dist/gemini.js.map +1 -1
  144. package/dist/grok-video.cjs +14 -12
  145. package/dist/grok-video.cjs.map +1 -1
  146. package/dist/grok-video.d.cts.map +1 -1
  147. package/dist/grok-video.d.ts.map +1 -1
  148. package/dist/grok-video.js +8 -6
  149. package/dist/grok-video.js.map +1 -1
  150. package/dist/helpers.cjs +11 -68
  151. package/dist/helpers.cjs.map +1 -1
  152. package/dist/helpers.d.cts.map +1 -1
  153. package/dist/helpers.d.ts.map +1 -1
  154. package/dist/helpers.js +12 -67
  155. package/dist/helpers.js.map +1 -1
  156. package/dist/images.cjs +30 -28
  157. package/dist/images.cjs.map +1 -1
  158. package/dist/images.d.cts.map +1 -1
  159. package/dist/images.d.ts.map +1 -1
  160. package/dist/images.js +27 -25
  161. package/dist/images.js.map +1 -1
  162. package/dist/index.d.cts +2 -2
  163. package/dist/index.d.ts +2 -2
  164. package/dist/journal.cjs +3 -1
  165. package/dist/journal.cjs.map +1 -1
  166. package/dist/journal.d.cts.map +1 -1
  167. package/dist/journal.d.ts.map +1 -1
  168. package/dist/journal.js +2 -1
  169. package/dist/journal.js.map +1 -1
  170. package/dist/llmock.cjs +3 -0
  171. package/dist/llmock.cjs.map +1 -1
  172. package/dist/llmock.d.cts.map +1 -1
  173. package/dist/llmock.d.ts.map +1 -1
  174. package/dist/llmock.js +3 -0
  175. package/dist/llmock.js.map +1 -1
  176. package/dist/mcp-fakes.d.cts.map +1 -1
  177. package/dist/mcp-handler.cjs +14 -4
  178. package/dist/mcp-handler.cjs.map +1 -1
  179. package/dist/mcp-handler.js +14 -4
  180. package/dist/mcp-handler.js.map +1 -1
  181. package/dist/mcp-recorder.cjs +2 -1
  182. package/dist/mcp-recorder.cjs.map +1 -1
  183. package/dist/mcp-recorder.js +3 -2
  184. package/dist/mcp-recorder.js.map +1 -1
  185. package/dist/messages.cjs +111 -96
  186. package/dist/messages.cjs.map +1 -1
  187. package/dist/messages.d.cts.map +1 -1
  188. package/dist/messages.d.ts.map +1 -1
  189. package/dist/messages.js +109 -95
  190. package/dist/messages.js.map +1 -1
  191. package/dist/metrics.cjs +5 -2
  192. package/dist/metrics.cjs.map +1 -1
  193. package/dist/metrics.d.cts.map +1 -1
  194. package/dist/metrics.d.ts.map +1 -1
  195. package/dist/metrics.js +6 -3
  196. package/dist/metrics.js.map +1 -1
  197. package/dist/model-utils.cjs +1 -0
  198. package/dist/model-utils.cjs.map +1 -1
  199. package/dist/model-utils.js +1 -1
  200. package/dist/model-utils.js.map +1 -1
  201. package/dist/moderation.cjs +15 -12
  202. package/dist/moderation.cjs.map +1 -1
  203. package/dist/moderation.js +14 -11
  204. package/dist/moderation.js.map +1 -1
  205. package/dist/ollama.cjs +128 -68
  206. package/dist/ollama.cjs.map +1 -1
  207. package/dist/ollama.d.cts.map +1 -1
  208. package/dist/ollama.d.ts.map +1 -1
  209. package/dist/ollama.js +124 -64
  210. package/dist/ollama.js.map +1 -1
  211. package/dist/openapi.cjs +323 -3
  212. package/dist/openapi.cjs.map +1 -1
  213. package/dist/openapi.d.cts.map +1 -1
  214. package/dist/openapi.d.ts.map +1 -1
  215. package/dist/openapi.js +324 -4
  216. package/dist/openapi.js.map +1 -1
  217. package/dist/openrouter-chat.cjs +11 -155
  218. package/dist/openrouter-chat.cjs.map +1 -1
  219. package/dist/openrouter-chat.js +11 -155
  220. package/dist/openrouter-chat.js.map +1 -1
  221. package/dist/openrouter-video.cjs +76 -71
  222. package/dist/openrouter-video.cjs.map +1 -1
  223. package/dist/openrouter-video.d.cts.map +1 -1
  224. package/dist/openrouter-video.d.ts.map +1 -1
  225. package/dist/openrouter-video.js +63 -58
  226. package/dist/openrouter-video.js.map +1 -1
  227. package/dist/recorder.cjs +176 -95
  228. package/dist/recorder.cjs.map +1 -1
  229. package/dist/recorder.d.cts.map +1 -1
  230. package/dist/recorder.d.ts.map +1 -1
  231. package/dist/recorder.js +176 -95
  232. package/dist/recorder.js.map +1 -1
  233. package/dist/rerank.cjs +13 -11
  234. package/dist/rerank.cjs.map +1 -1
  235. package/dist/rerank.js +12 -10
  236. package/dist/rerank.js.map +1 -1
  237. package/dist/response/catalog/anthropic-page.cjs +39 -0
  238. package/dist/response/catalog/anthropic-page.cjs.map +1 -0
  239. package/dist/response/catalog/anthropic-page.js +38 -0
  240. package/dist/response/catalog/anthropic-page.js.map +1 -0
  241. package/dist/response/catalog/collect.cjs +61 -0
  242. package/dist/response/catalog/collect.cjs.map +1 -0
  243. package/dist/response/catalog/collect.js +59 -0
  244. package/dist/response/catalog/collect.js.map +1 -0
  245. package/dist/response/catalog/gemini-page.cjs +25 -0
  246. package/dist/response/catalog/gemini-page.cjs.map +1 -0
  247. package/dist/response/catalog/gemini-page.js +24 -0
  248. package/dist/response/catalog/gemini-page.js.map +1 -0
  249. package/dist/response/catalog/render.cjs +182 -0
  250. package/dist/response/catalog/render.cjs.map +1 -0
  251. package/dist/response/catalog/render.js +171 -0
  252. package/dist/response/catalog/render.js.map +1 -0
  253. package/dist/response/errors.cjs +225 -0
  254. package/dist/response/errors.cjs.map +1 -0
  255. package/dist/response/errors.js +224 -0
  256. package/dist/response/errors.js.map +1 -0
  257. package/dist/response/finish.cjs +39 -0
  258. package/dist/response/finish.cjs.map +1 -0
  259. package/dist/response/finish.js +35 -0
  260. package/dist/response/finish.js.map +1 -0
  261. package/dist/response/policy.cjs +126 -0
  262. package/dist/response/policy.cjs.map +1 -0
  263. package/dist/response/policy.js +120 -0
  264. package/dist/response/policy.js.map +1 -0
  265. package/dist/response/profiles.cjs +69 -0
  266. package/dist/response/profiles.cjs.map +1 -0
  267. package/dist/response/profiles.js +65 -0
  268. package/dist/response/profiles.js.map +1 -0
  269. package/dist/response/usage/codecs/anthropic.cjs +52 -0
  270. package/dist/response/usage/codecs/anthropic.cjs.map +1 -0
  271. package/dist/response/usage/codecs/anthropic.js +50 -0
  272. package/dist/response/usage/codecs/anthropic.js.map +1 -0
  273. package/dist/response/usage/codecs/cohere.cjs +36 -0
  274. package/dist/response/usage/codecs/cohere.cjs.map +1 -0
  275. package/dist/response/usage/codecs/cohere.js +35 -0
  276. package/dist/response/usage/codecs/cohere.js.map +1 -0
  277. package/dist/response/usage/codecs/converse.cjs +16 -0
  278. package/dist/response/usage/codecs/converse.cjs.map +1 -0
  279. package/dist/response/usage/codecs/converse.js +15 -0
  280. package/dist/response/usage/codecs/converse.js.map +1 -0
  281. package/dist/response/usage/codecs/gemini.cjs +31 -0
  282. package/dist/response/usage/codecs/gemini.cjs.map +1 -0
  283. package/dist/response/usage/codecs/gemini.js +31 -0
  284. package/dist/response/usage/codecs/gemini.js.map +1 -0
  285. package/dist/response/usage/codecs/interactions.cjs +22 -0
  286. package/dist/response/usage/codecs/interactions.cjs.map +1 -0
  287. package/dist/response/usage/codecs/interactions.js +21 -0
  288. package/dist/response/usage/codecs/interactions.js.map +1 -0
  289. package/dist/response/usage/codecs/ollama.cjs +17 -0
  290. package/dist/response/usage/codecs/ollama.cjs.map +1 -0
  291. package/dist/response/usage/codecs/ollama.js +17 -0
  292. package/dist/response/usage/codecs/ollama.js.map +1 -0
  293. package/dist/response/usage/codecs/openai.cjs +52 -0
  294. package/dist/response/usage/codecs/openai.cjs.map +1 -0
  295. package/dist/response/usage/codecs/openai.js +50 -0
  296. package/dist/response/usage/codecs/openai.js.map +1 -0
  297. package/dist/response/usage/codecs/openrouter.cjs +68 -0
  298. package/dist/response/usage/codecs/openrouter.cjs.map +1 -0
  299. package/dist/response/usage/codecs/openrouter.js +67 -0
  300. package/dist/response/usage/codecs/openrouter.js.map +1 -0
  301. package/dist/response/usage/codecs/realtime.cjs +19 -0
  302. package/dist/response/usage/codecs/realtime.cjs.map +1 -0
  303. package/dist/response/usage/codecs/realtime.js +18 -0
  304. package/dist/response/usage/codecs/realtime.js.map +1 -0
  305. package/dist/response/usage/codecs/responses.cjs +21 -0
  306. package/dist/response/usage/codecs/responses.cjs.map +1 -0
  307. package/dist/response/usage/codecs/responses.js +20 -0
  308. package/dist/response/usage/codecs/responses.js.map +1 -0
  309. package/dist/response/usage/estimate.cjs +23 -0
  310. package/dist/response/usage/estimate.cjs.map +1 -0
  311. package/dist/response/usage/estimate.js +21 -0
  312. package/dist/response/usage/estimate.js.map +1 -0
  313. package/dist/response/usage/fields.cjs +72 -0
  314. package/dist/response/usage/fields.cjs.map +1 -0
  315. package/dist/response/usage/fields.js +70 -0
  316. package/dist/response/usage/fields.js.map +1 -0
  317. package/dist/response/usage/recording.cjs +52 -0
  318. package/dist/response/usage/recording.cjs.map +1 -0
  319. package/dist/response/usage/recording.js +52 -0
  320. package/dist/response/usage/recording.js.map +1 -0
  321. package/dist/responses.cjs +45 -58
  322. package/dist/responses.cjs.map +1 -1
  323. package/dist/responses.d.cts.map +1 -1
  324. package/dist/responses.d.ts.map +1 -1
  325. package/dist/responses.js +44 -57
  326. package/dist/responses.js.map +1 -1
  327. package/dist/route-registry.cjs +45 -0
  328. package/dist/route-registry.cjs.map +1 -1
  329. package/dist/route-registry.d.cts.map +1 -1
  330. package/dist/route-registry.d.ts.map +1 -1
  331. package/dist/route-registry.js +41 -1
  332. package/dist/route-registry.js.map +1 -1
  333. package/dist/router.cjs +4 -0
  334. package/dist/router.cjs.map +1 -1
  335. package/dist/router.d.cts.map +1 -1
  336. package/dist/router.d.ts.map +1 -1
  337. package/dist/router.js +3 -0
  338. package/dist/router.js.map +1 -1
  339. package/dist/search.cjs +13 -11
  340. package/dist/search.cjs.map +1 -1
  341. package/dist/search.js +12 -10
  342. package/dist/search.js.map +1 -1
  343. package/dist/server.cjs +222 -146
  344. package/dist/server.cjs.map +1 -1
  345. package/dist/server.d.cts.map +1 -1
  346. package/dist/server.d.ts.map +1 -1
  347. package/dist/server.js +223 -147
  348. package/dist/server.js.map +1 -1
  349. package/dist/speech.cjs +20 -18
  350. package/dist/speech.cjs.map +1 -1
  351. package/dist/speech.d.cts.map +1 -1
  352. package/dist/speech.d.ts.map +1 -1
  353. package/dist/speech.js +19 -17
  354. package/dist/speech.js.map +1 -1
  355. package/dist/sse-writer.cjs +7 -0
  356. package/dist/sse-writer.cjs.map +1 -1
  357. package/dist/sse-writer.d.cts.map +1 -1
  358. package/dist/sse-writer.d.ts.map +1 -1
  359. package/dist/sse-writer.js +7 -1
  360. package/dist/sse-writer.js.map +1 -1
  361. package/dist/stream-collapse.cjs +118 -11
  362. package/dist/stream-collapse.cjs.map +1 -1
  363. package/dist/stream-collapse.d.cts +10 -9
  364. package/dist/stream-collapse.d.cts.map +1 -1
  365. package/dist/stream-collapse.d.ts +10 -9
  366. package/dist/stream-collapse.d.ts.map +1 -1
  367. package/dist/stream-collapse.js +118 -11
  368. package/dist/stream-collapse.js.map +1 -1
  369. package/dist/transcription.cjs +12 -10
  370. package/dist/transcription.cjs.map +1 -1
  371. package/dist/transcription.d.cts.map +1 -1
  372. package/dist/transcription.d.ts.map +1 -1
  373. package/dist/transcription.js +11 -9
  374. package/dist/transcription.js.map +1 -1
  375. package/dist/types.cjs.map +1 -1
  376. package/dist/types.d.cts +62 -3
  377. package/dist/types.d.cts.map +1 -1
  378. package/dist/types.d.ts +62 -3
  379. package/dist/types.d.ts.map +1 -1
  380. package/dist/types.js.map +1 -1
  381. package/dist/vector-mock.cjs +3 -8
  382. package/dist/vector-mock.cjs.map +1 -1
  383. package/dist/vector-mock.d.cts.map +1 -1
  384. package/dist/vector-mock.d.ts.map +1 -1
  385. package/dist/vector-mock.js +3 -8
  386. package/dist/vector-mock.js.map +1 -1
  387. package/dist/vector-stores.cjs +2 -4
  388. package/dist/vector-stores.cjs.map +1 -1
  389. package/dist/vector-stores.d.cts.map +1 -1
  390. package/dist/vector-stores.d.ts.map +1 -1
  391. package/dist/vector-stores.js +2 -4
  392. package/dist/vector-stores.js.map +1 -1
  393. package/dist/veo-video.cjs +16 -14
  394. package/dist/veo-video.cjs.map +1 -1
  395. package/dist/veo-video.js +10 -8
  396. package/dist/veo-video.js.map +1 -1
  397. package/dist/video.cjs +21 -19
  398. package/dist/video.cjs.map +1 -1
  399. package/dist/video.d.cts.map +1 -1
  400. package/dist/video.d.ts.map +1 -1
  401. package/dist/video.js +20 -18
  402. package/dist/video.js.map +1 -1
  403. package/dist/ws-gemini-live.cjs +11 -3
  404. package/dist/ws-gemini-live.cjs.map +1 -1
  405. package/dist/ws-gemini-live.d.cts +0 -1
  406. package/dist/ws-gemini-live.d.cts.map +1 -1
  407. package/dist/ws-gemini-live.d.ts +0 -1
  408. package/dist/ws-gemini-live.d.ts.map +1 -1
  409. package/dist/ws-gemini-live.js +10 -2
  410. package/dist/ws-gemini-live.js.map +1 -1
  411. package/dist/ws-live.cjs +6 -5
  412. package/dist/ws-live.cjs.map +1 -1
  413. package/dist/ws-live.js +5 -4
  414. package/dist/ws-live.js.map +1 -1
  415. package/dist/ws-realtime.cjs +28 -54
  416. package/dist/ws-realtime.cjs.map +1 -1
  417. package/dist/ws-realtime.d.cts.map +1 -1
  418. package/dist/ws-realtime.d.ts.map +1 -1
  419. package/dist/ws-realtime.js +25 -51
  420. package/dist/ws-realtime.js.map +1 -1
  421. package/dist/ws-responses.cjs +8 -6
  422. package/dist/ws-responses.cjs.map +1 -1
  423. package/dist/ws-responses.js +7 -5
  424. package/dist/ws-responses.js.map +1 -1
  425. package/package.json +4 -1
  426. package/skills/write-fixtures/SKILL.md +25 -16
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.cjs","names":["AZURE_RE","ELEVENLABS_TTS_RE","ELEVENLABS_VOICE_RE","OPENROUTER_VIDEO_CONTENT_RE","OPENROUTER_VIDEO_STATUS_RE","VEO_PREDICT_LRO_RE","VEO_OPERATION_RE","GROK_VIDEO_SUBMIT_PATH","OPENAI_VIDEO_STATUS_RE","BYTEPLUS_VIDEO_STATUS_RE","BYTEPLUS_VIDEO_SUBMIT_RE","BATCHES_CANCEL_RE","BATCHES_ID_RE","FILES_CONTENT_RE","FILES_ID_RE","VECTOR_STORES_SEARCH_RE","VECTOR_STORES_BATCH_FILES_RE","VECTOR_STORES_BATCH_CANCEL_RE","VECTOR_STORES_BATCH_RE","VECTOR_STORES_FILE_RE","VECTOR_STORES_FILES_RE","VECTOR_STORES_FILE_BATCHES_RE","VECTOR_STORES_ID_RE","FAL_ROUTE_RE","FINE_TUNING_ID_RE"],"sources":["../src/metrics.ts"],"sourcesContent":["/**\n * Lightweight Prometheus metrics registry for LLMock.\n *\n * Zero external dependencies — implements counters, histograms, and gauges\n * with Prometheus text exposition format serialization.\n */\n\nimport {\n AZURE_DEPLOYMENT_RE as AZURE_RE,\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n ELEVENLABS_TTS_RE,\n ELEVENLABS_VOICE_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n FINE_TUNING_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILES_RE,\n VECTOR_STORES_FILE_BATCHES_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n} from \"./route-registry.js\";\n\n// Re-exported so existing importers (route tests) keep resolving these\n// against the metrics module. The bindings ARE the registry's — there is\n// exactly one pattern object per route family.\nexport {\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n};\n\n// ---------------------------------------------------------------------------\n// Public interface\n// ---------------------------------------------------------------------------\n\nexport interface MetricsRegistry {\n incrementCounter(name: string, labels: Record<string, string>): void;\n observeHistogram(name: string, labels: Record<string, string>, value: number): void;\n setGauge(name: string, labels: Record<string, string>, value: number): void;\n serialize(): string;\n reset(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Histogram bucket boundaries (Prometheus default-ish)\n// ---------------------------------------------------------------------------\n\nconst HISTOGRAM_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10];\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/** Build a stable label key string for map lookups: `label1=\"v1\",label2=\"v2\"` */\nfunction labelKey(labels: Record<string, string>): string {\n const entries = Object.entries(labels).sort(([a], [b]) => a.localeCompare(b));\n if (entries.length === 0) return \"\";\n return entries.map(([k, v]) => `${k}=\"${escapeLabelValue(v)}\"`).join(\",\");\n}\n\n/** Escape a label value per Prometheus text exposition format. */\nfunction escapeLabelValue(v: string): string {\n return v.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"').replace(/\\n/g, \"\\\\n\");\n}\n\n/** Format labels for Prometheus output: `{label1=\"v1\",label2=\"v2\"}` */\nfunction formatLabels(labels: Record<string, string>): string {\n return `{${labelKey(labels)}}`;\n}\n\n// ---------------------------------------------------------------------------\n// Internal metric storage types\n// ---------------------------------------------------------------------------\n\ninterface CounterData {\n type: \"counter\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ninterface HistogramData {\n type: \"histogram\";\n /** Map from labelKey → bucket counts, sum, count */\n series: Map<\n string,\n {\n labels: Record<string, string>;\n bucketCounts: number[]; // one per HISTOGRAM_BUCKETS entry\n sum: number;\n count: number;\n }\n >;\n}\n\ninterface GaugeData {\n type: \"gauge\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ntype MetricData = CounterData | HistogramData | GaugeData;\n\n// ---------------------------------------------------------------------------\n// Registry implementation\n// ---------------------------------------------------------------------------\n\nexport function createMetricsRegistry(): MetricsRegistry {\n /** Ordered map: metric name → data. Insertion order preserved for stable output. */\n const metrics = new Map<string, MetricData>();\n\n function getOrCreateCounter(name: string): CounterData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"counter\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"counter\") throw new Error(`Metric ${name} is not a counter`);\n return data as CounterData;\n }\n\n function getOrCreateHistogram(name: string): HistogramData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"histogram\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"histogram\") throw new Error(`Metric ${name} is not a histogram`);\n return data as HistogramData;\n }\n\n function getOrCreateGauge(name: string): GaugeData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"gauge\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"gauge\") throw new Error(`Metric ${name} is not a gauge`);\n return data as GaugeData;\n }\n\n return {\n incrementCounter(name: string, labels: Record<string, string>): void {\n const counter = getOrCreateCounter(name);\n const key = labelKey(labels);\n const existing = counter.series.get(key);\n if (existing) {\n existing.value += 1;\n } else {\n counter.series.set(key, { labels, value: 1 });\n }\n },\n\n observeHistogram(name: string, labels: Record<string, string>, value: number): void {\n const histogram = getOrCreateHistogram(name);\n const key = labelKey(labels);\n let existing = histogram.series.get(key);\n if (!existing) {\n existing = {\n labels,\n bucketCounts: new Array(HISTOGRAM_BUCKETS.length).fill(0) as number[],\n sum: 0,\n count: 0,\n };\n histogram.series.set(key, existing);\n }\n // Update cumulative bucket counts\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n if (value <= HISTOGRAM_BUCKETS[i]) {\n existing.bucketCounts[i] += 1;\n }\n }\n existing.sum += value;\n existing.count += 1;\n },\n\n setGauge(name: string, labels: Record<string, string>, value: number): void {\n const gauge = getOrCreateGauge(name);\n const key = labelKey(labels);\n const existing = gauge.series.get(key);\n if (existing) {\n existing.value = value;\n } else {\n gauge.series.set(key, { labels, value });\n }\n },\n\n serialize(): string {\n const lines: string[] = [];\n\n for (const [name, data] of metrics) {\n switch (data.type) {\n case \"counter\": {\n lines.push(`# TYPE ${name} counter`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n case \"histogram\": {\n lines.push(`# TYPE ${name} histogram`);\n for (const series of data.series.values()) {\n const lblStr = labelKey(series.labels);\n const lblPrefix = lblStr ? `${lblStr},` : \"\";\n // Bucket lines\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n lines.push(\n `${name}_bucket{${lblPrefix}le=\"${HISTOGRAM_BUCKETS[i]}\"} ${series.bucketCounts[i]}`,\n );\n }\n // +Inf bucket\n lines.push(`${name}_bucket{${lblPrefix}le=\"+Inf\"} ${series.count}`);\n // Sum and count\n lines.push(`${name}_sum${formatLabels(series.labels)} ${series.sum}`);\n lines.push(`${name}_count${formatLabels(series.labels)} ${series.count}`);\n }\n break;\n }\n case \"gauge\": {\n lines.push(`# TYPE ${name} gauge`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n }\n }\n\n return lines.length > 0 ? lines.join(\"\\n\") + \"\\n\" : \"\";\n },\n\n reset(): void {\n metrics.clear();\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Path normalization for metric labels\n// ---------------------------------------------------------------------------\n\n// Regex patterns for parametric API routes. The dispatch+labeling patterns\n// shared with server.ts dispatch and the machine-readable catalog are defined\n// in route-registry.ts (single source of truth) and imported above; only\n// labeling-specific patterns are declared here: the Bedrock union, the Looser\n// Vertex shape, the widened Gemini action bucket (+ its allowlists), and the\n// served-or-not namespace cascades below.\nconst BEDROCK_RE =\n /^\\/model\\/([^/]+)\\/(invoke|invoke-with-response-stream|converse|converse-stream)$/;\nconst VERTEX_RE =\n /^\\/v1\\/projects\\/([^/]+)\\/locations\\/([^/]+)\\/publishers\\/google\\/models\\/([^:]+):(.+)$/;\n// Gemini `/v1beta/models/{model}:{action}`. The action segment is caller\n// controlled, so only the actions the server routes stay verbatim; anything\n// else collapses to `{action}`. `predictLongRunning` is listed so the Veo\n// submit label below stays byte-identical to what it was before this RE\n// widened past generate/streamGenerate — the two rules must agree.\nconst GEMINI_RE = /^\\/v1beta\\/models\\/([^:]+):([^/]+)$/;\nconst GEMINI_ACTIONS = new Set([\n \"generateContent\",\n \"streamGenerateContent\",\n \"embedContent\",\n \"batchEmbedContents\",\n \"countTokens\",\n \"predict\",\n \"predictLongRunning\",\n]);\nconst GEMINI_MODEL_RE = /^\\/v1beta\\/models\\/([^:/]+)$/;\n// The Vertex `:action` segment is caller controlled exactly as Gemini's is;\n// server.ts routes only these two, so anything else collapses to `{action}`.\nconst VERTEX_ACTIONS = new Set([\"generateContent\", \"streamGenerateContent\"]);\n\n/**\n * Closed namespaces beyond fine-tuning. Each prefix below is entered by prefix\n * and always returns, so no id-bearing or unknown-depth path under it can\n * reach the verbatim return at the bottom of `normalizePathLabel`:\n *\n * - fal: `/fal/queue/requests/{id}[/status|/cancel|/stream]` (aimock's own\n * queue layout), `/fal/{model}/requests/{id}[/…]` (the `x-fal-target-host`\n * path-mirror of `queue.fal.run`), `/fal/queue/submit/{model}`,\n * `/fal/run/{model}`. Request ids are minted per submit and model ids are\n * caller-controlled multi-segment paths, so both collapse.\n * - music: `/v1/music/{generation|variation|remix|extend|plan|detailed|stream}`\n * are the ElevenLabs routes (`plan`/`stream` take their own response shape\n * in elevenlabs-audio.ts); the server RE accepts any suffix, so an unknown\n * one collapses.\n * - files / batches: the id and sub-resource rules above cover the routed\n * shapes; any other depth collapses to the namespace's `{other}`.\n */\n/**\n * The fal.ai route shape (`FAL_ROUTE_RE`, imported from route-registry.ts so\n * the label rule cannot drift from the route rule): a bare `/fal` is routed,\n * so it is labelled here rather than falling through to `{unknown}`.\n */\nconst FAL_QUEUE_REQUEST_RE = /^\\/fal\\/queue\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_MIRROR_REQUEST_RE = /^\\/fal\\/.+\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_REQUEST_SUBRESOURCES = new Set([\"status\", \"cancel\", \"stream\"]);\nconst FAL_QUEUE_SUBMIT_RE = /^\\/fal\\/queue\\/submit\\/.+$/;\nconst FAL_RUN_RE = /^\\/fal\\/run\\/.+$/;\nconst FAL_OTHER_LABEL = \"/fal/{other}\";\nconst MUSIC_PREFIX = \"/v1/music/\";\nconst MUSIC_ACTIONS = new Set([\n \"generation\",\n \"variation\",\n \"remix\",\n \"extend\",\n \"plan\",\n \"detailed\",\n \"stream\",\n]);\nconst MUSIC_OTHER_LABEL = \"/v1/music/{other}\";\nconst FILES_PREFIX = \"/v1/files/\";\nconst FILES_OTHER_LABEL = \"/v1/files/{other}\";\nconst BATCHES_PREFIX = \"/v1/batches/\";\nconst BATCHES_OTHER_LABEL = \"/v1/batches/{other}\";\nconst VECTOR_STORES_PREFIX = \"/v1/vector_stores/\";\nconst VECTOR_STORES_OTHER_LABEL = \"/v1/vector_stores/{other}\";\n\n/**\n * Label for a path no route claimed. Metrics are recorded for EVERY response,\n * the generic 404 included, so an unrouted path is caller-controlled text and\n * a fuzzer (or a typo'd SDK base URL) would mint one label per request.\n *\n * The collapse is decided by ROUTE SHAPE, never by status: a 404 is not the\n * only way an unrouted path gets answered (a CORS preflight is 204 for any\n * path, a torn-down response has no status at all), and a routed path can\n * legitimately 404 (a fixture miss, a missing file) without becoming\n * unknown. Every path that is not claimed by a placeholder rule above must\n * therefore be listed here to keep its verbatim label.\n */\nexport const UNKNOWN_PATH_LABEL = \"{unknown}\";\n\n/**\n * Static paths server.ts dispatches by exact match (after\n * `normalizeCompatPath`, so the canonical `/v1/...` spelling). A path absent\n * from this table that no placeholder rule claims is labelled `{unknown}`\n * whatever its status — so a new static route needs an entry here or its\n * traffic is counted but not named.\n */\nconst STATIC_ROUTE_PATHS = new Set([\n \"/health\",\n \"/ready\",\n \"/metrics\",\n \"/search\",\n \"/v1/chat/completions\",\n \"/v1/responses\",\n \"/v1/realtime\",\n \"/v1/messages\",\n \"/v1/embeddings\",\n \"/v1/moderations\",\n \"/v1/models\",\n \"/v1/_requests\",\n \"/v1/images/generations\",\n \"/v1/images/edits\",\n \"/v1/images/variations\",\n \"/v1/audio/speech\",\n \"/v1/audio/transcriptions\",\n \"/v1/audio/translations\",\n \"/v1/videos\",\n \"/v1/batches\",\n \"/v1/files\",\n \"/v1/vector_stores\",\n \"/v1/sound-generation\",\n \"/v1/music\",\n \"/v1/text-to-voice\",\n \"/v1/text-to-voice/design\",\n \"/v1beta/interactions\",\n \"/v2/chat\",\n \"/v2/embed\",\n \"/v2/rerank\",\n \"/api/chat\",\n \"/api/generate\",\n \"/api/embeddings\",\n \"/api/embed\",\n \"/api/tags\",\n \"/api/v1/videos\",\n \"/api/v1/videos/models\",\n \"/api/v1/credits\",\n \"/api/v1/key\",\n \"/api/v1/models\",\n \"/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent\",\n]);\n\n/**\n * Control API (`/__aimock/...`): a closed set of sub-paths, matched exactly\n * in `handleControlAPI`; anything else under the prefix collapses.\n */\nconst CONTROL_PREFIX = \"/__aimock/\";\nconst CONTROL_PATHS = new Set([\n \"/__aimock/health\",\n \"/__aimock/journal\",\n \"/__aimock/fixtures\",\n \"/__aimock/chaos\",\n \"/__aimock/reset\",\n \"/__aimock/reset/journal\",\n \"/__aimock/reset/fixtures\",\n \"/__aimock/error\",\n \"/__aimock/openapi.json\",\n \"/__aimock/routes\",\n]);\nconst CONTROL_OTHER_LABEL = \"/__aimock/{other}\";\n\n/**\n * Sub-paths a mounted service (`createServer(..., mounts)`) answers below its\n * mount root. The mount roots themselves are runtime configuration, so the\n * caller passes them in; the JSON-RPC handlers (MCP, A2A, AG-UI, vector) take\n * the root only, and A2A additionally serves its agent card.\n */\nconst MOUNT_SUBPATHS = new Set([\"/.well-known/agent-card.json\"]);\n\n/**\n * Status label for a response that was destroyed before its body ended: no\n * status line reached the client as a completed response, so no HTTP code\n * describes the outcome truthfully. Distinct from every numeric status so\n * `sum(aimock_requests_total)` equals requests served.\n */\nexport const DESTROYED_STATUS_LABEL = \"destroyed\";\n\n/**\n * Fine-tuning routes. Both id families (`ftjob-…` per create, `ftckpt-…` per\n * checkpoint) are minted per resource, so every id-bearing path has to collapse\n * or each job and each checkpoint mints its own label pair.\n *\n * The label hazard is NOT limited to the routes this server implements: metrics\n * are recorded on `res.on(\"finish\")` for EVERY response, the generic 404\n * included, and `openai@4.104.0` calls a good deal more of the namespace than\n * aimock handles. Enumerated from that SDK:\n *\n * - `resources/fine-tuning/jobs/jobs.js` — `/fine_tuning/jobs`,\n * `…/jobs/{id}`, `…/jobs/{id}/cancel`, `…/jobs/{id}/pause`,\n * `…/jobs/{id}/resume`\n * - `resources/fine-tuning/jobs/checkpoints.js` — `…/jobs/{id}/checkpoints`\n * - `resources/fine-tuning/checkpoints/permissions.js` —\n * `…/checkpoints/{ckpt}/permissions` (create/list) and\n * `…/checkpoints/{ckpt}/permissions/{id}` (delete)\n * - `resources/fine-tuning/alpha/graders.js` —\n * `/fine_tuning/alpha/graders/run`, `/fine_tuning/alpha/graders/validate`\n *\n * The grader routes carry no ids, so they need no placeholder — but they DO\n * need naming here, because the namespace cascade below ends in a catch-all\n * and a static route must not be swallowed by it.\n *\n * Every segment after `/v1/fine_tuning/` is caller-controlled, so the rule is:\n * known action names are kept verbatim, ids collapse to `{id}`/`{ckpt}`, and\n * anything else — an unknown action, an unknown depth — collapses to a single\n * bucket. That is what actually keeps the fine-tuning label set finite no\n * matter what is requested; an un-collapsed tail would leave the hole open to\n * a typo or a fuzzer.\n *\n * Not exported: server.ts dispatches fine-tuning jobs from the same\n * route-registry.ts bindings (`FINE_TUNING_JOBS_PATH`, `FINE_TUNING_ID_RE`,\n * `FINE_TUNING_CANCEL_RE`, `FINE_TUNING_EVENTS_RE`).\n */\nconst FINE_TUNING_PREFIX = \"/v1/fine_tuning/\";\nconst FINE_TUNING_STATIC_PATHS = new Set([\n \"/v1/fine_tuning/jobs\",\n \"/v1/fine_tuning/alpha/graders/run\",\n \"/v1/fine_tuning/alpha/graders/validate\",\n]);\nconst FINE_TUNING_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/jobs\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_SUBRESOURCES = new Set([\"cancel\", \"events\", \"pause\", \"resume\", \"checkpoints\"]);\nconst FINE_TUNING_PERMISSION_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/permissions\\/[^/]+$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCES = new Set([\"permissions\"]);\nconst FINE_TUNING_CHECKPOINT_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/([^/]+)$/;\nconst FINE_TUNING_OTHER_LABEL = \"/v1/fine_tuning/{other}\";\n\n/**\n * Normalize parametric API paths to route patterns for use as metric labels.\n * Replaces dynamic segments (model IDs, deployment names, etc.) with placeholders.\n * `mountPaths` are the roots of the mounted services, so their traffic keeps a\n * bounded label instead of collapsing to `{unknown}`.\n */\nexport function normalizePathLabel(pathname: string, mountPaths: readonly string[] = []): string {\n // Match server dispatch precedence: controls, mounts in registration order,\n // then provider routes. A mount may overlap any provider namespace.\n // Control API: exact sub-paths verbatim, anything else under the prefix\n // collapses.\n if (pathname.startsWith(CONTROL_PREFIX)) {\n return CONTROL_PATHS.has(pathname) ? pathname : CONTROL_OTHER_LABEL;\n }\n\n // Mounted services: the root and the known sub-paths verbatim, anything\n // deeper collapses under the mount.\n for (const mountPath of mountPaths) {\n if (pathname === mountPath) return pathname;\n if (pathname.startsWith(mountPath + \"/\")) {\n return MOUNT_SUBPATHS.has(pathname.slice(mountPath.length))\n ? pathname\n : `${mountPath}/{other}`;\n }\n }\n\n // Bedrock: /model/{modelId}/{operation}\n const bedrockMatch = pathname.match(BEDROCK_RE);\n if (bedrockMatch) {\n return `/model/{modelId}/${bedrockMatch[2]}`;\n }\n\n // Gemini: /v1beta/models/{model}:{action}, plus the bare GET model lookup.\n const geminiMatch = pathname.match(GEMINI_RE);\n if (geminiMatch) {\n const action = GEMINI_ACTIONS.has(geminiMatch[2]) ? geminiMatch[2] : \"{action}\";\n return `/v1beta/models/{model}:${action}`;\n }\n if (GEMINI_MODEL_RE.test(pathname)) {\n return \"/v1beta/models/{model}\";\n }\n\n // Azure: /openai/deployments/{id}/{operation}\n const azureMatch = pathname.match(AZURE_RE);\n if (azureMatch) {\n return `/openai/deployments/{id}/${azureMatch[2]}`;\n }\n\n // Vertex AI: /v1/projects/{p}/locations/{l}/publishers/google/models/{m}:{action}\n const vertexMatch = pathname.match(VERTEX_RE);\n if (vertexMatch) {\n const action = VERTEX_ACTIONS.has(vertexMatch[4]) ? vertexMatch[4] : \"{action}\";\n return `/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:${action}`;\n }\n\n // ElevenLabs TTS: /v1/text-to-speech/{voice_id}\n if (ELEVENLABS_TTS_RE.test(pathname)) {\n return \"/v1/text-to-speech/{voice_id}\";\n }\n\n // ElevenLabs voices: /v1/voices/{voice_id}\n if (ELEVENLABS_VOICE_RE.test(pathname)) {\n return \"/v1/voices/{voice_id}\";\n }\n\n // OpenRouter video: /api/v1/videos/{jobId}[/content] — jobIds are random\n // UUIDs, so raw paths would mint unbounded label cardinality. The static\n // /api/v1/videos/models listing route must not collapse into {jobId}.\n if (OPENROUTER_VIDEO_CONTENT_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}/content\";\n }\n if (pathname !== \"/api/v1/videos/models\" && OPENROUTER_VIDEO_STATUS_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}\";\n }\n\n // Google Veo video: submit `:predictLongRunning` + poll `/v1beta/operations/{name}`.\n // Operation names are random UUIDs, so the raw path would mint unbounded\n // label cardinality.\n if (VEO_PREDICT_LRO_RE.test(pathname)) {\n return \"/v1beta/models/{model}:predictLongRunning\";\n }\n if (VEO_OPERATION_RE.test(pathname)) {\n return \"/v1beta/operations/{name}\";\n }\n\n // xAI Grok Imagine submit is a static literal path — keep it distinct from\n // the `/v1/videos/{id}` status label below (which it would otherwise collapse\n // into), exactly as `/api/v1/videos/models` is kept out of the jobId bucket.\n if (pathname === GROK_VIDEO_SUBMIT_PATH) {\n return GROK_VIDEO_SUBMIT_PATH;\n }\n\n // OpenAI/Grok video status: /v1/videos/{id}\n if (OPENAI_VIDEO_STATUS_RE.test(pathname)) {\n return \"/v1/videos/{id}\";\n }\n\n // BytePlus Ark video: /[api/v3/]contents/generations/tasks[/{id}] — task ids\n // (`cgt-…`) are unbounded cardinality. Status before submit: the status RE is\n // the more specific of the two and the submit RE cannot match a trailing id\n // segment, so the order is belt-and-braces. Appended at the end of the\n // cascade because the anchored REs above cannot match any path an earlier\n // entry claims.\n if (BYTEPLUS_VIDEO_STATUS_RE.test(pathname)) {\n return \"/contents/generations/tasks/{id}\";\n }\n if (BYTEPLUS_VIDEO_SUBMIT_RE.test(pathname)) {\n return \"/contents/generations/tasks\";\n }\n\n if (BATCHES_CANCEL_RE.test(pathname)) {\n return \"/v1/batches/{id}/cancel\";\n }\n if (pathname !== \"/v1/batches\" && BATCHES_ID_RE.test(pathname)) {\n return \"/v1/batches/{id}\";\n }\n if (pathname.startsWith(BATCHES_PREFIX)) {\n return BATCHES_OTHER_LABEL;\n }\n\n // Files API: /v1/files/{id} and /v1/files/{id}/content carry random\n // `file-…` ids — raw paths would mint unbounded label cardinality.\n // Content before id: the id RE would otherwise swallow the content suffix.\n if (FILES_CONTENT_RE.test(pathname)) {\n return \"/v1/files/{id}/content\";\n }\n if (pathname !== \"/v1/files\" && FILES_ID_RE.test(pathname)) {\n return \"/v1/files/{id}\";\n }\n if (pathname.startsWith(FILES_PREFIX)) {\n return FILES_OTHER_LABEL;\n }\n\n // Vector Stores: /v1/vector_stores/{id}[/files[/{fileId}]|/file_batches…|/search].\n // Most-specific first so the id RE cannot swallow a sub-resource suffix.\n if (VECTOR_STORES_SEARCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/search\";\n }\n if (VECTOR_STORES_BATCH_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/files\";\n }\n if (VECTOR_STORES_BATCH_CANCEL_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/cancel\";\n }\n if (VECTOR_STORES_BATCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}\";\n }\n if (VECTOR_STORES_FILE_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files/{fileId}\";\n }\n if (VECTOR_STORES_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files\";\n }\n if (VECTOR_STORES_FILE_BATCHES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches\";\n }\n if (pathname !== \"/v1/vector_stores\" && VECTOR_STORES_ID_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}\";\n }\n if (pathname.startsWith(VECTOR_STORES_PREFIX)) {\n return VECTOR_STORES_OTHER_LABEL;\n }\n\n // fal.ai: see the namespace note above. Queue-request rules read before the\n // path-mirror rule because `/fal/queue/requests/…` also matches the mirror\n // RE's `.+/requests/` shape; both would label correctly, but the specific\n // rule reading first keeps the cascade legible.\n if (FAL_ROUTE_RE.test(pathname)) {\n const queueRequest = pathname.match(FAL_QUEUE_REQUEST_RE);\n if (queueRequest) {\n return `/fal/queue/requests/{id}${falRequestSuffix(queueRequest[1])}`;\n }\n if (FAL_QUEUE_SUBMIT_RE.test(pathname)) return \"/fal/queue/submit/{model}\";\n if (FAL_RUN_RE.test(pathname)) return \"/fal/run/{model}\";\n const mirrorRequest = pathname.match(FAL_MIRROR_REQUEST_RE);\n if (mirrorRequest) {\n return `/fal/{model}/requests/{id}${falRequestSuffix(mirrorRequest[1])}`;\n }\n return FAL_OTHER_LABEL;\n }\n\n // ElevenLabs Music: known actions verbatim, anything else collapses.\n if (pathname.startsWith(MUSIC_PREFIX)) {\n return MUSIC_ACTIONS.has(pathname.slice(MUSIC_PREFIX.length)) ? pathname : MUSIC_OTHER_LABEL;\n }\n\n // Fine-tuning. Handled as one closed namespace rather than a few loose REs:\n // the cascade is entered by prefix and always returns, so no fine-tuning path\n // can reach the verbatim return at the bottom of this function.\n //\n // Order matters twice. The id-bearing permission rule reads before the\n // checkpoint sub-resource rule, because `…/permissions/{id}` would otherwise\n // never be reached (its own second segment is the id). Within each family the\n // sub-resource rule reads before the id rule; the id REs are anchored to a\n // single trailing segment so the two cannot both match, but the more specific\n // path reading first is what makes the cascade legible.\n if (pathname.startsWith(FINE_TUNING_PREFIX)) {\n if (FINE_TUNING_STATIC_PATHS.has(pathname)) return pathname;\n\n const ftSubresource = pathname.match(FINE_TUNING_SUBRESOURCE_RE);\n if (ftSubresource) {\n const action = FINE_TUNING_SUBRESOURCES.has(ftSubresource[1]) ? ftSubresource[1] : \"{action}\";\n return `/v1/fine_tuning/jobs/{id}/${action}`;\n }\n if (FINE_TUNING_ID_RE.test(pathname)) return \"/v1/fine_tuning/jobs/{id}\";\n\n if (FINE_TUNING_PERMISSION_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}/permissions/{id}\";\n }\n const ckptSubresource = pathname.match(FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE);\n if (ckptSubresource) {\n const action = FINE_TUNING_CHECKPOINT_SUBRESOURCES.has(ckptSubresource[1])\n ? ckptSubresource[1]\n : \"{action}\";\n return `/v1/fine_tuning/checkpoints/{ckpt}/${action}`;\n }\n if (FINE_TUNING_CHECKPOINT_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}\";\n }\n\n return FINE_TUNING_OTHER_LABEL;\n }\n\n // Static path — verbatim only if server.ts routes it. Anything else is, as\n // far as metrics can tell, caller-controlled text, whatever status it got\n // (404, a 204 preflight, a destroyed response); every routed id path that\n // can legitimately 404 has already returned its placeholder label above.\n return STATIC_ROUTE_PATHS.has(pathname) ? pathname : UNKNOWN_PATH_LABEL;\n}\n\nfunction falRequestSuffix(sub: string | undefined): string {\n if (sub === undefined) return \"\";\n return FAL_REQUEST_SUBRESOURCES.has(sub) ? `/${sub}` : \"/{other}\";\n}\n"],"mappings":";;;;;;;;;AA8EA,MAAM,oBAAoB;CAAC;CAAO;CAAM;CAAO;CAAM;CAAK;CAAM;CAAK;CAAG;CAAK;CAAG;CAAG;;AAOnF,SAAS,SAAS,QAAwC;CACxD,MAAM,UAAU,OAAO,QAAQ,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC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,IAAI,gBAAgB,GAAG,GACtE,gBAAgB,KAChB;AAGN,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;AAGT,SAAO;;AAOT,QAAO,mBAAmB,IAAI,SAAS,GAAG,WAAW;;AAGvD,SAAS,iBAAiB,KAAiC;AACzD,KAAI,QAAQ,OAAW,QAAO;AAC9B,QAAO,yBAAyB,IAAI,IAAI,GAAG,IAAI,QAAQ"}
1
+ {"version":3,"file":"metrics.cjs","names":["MODELS_DETAIL_RE","GEMINI_MODELS_PATH","GEMINI_MODEL_DETAIL_RE","AZURE_RE","ELEVENLABS_TTS_RE","ELEVENLABS_VOICE_RE","OPENROUTER_VIDEO_CONTENT_RE","OPENROUTER_VIDEO_STATUS_RE","VEO_PREDICT_LRO_RE","VEO_OPERATION_RE","GROK_VIDEO_SUBMIT_PATH","OPENAI_VIDEO_STATUS_RE","BYTEPLUS_VIDEO_STATUS_RE","BYTEPLUS_VIDEO_SUBMIT_RE","BATCHES_CANCEL_RE","BATCHES_ID_RE","FILES_CONTENT_RE","FILES_ID_RE","VECTOR_STORES_SEARCH_RE","VECTOR_STORES_BATCH_FILES_RE","VECTOR_STORES_BATCH_CANCEL_RE","VECTOR_STORES_BATCH_RE","VECTOR_STORES_FILE_RE","VECTOR_STORES_FILES_RE","VECTOR_STORES_FILE_BATCHES_RE","VECTOR_STORES_ID_RE","FAL_ROUTE_RE","FINE_TUNING_ID_RE"],"sources":["../src/metrics.ts"],"sourcesContent":["/**\n * Lightweight Prometheus metrics registry for LLMock.\n *\n * Zero external dependencies — implements counters, histograms, and gauges\n * with Prometheus text exposition format serialization.\n */\n\nimport {\n AZURE_DEPLOYMENT_RE as AZURE_RE,\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n ELEVENLABS_TTS_RE,\n ELEVENLABS_VOICE_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n FINE_TUNING_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n MODELS_DETAIL_RE,\n GEMINI_MODEL_DETAIL_RE,\n GEMINI_MODELS_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILES_RE,\n VECTOR_STORES_FILE_BATCHES_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n} from \"./route-registry.js\";\n\n// Re-exported so existing importers (route tests) keep resolving these\n// against the metrics module. The bindings ARE the registry's — there is\n// exactly one pattern object per route family.\nexport {\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n};\n\n// ---------------------------------------------------------------------------\n// Public interface\n// ---------------------------------------------------------------------------\n\nexport interface MetricsRegistry {\n incrementCounter(name: string, labels: Record<string, string>): void;\n observeHistogram(name: string, labels: Record<string, string>, value: number): void;\n setGauge(name: string, labels: Record<string, string>, value: number): void;\n serialize(): string;\n reset(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Histogram bucket boundaries (Prometheus default-ish)\n// ---------------------------------------------------------------------------\n\nconst HISTOGRAM_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10];\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/** Build a stable label key string for map lookups: `label1=\"v1\",label2=\"v2\"` */\nfunction labelKey(labels: Record<string, string>): string {\n const entries = Object.entries(labels).sort(([a], [b]) => a.localeCompare(b));\n if (entries.length === 0) return \"\";\n return entries.map(([k, v]) => `${k}=\"${escapeLabelValue(v)}\"`).join(\",\");\n}\n\n/** Escape a label value per Prometheus text exposition format. */\nfunction escapeLabelValue(v: string): string {\n return v.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"').replace(/\\n/g, \"\\\\n\");\n}\n\n/** Format labels for Prometheus output: `{label1=\"v1\",label2=\"v2\"}` */\nfunction formatLabels(labels: Record<string, string>): string {\n return `{${labelKey(labels)}}`;\n}\n\n// ---------------------------------------------------------------------------\n// Internal metric storage types\n// ---------------------------------------------------------------------------\n\ninterface CounterData {\n type: \"counter\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ninterface HistogramData {\n type: \"histogram\";\n /** Map from labelKey → bucket counts, sum, count */\n series: Map<\n string,\n {\n labels: Record<string, string>;\n bucketCounts: number[]; // one per HISTOGRAM_BUCKETS entry\n sum: number;\n count: number;\n }\n >;\n}\n\ninterface GaugeData {\n type: \"gauge\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ntype MetricData = CounterData | HistogramData | GaugeData;\n\n// ---------------------------------------------------------------------------\n// Registry implementation\n// ---------------------------------------------------------------------------\n\nexport function createMetricsRegistry(): MetricsRegistry {\n /** Ordered map: metric name → data. Insertion order preserved for stable output. */\n const metrics = new Map<string, MetricData>();\n\n function getOrCreateCounter(name: string): CounterData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"counter\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"counter\") throw new Error(`Metric ${name} is not a counter`);\n return data as CounterData;\n }\n\n function getOrCreateHistogram(name: string): HistogramData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"histogram\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"histogram\") throw new Error(`Metric ${name} is not a histogram`);\n return data as HistogramData;\n }\n\n function getOrCreateGauge(name: string): GaugeData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"gauge\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"gauge\") throw new Error(`Metric ${name} is not a gauge`);\n return data as GaugeData;\n }\n\n return {\n incrementCounter(name: string, labels: Record<string, string>): void {\n const counter = getOrCreateCounter(name);\n const key = labelKey(labels);\n const existing = counter.series.get(key);\n if (existing) {\n existing.value += 1;\n } else {\n counter.series.set(key, { labels, value: 1 });\n }\n },\n\n observeHistogram(name: string, labels: Record<string, string>, value: number): void {\n const histogram = getOrCreateHistogram(name);\n const key = labelKey(labels);\n let existing = histogram.series.get(key);\n if (!existing) {\n existing = {\n labels,\n bucketCounts: new Array(HISTOGRAM_BUCKETS.length).fill(0) as number[],\n sum: 0,\n count: 0,\n };\n histogram.series.set(key, existing);\n }\n // Update cumulative bucket counts\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n if (value <= HISTOGRAM_BUCKETS[i]) {\n existing.bucketCounts[i] += 1;\n }\n }\n existing.sum += value;\n existing.count += 1;\n },\n\n setGauge(name: string, labels: Record<string, string>, value: number): void {\n const gauge = getOrCreateGauge(name);\n const key = labelKey(labels);\n const existing = gauge.series.get(key);\n if (existing) {\n existing.value = value;\n } else {\n gauge.series.set(key, { labels, value });\n }\n },\n\n serialize(): string {\n const lines: string[] = [];\n\n for (const [name, data] of metrics) {\n switch (data.type) {\n case \"counter\": {\n lines.push(`# TYPE ${name} counter`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n case \"histogram\": {\n lines.push(`# TYPE ${name} histogram`);\n for (const series of data.series.values()) {\n const lblStr = labelKey(series.labels);\n const lblPrefix = lblStr ? `${lblStr},` : \"\";\n // Bucket lines\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n lines.push(\n `${name}_bucket{${lblPrefix}le=\"${HISTOGRAM_BUCKETS[i]}\"} ${series.bucketCounts[i]}`,\n );\n }\n // +Inf bucket\n lines.push(`${name}_bucket{${lblPrefix}le=\"+Inf\"} ${series.count}`);\n // Sum and count\n lines.push(`${name}_sum${formatLabels(series.labels)} ${series.sum}`);\n lines.push(`${name}_count${formatLabels(series.labels)} ${series.count}`);\n }\n break;\n }\n case \"gauge\": {\n lines.push(`# TYPE ${name} gauge`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n }\n }\n\n return lines.length > 0 ? lines.join(\"\\n\") + \"\\n\" : \"\";\n },\n\n reset(): void {\n metrics.clear();\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Path normalization for metric labels\n// ---------------------------------------------------------------------------\n\n// Regex patterns for parametric API routes. The dispatch+labeling patterns\n// shared with server.ts dispatch and the machine-readable catalog are defined\n// in route-registry.ts (single source of truth) and imported above; only\n// labeling-specific patterns are declared here: the Bedrock union, the Looser\n// Vertex shape, the widened Gemini action bucket (+ its allowlists), and the\n// served-or-not namespace cascades below.\nconst BEDROCK_RE =\n /^\\/model\\/([^/]+)\\/(invoke|invoke-with-response-stream|converse|converse-stream)$/;\nconst VERTEX_RE =\n /^\\/v1\\/projects\\/([^/]+)\\/locations\\/([^/]+)\\/publishers\\/google\\/models\\/([^:]+):(.+)$/;\n// Gemini `/v1beta/models/{model}:{action}`. The action segment is caller\n// controlled, so only the actions the server routes stay verbatim; anything\n// else collapses to `{action}`. `predictLongRunning` is listed so the Veo\n// submit label below stays byte-identical to what it was before this RE\n// widened past generate/streamGenerate — the two rules must agree.\nconst GEMINI_RE = /^\\/v1beta\\/models\\/([^:]+):([^/]+)$/;\n// Retain the historical label for unserved single-segment encoded action IDs.\nconst GEMINI_MODEL_LABEL_RE = /^\\/v1beta\\/models\\/([^:/]+)$/;\nconst GEMINI_ACTIONS = new Set([\n \"generateContent\",\n \"streamGenerateContent\",\n \"embedContent\",\n \"batchEmbedContents\",\n \"countTokens\",\n \"predict\",\n \"predictLongRunning\",\n]);\n// The Vertex `:action` segment is caller controlled exactly as Gemini's is;\n// server.ts routes only these two, so anything else collapses to `{action}`.\nconst VERTEX_ACTIONS = new Set([\"generateContent\", \"streamGenerateContent\"]);\n\n/**\n * Closed namespaces beyond fine-tuning. Each prefix below is entered by prefix\n * and always returns, so no id-bearing or unknown-depth path under it can\n * reach the verbatim return at the bottom of `normalizePathLabel`:\n *\n * - fal: `/fal/queue/requests/{id}[/status|/cancel|/stream]` (aimock's own\n * queue layout), `/fal/{model}/requests/{id}[/…]` (the `x-fal-target-host`\n * path-mirror of `queue.fal.run`), `/fal/queue/submit/{model}`,\n * `/fal/run/{model}`. Request ids are minted per submit and model ids are\n * caller-controlled multi-segment paths, so both collapse.\n * - music: `/v1/music/{generation|variation|remix|extend|plan|detailed|stream}`\n * are the ElevenLabs routes (`plan`/`stream` take their own response shape\n * in elevenlabs-audio.ts); the server RE accepts any suffix, so an unknown\n * one collapses.\n * - files / batches: the id and sub-resource rules above cover the routed\n * shapes; any other depth collapses to the namespace's `{other}`.\n */\n/**\n * The fal.ai route shape (`FAL_ROUTE_RE`, imported from route-registry.ts so\n * the label rule cannot drift from the route rule): a bare `/fal` is routed,\n * so it is labelled here rather than falling through to `{unknown}`.\n */\nconst FAL_QUEUE_REQUEST_RE = /^\\/fal\\/queue\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_MIRROR_REQUEST_RE = /^\\/fal\\/.+\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_REQUEST_SUBRESOURCES = new Set([\"status\", \"cancel\", \"stream\"]);\nconst FAL_QUEUE_SUBMIT_RE = /^\\/fal\\/queue\\/submit\\/.+$/;\nconst FAL_RUN_RE = /^\\/fal\\/run\\/.+$/;\nconst FAL_OTHER_LABEL = \"/fal/{other}\";\nconst MUSIC_PREFIX = \"/v1/music/\";\nconst MUSIC_ACTIONS = new Set([\n \"generation\",\n \"variation\",\n \"remix\",\n \"extend\",\n \"plan\",\n \"detailed\",\n \"stream\",\n]);\nconst MUSIC_OTHER_LABEL = \"/v1/music/{other}\";\nconst FILES_PREFIX = \"/v1/files/\";\nconst FILES_OTHER_LABEL = \"/v1/files/{other}\";\nconst BATCHES_PREFIX = \"/v1/batches/\";\nconst BATCHES_OTHER_LABEL = \"/v1/batches/{other}\";\nconst VECTOR_STORES_PREFIX = \"/v1/vector_stores/\";\nconst VECTOR_STORES_OTHER_LABEL = \"/v1/vector_stores/{other}\";\n\n/**\n * Label for a path no route claimed. Metrics are recorded for EVERY response,\n * the generic 404 included, so an unrouted path is caller-controlled text and\n * a fuzzer (or a typo'd SDK base URL) would mint one label per request.\n *\n * The collapse is decided by ROUTE SHAPE, never by status: a 404 is not the\n * only way an unrouted path gets answered (a CORS preflight is 204 for any\n * path, a torn-down response has no status at all), and a routed path can\n * legitimately 404 (a fixture miss, a missing file) without becoming\n * unknown. Every path that is not claimed by a placeholder rule above must\n * therefore be listed here to keep its verbatim label.\n */\nexport const UNKNOWN_PATH_LABEL = \"{unknown}\";\n\n/**\n * Static paths server.ts dispatches by exact match (after\n * `normalizeCompatPath`, so the canonical `/v1/...` spelling). A path absent\n * from this table that no placeholder rule claims is labelled `{unknown}`\n * whatever its status — so a new static route needs an entry here or its\n * traffic is counted but not named.\n */\nconst STATIC_ROUTE_PATHS = new Set([\n \"/health\",\n \"/ready\",\n \"/metrics\",\n \"/search\",\n \"/v1/chat/completions\",\n \"/v1/responses\",\n \"/v1/realtime\",\n \"/v1/messages\",\n \"/v1/messages/count_tokens\",\n \"/v1/embeddings\",\n \"/v1/moderations\",\n \"/v1/models\",\n \"/v1/_requests\",\n \"/v1/images/generations\",\n \"/v1/images/edits\",\n \"/v1/images/variations\",\n \"/v1/audio/speech\",\n \"/v1/audio/transcriptions\",\n \"/v1/audio/translations\",\n \"/v1/videos\",\n \"/v1/batches\",\n \"/v1/files\",\n \"/v1/vector_stores\",\n \"/v1/sound-generation\",\n \"/v1/music\",\n \"/v1/text-to-voice\",\n \"/v1/text-to-voice/design\",\n \"/v1beta/interactions\",\n \"/v2/chat\",\n \"/v2/embed\",\n \"/v2/rerank\",\n \"/api/chat\",\n \"/api/generate\",\n \"/api/embeddings\",\n \"/api/embed\",\n \"/api/tags\",\n \"/api/v1/videos\",\n \"/api/v1/videos/models\",\n \"/api/v1/credits\",\n \"/api/v1/key\",\n \"/api/v1/models\",\n \"/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent\",\n]);\n\n/**\n * Control API (`/__aimock/...`): a closed set of sub-paths, matched exactly\n * in `handleControlAPI`; anything else under the prefix collapses.\n */\nconst CONTROL_PREFIX = \"/__aimock/\";\nconst CONTROL_PATHS = new Set([\n \"/__aimock/health\",\n \"/__aimock/journal\",\n \"/__aimock/fixtures\",\n \"/__aimock/chaos\",\n \"/__aimock/reset\",\n \"/__aimock/reset/journal\",\n \"/__aimock/reset/fixtures\",\n \"/__aimock/error\",\n \"/__aimock/openapi.json\",\n \"/__aimock/routes\",\n]);\nconst CONTROL_OTHER_LABEL = \"/__aimock/{other}\";\n\n/**\n * Sub-paths a mounted service (`createServer(..., mounts)`) answers below its\n * mount root. The mount roots themselves are runtime configuration, so the\n * caller passes them in; the JSON-RPC handlers (MCP, A2A, AG-UI, vector) take\n * the root only, and A2A additionally serves its agent card.\n */\nconst MOUNT_SUBPATHS = new Set([\"/.well-known/agent-card.json\"]);\n\n/**\n * Status label for a response that was destroyed before its body ended: no\n * status line reached the client as a completed response, so no HTTP code\n * describes the outcome truthfully. Distinct from every numeric status so\n * `sum(aimock_requests_total)` equals requests served.\n */\nexport const DESTROYED_STATUS_LABEL = \"destroyed\";\n\n/**\n * Fine-tuning routes. Both id families (`ftjob-…` per create, `ftckpt-…` per\n * checkpoint) are minted per resource, so every id-bearing path has to collapse\n * or each job and each checkpoint mints its own label pair.\n *\n * The label hazard is NOT limited to the routes this server implements: metrics\n * are recorded on `res.on(\"finish\")` for EVERY response, the generic 404\n * included, and `openai@4.104.0` calls a good deal more of the namespace than\n * aimock handles. Enumerated from that SDK:\n *\n * - `resources/fine-tuning/jobs/jobs.js` — `/fine_tuning/jobs`,\n * `…/jobs/{id}`, `…/jobs/{id}/cancel`, `…/jobs/{id}/pause`,\n * `…/jobs/{id}/resume`\n * - `resources/fine-tuning/jobs/checkpoints.js` — `…/jobs/{id}/checkpoints`\n * - `resources/fine-tuning/checkpoints/permissions.js` —\n * `…/checkpoints/{ckpt}/permissions` (create/list) and\n * `…/checkpoints/{ckpt}/permissions/{id}` (delete)\n * - `resources/fine-tuning/alpha/graders.js` —\n * `/fine_tuning/alpha/graders/run`, `/fine_tuning/alpha/graders/validate`\n *\n * The grader routes carry no ids, so they need no placeholder — but they DO\n * need naming here, because the namespace cascade below ends in a catch-all\n * and a static route must not be swallowed by it.\n *\n * Every segment after `/v1/fine_tuning/` is caller-controlled, so the rule is:\n * known action names are kept verbatim, ids collapse to `{id}`/`{ckpt}`, and\n * anything else — an unknown action, an unknown depth — collapses to a single\n * bucket. That is what actually keeps the fine-tuning label set finite no\n * matter what is requested; an un-collapsed tail would leave the hole open to\n * a typo or a fuzzer.\n *\n * Not exported: server.ts dispatches fine-tuning jobs from the same\n * route-registry.ts bindings (`FINE_TUNING_JOBS_PATH`, `FINE_TUNING_ID_RE`,\n * `FINE_TUNING_CANCEL_RE`, `FINE_TUNING_EVENTS_RE`).\n */\nconst FINE_TUNING_PREFIX = \"/v1/fine_tuning/\";\nconst FINE_TUNING_STATIC_PATHS = new Set([\n \"/v1/fine_tuning/jobs\",\n \"/v1/fine_tuning/alpha/graders/run\",\n \"/v1/fine_tuning/alpha/graders/validate\",\n]);\nconst FINE_TUNING_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/jobs\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_SUBRESOURCES = new Set([\"cancel\", \"events\", \"pause\", \"resume\", \"checkpoints\"]);\nconst FINE_TUNING_PERMISSION_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/permissions\\/[^/]+$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCES = new Set([\"permissions\"]);\nconst FINE_TUNING_CHECKPOINT_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/([^/]+)$/;\nconst FINE_TUNING_OTHER_LABEL = \"/v1/fine_tuning/{other}\";\n\n/**\n * Normalize parametric API paths to route patterns for use as metric labels.\n * Replaces dynamic segments (model IDs, deployment names, etc.) with placeholders.\n * `mountPaths` are the roots of the mounted services, so their traffic keeps a\n * bounded label instead of collapsing to `{unknown}`.\n */\nexport function normalizePathLabel(pathname: string, mountPaths: readonly string[] = []): string {\n // Match server dispatch precedence: controls, mounts in registration order,\n // then provider routes. A mount may overlap any provider namespace.\n // Control API: exact sub-paths verbatim, anything else under the prefix\n // collapses.\n if (pathname.startsWith(CONTROL_PREFIX)) {\n return CONTROL_PATHS.has(pathname) ? pathname : CONTROL_OTHER_LABEL;\n }\n\n // Mounted services: the root and the known sub-paths verbatim, anything\n // deeper collapses under the mount.\n for (const mountPath of mountPaths) {\n if (pathname === mountPath) return pathname;\n if (pathname.startsWith(mountPath + \"/\")) {\n return MOUNT_SUBPATHS.has(pathname.slice(mountPath.length))\n ? pathname\n : `${mountPath}/{other}`;\n }\n }\n\n if (MODELS_DETAIL_RE.test(pathname)) return \"/v1/models/{id}\";\n if (pathname === GEMINI_MODELS_PATH) return GEMINI_MODELS_PATH;\n\n // Bedrock: /model/{modelId}/{operation}\n const bedrockMatch = pathname.match(BEDROCK_RE);\n if (bedrockMatch) {\n return `/model/{modelId}/${bedrockMatch[2]}`;\n }\n\n // Gemini: /v1beta/models/{model}:{action}, plus the bare GET model lookup.\n const geminiMatch = pathname.match(GEMINI_RE);\n if (geminiMatch) {\n const action = GEMINI_ACTIONS.has(geminiMatch[2]) ? geminiMatch[2] : \"{action}\";\n return `/v1beta/models/{model}:${action}`;\n }\n if (GEMINI_MODEL_DETAIL_RE.test(pathname) || GEMINI_MODEL_LABEL_RE.test(pathname)) {\n return \"/v1beta/models/{model}\";\n }\n\n // Azure: /openai/deployments/{id}/{operation}\n const azureMatch = pathname.match(AZURE_RE);\n if (azureMatch) {\n return `/openai/deployments/{id}/${azureMatch[2]}`;\n }\n\n // Vertex AI: /v1/projects/{p}/locations/{l}/publishers/google/models/{m}:{action}\n const vertexMatch = pathname.match(VERTEX_RE);\n if (vertexMatch) {\n const action = VERTEX_ACTIONS.has(vertexMatch[4]) ? vertexMatch[4] : \"{action}\";\n return `/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:${action}`;\n }\n\n // ElevenLabs TTS: /v1/text-to-speech/{voice_id}\n if (ELEVENLABS_TTS_RE.test(pathname)) {\n return \"/v1/text-to-speech/{voice_id}\";\n }\n\n // ElevenLabs voices: /v1/voices/{voice_id}\n if (ELEVENLABS_VOICE_RE.test(pathname)) {\n return \"/v1/voices/{voice_id}\";\n }\n\n // OpenRouter video: /api/v1/videos/{jobId}[/content] — jobIds are random\n // UUIDs, so raw paths would mint unbounded label cardinality. The static\n // /api/v1/videos/models listing route must not collapse into {jobId}.\n if (OPENROUTER_VIDEO_CONTENT_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}/content\";\n }\n if (pathname !== \"/api/v1/videos/models\" && OPENROUTER_VIDEO_STATUS_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}\";\n }\n\n // Google Veo video: submit `:predictLongRunning` + poll `/v1beta/operations/{name}`.\n // Operation names are random UUIDs, so the raw path would mint unbounded\n // label cardinality.\n if (VEO_PREDICT_LRO_RE.test(pathname)) {\n return \"/v1beta/models/{model}:predictLongRunning\";\n }\n if (VEO_OPERATION_RE.test(pathname)) {\n return \"/v1beta/operations/{name}\";\n }\n\n // xAI Grok Imagine submit is a static literal path — keep it distinct from\n // the `/v1/videos/{id}` status label below (which it would otherwise collapse\n // into), exactly as `/api/v1/videos/models` is kept out of the jobId bucket.\n if (pathname === GROK_VIDEO_SUBMIT_PATH) {\n return GROK_VIDEO_SUBMIT_PATH;\n }\n\n // OpenAI/Grok video status: /v1/videos/{id}\n if (OPENAI_VIDEO_STATUS_RE.test(pathname)) {\n return \"/v1/videos/{id}\";\n }\n\n // BytePlus Ark video: /[api/v3/]contents/generations/tasks[/{id}] — task ids\n // (`cgt-…`) are unbounded cardinality. Status before submit: the status RE is\n // the more specific of the two and the submit RE cannot match a trailing id\n // segment, so the order is belt-and-braces. Appended at the end of the\n // cascade because the anchored REs above cannot match any path an earlier\n // entry claims.\n if (BYTEPLUS_VIDEO_STATUS_RE.test(pathname)) {\n return \"/contents/generations/tasks/{id}\";\n }\n if (BYTEPLUS_VIDEO_SUBMIT_RE.test(pathname)) {\n return \"/contents/generations/tasks\";\n }\n\n if (BATCHES_CANCEL_RE.test(pathname)) {\n return \"/v1/batches/{id}/cancel\";\n }\n if (pathname !== \"/v1/batches\" && BATCHES_ID_RE.test(pathname)) {\n return \"/v1/batches/{id}\";\n }\n if (pathname.startsWith(BATCHES_PREFIX)) {\n return BATCHES_OTHER_LABEL;\n }\n\n // Files API: /v1/files/{id} and /v1/files/{id}/content carry random\n // `file-…` ids — raw paths would mint unbounded label cardinality.\n // Content before id: the id RE would otherwise swallow the content suffix.\n if (FILES_CONTENT_RE.test(pathname)) {\n return \"/v1/files/{id}/content\";\n }\n if (pathname !== \"/v1/files\" && FILES_ID_RE.test(pathname)) {\n return \"/v1/files/{id}\";\n }\n if (pathname.startsWith(FILES_PREFIX)) {\n return FILES_OTHER_LABEL;\n }\n\n // Vector Stores: /v1/vector_stores/{id}[/files[/{fileId}]|/file_batches…|/search].\n // Most-specific first so the id RE cannot swallow a sub-resource suffix.\n if (VECTOR_STORES_SEARCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/search\";\n }\n if (VECTOR_STORES_BATCH_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/files\";\n }\n if (VECTOR_STORES_BATCH_CANCEL_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/cancel\";\n }\n if (VECTOR_STORES_BATCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}\";\n }\n if (VECTOR_STORES_FILE_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files/{fileId}\";\n }\n if (VECTOR_STORES_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files\";\n }\n if (VECTOR_STORES_FILE_BATCHES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches\";\n }\n if (pathname !== \"/v1/vector_stores\" && VECTOR_STORES_ID_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}\";\n }\n if (pathname.startsWith(VECTOR_STORES_PREFIX)) {\n return VECTOR_STORES_OTHER_LABEL;\n }\n\n // fal.ai: see the namespace note above. Queue-request rules read before the\n // path-mirror rule because `/fal/queue/requests/…` also matches the mirror\n // RE's `.+/requests/` shape; both would label correctly, but the specific\n // rule reading first keeps the cascade legible.\n if (FAL_ROUTE_RE.test(pathname)) {\n const queueRequest = pathname.match(FAL_QUEUE_REQUEST_RE);\n if (queueRequest) {\n return `/fal/queue/requests/{id}${falRequestSuffix(queueRequest[1])}`;\n }\n if (FAL_QUEUE_SUBMIT_RE.test(pathname)) return \"/fal/queue/submit/{model}\";\n if (FAL_RUN_RE.test(pathname)) return \"/fal/run/{model}\";\n const mirrorRequest = pathname.match(FAL_MIRROR_REQUEST_RE);\n if (mirrorRequest) {\n return `/fal/{model}/requests/{id}${falRequestSuffix(mirrorRequest[1])}`;\n }\n return FAL_OTHER_LABEL;\n }\n\n // ElevenLabs Music: known actions verbatim, anything else collapses.\n if (pathname.startsWith(MUSIC_PREFIX)) {\n return MUSIC_ACTIONS.has(pathname.slice(MUSIC_PREFIX.length)) ? pathname : MUSIC_OTHER_LABEL;\n }\n\n // Fine-tuning. Handled as one closed namespace rather than a few loose REs:\n // the cascade is entered by prefix and always returns, so no fine-tuning path\n // can reach the verbatim return at the bottom of this function.\n //\n // Order matters twice. The id-bearing permission rule reads before the\n // checkpoint sub-resource rule, because `…/permissions/{id}` would otherwise\n // never be reached (its own second segment is the id). Within each family the\n // sub-resource rule reads before the id rule; the id REs are anchored to a\n // single trailing segment so the two cannot both match, but the more specific\n // path reading first is what makes the cascade legible.\n if (pathname.startsWith(FINE_TUNING_PREFIX)) {\n if (FINE_TUNING_STATIC_PATHS.has(pathname)) return pathname;\n\n const ftSubresource = pathname.match(FINE_TUNING_SUBRESOURCE_RE);\n if (ftSubresource) {\n const action = FINE_TUNING_SUBRESOURCES.has(ftSubresource[1]) ? ftSubresource[1] : \"{action}\";\n return `/v1/fine_tuning/jobs/{id}/${action}`;\n }\n if (FINE_TUNING_ID_RE.test(pathname)) return \"/v1/fine_tuning/jobs/{id}\";\n\n if (FINE_TUNING_PERMISSION_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}/permissions/{id}\";\n }\n const ckptSubresource = pathname.match(FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE);\n if (ckptSubresource) {\n const action = FINE_TUNING_CHECKPOINT_SUBRESOURCES.has(ckptSubresource[1])\n ? ckptSubresource[1]\n : \"{action}\";\n return `/v1/fine_tuning/checkpoints/{ckpt}/${action}`;\n }\n if (FINE_TUNING_CHECKPOINT_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}\";\n }\n\n return FINE_TUNING_OTHER_LABEL;\n }\n\n // Static path — verbatim only if server.ts routes it. Anything else is, as\n // far as metrics can tell, caller-controlled text, whatever status it got\n // (404, a 204 preflight, a destroyed response); every routed id path that\n // can legitimately 404 has already returned its placeholder label above.\n return STATIC_ROUTE_PATHS.has(pathname) ? pathname : UNKNOWN_PATH_LABEL;\n}\n\nfunction falRequestSuffix(sub: string | undefined): string {\n if (sub === undefined) return \"\";\n return FAL_REQUEST_SUBRESOURCES.has(sub) ? `/${sub}` : \"/{other}\";\n}\n"],"mappings":";;;;;;;;;AAiFA,MAAM,oBAAoB;CAAC;CAAO;CAAM;CAAO;CAAM;CAAK;CAAM;CAAK;CAAG;CAAK;CAAG;CAAG;;AAOnF,SAAS,SAAS,QAAwC;CACxD,MAAM,UAAU,OAAO,QAAQ,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC;AAC7E,KAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,QAAO,QAAQ,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,IAAI,iBAAiB,EAAE,CAAC,GAAG,CAAC,KAAK,IAAI;;;AAI3E,SAAS,iBAAiB,GAAmB;AAC3C,QAAO,EAAE,QAAQ,OAAO,OAAO,CAAC,QAAQ,MAAM,OAAM,CAAC,QAAQ,OAAO,MAAM;;;AAI5E,SAAS,aAAa,QAAwC;AAC5D,QAAO,IAAI,SAAS,OAAO,CAAC;;AAuC9B,SAAgB,wBAAyC;;CAEvD,MAAM,0BAAU,IAAI,KAAyB;CAE7C,SAAS,mBAAmB,MAA2B;EACrD,IAAI,OAAO,QAAQ,IAAI,KAAK;AAC5B,MAAI,CAAC,MAAM;AACT,UAAO;IAAE,MAAM;IAAW,wBAAQ,IAAI,KAAK;IAAE;AAC7C,WAAQ,IAAI,MAAM,KAAK;;AAEzB,MAAI,KAAK,SAAS,UAAW,OAAM,IAAI,MAAM,UAAU,KAAK,mBAAmB;AAC/E,SAAO;;CAGT,SAAS,qBAAqB,MAA6B;E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AErE,MAAI,oBAAoB,KAAK,SAAS,CAAE,QAAO;AAC/C,MAAI,WAAW,KAAK,SAAS,CAAE,QAAO;EACtC,MAAM,gBAAgB,SAAS,MAAM,sBAAsB;AAC3D,MAAI,cACF,QAAO,6BAA6B,iBAAiB,cAAc,GAAG;AAExE,SAAO;;AAIT,KAAI,SAAS,WAAW,aAAa,CACnC,QAAO,cAAc,IAAI,SAAS,MAAM,GAAoB,CAAC,GAAG,WAAW;AAa7E,KAAI,SAAS,WAAW,mBAAmB,EAAE;AAC3C,MAAI,yBAAyB,IAAI,SAAS,CAAE,QAAO;EAEnD,MAAM,gBAAgB,SAAS,MAAM,2BAA2B;AAChE,MAAI,cAEF,QAAO,6BADQ,yBAAyB,IAAI,cAAc,GAAG,GAAG,cAAc,KAAK;AAGrF,MAAIC,yCAAkB,KAAK,SAAS,CAAE,QAAO;AAE7C,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;EAET,MAAM,kBAAkB,SAAS,MAAM,sCAAsC;AAC7E,MAAI,gBAIF,QAAO,sCAHQ,oCAAoC,IAAI,gBAAgB,GAAG,GACtE,gBAAgB,KAChB;AAGN,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;AAGT,SAAO;;AAOT,QAAO,mBAAmB,IAAI,SAAS,GAAG,WAAW;;AAGvD,SAAS,iBAAiB,KAAiC;AACzD,KAAI,QAAQ,OAAW,QAAO;AAC9B,QAAO,yBAAyB,IAAI,IAAI,GAAG,IAAI,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.cts","names":[],"sources":["../src/metrics.ts"],"sourcesContent":[],"mappings":";;AAsfgB,UApbC,eAAA,CAobiB;yCAnbO;yCACA;iCACR;;;;iBAoEjB,qBAAA,CAAA,GAAyB;;;;;;;;;;;;;;;;;;;;iBA6WzB,kBAAA"}
1
+ {"version":3,"file":"metrics.d.cts","names":[],"sources":["../src/metrics.ts"],"sourcesContent":[],"mappings":";;AA2fgB,UAtbC,eAAA,CAsbiB;yCArbO;yCACA;iCACR;;;;iBAoEjB,qBAAA,CAAA,GAAyB;;;;;;;;;;;;;;;;;;;;iBA+WzB,kBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.d.ts","names":[],"sources":["../src/metrics.ts"],"sourcesContent":[],"mappings":";;AAsfgB,UApbC,eAAA,CAobiB;yCAnbO;yCACA;iCACR;;;;iBAoEjB,qBAAA,CAAA,GAAyB;;;;;;;;;;;;;;;;;;;;iBA6WzB,kBAAA"}
1
+ {"version":3,"file":"metrics.d.ts","names":[],"sources":["../src/metrics.ts"],"sourcesContent":[],"mappings":";;AA2fgB,UAtbC,eAAA,CAsbiB;yCArbO;yCACA;iCACR;;;;iBAoEjB,qBAAA,CAAA,GAAyB;;;;;;;;;;;;;;;;;;;;iBA+WzB,kBAAA"}
package/dist/metrics.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AZURE_DEPLOYMENT_RE, BATCHES_CANCEL_RE, BATCHES_ID_RE, BYTEPLUS_VIDEO_STATUS_RE, BYTEPLUS_VIDEO_SUBMIT_RE, ELEVENLABS_TTS_RE, ELEVENLABS_VOICE_RE, FAL_ROUTE_RE, FILES_CONTENT_RE, FILES_ID_RE, FINE_TUNING_ID_RE, GROK_VIDEO_STATUS_RE, GROK_VIDEO_SUBMIT_PATH, OPENAI_VIDEO_STATUS_RE, OPENROUTER_VIDEO_CONTENT_RE, OPENROUTER_VIDEO_STATUS_RE, VECTOR_STORES_BATCH_CANCEL_RE, VECTOR_STORES_BATCH_FILES_RE, VECTOR_STORES_BATCH_RE, VECTOR_STORES_FILES_RE, VECTOR_STORES_FILE_BATCHES_RE, VECTOR_STORES_FILE_RE, VECTOR_STORES_ID_RE, VECTOR_STORES_SEARCH_RE, VEO_OPERATION_RE, VEO_PREDICT_LRO_RE } from "./route-registry.js";
1
+ import { AZURE_DEPLOYMENT_RE, BATCHES_CANCEL_RE, BATCHES_ID_RE, BYTEPLUS_VIDEO_STATUS_RE, BYTEPLUS_VIDEO_SUBMIT_RE, ELEVENLABS_TTS_RE, ELEVENLABS_VOICE_RE, FAL_ROUTE_RE, FILES_CONTENT_RE, FILES_ID_RE, FINE_TUNING_ID_RE, GEMINI_MODELS_PATH, GEMINI_MODEL_DETAIL_RE, GROK_VIDEO_STATUS_RE, GROK_VIDEO_SUBMIT_PATH, MODELS_DETAIL_RE, OPENAI_VIDEO_STATUS_RE, OPENROUTER_VIDEO_CONTENT_RE, OPENROUTER_VIDEO_STATUS_RE, VECTOR_STORES_BATCH_CANCEL_RE, VECTOR_STORES_BATCH_FILES_RE, VECTOR_STORES_BATCH_RE, VECTOR_STORES_FILES_RE, VECTOR_STORES_FILE_BATCHES_RE, VECTOR_STORES_FILE_RE, VECTOR_STORES_ID_RE, VECTOR_STORES_SEARCH_RE, VEO_OPERATION_RE, VEO_PREDICT_LRO_RE } from "./route-registry.js";
2
2
 
3
3
  //#region src/metrics.ts
4
4
  /**
@@ -144,6 +144,7 @@ function createMetricsRegistry() {
144
144
  const BEDROCK_RE = /^\/model\/([^/]+)\/(invoke|invoke-with-response-stream|converse|converse-stream)$/;
145
145
  const VERTEX_RE = /^\/v1\/projects\/([^/]+)\/locations\/([^/]+)\/publishers\/google\/models\/([^:]+):(.+)$/;
146
146
  const GEMINI_RE = /^\/v1beta\/models\/([^:]+):([^/]+)$/;
147
+ const GEMINI_MODEL_LABEL_RE = /^\/v1beta\/models\/([^:/]+)$/;
147
148
  const GEMINI_ACTIONS = new Set([
148
149
  "generateContent",
149
150
  "streamGenerateContent",
@@ -153,7 +154,6 @@ const GEMINI_ACTIONS = new Set([
153
154
  "predict",
154
155
  "predictLongRunning"
155
156
  ]);
156
- const GEMINI_MODEL_RE = /^\/v1beta\/models\/([^:/]+)$/;
157
157
  const VERTEX_ACTIONS = new Set(["generateContent", "streamGenerateContent"]);
158
158
  /**
159
159
  * Closed namespaces beyond fine-tuning. Each prefix below is entered by prefix
@@ -233,6 +233,7 @@ const STATIC_ROUTE_PATHS = new Set([
233
233
  "/v1/responses",
234
234
  "/v1/realtime",
235
235
  "/v1/messages",
236
+ "/v1/messages/count_tokens",
236
237
  "/v1/embeddings",
237
238
  "/v1/moderations",
238
239
  "/v1/models",
@@ -365,11 +366,13 @@ function normalizePathLabel(pathname, mountPaths = []) {
365
366
  if (pathname === mountPath) return pathname;
366
367
  if (pathname.startsWith(mountPath + "/")) return MOUNT_SUBPATHS.has(pathname.slice(mountPath.length)) ? pathname : `${mountPath}/{other}`;
367
368
  }
369
+ if (MODELS_DETAIL_RE.test(pathname)) return "/v1/models/{id}";
370
+ if (pathname === GEMINI_MODELS_PATH) return GEMINI_MODELS_PATH;
368
371
  const bedrockMatch = pathname.match(BEDROCK_RE);
369
372
  if (bedrockMatch) return `/model/{modelId}/${bedrockMatch[2]}`;
370
373
  const geminiMatch = pathname.match(GEMINI_RE);
371
374
  if (geminiMatch) return `/v1beta/models/{model}:${GEMINI_ACTIONS.has(geminiMatch[2]) ? geminiMatch[2] : "{action}"}`;
372
- if (GEMINI_MODEL_RE.test(pathname)) return "/v1beta/models/{model}";
375
+ if (GEMINI_MODEL_DETAIL_RE.test(pathname) || GEMINI_MODEL_LABEL_RE.test(pathname)) return "/v1beta/models/{model}";
373
376
  const azureMatch = pathname.match(AZURE_DEPLOYMENT_RE);
374
377
  if (azureMatch) return `/openai/deployments/{id}/${azureMatch[2]}`;
375
378
  const vertexMatch = pathname.match(VERTEX_RE);
@@ -1 +1 @@
1
- {"version":3,"file":"metrics.js","names":["AZURE_RE"],"sources":["../src/metrics.ts"],"sourcesContent":["/**\n * Lightweight Prometheus metrics registry for LLMock.\n *\n * Zero external dependencies — implements counters, histograms, and gauges\n * with Prometheus text exposition format serialization.\n */\n\nimport {\n AZURE_DEPLOYMENT_RE as AZURE_RE,\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n ELEVENLABS_TTS_RE,\n ELEVENLABS_VOICE_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n FINE_TUNING_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILES_RE,\n VECTOR_STORES_FILE_BATCHES_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n} from \"./route-registry.js\";\n\n// Re-exported so existing importers (route tests) keep resolving these\n// against the metrics module. The bindings ARE the registry's — there is\n// exactly one pattern object per route family.\nexport {\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n};\n\n// ---------------------------------------------------------------------------\n// Public interface\n// ---------------------------------------------------------------------------\n\nexport interface MetricsRegistry {\n incrementCounter(name: string, labels: Record<string, string>): void;\n observeHistogram(name: string, labels: Record<string, string>, value: number): void;\n setGauge(name: string, labels: Record<string, string>, value: number): void;\n serialize(): string;\n reset(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Histogram bucket boundaries (Prometheus default-ish)\n// ---------------------------------------------------------------------------\n\nconst HISTOGRAM_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10];\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/** Build a stable label key string for map lookups: `label1=\"v1\",label2=\"v2\"` */\nfunction labelKey(labels: Record<string, string>): string {\n const entries = Object.entries(labels).sort(([a], [b]) => a.localeCompare(b));\n if (entries.length === 0) return \"\";\n return entries.map(([k, v]) => `${k}=\"${escapeLabelValue(v)}\"`).join(\",\");\n}\n\n/** Escape a label value per Prometheus text exposition format. */\nfunction escapeLabelValue(v: string): string {\n return v.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"').replace(/\\n/g, \"\\\\n\");\n}\n\n/** Format labels for Prometheus output: `{label1=\"v1\",label2=\"v2\"}` */\nfunction formatLabels(labels: Record<string, string>): string {\n return `{${labelKey(labels)}}`;\n}\n\n// ---------------------------------------------------------------------------\n// Internal metric storage types\n// ---------------------------------------------------------------------------\n\ninterface CounterData {\n type: \"counter\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ninterface HistogramData {\n type: \"histogram\";\n /** Map from labelKey → bucket counts, sum, count */\n series: Map<\n string,\n {\n labels: Record<string, string>;\n bucketCounts: number[]; // one per HISTOGRAM_BUCKETS entry\n sum: number;\n count: number;\n }\n >;\n}\n\ninterface GaugeData {\n type: \"gauge\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ntype MetricData = CounterData | HistogramData | GaugeData;\n\n// ---------------------------------------------------------------------------\n// Registry implementation\n// ---------------------------------------------------------------------------\n\nexport function createMetricsRegistry(): MetricsRegistry {\n /** Ordered map: metric name → data. Insertion order preserved for stable output. */\n const metrics = new Map<string, MetricData>();\n\n function getOrCreateCounter(name: string): CounterData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"counter\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"counter\") throw new Error(`Metric ${name} is not a counter`);\n return data as CounterData;\n }\n\n function getOrCreateHistogram(name: string): HistogramData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"histogram\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"histogram\") throw new Error(`Metric ${name} is not a histogram`);\n return data as HistogramData;\n }\n\n function getOrCreateGauge(name: string): GaugeData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"gauge\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"gauge\") throw new Error(`Metric ${name} is not a gauge`);\n return data as GaugeData;\n }\n\n return {\n incrementCounter(name: string, labels: Record<string, string>): void {\n const counter = getOrCreateCounter(name);\n const key = labelKey(labels);\n const existing = counter.series.get(key);\n if (existing) {\n existing.value += 1;\n } else {\n counter.series.set(key, { labels, value: 1 });\n }\n },\n\n observeHistogram(name: string, labels: Record<string, string>, value: number): void {\n const histogram = getOrCreateHistogram(name);\n const key = labelKey(labels);\n let existing = histogram.series.get(key);\n if (!existing) {\n existing = {\n labels,\n bucketCounts: new Array(HISTOGRAM_BUCKETS.length).fill(0) as number[],\n sum: 0,\n count: 0,\n };\n histogram.series.set(key, existing);\n }\n // Update cumulative bucket counts\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n if (value <= HISTOGRAM_BUCKETS[i]) {\n existing.bucketCounts[i] += 1;\n }\n }\n existing.sum += value;\n existing.count += 1;\n },\n\n setGauge(name: string, labels: Record<string, string>, value: number): void {\n const gauge = getOrCreateGauge(name);\n const key = labelKey(labels);\n const existing = gauge.series.get(key);\n if (existing) {\n existing.value = value;\n } else {\n gauge.series.set(key, { labels, value });\n }\n },\n\n serialize(): string {\n const lines: string[] = [];\n\n for (const [name, data] of metrics) {\n switch (data.type) {\n case \"counter\": {\n lines.push(`# TYPE ${name} counter`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n case \"histogram\": {\n lines.push(`# TYPE ${name} histogram`);\n for (const series of data.series.values()) {\n const lblStr = labelKey(series.labels);\n const lblPrefix = lblStr ? `${lblStr},` : \"\";\n // Bucket lines\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n lines.push(\n `${name}_bucket{${lblPrefix}le=\"${HISTOGRAM_BUCKETS[i]}\"} ${series.bucketCounts[i]}`,\n );\n }\n // +Inf bucket\n lines.push(`${name}_bucket{${lblPrefix}le=\"+Inf\"} ${series.count}`);\n // Sum and count\n lines.push(`${name}_sum${formatLabels(series.labels)} ${series.sum}`);\n lines.push(`${name}_count${formatLabels(series.labels)} ${series.count}`);\n }\n break;\n }\n case \"gauge\": {\n lines.push(`# TYPE ${name} gauge`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n }\n }\n\n return lines.length > 0 ? lines.join(\"\\n\") + \"\\n\" : \"\";\n },\n\n reset(): void {\n metrics.clear();\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Path normalization for metric labels\n// ---------------------------------------------------------------------------\n\n// Regex patterns for parametric API routes. The dispatch+labeling patterns\n// shared with server.ts dispatch and the machine-readable catalog are defined\n// in route-registry.ts (single source of truth) and imported above; only\n// labeling-specific patterns are declared here: the Bedrock union, the Looser\n// Vertex shape, the widened Gemini action bucket (+ its allowlists), and the\n// served-or-not namespace cascades below.\nconst BEDROCK_RE =\n /^\\/model\\/([^/]+)\\/(invoke|invoke-with-response-stream|converse|converse-stream)$/;\nconst VERTEX_RE =\n /^\\/v1\\/projects\\/([^/]+)\\/locations\\/([^/]+)\\/publishers\\/google\\/models\\/([^:]+):(.+)$/;\n// Gemini `/v1beta/models/{model}:{action}`. The action segment is caller\n// controlled, so only the actions the server routes stay verbatim; anything\n// else collapses to `{action}`. `predictLongRunning` is listed so the Veo\n// submit label below stays byte-identical to what it was before this RE\n// widened past generate/streamGenerate — the two rules must agree.\nconst GEMINI_RE = /^\\/v1beta\\/models\\/([^:]+):([^/]+)$/;\nconst GEMINI_ACTIONS = new Set([\n \"generateContent\",\n \"streamGenerateContent\",\n \"embedContent\",\n \"batchEmbedContents\",\n \"countTokens\",\n \"predict\",\n \"predictLongRunning\",\n]);\nconst GEMINI_MODEL_RE = /^\\/v1beta\\/models\\/([^:/]+)$/;\n// The Vertex `:action` segment is caller controlled exactly as Gemini's is;\n// server.ts routes only these two, so anything else collapses to `{action}`.\nconst VERTEX_ACTIONS = new Set([\"generateContent\", \"streamGenerateContent\"]);\n\n/**\n * Closed namespaces beyond fine-tuning. Each prefix below is entered by prefix\n * and always returns, so no id-bearing or unknown-depth path under it can\n * reach the verbatim return at the bottom of `normalizePathLabel`:\n *\n * - fal: `/fal/queue/requests/{id}[/status|/cancel|/stream]` (aimock's own\n * queue layout), `/fal/{model}/requests/{id}[/…]` (the `x-fal-target-host`\n * path-mirror of `queue.fal.run`), `/fal/queue/submit/{model}`,\n * `/fal/run/{model}`. Request ids are minted per submit and model ids are\n * caller-controlled multi-segment paths, so both collapse.\n * - music: `/v1/music/{generation|variation|remix|extend|plan|detailed|stream}`\n * are the ElevenLabs routes (`plan`/`stream` take their own response shape\n * in elevenlabs-audio.ts); the server RE accepts any suffix, so an unknown\n * one collapses.\n * - files / batches: the id and sub-resource rules above cover the routed\n * shapes; any other depth collapses to the namespace's `{other}`.\n */\n/**\n * The fal.ai route shape (`FAL_ROUTE_RE`, imported from route-registry.ts so\n * the label rule cannot drift from the route rule): a bare `/fal` is routed,\n * so it is labelled here rather than falling through to `{unknown}`.\n */\nconst FAL_QUEUE_REQUEST_RE = /^\\/fal\\/queue\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_MIRROR_REQUEST_RE = /^\\/fal\\/.+\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_REQUEST_SUBRESOURCES = new Set([\"status\", \"cancel\", \"stream\"]);\nconst FAL_QUEUE_SUBMIT_RE = /^\\/fal\\/queue\\/submit\\/.+$/;\nconst FAL_RUN_RE = /^\\/fal\\/run\\/.+$/;\nconst FAL_OTHER_LABEL = \"/fal/{other}\";\nconst MUSIC_PREFIX = \"/v1/music/\";\nconst MUSIC_ACTIONS = new Set([\n \"generation\",\n \"variation\",\n \"remix\",\n \"extend\",\n \"plan\",\n \"detailed\",\n \"stream\",\n]);\nconst MUSIC_OTHER_LABEL = \"/v1/music/{other}\";\nconst FILES_PREFIX = \"/v1/files/\";\nconst FILES_OTHER_LABEL = \"/v1/files/{other}\";\nconst BATCHES_PREFIX = \"/v1/batches/\";\nconst BATCHES_OTHER_LABEL = \"/v1/batches/{other}\";\nconst VECTOR_STORES_PREFIX = \"/v1/vector_stores/\";\nconst VECTOR_STORES_OTHER_LABEL = \"/v1/vector_stores/{other}\";\n\n/**\n * Label for a path no route claimed. Metrics are recorded for EVERY response,\n * the generic 404 included, so an unrouted path is caller-controlled text and\n * a fuzzer (or a typo'd SDK base URL) would mint one label per request.\n *\n * The collapse is decided by ROUTE SHAPE, never by status: a 404 is not the\n * only way an unrouted path gets answered (a CORS preflight is 204 for any\n * path, a torn-down response has no status at all), and a routed path can\n * legitimately 404 (a fixture miss, a missing file) without becoming\n * unknown. Every path that is not claimed by a placeholder rule above must\n * therefore be listed here to keep its verbatim label.\n */\nexport const UNKNOWN_PATH_LABEL = \"{unknown}\";\n\n/**\n * Static paths server.ts dispatches by exact match (after\n * `normalizeCompatPath`, so the canonical `/v1/...` spelling). A path absent\n * from this table that no placeholder rule claims is labelled `{unknown}`\n * whatever its status — so a new static route needs an entry here or its\n * traffic is counted but not named.\n */\nconst STATIC_ROUTE_PATHS = new Set([\n \"/health\",\n \"/ready\",\n \"/metrics\",\n \"/search\",\n \"/v1/chat/completions\",\n \"/v1/responses\",\n \"/v1/realtime\",\n \"/v1/messages\",\n \"/v1/embeddings\",\n \"/v1/moderations\",\n \"/v1/models\",\n \"/v1/_requests\",\n \"/v1/images/generations\",\n \"/v1/images/edits\",\n \"/v1/images/variations\",\n \"/v1/audio/speech\",\n \"/v1/audio/transcriptions\",\n \"/v1/audio/translations\",\n \"/v1/videos\",\n \"/v1/batches\",\n \"/v1/files\",\n \"/v1/vector_stores\",\n \"/v1/sound-generation\",\n \"/v1/music\",\n \"/v1/text-to-voice\",\n \"/v1/text-to-voice/design\",\n \"/v1beta/interactions\",\n \"/v2/chat\",\n \"/v2/embed\",\n \"/v2/rerank\",\n \"/api/chat\",\n \"/api/generate\",\n \"/api/embeddings\",\n \"/api/embed\",\n \"/api/tags\",\n \"/api/v1/videos\",\n \"/api/v1/videos/models\",\n \"/api/v1/credits\",\n \"/api/v1/key\",\n \"/api/v1/models\",\n \"/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent\",\n]);\n\n/**\n * Control API (`/__aimock/...`): a closed set of sub-paths, matched exactly\n * in `handleControlAPI`; anything else under the prefix collapses.\n */\nconst CONTROL_PREFIX = \"/__aimock/\";\nconst CONTROL_PATHS = new Set([\n \"/__aimock/health\",\n \"/__aimock/journal\",\n \"/__aimock/fixtures\",\n \"/__aimock/chaos\",\n \"/__aimock/reset\",\n \"/__aimock/reset/journal\",\n \"/__aimock/reset/fixtures\",\n \"/__aimock/error\",\n \"/__aimock/openapi.json\",\n \"/__aimock/routes\",\n]);\nconst CONTROL_OTHER_LABEL = \"/__aimock/{other}\";\n\n/**\n * Sub-paths a mounted service (`createServer(..., mounts)`) answers below its\n * mount root. The mount roots themselves are runtime configuration, so the\n * caller passes them in; the JSON-RPC handlers (MCP, A2A, AG-UI, vector) take\n * the root only, and A2A additionally serves its agent card.\n */\nconst MOUNT_SUBPATHS = new Set([\"/.well-known/agent-card.json\"]);\n\n/**\n * Status label for a response that was destroyed before its body ended: no\n * status line reached the client as a completed response, so no HTTP code\n * describes the outcome truthfully. Distinct from every numeric status so\n * `sum(aimock_requests_total)` equals requests served.\n */\nexport const DESTROYED_STATUS_LABEL = \"destroyed\";\n\n/**\n * Fine-tuning routes. Both id families (`ftjob-…` per create, `ftckpt-…` per\n * checkpoint) are minted per resource, so every id-bearing path has to collapse\n * or each job and each checkpoint mints its own label pair.\n *\n * The label hazard is NOT limited to the routes this server implements: metrics\n * are recorded on `res.on(\"finish\")` for EVERY response, the generic 404\n * included, and `openai@4.104.0` calls a good deal more of the namespace than\n * aimock handles. Enumerated from that SDK:\n *\n * - `resources/fine-tuning/jobs/jobs.js` — `/fine_tuning/jobs`,\n * `…/jobs/{id}`, `…/jobs/{id}/cancel`, `…/jobs/{id}/pause`,\n * `…/jobs/{id}/resume`\n * - `resources/fine-tuning/jobs/checkpoints.js` — `…/jobs/{id}/checkpoints`\n * - `resources/fine-tuning/checkpoints/permissions.js` —\n * `…/checkpoints/{ckpt}/permissions` (create/list) and\n * `…/checkpoints/{ckpt}/permissions/{id}` (delete)\n * - `resources/fine-tuning/alpha/graders.js` —\n * `/fine_tuning/alpha/graders/run`, `/fine_tuning/alpha/graders/validate`\n *\n * The grader routes carry no ids, so they need no placeholder — but they DO\n * need naming here, because the namespace cascade below ends in a catch-all\n * and a static route must not be swallowed by it.\n *\n * Every segment after `/v1/fine_tuning/` is caller-controlled, so the rule is:\n * known action names are kept verbatim, ids collapse to `{id}`/`{ckpt}`, and\n * anything else — an unknown action, an unknown depth — collapses to a single\n * bucket. That is what actually keeps the fine-tuning label set finite no\n * matter what is requested; an un-collapsed tail would leave the hole open to\n * a typo or a fuzzer.\n *\n * Not exported: server.ts dispatches fine-tuning jobs from the same\n * route-registry.ts bindings (`FINE_TUNING_JOBS_PATH`, `FINE_TUNING_ID_RE`,\n * `FINE_TUNING_CANCEL_RE`, `FINE_TUNING_EVENTS_RE`).\n */\nconst FINE_TUNING_PREFIX = \"/v1/fine_tuning/\";\nconst FINE_TUNING_STATIC_PATHS = new Set([\n \"/v1/fine_tuning/jobs\",\n \"/v1/fine_tuning/alpha/graders/run\",\n \"/v1/fine_tuning/alpha/graders/validate\",\n]);\nconst FINE_TUNING_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/jobs\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_SUBRESOURCES = new Set([\"cancel\", \"events\", \"pause\", \"resume\", \"checkpoints\"]);\nconst FINE_TUNING_PERMISSION_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/permissions\\/[^/]+$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCES = new Set([\"permissions\"]);\nconst FINE_TUNING_CHECKPOINT_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/([^/]+)$/;\nconst FINE_TUNING_OTHER_LABEL = \"/v1/fine_tuning/{other}\";\n\n/**\n * Normalize parametric API paths to route patterns for use as metric labels.\n * Replaces dynamic segments (model IDs, deployment names, etc.) with placeholders.\n * `mountPaths` are the roots of the mounted services, so their traffic keeps a\n * bounded label instead of collapsing to `{unknown}`.\n */\nexport function normalizePathLabel(pathname: string, mountPaths: readonly string[] = []): string {\n // Match server dispatch precedence: controls, mounts in registration order,\n // then provider routes. A mount may overlap any provider namespace.\n // Control API: exact sub-paths verbatim, anything else under the prefix\n // collapses.\n if (pathname.startsWith(CONTROL_PREFIX)) {\n return CONTROL_PATHS.has(pathname) ? pathname : CONTROL_OTHER_LABEL;\n }\n\n // Mounted services: the root and the known sub-paths verbatim, anything\n // deeper collapses under the mount.\n for (const mountPath of mountPaths) {\n if (pathname === mountPath) return pathname;\n if (pathname.startsWith(mountPath + \"/\")) {\n return MOUNT_SUBPATHS.has(pathname.slice(mountPath.length))\n ? pathname\n : `${mountPath}/{other}`;\n }\n }\n\n // Bedrock: /model/{modelId}/{operation}\n const bedrockMatch = pathname.match(BEDROCK_RE);\n if (bedrockMatch) {\n return `/model/{modelId}/${bedrockMatch[2]}`;\n }\n\n // Gemini: /v1beta/models/{model}:{action}, plus the bare GET model lookup.\n const geminiMatch = pathname.match(GEMINI_RE);\n if (geminiMatch) {\n const action = GEMINI_ACTIONS.has(geminiMatch[2]) ? geminiMatch[2] : \"{action}\";\n return `/v1beta/models/{model}:${action}`;\n }\n if (GEMINI_MODEL_RE.test(pathname)) {\n return \"/v1beta/models/{model}\";\n }\n\n // Azure: /openai/deployments/{id}/{operation}\n const azureMatch = pathname.match(AZURE_RE);\n if (azureMatch) {\n return `/openai/deployments/{id}/${azureMatch[2]}`;\n }\n\n // Vertex AI: /v1/projects/{p}/locations/{l}/publishers/google/models/{m}:{action}\n const vertexMatch = pathname.match(VERTEX_RE);\n if (vertexMatch) {\n const action = VERTEX_ACTIONS.has(vertexMatch[4]) ? vertexMatch[4] : \"{action}\";\n return `/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:${action}`;\n }\n\n // ElevenLabs TTS: /v1/text-to-speech/{voice_id}\n if (ELEVENLABS_TTS_RE.test(pathname)) {\n return \"/v1/text-to-speech/{voice_id}\";\n }\n\n // ElevenLabs voices: /v1/voices/{voice_id}\n if (ELEVENLABS_VOICE_RE.test(pathname)) {\n return \"/v1/voices/{voice_id}\";\n }\n\n // OpenRouter video: /api/v1/videos/{jobId}[/content] — jobIds are random\n // UUIDs, so raw paths would mint unbounded label cardinality. The static\n // /api/v1/videos/models listing route must not collapse into {jobId}.\n if (OPENROUTER_VIDEO_CONTENT_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}/content\";\n }\n if (pathname !== \"/api/v1/videos/models\" && OPENROUTER_VIDEO_STATUS_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}\";\n }\n\n // Google Veo video: submit `:predictLongRunning` + poll `/v1beta/operations/{name}`.\n // Operation names are random UUIDs, so the raw path would mint unbounded\n // label cardinality.\n if (VEO_PREDICT_LRO_RE.test(pathname)) {\n return \"/v1beta/models/{model}:predictLongRunning\";\n }\n if (VEO_OPERATION_RE.test(pathname)) {\n return \"/v1beta/operations/{name}\";\n }\n\n // xAI Grok Imagine submit is a static literal path — keep it distinct from\n // the `/v1/videos/{id}` status label below (which it would otherwise collapse\n // into), exactly as `/api/v1/videos/models` is kept out of the jobId bucket.\n if (pathname === GROK_VIDEO_SUBMIT_PATH) {\n return GROK_VIDEO_SUBMIT_PATH;\n }\n\n // OpenAI/Grok video status: /v1/videos/{id}\n if (OPENAI_VIDEO_STATUS_RE.test(pathname)) {\n return \"/v1/videos/{id}\";\n }\n\n // BytePlus Ark video: /[api/v3/]contents/generations/tasks[/{id}] — task ids\n // (`cgt-…`) are unbounded cardinality. Status before submit: the status RE is\n // the more specific of the two and the submit RE cannot match a trailing id\n // segment, so the order is belt-and-braces. Appended at the end of the\n // cascade because the anchored REs above cannot match any path an earlier\n // entry claims.\n if (BYTEPLUS_VIDEO_STATUS_RE.test(pathname)) {\n return \"/contents/generations/tasks/{id}\";\n }\n if (BYTEPLUS_VIDEO_SUBMIT_RE.test(pathname)) {\n return \"/contents/generations/tasks\";\n }\n\n if (BATCHES_CANCEL_RE.test(pathname)) {\n return \"/v1/batches/{id}/cancel\";\n }\n if (pathname !== \"/v1/batches\" && BATCHES_ID_RE.test(pathname)) {\n return \"/v1/batches/{id}\";\n }\n if (pathname.startsWith(BATCHES_PREFIX)) {\n return BATCHES_OTHER_LABEL;\n }\n\n // Files API: /v1/files/{id} and /v1/files/{id}/content carry random\n // `file-…` ids — raw paths would mint unbounded label cardinality.\n // Content before id: the id RE would otherwise swallow the content suffix.\n if (FILES_CONTENT_RE.test(pathname)) {\n return \"/v1/files/{id}/content\";\n }\n if (pathname !== \"/v1/files\" && FILES_ID_RE.test(pathname)) {\n return \"/v1/files/{id}\";\n }\n if (pathname.startsWith(FILES_PREFIX)) {\n return FILES_OTHER_LABEL;\n }\n\n // Vector Stores: /v1/vector_stores/{id}[/files[/{fileId}]|/file_batches…|/search].\n // Most-specific first so the id RE cannot swallow a sub-resource suffix.\n if (VECTOR_STORES_SEARCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/search\";\n }\n if (VECTOR_STORES_BATCH_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/files\";\n }\n if (VECTOR_STORES_BATCH_CANCEL_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/cancel\";\n }\n if (VECTOR_STORES_BATCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}\";\n }\n if (VECTOR_STORES_FILE_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files/{fileId}\";\n }\n if (VECTOR_STORES_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files\";\n }\n if (VECTOR_STORES_FILE_BATCHES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches\";\n }\n if (pathname !== \"/v1/vector_stores\" && VECTOR_STORES_ID_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}\";\n }\n if (pathname.startsWith(VECTOR_STORES_PREFIX)) {\n return VECTOR_STORES_OTHER_LABEL;\n }\n\n // fal.ai: see the namespace note above. Queue-request rules read before the\n // path-mirror rule because `/fal/queue/requests/…` also matches the mirror\n // RE's `.+/requests/` shape; both would label correctly, but the specific\n // rule reading first keeps the cascade legible.\n if (FAL_ROUTE_RE.test(pathname)) {\n const queueRequest = pathname.match(FAL_QUEUE_REQUEST_RE);\n if (queueRequest) {\n return `/fal/queue/requests/{id}${falRequestSuffix(queueRequest[1])}`;\n }\n if (FAL_QUEUE_SUBMIT_RE.test(pathname)) return \"/fal/queue/submit/{model}\";\n if (FAL_RUN_RE.test(pathname)) return \"/fal/run/{model}\";\n const mirrorRequest = pathname.match(FAL_MIRROR_REQUEST_RE);\n if (mirrorRequest) {\n return `/fal/{model}/requests/{id}${falRequestSuffix(mirrorRequest[1])}`;\n }\n return FAL_OTHER_LABEL;\n }\n\n // ElevenLabs Music: known actions verbatim, anything else collapses.\n if (pathname.startsWith(MUSIC_PREFIX)) {\n return MUSIC_ACTIONS.has(pathname.slice(MUSIC_PREFIX.length)) ? pathname : MUSIC_OTHER_LABEL;\n }\n\n // Fine-tuning. Handled as one closed namespace rather than a few loose REs:\n // the cascade is entered by prefix and always returns, so no fine-tuning path\n // can reach the verbatim return at the bottom of this function.\n //\n // Order matters twice. The id-bearing permission rule reads before the\n // checkpoint sub-resource rule, because `…/permissions/{id}` would otherwise\n // never be reached (its own second segment is the id). Within each family the\n // sub-resource rule reads before the id rule; the id REs are anchored to a\n // single trailing segment so the two cannot both match, but the more specific\n // path reading first is what makes the cascade legible.\n if (pathname.startsWith(FINE_TUNING_PREFIX)) {\n if (FINE_TUNING_STATIC_PATHS.has(pathname)) return pathname;\n\n const ftSubresource = pathname.match(FINE_TUNING_SUBRESOURCE_RE);\n if (ftSubresource) {\n const action = FINE_TUNING_SUBRESOURCES.has(ftSubresource[1]) ? ftSubresource[1] : \"{action}\";\n return `/v1/fine_tuning/jobs/{id}/${action}`;\n }\n if (FINE_TUNING_ID_RE.test(pathname)) return \"/v1/fine_tuning/jobs/{id}\";\n\n if (FINE_TUNING_PERMISSION_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}/permissions/{id}\";\n }\n const ckptSubresource = pathname.match(FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE);\n if (ckptSubresource) {\n const action = FINE_TUNING_CHECKPOINT_SUBRESOURCES.has(ckptSubresource[1])\n ? ckptSubresource[1]\n : \"{action}\";\n return `/v1/fine_tuning/checkpoints/{ckpt}/${action}`;\n }\n if (FINE_TUNING_CHECKPOINT_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}\";\n }\n\n return FINE_TUNING_OTHER_LABEL;\n }\n\n // Static path — verbatim only if server.ts routes it. Anything else is, as\n // far as metrics can tell, caller-controlled text, whatever status it got\n // (404, a 204 preflight, a destroyed response); every routed id path that\n // can legitimately 404 has already returned its placeholder label above.\n return STATIC_ROUTE_PATHS.has(pathname) ? pathname : UNKNOWN_PATH_LABEL;\n}\n\nfunction falRequestSuffix(s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AO;EAEnD,MAAM,gBAAgB,SAAS,MAAM,2BAA2B;AAChE,MAAI,cAEF,QAAO,6BADQ,yBAAyB,IAAI,cAAc,GAAG,GAAG,cAAc,KAAK;AAGrF,MAAI,kBAAkB,KAAK,SAAS,CAAE,QAAO;AAE7C,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;EAET,MAAM,kBAAkB,SAAS,MAAM,sCAAsC;AAC7E,MAAI,gBAIF,QAAO,sCAHQ,oCAAoC,IAAI,gBAAgB,GAAG,GACtE,gBAAgB,KAChB;AAGN,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;AAGT,SAAO;;AAOT,QAAO,mBAAmB,IAAI,SAAS,GAAG,WAAW;;AAGvD,SAAS,iBAAiB,KAAiC;AACzD,KAAI,QAAQ,OAAW,QAAO;AAC9B,QAAO,yBAAyB,IAAI,IAAI,GAAG,IAAI,QAAQ"}
1
+ {"version":3,"file":"metrics.js","names":["AZURE_RE"],"sources":["../src/metrics.ts"],"sourcesContent":["/**\n * Lightweight Prometheus metrics registry for LLMock.\n *\n * Zero external dependencies — implements counters, histograms, and gauges\n * with Prometheus text exposition format serialization.\n */\n\nimport {\n AZURE_DEPLOYMENT_RE as AZURE_RE,\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n ELEVENLABS_TTS_RE,\n ELEVENLABS_VOICE_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n FINE_TUNING_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n MODELS_DETAIL_RE,\n GEMINI_MODEL_DETAIL_RE,\n GEMINI_MODELS_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILES_RE,\n VECTOR_STORES_FILE_BATCHES_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n} from \"./route-registry.js\";\n\n// Re-exported so existing importers (route tests) keep resolving these\n// against the metrics module. The bindings ARE the registry's — there is\n// exactly one pattern object per route family.\nexport {\n BATCHES_CANCEL_RE,\n BATCHES_ID_RE,\n BYTEPLUS_VIDEO_STATUS_RE,\n BYTEPLUS_VIDEO_SUBMIT_RE,\n FAL_ROUTE_RE,\n FILES_CONTENT_RE,\n FILES_ID_RE,\n GROK_VIDEO_STATUS_RE,\n GROK_VIDEO_SUBMIT_PATH,\n OPENAI_VIDEO_STATUS_RE,\n OPENROUTER_VIDEO_CONTENT_RE,\n OPENROUTER_VIDEO_STATUS_RE,\n VEO_OPERATION_RE,\n VEO_PREDICT_LRO_RE,\n VECTOR_STORES_BATCH_CANCEL_RE,\n VECTOR_STORES_BATCH_FILES_RE,\n VECTOR_STORES_BATCH_RE,\n VECTOR_STORES_FILE_RE,\n VECTOR_STORES_ID_RE,\n VECTOR_STORES_SEARCH_RE,\n};\n\n// ---------------------------------------------------------------------------\n// Public interface\n// ---------------------------------------------------------------------------\n\nexport interface MetricsRegistry {\n incrementCounter(name: string, labels: Record<string, string>): void;\n observeHistogram(name: string, labels: Record<string, string>, value: number): void;\n setGauge(name: string, labels: Record<string, string>, value: number): void;\n serialize(): string;\n reset(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Histogram bucket boundaries (Prometheus default-ish)\n// ---------------------------------------------------------------------------\n\nconst HISTOGRAM_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10];\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\n/** Build a stable label key string for map lookups: `label1=\"v1\",label2=\"v2\"` */\nfunction labelKey(labels: Record<string, string>): string {\n const entries = Object.entries(labels).sort(([a], [b]) => a.localeCompare(b));\n if (entries.length === 0) return \"\";\n return entries.map(([k, v]) => `${k}=\"${escapeLabelValue(v)}\"`).join(\",\");\n}\n\n/** Escape a label value per Prometheus text exposition format. */\nfunction escapeLabelValue(v: string): string {\n return v.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"').replace(/\\n/g, \"\\\\n\");\n}\n\n/** Format labels for Prometheus output: `{label1=\"v1\",label2=\"v2\"}` */\nfunction formatLabels(labels: Record<string, string>): string {\n return `{${labelKey(labels)}}`;\n}\n\n// ---------------------------------------------------------------------------\n// Internal metric storage types\n// ---------------------------------------------------------------------------\n\ninterface CounterData {\n type: \"counter\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ninterface HistogramData {\n type: \"histogram\";\n /** Map from labelKey → bucket counts, sum, count */\n series: Map<\n string,\n {\n labels: Record<string, string>;\n bucketCounts: number[]; // one per HISTOGRAM_BUCKETS entry\n sum: number;\n count: number;\n }\n >;\n}\n\ninterface GaugeData {\n type: \"gauge\";\n /** Map from labelKey → value */\n series: Map<string, { labels: Record<string, string>; value: number }>;\n}\n\ntype MetricData = CounterData | HistogramData | GaugeData;\n\n// ---------------------------------------------------------------------------\n// Registry implementation\n// ---------------------------------------------------------------------------\n\nexport function createMetricsRegistry(): MetricsRegistry {\n /** Ordered map: metric name → data. Insertion order preserved for stable output. */\n const metrics = new Map<string, MetricData>();\n\n function getOrCreateCounter(name: string): CounterData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"counter\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"counter\") throw new Error(`Metric ${name} is not a counter`);\n return data as CounterData;\n }\n\n function getOrCreateHistogram(name: string): HistogramData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"histogram\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"histogram\") throw new Error(`Metric ${name} is not a histogram`);\n return data as HistogramData;\n }\n\n function getOrCreateGauge(name: string): GaugeData {\n let data = metrics.get(name);\n if (!data) {\n data = { type: \"gauge\", series: new Map() };\n metrics.set(name, data);\n }\n if (data.type !== \"gauge\") throw new Error(`Metric ${name} is not a gauge`);\n return data as GaugeData;\n }\n\n return {\n incrementCounter(name: string, labels: Record<string, string>): void {\n const counter = getOrCreateCounter(name);\n const key = labelKey(labels);\n const existing = counter.series.get(key);\n if (existing) {\n existing.value += 1;\n } else {\n counter.series.set(key, { labels, value: 1 });\n }\n },\n\n observeHistogram(name: string, labels: Record<string, string>, value: number): void {\n const histogram = getOrCreateHistogram(name);\n const key = labelKey(labels);\n let existing = histogram.series.get(key);\n if (!existing) {\n existing = {\n labels,\n bucketCounts: new Array(HISTOGRAM_BUCKETS.length).fill(0) as number[],\n sum: 0,\n count: 0,\n };\n histogram.series.set(key, existing);\n }\n // Update cumulative bucket counts\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n if (value <= HISTOGRAM_BUCKETS[i]) {\n existing.bucketCounts[i] += 1;\n }\n }\n existing.sum += value;\n existing.count += 1;\n },\n\n setGauge(name: string, labels: Record<string, string>, value: number): void {\n const gauge = getOrCreateGauge(name);\n const key = labelKey(labels);\n const existing = gauge.series.get(key);\n if (existing) {\n existing.value = value;\n } else {\n gauge.series.set(key, { labels, value });\n }\n },\n\n serialize(): string {\n const lines: string[] = [];\n\n for (const [name, data] of metrics) {\n switch (data.type) {\n case \"counter\": {\n lines.push(`# TYPE ${name} counter`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n case \"histogram\": {\n lines.push(`# TYPE ${name} histogram`);\n for (const series of data.series.values()) {\n const lblStr = labelKey(series.labels);\n const lblPrefix = lblStr ? `${lblStr},` : \"\";\n // Bucket lines\n for (let i = 0; i < HISTOGRAM_BUCKETS.length; i++) {\n lines.push(\n `${name}_bucket{${lblPrefix}le=\"${HISTOGRAM_BUCKETS[i]}\"} ${series.bucketCounts[i]}`,\n );\n }\n // +Inf bucket\n lines.push(`${name}_bucket{${lblPrefix}le=\"+Inf\"} ${series.count}`);\n // Sum and count\n lines.push(`${name}_sum${formatLabels(series.labels)} ${series.sum}`);\n lines.push(`${name}_count${formatLabels(series.labels)} ${series.count}`);\n }\n break;\n }\n case \"gauge\": {\n lines.push(`# TYPE ${name} gauge`);\n for (const series of data.series.values()) {\n lines.push(`${name}${formatLabels(series.labels)} ${series.value}`);\n }\n break;\n }\n }\n }\n\n return lines.length > 0 ? lines.join(\"\\n\") + \"\\n\" : \"\";\n },\n\n reset(): void {\n metrics.clear();\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Path normalization for metric labels\n// ---------------------------------------------------------------------------\n\n// Regex patterns for parametric API routes. The dispatch+labeling patterns\n// shared with server.ts dispatch and the machine-readable catalog are defined\n// in route-registry.ts (single source of truth) and imported above; only\n// labeling-specific patterns are declared here: the Bedrock union, the Looser\n// Vertex shape, the widened Gemini action bucket (+ its allowlists), and the\n// served-or-not namespace cascades below.\nconst BEDROCK_RE =\n /^\\/model\\/([^/]+)\\/(invoke|invoke-with-response-stream|converse|converse-stream)$/;\nconst VERTEX_RE =\n /^\\/v1\\/projects\\/([^/]+)\\/locations\\/([^/]+)\\/publishers\\/google\\/models\\/([^:]+):(.+)$/;\n// Gemini `/v1beta/models/{model}:{action}`. The action segment is caller\n// controlled, so only the actions the server routes stay verbatim; anything\n// else collapses to `{action}`. `predictLongRunning` is listed so the Veo\n// submit label below stays byte-identical to what it was before this RE\n// widened past generate/streamGenerate — the two rules must agree.\nconst GEMINI_RE = /^\\/v1beta\\/models\\/([^:]+):([^/]+)$/;\n// Retain the historical label for unserved single-segment encoded action IDs.\nconst GEMINI_MODEL_LABEL_RE = /^\\/v1beta\\/models\\/([^:/]+)$/;\nconst GEMINI_ACTIONS = new Set([\n \"generateContent\",\n \"streamGenerateContent\",\n \"embedContent\",\n \"batchEmbedContents\",\n \"countTokens\",\n \"predict\",\n \"predictLongRunning\",\n]);\n// The Vertex `:action` segment is caller controlled exactly as Gemini's is;\n// server.ts routes only these two, so anything else collapses to `{action}`.\nconst VERTEX_ACTIONS = new Set([\"generateContent\", \"streamGenerateContent\"]);\n\n/**\n * Closed namespaces beyond fine-tuning. Each prefix below is entered by prefix\n * and always returns, so no id-bearing or unknown-depth path under it can\n * reach the verbatim return at the bottom of `normalizePathLabel`:\n *\n * - fal: `/fal/queue/requests/{id}[/status|/cancel|/stream]` (aimock's own\n * queue layout), `/fal/{model}/requests/{id}[/…]` (the `x-fal-target-host`\n * path-mirror of `queue.fal.run`), `/fal/queue/submit/{model}`,\n * `/fal/run/{model}`. Request ids are minted per submit and model ids are\n * caller-controlled multi-segment paths, so both collapse.\n * - music: `/v1/music/{generation|variation|remix|extend|plan|detailed|stream}`\n * are the ElevenLabs routes (`plan`/`stream` take their own response shape\n * in elevenlabs-audio.ts); the server RE accepts any suffix, so an unknown\n * one collapses.\n * - files / batches: the id and sub-resource rules above cover the routed\n * shapes; any other depth collapses to the namespace's `{other}`.\n */\n/**\n * The fal.ai route shape (`FAL_ROUTE_RE`, imported from route-registry.ts so\n * the label rule cannot drift from the route rule): a bare `/fal` is routed,\n * so it is labelled here rather than falling through to `{unknown}`.\n */\nconst FAL_QUEUE_REQUEST_RE = /^\\/fal\\/queue\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_MIRROR_REQUEST_RE = /^\\/fal\\/.+\\/requests\\/[^/]+(?:\\/([^/]+))?$/;\nconst FAL_REQUEST_SUBRESOURCES = new Set([\"status\", \"cancel\", \"stream\"]);\nconst FAL_QUEUE_SUBMIT_RE = /^\\/fal\\/queue\\/submit\\/.+$/;\nconst FAL_RUN_RE = /^\\/fal\\/run\\/.+$/;\nconst FAL_OTHER_LABEL = \"/fal/{other}\";\nconst MUSIC_PREFIX = \"/v1/music/\";\nconst MUSIC_ACTIONS = new Set([\n \"generation\",\n \"variation\",\n \"remix\",\n \"extend\",\n \"plan\",\n \"detailed\",\n \"stream\",\n]);\nconst MUSIC_OTHER_LABEL = \"/v1/music/{other}\";\nconst FILES_PREFIX = \"/v1/files/\";\nconst FILES_OTHER_LABEL = \"/v1/files/{other}\";\nconst BATCHES_PREFIX = \"/v1/batches/\";\nconst BATCHES_OTHER_LABEL = \"/v1/batches/{other}\";\nconst VECTOR_STORES_PREFIX = \"/v1/vector_stores/\";\nconst VECTOR_STORES_OTHER_LABEL = \"/v1/vector_stores/{other}\";\n\n/**\n * Label for a path no route claimed. Metrics are recorded for EVERY response,\n * the generic 404 included, so an unrouted path is caller-controlled text and\n * a fuzzer (or a typo'd SDK base URL) would mint one label per request.\n *\n * The collapse is decided by ROUTE SHAPE, never by status: a 404 is not the\n * only way an unrouted path gets answered (a CORS preflight is 204 for any\n * path, a torn-down response has no status at all), and a routed path can\n * legitimately 404 (a fixture miss, a missing file) without becoming\n * unknown. Every path that is not claimed by a placeholder rule above must\n * therefore be listed here to keep its verbatim label.\n */\nexport const UNKNOWN_PATH_LABEL = \"{unknown}\";\n\n/**\n * Static paths server.ts dispatches by exact match (after\n * `normalizeCompatPath`, so the canonical `/v1/...` spelling). A path absent\n * from this table that no placeholder rule claims is labelled `{unknown}`\n * whatever its status — so a new static route needs an entry here or its\n * traffic is counted but not named.\n */\nconst STATIC_ROUTE_PATHS = new Set([\n \"/health\",\n \"/ready\",\n \"/metrics\",\n \"/search\",\n \"/v1/chat/completions\",\n \"/v1/responses\",\n \"/v1/realtime\",\n \"/v1/messages\",\n \"/v1/messages/count_tokens\",\n \"/v1/embeddings\",\n \"/v1/moderations\",\n \"/v1/models\",\n \"/v1/_requests\",\n \"/v1/images/generations\",\n \"/v1/images/edits\",\n \"/v1/images/variations\",\n \"/v1/audio/speech\",\n \"/v1/audio/transcriptions\",\n \"/v1/audio/translations\",\n \"/v1/videos\",\n \"/v1/batches\",\n \"/v1/files\",\n \"/v1/vector_stores\",\n \"/v1/sound-generation\",\n \"/v1/music\",\n \"/v1/text-to-voice\",\n \"/v1/text-to-voice/design\",\n \"/v1beta/interactions\",\n \"/v2/chat\",\n \"/v2/embed\",\n \"/v2/rerank\",\n \"/api/chat\",\n \"/api/generate\",\n \"/api/embeddings\",\n \"/api/embed\",\n \"/api/tags\",\n \"/api/v1/videos\",\n \"/api/v1/videos/models\",\n \"/api/v1/credits\",\n \"/api/v1/key\",\n \"/api/v1/models\",\n \"/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent\",\n]);\n\n/**\n * Control API (`/__aimock/...`): a closed set of sub-paths, matched exactly\n * in `handleControlAPI`; anything else under the prefix collapses.\n */\nconst CONTROL_PREFIX = \"/__aimock/\";\nconst CONTROL_PATHS = new Set([\n \"/__aimock/health\",\n \"/__aimock/journal\",\n \"/__aimock/fixtures\",\n \"/__aimock/chaos\",\n \"/__aimock/reset\",\n \"/__aimock/reset/journal\",\n \"/__aimock/reset/fixtures\",\n \"/__aimock/error\",\n \"/__aimock/openapi.json\",\n \"/__aimock/routes\",\n]);\nconst CONTROL_OTHER_LABEL = \"/__aimock/{other}\";\n\n/**\n * Sub-paths a mounted service (`createServer(..., mounts)`) answers below its\n * mount root. The mount roots themselves are runtime configuration, so the\n * caller passes them in; the JSON-RPC handlers (MCP, A2A, AG-UI, vector) take\n * the root only, and A2A additionally serves its agent card.\n */\nconst MOUNT_SUBPATHS = new Set([\"/.well-known/agent-card.json\"]);\n\n/**\n * Status label for a response that was destroyed before its body ended: no\n * status line reached the client as a completed response, so no HTTP code\n * describes the outcome truthfully. Distinct from every numeric status so\n * `sum(aimock_requests_total)` equals requests served.\n */\nexport const DESTROYED_STATUS_LABEL = \"destroyed\";\n\n/**\n * Fine-tuning routes. Both id families (`ftjob-…` per create, `ftckpt-…` per\n * checkpoint) are minted per resource, so every id-bearing path has to collapse\n * or each job and each checkpoint mints its own label pair.\n *\n * The label hazard is NOT limited to the routes this server implements: metrics\n * are recorded on `res.on(\"finish\")` for EVERY response, the generic 404\n * included, and `openai@4.104.0` calls a good deal more of the namespace than\n * aimock handles. Enumerated from that SDK:\n *\n * - `resources/fine-tuning/jobs/jobs.js` — `/fine_tuning/jobs`,\n * `…/jobs/{id}`, `…/jobs/{id}/cancel`, `…/jobs/{id}/pause`,\n * `…/jobs/{id}/resume`\n * - `resources/fine-tuning/jobs/checkpoints.js` — `…/jobs/{id}/checkpoints`\n * - `resources/fine-tuning/checkpoints/permissions.js` —\n * `…/checkpoints/{ckpt}/permissions` (create/list) and\n * `…/checkpoints/{ckpt}/permissions/{id}` (delete)\n * - `resources/fine-tuning/alpha/graders.js` —\n * `/fine_tuning/alpha/graders/run`, `/fine_tuning/alpha/graders/validate`\n *\n * The grader routes carry no ids, so they need no placeholder — but they DO\n * need naming here, because the namespace cascade below ends in a catch-all\n * and a static route must not be swallowed by it.\n *\n * Every segment after `/v1/fine_tuning/` is caller-controlled, so the rule is:\n * known action names are kept verbatim, ids collapse to `{id}`/`{ckpt}`, and\n * anything else — an unknown action, an unknown depth — collapses to a single\n * bucket. That is what actually keeps the fine-tuning label set finite no\n * matter what is requested; an un-collapsed tail would leave the hole open to\n * a typo or a fuzzer.\n *\n * Not exported: server.ts dispatches fine-tuning jobs from the same\n * route-registry.ts bindings (`FINE_TUNING_JOBS_PATH`, `FINE_TUNING_ID_RE`,\n * `FINE_TUNING_CANCEL_RE`, `FINE_TUNING_EVENTS_RE`).\n */\nconst FINE_TUNING_PREFIX = \"/v1/fine_tuning/\";\nconst FINE_TUNING_STATIC_PATHS = new Set([\n \"/v1/fine_tuning/jobs\",\n \"/v1/fine_tuning/alpha/graders/run\",\n \"/v1/fine_tuning/alpha/graders/validate\",\n]);\nconst FINE_TUNING_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/jobs\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_SUBRESOURCES = new Set([\"cancel\", \"events\", \"pause\", \"resume\", \"checkpoints\"]);\nconst FINE_TUNING_PERMISSION_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/permissions\\/[^/]+$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/[^/]+\\/([^/]+)$/;\nconst FINE_TUNING_CHECKPOINT_SUBRESOURCES = new Set([\"permissions\"]);\nconst FINE_TUNING_CHECKPOINT_ID_RE = /^\\/v1\\/fine_tuning\\/checkpoints\\/([^/]+)$/;\nconst FINE_TUNING_OTHER_LABEL = \"/v1/fine_tuning/{other}\";\n\n/**\n * Normalize parametric API paths to route patterns for use as metric labels.\n * Replaces dynamic segments (model IDs, deployment names, etc.) with placeholders.\n * `mountPaths` are the roots of the mounted services, so their traffic keeps a\n * bounded label instead of collapsing to `{unknown}`.\n */\nexport function normalizePathLabel(pathname: string, mountPaths: readonly string[] = []): string {\n // Match server dispatch precedence: controls, mounts in registration order,\n // then provider routes. A mount may overlap any provider namespace.\n // Control API: exact sub-paths verbatim, anything else under the prefix\n // collapses.\n if (pathname.startsWith(CONTROL_PREFIX)) {\n return CONTROL_PATHS.has(pathname) ? pathname : CONTROL_OTHER_LABEL;\n }\n\n // Mounted services: the root and the known sub-paths verbatim, anything\n // deeper collapses under the mount.\n for (const mountPath of mountPaths) {\n if (pathname === mountPath) return pathname;\n if (pathname.startsWith(mountPath + \"/\")) {\n return MOUNT_SUBPATHS.has(pathname.slice(mountPath.length))\n ? pathname\n : `${mountPath}/{other}`;\n }\n }\n\n if (MODELS_DETAIL_RE.test(pathname)) return \"/v1/models/{id}\";\n if (pathname === GEMINI_MODELS_PATH) return GEMINI_MODELS_PATH;\n\n // Bedrock: /model/{modelId}/{operation}\n const bedrockMatch = pathname.match(BEDROCK_RE);\n if (bedrockMatch) {\n return `/model/{modelId}/${bedrockMatch[2]}`;\n }\n\n // Gemini: /v1beta/models/{model}:{action}, plus the bare GET model lookup.\n const geminiMatch = pathname.match(GEMINI_RE);\n if (geminiMatch) {\n const action = GEMINI_ACTIONS.has(geminiMatch[2]) ? geminiMatch[2] : \"{action}\";\n return `/v1beta/models/{model}:${action}`;\n }\n if (GEMINI_MODEL_DETAIL_RE.test(pathname) || GEMINI_MODEL_LABEL_RE.test(pathname)) {\n return \"/v1beta/models/{model}\";\n }\n\n // Azure: /openai/deployments/{id}/{operation}\n const azureMatch = pathname.match(AZURE_RE);\n if (azureMatch) {\n return `/openai/deployments/{id}/${azureMatch[2]}`;\n }\n\n // Vertex AI: /v1/projects/{p}/locations/{l}/publishers/google/models/{m}:{action}\n const vertexMatch = pathname.match(VERTEX_RE);\n if (vertexMatch) {\n const action = VERTEX_ACTIONS.has(vertexMatch[4]) ? vertexMatch[4] : \"{action}\";\n return `/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:${action}`;\n }\n\n // ElevenLabs TTS: /v1/text-to-speech/{voice_id}\n if (ELEVENLABS_TTS_RE.test(pathname)) {\n return \"/v1/text-to-speech/{voice_id}\";\n }\n\n // ElevenLabs voices: /v1/voices/{voice_id}\n if (ELEVENLABS_VOICE_RE.test(pathname)) {\n return \"/v1/voices/{voice_id}\";\n }\n\n // OpenRouter video: /api/v1/videos/{jobId}[/content] — jobIds are random\n // UUIDs, so raw paths would mint unbounded label cardinality. The static\n // /api/v1/videos/models listing route must not collapse into {jobId}.\n if (OPENROUTER_VIDEO_CONTENT_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}/content\";\n }\n if (pathname !== \"/api/v1/videos/models\" && OPENROUTER_VIDEO_STATUS_RE.test(pathname)) {\n return \"/api/v1/videos/{jobId}\";\n }\n\n // Google Veo video: submit `:predictLongRunning` + poll `/v1beta/operations/{name}`.\n // Operation names are random UUIDs, so the raw path would mint unbounded\n // label cardinality.\n if (VEO_PREDICT_LRO_RE.test(pathname)) {\n return \"/v1beta/models/{model}:predictLongRunning\";\n }\n if (VEO_OPERATION_RE.test(pathname)) {\n return \"/v1beta/operations/{name}\";\n }\n\n // xAI Grok Imagine submit is a static literal path — keep it distinct from\n // the `/v1/videos/{id}` status label below (which it would otherwise collapse\n // into), exactly as `/api/v1/videos/models` is kept out of the jobId bucket.\n if (pathname === GROK_VIDEO_SUBMIT_PATH) {\n return GROK_VIDEO_SUBMIT_PATH;\n }\n\n // OpenAI/Grok video status: /v1/videos/{id}\n if (OPENAI_VIDEO_STATUS_RE.test(pathname)) {\n return \"/v1/videos/{id}\";\n }\n\n // BytePlus Ark video: /[api/v3/]contents/generations/tasks[/{id}] — task ids\n // (`cgt-…`) are unbounded cardinality. Status before submit: the status RE is\n // the more specific of the two and the submit RE cannot match a trailing id\n // segment, so the order is belt-and-braces. Appended at the end of the\n // cascade because the anchored REs above cannot match any path an earlier\n // entry claims.\n if (BYTEPLUS_VIDEO_STATUS_RE.test(pathname)) {\n return \"/contents/generations/tasks/{id}\";\n }\n if (BYTEPLUS_VIDEO_SUBMIT_RE.test(pathname)) {\n return \"/contents/generations/tasks\";\n }\n\n if (BATCHES_CANCEL_RE.test(pathname)) {\n return \"/v1/batches/{id}/cancel\";\n }\n if (pathname !== \"/v1/batches\" && BATCHES_ID_RE.test(pathname)) {\n return \"/v1/batches/{id}\";\n }\n if (pathname.startsWith(BATCHES_PREFIX)) {\n return BATCHES_OTHER_LABEL;\n }\n\n // Files API: /v1/files/{id} and /v1/files/{id}/content carry random\n // `file-…` ids — raw paths would mint unbounded label cardinality.\n // Content before id: the id RE would otherwise swallow the content suffix.\n if (FILES_CONTENT_RE.test(pathname)) {\n return \"/v1/files/{id}/content\";\n }\n if (pathname !== \"/v1/files\" && FILES_ID_RE.test(pathname)) {\n return \"/v1/files/{id}\";\n }\n if (pathname.startsWith(FILES_PREFIX)) {\n return FILES_OTHER_LABEL;\n }\n\n // Vector Stores: /v1/vector_stores/{id}[/files[/{fileId}]|/file_batches…|/search].\n // Most-specific first so the id RE cannot swallow a sub-resource suffix.\n if (VECTOR_STORES_SEARCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/search\";\n }\n if (VECTOR_STORES_BATCH_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/files\";\n }\n if (VECTOR_STORES_BATCH_CANCEL_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}/cancel\";\n }\n if (VECTOR_STORES_BATCH_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches/{batchId}\";\n }\n if (VECTOR_STORES_FILE_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files/{fileId}\";\n }\n if (VECTOR_STORES_FILES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/files\";\n }\n if (VECTOR_STORES_FILE_BATCHES_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}/file_batches\";\n }\n if (pathname !== \"/v1/vector_stores\" && VECTOR_STORES_ID_RE.test(pathname)) {\n return \"/v1/vector_stores/{id}\";\n }\n if (pathname.startsWith(VECTOR_STORES_PREFIX)) {\n return VECTOR_STORES_OTHER_LABEL;\n }\n\n // fal.ai: see the namespace note above. Queue-request rules read before the\n // path-mirror rule because `/fal/queue/requests/…` also matches the mirror\n // RE's `.+/requests/` shape; both would label correctly, but the specific\n // rule reading first keeps the cascade legible.\n if (FAL_ROUTE_RE.test(pathname)) {\n const queueRequest = pathname.match(FAL_QUEUE_REQUEST_RE);\n if (queueRequest) {\n return `/fal/queue/requests/{id}${falRequestSuffix(queueRequest[1])}`;\n }\n if (FAL_QUEUE_SUBMIT_RE.test(pathname)) return \"/fal/queue/submit/{model}\";\n if (FAL_RUN_RE.test(pathname)) return \"/fal/run/{model}\";\n const mirrorRequest = pathname.match(FAL_MIRROR_REQUEST_RE);\n if (mirrorRequest) {\n return `/fal/{model}/requests/{id}${falRequestSuffix(mirrorRequest[1])}`;\n }\n return FAL_OTHER_LABEL;\n }\n\n // ElevenLabs Music: known actions verbatim, anything else collapses.\n if (pathname.startsWith(MUSIC_PREFIX)) {\n return MUSIC_ACTIONS.has(pathname.slice(MUSIC_PREFIX.length)) ? pathname : MUSIC_OTHER_LABEL;\n }\n\n // Fine-tuning. Handled as one closed namespace rather than a few loose REs:\n // the cascade is entered by prefix and always returns, so no fine-tuning path\n // can reach the verbatim return at the bottom of this function.\n //\n // Order matters twice. The id-bearing permission rule reads before the\n // checkpoint sub-resource rule, because `…/permissions/{id}` would otherwise\n // never be reached (its own second segment is the id). Within each family the\n // sub-resource rule reads before the id rule; the id REs are anchored to a\n // single trailing segment so the two cannot both match, but the more specific\n // path reading first is what makes the cascade legible.\n if (pathname.startsWith(FINE_TUNING_PREFIX)) {\n if (FINE_TUNING_STATIC_PATHS.has(pathname)) return pathname;\n\n const ftSubresource = pathname.match(FINE_TUNING_SUBRESOURCE_RE);\n if (ftSubresource) {\n const action = FINE_TUNING_SUBRESOURCES.has(ftSubresource[1]) ? ftSubresource[1] : \"{action}\";\n return `/v1/fine_tuning/jobs/{id}/${action}`;\n }\n if (FINE_TUNING_ID_RE.test(pathname)) return \"/v1/fine_tuning/jobs/{id}\";\n\n if (FINE_TUNING_PERMISSION_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}/permissions/{id}\";\n }\n const ckptSubresource = pathname.match(FINE_TUNING_CHECKPOINT_SUBRESOURCE_RE);\n if (ckptSubresource) {\n const action = FINE_TUNING_CHECKPOINT_SUBRESOURCES.has(ckptSubresource[1])\n ? ckptSubresource[1]\n : \"{action}\";\n return `/v1/fine_tuning/checkpoints/{ckpt}/${action}`;\n }\n if (FINE_TUNING_CHECKPOINT_ID_RE.test(pathname)) {\n return \"/v1/fine_tuning/checkpoints/{ckpt}\";\n }\n\n return FINE_TUNING_OTHER_LABEL;\n }\n\n // Static path — verbatim only if server.ts routes it. Anything else is, as\n // far as metrics can tell, caller-controlled text, whatever status it got\n // (404, a 204 preflight, a destroyed response); every routed id path that\n // can legitimately 404 has already returned its placeholder label above.\n return STATIC_ROUTE_PATHS.has(pathname) ? pathname : UNKNOWN_PATH_LABEL;\n}\n\nfunction falRequestSuffix(sub: string | undefined): string {\n if (sub === undefined) return \"\";\n return FAL_REQUEST_SUBRESOURCES.has(sub) ?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AE;AAC3C,MAAI,yBAAyB,IAAI,SAAS,CAAE,QAAO;EAEnD,MAAM,gBAAgB,SAAS,MAAM,2BAA2B;AAChE,MAAI,cAEF,QAAO,6BADQ,yBAAyB,IAAI,cAAc,GAAG,GAAG,cAAc,KAAK;AAGrF,MAAI,kBAAkB,KAAK,SAAS,CAAE,QAAO;AAE7C,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;EAET,MAAM,kBAAkB,SAAS,MAAM,sCAAsC;AAC7E,MAAI,gBAIF,QAAO,sCAHQ,oCAAoC,IAAI,gBAAgB,GAAG,GACtE,gBAAgB,KAChB;AAGN,MAAI,6BAA6B,KAAK,SAAS,CAC7C,QAAO;AAGT,SAAO;;AAOT,QAAO,mBAAmB,IAAI,SAAS,GAAG,WAAW;;AAGvD,SAAS,iBAAiB,KAAiC;AACzD,KAAI,QAAQ,OAAW,QAAO;AAC9B,QAAO,yBAAyB,IAAI,IAAI,GAAG,IAAI,QAAQ"}
@@ -76,4 +76,5 @@ function isReasoningModel(model) {
76
76
  //#endregion
77
77
  exports.isReasoningModel = isReasoningModel;
78
78
  exports.normalizeModelName = normalizeModelName;
79
+ exports.stripProviderPrefix = stripProviderPrefix;
79
80
  //# sourceMappingURL=model-utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-utils.cjs","names":[],"sources":["../src/model-utils.ts"],"sourcesContent":["const DATE_SUFFIX_RE = /[-](\\d{8}(-v\\d+([:.]\\d+)*)?)$|[-]\\d{4}-\\d{2}-\\d{2}$/;\n\nexport function normalizeModelName(\n model: string | undefined,\n skipNormalization?: boolean,\n): string | undefined {\n if (!model || skipNormalization) return model;\n return model.replace(DATE_SUFFIX_RE, \"\");\n}\n\n// ─── Reasoning-capability map ───────────────────────────────────────────────\n//\n// `isReasoningModel` answers: \"would the REAL provider for this model id emit a\n// reasoning/thinking channel?\" aimock uses it to gate synthesized reasoning so a\n// fixture's `reasoning` field is not replayed for a model that cannot reason\n// (the gpt-4.1 false-green described in aimock#254).\n//\n// Policy (see the #254 spec for the full rationale):\n// - The KNOWN-NON-REASONING list (NONREASONING_FAMILIES) is the load-bearing\n// guard. A match there → false.\n// - The reasoning list (REASONING_FAMILIES) is mostly documentation; because\n// unknown ids default to `true` it is not load-bearing for correctness.\n// - UNKNOWN id → true (assume reasoning-capable). A false negative silently\n// breaks legitimate replays and is hard to notice; a false positive merely\n// fails to catch one mis-wiring class. Failing open keeps the blast radius\n// small and bounds maintenance to the explicit non-reasoning list.\n//\n// Env overrides let users correct drift without a release:\n// AIMOCK_REASONING_MODELS — comma-separated ids/prefixes forced capable.\n// AIMOCK_NONREASONING_MODELS — comma-separated ids/prefixes forced incapable.\n// Env entries are normalized IDENTICALLY to the incoming model id (date suffix\n// + provider/region prefix stripped, lowercased) so a prefixed entry such as\n// `anthropic.claude-opus-4` matches the already-stripped id.\n//\n// Precedence is BETWEEN lists, enforced by the sequential `if` checks below:\n// env-nonreasoning > env-reasoning > built-in-nonreasoning > built-in-reasoning > unknown(true)\n// Within any single list the result is order-INDEPENDENT — `matchesAny` uses\n// `Array.some(startsWith)`, so any prefix match yields that list's verdict.\n\n// Known non-reasoning families — the load-bearing denylist. Entries are matched\n// as prefixes against the normalized, lowercased, provider-stripped model id.\n// Order within this list does not matter (see `matchesAny`): any prefix that\n// matches the id produces `false`.\nconst NONREASONING_FAMILIES = [\n \"gpt-4.1\", // the exact model from aimock#254 (covers -mini / -nano)\n \"gpt-4o\", // covers gpt-4o-mini\n \"gpt-4-turbo\",\n \"gpt-4\", // plain gpt-4; order-independent, and prefix-safe since longer ids (gpt-4.1/gpt-4o/gpt-4-turbo) are also denylisted\n \"gpt-3.5\",\n \"claude-3-5-\", // Sonnet/Haiku 3.5 — no extended thinking\n \"claude-3-haiku\",\n \"claude-3-opus\",\n \"claude-3-sonnet\",\n \"gemini-1.5-\",\n];\n\n// Reasoning-capable families (informational; unknown already defaults to true).\nconst REASONING_FAMILIES = [\n \"o1\",\n \"o3\",\n \"o4\",\n \"gpt-5\",\n \"deepseek-r1\",\n \"deepseek-reasoner\",\n \"claude-3-7-sonnet\",\n \"claude-opus-4\",\n \"claude-sonnet-4\",\n \"claude-haiku-4\",\n \"gpt-oss\",\n \"gemini-2.5-pro\",\n \"gemini-2.5-flash\",\n \"gemini-2.0-flash-thinking\",\n \"qwq\",\n \"qwen3\",\n];\n\n/**\n * Strip a leading provider segment that Bedrock (and similar) prepend before\n * the actual family token — e.g. `anthropic.`, `us.anthropic.`, `eu.`. Keeps\n * everything from the recognised family token onward so prefix matching works.\n */\nfunction stripProviderPrefix(id: string): string {\n // Remove leading region/provider segments (dot-separated) until we hit the\n // model token. Provider/region segments never contain a hyphen, whereas\n // model families do (e.g. `claude-3-5-sonnet`, `gpt-4.1`). So drop any\n // leading dot-separated segment that has no hyphen.\n let rest = id;\n while (true) {\n const dot = rest.indexOf(\".\");\n if (dot === -1) break;\n const head = rest.slice(0, dot);\n if (head.length === 0 || head.includes(\"-\")) break;\n rest = rest.slice(dot + 1);\n }\n return rest;\n}\n\n// Normalize each comma-separated env entry IDENTICALLY to the incoming model id\n// (date-suffix + provider/region prefix stripped, lowercased) so a prefixed\n// entry such as `anthropic.claude-opus-4` matches the already-stripped id.\nfunction parseEnvList(raw: string | undefined): string[] {\n if (!raw) return [];\n return raw\n .split(\",\")\n .map((s) => stripProviderPrefix(normalizeModelName(s.trim())?.toLowerCase() ?? \"\"))\n .filter((s) => s.length > 0);\n}\n\nfunction matchesAny(id: string, families: readonly string[]): boolean {\n return families.some((fam) => id.startsWith(fam));\n}\n\n/**\n * Returns whether the real provider for `model` would emit a reasoning/thinking\n * channel. Absence of a model id, or an unrecognised id, defaults to `true`\n * (assume capable) — see the policy note above.\n */\nexport function isReasoningModel(model: string | undefined): boolean {\n if (!model) return true;\n\n const normalized = normalizeModelName(model)?.toLowerCase() ?? \"\";\n const id = stripProviderPrefix(normalized);\n\n // Env overrides win, parsed fresh so they remain test-stubbable.\n const envNon = parseEnvList(process.env.AIMOCK_NONREASONING_MODELS);\n if (matchesAny(id, envNon)) return false;\n const envReasoning = parseEnvList(process.env.AIMOCK_REASONING_MODELS);\n if (matchesAny(id, envReasoning)) return true;\n\n // Built-in denylist is the active guard.\n if (matchesAny(id, NONREASONING_FAMILIES)) return false;\n // Built-in reasoning list short-circuits to capable.\n if (matchesAny(id, REASONING_FAMILIES)) return true;\n\n // Unknown → assume reasoning-capable (fail open).\n return true;\n}\n"],"mappings":";;AAAA,MAAM,iBAAiB;AAEvB,SAAgB,mBACd,OACA,mBACoB;AACpB,KAAI,CAAC,SAAS,kBAAmB,QAAO;AACxC,QAAO,MAAM,QAAQ,gBAAgB,GAAG;;AAoC1C,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAGD,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;AAOD,SAAS,oBAAoB,IAAoB;CAK/C,IAAI,OAAO;AACX,QAAO,MAAM;EACX,MAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI;EAChB,MAAM,OAAO,KAAK,MAAM,GAAG,IAAI;AAC/B,MAAI,KAAK,WAAW,KAAK,KAAK,SAAS,IAAI,CAAE;AAC7C,SAAO,KAAK,MAAM,MAAM,EAAE;;AAE5B,QAAO;;AAMT,SAAS,aAAa,KAAmC;AACvD,KAAI,CAAC,IAAK,QAAO,EAAE;AACnB,QAAO,IACJ,MAAM,IAAI,CACV,KAAK,MAAM,oBAAoB,mBAAmB,EAAE,MAAM,CAAC,EAAE,aAAa,IAAI,GAAG,CAAC,CAClF,QAAQ,MAAM,EAAE,SAAS,EAAE;;AAGhC,SAAS,WAAW,IAAY,UAAsC;AACpE,QAAO,SAAS,MAAM,QAAQ,GAAG,WAAW,IAAI,CAAC;;;;;;;AAQnD,SAAgB,iBAAiB,OAAoC;AACnE,KAAI,CAAC,MAAO,QAAO;CAGnB,MAAM,KAAK,oBADQ,mBAAmB,MAAM,EAAE,aAAa,IAAI,GACrB;AAI1C,KAAI,WAAW,IADA,aAAa,QAAQ,IAAI,2BAA2B,CACzC,CAAE,QAAO;AAEnC,KAAI,WAAW,IADM,aAAa,QAAQ,IAAI,wBAAwB,CACtC,CAAE,QAAO;AAGzC,KAAI,WAAW,IAAI,sBAAsB,CAAE,QAAO;AAElD,KAAI,WAAW,IAAI,mBAAmB,CAAE,QAAO;AAG/C,QAAO"}
1
+ {"version":3,"file":"model-utils.cjs","names":[],"sources":["../src/model-utils.ts"],"sourcesContent":["const DATE_SUFFIX_RE = /[-](\\d{8}(-v\\d+([:.]\\d+)*)?)$|[-]\\d{4}-\\d{2}-\\d{2}$/;\n\nexport function normalizeModelName(\n model: string | undefined,\n skipNormalization?: boolean,\n): string | undefined {\n if (!model || skipNormalization) return model;\n return model.replace(DATE_SUFFIX_RE, \"\");\n}\n\n// ─── Reasoning-capability map ───────────────────────────────────────────────\n//\n// `isReasoningModel` answers: \"would the REAL provider for this model id emit a\n// reasoning/thinking channel?\" aimock uses it to gate synthesized reasoning so a\n// fixture's `reasoning` field is not replayed for a model that cannot reason\n// (the gpt-4.1 false-green described in aimock#254).\n//\n// Policy (see the #254 spec for the full rationale):\n// - The KNOWN-NON-REASONING list (NONREASONING_FAMILIES) is the load-bearing\n// guard. A match there → false.\n// - The reasoning list (REASONING_FAMILIES) is mostly documentation; because\n// unknown ids default to `true` it is not load-bearing for correctness.\n// - UNKNOWN id → true (assume reasoning-capable). A false negative silently\n// breaks legitimate replays and is hard to notice; a false positive merely\n// fails to catch one mis-wiring class. Failing open keeps the blast radius\n// small and bounds maintenance to the explicit non-reasoning list.\n//\n// Env overrides let users correct drift without a release:\n// AIMOCK_REASONING_MODELS — comma-separated ids/prefixes forced capable.\n// AIMOCK_NONREASONING_MODELS — comma-separated ids/prefixes forced incapable.\n// Env entries are normalized IDENTICALLY to the incoming model id (date suffix\n// + provider/region prefix stripped, lowercased) so a prefixed entry such as\n// `anthropic.claude-opus-4` matches the already-stripped id.\n//\n// Precedence is BETWEEN lists, enforced by the sequential `if` checks below:\n// env-nonreasoning > env-reasoning > built-in-nonreasoning > built-in-reasoning > unknown(true)\n// Within any single list the result is order-INDEPENDENT — `matchesAny` uses\n// `Array.some(startsWith)`, so any prefix match yields that list's verdict.\n\n// Known non-reasoning families — the load-bearing denylist. Entries are matched\n// as prefixes against the normalized, lowercased, provider-stripped model id.\n// Order within this list does not matter (see `matchesAny`): any prefix that\n// matches the id produces `false`.\nconst NONREASONING_FAMILIES = [\n \"gpt-4.1\", // the exact model from aimock#254 (covers -mini / -nano)\n \"gpt-4o\", // covers gpt-4o-mini\n \"gpt-4-turbo\",\n \"gpt-4\", // plain gpt-4; order-independent, and prefix-safe since longer ids (gpt-4.1/gpt-4o/gpt-4-turbo) are also denylisted\n \"gpt-3.5\",\n \"claude-3-5-\", // Sonnet/Haiku 3.5 — no extended thinking\n \"claude-3-haiku\",\n \"claude-3-opus\",\n \"claude-3-sonnet\",\n \"gemini-1.5-\",\n];\n\n// Reasoning-capable families (informational; unknown already defaults to true).\nconst REASONING_FAMILIES = [\n \"o1\",\n \"o3\",\n \"o4\",\n \"gpt-5\",\n \"deepseek-r1\",\n \"deepseek-reasoner\",\n \"claude-3-7-sonnet\",\n \"claude-opus-4\",\n \"claude-sonnet-4\",\n \"claude-haiku-4\",\n \"gpt-oss\",\n \"gemini-2.5-pro\",\n \"gemini-2.5-flash\",\n \"gemini-2.0-flash-thinking\",\n \"qwq\",\n \"qwen3\",\n];\n\n/**\n * Strip a leading provider segment that Bedrock (and similar) prepend before\n * the actual family token — e.g. `anthropic.`, `us.anthropic.`, `eu.`. Keeps\n * everything from the recognised family token onward so prefix matching works.\n */\nexport function stripProviderPrefix(id: string): string {\n // Remove leading region/provider segments (dot-separated) until we hit the\n // model token. Provider/region segments never contain a hyphen, whereas\n // model families do (e.g. `claude-3-5-sonnet`, `gpt-4.1`). So drop any\n // leading dot-separated segment that has no hyphen.\n let rest = id;\n while (true) {\n const dot = rest.indexOf(\".\");\n if (dot === -1) break;\n const head = rest.slice(0, dot);\n if (head.length === 0 || head.includes(\"-\")) break;\n rest = rest.slice(dot + 1);\n }\n return rest;\n}\n\n// Normalize each comma-separated env entry IDENTICALLY to the incoming model id\n// (date-suffix + provider/region prefix stripped, lowercased) so a prefixed\n// entry such as `anthropic.claude-opus-4` matches the already-stripped id.\nfunction parseEnvList(raw: string | undefined): string[] {\n if (!raw) return [];\n return raw\n .split(\",\")\n .map((s) => stripProviderPrefix(normalizeModelName(s.trim())?.toLowerCase() ?? \"\"))\n .filter((s) => s.length > 0);\n}\n\nfunction matchesAny(id: string, families: readonly string[]): boolean {\n return families.some((fam) => id.startsWith(fam));\n}\n\n/**\n * Returns whether the real provider for `model` would emit a reasoning/thinking\n * channel. Absence of a model id, or an unrecognised id, defaults to `true`\n * (assume capable) — see the policy note above.\n */\nexport function isReasoningModel(model: string | undefined): boolean {\n if (!model) return true;\n\n const normalized = normalizeModelName(model)?.toLowerCase() ?? \"\";\n const id = stripProviderPrefix(normalized);\n\n // Env overrides win, parsed fresh so they remain test-stubbable.\n const envNon = parseEnvList(process.env.AIMOCK_NONREASONING_MODELS);\n if (matchesAny(id, envNon)) return false;\n const envReasoning = parseEnvList(process.env.AIMOCK_REASONING_MODELS);\n if (matchesAny(id, envReasoning)) return true;\n\n // Built-in denylist is the active guard.\n if (matchesAny(id, NONREASONING_FAMILIES)) return false;\n // Built-in reasoning list short-circuits to capable.\n if (matchesAny(id, REASONING_FAMILIES)) return true;\n\n // Unknown → assume reasoning-capable (fail open).\n return true;\n}\n"],"mappings":";;AAAA,MAAM,iBAAiB;AAEvB,SAAgB,mBACd,OACA,mBACoB;AACpB,KAAI,CAAC,SAAS,kBAAmB,QAAO;AACxC,QAAO,MAAM,QAAQ,gBAAgB,GAAG;;AAoC1C,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAGD,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;AAOD,SAAgB,oBAAoB,IAAoB;CAKtD,IAAI,OAAO;AACX,QAAO,MAAM;EACX,MAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI;EAChB,MAAM,OAAO,KAAK,MAAM,GAAG,IAAI;AAC/B,MAAI,KAAK,WAAW,KAAK,KAAK,SAAS,IAAI,CAAE;AAC7C,SAAO,KAAK,MAAM,MAAM,EAAE;;AAE5B,QAAO;;AAMT,SAAS,aAAa,KAAmC;AACvD,KAAI,CAAC,IAAK,QAAO,EAAE;AACnB,QAAO,IACJ,MAAM,IAAI,CACV,KAAK,MAAM,oBAAoB,mBAAmB,EAAE,MAAM,CAAC,EAAE,aAAa,IAAI,GAAG,CAAC,CAClF,QAAQ,MAAM,EAAE,SAAS,EAAE;;AAGhC,SAAS,WAAW,IAAY,UAAsC;AACpE,QAAO,SAAS,MAAM,QAAQ,GAAG,WAAW,IAAI,CAAC;;;;;;;AAQnD,SAAgB,iBAAiB,OAAoC;AACnE,KAAI,CAAC,MAAO,QAAO;CAGnB,MAAM,KAAK,oBADQ,mBAAmB,MAAM,EAAE,aAAa,IAAI,GACrB;AAI1C,KAAI,WAAW,IADA,aAAa,QAAQ,IAAI,2BAA2B,CACzC,CAAE,QAAO;AAEnC,KAAI,WAAW,IADM,aAAa,QAAQ,IAAI,wBAAwB,CACtC,CAAE,QAAO;AAGzC,KAAI,WAAW,IAAI,sBAAsB,CAAE,QAAO;AAElD,KAAI,WAAW,IAAI,mBAAmB,CAAE,QAAO;AAG/C,QAAO"}
@@ -73,5 +73,5 @@ function isReasoningModel(model) {
73
73
  }
74
74
 
75
75
  //#endregion
76
- export { isReasoningModel, normalizeModelName };
76
+ export { isReasoningModel, normalizeModelName, stripProviderPrefix };
77
77
  //# sourceMappingURL=model-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-utils.js","names":[],"sources":["../src/model-utils.ts"],"sourcesContent":["const DATE_SUFFIX_RE = /[-](\\d{8}(-v\\d+([:.]\\d+)*)?)$|[-]\\d{4}-\\d{2}-\\d{2}$/;\n\nexport function normalizeModelName(\n model: string | undefined,\n skipNormalization?: boolean,\n): string | undefined {\n if (!model || skipNormalization) return model;\n return model.replace(DATE_SUFFIX_RE, \"\");\n}\n\n// ─── Reasoning-capability map ───────────────────────────────────────────────\n//\n// `isReasoningModel` answers: \"would the REAL provider for this model id emit a\n// reasoning/thinking channel?\" aimock uses it to gate synthesized reasoning so a\n// fixture's `reasoning` field is not replayed for a model that cannot reason\n// (the gpt-4.1 false-green described in aimock#254).\n//\n// Policy (see the #254 spec for the full rationale):\n// - The KNOWN-NON-REASONING list (NONREASONING_FAMILIES) is the load-bearing\n// guard. A match there → false.\n// - The reasoning list (REASONING_FAMILIES) is mostly documentation; because\n// unknown ids default to `true` it is not load-bearing for correctness.\n// - UNKNOWN id → true (assume reasoning-capable). A false negative silently\n// breaks legitimate replays and is hard to notice; a false positive merely\n// fails to catch one mis-wiring class. Failing open keeps the blast radius\n// small and bounds maintenance to the explicit non-reasoning list.\n//\n// Env overrides let users correct drift without a release:\n// AIMOCK_REASONING_MODELS — comma-separated ids/prefixes forced capable.\n// AIMOCK_NONREASONING_MODELS — comma-separated ids/prefixes forced incapable.\n// Env entries are normalized IDENTICALLY to the incoming model id (date suffix\n// + provider/region prefix stripped, lowercased) so a prefixed entry such as\n// `anthropic.claude-opus-4` matches the already-stripped id.\n//\n// Precedence is BETWEEN lists, enforced by the sequential `if` checks below:\n// env-nonreasoning > env-reasoning > built-in-nonreasoning > built-in-reasoning > unknown(true)\n// Within any single list the result is order-INDEPENDENT — `matchesAny` uses\n// `Array.some(startsWith)`, so any prefix match yields that list's verdict.\n\n// Known non-reasoning families — the load-bearing denylist. Entries are matched\n// as prefixes against the normalized, lowercased, provider-stripped model id.\n// Order within this list does not matter (see `matchesAny`): any prefix that\n// matches the id produces `false`.\nconst NONREASONING_FAMILIES = [\n \"gpt-4.1\", // the exact model from aimock#254 (covers -mini / -nano)\n \"gpt-4o\", // covers gpt-4o-mini\n \"gpt-4-turbo\",\n \"gpt-4\", // plain gpt-4; order-independent, and prefix-safe since longer ids (gpt-4.1/gpt-4o/gpt-4-turbo) are also denylisted\n \"gpt-3.5\",\n \"claude-3-5-\", // Sonnet/Haiku 3.5 — no extended thinking\n \"claude-3-haiku\",\n \"claude-3-opus\",\n \"claude-3-sonnet\",\n \"gemini-1.5-\",\n];\n\n// Reasoning-capable families (informational; unknown already defaults to true).\nconst REASONING_FAMILIES = [\n \"o1\",\n \"o3\",\n \"o4\",\n \"gpt-5\",\n \"deepseek-r1\",\n \"deepseek-reasoner\",\n \"claude-3-7-sonnet\",\n \"claude-opus-4\",\n \"claude-sonnet-4\",\n \"claude-haiku-4\",\n \"gpt-oss\",\n \"gemini-2.5-pro\",\n \"gemini-2.5-flash\",\n \"gemini-2.0-flash-thinking\",\n \"qwq\",\n \"qwen3\",\n];\n\n/**\n * Strip a leading provider segment that Bedrock (and similar) prepend before\n * the actual family token — e.g. `anthropic.`, `us.anthropic.`, `eu.`. Keeps\n * everything from the recognised family token onward so prefix matching works.\n */\nfunction stripProviderPrefix(id: string): string {\n // Remove leading region/provider segments (dot-separated) until we hit the\n // model token. Provider/region segments never contain a hyphen, whereas\n // model families do (e.g. `claude-3-5-sonnet`, `gpt-4.1`). So drop any\n // leading dot-separated segment that has no hyphen.\n let rest = id;\n while (true) {\n const dot = rest.indexOf(\".\");\n if (dot === -1) break;\n const head = rest.slice(0, dot);\n if (head.length === 0 || head.includes(\"-\")) break;\n rest = rest.slice(dot + 1);\n }\n return rest;\n}\n\n// Normalize each comma-separated env entry IDENTICALLY to the incoming model id\n// (date-suffix + provider/region prefix stripped, lowercased) so a prefixed\n// entry such as `anthropic.claude-opus-4` matches the already-stripped id.\nfunction parseEnvList(raw: string | undefined): string[] {\n if (!raw) return [];\n return raw\n .split(\",\")\n .map((s) => stripProviderPrefix(normalizeModelName(s.trim())?.toLowerCase() ?? \"\"))\n .filter((s) => s.length > 0);\n}\n\nfunction matchesAny(id: string, families: readonly string[]): boolean {\n return families.some((fam) => id.startsWith(fam));\n}\n\n/**\n * Returns whether the real provider for `model` would emit a reasoning/thinking\n * channel. Absence of a model id, or an unrecognised id, defaults to `true`\n * (assume capable) — see the policy note above.\n */\nexport function isReasoningModel(model: string | undefined): boolean {\n if (!model) return true;\n\n const normalized = normalizeModelName(model)?.toLowerCase() ?? \"\";\n const id = stripProviderPrefix(normalized);\n\n // Env overrides win, parsed fresh so they remain test-stubbable.\n const envNon = parseEnvList(process.env.AIMOCK_NONREASONING_MODELS);\n if (matchesAny(id, envNon)) return false;\n const envReasoning = parseEnvList(process.env.AIMOCK_REASONING_MODELS);\n if (matchesAny(id, envReasoning)) return true;\n\n // Built-in denylist is the active guard.\n if (matchesAny(id, NONREASONING_FAMILIES)) return false;\n // Built-in reasoning list short-circuits to capable.\n if (matchesAny(id, REASONING_FAMILIES)) return true;\n\n // Unknown → assume reasoning-capable (fail open).\n return true;\n}\n"],"mappings":";AAAA,MAAM,iBAAiB;AAEvB,SAAgB,mBACd,OACA,mBACoB;AACpB,KAAI,CAAC,SAAS,kBAAmB,QAAO;AACxC,QAAO,MAAM,QAAQ,gBAAgB,GAAG;;AAoC1C,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAGD,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;AAOD,SAAS,oBAAoB,IAAoB;CAK/C,IAAI,OAAO;AACX,QAAO,MAAM;EACX,MAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI;EAChB,MAAM,OAAO,KAAK,MAAM,GAAG,IAAI;AAC/B,MAAI,KAAK,WAAW,KAAK,KAAK,SAAS,IAAI,CAAE;AAC7C,SAAO,KAAK,MAAM,MAAM,EAAE;;AAE5B,QAAO;;AAMT,SAAS,aAAa,KAAmC;AACvD,KAAI,CAAC,IAAK,QAAO,EAAE;AACnB,QAAO,IACJ,MAAM,IAAI,CACV,KAAK,MAAM,oBAAoB,mBAAmB,EAAE,MAAM,CAAC,EAAE,aAAa,IAAI,GAAG,CAAC,CAClF,QAAQ,MAAM,EAAE,SAAS,EAAE;;AAGhC,SAAS,WAAW,IAAY,UAAsC;AACpE,QAAO,SAAS,MAAM,QAAQ,GAAG,WAAW,IAAI,CAAC;;;;;;;AAQnD,SAAgB,iBAAiB,OAAoC;AACnE,KAAI,CAAC,MAAO,QAAO;CAGnB,MAAM,KAAK,oBADQ,mBAAmB,MAAM,EAAE,aAAa,IAAI,GACrB;AAI1C,KAAI,WAAW,IADA,aAAa,QAAQ,IAAI,2BAA2B,CACzC,CAAE,QAAO;AAEnC,KAAI,WAAW,IADM,aAAa,QAAQ,IAAI,wBAAwB,CACtC,CAAE,QAAO;AAGzC,KAAI,WAAW,IAAI,sBAAsB,CAAE,QAAO;AAElD,KAAI,WAAW,IAAI,mBAAmB,CAAE,QAAO;AAG/C,QAAO"}
1
+ {"version":3,"file":"model-utils.js","names":[],"sources":["../src/model-utils.ts"],"sourcesContent":["const DATE_SUFFIX_RE = /[-](\\d{8}(-v\\d+([:.]\\d+)*)?)$|[-]\\d{4}-\\d{2}-\\d{2}$/;\n\nexport function normalizeModelName(\n model: string | undefined,\n skipNormalization?: boolean,\n): string | undefined {\n if (!model || skipNormalization) return model;\n return model.replace(DATE_SUFFIX_RE, \"\");\n}\n\n// ─── Reasoning-capability map ───────────────────────────────────────────────\n//\n// `isReasoningModel` answers: \"would the REAL provider for this model id emit a\n// reasoning/thinking channel?\" aimock uses it to gate synthesized reasoning so a\n// fixture's `reasoning` field is not replayed for a model that cannot reason\n// (the gpt-4.1 false-green described in aimock#254).\n//\n// Policy (see the #254 spec for the full rationale):\n// - The KNOWN-NON-REASONING list (NONREASONING_FAMILIES) is the load-bearing\n// guard. A match there → false.\n// - The reasoning list (REASONING_FAMILIES) is mostly documentation; because\n// unknown ids default to `true` it is not load-bearing for correctness.\n// - UNKNOWN id → true (assume reasoning-capable). A false negative silently\n// breaks legitimate replays and is hard to notice; a false positive merely\n// fails to catch one mis-wiring class. Failing open keeps the blast radius\n// small and bounds maintenance to the explicit non-reasoning list.\n//\n// Env overrides let users correct drift without a release:\n// AIMOCK_REASONING_MODELS — comma-separated ids/prefixes forced capable.\n// AIMOCK_NONREASONING_MODELS — comma-separated ids/prefixes forced incapable.\n// Env entries are normalized IDENTICALLY to the incoming model id (date suffix\n// + provider/region prefix stripped, lowercased) so a prefixed entry such as\n// `anthropic.claude-opus-4` matches the already-stripped id.\n//\n// Precedence is BETWEEN lists, enforced by the sequential `if` checks below:\n// env-nonreasoning > env-reasoning > built-in-nonreasoning > built-in-reasoning > unknown(true)\n// Within any single list the result is order-INDEPENDENT — `matchesAny` uses\n// `Array.some(startsWith)`, so any prefix match yields that list's verdict.\n\n// Known non-reasoning families — the load-bearing denylist. Entries are matched\n// as prefixes against the normalized, lowercased, provider-stripped model id.\n// Order within this list does not matter (see `matchesAny`): any prefix that\n// matches the id produces `false`.\nconst NONREASONING_FAMILIES = [\n \"gpt-4.1\", // the exact model from aimock#254 (covers -mini / -nano)\n \"gpt-4o\", // covers gpt-4o-mini\n \"gpt-4-turbo\",\n \"gpt-4\", // plain gpt-4; order-independent, and prefix-safe since longer ids (gpt-4.1/gpt-4o/gpt-4-turbo) are also denylisted\n \"gpt-3.5\",\n \"claude-3-5-\", // Sonnet/Haiku 3.5 — no extended thinking\n \"claude-3-haiku\",\n \"claude-3-opus\",\n \"claude-3-sonnet\",\n \"gemini-1.5-\",\n];\n\n// Reasoning-capable families (informational; unknown already defaults to true).\nconst REASONING_FAMILIES = [\n \"o1\",\n \"o3\",\n \"o4\",\n \"gpt-5\",\n \"deepseek-r1\",\n \"deepseek-reasoner\",\n \"claude-3-7-sonnet\",\n \"claude-opus-4\",\n \"claude-sonnet-4\",\n \"claude-haiku-4\",\n \"gpt-oss\",\n \"gemini-2.5-pro\",\n \"gemini-2.5-flash\",\n \"gemini-2.0-flash-thinking\",\n \"qwq\",\n \"qwen3\",\n];\n\n/**\n * Strip a leading provider segment that Bedrock (and similar) prepend before\n * the actual family token — e.g. `anthropic.`, `us.anthropic.`, `eu.`. Keeps\n * everything from the recognised family token onward so prefix matching works.\n */\nexport function stripProviderPrefix(id: string): string {\n // Remove leading region/provider segments (dot-separated) until we hit the\n // model token. Provider/region segments never contain a hyphen, whereas\n // model families do (e.g. `claude-3-5-sonnet`, `gpt-4.1`). So drop any\n // leading dot-separated segment that has no hyphen.\n let rest = id;\n while (true) {\n const dot = rest.indexOf(\".\");\n if (dot === -1) break;\n const head = rest.slice(0, dot);\n if (head.length === 0 || head.includes(\"-\")) break;\n rest = rest.slice(dot + 1);\n }\n return rest;\n}\n\n// Normalize each comma-separated env entry IDENTICALLY to the incoming model id\n// (date-suffix + provider/region prefix stripped, lowercased) so a prefixed\n// entry such as `anthropic.claude-opus-4` matches the already-stripped id.\nfunction parseEnvList(raw: string | undefined): string[] {\n if (!raw) return [];\n return raw\n .split(\",\")\n .map((s) => stripProviderPrefix(normalizeModelName(s.trim())?.toLowerCase() ?? \"\"))\n .filter((s) => s.length > 0);\n}\n\nfunction matchesAny(id: string, families: readonly string[]): boolean {\n return families.some((fam) => id.startsWith(fam));\n}\n\n/**\n * Returns whether the real provider for `model` would emit a reasoning/thinking\n * channel. Absence of a model id, or an unrecognised id, defaults to `true`\n * (assume capable) — see the policy note above.\n */\nexport function isReasoningModel(model: string | undefined): boolean {\n if (!model) return true;\n\n const normalized = normalizeModelName(model)?.toLowerCase() ?? \"\";\n const id = stripProviderPrefix(normalized);\n\n // Env overrides win, parsed fresh so they remain test-stubbable.\n const envNon = parseEnvList(process.env.AIMOCK_NONREASONING_MODELS);\n if (matchesAny(id, envNon)) return false;\n const envReasoning = parseEnvList(process.env.AIMOCK_REASONING_MODELS);\n if (matchesAny(id, envReasoning)) return true;\n\n // Built-in denylist is the active guard.\n if (matchesAny(id, NONREASONING_FAMILIES)) return false;\n // Built-in reasoning list short-circuits to capable.\n if (matchesAny(id, REASONING_FAMILIES)) return true;\n\n // Unknown → assume reasoning-capable (fail open).\n return true;\n}\n"],"mappings":";AAAA,MAAM,iBAAiB;AAEvB,SAAgB,mBACd,OACA,mBACoB;AACpB,KAAI,CAAC,SAAS,kBAAmB,QAAO;AACxC,QAAO,MAAM,QAAQ,gBAAgB,GAAG;;AAoC1C,MAAM,wBAAwB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAGD,MAAM,qBAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;AAOD,SAAgB,oBAAoB,IAAoB;CAKtD,IAAI,OAAO;AACX,QAAO,MAAM;EACX,MAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI;EAChB,MAAM,OAAO,KAAK,MAAM,GAAG,IAAI;AAC/B,MAAI,KAAK,WAAW,KAAK,KAAK,SAAS,IAAI,CAAE;AAC7C,SAAO,KAAK,MAAM,MAAM,EAAE;;AAE5B,QAAO;;AAMT,SAAS,aAAa,KAAmC;AACvD,KAAI,CAAC,IAAK,QAAO,EAAE;AACnB,QAAO,IACJ,MAAM,IAAI,CACV,KAAK,MAAM,oBAAoB,mBAAmB,EAAE,MAAM,CAAC,EAAE,aAAa,IAAI,GAAG,CAAC,CAClF,QAAQ,MAAM,EAAE,SAAS,EAAE;;AAGhC,SAAS,WAAW,IAAY,UAAsC;AACpE,QAAO,SAAS,MAAM,QAAQ,GAAG,WAAW,IAAI,CAAC;;;;;;;AAQnD,SAAgB,iBAAiB,OAAoC;AACnE,KAAI,CAAC,MAAO,QAAO;CAGnB,MAAM,KAAK,oBADQ,mBAAmB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