@copilotkit/aimock 1.43.0 → 1.45.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 (396) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +46 -0
  4. package/README.md +14 -2
  5. package/dist/agui-handler.d.ts.map +1 -1
  6. package/dist/aimock-cli.cjs +31 -5
  7. package/dist/aimock-cli.cjs.map +1 -1
  8. package/dist/aimock-cli.d.cts.map +1 -1
  9. package/dist/aimock-cli.d.ts.map +1 -1
  10. package/dist/aimock-cli.js +31 -5
  11. package/dist/aimock-cli.js.map +1 -1
  12. package/dist/bedrock-converse.cjs +344 -43
  13. package/dist/bedrock-converse.cjs.map +1 -1
  14. package/dist/bedrock-converse.d.cts.map +1 -1
  15. package/dist/bedrock-converse.d.ts.map +1 -1
  16. package/dist/bedrock-converse.js +345 -44
  17. package/dist/bedrock-converse.js.map +1 -1
  18. package/dist/bedrock.cjs +195 -42
  19. package/dist/bedrock.cjs.map +1 -1
  20. package/dist/bedrock.d.cts.map +1 -1
  21. package/dist/bedrock.d.ts.map +1 -1
  22. package/dist/bedrock.js +196 -43
  23. package/dist/bedrock.js.map +1 -1
  24. package/dist/chaos.cjs +9 -5
  25. package/dist/chaos.cjs.map +1 -1
  26. package/dist/chaos.d.cts.map +1 -1
  27. package/dist/chaos.d.ts.map +1 -1
  28. package/dist/chaos.js +10 -7
  29. package/dist/chaos.js.map +1 -1
  30. package/dist/cli.cjs +238 -9
  31. package/dist/cli.cjs.map +1 -1
  32. package/dist/cli.js +242 -13
  33. package/dist/cli.js.map +1 -1
  34. package/dist/cohere.cjs +159 -72
  35. package/dist/cohere.cjs.map +1 -1
  36. package/dist/cohere.d.cts.map +1 -1
  37. package/dist/cohere.d.ts.map +1 -1
  38. package/dist/cohere.js +160 -73
  39. package/dist/cohere.js.map +1 -1
  40. package/dist/config-loader.cjs +63 -5
  41. package/dist/config-loader.cjs.map +1 -1
  42. package/dist/config-loader.d.cts +37 -4
  43. package/dist/config-loader.d.cts.map +1 -1
  44. package/dist/config-loader.d.ts +37 -4
  45. package/dist/config-loader.d.ts.map +1 -1
  46. package/dist/config-loader.js +63 -5
  47. package/dist/config-loader.js.map +1 -1
  48. package/dist/constants.cjs +8 -0
  49. package/dist/constants.cjs.map +1 -1
  50. package/dist/constants.d.cts +6 -2
  51. package/dist/constants.d.ts +6 -2
  52. package/dist/constants.js +8 -1
  53. package/dist/constants.js.map +1 -1
  54. package/dist/echo-text.cjs +65 -0
  55. package/dist/echo-text.cjs.map +1 -0
  56. package/dist/echo-text.d.cts +22 -0
  57. package/dist/echo-text.d.cts.map +1 -0
  58. package/dist/echo-text.d.ts +22 -0
  59. package/dist/echo-text.d.ts.map +1 -0
  60. package/dist/echo-text.js +65 -0
  61. package/dist/echo-text.js.map +1 -0
  62. package/dist/embeddings.cjs +18 -1
  63. package/dist/embeddings.cjs.map +1 -1
  64. package/dist/embeddings.d.cts +1 -1
  65. package/dist/embeddings.d.cts.map +1 -1
  66. package/dist/embeddings.d.ts +1 -1
  67. package/dist/embeddings.d.ts.map +1 -1
  68. package/dist/embeddings.js +18 -1
  69. package/dist/embeddings.js.map +1 -1
  70. package/dist/fakes-plugin.cjs +131 -0
  71. package/dist/fakes-plugin.cjs.map +1 -0
  72. package/dist/fakes-plugin.d.cts +23 -0
  73. package/dist/fakes-plugin.d.cts.map +1 -0
  74. package/dist/fakes-plugin.d.ts +23 -0
  75. package/dist/fakes-plugin.d.ts.map +1 -0
  76. package/dist/fakes-plugin.js +127 -0
  77. package/dist/fakes-plugin.js.map +1 -0
  78. package/dist/files.cjs +9 -11
  79. package/dist/files.cjs.map +1 -1
  80. package/dist/files.d.cts.map +1 -1
  81. package/dist/files.d.ts.map +1 -1
  82. package/dist/files.js +10 -13
  83. package/dist/files.js.map +1 -1
  84. package/dist/fine-tuning.cjs +1 -19
  85. package/dist/fine-tuning.cjs.map +1 -1
  86. package/dist/fine-tuning.d.cts.map +1 -1
  87. package/dist/fine-tuning.d.ts.map +1 -1
  88. package/dist/fine-tuning.js +2 -20
  89. package/dist/fine-tuning.js.map +1 -1
  90. package/dist/fixture-loader-services.cjs +116 -0
  91. package/dist/fixture-loader-services.cjs.map +1 -0
  92. package/dist/fixture-loader-services.d.cts +48 -0
  93. package/dist/fixture-loader-services.d.cts.map +1 -0
  94. package/dist/fixture-loader-services.d.ts +48 -0
  95. package/dist/fixture-loader-services.d.ts.map +1 -0
  96. package/dist/fixture-loader-services.js +114 -0
  97. package/dist/fixture-loader-services.js.map +1 -0
  98. package/dist/fixture-loader.cjs +552 -29
  99. package/dist/fixture-loader.cjs.map +1 -1
  100. package/dist/fixture-loader.d.cts +140 -2
  101. package/dist/fixture-loader.d.cts.map +1 -1
  102. package/dist/fixture-loader.d.ts +140 -2
  103. package/dist/fixture-loader.d.ts.map +1 -1
  104. package/dist/fixture-loader.js +542 -31
  105. package/dist/fixture-loader.js.map +1 -1
  106. package/dist/gemini-embeddings.cjs +42 -2
  107. package/dist/gemini-embeddings.cjs.map +1 -1
  108. package/dist/gemini-embeddings.js +43 -3
  109. package/dist/gemini-embeddings.js.map +1 -1
  110. package/dist/gemini-interactions.cjs +288 -52
  111. package/dist/gemini-interactions.cjs.map +1 -1
  112. package/dist/gemini-interactions.d.cts.map +1 -1
  113. package/dist/gemini-interactions.d.ts.map +1 -1
  114. package/dist/gemini-interactions.js +289 -53
  115. package/dist/gemini-interactions.js.map +1 -1
  116. package/dist/gemini.cjs +234 -38
  117. package/dist/gemini.cjs.map +1 -1
  118. package/dist/gemini.d.cts.map +1 -1
  119. package/dist/gemini.d.ts.map +1 -1
  120. package/dist/gemini.js +235 -39
  121. package/dist/gemini.js.map +1 -1
  122. package/dist/helpers.cjs +1157 -12
  123. package/dist/helpers.cjs.map +1 -1
  124. package/dist/helpers.d.cts +85 -4
  125. package/dist/helpers.d.cts.map +1 -1
  126. package/dist/helpers.d.ts +85 -4
  127. package/dist/helpers.d.ts.map +1 -1
  128. package/dist/helpers.js +1113 -14
  129. package/dist/helpers.js.map +1 -1
  130. package/dist/images.cjs +3 -2
  131. package/dist/images.cjs.map +1 -1
  132. package/dist/images.js +3 -2
  133. package/dist/images.js.map +1 -1
  134. package/dist/index.cjs +39 -1
  135. package/dist/index.d.cts +11 -4
  136. package/dist/index.d.ts +11 -4
  137. package/dist/index.js +11 -4
  138. package/dist/jest.cjs +43 -14
  139. package/dist/jest.cjs.map +1 -1
  140. package/dist/jest.d.cts +47 -5
  141. package/dist/jest.d.cts.map +1 -1
  142. package/dist/jest.d.ts +47 -5
  143. package/dist/jest.d.ts.map +1 -1
  144. package/dist/jest.js +45 -16
  145. package/dist/jest.js.map +1 -1
  146. package/dist/journal.cjs +155 -13
  147. package/dist/journal.cjs.map +1 -1
  148. package/dist/journal.d.cts +54 -4
  149. package/dist/journal.d.cts.map +1 -1
  150. package/dist/journal.d.ts +54 -4
  151. package/dist/journal.d.ts.map +1 -1
  152. package/dist/journal.js +155 -13
  153. package/dist/journal.js.map +1 -1
  154. package/dist/live-sanitize.cjs +4 -32
  155. package/dist/live-sanitize.cjs.map +1 -1
  156. package/dist/live-sanitize.js +4 -32
  157. package/dist/live-sanitize.js.map +1 -1
  158. package/dist/llmock.cjs +204 -39
  159. package/dist/llmock.cjs.map +1 -1
  160. package/dist/llmock.d.cts +51 -1
  161. package/dist/llmock.d.cts.map +1 -1
  162. package/dist/llmock.d.ts +51 -1
  163. package/dist/llmock.d.ts.map +1 -1
  164. package/dist/llmock.js +206 -41
  165. package/dist/llmock.js.map +1 -1
  166. package/dist/mcp-fakes-mount.cjs +217 -0
  167. package/dist/mcp-fakes-mount.cjs.map +1 -0
  168. package/dist/mcp-fakes-mount.js +211 -0
  169. package/dist/mcp-fakes-mount.js.map +1 -0
  170. package/dist/mcp-fakes-report.cjs +111 -0
  171. package/dist/mcp-fakes-report.cjs.map +1 -0
  172. package/dist/mcp-fakes-report.d.cts +40 -0
  173. package/dist/mcp-fakes-report.d.cts.map +1 -0
  174. package/dist/mcp-fakes-report.d.ts +40 -0
  175. package/dist/mcp-fakes-report.d.ts.map +1 -0
  176. package/dist/mcp-fakes-report.js +107 -0
  177. package/dist/mcp-fakes-report.js.map +1 -0
  178. package/dist/mcp-fakes.cjs +1942 -0
  179. package/dist/mcp-fakes.cjs.map +1 -0
  180. package/dist/mcp-fakes.d.cts +504 -0
  181. package/dist/mcp-fakes.d.cts.map +1 -0
  182. package/dist/mcp-fakes.d.ts +504 -0
  183. package/dist/mcp-fakes.d.ts.map +1 -0
  184. package/dist/mcp-fakes.js +1937 -0
  185. package/dist/mcp-fakes.js.map +1 -0
  186. package/dist/mcp-handler.cjs +534 -27
  187. package/dist/mcp-handler.cjs.map +1 -1
  188. package/dist/mcp-handler.d.cts +49 -0
  189. package/dist/mcp-handler.d.cts.map +1 -0
  190. package/dist/mcp-handler.d.ts +49 -0
  191. package/dist/mcp-handler.d.ts.map +1 -0
  192. package/dist/mcp-handler.js +530 -28
  193. package/dist/mcp-handler.js.map +1 -1
  194. package/dist/mcp-mock.cjs +326 -47
  195. package/dist/mcp-mock.cjs.map +1 -1
  196. package/dist/mcp-mock.d.cts +97 -1
  197. package/dist/mcp-mock.d.cts.map +1 -1
  198. package/dist/mcp-mock.d.ts +97 -1
  199. package/dist/mcp-mock.d.ts.map +1 -1
  200. package/dist/mcp-mock.js +327 -48
  201. package/dist/mcp-mock.js.map +1 -1
  202. package/dist/mcp-recorder.cjs +1224 -0
  203. package/dist/mcp-recorder.cjs.map +1 -0
  204. package/dist/mcp-recorder.d.cts +108 -0
  205. package/dist/mcp-recorder.d.cts.map +1 -0
  206. package/dist/mcp-recorder.d.ts +108 -0
  207. package/dist/mcp-recorder.d.ts.map +1 -0
  208. package/dist/mcp-recorder.js +1215 -0
  209. package/dist/mcp-recorder.js.map +1 -0
  210. package/dist/mcp-stub.cjs +5 -1
  211. package/dist/mcp-stub.d.cts +3 -1
  212. package/dist/mcp-stub.d.ts +3 -1
  213. package/dist/mcp-stub.js +3 -1
  214. package/dist/mcp-types.d.cts +6 -0
  215. package/dist/mcp-types.d.ts +6 -0
  216. package/dist/message-text.cjs +192 -0
  217. package/dist/message-text.cjs.map +1 -0
  218. package/dist/message-text.d.cts +31 -0
  219. package/dist/message-text.d.cts.map +1 -0
  220. package/dist/message-text.d.ts +31 -0
  221. package/dist/message-text.d.ts.map +1 -0
  222. package/dist/message-text.js +184 -0
  223. package/dist/message-text.js.map +1 -0
  224. package/dist/messages.cjs +400 -56
  225. package/dist/messages.cjs.map +1 -1
  226. package/dist/messages.d.cts.map +1 -1
  227. package/dist/messages.d.ts.map +1 -1
  228. package/dist/messages.js +401 -58
  229. package/dist/messages.js.map +1 -1
  230. package/dist/metrics.cjs +46 -66
  231. package/dist/metrics.cjs.map +1 -1
  232. package/dist/metrics.d.cts +14 -6
  233. package/dist/metrics.d.cts.map +1 -1
  234. package/dist/metrics.d.ts +14 -6
  235. package/dist/metrics.d.ts.map +1 -1
  236. package/dist/metrics.js +32 -40
  237. package/dist/metrics.js.map +1 -1
  238. package/dist/misbehavior.cjs +1523 -0
  239. package/dist/misbehavior.cjs.map +1 -0
  240. package/dist/misbehavior.d.cts +43 -0
  241. package/dist/misbehavior.d.cts.map +1 -0
  242. package/dist/misbehavior.d.ts +43 -0
  243. package/dist/misbehavior.d.ts.map +1 -0
  244. package/dist/misbehavior.js +1511 -0
  245. package/dist/misbehavior.js.map +1 -0
  246. package/dist/ollama.cjs +315 -113
  247. package/dist/ollama.cjs.map +1 -1
  248. package/dist/ollama.d.cts.map +1 -1
  249. package/dist/ollama.d.ts.map +1 -1
  250. package/dist/ollama.js +316 -114
  251. package/dist/ollama.js.map +1 -1
  252. package/dist/openapi.cjs +3405 -0
  253. package/dist/openapi.cjs.map +1 -0
  254. package/dist/openapi.d.cts +30 -0
  255. package/dist/openapi.d.cts.map +1 -0
  256. package/dist/openapi.d.ts +30 -0
  257. package/dist/openapi.d.ts.map +1 -0
  258. package/dist/openapi.js +3404 -0
  259. package/dist/openapi.js.map +1 -0
  260. package/dist/openrouter-video.cjs +4 -4
  261. package/dist/openrouter-video.cjs.map +1 -1
  262. package/dist/openrouter-video.d.cts.map +1 -1
  263. package/dist/openrouter-video.d.ts.map +1 -1
  264. package/dist/openrouter-video.js +4 -4
  265. package/dist/openrouter-video.js.map +1 -1
  266. package/dist/record-sanitize.cjs +231 -0
  267. package/dist/record-sanitize.cjs.map +1 -0
  268. package/dist/record-sanitize.js +224 -0
  269. package/dist/record-sanitize.js.map +1 -0
  270. package/dist/recorder.cjs +115 -6
  271. package/dist/recorder.cjs.map +1 -1
  272. package/dist/recorder.d.cts +2 -1
  273. package/dist/recorder.d.cts.map +1 -1
  274. package/dist/recorder.d.ts +2 -1
  275. package/dist/recorder.d.ts.map +1 -1
  276. package/dist/recorder.js +116 -8
  277. package/dist/recorder.js.map +1 -1
  278. package/dist/responses.cjs +701 -166
  279. package/dist/responses.cjs.map +1 -1
  280. package/dist/responses.d.cts +5 -13
  281. package/dist/responses.d.cts.map +1 -1
  282. package/dist/responses.d.ts +5 -13
  283. package/dist/responses.d.ts.map +1 -1
  284. package/dist/responses.js +699 -169
  285. package/dist/responses.js.map +1 -1
  286. package/dist/route-registry.cjs +951 -0
  287. package/dist/route-registry.cjs.map +1 -0
  288. package/dist/route-registry.d.cts +33 -0
  289. package/dist/route-registry.d.cts.map +1 -0
  290. package/dist/route-registry.d.ts +33 -0
  291. package/dist/route-registry.d.ts.map +1 -0
  292. package/dist/route-registry.js +866 -0
  293. package/dist/route-registry.js.map +1 -0
  294. package/dist/router.cjs +24 -2
  295. package/dist/router.cjs.map +1 -1
  296. package/dist/router.d.cts.map +1 -1
  297. package/dist/router.d.ts.map +1 -1
  298. package/dist/router.js +25 -4
  299. package/dist/router.js.map +1 -1
  300. package/dist/server.cjs +1159 -264
  301. package/dist/server.cjs.map +1 -1
  302. package/dist/server.d.cts +4 -1
  303. package/dist/server.d.cts.map +1 -1
  304. package/dist/server.d.ts +4 -1
  305. package/dist/server.d.ts.map +1 -1
  306. package/dist/server.js +1067 -172
  307. package/dist/server.js.map +1 -1
  308. package/dist/speech.cjs +4 -2
  309. package/dist/speech.cjs.map +1 -1
  310. package/dist/speech.js +4 -2
  311. package/dist/speech.js.map +1 -1
  312. package/dist/stream-collapse.cjs +236 -34
  313. package/dist/stream-collapse.cjs.map +1 -1
  314. package/dist/stream-collapse.d.cts +39 -4
  315. package/dist/stream-collapse.d.cts.map +1 -1
  316. package/dist/stream-collapse.d.ts +39 -4
  317. package/dist/stream-collapse.d.ts.map +1 -1
  318. package/dist/stream-collapse.js +235 -35
  319. package/dist/stream-collapse.js.map +1 -1
  320. package/dist/suite.cjs +1 -1
  321. package/dist/suite.js +1 -1
  322. package/dist/transcription.cjs +2 -2
  323. package/dist/transcription.cjs.map +1 -1
  324. package/dist/transcription.d.cts.map +1 -1
  325. package/dist/transcription.d.ts.map +1 -1
  326. package/dist/transcription.js +2 -2
  327. package/dist/transcription.js.map +1 -1
  328. package/dist/types.cjs +18 -0
  329. package/dist/types.cjs.map +1 -0
  330. package/dist/types.d.cts +516 -5
  331. package/dist/types.d.cts.map +1 -1
  332. package/dist/types.d.ts +516 -5
  333. package/dist/types.d.ts.map +1 -1
  334. package/dist/types.js +17 -0
  335. package/dist/types.js.map +1 -0
  336. package/dist/validate-cli.cjs +123 -33
  337. package/dist/validate-cli.cjs.map +1 -1
  338. package/dist/validate-cli.js +125 -35
  339. package/dist/validate-cli.js.map +1 -1
  340. package/dist/vector-stores.cjs +1180 -0
  341. package/dist/vector-stores.cjs.map +1 -0
  342. package/dist/vector-stores.d.cts +106 -0
  343. package/dist/vector-stores.d.cts.map +1 -0
  344. package/dist/vector-stores.d.ts +106 -0
  345. package/dist/vector-stores.d.ts.map +1 -0
  346. package/dist/vector-stores.js +1164 -0
  347. package/dist/vector-stores.js.map +1 -0
  348. package/dist/vector-types.d.cts.map +1 -1
  349. package/dist/version.cjs +45 -0
  350. package/dist/version.cjs.map +1 -0
  351. package/dist/version.js +44 -0
  352. package/dist/version.js.map +1 -0
  353. package/dist/video.cjs +19 -0
  354. package/dist/video.cjs.map +1 -1
  355. package/dist/video.d.cts.map +1 -1
  356. package/dist/video.d.ts.map +1 -1
  357. package/dist/video.js +19 -0
  358. package/dist/video.js.map +1 -1
  359. package/dist/vitest.cjs +77 -16
  360. package/dist/vitest.cjs.map +1 -1
  361. package/dist/vitest.d.cts +38 -5
  362. package/dist/vitest.d.cts.map +1 -1
  363. package/dist/vitest.d.ts +38 -5
  364. package/dist/vitest.d.ts.map +1 -1
  365. package/dist/vitest.js +78 -17
  366. package/dist/vitest.js.map +1 -1
  367. package/dist/watcher.cjs +6 -2
  368. package/dist/watcher.cjs.map +1 -1
  369. package/dist/watcher.js +6 -2
  370. package/dist/watcher.js.map +1 -1
  371. package/dist/ws-gemini-live.cjs +210 -101
  372. package/dist/ws-gemini-live.cjs.map +1 -1
  373. package/dist/ws-gemini-live.d.cts +9 -3
  374. package/dist/ws-gemini-live.d.cts.map +1 -1
  375. package/dist/ws-gemini-live.d.ts +9 -3
  376. package/dist/ws-gemini-live.d.ts.map +1 -1
  377. package/dist/ws-gemini-live.js +211 -102
  378. package/dist/ws-gemini-live.js.map +1 -1
  379. package/dist/ws-realtime.cjs +175 -62
  380. package/dist/ws-realtime.cjs.map +1 -1
  381. package/dist/ws-realtime.d.cts +8 -3
  382. package/dist/ws-realtime.d.cts.map +1 -1
  383. package/dist/ws-realtime.d.ts +8 -3
  384. package/dist/ws-realtime.d.ts.map +1 -1
  385. package/dist/ws-realtime.js +176 -63
  386. package/dist/ws-realtime.js.map +1 -1
  387. package/dist/ws-responses.cjs +121 -16
  388. package/dist/ws-responses.cjs.map +1 -1
  389. package/dist/ws-responses.d.cts +8 -12
  390. package/dist/ws-responses.d.cts.map +1 -1
  391. package/dist/ws-responses.d.ts +8 -12
  392. package/dist/ws-responses.d.ts.map +1 -1
  393. package/dist/ws-responses.js +123 -18
  394. package/dist/ws-responses.js.map +1 -1
  395. package/package.json +13 -2
  396. package/skills/write-fixtures/SKILL.md +179 -21
package/dist/llmock.js CHANGED
@@ -1,31 +1,77 @@
1
- import { isLiveResponse } from "./helpers.js";
1
+ import { DEFAULT_TEST_ID } from "./constants.js";
2
+ import { build, msg, quote } from "./message-text.js";
3
+ import { isLiveResponse, markServerOwnedFixtures } from "./helpers.js";
2
4
  import { normalizeLiveFixture, normalizeLiveOptions } from "./live-fixture.js";
3
- import { INJECTED_STATUS_RANGE, clearFixtureQueue, entryToFixture, isInjectableStatus, loadFixtureFile, loadFixturesFromDir, normalizeResponse, queueOneShotError, validateFixtures } from "./fixture-loader.js";
5
+ import { getFixtureMisbehaviorPosition, parseMisbehavior, resolveMisbehaviorSeed, setFixtureMisbehaviorPosition, validateFixtureMisbehavior } from "./misbehavior.js";
6
+ import { INJECTED_STATUS_RANGE, MisbehaviorConfigError, clearFixtureQueue, enableHeldFixtureMisbehavior, entryToFixture, isInjectableStatus, markFixtureMisbehaviorEnabled, markFixtureResponsesToolsExtended, normalizeResponse, normalizeResponsesToolsKeys, queueOneShotError, validateFixtures } from "./fixture-loader.js";
4
7
  import { imageResponseToFalJson, videoResponseToFalJson } from "./fal.js";
5
8
  import { voiceDesignToJson } from "./elevenlabs-voice.js";
9
+ import { MCPMock } from "./mcp-mock.js";
10
+ import { ensureFakeMount, isAutoMount, planFileFakes } from "./mcp-fakes-mount.js";
6
11
  import { createServer, createServerWithResolvedAuth, performFullReset } from "./server.js";
12
+ import { loadFixtureFileWithServices, loadFixturesFromDirWithServices } from "./fixture-loader-services.js";
7
13
 
8
14
  //#region src/llmock.ts
9
15
  var LLMock = class LLMock {
10
16
  fixtures = [];
17
+ fixtureAddition = 0;
18
+ fixtureCountOrigins = /* @__PURE__ */ new WeakMap();
19
+ /**
20
+ * Fixtures this LLMock built itself (on() and the other helpers), so the
21
+ * caller never held them: the stored object is their identity.
22
+ */
23
+ ownFixtures = /* @__PURE__ */ new WeakSet();
11
24
  searchFixtures = [];
12
25
  rerankFixtures = [];
13
26
  moderationFixtures = [];
14
27
  mounts = [];
28
+ /** `mcpFakes` blocks loaded before `start()`, handed to the server at start (W2). */
29
+ mcpFakeBuffer = [];
30
+ /** MCPMocks the server or a load auto-mounted (W3, W6), for the L6 check. */
15
31
  serverInstance = null;
16
32
  options;
17
33
  resolvedInboundAuth;
18
34
  constructor(options, resolvedInboundAuth) {
35
+ markServerOwnedFixtures(this.fixtures);
19
36
  this.options = options ?? {};
20
37
  if (this.options.live !== void 0) normalizeLiveOptions(this.options.live);
38
+ if (this.misbehaviorEnabled && this.options.misbehavior !== void 0) this.setMisbehavior(this.options.misbehavior);
21
39
  this.resolvedInboundAuth = resolvedInboundAuth;
22
40
  }
41
+ /** Misbehavior (fixture keys, header, `misbehavior` option) needs `enableMisbehavior: true`. */
42
+ get misbehaviorEnabled() {
43
+ return this.options.enableMisbehavior === true;
44
+ }
23
45
  normalizeFixture(fixture) {
24
- if (isLiveResponse(fixture.response) || fixture.match.endpoint === "openai-live" && typeof fixture.response !== "function") return {
46
+ const misbehaviorEnabled = this.misbehaviorEnabled;
47
+ if (misbehaviorEnabled) enableHeldFixtureMisbehavior(fixture);
48
+ const own = this.ownFixtures.delete(fixture);
49
+ const countIdentity = own ? void 0 : this.fixtureCountOrigins.get(fixture) ?? fixture;
50
+ const previousPosition = getFixtureMisbehaviorPosition(fixture);
51
+ const isNewAddition = previousPosition === void 0 || /^code#\d+$/.test(previousPosition);
52
+ const position = isNewAddition ? `code#${this.fixtureAddition++}` : previousPosition;
53
+ if (isNewAddition && misbehaviorEnabled && !own) fixture = { ...fixture };
54
+ if (misbehaviorEnabled && fixture.misbehavior !== void 0) {
55
+ const parsed = parseMisbehavior(fixture.misbehavior);
56
+ if (parsed.ok) fixture = {
57
+ ...fixture,
58
+ misbehavior: parsed.config
59
+ };
60
+ const issue = parsed.ok ? validateFixtureMisbehavior(fixture) : parsed.issue;
61
+ if (issue) throw new MisbehaviorConfigError({
62
+ rule: issue.rule,
63
+ file: position,
64
+ detail: issue.message
65
+ });
66
+ }
67
+ if (isLiveResponse(fixture.response) || fixture.match.endpoint === "openai-live" && typeof fixture.response !== "function") fixture = {
25
68
  ...fixture,
26
69
  match: { ...fixture.match },
27
70
  response: normalizeLiveFixture(fixture.response, this.options.live)
28
71
  };
72
+ else if (countIdentity !== void 0 && fixture !== countIdentity) this.fixtureCountOrigins.set(fixture, countIdentity);
73
+ setFixtureMisbehaviorPosition(fixture, position);
74
+ if (misbehaviorEnabled && fixture.misbehavior !== void 0) markFixtureMisbehaviorEnabled(fixture);
29
75
  return fixture;
30
76
  }
31
77
  addFixture(fixture) {
@@ -40,18 +86,81 @@ var LLMock = class LLMock {
40
86
  this.fixtures.unshift(this.normalizeFixture(fixture));
41
87
  return this;
42
88
  }
89
+ /** Mark a fixture this LLMock built, for {@link normalizeFixture}. */
90
+ own(fixture) {
91
+ this.ownFixtures.add(fixture);
92
+ return fixture;
93
+ }
43
94
  getFixtures() {
44
95
  return this.fixtures;
45
96
  }
97
+ /**
98
+ * Load a fixture file: its LLM fixtures and its `mcpFakes` blocks (F4).
99
+ * Before `start()` the blocks are buffered and handed to the server at
100
+ * start (W2); after it they go to the MCPMock serving each block's `mount`
101
+ * path, auto-mounted when none does (W6). A block that cannot be honored
102
+ * throws a `FixtureLoadError` and nothing from the file is added.
103
+ */
46
104
  loadFixtureFile(filePath) {
47
- this.fixtures.push(...loadFixtureFile(filePath, void 0, this.options.live));
48
- return this;
105
+ return this.acceptLoaded(loadFixtureFileWithServices(filePath, void 0, this.options.live));
49
106
  }
107
+ /** As {@link loadFixtureFile}, for every fixture file under `dirPath`. */
50
108
  loadFixtureDir(dirPath) {
51
- this.fixtures.push(...loadFixturesFromDir(dirPath, void 0, this.options.live));
109
+ return this.acceptLoaded(loadFixturesFromDirWithServices(dirPath, void 0, this.options.live));
110
+ }
111
+ /**
112
+ * Add a load's fakes (all or nothing), then its LLM fixtures. Before start
113
+ * the fakes are checked as the start-time hand-off will check them, with
114
+ * the blocks already buffered and the mounts added so far, so a file whose
115
+ * fakes would be rejected adds nothing. A mount added after the load can
116
+ * still make `start()` reject.
117
+ */
118
+ acceptLoaded(loaded) {
119
+ if (this.misbehaviorEnabled) loaded.fixtures.forEach(enableHeldFixtureMisbehavior);
120
+ if (this.options.responsesTools === "extended") loaded.fixtures.forEach(markFixtureResponsesToolsExtended);
121
+ if (loaded.mcpFakes.length > 0) if (this.serverInstance) this.addFakesAfterStart(this.serverInstance, loaded.mcpFakes);
122
+ else {
123
+ planFileFakes(this.mounts, [...this.mcpFakeBuffer, ...loaded.mcpFakes], new Set(loaded.mcpFakes));
124
+ this.mcpFakeBuffer.push(...loaded.mcpFakes);
125
+ }
126
+ this.fixtures.push(...loaded.fixtures);
52
127
  return this;
53
128
  }
54
129
  /**
130
+ * W6 for a load after start. Every group of blocks (by `mount` path) is
131
+ * checked before any mount is touched: a path held by a mount that is not
132
+ * an MCPMock is a mount conflict, and each group is first added to a
133
+ * throwaway store. Groups for an existing MCPMock are then added to it (its
134
+ * own add is all or nothing and finds collisions with its loaded ids);
135
+ * groups for a free path are added last, to a new auto-mounted MCPMock,
136
+ * wired as W4. The add warnings (L8) are logged at `warn`.
137
+ */
138
+ addFakesAfterStart(server, sources) {
139
+ const { onExisting, onNew } = planFileFakes(this.mounts, sources);
140
+ const logger = server.defaults.logger;
141
+ for (const { handler, group } of onExisting) {
142
+ const result = handler.addMcpFakes?.(group, { kind: "file" });
143
+ for (const warning of result?.warnings ?? []) logger.warn(warning.message);
144
+ }
145
+ const registry = server.defaults.registry;
146
+ for (const { path, group } of onNew) {
147
+ const target = ensureFakeMount(this.mounts, path, {
148
+ journal: server.journal,
149
+ ...registry ? { registry } : {},
150
+ logger,
151
+ replaySpeed: server.defaults.replaySpeed
152
+ }, logger);
153
+ if ("conflict" in target) continue;
154
+ const result = target.handler.addMcpFakes?.(group, { kind: "file" });
155
+ for (const warning of result?.warnings ?? []) logger.warn(warning.message);
156
+ }
157
+ }
158
+ /** R4, R5: unload the fakes of every mount and the pre-start buffer. */
159
+ unloadMcpFakes() {
160
+ this.mcpFakeBuffer.length = 0;
161
+ for (const { handler } of this.mounts) handler.clearMcpFakes?.();
162
+ }
163
+ /**
55
164
  * Add fixtures from a JSON string or pre-parsed array of fixture entries.
56
165
  * Validates all fixtures and throws if any have severity "error".
57
166
  */
@@ -63,7 +172,18 @@ var LLMock = class LLMock {
63
172
  throw new Error(`addFixturesFromJSON: invalid JSON — ${err instanceof Error ? err.message : String(err)}`);
64
173
  }
65
174
  else entries = input;
66
- const converted = entries.map((e) => entryToFixture(e, void 0, this.options.live));
175
+ if (!Array.isArray(entries)) throw new TypeError("addFixturesFromJSON: expected an array of fixture entries; use loadFixtureFile for a {fixtures:[...]} file");
176
+ const converted = entries.map((entry) => {
177
+ const position = `code#${this.fixtureAddition++}`;
178
+ const fixture = entryToFixture(entry, void 0, this.options.live, {
179
+ file: position,
180
+ index: 0
181
+ });
182
+ setFixtureMisbehaviorPosition(fixture, position);
183
+ if (this.misbehaviorEnabled) enableHeldFixtureMisbehavior(fixture);
184
+ if (this.options.responsesTools === "extended") markFixtureResponsesToolsExtended(fixture);
185
+ return fixture;
186
+ });
67
187
  const errors = validateFixtures(converted, this.options.live).filter((i) => i.severity === "error");
68
188
  if (errors.length > 0) throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);
69
189
  this.fixtures.push(...converted);
@@ -71,14 +191,21 @@ var LLMock = class LLMock {
71
191
  }
72
192
  clearFixtures() {
73
193
  clearFixtureQueue(this.fixtures);
194
+ this.serverInstance?.journal.clearMisbehaviorCounters();
195
+ this.unloadMcpFakes();
74
196
  return this;
75
197
  }
76
198
  on(match, response, opts) {
77
- return this.addFixture({
199
+ let normalized = response;
200
+ if (typeof response !== "function") {
201
+ normalized = normalizeResponse(response, this.options.live);
202
+ if (this.options.responsesTools === "extended" && !isLiveResponse(normalized)) normalizeResponsesToolsKeys(normalized);
203
+ }
204
+ return this.addFixture(this.own({
78
205
  match,
79
- response: typeof response === "function" ? response : normalizeResponse(response, this.options.live),
206
+ response: normalized,
80
207
  ...opts
81
- });
208
+ }));
82
209
  }
83
210
  onLive(match, transcript, opts) {
84
211
  return this.on({
@@ -112,99 +239,99 @@ var LLMock = class LLMock {
112
239
  }, response, opts);
113
240
  }
114
241
  onImage(prompt, response) {
115
- return this.addFixture({
242
+ return this.addFixture(this.own({
116
243
  match: {
117
244
  userMessage: prompt,
118
245
  endpoint: "image"
119
246
  },
120
247
  response
121
- });
248
+ }));
122
249
  }
123
250
  onSpeech(input, response) {
124
- return this.addFixture({
251
+ return this.addFixture(this.own({
125
252
  match: {
126
253
  userMessage: input,
127
254
  endpoint: "speech"
128
255
  },
129
256
  response
130
- });
257
+ }));
131
258
  }
132
259
  onTranscription(response) {
133
- return this.addFixture({
260
+ return this.addFixture(this.own({
134
261
  match: { endpoint: "transcription" },
135
262
  response
136
- });
263
+ }));
137
264
  }
138
265
  onTranslation(response) {
139
- return this.addFixture({
266
+ return this.addFixture(this.own({
140
267
  match: { endpoint: "translation" },
141
268
  response
142
- });
269
+ }));
143
270
  }
144
271
  onVideo(prompt, response) {
145
- return this.addFixture({
272
+ return this.addFixture(this.own({
146
273
  match: {
147
274
  userMessage: prompt,
148
275
  endpoint: "video"
149
276
  },
150
277
  response
151
- });
278
+ }));
152
279
  }
153
280
  onAudio(input, response) {
154
- return this.addFixture({
281
+ return this.addFixture(this.own({
155
282
  match: { userMessage: input },
156
283
  response
157
- });
284
+ }));
158
285
  }
159
286
  onSoundEffect(text, response) {
160
- return this.addFixture({
287
+ return this.addFixture(this.own({
161
288
  match: {
162
289
  userMessage: text,
163
290
  endpoint: "audio-gen"
164
291
  },
165
292
  response
166
- });
293
+ }));
167
294
  }
168
295
  onMusic(prompt, response) {
169
- return this.addFixture({
296
+ return this.addFixture(this.own({
170
297
  match: {
171
298
  userMessage: prompt,
172
299
  endpoint: "audio-gen"
173
300
  },
174
301
  response
175
- });
302
+ }));
176
303
  }
177
304
  onElevenLabsTTS(text, response) {
178
- return this.addFixture({
305
+ return this.addFixture(this.own({
179
306
  match: {
180
307
  userMessage: text,
181
308
  endpoint: "elevenlabs-tts"
182
309
  },
183
310
  response
184
- });
311
+ }));
185
312
  }
186
313
  onElevenLabsVoiceDesign(description, response) {
187
- return this.addFixture({
314
+ return this.addFixture(this.own({
188
315
  match: {
189
316
  userMessage: description,
190
317
  endpoint: "elevenlabs-voice-design"
191
318
  },
192
319
  response: voiceDesignToJson(response)
193
- });
320
+ }));
194
321
  }
195
322
  onFalAudio(prompt, response, model) {
196
- return this.addFixture({
323
+ return this.addFixture(this.own({
197
324
  match: {
198
325
  userMessage: prompt,
199
326
  endpoint: "fal-audio",
200
327
  ...model ? { model } : {}
201
328
  },
202
329
  response
203
- });
330
+ }));
204
331
  }
205
332
  onFalQueue(modelOrPrompt, response, opts) {
206
333
  const { billableUnits, ...fixtureOpts } = opts ?? {};
207
- return this.addFixture({
334
+ return this.addFixture(this.own({
208
335
  match: {
209
336
  model: modelOrPrompt,
210
337
  endpoint: "fal"
@@ -214,7 +341,7 @@ var LLMock = class LLMock {
214
341
  ...billableUnits != null ? { billableUnits } : {}
215
342
  },
216
343
  ...fixtureOpts
217
- });
344
+ }));
218
345
  }
219
346
  onFalRun(modelOrPrompt, response, opts) {
220
347
  return this.onFalQueue(modelOrPrompt, response, opts);
@@ -269,6 +396,7 @@ var LLMock = class LLMock {
269
396
  return this;
270
397
  }
271
398
  mount(path, handler) {
399
+ const shadowedBy = this.serverInstance ? this.mounts.find((m) => isAutoMount(m.handler) && (path === m.path || path === m.path + "/")) : void 0;
272
400
  this.mounts.push({
273
401
  path,
274
402
  handler
@@ -278,6 +406,10 @@ var LLMock = class LLMock {
278
406
  if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);
279
407
  const registry = this.serverInstance.defaults.registry;
280
408
  if (registry && handler.setRegistry) handler.setRegistry(registry);
409
+ const logger = this.serverInstance.defaults.logger;
410
+ if (handler.setLogger) handler.setLogger(logger);
411
+ if (handler instanceof MCPMock) handler.setReplaySpeed(this.serverInstance.defaults.replaySpeed);
412
+ if (shadowedBy) logger.warn(build(msg`MCP fakes: the mount at ${quote(path)} is shadowed by the MCP mock auto-mounted at ${quote(shadowedBy.path)}; its requests reach the auto-mount`));
281
413
  }
282
414
  return this;
283
415
  }
@@ -294,8 +426,13 @@ var LLMock = class LLMock {
294
426
  clearRequests() {
295
427
  this.journal.clearEntries();
296
428
  }
429
+ /**
430
+ * Reset fixture match counts, and the MCP fakes consumption state of every
431
+ * mount (R6), for `testId` or for all test ids. Fakes stay loaded.
432
+ */
297
433
  resetMatchCounts(testId) {
298
434
  if (this.serverInstance) this.serverInstance.journal.clearMatchCounts(testId);
435
+ for (const { handler } of this.mounts) handler.resetScenarioState?.(testId);
299
436
  return this;
300
437
  }
301
438
  /**
@@ -320,6 +457,32 @@ var LLMock = class LLMock {
320
457
  if (this.serverInstance) this.serverInstance.defaults.chaos = void 0;
321
458
  return this;
322
459
  }
460
+ /** Replace construction/runtime baselines without changing named test overrides. */
461
+ setMisbehavior(config) {
462
+ if (!this.misbehaviorEnabled) throw new TypeError("setMisbehavior: misbehavior is not enabled; construct with enableMisbehavior: true");
463
+ const parsed = parseMisbehavior(config);
464
+ if (!parsed.ok) throw new TypeError(`${parsed.issue.rule}: ${parsed.issue.message}`);
465
+ this.options.misbehavior = parsed.config;
466
+ const defaults = this.serverInstance?.defaults;
467
+ if (defaults?.misbehavior) {
468
+ defaults.misbehavior.baseline = parsed.config.seed === "random" ? {
469
+ ...parsed.config,
470
+ seed: resolveMisbehaviorSeed(parsed.config.seed, defaults.logger)
471
+ } : parsed.config;
472
+ if (defaults.misbehavior.byTestId.has(DEFAULT_TEST_ID)) defaults.misbehavior.byTestId.set(DEFAULT_TEST_ID, defaults.misbehavior.baseline);
473
+ }
474
+ return this;
475
+ }
476
+ /** Clear the baseline and all runtime overrides, before or after start. */
477
+ clearMisbehavior() {
478
+ delete this.options.misbehavior;
479
+ const scope = this.serverInstance?.defaults.misbehavior;
480
+ if (scope) {
481
+ scope.baseline = void 0;
482
+ scope.byTestId.clear();
483
+ }
484
+ return this;
485
+ }
323
486
  enableRecording(config) {
324
487
  this.options.record = config;
325
488
  return this;
@@ -356,20 +519,22 @@ var LLMock = class LLMock {
356
519
  this.searchFixtures.length = 0;
357
520
  this.rerankFixtures.length = 0;
358
521
  this.moderationFixtures.length = 0;
522
+ this.unloadMcpFakes();
359
523
  performFullReset(this.fixtures, this.serverInstance);
360
524
  return this;
361
525
  }
362
526
  async start() {
363
527
  if (this.serverInstance) throw new Error("Server already started");
364
- this.serverInstance = await (this.resolvedInboundAuth ? createServerWithResolvedAuth(this.fixtures, this.options, this.resolvedInboundAuth, this.mounts, {
528
+ const serviceFixtures = {
365
529
  search: this.searchFixtures,
366
530
  rerank: this.rerankFixtures,
367
- moderation: this.moderationFixtures
368
- }) : createServer(this.fixtures, this.options, this.mounts, {
369
- search: this.searchFixtures,
370
- rerank: this.rerankFixtures,
371
- moderation: this.moderationFixtures
372
- }));
531
+ moderation: this.moderationFixtures,
532
+ mcpFakes: [...this.mcpFakeBuffer]
533
+ };
534
+ this.serverInstance = await (this.resolvedInboundAuth ? createServerWithResolvedAuth(this.fixtures, this.options, this.resolvedInboundAuth, this.mounts, serviceFixtures) : createServer(this.fixtures, this.options, this.mounts, serviceFixtures));
535
+ const countIdentity = (fixture) => this.fixtureCountOrigins.get(fixture) ?? fixture;
536
+ this.serverInstance.journal.configureFixtureCountIdentity(countIdentity);
537
+ this.mcpFakeBuffer.length = 0;
373
538
  return this.serverInstance.url;
374
539
  }
375
540
  closeLiveSessions(testId) {
@@ -1 +1 @@
1
- {"version":3,"file":"llmock.js","names":[],"sources":["../src/llmock.ts"],"sourcesContent":["import type { LiveTranscript } from \"./live-types.js\";\nimport { normalizeLiveFixture, normalizeLiveOptions } from \"./live-fixture.js\";\nimport { isLiveResponse } from \"./helpers.js\";\nimport type {\n AudioResponse,\n ChaosConfig,\n EmbeddingFixtureOpts,\n FalQueueOpts,\n Fixture,\n FixtureFileEntry,\n FixtureFileResponse,\n FixtureMatch,\n FixtureOpts,\n ImageResponse,\n MockServerOptions,\n Mountable,\n RecordConfig,\n ResponseFactory,\n TranscriptionResponse,\n VideoResponse,\n VoiceDesignResponse,\n} from \"./types.js\";\nimport {\n createServer,\n createServerWithResolvedAuth,\n performFullReset,\n type ServerInstance,\n} from \"./server.js\";\nimport type { ResolvedInboundAuth } from \"./api-key-auth.js\";\nimport {\n isInjectableStatus,\n INJECTED_STATUS_RANGE,\n queueOneShotError,\n clearFixtureQueue,\n loadFixtureFile,\n loadFixturesFromDir,\n entryToFixture,\n normalizeResponse,\n validateFixtures,\n} from \"./fixture-loader.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\nimport { imageResponseToFalJson, videoResponseToFalJson } from \"./fal.js\";\nimport { voiceDesignToJson } from \"./elevenlabs-voice.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n private readonly resolvedInboundAuth?: ResolvedInboundAuth;\n\n constructor(options?: MockServerOptions, resolvedInboundAuth?: ResolvedInboundAuth) {\n this.options = options ?? {};\n if (this.options.live !== undefined) normalizeLiveOptions(this.options.live);\n this.resolvedInboundAuth = resolvedInboundAuth;\n }\n\n // ---- Fixture management ----\n\n private normalizeFixture(fixture: Fixture): Fixture {\n if (\n isLiveResponse(fixture.response) ||\n (fixture.match.endpoint === \"openai-live\" && typeof fixture.response !== \"function\")\n ) {\n return {\n ...fixture,\n match: { ...fixture.match },\n response: normalizeLiveFixture(fixture.response, this.options.live),\n };\n }\n return fixture;\n }\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(this.normalizeFixture(fixture));\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures.map((fixture) => this.normalizeFixture(fixture)));\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(this.normalizeFixture(fixture));\n return this;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n loadFixtureFile(filePath: string): this {\n this.fixtures.push(...loadFixtureFile(filePath, undefined, this.options.live));\n return this;\n }\n\n loadFixtureDir(dirPath: string): this {\n this.fixtures.push(...loadFixturesFromDir(dirPath, undefined, this.options.live));\n return this;\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n let entries: FixtureFileEntry[];\n if (typeof input === \"string\") {\n try {\n entries = JSON.parse(input);\n } catch (err) {\n throw new Error(\n `addFixturesFromJSON: invalid JSON — ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n } else {\n entries = input;\n }\n const converted = entries.map((e) => entryToFixture(e, undefined, this.options.live));\n const issues = validateFixtures(converted, this.options.live);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Clears in place to preserve array reference identity — the running\n // server reads this same array on every request — and invalidates any\n // one-shot claim parked in flight so it cannot re-arm into the cleared queue.\n clearFixtures(): this {\n clearFixtureQueue(this.fixtures);\n return this;\n }\n\n // ---- Convenience ----\n\n on(\n match: FixtureMatch,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.addFixture({\n match,\n response:\n typeof response === \"function\" ? response : normalizeResponse(response, this.options.live),\n ...opts,\n });\n }\n\n onLive(\n match: Omit<FixtureMatch, \"endpoint\">,\n transcript: LiveTranscript,\n opts?: FixtureOpts,\n ): this {\n return this.on({ ...match, endpoint: \"openai-live\" }, { live: transcript }, opts);\n }\n\n onMessage(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(\n name: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(\n id: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n onTurn(\n turn: number,\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern, turnIndex: turn }, response, opts);\n }\n\n onImage(prompt: string | RegExp, response: ImageResponse): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"image\" },\n response,\n });\n }\n\n onSpeech(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: input, endpoint: \"speech\" },\n response,\n });\n }\n\n onTranscription(response: TranscriptionResponse): this {\n return this.addFixture({\n match: { endpoint: \"transcription\" },\n response,\n });\n }\n\n onTranslation(response: TranscriptionResponse): this {\n return this.addFixture({\n match: { endpoint: \"translation\" },\n response,\n });\n }\n\n onVideo(prompt: string | RegExp, response: VideoResponse): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"video\" },\n response,\n });\n }\n\n onAudio(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture({ match: { userMessage: input }, response });\n }\n\n onSoundEffect(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: text, endpoint: \"audio-gen\" },\n response,\n });\n }\n\n onMusic(prompt: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"audio-gen\" },\n response,\n });\n }\n\n onElevenLabsTTS(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture({\n match: { userMessage: text, endpoint: \"elevenlabs-tts\" },\n response,\n });\n }\n\n onElevenLabsVoiceDesign(description: string | RegExp, response: VoiceDesignResponse): this {\n return this.addFixture({\n match: { userMessage: description, endpoint: \"elevenlabs-voice-design\" },\n response: voiceDesignToJson(response),\n });\n }\n\n onFalAudio(prompt: string | RegExp, response: AudioResponse, model?: string): this {\n return this.addFixture({\n match: { userMessage: prompt, endpoint: \"fal-audio\", ...(model ? { model } : {}) },\n response,\n });\n }\n\n // fal.queue.* is the dominant client API; onFalRun is a sync alias.\n //\n // `opts.billableUnits` rides through to the completed `queue-result`\n // response's `x-fal-billable-units` header (emitted alongside\n // `x-fal-request-id`), letting consumers like `@tanstack/ai-fal` surface a\n // billed-units value on replay. Omit it to preserve the header-less default.\n onFalQueue(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n const { billableUnits, ...fixtureOpts } = opts ?? {};\n return this.addFixture({\n match: { model: modelOrPrompt, endpoint: \"fal\" },\n response: { json: response, ...(billableUnits != null ? { billableUnits } : {}) },\n ...fixtureOpts,\n });\n }\n\n onFalRun(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, response, opts);\n }\n\n /**\n * Register a fal.ai image fixture. Wraps an `ImageResponse` (the shape used\n * by `onImage` and OpenAI/Azure image fixtures) into fal's image envelope\n * before storing it as a `RawJSONResponse`. Defaults `width`/`height` to\n * 1024 when the fixture's `ImageItem` doesn't carry them.\n */\n onFalImage(modelOrPrompt: string | RegExp, response: ImageResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, imageResponseToFalJson(response), opts);\n }\n\n /**\n * Register a fal.ai video fixture. Wraps a `VideoResponse` into fal's video\n * envelope (`{ video: { url, content_type, file_name, file_size }, seed }`)\n * before storing it as a `RawJSONResponse`.\n */\n onFalVideo(modelOrPrompt: string | RegExp, response: VideoResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, videoResponseToFalJson(response), opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * inserted at the front of the fixture list; see `queueOneShotError` for\n * the endpoint gate and the served-not-evaluated consumption rule.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n // Same gate as `POST /__aimock/error` and fixture validation — this is the\n // form the docs use, and an unchecked status reaches `res.writeHead` on\n // the next matched request: 99/1000 throw there (the injected error is\n // lost and the caller sees a generic 500), and 1xx hangs the request until\n // the client times out. Throwing HERE names the offending call instead.\n if (!isInjectableStatus(status)) {\n throw new RangeError(\n `nextRequestError: invalid status ${String(status)} — must be ${INJECTED_STATUS_RANGE}`,\n );\n }\n queueOneShotError(this.fixtures, status, errorBody);\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, and baseUrl immediately\n // so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n /**\n * Clear the request journal. Fixture match-counts (sequencing state) are\n * left intact — use `resetMatchCounts()` for those.\n */\n clearRequests(): void {\n this.journal.clearEntries();\n }\n\n resetMatchCounts(testId?: string): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts(testId);\n }\n return this;\n }\n\n // ---- Chaos ----\n\n /**\n * Set the server-wide chaos baseline. Writes through to a RUNNING server as\n * well as the construction options: an untagged `POST /__aimock/chaos`\n * installs a baseline override that shadows `options.chaos`, and without this\n * the call would silently do nothing until the next `reset()`. Per-testId\n * overrides still win over the baseline.\n */\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n if (this.serverInstance) this.serverInstance.defaults.chaos = config;\n return this;\n }\n\n /**\n * Turn chaos off everywhere: the construction config, the runtime baseline,\n * and every per-testId override (assigning `undefined` is the full-clear\n * signal the `defaults.chaos` setter defines).\n */\n clearChaos(): this {\n delete this.options.chaos;\n if (this.serverInstance) this.serverInstance.defaults.chaos = undefined;\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n /**\n * Full reset — the in-process equivalent of `POST /__aimock/reset`. Shares\n * one implementation with the control-API route so the two cannot drift.\n *\n * The one deliberate difference: search / rerank / moderation fixtures are\n * also cleared here. Those are registered through this class only — the\n * control API has no route that creates them, so the HTTP reset can neither\n * reach nor observe them.\n *\n * NOT ALL OF THIS IS PER-INSTANCE. `performFullReset` clears module-global\n * state as well: the Gemini interaction and event-id counters\n * (`resetInteractionCounter` / `resetEventIdCounter` in\n * `./gemini-interactions.js`), the fal.ai job/queue maps (`falJobs`,\n * `falQueueStates`), the fine-tuning job store (`clearFineTuningStore`),\n * and the ElevenLabs Voice Design store (`clearElevenLabsVoices`). With two\n * `LLMock` instances live in one process,\n * `a.reset()` rewinds the Gemini id sequence that `b` is mid-way through —\n * `b` then re-emits `aimock-int-0` / `evt_1`, ids it has already handed\n * out — and drops `b`'s in-flight fal jobs. Give each instance its own\n * process (or its own vitest worker) if that matters.\n *\n * The global stores are cleared even before `start()`, when there is no\n * server instance to reset.\n */\n reset(): this {\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n performFullReset(this.fixtures, this.serverInstance);\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n this.serverInstance = await (this.resolvedInboundAuth\n ? createServerWithResolvedAuth(\n this.fixtures,\n this.options,\n this.resolvedInboundAuth,\n this.mounts,\n {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n },\n )\n : createServer(this.fixtures, this.options, this.mounts, {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n }));\n return this.serverInstance.url;\n }\n\n closeLiveSessions(testId?: string): this {\n this.serverInstance?.closeLiveSessions(testId);\n return this;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n\n/** @internal Configuration startup preserves a policy resolved from the selected source. */\nexport function createLLMockWithResolvedAuth(\n options: MockServerOptions,\n resolvedAuth: ResolvedInboundAuth,\n): LLMock {\n return new LLMock(options, resolvedAuth);\n}\n"],"mappings":";;;;;;;;AA+CA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;CAChE,AAAQ,iBAAwC;CAChD,AAAQ;CACR,AAAiB;CAEjB,YAAY,SAA6B,qBAA2C;AAClF,OAAK,UAAU,WAAW,EAAE;AAC5B,MAAI,KAAK,QAAQ,SAAS,OAAW,sBAAqB,KAAK,QAAQ,KAAK;AAC5E,OAAK,sBAAsB;;CAK7B,AAAQ,iBAAiB,SAA2B;AAClD,MACE,eAAe,QAAQ,SAAS,IAC/B,QAAQ,MAAM,aAAa,iBAAiB,OAAO,QAAQ,aAAa,WAEzE,QAAO;GACL,GAAG;GACH,OAAO,EAAE,GAAG,QAAQ,OAAO;GAC3B,UAAU,qBAAqB,QAAQ,UAAU,KAAK,QAAQ,KAAK;GACpE;AAEH,SAAO;;CAGT,WAAW,SAAwB;AACjC,OAAK,SAAS,KAAK,KAAK,iBAAiB,QAAQ,CAAC;AAClD,SAAO;;CAGT,YAAY,UAA2B;AACrC,OAAK,SAAS,KAAK,GAAG,SAAS,KAAK,YAAY,KAAK,iBAAiB,QAAQ,CAAC,CAAC;AAChF,SAAO;;CAGT,eAAe,SAAwB;AACrC,OAAK,SAAS,QAAQ,KAAK,iBAAiB,QAAQ,CAAC;AACrD,SAAO;;CAGT,cAAk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SAA8C;EAChE,MAAM,WAAW,IAAI,OAAO,QAAQ;AACpC,QAAM,SAAS,OAAO;AACtB,SAAO;;;;AAKX,SAAgB,6BACd,SACA,cACQ;AACR,QAAO,IAAI,OAAO,SAAS,aAAa"}
1
+ {"version":3,"file":"llmock.js","names":[],"sources":["../src/llmock.ts"],"sourcesContent":["import type { LiveTranscript } from \"./live-types.js\";\nimport { normalizeLiveFixture, normalizeLiveOptions } from \"./live-fixture.js\";\nimport { isLiveResponse, markServerOwnedFixtures } from \"./helpers.js\";\nimport type {\n AudioResponse,\n ChaosConfig,\n EmbeddingFixtureOpts,\n FalQueueOpts,\n Fixture,\n FixtureFileEntry,\n FixtureFileResponse,\n FixtureMatch,\n FixtureOpts,\n FixtureResponse,\n ImageResponse,\n McpFakeSource,\n MockServerOptions,\n MisbehaviorConfig,\n MisbehaviorFaultId,\n Mountable,\n RecordConfig,\n ResponseFactory,\n TranscriptionResponse,\n VideoResponse,\n VoiceDesignResponse,\n} from \"./types.js\";\nimport {\n createServer,\n createServerWithResolvedAuth,\n performFullReset,\n type ServerInstance,\n} from \"./server.js\";\nimport type { ResolvedInboundAuth } from \"./api-key-auth.js\";\nimport {\n isInjectableStatus,\n INJECTED_STATUS_RANGE,\n queueOneShotError,\n clearFixtureQueue,\n entryToFixture,\n normalizeResponse,\n normalizeResponsesToolsKeys,\n validateFixtures,\n enableHeldFixtureMisbehavior,\n markFixtureResponsesToolsExtended,\n markFixtureMisbehaviorEnabled,\n MisbehaviorConfigError,\n} from \"./fixture-loader.js\";\nimport {\n loadFixtureFileWithServices,\n loadFixturesFromDirWithServices,\n type FixturesWithServices,\n} from \"./fixture-loader-services.js\";\nimport { ensureFakeMount, isAutoMount, planFileFakes } from \"./mcp-fakes-mount.js\";\nimport { MCPMock } from \"./mcp-mock.js\";\nimport { build, msg, quote } from \"./message-text.js\";\nimport { DEFAULT_TEST_ID } from \"./constants.js\";\nimport { Journal } from \"./journal.js\";\nimport type { SearchFixture, SearchResult } from \"./search.js\";\nimport type { RerankFixture, RerankResult } from \"./rerank.js\";\nimport type { ModerationFixture, ModerationResult } from \"./moderation.js\";\nimport { imageResponseToFalJson, videoResponseToFalJson } from \"./fal.js\";\nimport { voiceDesignToJson } from \"./elevenlabs-voice.js\";\n\nimport {\n getFixtureMisbehaviorPosition,\n parseMisbehavior,\n resolveMisbehaviorSeed,\n setFixtureMisbehaviorPosition,\n validateFixtureMisbehavior,\n} from \"./misbehavior.js\";\n\nexport class LLMock {\n private fixtures: Fixture[] = [];\n private fixtureAddition = 0;\n private readonly fixtureCountOrigins = new WeakMap<Fixture, Fixture>();\n /**\n * Fixtures this LLMock built itself (on() and the other helpers), so the\n * caller never held them: the stored object is their identity.\n */\n private readonly ownFixtures = new WeakSet<Fixture>();\n private searchFixtures: SearchFixture[] = [];\n private rerankFixtures: RerankFixture[] = [];\n private moderationFixtures: ModerationFixture[] = [];\n private mounts: Array<{ path: string; handler: Mountable }> = [];\n /** `mcpFakes` blocks loaded before `start()`, handed to the server at start (W2). */\n private mcpFakeBuffer: McpFakeSource[] = [];\n /** MCPMocks the server or a load auto-mounted (W3, W6), for the L6 check. */\n private serverInstance: ServerInstance | null = null;\n private options: MockServerOptions;\n private readonly resolvedInboundAuth?: ResolvedInboundAuth;\n\n constructor(options?: MockServerOptions, resolvedInboundAuth?: ResolvedInboundAuth) {\n // Only this LLMock's server reads its array, so fixtures it makes may be marked in place.\n markServerOwnedFixtures(this.fixtures);\n this.options = options ?? {};\n if (this.options.live !== undefined) normalizeLiveOptions(this.options.live);\n // The `misbehavior` option is read only with `enableMisbehavior: true`;\n // otherwise it is unused data, as in 1.44.0.\n if (this.misbehaviorEnabled && this.options.misbehavior !== undefined) {\n this.setMisbehavior(this.options.misbehavior);\n }\n this.resolvedInboundAuth = resolvedInboundAuth;\n }\n\n /** Misbehavior (fixture keys, header, `misbehavior` option) needs `enableMisbehavior: true`. */\n private get misbehaviorEnabled(): boolean {\n return this.options.enableMisbehavior === true;\n }\n\n // ---- Fixture management ----\n\n private normalizeFixture(fixture: Fixture): Fixture {\n const misbehaviorEnabled = this.misbehaviorEnabled;\n // A fixture loaded from a file holds its `misbehavior` key until enabled.\n if (misbehaviorEnabled) enableHeldFixtureMisbehavior(fixture);\n // A fixture this LLMock built (on() and the helpers) is new to it, so it\n // needs no per-addition copy, and the object stored is its identity.\n const own = this.ownFixtures.delete(fixture);\n const countIdentity = own ? undefined : (this.fixtureCountOrigins.get(fixture) ?? fixture);\n const previousPosition = getFixtureMisbehaviorPosition(fixture);\n const isNewAddition = previousPosition === undefined || /^code#\\d+$/.test(previousPosition);\n const position = isNewAddition ? `code#${this.fixtureAddition++}` : previousPosition;\n // With misbehavior enabled, re-adding a code fixture creates a new fault\n // source without changing the old entry, so each addition is its own copy.\n // The journal counts and records every copy under the caller's object\n // (fixtureCountOrigins), so the identity APIs read as they do without\n // misbehavior: an object added twice is one caller fixture, as in 1.44.0.\n // Without misbehavior the position is never read, and the caller's object\n // is stored as in 1.44.0.\n if (isNewAddition && misbehaviorEnabled && !own) fixture = { ...fixture };\n if (misbehaviorEnabled && fixture.misbehavior !== undefined) {\n const parsed = parseMisbehavior(fixture.misbehavior);\n if (parsed.ok) fixture = { ...fixture, misbehavior: parsed.config };\n const issue = parsed.ok ? validateFixtureMisbehavior(fixture) : parsed.issue;\n if (issue) {\n throw new MisbehaviorConfigError({\n rule: issue.rule,\n file: position,\n detail: issue.message,\n });\n }\n }\n\n if (\n isLiveResponse(fixture.response) ||\n (fixture.match.endpoint === \"openai-live\" && typeof fixture.response !== \"function\")\n ) {\n fixture = {\n ...fixture,\n match: { ...fixture.match },\n response: normalizeLiveFixture(fixture.response, this.options.live),\n };\n } else if (countIdentity !== undefined && fixture !== countIdentity) {\n this.fixtureCountOrigins.set(fixture, countIdentity);\n }\n setFixtureMisbehaviorPosition(fixture, position);\n if (misbehaviorEnabled && fixture.misbehavior !== undefined) {\n markFixtureMisbehaviorEnabled(fixture);\n }\n // A fixture passed in is not marked for responsesTools \"extended\": the\n // server reads it through its extended view, so the caller's object (which\n // another server may share) is left as it was loaded.\n return fixture;\n }\n\n addFixture(fixture: Fixture): this {\n this.fixtures.push(this.normalizeFixture(fixture));\n return this;\n }\n\n addFixtures(fixtures: Fixture[]): this {\n this.fixtures.push(...fixtures.map((fixture) => this.normalizeFixture(fixture)));\n return this;\n }\n\n prependFixture(fixture: Fixture): this {\n this.fixtures.unshift(this.normalizeFixture(fixture));\n return this;\n }\n\n /** Mark a fixture this LLMock built, for {@link normalizeFixture}. */\n private own(fixture: Fixture): Fixture {\n this.ownFixtures.add(fixture);\n return fixture;\n }\n\n getFixtures(): readonly Fixture[] {\n return this.fixtures;\n }\n\n /**\n * Load a fixture file: its LLM fixtures and its `mcpFakes` blocks (F4).\n * Before `start()` the blocks are buffered and handed to the server at\n * start (W2); after it they go to the MCPMock serving each block's `mount`\n * path, auto-mounted when none does (W6). A block that cannot be honored\n * throws a `FixtureLoadError` and nothing from the file is added.\n */\n loadFixtureFile(filePath: string): this {\n return this.acceptLoaded(loadFixtureFileWithServices(filePath, undefined, this.options.live));\n }\n\n /** As {@link loadFixtureFile}, for every fixture file under `dirPath`. */\n loadFixtureDir(dirPath: string): this {\n return this.acceptLoaded(\n loadFixturesFromDirWithServices(dirPath, undefined, this.options.live),\n );\n }\n\n /**\n * Add a load's fakes (all or nothing), then its LLM fixtures. Before start\n * the fakes are checked as the start-time hand-off will check them, with\n * the blocks already buffered and the mounts added so far, so a file whose\n * fakes would be rejected adds nothing. A mount added after the load can\n * still make `start()` reject.\n */\n private acceptLoaded(loaded: FixturesWithServices): this {\n // With misbehavior enabled, a bad `misbehavior` key throws before anything is added.\n if (this.misbehaviorEnabled) loaded.fixtures.forEach(enableHeldFixtureMisbehavior);\n if (this.options.responsesTools === \"extended\") {\n loaded.fixtures.forEach(markFixtureResponsesToolsExtended);\n }\n if (loaded.mcpFakes.length > 0) {\n if (this.serverInstance) {\n this.addFakesAfterStart(this.serverInstance, loaded.mcpFakes);\n } else {\n planFileFakes(\n this.mounts,\n [...this.mcpFakeBuffer, ...loaded.mcpFakes],\n new Set(loaded.mcpFakes),\n );\n this.mcpFakeBuffer.push(...loaded.mcpFakes);\n }\n }\n this.fixtures.push(...loaded.fixtures);\n return this;\n }\n\n /**\n * W6 for a load after start. Every group of blocks (by `mount` path) is\n * checked before any mount is touched: a path held by a mount that is not\n * an MCPMock is a mount conflict, and each group is first added to a\n * throwaway store. Groups for an existing MCPMock are then added to it (its\n * own add is all or nothing and finds collisions with its loaded ids);\n * groups for a free path are added last, to a new auto-mounted MCPMock,\n * wired as W4. The add warnings (L8) are logged at `warn`.\n */\n private addFakesAfterStart(server: ServerInstance, sources: McpFakeSource[]): void {\n const { onExisting, onNew } = planFileFakes(this.mounts, sources);\n\n const logger = server.defaults.logger;\n for (const { handler, group } of onExisting) {\n const result = handler.addMcpFakes?.(group, { kind: \"file\" });\n for (const warning of result?.warnings ?? []) logger.warn(warning.message);\n }\n const registry = server.defaults.registry;\n for (const { path, group } of onNew) {\n const target = ensureFakeMount(\n this.mounts,\n path,\n {\n journal: server.journal,\n ...(registry ? { registry } : {}),\n logger,\n replaySpeed: server.defaults.replaySpeed,\n },\n logger,\n );\n // The check above found no mount at this path, and nothing ran since.\n if (\"conflict\" in target) continue;\n const result = target.handler.addMcpFakes?.(group, { kind: \"file\" });\n for (const warning of result?.warnings ?? []) logger.warn(warning.message);\n }\n }\n\n /** R4, R5: unload the fakes of every mount and the pre-start buffer. */\n private unloadMcpFakes(): void {\n this.mcpFakeBuffer.length = 0;\n for (const { handler } of this.mounts) handler.clearMcpFakes?.();\n }\n\n /**\n * Add fixtures from a JSON string or pre-parsed array of fixture entries.\n * Validates all fixtures and throws if any have severity \"error\".\n */\n addFixturesFromJSON(input: string | FixtureFileEntry[]): this {\n let entries: FixtureFileEntry[];\n if (typeof input === \"string\") {\n try {\n entries = JSON.parse(input);\n } catch (err) {\n throw new Error(\n `addFixturesFromJSON: invalid JSON — ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n } else {\n entries = input;\n }\n if (!Array.isArray(entries)) {\n throw new TypeError(\n \"addFixturesFromJSON: expected an array of fixture entries; use loadFixtureFile for a {fixtures:[...]} file\",\n );\n }\n const converted = entries.map((entry) => {\n const position = `code#${this.fixtureAddition++}`;\n const fixture = entryToFixture(entry, undefined, this.options.live, {\n file: position,\n index: 0,\n });\n setFixtureMisbehaviorPosition(fixture, position);\n if (this.misbehaviorEnabled) enableHeldFixtureMisbehavior(fixture);\n if (this.options.responsesTools === \"extended\") markFixtureResponsesToolsExtended(fixture);\n return fixture;\n });\n\n const issues = validateFixtures(converted, this.options.live);\n const errors = issues.filter((i) => i.severity === \"error\");\n if (errors.length > 0) {\n throw new Error(`Fixture validation failed: ${JSON.stringify(errors)}`);\n }\n this.fixtures.push(...converted);\n return this;\n }\n\n // Clears in place to preserve array reference identity — the running\n // server reads this same array on every request — and invalidates any\n // one-shot claim parked in flight so it cannot re-arm into the cleared queue.\n clearFixtures(): this {\n clearFixtureQueue(this.fixtures);\n this.serverInstance?.journal.clearMisbehaviorCounters();\n this.unloadMcpFakes();\n return this;\n }\n\n // ---- Convenience ----\n\n on(\n match: FixtureMatch,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n let normalized: FixtureResponse | ResponseFactory = response as ResponseFactory;\n if (typeof response !== \"function\") {\n normalized = normalizeResponse(response, this.options.live);\n // `customToolCalls` / `responsesBlocks` are normalized only where they are\n // read; otherwise they stay as written, as in 1.44.0.\n if (this.options.responsesTools === \"extended\" && !isLiveResponse(normalized)) {\n normalizeResponsesToolsKeys(normalized as unknown as Record<string, unknown>);\n }\n }\n return this.addFixture(this.own({ match, response: normalized, ...opts }));\n }\n\n onLive(\n match: Omit<FixtureMatch, \"endpoint\">,\n transcript: LiveTranscript,\n opts?: FixtureOpts,\n ): this {\n return this.on({ ...match, endpoint: \"openai-live\" }, { live: transcript }, opts);\n }\n\n onMessage(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern }, response, opts);\n }\n\n onEmbedding(\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: EmbeddingFixtureOpts,\n ): this {\n return this.on({ inputText: pattern }, response, opts);\n }\n\n onJsonOutput(pattern: string | RegExp, jsonContent: object | string, opts?: FixtureOpts): this {\n const content = typeof jsonContent === \"string\" ? jsonContent : JSON.stringify(jsonContent);\n return this.on({ userMessage: pattern, responseFormat: \"json_object\" }, { content }, opts);\n }\n\n onToolCall(\n name: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolName: name }, response, opts);\n }\n\n onToolResult(\n id: string,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ toolCallId: id }, response, opts);\n }\n\n onTurn(\n turn: number,\n pattern: string | RegExp,\n response: FixtureFileResponse | ResponseFactory,\n opts?: FixtureOpts,\n ): this {\n return this.on({ userMessage: pattern, turnIndex: turn }, response, opts);\n }\n\n onImage(prompt: string | RegExp, response: ImageResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"image\" },\n response,\n }),\n );\n }\n\n onSpeech(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: input, endpoint: \"speech\" },\n response,\n }),\n );\n }\n\n onTranscription(response: TranscriptionResponse): this {\n return this.addFixture(\n this.own({\n match: { endpoint: \"transcription\" },\n response,\n }),\n );\n }\n\n onTranslation(response: TranscriptionResponse): this {\n return this.addFixture(\n this.own({\n match: { endpoint: \"translation\" },\n response,\n }),\n );\n }\n\n onVideo(prompt: string | RegExp, response: VideoResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"video\" },\n response,\n }),\n );\n }\n\n onAudio(input: string | RegExp, response: AudioResponse): this {\n return this.addFixture(this.own({ match: { userMessage: input }, response }));\n }\n\n onSoundEffect(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: text, endpoint: \"audio-gen\" },\n response,\n }),\n );\n }\n\n onMusic(prompt: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"audio-gen\" },\n response,\n }),\n );\n }\n\n onElevenLabsTTS(text: string | RegExp, response: AudioResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: text, endpoint: \"elevenlabs-tts\" },\n response,\n }),\n );\n }\n\n onElevenLabsVoiceDesign(description: string | RegExp, response: VoiceDesignResponse): this {\n return this.addFixture(\n this.own({\n match: { userMessage: description, endpoint: \"elevenlabs-voice-design\" },\n response: voiceDesignToJson(response),\n }),\n );\n }\n\n onFalAudio(prompt: string | RegExp, response: AudioResponse, model?: string): this {\n return this.addFixture(\n this.own({\n match: { userMessage: prompt, endpoint: \"fal-audio\", ...(model ? { model } : {}) },\n response,\n }),\n );\n }\n\n // fal.queue.* is the dominant client API; onFalRun is a sync alias.\n //\n // `opts.billableUnits` rides through to the completed `queue-result`\n // response's `x-fal-billable-units` header (emitted alongside\n // `x-fal-request-id`), letting consumers like `@tanstack/ai-fal` surface a\n // billed-units value on replay. Omit it to preserve the header-less default.\n onFalQueue(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n const { billableUnits, ...fixtureOpts } = opts ?? {};\n return this.addFixture(\n this.own({\n match: { model: modelOrPrompt, endpoint: \"fal\" },\n response: { json: response, ...(billableUnits != null ? { billableUnits } : {}) },\n ...fixtureOpts,\n }),\n );\n }\n\n onFalRun(modelOrPrompt: string | RegExp, response: unknown, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, response, opts);\n }\n\n /**\n * Register a fal.ai image fixture. Wraps an `ImageResponse` (the shape used\n * by `onImage` and OpenAI/Azure image fixtures) into fal's image envelope\n * before storing it as a `RawJSONResponse`. Defaults `width`/`height` to\n * 1024 when the fixture's `ImageItem` doesn't carry them.\n */\n onFalImage(modelOrPrompt: string | RegExp, response: ImageResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, imageResponseToFalJson(response), opts);\n }\n\n /**\n * Register a fal.ai video fixture. Wraps a `VideoResponse` into fal's video\n * envelope (`{ video: { url, content_type, file_name, file_size }, seed }`)\n * before storing it as a `RawJSONResponse`.\n */\n onFalVideo(modelOrPrompt: string | RegExp, response: VideoResponse, opts?: FalQueueOpts): this {\n return this.onFalQueue(modelOrPrompt, videoResponseToFalJson(response), opts);\n }\n\n // ---- Service mock convenience methods ----\n\n onSearch(pattern: string | RegExp, results: SearchResult[]): this {\n this.searchFixtures.push({ match: pattern, results });\n return this;\n }\n\n onRerank(pattern: string | RegExp, results: RerankResult[]): this {\n this.rerankFixtures.push({ match: pattern, results });\n return this;\n }\n\n onModerate(pattern: string | RegExp, result: ModerationResult): this {\n this.moderationFixtures.push({ match: pattern, result });\n return this;\n }\n\n /**\n * Queue a one-shot error that will be returned for the next matching\n * request, then automatically removed. Implemented as an internal fixture\n * inserted at the front of the fixture list; see `queueOneShotError` for\n * the endpoint gate and the served-not-evaluated consumption rule.\n */\n nextRequestError(\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n ): this {\n // Same gate as `POST /__aimock/error` and fixture validation — this is the\n // form the docs use, and an unchecked status reaches `res.writeHead` on\n // the next matched request: 99/1000 throw there (the injected error is\n // lost and the caller sees a generic 500), and 1xx hangs the request until\n // the client times out. Throwing HERE names the offending call instead.\n if (!isInjectableStatus(status)) {\n throw new RangeError(\n `nextRequestError: invalid status ${String(status)} — must be ${INJECTED_STATUS_RANGE}`,\n );\n }\n queueOneShotError(this.fixtures, status, errorBody);\n return this;\n }\n\n // ---- Mounts ----\n\n mount(path: string, handler: Mountable): this {\n // W4: an auto-mounted MCPMock at `path` takes its requests first (dispatch\n // takes the first match), so the new mount is shadowed; so is one at\n // `path` plus \"/\", whose root request the auto-mount answers as its own.\n // An auto-mount lets any other sub-path fall through: that is no shadow.\n const shadowedBy = this.serverInstance\n ? this.mounts.find(\n (m) => isAutoMount(m.handler) && (path === m.path || path === m.path + \"/\"),\n )\n : undefined;\n this.mounts.push({ path, handler });\n\n // If server is already running, wire up journal, registry, logger and baseUrl\n // immediately so late mounts behave identically to pre-start mounts.\n if (this.serverInstance) {\n if (handler.setJournal) handler.setJournal(this.serverInstance.journal);\n if (handler.setBaseUrl) handler.setBaseUrl(this.serverInstance.url + path);\n const registry = this.serverInstance.defaults.registry;\n if (registry && handler.setRegistry) handler.setRegistry(registry);\n const logger = this.serverInstance.defaults.logger;\n if (handler.setLogger) handler.setLogger(logger);\n // B11/R12: only aimock's own MCPMock takes the replay speed; a custom\n // Mountable is never called (1.44.0 had no such hook).\n if (handler instanceof MCPMock) {\n handler.setReplaySpeed(this.serverInstance.defaults.replaySpeed);\n }\n if (shadowedBy) {\n logger.warn(\n build(\n msg`MCP fakes: the mount at ${quote(path)} is shadowed by the MCP mock auto-mounted at ${quote(shadowedBy.path)}; its requests reach the auto-mount`,\n ),\n );\n }\n }\n\n return this;\n }\n\n // ---- Journal proxies ----\n\n getRequests(): import(\"./types.js\").JournalEntry[] {\n return this.journal.getAll();\n }\n\n getLastRequest(): import(\"./types.js\").JournalEntry | null {\n return this.journal.getLast();\n }\n\n /**\n * Clear the request journal. Fixture match-counts (sequencing state) are\n * left intact — use `resetMatchCounts()` for those.\n */\n clearRequests(): void {\n this.journal.clearEntries();\n }\n\n /**\n * Reset fixture match counts, and the MCP fakes consumption state of every\n * mount (R6), for `testId` or for all test ids. Fakes stay loaded.\n */\n resetMatchCounts(testId?: string): this {\n if (this.serverInstance) {\n this.serverInstance.journal.clearMatchCounts(testId);\n }\n for (const { handler } of this.mounts) handler.resetScenarioState?.(testId);\n return this;\n }\n\n // ---- Chaos ----\n\n /**\n * Set the server-wide chaos baseline. Writes through to a RUNNING server as\n * well as the construction options: an untagged `POST /__aimock/chaos`\n * installs a baseline override that shadows `options.chaos`, and without this\n * the call would silently do nothing until the next `reset()`. Per-testId\n * overrides still win over the baseline.\n */\n setChaos(config: ChaosConfig): this {\n this.options.chaos = config;\n if (this.serverInstance) this.serverInstance.defaults.chaos = config;\n return this;\n }\n\n /**\n * Turn chaos off everywhere: the construction config, the runtime baseline,\n * and every per-testId override (assigning `undefined` is the full-clear\n * signal the `defaults.chaos` setter defines).\n */\n clearChaos(): this {\n delete this.options.chaos;\n if (this.serverInstance) this.serverInstance.defaults.chaos = undefined;\n return this;\n }\n\n // ---- Semantic misbehavior ----\n\n /** Replace construction/runtime baselines without changing named test overrides. */\n setMisbehavior(config: MisbehaviorConfig | MisbehaviorFaultId): this {\n if (!this.misbehaviorEnabled) {\n throw new TypeError(\n \"setMisbehavior: misbehavior is not enabled; construct with enableMisbehavior: true\",\n );\n }\n const parsed = parseMisbehavior(config);\n if (!parsed.ok) throw new TypeError(`${parsed.issue.rule}: ${parsed.issue.message}`);\n this.options.misbehavior = parsed.config;\n const defaults = this.serverInstance?.defaults;\n if (defaults?.misbehavior) {\n defaults.misbehavior.baseline =\n parsed.config.seed === \"random\"\n ? { ...parsed.config, seed: resolveMisbehaviorSeed(parsed.config.seed, defaults.logger) }\n : parsed.config;\n if (defaults.misbehavior.byTestId.has(DEFAULT_TEST_ID)) {\n defaults.misbehavior.byTestId.set(DEFAULT_TEST_ID, defaults.misbehavior.baseline);\n }\n }\n return this;\n }\n\n /** Clear the baseline and all runtime overrides, before or after start. */\n clearMisbehavior(): this {\n delete this.options.misbehavior;\n const scope = this.serverInstance?.defaults.misbehavior;\n if (scope) {\n scope.baseline = undefined;\n scope.byTestId.clear();\n }\n return this;\n }\n\n // ---- Recording ----\n\n enableRecording(config: RecordConfig): this {\n this.options.record = config;\n return this;\n }\n\n disableRecording(): this {\n delete this.options.record;\n return this;\n }\n\n // ---- Reset ----\n\n /**\n * Full reset — the in-process equivalent of `POST /__aimock/reset`. Shares\n * one implementation with the control-API route so the two cannot drift.\n *\n * The one deliberate difference: search / rerank / moderation fixtures are\n * also cleared here. Those are registered through this class only — the\n * control API has no route that creates them, so the HTTP reset can neither\n * reach nor observe them.\n *\n * NOT ALL OF THIS IS PER-INSTANCE. `performFullReset` clears module-global\n * state as well: the Gemini interaction and event-id counters\n * (`resetInteractionCounter` / `resetEventIdCounter` in\n * `./gemini-interactions.js`), the fal.ai job/queue maps (`falJobs`,\n * `falQueueStates`), the fine-tuning job store (`clearFineTuningStore`),\n * and the ElevenLabs Voice Design store (`clearElevenLabsVoices`). With two\n * `LLMock` instances live in one process,\n * `a.reset()` rewinds the Gemini id sequence that `b` is mid-way through —\n * `b` then re-emits `aimock-int-0` / `evt_1`, ids it has already handed\n * out — and drops `b`'s in-flight fal jobs. Give each instance its own\n * process (or its own vitest worker) if that matters.\n *\n * The global stores are cleared even before `start()`, when there is no\n * server instance to reset.\n */\n reset(): this {\n this.searchFixtures.length = 0;\n this.rerankFixtures.length = 0;\n this.moderationFixtures.length = 0;\n // `ServerInstance` carries no mounts, so the fakes are unloaded here (R4).\n this.unloadMcpFakes();\n performFullReset(this.fixtures, this.serverInstance);\n return this;\n }\n\n // ---- Server lifecycle ----\n\n async start(): Promise<string> {\n if (this.serverInstance) {\n throw new Error(\"Server already started\");\n }\n const serviceFixtures = {\n search: this.searchFixtures,\n rerank: this.rerankFixtures,\n moderation: this.moderationFixtures,\n mcpFakes: [...this.mcpFakeBuffer],\n };\n this.serverInstance = await (this.resolvedInboundAuth\n ? createServerWithResolvedAuth(\n this.fixtures,\n this.options,\n this.resolvedInboundAuth,\n this.mounts,\n serviceFixtures,\n )\n : createServer(this.fixtures, this.options, this.mounts, serviceFixtures));\n const countIdentity = (fixture: Fixture) => this.fixtureCountOrigins.get(fixture) ?? fixture;\n this.serverInstance.journal.configureFixtureCountIdentity(countIdentity);\n // The server holds the buffered fakes now (W2). A start that rejects took\n // its hand-off back, so the buffer is kept for a retry.\n this.mcpFakeBuffer.length = 0;\n return this.serverInstance.url;\n }\n\n closeLiveSessions(testId?: string): this {\n this.serverInstance?.closeLiveSessions(testId);\n return this;\n }\n\n async stop(): Promise<void> {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n const { server } = this.serverInstance;\n await new Promise<void>((resolve, reject) => {\n server.close((err: Error | undefined) => (err ? reject(err) : resolve()));\n });\n this.serverInstance = null;\n }\n\n // ---- Accessors ----\n\n get journal(): Journal {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.journal;\n }\n\n get url(): string {\n if (!this.serverInstance) {\n throw new Error(\"Server not started\");\n }\n return this.serverInstance.url;\n }\n\n get baseUrl(): string {\n return this.url;\n }\n\n get port(): number {\n const parsed = new URL(this.url); // this.url throws if not started\n if (!parsed.port) {\n throw new Error(`Server URL has no explicit port: ${this.url}`);\n }\n return parseInt(parsed.port, 10);\n }\n\n // ---- Static factory ----\n\n static async create(options?: MockServerOptions): Promise<LLMock> {\n const instance = new LLMock(options);\n await instance.start();\n return instance;\n }\n}\n\n/** @internal Configuration startup preserves a policy resolved from the selected source. */\nexport function createLLMockWithResolvedAuth(\n options: MockServerOptions,\n resolvedAuth: ResolvedInboundAuth,\n): LLMock {\n return new LLMock(options, resolvedAuth);\n}\n"],"mappings":";;;;;;;;;;;;;;AAuEA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAQ,WAAsB,EAAE;CAChC,AAAQ,kBAAkB;CAC1B,AAAiB,sCAAsB,IAAI,SAA2B;;;;;CAKtE,AAAiB,8BAAc,IAAI,SAAkB;CACrD,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,iBAAkC,EAAE;CAC5C,AAAQ,qBAA0C,EAAE;CACpD,AAAQ,SAAsD,EAAE;;CAEhE,AAAQ,gBAAiC,EAAE;;CAE3C,AAAQ,iBAAwC;CAChD,AAAQ;CACR,AAAiB;CAEjB,YAAY,SAA6B,qBAA2C;AAElF,0BAAwB,KAAK,SAAS;AACtC,OAAK,UAAU,WAAW,EAAE;AAC5B,MAAI,KAAK,QAAQ,SAAS,OAAW,sBAAqB,KAAK,QAAQ,KAAK;AAG5E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