@copilotkit/aimock 1.45.1 → 1.47.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 (492) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +25 -1
  4. package/README.md +11 -2
  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.cts.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/aws-event-stream.cjs +20 -23
  25. package/dist/aws-event-stream.cjs.map +1 -1
  26. package/dist/aws-event-stream.d.cts +0 -1
  27. package/dist/aws-event-stream.d.ts +0 -1
  28. package/dist/aws-event-stream.js +20 -24
  29. package/dist/aws-event-stream.js.map +1 -1
  30. package/dist/batches.cjs +2 -4
  31. package/dist/batches.cjs.map +1 -1
  32. package/dist/batches.d.cts.map +1 -1
  33. package/dist/batches.d.ts.map +1 -1
  34. package/dist/batches.js +2 -4
  35. package/dist/batches.js.map +1 -1
  36. package/dist/bedrock-converse.cjs +139 -161
  37. package/dist/bedrock-converse.cjs.map +1 -1
  38. package/dist/bedrock-converse.d.cts.map +1 -1
  39. package/dist/bedrock-converse.d.ts.map +1 -1
  40. package/dist/bedrock-converse.js +137 -159
  41. package/dist/bedrock-converse.js.map +1 -1
  42. package/dist/bedrock.cjs +175 -216
  43. package/dist/bedrock.cjs.map +1 -1
  44. package/dist/bedrock.d.cts.map +1 -1
  45. package/dist/bedrock.d.ts.map +1 -1
  46. package/dist/bedrock.js +172 -213
  47. package/dist/bedrock.js.map +1 -1
  48. package/dist/byteplus-video.cjs +11 -10
  49. package/dist/byteplus-video.cjs.map +1 -1
  50. package/dist/byteplus-video.d.cts.map +1 -1
  51. package/dist/byteplus-video.d.ts.map +1 -1
  52. package/dist/byteplus-video.js +5 -4
  53. package/dist/byteplus-video.js.map +1 -1
  54. package/dist/chaos.cjs +5 -4
  55. package/dist/chaos.cjs.map +1 -1
  56. package/dist/chaos.d.cts.map +1 -1
  57. package/dist/chaos.d.ts.map +1 -1
  58. package/dist/chaos.js +5 -4
  59. package/dist/chaos.js.map +1 -1
  60. package/dist/cli.cjs +15 -0
  61. package/dist/cli.cjs.map +1 -1
  62. package/dist/cli.js +15 -0
  63. package/dist/cli.js.map +1 -1
  64. package/dist/cohere.cjs +107 -180
  65. package/dist/cohere.cjs.map +1 -1
  66. package/dist/cohere.d.cts.map +1 -1
  67. package/dist/cohere.d.ts.map +1 -1
  68. package/dist/cohere.js +106 -179
  69. package/dist/cohere.js.map +1 -1
  70. package/dist/config-loader.cjs +29 -1
  71. package/dist/config-loader.cjs.map +1 -1
  72. package/dist/config-loader.d.cts +7 -1
  73. package/dist/config-loader.d.cts.map +1 -1
  74. package/dist/config-loader.d.ts +7 -1
  75. package/dist/config-loader.d.ts.map +1 -1
  76. package/dist/config-loader.js +29 -2
  77. package/dist/config-loader.js.map +1 -1
  78. package/dist/count-tokens.cjs +146 -0
  79. package/dist/count-tokens.cjs.map +1 -0
  80. package/dist/count-tokens.js +146 -0
  81. package/dist/count-tokens.js.map +1 -0
  82. package/dist/elevenlabs-audio.cjs +36 -34
  83. package/dist/elevenlabs-audio.cjs.map +1 -1
  84. package/dist/elevenlabs-audio.d.cts.map +1 -1
  85. package/dist/elevenlabs-audio.d.ts.map +1 -1
  86. package/dist/elevenlabs-audio.js +33 -31
  87. package/dist/elevenlabs-audio.js.map +1 -1
  88. package/dist/elevenlabs-voice.cjs +38 -37
  89. package/dist/elevenlabs-voice.cjs.map +1 -1
  90. package/dist/elevenlabs-voice.d.cts.map +1 -1
  91. package/dist/elevenlabs-voice.d.ts.map +1 -1
  92. package/dist/elevenlabs-voice.js +33 -32
  93. package/dist/elevenlabs-voice.js.map +1 -1
  94. package/dist/embedding-request.cjs +16 -0
  95. package/dist/embedding-request.cjs.map +1 -0
  96. package/dist/embedding-request.js +14 -0
  97. package/dist/embedding-request.js.map +1 -0
  98. package/dist/embeddings.cjs +30 -20
  99. package/dist/embeddings.cjs.map +1 -1
  100. package/dist/embeddings.d.cts.map +1 -1
  101. package/dist/embeddings.d.ts.map +1 -1
  102. package/dist/embeddings.js +30 -20
  103. package/dist/embeddings.js.map +1 -1
  104. package/dist/fal-audio.cjs +45 -43
  105. package/dist/fal-audio.cjs.map +1 -1
  106. package/dist/fal-audio.d.cts.map +1 -1
  107. package/dist/fal-audio.d.ts.map +1 -1
  108. package/dist/fal-audio.js +42 -40
  109. package/dist/fal-audio.js.map +1 -1
  110. package/dist/fal.cjs +17 -15
  111. package/dist/fal.cjs.map +1 -1
  112. package/dist/fal.js +16 -14
  113. package/dist/fal.js.map +1 -1
  114. package/dist/files.cjs +2 -4
  115. package/dist/files.cjs.map +1 -1
  116. package/dist/files.d.cts.map +1 -1
  117. package/dist/files.d.ts.map +1 -1
  118. package/dist/files.js +2 -4
  119. package/dist/files.js.map +1 -1
  120. package/dist/fine-tuning.cjs +2 -4
  121. package/dist/fine-tuning.cjs.map +1 -1
  122. package/dist/fine-tuning.d.cts.map +1 -1
  123. package/dist/fine-tuning.d.ts.map +1 -1
  124. package/dist/fine-tuning.js +2 -4
  125. package/dist/fine-tuning.js.map +1 -1
  126. package/dist/fixture-loader.cjs +140 -44
  127. package/dist/fixture-loader.cjs.map +1 -1
  128. package/dist/fixture-loader.d.cts.map +1 -1
  129. package/dist/fixture-loader.d.ts.map +1 -1
  130. package/dist/fixture-loader.js +141 -46
  131. package/dist/fixture-loader.js.map +1 -1
  132. package/dist/gemini-embeddings.cjs +26 -24
  133. package/dist/gemini-embeddings.cjs.map +1 -1
  134. package/dist/gemini-embeddings.js +26 -24
  135. package/dist/gemini-embeddings.js.map +1 -1
  136. package/dist/gemini-interactions.cjs +113 -156
  137. package/dist/gemini-interactions.cjs.map +1 -1
  138. package/dist/gemini-interactions.d.cts +0 -1
  139. package/dist/gemini-interactions.d.cts.map +1 -1
  140. package/dist/gemini-interactions.d.ts +0 -1
  141. package/dist/gemini-interactions.d.ts.map +1 -1
  142. package/dist/gemini-interactions.js +113 -156
  143. package/dist/gemini-interactions.js.map +1 -1
  144. package/dist/gemini.cjs +295 -218
  145. package/dist/gemini.cjs.map +1 -1
  146. package/dist/gemini.d.cts.map +1 -1
  147. package/dist/gemini.d.ts.map +1 -1
  148. package/dist/gemini.js +295 -219
  149. package/dist/gemini.js.map +1 -1
  150. package/dist/grok-video.cjs +14 -12
  151. package/dist/grok-video.cjs.map +1 -1
  152. package/dist/grok-video.d.cts.map +1 -1
  153. package/dist/grok-video.d.ts.map +1 -1
  154. package/dist/grok-video.js +8 -6
  155. package/dist/grok-video.js.map +1 -1
  156. package/dist/helpers.cjs +411 -75
  157. package/dist/helpers.cjs.map +1 -1
  158. package/dist/helpers.d.cts +51 -1
  159. package/dist/helpers.d.cts.map +1 -1
  160. package/dist/helpers.d.ts +51 -1
  161. package/dist/helpers.d.ts.map +1 -1
  162. package/dist/helpers.js +402 -74
  163. package/dist/helpers.js.map +1 -1
  164. package/dist/images.cjs +30 -28
  165. package/dist/images.cjs.map +1 -1
  166. package/dist/images.d.cts.map +1 -1
  167. package/dist/images.d.ts.map +1 -1
  168. package/dist/images.js +27 -25
  169. package/dist/images.js.map +1 -1
  170. package/dist/index.cjs +4 -2
  171. package/dist/index.d.cts +4 -4
  172. package/dist/index.d.ts +4 -4
  173. package/dist/index.js +4 -4
  174. package/dist/journal.cjs +3 -1
  175. package/dist/journal.cjs.map +1 -1
  176. package/dist/journal.d.cts.map +1 -1
  177. package/dist/journal.d.ts.map +1 -1
  178. package/dist/journal.js +2 -1
  179. package/dist/journal.js.map +1 -1
  180. package/dist/llmock.cjs +3 -0
  181. package/dist/llmock.cjs.map +1 -1
  182. package/dist/llmock.d.cts.map +1 -1
  183. package/dist/llmock.d.ts.map +1 -1
  184. package/dist/llmock.js +3 -0
  185. package/dist/llmock.js.map +1 -1
  186. package/dist/mcp-fakes.d.cts.map +1 -1
  187. package/dist/mcp-handler.cjs +7 -3
  188. package/dist/mcp-handler.cjs.map +1 -1
  189. package/dist/mcp-handler.js +7 -3
  190. package/dist/mcp-handler.js.map +1 -1
  191. package/dist/mcp-recorder.cjs +2 -1
  192. package/dist/mcp-recorder.cjs.map +1 -1
  193. package/dist/mcp-recorder.js +3 -2
  194. package/dist/mcp-recorder.js.map +1 -1
  195. package/dist/messages.cjs +235 -202
  196. package/dist/messages.cjs.map +1 -1
  197. package/dist/messages.d.cts.map +1 -1
  198. package/dist/messages.d.ts.map +1 -1
  199. package/dist/messages.js +234 -202
  200. package/dist/messages.js.map +1 -1
  201. package/dist/metrics.cjs +5 -2
  202. package/dist/metrics.cjs.map +1 -1
  203. package/dist/metrics.d.cts.map +1 -1
  204. package/dist/metrics.d.ts.map +1 -1
  205. package/dist/metrics.js +6 -3
  206. package/dist/metrics.js.map +1 -1
  207. package/dist/misbehavior.cjs +62 -3
  208. package/dist/misbehavior.cjs.map +1 -1
  209. package/dist/misbehavior.d.cts.map +1 -1
  210. package/dist/misbehavior.d.ts.map +1 -1
  211. package/dist/misbehavior.js +63 -4
  212. package/dist/misbehavior.js.map +1 -1
  213. package/dist/model-utils.cjs +1 -0
  214. package/dist/model-utils.cjs.map +1 -1
  215. package/dist/model-utils.js +1 -1
  216. package/dist/model-utils.js.map +1 -1
  217. package/dist/moderation.cjs +15 -12
  218. package/dist/moderation.cjs.map +1 -1
  219. package/dist/moderation.js +14 -11
  220. package/dist/moderation.js.map +1 -1
  221. package/dist/ndjson-writer.cjs +21 -23
  222. package/dist/ndjson-writer.cjs.map +1 -1
  223. package/dist/ndjson-writer.d.cts +0 -1
  224. package/dist/ndjson-writer.d.cts.map +1 -1
  225. package/dist/ndjson-writer.d.ts +0 -1
  226. package/dist/ndjson-writer.d.ts.map +1 -1
  227. package/dist/ndjson-writer.js +21 -24
  228. package/dist/ndjson-writer.js.map +1 -1
  229. package/dist/ollama.cjs +276 -210
  230. package/dist/ollama.cjs.map +1 -1
  231. package/dist/ollama.d.cts.map +1 -1
  232. package/dist/ollama.d.ts.map +1 -1
  233. package/dist/ollama.js +273 -207
  234. package/dist/ollama.js.map +1 -1
  235. package/dist/openapi.cjs +323 -3
  236. package/dist/openapi.cjs.map +1 -1
  237. package/dist/openapi.d.cts.map +1 -1
  238. package/dist/openapi.d.ts.map +1 -1
  239. package/dist/openapi.js +324 -4
  240. package/dist/openapi.js.map +1 -1
  241. package/dist/openrouter-chat.cjs +11 -155
  242. package/dist/openrouter-chat.cjs.map +1 -1
  243. package/dist/openrouter-chat.js +11 -155
  244. package/dist/openrouter-chat.js.map +1 -1
  245. package/dist/openrouter-video.cjs +51 -74
  246. package/dist/openrouter-video.cjs.map +1 -1
  247. package/dist/openrouter-video.d.cts.map +1 -1
  248. package/dist/openrouter-video.d.ts.map +1 -1
  249. package/dist/openrouter-video.js +37 -60
  250. package/dist/openrouter-video.js.map +1 -1
  251. package/dist/raw-validation.cjs +177 -0
  252. package/dist/raw-validation.cjs.map +1 -0
  253. package/dist/raw-validation.js +176 -0
  254. package/dist/raw-validation.js.map +1 -0
  255. package/dist/recorder.cjs +176 -95
  256. package/dist/recorder.cjs.map +1 -1
  257. package/dist/recorder.d.cts.map +1 -1
  258. package/dist/recorder.d.ts.map +1 -1
  259. package/dist/recorder.js +176 -95
  260. package/dist/recorder.js.map +1 -1
  261. package/dist/rerank.cjs +13 -11
  262. package/dist/rerank.cjs.map +1 -1
  263. package/dist/rerank.js +12 -10
  264. package/dist/rerank.js.map +1 -1
  265. package/dist/response/catalog/anthropic-page.cjs +39 -0
  266. package/dist/response/catalog/anthropic-page.cjs.map +1 -0
  267. package/dist/response/catalog/anthropic-page.js +38 -0
  268. package/dist/response/catalog/anthropic-page.js.map +1 -0
  269. package/dist/response/catalog/collect.cjs +61 -0
  270. package/dist/response/catalog/collect.cjs.map +1 -0
  271. package/dist/response/catalog/collect.js +59 -0
  272. package/dist/response/catalog/collect.js.map +1 -0
  273. package/dist/response/catalog/gemini-page.cjs +25 -0
  274. package/dist/response/catalog/gemini-page.cjs.map +1 -0
  275. package/dist/response/catalog/gemini-page.js +24 -0
  276. package/dist/response/catalog/gemini-page.js.map +1 -0
  277. package/dist/response/catalog/render.cjs +182 -0
  278. package/dist/response/catalog/render.cjs.map +1 -0
  279. package/dist/response/catalog/render.js +171 -0
  280. package/dist/response/catalog/render.js.map +1 -0
  281. package/dist/response/deliver.cjs +144 -0
  282. package/dist/response/deliver.cjs.map +1 -0
  283. package/dist/response/deliver.js +143 -0
  284. package/dist/response/deliver.js.map +1 -0
  285. package/dist/response/errors.cjs +225 -0
  286. package/dist/response/errors.cjs.map +1 -0
  287. package/dist/response/errors.js +224 -0
  288. package/dist/response/errors.js.map +1 -0
  289. package/dist/response/finish.cjs +39 -0
  290. package/dist/response/finish.cjs.map +1 -0
  291. package/dist/response/finish.js +35 -0
  292. package/dist/response/finish.js.map +1 -0
  293. package/dist/response/frame-loop.cjs +102 -0
  294. package/dist/response/frame-loop.cjs.map +1 -0
  295. package/dist/response/frame-loop.js +100 -0
  296. package/dist/response/frame-loop.js.map +1 -0
  297. package/dist/response/lifecycle.cjs +223 -0
  298. package/dist/response/lifecycle.cjs.map +1 -0
  299. package/dist/response/lifecycle.js +211 -0
  300. package/dist/response/lifecycle.js.map +1 -0
  301. package/dist/response/policy.cjs +126 -0
  302. package/dist/response/policy.cjs.map +1 -0
  303. package/dist/response/policy.js +120 -0
  304. package/dist/response/policy.js.map +1 -0
  305. package/dist/response/profiles.cjs +69 -0
  306. package/dist/response/profiles.cjs.map +1 -0
  307. package/dist/response/profiles.js +65 -0
  308. package/dist/response/profiles.js.map +1 -0
  309. package/dist/response/proxy.cjs +71 -0
  310. package/dist/response/proxy.cjs.map +1 -0
  311. package/dist/response/proxy.js +70 -0
  312. package/dist/response/proxy.js.map +1 -0
  313. package/dist/response/raw.cjs +228 -0
  314. package/dist/response/raw.cjs.map +1 -0
  315. package/dist/response/raw.js +227 -0
  316. package/dist/response/raw.js.map +1 -0
  317. package/dist/response/timing.cjs +157 -0
  318. package/dist/response/timing.cjs.map +1 -0
  319. package/dist/response/timing.js +150 -0
  320. package/dist/response/timing.js.map +1 -0
  321. package/dist/response/usage/codecs/anthropic.cjs +52 -0
  322. package/dist/response/usage/codecs/anthropic.cjs.map +1 -0
  323. package/dist/response/usage/codecs/anthropic.js +50 -0
  324. package/dist/response/usage/codecs/anthropic.js.map +1 -0
  325. package/dist/response/usage/codecs/cohere.cjs +36 -0
  326. package/dist/response/usage/codecs/cohere.cjs.map +1 -0
  327. package/dist/response/usage/codecs/cohere.js +35 -0
  328. package/dist/response/usage/codecs/cohere.js.map +1 -0
  329. package/dist/response/usage/codecs/converse.cjs +16 -0
  330. package/dist/response/usage/codecs/converse.cjs.map +1 -0
  331. package/dist/response/usage/codecs/converse.js +15 -0
  332. package/dist/response/usage/codecs/converse.js.map +1 -0
  333. package/dist/response/usage/codecs/gemini.cjs +31 -0
  334. package/dist/response/usage/codecs/gemini.cjs.map +1 -0
  335. package/dist/response/usage/codecs/gemini.js +31 -0
  336. package/dist/response/usage/codecs/gemini.js.map +1 -0
  337. package/dist/response/usage/codecs/interactions.cjs +22 -0
  338. package/dist/response/usage/codecs/interactions.cjs.map +1 -0
  339. package/dist/response/usage/codecs/interactions.js +21 -0
  340. package/dist/response/usage/codecs/interactions.js.map +1 -0
  341. package/dist/response/usage/codecs/ollama.cjs +17 -0
  342. package/dist/response/usage/codecs/ollama.cjs.map +1 -0
  343. package/dist/response/usage/codecs/ollama.js +17 -0
  344. package/dist/response/usage/codecs/ollama.js.map +1 -0
  345. package/dist/response/usage/codecs/openai.cjs +52 -0
  346. package/dist/response/usage/codecs/openai.cjs.map +1 -0
  347. package/dist/response/usage/codecs/openai.js +50 -0
  348. package/dist/response/usage/codecs/openai.js.map +1 -0
  349. package/dist/response/usage/codecs/openrouter.cjs +68 -0
  350. package/dist/response/usage/codecs/openrouter.cjs.map +1 -0
  351. package/dist/response/usage/codecs/openrouter.js +67 -0
  352. package/dist/response/usage/codecs/openrouter.js.map +1 -0
  353. package/dist/response/usage/codecs/realtime.cjs +19 -0
  354. package/dist/response/usage/codecs/realtime.cjs.map +1 -0
  355. package/dist/response/usage/codecs/realtime.js +18 -0
  356. package/dist/response/usage/codecs/realtime.js.map +1 -0
  357. package/dist/response/usage/codecs/responses.cjs +21 -0
  358. package/dist/response/usage/codecs/responses.cjs.map +1 -0
  359. package/dist/response/usage/codecs/responses.js +20 -0
  360. package/dist/response/usage/codecs/responses.js.map +1 -0
  361. package/dist/response/usage/estimate.cjs +23 -0
  362. package/dist/response/usage/estimate.cjs.map +1 -0
  363. package/dist/response/usage/estimate.js +21 -0
  364. package/dist/response/usage/estimate.js.map +1 -0
  365. package/dist/response/usage/fields.cjs +72 -0
  366. package/dist/response/usage/fields.cjs.map +1 -0
  367. package/dist/response/usage/fields.js +70 -0
  368. package/dist/response/usage/fields.js.map +1 -0
  369. package/dist/response/usage/recording.cjs +52 -0
  370. package/dist/response/usage/recording.cjs.map +1 -0
  371. package/dist/response/usage/recording.js +52 -0
  372. package/dist/response/usage/recording.js.map +1 -0
  373. package/dist/responses.cjs +304 -196
  374. package/dist/responses.cjs.map +1 -1
  375. package/dist/responses.d.cts.map +1 -1
  376. package/dist/responses.d.ts.map +1 -1
  377. package/dist/responses.js +303 -195
  378. package/dist/responses.js.map +1 -1
  379. package/dist/route-registry.cjs +45 -0
  380. package/dist/route-registry.cjs.map +1 -1
  381. package/dist/route-registry.d.cts.map +1 -1
  382. package/dist/route-registry.d.ts.map +1 -1
  383. package/dist/route-registry.js +41 -1
  384. package/dist/route-registry.js.map +1 -1
  385. package/dist/router.cjs +24 -4
  386. package/dist/router.cjs.map +1 -1
  387. package/dist/router.d.cts +7 -1
  388. package/dist/router.d.cts.map +1 -1
  389. package/dist/router.d.ts +7 -1
  390. package/dist/router.d.ts.map +1 -1
  391. package/dist/router.js +24 -5
  392. package/dist/router.js.map +1 -1
  393. package/dist/search.cjs +13 -11
  394. package/dist/search.cjs.map +1 -1
  395. package/dist/search.js +12 -10
  396. package/dist/search.js.map +1 -1
  397. package/dist/server.cjs +293 -248
  398. package/dist/server.cjs.map +1 -1
  399. package/dist/server.d.cts.map +1 -1
  400. package/dist/server.d.ts.map +1 -1
  401. package/dist/server.js +294 -249
  402. package/dist/server.js.map +1 -1
  403. package/dist/speech.cjs +20 -18
  404. package/dist/speech.cjs.map +1 -1
  405. package/dist/speech.d.cts.map +1 -1
  406. package/dist/speech.d.ts.map +1 -1
  407. package/dist/speech.js +19 -17
  408. package/dist/speech.js.map +1 -1
  409. package/dist/sse-writer.cjs +56 -30
  410. package/dist/sse-writer.cjs.map +1 -1
  411. package/dist/sse-writer.d.cts +0 -1
  412. package/dist/sse-writer.d.cts.map +1 -1
  413. package/dist/sse-writer.d.ts +0 -1
  414. package/dist/sse-writer.d.ts.map +1 -1
  415. package/dist/sse-writer.js +55 -31
  416. package/dist/sse-writer.js.map +1 -1
  417. package/dist/stream-collapse.cjs +118 -11
  418. package/dist/stream-collapse.cjs.map +1 -1
  419. package/dist/stream-collapse.d.cts +10 -9
  420. package/dist/stream-collapse.d.cts.map +1 -1
  421. package/dist/stream-collapse.d.ts +10 -9
  422. package/dist/stream-collapse.d.ts.map +1 -1
  423. package/dist/stream-collapse.js +118 -11
  424. package/dist/stream-collapse.js.map +1 -1
  425. package/dist/transcription.cjs +31 -43
  426. package/dist/transcription.cjs.map +1 -1
  427. package/dist/transcription.d.cts.map +1 -1
  428. package/dist/transcription.d.ts.map +1 -1
  429. package/dist/transcription.js +31 -43
  430. package/dist/transcription.js.map +1 -1
  431. package/dist/types.cjs.map +1 -1
  432. package/dist/types.d.cts +231 -9
  433. package/dist/types.d.cts.map +1 -1
  434. package/dist/types.d.ts +231 -9
  435. package/dist/types.d.ts.map +1 -1
  436. package/dist/types.js.map +1 -1
  437. package/dist/vector-mock.cjs +3 -8
  438. package/dist/vector-mock.cjs.map +1 -1
  439. package/dist/vector-mock.d.cts.map +1 -1
  440. package/dist/vector-mock.d.ts.map +1 -1
  441. package/dist/vector-mock.js +3 -8
  442. package/dist/vector-mock.js.map +1 -1
  443. package/dist/vector-stores.cjs +2 -4
  444. package/dist/vector-stores.cjs.map +1 -1
  445. package/dist/vector-stores.d.cts.map +1 -1
  446. package/dist/vector-stores.d.ts.map +1 -1
  447. package/dist/vector-stores.js +2 -4
  448. package/dist/vector-stores.js.map +1 -1
  449. package/dist/veo-video.cjs +16 -14
  450. package/dist/veo-video.cjs.map +1 -1
  451. package/dist/veo-video.js +10 -8
  452. package/dist/veo-video.js.map +1 -1
  453. package/dist/video.cjs +21 -19
  454. package/dist/video.cjs.map +1 -1
  455. package/dist/video.d.cts.map +1 -1
  456. package/dist/video.d.ts.map +1 -1
  457. package/dist/video.js +20 -18
  458. package/dist/video.js.map +1 -1
  459. package/dist/ws-framing.cjs +12 -6
  460. package/dist/ws-framing.cjs.map +1 -1
  461. package/dist/ws-framing.d.cts +2 -0
  462. package/dist/ws-framing.d.cts.map +1 -1
  463. package/dist/ws-framing.d.ts +2 -0
  464. package/dist/ws-framing.d.ts.map +1 -1
  465. package/dist/ws-framing.js +12 -6
  466. package/dist/ws-framing.js.map +1 -1
  467. package/dist/ws-gemini-live.cjs +131 -96
  468. package/dist/ws-gemini-live.cjs.map +1 -1
  469. package/dist/ws-gemini-live.d.cts +0 -1
  470. package/dist/ws-gemini-live.d.cts.map +1 -1
  471. package/dist/ws-gemini-live.d.ts +0 -1
  472. package/dist/ws-gemini-live.d.ts.map +1 -1
  473. package/dist/ws-gemini-live.js +130 -95
  474. package/dist/ws-gemini-live.js.map +1 -1
  475. package/dist/ws-live.cjs +6 -5
  476. package/dist/ws-live.cjs.map +1 -1
  477. package/dist/ws-live.js +5 -4
  478. package/dist/ws-live.js.map +1 -1
  479. package/dist/ws-realtime.cjs +108 -124
  480. package/dist/ws-realtime.cjs.map +1 -1
  481. package/dist/ws-realtime.d.cts.map +1 -1
  482. package/dist/ws-realtime.d.ts.map +1 -1
  483. package/dist/ws-realtime.js +105 -121
  484. package/dist/ws-realtime.js.map +1 -1
  485. package/dist/ws-responses.cjs +80 -59
  486. package/dist/ws-responses.cjs.map +1 -1
  487. package/dist/ws-responses.d.cts.map +1 -1
  488. package/dist/ws-responses.d.ts.map +1 -1
  489. package/dist/ws-responses.js +79 -58
  490. package/dist/ws-responses.js.map +1 -1
  491. package/package.json +4 -1
  492. package/skills/write-fixtures/SKILL.md +57 -16
@@ -0,0 +1,182 @@
1
+
2
+ //#region src/response/catalog/render.ts
3
+ const DEFAULT_MODELS = [
4
+ "gpt-4",
5
+ "gpt-4o",
6
+ "claude-3-5-sonnet-20241022",
7
+ "gemini-2.0-flash",
8
+ "text-embedding-3-small"
9
+ ];
10
+ /** The core fallback is shared by list and detail visibility. */
11
+ function coreModelIds(ids) {
12
+ return ids.length > 0 ? ids : DEFAULT_MODELS;
13
+ }
14
+ function renderOpenAIModel(id) {
15
+ return {
16
+ id,
17
+ object: "model",
18
+ created: 1686935002,
19
+ owned_by: "aimock"
20
+ };
21
+ }
22
+ function renderAnthropicModel(id) {
23
+ return {
24
+ type: "model",
25
+ id,
26
+ display_name: id,
27
+ created_at: "1970-01-01T00:00:00Z",
28
+ capabilities: null,
29
+ lifecycle: "active",
30
+ line: null,
31
+ max_input_tokens: null,
32
+ max_tokens: null,
33
+ deprecated_at: null,
34
+ retires_at: null
35
+ };
36
+ }
37
+ function renderAnthropicModels(page) {
38
+ return {
39
+ data: page.ids.map(renderAnthropicModel),
40
+ has_more: page.hasMore,
41
+ first_id: page.firstId,
42
+ last_id: page.lastId
43
+ };
44
+ }
45
+ function renderGeminiModel(id) {
46
+ return {
47
+ name: `models/${id}`,
48
+ baseModelId: id,
49
+ version: "1",
50
+ displayName: id,
51
+ inputTokenLimit: 128e3,
52
+ outputTokenLimit: 8192,
53
+ supportedGenerationMethods: ["generateContent", "countTokens"]
54
+ };
55
+ }
56
+ function renderGeminiModels(page) {
57
+ return {
58
+ models: page.ids.map(renderGeminiModel),
59
+ ...page.nextPageToken === void 0 ? {} : { nextPageToken: page.nextPageToken }
60
+ };
61
+ }
62
+ const DEFAULT_OPENROUTER_MODELS = [
63
+ "openai/gpt-4o",
64
+ "anthropic/claude-3.5-sonnet",
65
+ "google/gemini-2.0-flash-001"
66
+ ];
67
+ const DEFAULT_OPENROUTER_VIDEO_MODEL = "bytedance/seedance-2.0";
68
+ const DEFAULT_OPENROUTER_VIDEO_MODELS = [DEFAULT_OPENROUTER_VIDEO_MODEL];
69
+ /** Native OpenAI list metadata, including its fixed historical timestamp. */
70
+ function renderOpenAIModels(ids) {
71
+ return {
72
+ object: "list",
73
+ data: coreModelIds(ids).map(renderOpenAIModel)
74
+ };
75
+ }
76
+ /** Call the supplied clock once per entry, as the existing tags route does. */
77
+ function renderOllamaTags(ids, readModifiedTime) {
78
+ return { models: (ids.length > 0 ? ids : DEFAULT_MODELS).map((name) => ({
79
+ name,
80
+ model: name,
81
+ modified_at: readModifiedTime(),
82
+ size: 0,
83
+ digest: "",
84
+ details: {}
85
+ })) };
86
+ }
87
+ /**
88
+ * Build one OpenRouter model-catalog object (deterministic static filler).
89
+ * Field set mirrors real OpenRouter bytes (or-capture/models-first.json):
90
+ * pricing values are STRINGS; the object also carries hugging_face_id,
91
+ * knowledge_cutoff, supported_voices, links, default_parameters,
92
+ * expiration_date, and a `reasoning` descriptor (SDKs tolerate extras).
93
+ */
94
+ function openRouterModelObject(id) {
95
+ return {
96
+ id,
97
+ canonical_slug: id,
98
+ hugging_face_id: null,
99
+ name: id,
100
+ created: 0,
101
+ description: `Mock OpenRouter model ${id} served by aimock.`,
102
+ context_length: 128e3,
103
+ architecture: {
104
+ modality: "text->text",
105
+ input_modalities: ["text"],
106
+ output_modalities: ["text"],
107
+ tokenizer: "Other",
108
+ instruct_type: null
109
+ },
110
+ pricing: {
111
+ prompt: "0",
112
+ completion: "0",
113
+ request: "0",
114
+ image: "0",
115
+ web_search: "0",
116
+ internal_reasoning: "0",
117
+ input_cache_read: "0",
118
+ input_cache_write: "0"
119
+ },
120
+ top_provider: {
121
+ context_length: 128e3,
122
+ max_completion_tokens: 16384,
123
+ is_moderated: false
124
+ },
125
+ per_request_limits: null,
126
+ supported_parameters: [
127
+ "tools",
128
+ "tool_choice",
129
+ "max_tokens",
130
+ "temperature",
131
+ "top_p",
132
+ "stop",
133
+ "reasoning"
134
+ ],
135
+ default_parameters: null,
136
+ supported_voices: null,
137
+ knowledge_cutoff: null,
138
+ expiration_date: null,
139
+ links: { details: `/api/v1/models/${id}/endpoints` },
140
+ reasoning: {
141
+ mandatory: false,
142
+ default_enabled: false
143
+ }
144
+ };
145
+ }
146
+ /** OpenRouter chat's native catalog body and unchanged fallback model set. */
147
+ function renderOpenRouterChatModels(ids) {
148
+ return { data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_MODELS).map(openRouterModelObject) };
149
+ }
150
+ /** OpenRouter video's native model metadata and unchanged fallback model set. */
151
+ function renderOpenRouterVideoModels(ids) {
152
+ return { data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_VIDEO_MODELS).map((id) => ({
153
+ id,
154
+ name: id,
155
+ supported_durations: [4, 8],
156
+ supported_resolutions: ["720p", "1080p"],
157
+ supported_aspect_ratios: [
158
+ "16:9",
159
+ "9:16",
160
+ "1:1"
161
+ ],
162
+ supported_frame_images: [],
163
+ supported_sizes: [],
164
+ generate_audio: false,
165
+ seed: true,
166
+ pricing_skus: []
167
+ })) };
168
+ }
169
+
170
+ //#endregion
171
+ exports.DEFAULT_OPENROUTER_VIDEO_MODEL = DEFAULT_OPENROUTER_VIDEO_MODEL;
172
+ exports.coreModelIds = coreModelIds;
173
+ exports.renderAnthropicModel = renderAnthropicModel;
174
+ exports.renderAnthropicModels = renderAnthropicModels;
175
+ exports.renderGeminiModel = renderGeminiModel;
176
+ exports.renderGeminiModels = renderGeminiModels;
177
+ exports.renderOllamaTags = renderOllamaTags;
178
+ exports.renderOpenAIModel = renderOpenAIModel;
179
+ exports.renderOpenAIModels = renderOpenAIModels;
180
+ exports.renderOpenRouterChatModels = renderOpenRouterChatModels;
181
+ exports.renderOpenRouterVideoModels = renderOpenRouterVideoModels;
182
+ //# sourceMappingURL=render.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.cjs","names":[],"sources":["../../../src/response/catalog/render.ts"],"sourcesContent":["import type { AnthropicCatalogPage } from \"./anthropic-page.js\";\nimport type { GeminiCatalogPage } from \"./gemini-page.js\";\n\nconst DEFAULT_MODELS = [\n \"gpt-4\",\n \"gpt-4o\",\n \"claude-3-5-sonnet-20241022\",\n \"gemini-2.0-flash\",\n \"text-embedding-3-small\",\n];\n\n/** The core fallback is shared by list and detail visibility. */\nexport function coreModelIds(ids: readonly string[]): readonly string[] {\n return ids.length > 0 ? ids : DEFAULT_MODELS;\n}\n\nexport function renderOpenAIModel(id: string) {\n return { id, object: \"model\" as const, created: 1686935002, owned_by: \"aimock\" };\n}\n\nexport function renderAnthropicModel(id: string) {\n return {\n type: \"model\" as const,\n id,\n display_name: id,\n created_at: \"1970-01-01T00:00:00Z\",\n capabilities: null,\n lifecycle: \"active\" as const,\n line: null,\n max_input_tokens: null,\n max_tokens: null,\n deprecated_at: null,\n retires_at: null,\n };\n}\n\nexport function renderAnthropicModels(page: AnthropicCatalogPage) {\n return {\n data: page.ids.map(renderAnthropicModel),\n has_more: page.hasMore,\n first_id: page.firstId,\n last_id: page.lastId,\n };\n}\n\nexport function renderGeminiModel(id: string) {\n return {\n name: `models/${id}`,\n baseModelId: id,\n version: \"1\",\n displayName: id,\n inputTokenLimit: 128000,\n outputTokenLimit: 8192,\n supportedGenerationMethods: [\"generateContent\", \"countTokens\"],\n };\n}\n\nexport function renderGeminiModels(page: GeminiCatalogPage) {\n return {\n models: page.ids.map(renderGeminiModel),\n ...(page.nextPageToken === undefined ? {} : { nextPageToken: page.nextPageToken }),\n };\n}\n\nconst DEFAULT_OPENROUTER_MODELS = [\n \"openai/gpt-4o\",\n \"anthropic/claude-3.5-sonnet\",\n \"google/gemini-2.0-flash-001\",\n];\n\nexport const DEFAULT_OPENROUTER_VIDEO_MODEL = \"bytedance/seedance-2.0\";\nconst DEFAULT_OPENROUTER_VIDEO_MODELS = [DEFAULT_OPENROUTER_VIDEO_MODEL];\n\n/** Native OpenAI list metadata, including its fixed historical timestamp. */\nexport function renderOpenAIModels(ids: readonly string[]) {\n return {\n object: \"list\" as const,\n data: coreModelIds(ids).map(renderOpenAIModel),\n };\n}\n\n/** Call the supplied clock once per entry, as the existing tags route does. */\nexport function renderOllamaTags(ids: readonly string[], readModifiedTime: () => string) {\n return {\n models: (ids.length > 0 ? ids : DEFAULT_MODELS).map((name) => ({\n name,\n model: name,\n modified_at: readModifiedTime(),\n size: 0,\n digest: \"\",\n details: {},\n })),\n };\n}\n\n/**\n * Build one OpenRouter model-catalog object (deterministic static filler).\n * Field set mirrors real OpenRouter bytes (or-capture/models-first.json):\n * pricing values are STRINGS; the object also carries hugging_face_id,\n * knowledge_cutoff, supported_voices, links, default_parameters,\n * expiration_date, and a `reasoning` descriptor (SDKs tolerate extras).\n */\nfunction openRouterModelObject(id: string) {\n return {\n id,\n canonical_slug: id,\n hugging_face_id: null,\n name: id,\n created: 0,\n description: `Mock OpenRouter model ${id} served by aimock.`,\n context_length: 128000,\n architecture: {\n modality: \"text->text\",\n input_modalities: [\"text\"],\n output_modalities: [\"text\"],\n tokenizer: \"Other\",\n instruct_type: null,\n },\n pricing: {\n prompt: \"0\",\n completion: \"0\",\n request: \"0\",\n image: \"0\",\n web_search: \"0\",\n internal_reasoning: \"0\",\n input_cache_read: \"0\",\n input_cache_write: \"0\",\n },\n top_provider: {\n context_length: 128000,\n max_completion_tokens: 16384,\n is_moderated: false,\n },\n per_request_limits: null,\n supported_parameters: [\n \"tools\",\n \"tool_choice\",\n \"max_tokens\",\n \"temperature\",\n \"top_p\",\n \"stop\",\n \"reasoning\",\n ],\n default_parameters: null,\n supported_voices: null,\n knowledge_cutoff: null,\n expiration_date: null,\n links: { details: `/api/v1/models/${id}/endpoints` },\n reasoning: { mandatory: false, default_enabled: false },\n };\n}\n\n/** OpenRouter chat's native catalog body and unchanged fallback model set. */\nexport function renderOpenRouterChatModels(ids: readonly string[]) {\n return { data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_MODELS).map(openRouterModelObject) };\n}\n\n/** OpenRouter video's native model metadata and unchanged fallback model set. */\nexport function renderOpenRouterVideoModels(ids: readonly string[]) {\n return {\n data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_VIDEO_MODELS).map((id) => ({\n id,\n name: id,\n supported_durations: [4, 8],\n supported_resolutions: [\"720p\", \"1080p\"],\n supported_aspect_ratios: [\"16:9\", \"9:16\", \"1:1\"],\n supported_frame_images: [],\n supported_sizes: [],\n generate_audio: false,\n seed: true,\n pricing_skus: [],\n })),\n };\n}\n"],"mappings":"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"}
@@ -0,0 +1,171 @@
1
+ //#region src/response/catalog/render.ts
2
+ const DEFAULT_MODELS = [
3
+ "gpt-4",
4
+ "gpt-4o",
5
+ "claude-3-5-sonnet-20241022",
6
+ "gemini-2.0-flash",
7
+ "text-embedding-3-small"
8
+ ];
9
+ /** The core fallback is shared by list and detail visibility. */
10
+ function coreModelIds(ids) {
11
+ return ids.length > 0 ? ids : DEFAULT_MODELS;
12
+ }
13
+ function renderOpenAIModel(id) {
14
+ return {
15
+ id,
16
+ object: "model",
17
+ created: 1686935002,
18
+ owned_by: "aimock"
19
+ };
20
+ }
21
+ function renderAnthropicModel(id) {
22
+ return {
23
+ type: "model",
24
+ id,
25
+ display_name: id,
26
+ created_at: "1970-01-01T00:00:00Z",
27
+ capabilities: null,
28
+ lifecycle: "active",
29
+ line: null,
30
+ max_input_tokens: null,
31
+ max_tokens: null,
32
+ deprecated_at: null,
33
+ retires_at: null
34
+ };
35
+ }
36
+ function renderAnthropicModels(page) {
37
+ return {
38
+ data: page.ids.map(renderAnthropicModel),
39
+ has_more: page.hasMore,
40
+ first_id: page.firstId,
41
+ last_id: page.lastId
42
+ };
43
+ }
44
+ function renderGeminiModel(id) {
45
+ return {
46
+ name: `models/${id}`,
47
+ baseModelId: id,
48
+ version: "1",
49
+ displayName: id,
50
+ inputTokenLimit: 128e3,
51
+ outputTokenLimit: 8192,
52
+ supportedGenerationMethods: ["generateContent", "countTokens"]
53
+ };
54
+ }
55
+ function renderGeminiModels(page) {
56
+ return {
57
+ models: page.ids.map(renderGeminiModel),
58
+ ...page.nextPageToken === void 0 ? {} : { nextPageToken: page.nextPageToken }
59
+ };
60
+ }
61
+ const DEFAULT_OPENROUTER_MODELS = [
62
+ "openai/gpt-4o",
63
+ "anthropic/claude-3.5-sonnet",
64
+ "google/gemini-2.0-flash-001"
65
+ ];
66
+ const DEFAULT_OPENROUTER_VIDEO_MODEL = "bytedance/seedance-2.0";
67
+ const DEFAULT_OPENROUTER_VIDEO_MODELS = [DEFAULT_OPENROUTER_VIDEO_MODEL];
68
+ /** Native OpenAI list metadata, including its fixed historical timestamp. */
69
+ function renderOpenAIModels(ids) {
70
+ return {
71
+ object: "list",
72
+ data: coreModelIds(ids).map(renderOpenAIModel)
73
+ };
74
+ }
75
+ /** Call the supplied clock once per entry, as the existing tags route does. */
76
+ function renderOllamaTags(ids, readModifiedTime) {
77
+ return { models: (ids.length > 0 ? ids : DEFAULT_MODELS).map((name) => ({
78
+ name,
79
+ model: name,
80
+ modified_at: readModifiedTime(),
81
+ size: 0,
82
+ digest: "",
83
+ details: {}
84
+ })) };
85
+ }
86
+ /**
87
+ * Build one OpenRouter model-catalog object (deterministic static filler).
88
+ * Field set mirrors real OpenRouter bytes (or-capture/models-first.json):
89
+ * pricing values are STRINGS; the object also carries hugging_face_id,
90
+ * knowledge_cutoff, supported_voices, links, default_parameters,
91
+ * expiration_date, and a `reasoning` descriptor (SDKs tolerate extras).
92
+ */
93
+ function openRouterModelObject(id) {
94
+ return {
95
+ id,
96
+ canonical_slug: id,
97
+ hugging_face_id: null,
98
+ name: id,
99
+ created: 0,
100
+ description: `Mock OpenRouter model ${id} served by aimock.`,
101
+ context_length: 128e3,
102
+ architecture: {
103
+ modality: "text->text",
104
+ input_modalities: ["text"],
105
+ output_modalities: ["text"],
106
+ tokenizer: "Other",
107
+ instruct_type: null
108
+ },
109
+ pricing: {
110
+ prompt: "0",
111
+ completion: "0",
112
+ request: "0",
113
+ image: "0",
114
+ web_search: "0",
115
+ internal_reasoning: "0",
116
+ input_cache_read: "0",
117
+ input_cache_write: "0"
118
+ },
119
+ top_provider: {
120
+ context_length: 128e3,
121
+ max_completion_tokens: 16384,
122
+ is_moderated: false
123
+ },
124
+ per_request_limits: null,
125
+ supported_parameters: [
126
+ "tools",
127
+ "tool_choice",
128
+ "max_tokens",
129
+ "temperature",
130
+ "top_p",
131
+ "stop",
132
+ "reasoning"
133
+ ],
134
+ default_parameters: null,
135
+ supported_voices: null,
136
+ knowledge_cutoff: null,
137
+ expiration_date: null,
138
+ links: { details: `/api/v1/models/${id}/endpoints` },
139
+ reasoning: {
140
+ mandatory: false,
141
+ default_enabled: false
142
+ }
143
+ };
144
+ }
145
+ /** OpenRouter chat's native catalog body and unchanged fallback model set. */
146
+ function renderOpenRouterChatModels(ids) {
147
+ return { data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_MODELS).map(openRouterModelObject) };
148
+ }
149
+ /** OpenRouter video's native model metadata and unchanged fallback model set. */
150
+ function renderOpenRouterVideoModels(ids) {
151
+ return { data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_VIDEO_MODELS).map((id) => ({
152
+ id,
153
+ name: id,
154
+ supported_durations: [4, 8],
155
+ supported_resolutions: ["720p", "1080p"],
156
+ supported_aspect_ratios: [
157
+ "16:9",
158
+ "9:16",
159
+ "1:1"
160
+ ],
161
+ supported_frame_images: [],
162
+ supported_sizes: [],
163
+ generate_audio: false,
164
+ seed: true,
165
+ pricing_skus: []
166
+ })) };
167
+ }
168
+
169
+ //#endregion
170
+ export { DEFAULT_OPENROUTER_VIDEO_MODEL, coreModelIds, renderAnthropicModel, renderAnthropicModels, renderGeminiModel, renderGeminiModels, renderOllamaTags, renderOpenAIModel, renderOpenAIModels, renderOpenRouterChatModels, renderOpenRouterVideoModels };
171
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","names":[],"sources":["../../../src/response/catalog/render.ts"],"sourcesContent":["import type { AnthropicCatalogPage } from \"./anthropic-page.js\";\nimport type { GeminiCatalogPage } from \"./gemini-page.js\";\n\nconst DEFAULT_MODELS = [\n \"gpt-4\",\n \"gpt-4o\",\n \"claude-3-5-sonnet-20241022\",\n \"gemini-2.0-flash\",\n \"text-embedding-3-small\",\n];\n\n/** The core fallback is shared by list and detail visibility. */\nexport function coreModelIds(ids: readonly string[]): readonly string[] {\n return ids.length > 0 ? ids : DEFAULT_MODELS;\n}\n\nexport function renderOpenAIModel(id: string) {\n return { id, object: \"model\" as const, created: 1686935002, owned_by: \"aimock\" };\n}\n\nexport function renderAnthropicModel(id: string) {\n return {\n type: \"model\" as const,\n id,\n display_name: id,\n created_at: \"1970-01-01T00:00:00Z\",\n capabilities: null,\n lifecycle: \"active\" as const,\n line: null,\n max_input_tokens: null,\n max_tokens: null,\n deprecated_at: null,\n retires_at: null,\n };\n}\n\nexport function renderAnthropicModels(page: AnthropicCatalogPage) {\n return {\n data: page.ids.map(renderAnthropicModel),\n has_more: page.hasMore,\n first_id: page.firstId,\n last_id: page.lastId,\n };\n}\n\nexport function renderGeminiModel(id: string) {\n return {\n name: `models/${id}`,\n baseModelId: id,\n version: \"1\",\n displayName: id,\n inputTokenLimit: 128000,\n outputTokenLimit: 8192,\n supportedGenerationMethods: [\"generateContent\", \"countTokens\"],\n };\n}\n\nexport function renderGeminiModels(page: GeminiCatalogPage) {\n return {\n models: page.ids.map(renderGeminiModel),\n ...(page.nextPageToken === undefined ? {} : { nextPageToken: page.nextPageToken }),\n };\n}\n\nconst DEFAULT_OPENROUTER_MODELS = [\n \"openai/gpt-4o\",\n \"anthropic/claude-3.5-sonnet\",\n \"google/gemini-2.0-flash-001\",\n];\n\nexport const DEFAULT_OPENROUTER_VIDEO_MODEL = \"bytedance/seedance-2.0\";\nconst DEFAULT_OPENROUTER_VIDEO_MODELS = [DEFAULT_OPENROUTER_VIDEO_MODEL];\n\n/** Native OpenAI list metadata, including its fixed historical timestamp. */\nexport function renderOpenAIModels(ids: readonly string[]) {\n return {\n object: \"list\" as const,\n data: coreModelIds(ids).map(renderOpenAIModel),\n };\n}\n\n/** Call the supplied clock once per entry, as the existing tags route does. */\nexport function renderOllamaTags(ids: readonly string[], readModifiedTime: () => string) {\n return {\n models: (ids.length > 0 ? ids : DEFAULT_MODELS).map((name) => ({\n name,\n model: name,\n modified_at: readModifiedTime(),\n size: 0,\n digest: \"\",\n details: {},\n })),\n };\n}\n\n/**\n * Build one OpenRouter model-catalog object (deterministic static filler).\n * Field set mirrors real OpenRouter bytes (or-capture/models-first.json):\n * pricing values are STRINGS; the object also carries hugging_face_id,\n * knowledge_cutoff, supported_voices, links, default_parameters,\n * expiration_date, and a `reasoning` descriptor (SDKs tolerate extras).\n */\nfunction openRouterModelObject(id: string) {\n return {\n id,\n canonical_slug: id,\n hugging_face_id: null,\n name: id,\n created: 0,\n description: `Mock OpenRouter model ${id} served by aimock.`,\n context_length: 128000,\n architecture: {\n modality: \"text->text\",\n input_modalities: [\"text\"],\n output_modalities: [\"text\"],\n tokenizer: \"Other\",\n instruct_type: null,\n },\n pricing: {\n prompt: \"0\",\n completion: \"0\",\n request: \"0\",\n image: \"0\",\n web_search: \"0\",\n internal_reasoning: \"0\",\n input_cache_read: \"0\",\n input_cache_write: \"0\",\n },\n top_provider: {\n context_length: 128000,\n max_completion_tokens: 16384,\n is_moderated: false,\n },\n per_request_limits: null,\n supported_parameters: [\n \"tools\",\n \"tool_choice\",\n \"max_tokens\",\n \"temperature\",\n \"top_p\",\n \"stop\",\n \"reasoning\",\n ],\n default_parameters: null,\n supported_voices: null,\n knowledge_cutoff: null,\n expiration_date: null,\n links: { details: `/api/v1/models/${id}/endpoints` },\n reasoning: { mandatory: false, default_enabled: false },\n };\n}\n\n/** OpenRouter chat's native catalog body and unchanged fallback model set. */\nexport function renderOpenRouterChatModels(ids: readonly string[]) {\n return { data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_MODELS).map(openRouterModelObject) };\n}\n\n/** OpenRouter video's native model metadata and unchanged fallback model set. */\nexport function renderOpenRouterVideoModels(ids: readonly string[]) {\n return {\n data: (ids.length > 0 ? ids : DEFAULT_OPENROUTER_VIDEO_MODELS).map((id) => ({\n id,\n name: id,\n supported_durations: [4, 8],\n supported_resolutions: [\"720p\", \"1080p\"],\n supported_aspect_ratios: [\"16:9\", \"9:16\", \"1:1\"],\n supported_frame_images: [],\n supported_sizes: [],\n generate_audio: false,\n seed: true,\n pricing_skus: [],\n })),\n };\n}\n"],"mappings":"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"}
@@ -0,0 +1,144 @@
1
+ const require_frame_loop = require('./frame-loop.cjs');
2
+ const require_sse_writer = require('../sse-writer.cjs');
3
+ const require_chaos = require('../chaos.cjs');
4
+ const require_lifecycle = require('./lifecycle.cjs');
5
+ const require_timing = require('./timing.cjs');
6
+
7
+ //#region src/response/deliver.ts
8
+ /**
9
+ * Journal a delivery that ended early. The reason is always set: the
10
+ * lifecycle's first cause when it fired, else {@link teardownReason} for the
11
+ * response that is gone. When no byte of the response reached the socket
12
+ * ({@link statusLineSent}), the status is 0, the rule the server and the
13
+ * chaos `disconnect` apply to a torn socket. A fixture interruption
14
+ * (`disconnectAfterMs`, `truncateAfterChunks`) keeps the status it was
15
+ * journaled with, as base recorded it.
16
+ */
17
+ function journalTeardown(entry, res, lifecycle) {
18
+ require_lifecycle.markInterrupted(entry, lifecycle?.reason() ?? require_lifecycle.teardownReason(res));
19
+ if (lifecycle?.cause() !== "fixture" && !require_lifecycle.statusLineSent(res)) entry.response.status = 0;
20
+ }
21
+ /**
22
+ * Whether the response was torn down: the lifecycle fired, the response is
23
+ * destroyed or chaos disconnected it, or the client closed the socket.
24
+ */
25
+ function tornDown(res, lifecycle) {
26
+ const socket = require_lifecycle.requestSocket(res);
27
+ const gone = require_chaos.responseGoneReason(res);
28
+ return lifecycle?.reason() !== void 0 || gone === "client-gone" || gone === "chaos-disconnected" || !res.writableEnded && !!socket && require_lifecycle.closedByClient(socket);
29
+ }
30
+ /**
31
+ * Journal a response that something else on aimock's side already answered
32
+ * (head committed or body ended) as aimock's teardown, with the status the
33
+ * client actually got.
34
+ */
35
+ function journalAnsweredElsewhere(entry, res) {
36
+ require_lifecycle.markInterrupted(entry, require_lifecycle.AIMOCK_DISCONNECTED);
37
+ entry.response.status = require_lifecycle.statusLineSent(res) ? res.statusCode : 0;
38
+ }
39
+ /**
40
+ * Whether `deliverJson` can no longer write its reply, journaling why when it
41
+ * cannot. Torn down ({@link tornDown}): {@link journalTeardown}. Already
42
+ * answered by something else on aimock's side (head committed or body
43
+ * ended): writing again would throw `ERR_HTTP_HEADERS_SENT`, so it is
44
+ * journaled by {@link journalAnsweredElsewhere}, and a body that never ended
45
+ * is destroyed so the client does not hang.
46
+ */
47
+ function journalUnwritable(entry, res, lifecycle) {
48
+ if (tornDown(res, lifecycle)) {
49
+ journalTeardown(entry, res, lifecycle);
50
+ return true;
51
+ }
52
+ if (res.headersSent || res.writableEnded) {
53
+ journalAnsweredElsewhere(entry, res);
54
+ if (!res.writableEnded) res.destroy();
55
+ return true;
56
+ }
57
+ return false;
58
+ }
59
+ /**
60
+ * Deliver one streamed reply and journal how it ended. Builds the HTTP
61
+ * lifecycle (client close + fixture interruption) and runs the frame loop on
62
+ * it. When the loop stops early it destroys `res` (if it has not ended) and
63
+ * marks the entry with the first cause's reason (or, when no cause fired, who
64
+ * tore the response down). A response other code already answered (head
65
+ * committed before the stream, or body ended) is journaled as
66
+ * {@link deliverJson} journals it. It disposes the lifecycle on every path.
67
+ */
68
+ async function deliverStream(res, entry, fixture, codec, frames, timing, opts) {
69
+ require_lifecycle.noteDeliveryStart(res);
70
+ const headSentBefore = res.headersSent;
71
+ const lifecycle = require_lifecycle.httpLifecycle(res, fixture, { streaming: true });
72
+ try {
73
+ if (!await require_frame_loop.runFrameLoop(require_frame_loop.httpSink(res), frames, codec, timing, {
74
+ lifecycle,
75
+ onChunkSent: lifecycle.tick,
76
+ status: opts?.status,
77
+ headers: opts?.headers
78
+ })) {
79
+ const answeredElsewhere = (headSentBefore || res.writableEnded) && !tornDown(res, lifecycle);
80
+ if (!res.writableEnded) res.destroy();
81
+ if (answeredElsewhere) journalAnsweredElsewhere(entry, res);
82
+ else journalTeardown(entry, res, lifecycle);
83
+ }
84
+ } finally {
85
+ lifecycle.dispose();
86
+ }
87
+ }
88
+ /**
89
+ * Deliver one non-streaming JSON reply. The body is a thunk.
90
+ *
91
+ * On both paths it first checks {@link journalUnwritable}, before any wait. A
92
+ * response that can no longer take the reply (torn down, or already answered)
93
+ * is not written, the thunk is never called, and the entry is marked
94
+ * interrupted. An already-answered response whose body never ended is
95
+ * destroyed, so the client does not hang.
96
+ *
97
+ * With non-streaming timing off (the default) it then runs
98
+ * `JSON.stringify(body())`, then `writeHead`, then `end`: the body is built
99
+ * before anything is written, so a builder that throws leaves the response
100
+ * unwritten.
101
+ *
102
+ * With timing on, it waits the non-streaming delay on the client's close
103
+ * signal, checks {@link journalUnwritable} again (the response can be torn
104
+ * down or answered during the wait), then runs the thunk, so a `created`
105
+ * timestamp reflects the write time.
106
+ *
107
+ * Rejects with a `RangeError` when `chunkSize` is a number below 1: that is
108
+ * a programming error, and the delay math divides by it. No user input reaches
109
+ * it, because every caller clamps with `Math.max(1, ...)`. A user value that
110
+ * is not a number clamps to `NaN`: the reply is still served, with a zero
111
+ * wait when timing is on.
112
+ */
113
+ async function deliverJson(res, entry, fixture, body, opts) {
114
+ if (opts.chunkSize < 1) throw new RangeError(`deliverJson: chunkSize must be >= 1, got ${opts.chunkSize}`);
115
+ const write = () => {
116
+ const text = JSON.stringify(body());
117
+ res.writeHead(opts.status ?? 200, {
118
+ "Content-Type": "application/json",
119
+ ...opts.headers
120
+ });
121
+ res.end(text);
122
+ };
123
+ require_lifecycle.noteDeliveryStart(res);
124
+ if (journalUnwritable(entry, res, void 0)) return;
125
+ if (!require_timing.nonStreamingTimingEnabled(fixture, opts.surface)) {
126
+ write();
127
+ return;
128
+ }
129
+ const lifecycle = require_lifecycle.httpLifecycle(res, fixture, { streaming: false });
130
+ try {
131
+ const fixtureTimings = require_timing.nonStreamingRecordedTimings(fixture, opts.surface, opts.recordedTimings);
132
+ const recordedTimings = opts.duplicateId ? require_timing.extendRecordedTimings(fixtureTimings, Math.max(1, Math.ceil(opts.payloadLength / opts.chunkSize)), true) : fixtureTimings;
133
+ await require_sse_writer.delay(require_timing.nonStreamingDelayMs(fixture, opts.payloadLength, opts.chunkSize, recordedTimings, opts.replaySpeed), lifecycle.signal);
134
+ if (journalUnwritable(entry, res, lifecycle)) return;
135
+ write();
136
+ } finally {
137
+ lifecycle.dispose();
138
+ }
139
+ }
140
+
141
+ //#endregion
142
+ exports.deliverJson = deliverJson;
143
+ exports.deliverStream = deliverStream;
144
+ //# sourceMappingURL=deliver.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deliver.cjs","names":["teardownReason","statusLineSent","requestSocket","responseGoneReason","closedByClient","AIMOCK_DISCONNECTED","httpLifecycle","runFrameLoop","httpSink","nonStreamingTimingEnabled","nonStreamingRecordedTimings","extendRecordedTimings","delay","nonStreamingDelayMs"],"sources":["../../src/response/deliver.ts"],"sourcesContent":["import type * as http from \"node:http\";\nimport type { Fixture, JournalEntry, RecordedTimings } from \"../types.js\";\nimport { delay } from \"../sse-writer.js\";\nimport { httpSink, runFrameLoop, type FrameCodec, type FrameTiming } from \"./frame-loop.js\";\nimport { responseGoneReason } from \"../chaos.js\";\nimport {\n AIMOCK_DISCONNECTED,\n closedByClient,\n httpLifecycle,\n markInterrupted,\n noteDeliveryStart,\n statusLineSent,\n teardownReason,\n requestSocket,\n type DeliveryLifecycle,\n} from \"./lifecycle.js\";\nimport {\n extendRecordedTimings,\n nonStreamingDelayMs,\n nonStreamingRecordedTimings,\n nonStreamingTimingEnabled,\n type NonStreamingSurface,\n} from \"./timing.js\";\n\n/** The lifecycle fields the teardown journal reads. */\ntype TeardownSource = Pick<DeliveryLifecycle, \"cause\" | \"reason\">;\n\n/**\n * Journal a delivery that ended early. The reason is always set: the\n * lifecycle's first cause when it fired, else {@link teardownReason} for the\n * response that is gone. When no byte of the response reached the socket\n * ({@link statusLineSent}), the status is 0, the rule the server and the\n * chaos `disconnect` apply to a torn socket. A fixture interruption\n * (`disconnectAfterMs`, `truncateAfterChunks`) keeps the status it was\n * journaled with, as base recorded it.\n */\nfunction journalTeardown(\n entry: JournalEntry,\n res: http.ServerResponse,\n lifecycle: TeardownSource | undefined,\n): void {\n markInterrupted(entry, lifecycle?.reason() ?? teardownReason(res));\n if (lifecycle?.cause() !== \"fixture\" && !statusLineSent(res)) entry.response.status = 0;\n}\n\n/**\n * Whether the response was torn down: the lifecycle fired, the response is\n * destroyed or chaos disconnected it, or the client closed the socket.\n */\nfunction tornDown(res: http.ServerResponse, lifecycle: TeardownSource | undefined): boolean {\n const socket = requestSocket(res);\n const gone = responseGoneReason(res);\n return (\n lifecycle?.reason() !== undefined ||\n gone === \"client-gone\" ||\n gone === \"chaos-disconnected\" ||\n (!res.writableEnded && !!socket && closedByClient(socket))\n );\n}\n\n/**\n * Journal a response that something else on aimock's side already answered\n * (head committed or body ended) as aimock's teardown, with the status the\n * client actually got.\n */\nfunction journalAnsweredElsewhere(entry: JournalEntry, res: http.ServerResponse): void {\n markInterrupted(entry, AIMOCK_DISCONNECTED);\n entry.response.status = statusLineSent(res) ? res.statusCode : 0;\n}\n\n/**\n * Whether `deliverJson` can no longer write its reply, journaling why when it\n * cannot. Torn down ({@link tornDown}): {@link journalTeardown}. Already\n * answered by something else on aimock's side (head committed or body\n * ended): writing again would throw `ERR_HTTP_HEADERS_SENT`, so it is\n * journaled by {@link journalAnsweredElsewhere}, and a body that never ended\n * is destroyed so the client does not hang.\n */\nfunction journalUnwritable(\n entry: JournalEntry,\n res: http.ServerResponse,\n lifecycle: TeardownSource | undefined,\n): boolean {\n if (tornDown(res, lifecycle)) {\n journalTeardown(entry, res, lifecycle);\n return true;\n }\n if (res.headersSent || res.writableEnded) {\n journalAnsweredElsewhere(entry, res);\n if (!res.writableEnded) res.destroy();\n return true;\n }\n return false;\n}\n\n/**\n * Deliver one streamed reply and journal how it ended. Builds the HTTP\n * lifecycle (client close + fixture interruption) and runs the frame loop on\n * it. When the loop stops early it destroys `res` (if it has not ended) and\n * marks the entry with the first cause's reason (or, when no cause fired, who\n * tore the response down). A response other code already answered (head\n * committed before the stream, or body ended) is journaled as\n * {@link deliverJson} journals it. It disposes the lifecycle on every path.\n */\nexport async function deliverStream<F>(\n res: http.ServerResponse,\n entry: JournalEntry,\n fixture: Fixture,\n codec: FrameCodec<F>,\n frames: readonly F[],\n timing: FrameTiming,\n opts?: {\n status?: number; // When set, sent with `writeHead` before the first frame (issue #549).\n headers?: Record<string, string>; // Merged over the codec's headers (issue #549).\n },\n): Promise<void> {\n noteDeliveryStart(res);\n const headSentBefore = res.headersSent;\n const lifecycle = httpLifecycle(res, fixture, { streaming: true });\n try {\n const completed = await runFrameLoop(httpSink(res), frames, codec, timing, {\n lifecycle,\n onChunkSent: lifecycle.tick,\n status: opts?.status,\n headers: opts?.headers,\n });\n if (!completed) {\n // Read before the destroy below, which makes any response look torn down.\n const answeredElsewhere = (headSentBefore || res.writableEnded) && !tornDown(res, lifecycle);\n if (!res.writableEnded) res.destroy();\n if (answeredElsewhere) journalAnsweredElsewhere(entry, res);\n else journalTeardown(entry, res, lifecycle);\n }\n } finally {\n lifecycle.dispose();\n }\n}\n\nexport interface DeliverJsonOptions {\n /**\n * Passed to `nonStreamingTimingEnabled` and `nonStreamingRecordedTimings`:\n * OpenAI chat, or any other provider.\n */\n surface: NonStreamingSurface;\n status?: number; // The response status, 200 when unset (issue #549).\n headers?: Record<string, string>; // Merged over the JSON `Content-Type` header (issue #549).\n /** The served payload length the wait is sized from. */\n payloadLength: number;\n /**\n * The wait is sized in chunks of this many characters. Callers pass\n * `Math.max(1, <fixture or server chunkSize>)`: 1 or more, or `NaN` for a\n * non-numeric value. `NaN` gives a zero wait.\n */\n chunkSize: number;\n recordedTimings?: RecordedTimings;\n /** A K4 duplicate-id plan: extend the recorded gaps before sizing the wait. */\n duplicateId?: boolean;\n replaySpeed?: number;\n}\n\n/**\n * Deliver one non-streaming JSON reply. The body is a thunk.\n *\n * On both paths it first checks {@link journalUnwritable}, before any wait. A\n * response that can no longer take the reply (torn down, or already answered)\n * is not written, the thunk is never called, and the entry is marked\n * interrupted. An already-answered response whose body never ended is\n * destroyed, so the client does not hang.\n *\n * With non-streaming timing off (the default) it then runs\n * `JSON.stringify(body())`, then `writeHead`, then `end`: the body is built\n * before anything is written, so a builder that throws leaves the response\n * unwritten.\n *\n * With timing on, it waits the non-streaming delay on the client's close\n * signal, checks {@link journalUnwritable} again (the response can be torn\n * down or answered during the wait), then runs the thunk, so a `created`\n * timestamp reflects the write time.\n *\n * Rejects with a `RangeError` when `chunkSize` is a number below 1: that is\n * a programming error, and the delay math divides by it. No user input reaches\n * it, because every caller clamps with `Math.max(1, ...)`. A user value that\n * is not a number clamps to `NaN`: the reply is still served, with a zero\n * wait when timing is on.\n */\nexport async function deliverJson(\n res: http.ServerResponse,\n entry: JournalEntry,\n fixture: Fixture,\n body: () => unknown,\n opts: DeliverJsonOptions,\n): Promise<void> {\n if (opts.chunkSize < 1) {\n throw new RangeError(`deliverJson: chunkSize must be >= 1, got ${opts.chunkSize}`);\n }\n const write = (): void => {\n const text = JSON.stringify(body());\n res.writeHead(opts.status ?? 200, { \"Content-Type\": \"application/json\", ...opts.headers });\n res.end(text);\n };\n noteDeliveryStart(res);\n // Checked before the lifecycle and the wait on both paths: a response that\n // cannot take the reply is journaled at once, with no wait.\n if (journalUnwritable(entry, res, undefined)) return;\n if (!nonStreamingTimingEnabled(fixture, opts.surface)) {\n write();\n return;\n }\n const lifecycle = httpLifecycle(res, fixture, { streaming: false });\n try {\n const fixtureTimings = nonStreamingRecordedTimings(fixture, opts.surface, opts.recordedTimings);\n const recordedTimings = opts.duplicateId\n ? extendRecordedTimings(\n fixtureTimings,\n Math.max(1, Math.ceil(opts.payloadLength / opts.chunkSize)),\n true,\n )\n : fixtureTimings;\n await delay(\n nonStreamingDelayMs(\n fixture,\n opts.payloadLength,\n opts.chunkSize,\n recordedTimings,\n opts.replaySpeed,\n ),\n lifecycle.signal,\n );\n if (journalUnwritable(entry, res, lifecycle)) return;\n write();\n } finally {\n lifecycle.dispose();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAoCA,SAAS,gBACP,OACA,KACA,WACM;AACN,mCAAgB,OAAO,WAAW,QAAQ,IAAIA,iCAAe,IAAI,CAAC;AAClE,KAAI,WAAW,OAAO,KAAK,aAAa,CAACC,iCAAe,IAAI,CAAE,OAAM,SAAS,SAAS;;;;;;AAOxF,SAAS,SAAS,KAA0B,WAAgD;CAC1F,MAAM,SAASC,gCAAc,IAAI;CACjC,MAAM,OAAOC,iCAAmB,IAAI;AACpC,QACE,WAAW,QAAQ,KAAK,UACxB,SAAS,iBACT,SAAS,wBACR,CAAC,IAAI,iBAAiB,CAAC,CAAC,UAAUC,iCAAe,OAAO;;;;;;;AAS7D,SAAS,yBAAyB,OAAqB,KAAgC;AACrF,mCAAgB,OAAOC,sCAAoB;AAC3C,OAAM,SAAS,SAASJ,iCAAe,IAAI,GAAG,IAAI,aAAa;;;;;;;;;;AAWjE,SAAS,kBACP,OACA,KACA,WACS;AACT,KAAI,SAAS,KAAK,UAAU,EAAE;AAC5B,kBAAgB,OAAO,KAAK,UAAU;AACtC,SAAO;;AAET,KAAI,IAAI,eAAe,IAAI,eAAe;AACxC,2BAAyB,OAAO,IAAI;AACpC,MAAI,CAAC,IAAI,cAAe,KAAI,SAAS;AACrC,SAAO;;AAET,QAAO;;;;;;;;;;;AAYT,eAAsB,cACpB,KACA,OACA,SACA,OACA,QACA,QACA,MAIe;AACf,qCAAkB,IAAI;CACtB,MAAM,iBAAiB,IAAI;CAC3B,MAAM,YAAYK,gCAAc,KAAK,SAAS,EAAE,WAAW,MAAM,CAAC;AAClE,KAAI;AAOF,MAAI,CANc,MAAMC,gCAAaC,4BAAS,IAAI,EAAE,QAAQ,OAAO,QAAQ;GACzE;GACA,aAAa,UAAU;GACvB,QAAQ,MAAM;GACd,SAAS,MAAM;GAChB,CAAC,EACc;GAEd,MAAM,qBAAqB,kBAAkB,IAAI,kBAAkB,CAAC,SAAS,KAAK,UAAU;AAC5F,OAAI,CAAC,IAAI,cAAe,KAAI,SAAS;AACrC,OAAI,kBAAmB,0BAAyB,OAAO,IAAI;OACtD,iBAAgB,OAAO,KAAK,UAAU;;WAErC;AACR,YAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDvB,eAAsB,YACpB,KACA,OACA,SACA,MACA,MACe;AACf,KAAI,KAAK,YAAY,EACnB,OAAM,IAAI,WAAW,4CAA4C,KAAK,YAAY;CAEpF,MAAM,cAAoB;EACxB,MAAM,OAAO,KAAK,UAAU,MAAM,CAAC;AACnC,MAAI,UAAU,KAAK,UAAU,KAAK;GAAE,gBAAgB;GAAoB,GAAG,KAAK;GAAS,CAAC;AAC1F,MAAI,IAAI,KAAK;;AAEf,qCAAkB,IAAI;AAGtB,KAAI,kBAAkB,OAAO,KAAK,OAAU,CAAE;AAC9C,KAAI,CAACC,yCAA0B,SAAS,KAAK,QAAQ,EAAE;AACrD,SAAO;AACP;;CAEF,MAAM,YAAYH,gCAAc,KAAK,SAAS,EAAE,WAAW,OAAO,CAAC;AACnE,KAAI;EACF,MAAM,iBAAiBI,2CAA4B,SAAS,KAAK,SAAS,KAAK,gBAAgB;EAC/F,MAAM,kBAAkB,KAAK,cACzBC,qCACE,gBACA,KAAK,IAAI,GAAG,KAAK,KAAK,KAAK,gBAAgB,KAAK,UAAU,CAAC,EAC3D,KACD,GACD;AACJ,QAAMC,yBACJC,mCACE,SACA,KAAK,eACL,KAAK,WACL,iBACA,KAAK,YACN,EACD,UAAU,OACX;AACD,MAAI,kBAAkB,OAAO,KAAK,UAAU,CAAE;AAC9C,SAAO;WACC;AACR,YAAU,SAAS"}