@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
package/dist/helpers.cjs CHANGED
@@ -1,4 +1,7 @@
1
1
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ const require_estimate = require('./response/usage/estimate.cjs');
3
+ const require_openai = require('./response/usage/codecs/openai.cjs');
4
+ const require_errors = require('./response/errors.cjs');
2
5
  const require_constants = require('./constants.cjs');
3
6
  const require_echo_text = require('./echo-text.cjs');
4
7
  const require_message_text = require('./message-text.cjs');
@@ -213,12 +216,331 @@ function requireEmittedFunctionToolCalls(response, wire) {
213
216
  if (Array.isArray(response.blocks) && response.blocks.length > 0) return [];
214
217
  return requireFunctionToolCalls(response.toolCalls ?? []);
215
218
  }
216
- /** True for the fixture tool-call errors a handler surfaces as a coded 500. */
219
+ /**
220
+ * A fixture's model-generated `files` reached a wire that has no faithful
221
+ * projection for them. Gemini (`inlineData` parts) and the OpenAI Responses
222
+ * API (`image_generation_call` items, `image/*` only) serve generated files.
223
+ * Chat Completions (OpenAI, Azure OpenAI, OpenRouter and BytePlus ModelArk)
224
+ * and Anthropic Messages raise this through {@link rejectGeneratedFiles}, and
225
+ * the Responses API raises a subclass for a non-`image/*` file, before any
226
+ * content is written. The handler surfaces it as a coded 500
227
+ * (`aimock_unsupported_generated_file`) like {@link UnsupportedToolCallError}.
228
+ */
229
+ var UnsupportedGeneratedFileError = class extends Error {
230
+ wire;
231
+ constructor(wire) {
232
+ super(`aimock: fixture "files" (model-generated files) are only supported on Gemini and the OpenAI Responses API; this request arrived on ${wire}`);
233
+ this.name = "UnsupportedGeneratedFileError";
234
+ this.wire = wire;
235
+ }
236
+ };
237
+ /**
238
+ * Reject a fixture that sets a non-empty `files` on a wire that cannot carry
239
+ * model-generated files. Throws {@link UnsupportedGeneratedFileError} naming
240
+ * `wire`. A malformed `files` value (see {@link fixtureFiles}) throws
241
+ * {@link InvalidFixtureOutputError} (`aimock_invalid_fixture_file`) first.
242
+ * Chat Completions and Anthropic Messages call this. Gemini and OpenAI
243
+ * Responses serve `files`; other wires ignore the field.
244
+ */
245
+ function rejectGeneratedFiles(response, wire) {
246
+ if (fixtureFiles(response.files).length > 0) throw new UnsupportedGeneratedFileError(wire);
247
+ }
248
+ /**
249
+ * A fixture's `citations` or `files` is malformed: not an array, an entry
250
+ * missing a required field, a non-integer offset, citation offsets outside
251
+ * `0 <= startIndex <= endIndex <= text.length`, a file citation `index`
252
+ * outside `0 <= index <= text.length`, an offset or `index` that splits a
253
+ * UTF-16 surrogate pair, a citation that mixes URL and file citation fields,
254
+ * or any `citations` but an empty array on a turn with no text (tool calls
255
+ * only, `blocks` with no text block, or empty content). The wires that read
256
+ * these keys (Chat Completions, Anthropic Messages, Gemini and OpenAI
257
+ * Responses) read them
258
+ * through {@link fixtureFiles} and {@link fixtureCitations}, which throw this
259
+ * at serve time, before any byte is written; the handler surfaces it as a
260
+ * coded 500 like {@link UnsupportedGeneratedFileError}. Other wires ignore
261
+ * `citations` and `files`, so they never throw this. The message names the
262
+ * offending entry and how to fix the fixture.
263
+ */
264
+ var InvalidFixtureOutputError = class extends Error {
265
+ code;
266
+ constructor(code, problem) {
267
+ super(`aimock: invalid fixture "${code === "aimock_invalid_fixture_file" ? "files" : "citations"}": ${problem}`);
268
+ this.name = "InvalidFixtureOutputError";
269
+ this.code = code;
270
+ }
271
+ };
272
+ /**
273
+ * A short description of a fixture value for an error message. Never throws:
274
+ * a programmatic fixture can hold values JSON cannot carry (BigInt, Symbol,
275
+ * function, NaN, Infinity), and each gets a readable name.
276
+ */
277
+ function describeFixtureValue(value) {
278
+ if (value === void 0) return "undefined";
279
+ if (Array.isArray(value)) return "an array";
280
+ if (value !== null && typeof value === "object") return "an object";
281
+ if (typeof value === "function") return "a function";
282
+ if (typeof value === "symbol") return value.toString();
283
+ if (typeof value === "bigint") return `${value}n`;
284
+ if (typeof value === "number" && !Number.isFinite(value)) return String(value);
285
+ const json = JSON.stringify(value);
286
+ return json.length > 40 ? `${json.slice(0, 37)}...` : json;
287
+ }
288
+ /**
289
+ * The UTF-16 index `at` falls between the two halves of a surrogate pair, so
290
+ * a span that starts or ends there cuts a character in half.
291
+ */
292
+ function splitsSurrogatePair(text, at) {
293
+ if (at <= 0 || at >= text.length) return false;
294
+ const before = text.charCodeAt(at - 1);
295
+ const after = text.charCodeAt(at);
296
+ return before >= 55296 && before <= 56319 && after >= 56320 && after <= 57343;
297
+ }
298
+ /**
299
+ * `text` cut into slices of at most `chunkSize` UTF-16 units, never between
300
+ * the two halves of a surrogate pair: a cut that would land inside a pair
301
+ * moves back before it, or, when that would leave the slice empty
302
+ * (`chunkSize` 1), forward past it. The slices rejoin to `text` exactly.
303
+ */
304
+ function surrogateSafeChunks(text, chunkSize) {
305
+ const chunks = [];
306
+ for (let i = 0; i < text.length;) {
307
+ let end = Math.min(i + chunkSize, text.length);
308
+ const high = text.charCodeAt(end - 1);
309
+ const low = text.charCodeAt(end);
310
+ if (high >= 55296 && high <= 56319 && low >= 56320 && low <= 57343) end = end - 1 > i ? end - 1 : end + 1;
311
+ chunks.push(text.slice(i, end));
312
+ i = end;
313
+ }
314
+ return chunks;
315
+ }
316
+ /** The message for a citation offset that splits a surrogate pair. */
317
+ function surrogateSplitProblem(where, at) {
318
+ return `${where} ${at} splits a UTF-16 surrogate pair (one character, e.g. an emoji); fix the offset to fall before or after the whole character`;
319
+ }
320
+ /** Fields only a URL citation has. */
321
+ const URL_CITATION_FIELDS = [
322
+ "url",
323
+ "title",
324
+ "startIndex",
325
+ "endIndex"
326
+ ];
327
+ /** Fields only a file citation has. */
328
+ const FILE_CITATION_FIELDS = [
329
+ "fileId",
330
+ "filename",
331
+ "index"
332
+ ];
333
+ /**
334
+ * A citation that mixes URL and file citation fields, or a file-shaped one
335
+ * (`fileId` / `filename` / `index`) with no `type`, which would otherwise be
336
+ * read as a URL citation and lose its file data. Undefined when the fields
337
+ * agree.
338
+ */
339
+ function mixedCitationProblem(citation, i) {
340
+ const present = (names) => names.filter((n) => citation[n] != null);
341
+ const fileFields = present(FILE_CITATION_FIELDS);
342
+ if (fileFields.length === 0) return void 0;
343
+ const urlFields = present(URL_CITATION_FIELDS);
344
+ const fix = citation.type === "file" ? `remove the URL citation fields (${urlFields.join(", ")}) from this file citation` : citation.type === "url" ? `remove the file citation fields (${fileFields.join(", ")}) from this URL citation, or set type: "file" for a file citation` : `set type: "file" for a file citation, or remove the stray fields`;
345
+ if (urlFields.length > 0) return `citations[${i}] mixes URL citation fields (${urlFields.join(", ")}) with file citation fields (${fileFields.join(", ")}); ${fix}`;
346
+ if (citation.type == null) return `citations[${i}] has file citation fields (${fileFields.join(", ")}) but no type; ${fix}`;
347
+ if (citation.type === "url") return `citations[${i}] has type "url" but file citation fields (${fileFields.join(", ")}); ${fix}`;
348
+ }
349
+ /** "an object", "a string", ... for a value that should have been an array. */
350
+ function describeFixtureKind(value) {
351
+ if (value === null) return "null";
352
+ if (value !== null && typeof value === "object") return "an object";
353
+ return typeof value === "string" ? "a string" : `a ${typeof value}`;
354
+ }
355
+ /**
356
+ * What is wrong with a fixture `files` value, or undefined when it is absent
357
+ * or an array of `{ mimeType, data }` string pairs. Shared by the serve-time
358
+ * check ({@link fixtureFiles}) and fixture load validation.
359
+ */
360
+ function fixtureFilesProblem(files) {
361
+ if (files === void 0 || files === null) return void 0;
362
+ if (!Array.isArray(files)) return `"files" must be an array of { mimeType, data } objects, got ${describeFixtureKind(files)}; wrap a single file in [ ]`;
363
+ for (let i = 0; i < files.length; i++) {
364
+ const file = files[i];
365
+ if (file === null || typeof file !== "object" || Array.isArray(file)) return `files[${i}] must be a { mimeType, data } object, got ${describeFixtureValue(file)}`;
366
+ const { mimeType, data } = file;
367
+ if (typeof mimeType !== "string" || mimeType.length === 0) return `files[${i}].mimeType must be a non-empty string, got ${describeFixtureValue(mimeType)}; set the file's MIME type, e.g. "image/png"`;
368
+ if (typeof data !== "string") return `files[${i}].data must be a string, got ${describeFixtureValue(data)}; set the base64-encoded file bytes`;
369
+ }
370
+ }
371
+ /**
372
+ * What is wrong with a fixture `citations` value, or undefined when it is
373
+ * absent or valid: an array of citation objects. A URL citation (no `type`,
374
+ * or `type: "url"`) has a non-empty string `url`, an optional string `title`
375
+ * and optional integer offsets. A file citation (`type: "file"`) has a
376
+ * non-empty string `fileId` and `filename` and an optional integer `index`;
377
+ * it has no `url`. When `text` is given, the resolved offsets must also
378
+ * satisfy `0 <= startIndex <= endIndex <= text.length`, and a file citation's
379
+ * `index` must satisfy `0 <= index <= text.length`, and no offset may split a
380
+ * UTF-16 surrogate pair. A citation must not mix URL and file citation
381
+ * fields, and one with file fields needs `type: "file"`. A `null` value, or a
382
+ * `null` optional field, is treated as absent. An empty `text` is a turn with
383
+ * no text (tool calls only, `blocks` with no text block, or empty content): a
384
+ * well-formed non-empty array is then a problem, since there is nothing to
385
+ * cite; a malformed value is reported by its shape first. Shared by the
386
+ * serve-time check ({@link fixtureCitations}) and fixture load validation.
387
+ */
388
+ function fixtureCitationsProblem(citations, text) {
389
+ if (citations === void 0 || citations === null) return void 0;
390
+ if (!Array.isArray(citations)) return `"citations" must be an array of { url, title?, startIndex?, endIndex? } or { type: "file", fileId, filename, index? } objects, got ${describeFixtureKind(citations)}; wrap a single citation in [ ]`;
391
+ const shape = citationEntriesProblem(citations, void 0);
392
+ if (shape !== void 0 || text === void 0) return shape;
393
+ if (text === "" && citations.length > 0) return "\"citations\" has nothing to cite: this turn has no text (only tool calls, or empty content); add text to the response or remove the citations";
394
+ return citationEntriesProblem(citations, text);
395
+ }
396
+ /**
397
+ * What is wrong with the entries of a `citations` array, or undefined when
398
+ * all are valid. Offsets are checked against `text` only when it is given. A
399
+ * `null` optional field (`type`, `title`, `startIndex`, `endIndex`, `index`)
400
+ * is treated as absent, as a `null` top-level key is.
401
+ */
402
+ function citationEntriesProblem(citations, text) {
403
+ for (let i = 0; i < citations.length; i++) {
404
+ const citation = citations[i];
405
+ if (citation === null || typeof citation !== "object" || Array.isArray(citation)) return `citations[${i}] must be a { url, title?, startIndex?, endIndex? } or { type: "file", fileId, filename, index? } object, got ${describeFixtureValue(citation)}`;
406
+ const fields = citation;
407
+ const url = fields.url;
408
+ const type = fields.type ?? void 0;
409
+ const title = fields.title ?? void 0;
410
+ const startIndex = fields.startIndex ?? void 0;
411
+ const endIndex = fields.endIndex ?? void 0;
412
+ if (type === void 0 || type === "url" || type === "file") {
413
+ const mixed = mixedCitationProblem(citation, i);
414
+ if (mixed !== void 0) return mixed;
415
+ }
416
+ if (type === "file") {
417
+ const problem = fixtureFileCitationProblem(citation, i, text);
418
+ if (problem !== void 0) return problem;
419
+ continue;
420
+ }
421
+ if (type !== void 0 && type !== "url") return `citations[${i}].type must be "url" or "file" when set, got ${describeFixtureValue(type)}; omit it for a URL citation`;
422
+ if (typeof url !== "string" || url.length === 0) return `citations[${i}].url must be a non-empty string, got ${describeFixtureValue(url)}; set the cited source URL`;
423
+ if (title !== void 0 && typeof title !== "string") return `citations[${i}].title must be a string when set, got ${describeFixtureValue(title)}`;
424
+ for (const [name, value] of [["startIndex", startIndex], ["endIndex", endIndex]]) if (value !== void 0 && !Number.isInteger(value)) return `citations[${i}].${name} must be an integer when set, got ${describeFixtureValue(value)}; give a character offset into the text, or omit it`;
425
+ if (text === void 0) continue;
426
+ const start = startIndex ?? 0;
427
+ const end = endIndex ?? text.length;
428
+ if (start < 0 || start > end || end > text.length) return `citations[${i}] offsets must satisfy 0 <= startIndex <= endIndex <= text length (${text.length}), got startIndex ${start}, endIndex ${end}; fix the offsets, or omit them to cite the whole text`;
429
+ if (splitsSurrogatePair(text, start)) return surrogateSplitProblem(`citations[${i}].startIndex`, start);
430
+ if (splitsSurrogatePair(text, end)) return surrogateSplitProblem(`citations[${i}].endIndex`, end);
431
+ }
432
+ }
433
+ /** What is wrong with the file citation `citations[i]`, or undefined when valid. */
434
+ function fixtureFileCitationProblem(citation, i, text) {
435
+ const { fileId, filename } = citation;
436
+ const index = citation.index ?? void 0;
437
+ if (typeof fileId !== "string" || fileId.length === 0) return `citations[${i}].fileId must be a non-empty string, got ${describeFixtureValue(fileId)}; set the cited file's ID, e.g. "file-abc123"`;
438
+ if (typeof filename !== "string" || filename.length === 0) return `citations[${i}].filename must be a non-empty string, got ${describeFixtureValue(filename)}; set the cited file's name`;
439
+ if (index !== void 0 && !Number.isInteger(index)) return `citations[${i}].index must be an integer when set, got ${describeFixtureValue(index)}; give a character position in the text, or omit it`;
440
+ if (text === void 0) return void 0;
441
+ const at = index ?? text.length;
442
+ if (at < 0 || at > text.length) return `citations[${i}].index must satisfy 0 <= index <= text length (${text.length}), got ${at}; fix the index, or omit it to cite the end of the text`;
443
+ if (splitsSurrogatePair(text, at)) return surrogateSplitProblem(`citations[${i}].index`, at);
444
+ }
445
+ /**
446
+ * Fixture `citations`, checked against the text they cite: the array itself,
447
+ * or empty when absent. Throws {@link InvalidFixtureOutputError}
448
+ * (`aimock_invalid_fixture_citation`) for every problem
449
+ * {@link fixtureCitationsProblem} reports: a malformed value, an offset
450
+ * outside the text or one that splits a surrogate pair, mixed URL and file
451
+ * citation fields, or citations on a turn with no text (`content` is empty:
452
+ * tool calls only, `blocks` with no text block, or empty content). Every
453
+ * provider that reads `citations` goes through this.
454
+ */
455
+ function fixtureCitations(content, citations) {
456
+ const problem = fixtureCitationsProblem(citations, content);
457
+ if (problem !== void 0) throw new InvalidFixtureOutputError("aimock_invalid_fixture_citation", problem);
458
+ return citations ?? [];
459
+ }
460
+ /**
461
+ * Fixture `files`, checked: the array itself, or empty when absent. Throws
462
+ * {@link InvalidFixtureOutputError} (`aimock_invalid_fixture_file`) for a
463
+ * malformed value. Every provider that reads `files` goes through this.
464
+ */
465
+ function fixtureFiles(files) {
466
+ const problem = fixtureFilesProblem(files);
467
+ if (problem !== void 0) throw new InvalidFixtureOutputError("aimock_invalid_fixture_file", problem);
468
+ return files ?? [];
469
+ }
470
+ /**
471
+ * Fixture URL `citations` against the text they cite, with defaults applied:
472
+ * the title falls back to the URL and the offsets to the whole text. Empty
473
+ * when the fixture sets none. File citations (`type: "file"`) are skipped:
474
+ * only OpenAI Responses has a wire shape for them (`file_citation`), and it
475
+ * builds those itself. Chat Completions, Anthropic Messages and Gemini, which
476
+ * resolve through here, serve URL citations only. This reads `citations`
477
+ * through {@link fixtureCitations}, so it is the serve-time check for those
478
+ * three wires: every problem {@link fixtureCitationsProblem} reports against
479
+ * `content`, including one in a file citation it then skips, throws
480
+ * {@link InvalidFixtureOutputError} (`aimock_invalid_fixture_citation`).
481
+ * OpenAI Responses calls {@link fixtureCitations} directly. Other wires
482
+ * ignore `citations`.
483
+ */
484
+ function resolveCitations(content, citations) {
485
+ return fixtureCitations(content, citations).flatMap((c) => c.type === "file" ? [] : [c]).map((c) => ({
486
+ url: c.url,
487
+ title: c.title ?? c.url,
488
+ startIndex: c.startIndex ?? 0,
489
+ endIndex: c.endIndex ?? content.length
490
+ }));
491
+ }
492
+ /**
493
+ * Fixture `citations` as Chat Completions `url_citation` annotations. File
494
+ * citations are skipped (see {@link resolveCitations}): Chat Completions has no
495
+ * `file_citation` annotation.
496
+ */
497
+ function chatCompletionAnnotations(content, citations) {
498
+ return resolveCitations(content, citations).map((c) => ({
499
+ type: "url_citation",
500
+ url_citation: {
501
+ url: c.url,
502
+ title: c.title,
503
+ start_index: c.startIndex,
504
+ end_index: c.endIndex
505
+ }
506
+ }));
507
+ }
508
+ /** `{ annotations }` for a Chat Completions message, or nothing when the fixture has no citations. */
509
+ function annotationsField(content, overrides) {
510
+ const annotations = chatCompletionAnnotations(content, overrides?.citations);
511
+ return annotations.length > 0 ? { annotations } : {};
512
+ }
513
+ /**
514
+ * The streamed form of {@link chatCompletionAnnotations}: one chunk whose
515
+ * `delta.annotations` holds every annotation, sent after the content and
516
+ * before the finish chunk. Nothing when the fixture has no citations.
517
+ */
518
+ function chatAnnotationChunks(content, overrides, envelope) {
519
+ const annotations = chatCompletionAnnotations(content, overrides?.citations);
520
+ if (annotations.length === 0) return [];
521
+ const fingerprint = overrides?.systemFingerprint;
522
+ return [{
523
+ id: envelope.id,
524
+ object: "chat.completion.chunk",
525
+ created: envelope.created,
526
+ model: envelope.model,
527
+ choices: [{
528
+ index: 0,
529
+ delta: { annotations },
530
+ logprobs: null,
531
+ finish_reason: null
532
+ }],
533
+ ...fingerprint !== void 0 && { system_fingerprint: fingerprint }
534
+ }];
535
+ }
536
+ /** True for the fixture errors a handler surfaces as a coded 500. */
217
537
  function isFixtureToolCallError(error) {
218
- return error instanceof InvalidToolArgumentsError || error instanceof UnsupportedToolCallError || error instanceof InvalidFixtureToolCallError;
538
+ return error instanceof InvalidToolArgumentsError || error instanceof UnsupportedToolCallError || error instanceof InvalidFixtureToolCallError || error instanceof UnsupportedGeneratedFileError || error instanceof InvalidFixtureOutputError;
219
539
  }
220
540
  /** The aimock error code carried in every provider envelope for a fixture tool-call error. */
221
541
  function fixtureToolCallErrorCode(error) {
542
+ if (error instanceof UnsupportedGeneratedFileError) return "aimock_unsupported_generated_file";
543
+ if (error instanceof InvalidFixtureOutputError) return error.code;
222
544
  if (error instanceof UnsupportedToolCallError) return "aimock_unsupported_tool_call";
223
545
  if (error instanceof InvalidFixtureToolCallError) return error.code;
224
546
  return "aimock_invalid_tool_arguments";
@@ -237,9 +559,10 @@ function googleFixtureToolCallErrorDetails(code) {
237
559
  }];
238
560
  }
239
561
  /**
240
- * Run a WebSocket preflight `check` that may raise a fixture tool-call error
241
- * ({@link InvalidToolArgumentsError}, {@link UnsupportedToolCallError} or
242
- * {@link InvalidFixtureToolCallError}).
562
+ * Run a WebSocket preflight `check` that may raise a fixture error
563
+ * ({@link InvalidToolArgumentsError}, {@link UnsupportedToolCallError},
564
+ * {@link InvalidFixtureToolCallError}, {@link UnsupportedGeneratedFileError}
565
+ * or {@link InvalidFixtureOutputError}).
243
566
  * Such an error marks the already-journaled entry as a 500 carrying the
244
567
  * message, then propagates to the transport's error handler.
245
568
  */
@@ -254,27 +577,6 @@ function journalFixtureToolCallError(journalEntry, check) {
254
577
  throw error;
255
578
  }
256
579
  }
257
- /**
258
- * Resolve effective strict mode from per-request header and server default.
259
- * Header values override the server default — same precedence pattern as chaos
260
- * config headers (see resolveChaosConfig in chaos.ts).
261
- *
262
- * Header: `X-AIMock-Strict` — "true"/"1" → strict on, "false"/"0" → strict off
263
- * (case-insensitive, surrounding whitespace trimmed).
264
- * When absent or unrecognised, falls back to the server-level default.
265
- */
266
- function resolveStrictMode(serverDefault, rawHeaders) {
267
- if (rawHeaders) {
268
- const header = rawHeaders["x-aimock-strict"];
269
- const rawVal = typeof header === "string" ? header : Array.isArray(header) ? header[0] : void 0;
270
- if (typeof rawVal === "string") {
271
- const val = rawVal.trim().toLowerCase();
272
- if (val === "true" || val === "1") return true;
273
- if (val === "false" || val === "0") return false;
274
- }
275
- }
276
- return serverDefault ?? false;
277
- }
278
580
  const STRICT_INTEGER_RE = /^\d+$/;
279
581
  /**
280
582
  * Strict decimal-integer grammar shared by the query/list parsers that grew
@@ -307,18 +609,6 @@ function wouldProxyMiss(effectiveStrict, record, providerKey) {
307
609
  return Boolean(record?.providers?.[providerKey]);
308
610
  }
309
611
  /**
310
- * Returns `true` or `false` when the X-AIMock-Strict header overrides the
311
- * server default, or `undefined` when it doesn't. Designed to be spread
312
- * directly into a journal entry's `response` object:
313
- *
314
- * response: { status, fixture, ...strictOverrideField(defaults.strict, req.headers) }
315
- */
316
- function strictOverrideField(serverDefault, rawHeaders) {
317
- const effective = resolveStrictMode(serverDefault, rawHeaders);
318
- if (effective !== (serverDefault ?? false)) return { strictOverride: effective };
319
- return {};
320
- }
321
- /**
322
612
  * Build the strict-mode 503 error message, distinguishing a true no-match from
323
613
  * a sequence/turn-exhausted miss.
324
614
  *
@@ -1056,12 +1346,7 @@ function isErrorResponse(r) {
1056
1346
  * response body. Real LLM APIs don't include it.
1057
1347
  */
1058
1348
  function serializeErrorResponse(response) {
1059
- return JSON.stringify({ error: {
1060
- message: response.error.message,
1061
- type: response.error.type ?? "server_error",
1062
- param: response.error.param ?? null,
1063
- code: response.error.code ?? null
1064
- } });
1349
+ return require_errors.renderError("openai", "fixture", response.error).body;
1065
1350
  }
1066
1351
  function isEmbeddingResponse(r) {
1067
1352
  return "embedding" in r && Array.isArray(r.embedding);
@@ -1102,9 +1387,47 @@ function isVideoResponse(r) {
1102
1387
  function isJSONResponse(r) {
1103
1388
  return "json" in r && r.json !== void 0;
1104
1389
  }
1390
+ /**
1391
+ * Every key some other response guard reads. A response carrying any of them
1392
+ * is that type (with a stray `raw` key the loader has always ignored), never
1393
+ * a raw response — so adding raw support changes nothing for such fixtures.
1394
+ */
1395
+ const NON_RAW_RESPONSE_MARKERS = [
1396
+ "content",
1397
+ "toolCalls",
1398
+ "blocks",
1399
+ "responsesBlocks",
1400
+ "customToolCalls",
1401
+ "error",
1402
+ "embedding",
1403
+ "image",
1404
+ "images",
1405
+ "audio",
1406
+ "transcription",
1407
+ "video",
1408
+ "json",
1409
+ "live"
1410
+ ];
1411
+ /**
1412
+ * @internal Whether `r` is a raw passthrough response: `raw` is a non-null,
1413
+ * non-array object and no other response type's marker key is present. The
1414
+ * shape of `raw` itself is checked by the loader and again at serve time.
1415
+ * Exported for in-repo use only; not part of the public API.
1416
+ *
1417
+ * A fixture added in code can hold a response that is not an object (null, a
1418
+ * string). `in` throws on such a value, so it is simply not raw.
1419
+ */
1420
+ function isRawResponse(r) {
1421
+ if (typeof r !== "object" || r === null || !("raw" in r)) return false;
1422
+ const raw = r.raw;
1423
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return false;
1424
+ return !NON_RAW_RESPONSE_MARKERS.some((marker) => marker in r);
1425
+ }
1105
1426
  function extractOverrides(response) {
1106
1427
  const r = response;
1107
1428
  return {
1429
+ ...r.citations !== void 0 && { citations: r.citations },
1430
+ ...r.files !== void 0 && { files: r.files },
1108
1431
  ...r.id !== void 0 && { id: r.id },
1109
1432
  ...r.created !== void 0 && { created: r.created },
1110
1433
  ...r.model !== void 0 && { model: r.model },
@@ -1112,6 +1435,7 @@ function extractOverrides(response) {
1112
1435
  ...r.systemFingerprint !== void 0 && { systemFingerprint: r.systemFingerprint },
1113
1436
  ...r.finishReason !== void 0 && { finishReason: r.finishReason },
1114
1437
  ...r.role !== void 0 && { role: r.role },
1438
+ ...r.phase !== void 0 && { phase: r.phase },
1115
1439
  ...r.provider !== void 0 && { provider: r.provider },
1116
1440
  ...r.nativeFinishReason !== void 0 && { nativeFinishReason: r.nativeFinishReason }
1117
1441
  };
@@ -1121,18 +1445,13 @@ function extractOverrides(response) {
1121
1445
  * Uses the ~4 characters per token heuristic common for English text.
1122
1446
  */
1123
1447
  function estimateTokens(text) {
1124
- return Math.max(1, Math.ceil(text.length / 4));
1448
+ return require_estimate.estimateTokens(text);
1125
1449
  }
1126
1450
  /**
1127
1451
  * Estimate prompt tokens from a request's messages array.
1128
1452
  */
1129
1453
  function estimatePromptTokens(messages) {
1130
- let totalChars = 0;
1131
- for (const msg of messages) if (typeof msg.content === "string") totalChars += msg.content.length;
1132
- else if (Array.isArray(msg.content)) {
1133
- for (const part of msg.content) if (part.text) totalChars += part.text.length;
1134
- }
1135
- return Math.max(1, Math.ceil(totalChars / 4));
1454
+ return require_estimate.estimatePromptTokens(messages);
1136
1455
  }
1137
1456
  /**
1138
1457
  * Build usage object: use explicit overrides if provided, otherwise estimate.
@@ -1143,26 +1462,10 @@ function estimatePromptTokens(messages) {
1143
1462
  * so the streaming path does not re-implement the estimation logic.
1144
1463
  */
1145
1464
  function resolveUsage(overrides, promptText, completionText) {
1146
- if (overrides?.usage) {
1147
- const u = overrides.usage;
1148
- const hasExplicitTokens = u.prompt_tokens !== void 0 || u.completion_tokens !== void 0 || u.total_tokens !== void 0 || u.input_tokens !== void 0 || u.output_tokens !== void 0 || u.promptTokenCount !== void 0 || u.candidatesTokenCount !== void 0 || u.totalTokenCount !== void 0;
1149
- const fallbackPrompt = hasExplicitTokens ? 0 : estimateTokens(promptText || "x");
1150
- const fallbackCompletion = hasExplicitTokens ? 0 : estimateTokens(completionText || "x");
1151
- const prompt = u.prompt_tokens ?? u.input_tokens ?? u.promptTokenCount ?? fallbackPrompt;
1152
- const completion = u.completion_tokens ?? u.output_tokens ?? u.candidatesTokenCount ?? fallbackCompletion;
1153
- return {
1154
- prompt_tokens: prompt,
1155
- completion_tokens: completion,
1156
- total_tokens: u.total_tokens ?? u.totalTokenCount ?? prompt + completion
1157
- };
1158
- }
1159
- const prompt = estimateTokens(promptText || "x");
1160
- const completion = estimateTokens(completionText || "x");
1161
- return {
1162
- prompt_tokens: prompt,
1163
- completion_tokens: completion,
1164
- total_tokens: prompt + completion
1165
- };
1465
+ return require_openai.render(require_openai.resolve(overrides, {
1466
+ promptText,
1467
+ completionText
1468
+ }));
1166
1469
  }
1167
1470
  /**
1168
1471
  * Build an SSE usage chunk for streaming responses.
@@ -1234,6 +1537,11 @@ function buildTextChunks(content, model, chunkSize, reasoning, overrides) {
1234
1537
  ...fingerprint !== void 0 && { system_fingerprint: fingerprint }
1235
1538
  });
1236
1539
  }
1540
+ chunks.push(...chatAnnotationChunks(content, overrides, {
1541
+ id,
1542
+ created,
1543
+ model: effectiveModel
1544
+ }));
1237
1545
  chunks.push({
1238
1546
  id,
1239
1547
  object: "chat.completion.chunk",
@@ -1253,6 +1561,7 @@ function buildTextChunks(content, model, chunkSize, reasoning, overrides) {
1253
1561
  function buildOpenAIReasoningChunks(reasoning, model, chunkSize, exposeReasoning, overrides) {
1254
1562
  return buildTextChunks(exposeReasoning ? reasoning : "", model, chunkSize, void 0, {
1255
1563
  ...overrides,
1564
+ citations: void 0,
1256
1565
  role: "assistant",
1257
1566
  finishReason: "length"
1258
1567
  }).map((chunk) => ({
@@ -1281,6 +1590,7 @@ function buildOpenAIReasoningCompletion(reasoning, model, exposeReasoning, overr
1281
1590
  const visible = exposeReasoning ? reasoning : "";
1282
1591
  const completion = buildTextCompletion(visible, model, void 0, {
1283
1592
  ...overrides,
1593
+ citations: void 0,
1284
1594
  role: "assistant",
1285
1595
  finishReason: "length",
1286
1596
  usage: void 0
@@ -1310,6 +1620,7 @@ function buildOpenAIReasoningCompletion(reasoning, model, exposeReasoning, overr
1310
1620
  function buildOpenAIContentFilterChunks(model, overrides) {
1311
1621
  return buildTextChunks("", model, 1, void 0, {
1312
1622
  ...overrides,
1623
+ citations: void 0,
1313
1624
  role: "assistant",
1314
1625
  finishReason: "content_filter"
1315
1626
  }).map((chunk) => ({
@@ -1327,6 +1638,7 @@ function buildOpenAIContentFilterChunks(model, overrides) {
1327
1638
  function buildOpenAIContentFilterCompletion(model, overrides, requestMessages) {
1328
1639
  const completion = buildTextCompletion("", model, void 0, {
1329
1640
  ...overrides,
1641
+ citations: void 0,
1330
1642
  role: "assistant",
1331
1643
  finishReason: "content_filter",
1332
1644
  usage: void 0
@@ -1347,6 +1659,7 @@ function buildOpenAIContentFilterCompletion(model, overrides, requestMessages) {
1347
1659
  function buildOpenAIRefusalChunks(refusal, model, chunkSize, overrides) {
1348
1660
  return buildTextChunks(refusal, model, chunkSize, void 0, {
1349
1661
  ...overrides,
1662
+ citations: void 0,
1350
1663
  role: "assistant",
1351
1664
  finishReason: "stop"
1352
1665
  }).map((chunk) => ({
@@ -1367,6 +1680,7 @@ function buildOpenAIRefusalChunks(refusal, model, chunkSize, overrides) {
1367
1680
  function buildOpenAIRefusalCompletion(refusal, model, overrides, requestMessages) {
1368
1681
  const completion = buildTextCompletion(refusal, model, void 0, {
1369
1682
  ...overrides,
1683
+ citations: void 0,
1370
1684
  role: "assistant",
1371
1685
  finishReason: "stop",
1372
1686
  usage: void 0
@@ -1384,6 +1698,7 @@ function buildOpenAIRefusalCompletion(refusal, model, overrides, requestMessages
1384
1698
  };
1385
1699
  }
1386
1700
  function buildToolCallChunks(toolCalls, model, chunkSize, reasoning, overrides) {
1701
+ fixtureCitations("", overrides?.citations);
1387
1702
  const id = overrides?.id ?? generateId();
1388
1703
  const created = overrides?.created ?? Math.floor(Date.now() / 1e3);
1389
1704
  const effectiveModel = overrides?.model ?? model;
@@ -1494,7 +1809,8 @@ function buildTextCompletion(content, model, reasoning, overrides, requestMessag
1494
1809
  role: overrides?.role ?? "assistant",
1495
1810
  content,
1496
1811
  refusal: null,
1497
- ...reasoning ? { reasoning_content: reasoning } : {}
1812
+ ...reasoning ? { reasoning_content: reasoning } : {},
1813
+ ...annotationsField(content, overrides)
1498
1814
  },
1499
1815
  logprobs: null,
1500
1816
  finish_reason: overrides?.finishReason ?? "stop"
@@ -1504,6 +1820,7 @@ function buildTextCompletion(content, model, reasoning, overrides, requestMessag
1504
1820
  };
1505
1821
  }
1506
1822
  function buildToolCallCompletion(toolCalls, model, reasoning, overrides, requestMessages) {
1823
+ fixtureCitations("", overrides?.citations);
1507
1824
  const promptText = requestMessages ? requestMessages.map((m) => typeof m.content === "string" ? m.content : Array.isArray(m.content) ? m.content.map((p) => p.text ?? "").join("") : "").join("") : "";
1508
1825
  const completionText = toolCalls.map((tc) => tc.name + tc.arguments).join("");
1509
1826
  return {
@@ -1640,6 +1957,11 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
1640
1957
  }
1641
1958
  tcIdx++;
1642
1959
  }
1960
+ chunks.push(...chatAnnotationChunks(outcome.content, overrides, {
1961
+ id,
1962
+ created,
1963
+ model: effectiveModel
1964
+ }));
1643
1965
  chunks.push({
1644
1966
  id,
1645
1967
  object: "chat.completion.chunk",
@@ -1751,6 +2073,11 @@ function buildContentWithToolCallsChunks(content, toolCalls, model, chunkSize, r
1751
2073
  });
1752
2074
  }
1753
2075
  }
2076
+ chunks.push(...chatAnnotationChunks(content, overrides, {
2077
+ id,
2078
+ created,
2079
+ model: effectiveModel
2080
+ }));
1754
2081
  chunks.push({
1755
2082
  id,
1756
2083
  object: "chat.completion.chunk",
@@ -1788,7 +2115,8 @@ function buildContentWithToolCallsCompletion(content, toolCalls, model, reasonin
1788
2115
  name: tc.name,
1789
2116
  arguments: tc.arguments
1790
2117
  }
1791
- }))
2118
+ })),
2119
+ ...annotationsField(content, overrides)
1792
2120
  },
1793
2121
  logprobs: null,
1794
2122
  finish_reason: overrides?.finishReason ?? "tool_calls"
@@ -2431,10 +2759,12 @@ function parseMcpUndeclared(raw) {
2431
2759
 
2432
2760
  //#endregion
2433
2761
  exports.FORMAT_TO_CONTENT_TYPE = FORMAT_TO_CONTENT_TYPE;
2762
+ exports.InvalidFixtureOutputError = InvalidFixtureOutputError;
2434
2763
  exports.InvalidFixtureToolCallError = InvalidFixtureToolCallError;
2435
2764
  exports.InvalidToolArgumentsError = InvalidToolArgumentsError;
2436
2765
  exports.MAX_EMBEDDING_DIMENSIONS = MAX_EMBEDDING_DIMENSIONS;
2437
2766
  exports.RequestBodyTooLargeError = RequestBodyTooLargeError;
2767
+ exports.UnsupportedGeneratedFileError = UnsupportedGeneratedFileError;
2438
2768
  exports.UnsupportedToolCallError = UnsupportedToolCallError;
2439
2769
  exports.assertCustomToolCalls = assertCustomToolCalls;
2440
2770
  exports.assertResponsesToolCalls = assertResponsesToolCalls;
@@ -2458,6 +2788,10 @@ exports.describeMatch = describeMatch;
2458
2788
  exports.estimatePromptTokens = estimatePromptTokens;
2459
2789
  exports.estimateTokens = estimateTokens;
2460
2790
  exports.extractOverrides = extractOverrides;
2791
+ exports.fixtureCitations = fixtureCitations;
2792
+ exports.fixtureCitationsProblem = fixtureCitationsProblem;
2793
+ exports.fixtureFiles = fixtureFiles;
2794
+ exports.fixtureFilesProblem = fixtureFilesProblem;
2461
2795
  exports.fixtureListTarget = fixtureListTarget;
2462
2796
  exports.fixtureToolCallErrorCode = fixtureToolCallErrorCode;
2463
2797
  exports.flattenHeaders = flattenHeaders;
@@ -2482,6 +2816,7 @@ exports.isImageResponse = isImageResponse;
2482
2816
  exports.isJSONResponse = isJSONResponse;
2483
2817
  exports.isJsonObject = isJsonObject;
2484
2818
  exports.isLiveResponse = isLiveResponse;
2819
+ exports.isRawResponse = isRawResponse;
2485
2820
  exports.isResponseFactory = isResponseFactory;
2486
2821
  exports.isServerOwnedFixtures = isServerOwnedFixtures;
2487
2822
  exports.isTextResponse = isTextResponse;
@@ -2501,10 +2836,12 @@ exports.prepareOpenAIChatMisbehavior = prepareOpenAIChatMisbehavior;
2501
2836
  exports.readBody = readBody;
2502
2837
  exports.readBodyBufferBounded = readBodyBufferBounded;
2503
2838
  exports.rebuildOrderedBlocks = rebuildOrderedBlocks;
2839
+ exports.rejectGeneratedFiles = rejectGeneratedFiles;
2504
2840
  exports.rejectResponsesOnlyToolCalls = rejectResponsesOnlyToolCalls;
2505
2841
  exports.requireEmittedFunctionToolCalls = requireEmittedFunctionToolCalls;
2506
2842
  exports.requireFunctionToolCalls = requireFunctionToolCalls;
2507
2843
  exports.requireServedFunctionToolCalls = requireServedFunctionToolCalls;
2844
+ exports.resolveCitations = resolveCitations;
2508
2845
  exports.resolveFixtureBlockOutcome = resolveFixtureBlockOutcome;
2509
2846
  exports.resolveFixtureBlocks = resolveFixtureBlocks;
2510
2847
  exports.resolveMcpIdentity = resolveMcpIdentity;
@@ -2515,7 +2852,6 @@ exports.resolveRequestId = resolveRequestId;
2515
2852
  exports.resolveResponse = resolveResponse;
2516
2853
  exports.resolveResponsesBlocks = resolveResponsesBlocks;
2517
2854
  exports.resolveServedBlockOutcome = resolveServedBlockOutcome;
2518
- exports.resolveStrictMode = resolveStrictMode;
2519
2855
  exports.resolveTestId = resolveTestId;
2520
2856
  exports.resolveUsage = resolveUsage;
2521
2857
  exports.runWithToolArgumentsScope = runWithToolArgumentsScope;
@@ -2526,8 +2862,8 @@ exports.slugifyContext = slugifyContext;
2526
2862
  exports.slugifyTestId = slugifyTestId;
2527
2863
  exports.strictNoMatchLogLine = strictNoMatchLogLine;
2528
2864
  exports.strictNoMatchMessage = strictNoMatchMessage;
2529
- exports.strictOverrideField = strictOverrideField;
2530
2865
  exports.strictToolArgumentsEnabled = strictToolArgumentsEnabled;
2866
+ exports.surrogateSafeChunks = surrogateSafeChunks;
2531
2867
  exports.toolArgsForWire = toolArgsForWire;
2532
2868
  exports.toolCallFixtureBlock = toolCallFixtureBlock;
2533
2869
  exports.validateChatMessages = validateChatMessages;