@copilotkit/aimock 1.38.0 → 1.40.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 (81) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +56 -0
  4. package/README.md +24 -2
  5. package/dist/agui-handler.cjs +20 -18
  6. package/dist/agui-handler.cjs.map +1 -1
  7. package/dist/agui-handler.d.cts +8 -1
  8. package/dist/agui-handler.d.cts.map +1 -1
  9. package/dist/agui-handler.d.ts +8 -1
  10. package/dist/agui-handler.d.ts.map +1 -1
  11. package/dist/agui-handler.js +20 -18
  12. package/dist/agui-handler.js.map +1 -1
  13. package/dist/agui-stub.d.cts +2 -2
  14. package/dist/agui-stub.d.ts +2 -2
  15. package/dist/agui-types.d.cts +84 -3
  16. package/dist/agui-types.d.cts.map +1 -1
  17. package/dist/agui-types.d.ts +84 -3
  18. package/dist/agui-types.d.ts.map +1 -1
  19. package/dist/aimock-cli.cjs +1 -1
  20. package/dist/aimock-cli.cjs.map +1 -1
  21. package/dist/aimock-cli.js +1 -1
  22. package/dist/aimock-cli.js.map +1 -1
  23. package/dist/cli.cjs +10 -10
  24. package/dist/cli.cjs.map +1 -1
  25. package/dist/cli.js +10 -10
  26. package/dist/cli.js.map +1 -1
  27. package/dist/config-loader.d.cts.map +1 -1
  28. package/dist/helpers.cjs +8 -4
  29. package/dist/helpers.cjs.map +1 -1
  30. package/dist/helpers.d.cts.map +1 -1
  31. package/dist/helpers.d.ts.map +1 -1
  32. package/dist/helpers.js +8 -4
  33. package/dist/helpers.js.map +1 -1
  34. package/dist/index.d.cts +2 -2
  35. package/dist/index.d.ts +2 -2
  36. package/dist/llmock.cjs +23 -9
  37. package/dist/llmock.cjs.map +1 -1
  38. package/dist/llmock.d.cts +22 -0
  39. package/dist/llmock.d.cts.map +1 -1
  40. package/dist/llmock.d.ts +22 -0
  41. package/dist/llmock.d.ts.map +1 -1
  42. package/dist/llmock.js +25 -11
  43. package/dist/llmock.js.map +1 -1
  44. package/dist/openrouter-chat.cjs +41 -0
  45. package/dist/openrouter-chat.cjs.map +1 -1
  46. package/dist/openrouter-chat.js +41 -0
  47. package/dist/openrouter-chat.js.map +1 -1
  48. package/dist/openrouter-video.cjs.map +1 -1
  49. package/dist/openrouter-video.js.map +1 -1
  50. package/dist/recorder.cjs +77 -8
  51. package/dist/recorder.cjs.map +1 -1
  52. package/dist/recorder.d.cts.map +1 -1
  53. package/dist/recorder.d.ts.map +1 -1
  54. package/dist/recorder.js +77 -8
  55. package/dist/recorder.js.map +1 -1
  56. package/dist/server.cjs +80 -17
  57. package/dist/server.cjs.map +1 -1
  58. package/dist/server.d.cts +6 -1
  59. package/dist/server.d.cts.map +1 -1
  60. package/dist/server.d.ts +6 -1
  61. package/dist/server.d.ts.map +1 -1
  62. package/dist/server.js +80 -18
  63. package/dist/server.js.map +1 -1
  64. package/dist/stream-collapse.cjs +97 -6
  65. package/dist/stream-collapse.cjs.map +1 -1
  66. package/dist/stream-collapse.d.cts +16 -0
  67. package/dist/stream-collapse.d.cts.map +1 -1
  68. package/dist/stream-collapse.d.ts +16 -0
  69. package/dist/stream-collapse.d.ts.map +1 -1
  70. package/dist/stream-collapse.js +97 -6
  71. package/dist/stream-collapse.js.map +1 -1
  72. package/dist/types.d.cts +22 -3
  73. package/dist/types.d.cts.map +1 -1
  74. package/dist/types.d.ts +22 -3
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/vector-types.d.ts.map +1 -1
  77. package/dist/ws-gemini-live.cjs +41 -6
  78. package/dist/ws-gemini-live.cjs.map +1 -1
  79. package/dist/ws-gemini-live.js +41 -6
  80. package/dist/ws-gemini-live.js.map +1 -1
  81. package/package.json +5 -3
package/dist/server.cjs CHANGED
@@ -145,23 +145,31 @@ function handleNotFound(res, message) {
145
145
  }
146
146
  const CONTROL_PREFIX = "/__aimock";
147
147
  /**
148
- * Perform a full fixtures reset: clear the fixtures array, journal, video/fal
149
- * generation state, and the interaction/event-id counters, then zero the
150
- * `aimock_fixtures_loaded` gauge. Shared by `/reset/fixtures` and the
151
- * deprecated `/reset` alias.
148
+ * Perform a full reset: clear the fixtures array, the journal (entries *and*
149
+ * per-test fixture match-counts, i.e. sequence position), the video and fal.ai
150
+ * job/queue state, and the Gemini interaction/event-id counters, then re-zero
151
+ * the `aimock_fixtures_loaded` gauge.
152
+ *
153
+ * `targets` is `null` when no server is running (an in-process `reset()` before
154
+ * `start()`). The process-global generation state is reset either way, since it
155
+ * is not owned by any one server instance.
156
+ *
157
+ * Shared by `POST /__aimock/reset` (canonical), its deprecated
158
+ * `POST /__aimock/reset/fixtures` alias, and `LLMock.reset()`.
152
159
  */
153
- function performFixturesReset(fixtures, journal, videoStates, openRouterVideoJobs, veoVideoJobs, grokVideoJobs, defaults) {
160
+ function performFullReset(fixtures, targets) {
154
161
  fixtures.length = 0;
155
- journal.clear();
156
- videoStates.clear();
157
- openRouterVideoJobs.clear();
158
- veoVideoJobs.clear();
159
- grokVideoJobs.clear();
160
162
  require_fal_audio.falJobs.clear();
161
163
  require_fal.falQueueStates.clear();
162
164
  require_gemini_interactions.resetInteractionCounter();
163
165
  require_gemini_interactions.resetEventIdCounter();
164
- if (defaults.registry) defaults.registry.setGauge("aimock_fixtures_loaded", {}, fixtures.length);
166
+ if (!targets) return;
167
+ targets.journal.clear();
168
+ targets.videoStates.clear();
169
+ targets.openRouterVideoJobs.clear();
170
+ targets.veoVideoJobs.clear();
171
+ targets.grokVideoJobs.clear();
172
+ if (targets.defaults.registry) targets.defaults.registry.setGauge("aimock_fixtures_loaded", {}, fixtures.length);
165
173
  }
166
174
  /**
167
175
  * Handle requests under `/__aimock/`. Returns `true` if the request was
@@ -181,6 +189,11 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
181
189
  res.end(JSON.stringify(journal.getAll()));
182
190
  return true;
183
191
  }
192
+ if (subPath === "/fixtures" && req.method === "GET") {
193
+ res.writeHead(200, { "Content-Type": "application/json" });
194
+ res.end(JSON.stringify({ count: fixtures.length }));
195
+ return true;
196
+ }
184
197
  if (subPath === "/fixtures" && req.method === "POST") {
185
198
  let raw;
186
199
  try {
@@ -230,8 +243,16 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
230
243
  res.end(JSON.stringify({ cleared: true }));
231
244
  return true;
232
245
  }
233
- if (subPath === "/reset/fixtures" && req.method === "POST") {
234
- performFixturesReset(fixtures, journal, videoStates, openRouterVideoJobs, veoVideoJobs, grokVideoJobs, defaults);
246
+ const resetTargets = () => ({
247
+ journal,
248
+ videoStates,
249
+ openRouterVideoJobs,
250
+ veoVideoJobs,
251
+ grokVideoJobs,
252
+ defaults
253
+ });
254
+ if (subPath === "/reset" && req.method === "POST") {
255
+ performFullReset(fixtures, resetTargets());
235
256
  res.writeHead(200, { "Content-Type": "application/json" });
236
257
  res.end(JSON.stringify({ reset: true }));
237
258
  return true;
@@ -242,10 +263,10 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
242
263
  res.end(JSON.stringify({ reset: true }));
243
264
  return true;
244
265
  }
245
- if (subPath === "/reset" && req.method === "POST") {
246
- performFixturesReset(fixtures, journal, videoStates, openRouterVideoJobs, veoVideoJobs, grokVideoJobs, defaults);
247
- const deprecation = "POST /__aimock/reset is deprecated; use POST /__aimock/reset/fixtures (full reset) or POST /__aimock/reset/journal (journal only)";
248
- defaults.logger.warn("POST /__aimock/reset is deprecated; use /__aimock/reset/fixtures or /__aimock/reset/journal");
266
+ if (subPath === "/reset/fixtures" && req.method === "POST") {
267
+ performFullReset(fixtures, resetTargets());
268
+ const deprecation = "POST /__aimock/reset/fixtures is deprecated; use POST /__aimock/reset (full reset) or POST /__aimock/reset/journal (journal only)";
269
+ defaults.logger.warn("POST /__aimock/reset/fixtures is deprecated; use /__aimock/reset or /__aimock/reset/journal");
249
270
  res.writeHead(200, {
250
271
  "Content-Type": "application/json",
251
272
  Deprecation: "true"
@@ -1839,7 +1860,48 @@ async function createServerWithResolvedAuth(fixtures, options, resolvedAuth, mou
1839
1860
  if (!socket.destroyed) socket.destroy();
1840
1861
  });
1841
1862
  });
1863
+ /**
1864
+ * Body bytes the platform already parsed onto `req` for an upgrade request.
1865
+ *
1866
+ * Node >= 26 delivers an upgrade request's body here and leaves `head`
1867
+ * empty; Node <= 24 leaves the body in `head` and ends `req` with nothing.
1868
+ * The stream has already ended in both cases, so this resolves on the next
1869
+ * tick either way — it never waits on the network.
1870
+ */
1871
+ function drainParsedRequestBody(req) {
1872
+ return new Promise((resolve) => {
1873
+ const chunks = [];
1874
+ let settled = false;
1875
+ const done = () => {
1876
+ if (settled) return;
1877
+ settled = true;
1878
+ resolve(Buffer.concat(chunks));
1879
+ };
1880
+ req.on("data", (c) => chunks.push(c));
1881
+ req.on("end", done);
1882
+ req.on("error", done);
1883
+ req.on("close", done);
1884
+ req.resume();
1885
+ });
1886
+ }
1842
1887
  async function handleUpgradeRequest(req, socket, head) {
1888
+ if ((req.headers.upgrade ?? "").toLowerCase() !== "websocket") {
1889
+ const parsedBody = await drainParsedRequestBody(req);
1890
+ const requestLine = `${req.method} ${req.url} HTTP/${req.httpVersion}\r\n`;
1891
+ const headerLines = [];
1892
+ for (let i = 0; i < req.rawHeaders.length; i += 2) {
1893
+ if (/^(?:upgrade|connection)$/i.test(req.rawHeaders[i])) continue;
1894
+ headerLines.push(`${req.rawHeaders[i]}: ${req.rawHeaders[i + 1]}`);
1895
+ }
1896
+ const rebuilt = Buffer.from(requestLine + headerLines.join("\r\n") + "\r\n\r\n");
1897
+ socket.unshift(Buffer.concat([
1898
+ rebuilt,
1899
+ parsedBody,
1900
+ head
1901
+ ]));
1902
+ server.emit("connection", socket);
1903
+ return;
1904
+ }
1843
1905
  const parsedUrl = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
1844
1906
  let pathname = parsedUrl.pathname;
1845
1907
  if (!require_api_key_auth.validateRequestApiKey(req, resolvedAuth.policy).ok) {
@@ -1940,4 +2002,5 @@ async function createServerWithResolvedAuth(fixtures, options, resolvedAuth, mou
1940
2002
  //#endregion
1941
2003
  exports.createServer = createServer;
1942
2004
  exports.createServerWithResolvedAuth = createServerWithResolvedAuth;
2005
+ exports.performFullReset = performFullReset;
1943
2006
  //# sourceMappingURL=server.cjs.map