@copilotkit/aimock 1.17.0 → 1.18.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +11 -0
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/bedrock-converse.cjs +4 -4
- package/dist/bedrock-converse.cjs.map +1 -1
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts.map +1 -1
- package/dist/bedrock-converse.js +4 -4
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +4 -4
- package/dist/bedrock.cjs.map +1 -1
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts.map +1 -1
- package/dist/bedrock.js +4 -4
- package/dist/bedrock.js.map +1 -1
- package/dist/chaos.cjs +35 -9
- package/dist/chaos.cjs.map +1 -1
- package/dist/chaos.d.cts +17 -2
- package/dist/chaos.d.cts.map +1 -1
- package/dist/chaos.d.ts +17 -2
- package/dist/chaos.d.ts.map +1 -1
- package/dist/chaos.js +35 -10
- package/dist/chaos.js.map +1 -1
- package/dist/cohere.cjs +2 -2
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.js +2 -2
- package/dist/cohere.js.map +1 -1
- package/dist/elevenlabs-audio.cjs +5 -2
- package/dist/elevenlabs-audio.cjs.map +1 -1
- package/dist/elevenlabs-audio.js +5 -2
- package/dist/elevenlabs-audio.js.map +1 -1
- package/dist/embeddings.cjs +2 -2
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.js +2 -2
- package/dist/embeddings.js.map +1 -1
- package/dist/fal-audio.cjs +11 -4
- package/dist/fal-audio.cjs.map +1 -1
- package/dist/fal-audio.js +11 -5
- package/dist/fal-audio.js.map +1 -1
- package/dist/fal.cjs +424 -0
- package/dist/fal.cjs.map +1 -0
- package/dist/fal.d.cts +39 -0
- package/dist/fal.d.cts.map +1 -0
- package/dist/fal.d.ts +39 -0
- package/dist/fal.d.ts.map +1 -0
- package/dist/fal.js +420 -0
- package/dist/fal.js.map +1 -0
- package/dist/fixture-loader.cjs +2 -2
- package/dist/fixture-loader.cjs.map +1 -1
- package/dist/fixture-loader.d.cts.map +1 -1
- package/dist/fixture-loader.d.ts.map +1 -1
- package/dist/fixture-loader.js +3 -3
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-interactions.cjs +4 -2
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.js +4 -2
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +2 -2
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.js +2 -2
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +4 -0
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +4 -1
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +2 -2
- package/dist/images.cjs.map +1 -1
- package/dist/images.js +2 -2
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/llmock.cjs +15 -0
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +2 -0
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +2 -0
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +15 -0
- package/dist/llmock.js.map +1 -1
- package/dist/messages.cjs +2 -2
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.js +2 -2
- package/dist/messages.js.map +1 -1
- package/dist/ollama.cjs +4 -4
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts.map +1 -1
- package/dist/ollama.js +4 -4
- package/dist/ollama.js.map +1 -1
- package/dist/recorder.cjs +42 -17
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts +50 -5
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts +50 -5
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +42 -17
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +2 -2
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.js +2 -2
- package/dist/responses.js.map +1 -1
- package/dist/router.cjs +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.cts.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +2 -2
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +128 -52
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +129 -53
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +2 -2
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.js +2 -2
- package/dist/speech.js.map +1 -1
- package/dist/transcription.cjs +2 -2
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.js +2 -2
- package/dist/transcription.js.map +1 -1
- package/dist/types.d.cts +30 -6
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +30 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/video.cjs +9 -3
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts +1 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts +1 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +9 -3
- package/dist/video.js.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -5,7 +5,7 @@ import { matchFixture } from "./router.js";
|
|
|
5
5
|
import { entryToFixture, validateFixtures } from "./fixture-loader.js";
|
|
6
6
|
import { writeErrorResponse, writeSSEStream } from "./sse-writer.js";
|
|
7
7
|
import { createInterruptionSignal } from "./interruption.js";
|
|
8
|
-
import {
|
|
8
|
+
import { applyChaosAction, evaluateChaos } from "./chaos.js";
|
|
9
9
|
import { proxyAndRecord } from "./recorder.js";
|
|
10
10
|
import { handleResponses } from "./responses.js";
|
|
11
11
|
import { handleMessages } from "./messages.js";
|
|
@@ -20,6 +20,7 @@ import { handleTranscription } from "./transcription.js";
|
|
|
20
20
|
import { VideoStateMap, handleVideoCreate, handleVideoStatus } from "./video.js";
|
|
21
21
|
import { handleElevenLabsAudio } from "./elevenlabs-audio.js";
|
|
22
22
|
import { falJobs, handleFalQueue } from "./fal-audio.js";
|
|
23
|
+
import { falQueueStates, handleFal } from "./fal.js";
|
|
23
24
|
import { handleOllama, handleOllamaGenerate } from "./ollama.js";
|
|
24
25
|
import { handleCohere } from "./cohere.js";
|
|
25
26
|
import { handleSearch } from "./search.js";
|
|
@@ -54,6 +55,7 @@ const ELEVENLABS_MUSIC_RE = /^\/v1\/music(?:\/(.+))?$/;
|
|
|
54
55
|
const FAL_QUEUE_SUBMIT_RE = /^\/fal\/queue\/submit\/(.+)$/;
|
|
55
56
|
const FAL_QUEUE_REQUESTS_RE = /^\/fal\/queue\/requests\/(.+)$/;
|
|
56
57
|
const FAL_RUN_RE = /^\/fal\/run\/(.+)$/;
|
|
58
|
+
const FAL_PREFIX_RE = /^\/fal(?:\/.*)?$/;
|
|
57
59
|
const DEFAULT_CHUNK_SIZE = 20;
|
|
58
60
|
const COMPAT_SUFFIXES = [
|
|
59
61
|
"/chat/completions",
|
|
@@ -209,6 +211,7 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
|
|
|
209
211
|
journal.clear();
|
|
210
212
|
videoStates.clear();
|
|
211
213
|
falJobs.clear();
|
|
214
|
+
falQueueStates.clear();
|
|
212
215
|
if (defaults.registry) defaults.registry.setGauge("aimock_fixtures_loaded", {}, fixtures.length);
|
|
213
216
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
214
217
|
res.end(JSON.stringify({ reset: true }));
|
|
@@ -327,6 +330,9 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
327
330
|
} }));
|
|
328
331
|
return;
|
|
329
332
|
}
|
|
333
|
+
const method = req.method ?? "POST";
|
|
334
|
+
const path = req.url ?? COMPLETIONS_PATH;
|
|
335
|
+
const flatHeaders = flattenHeaders(req.headers);
|
|
330
336
|
body._endpointType = "chat";
|
|
331
337
|
const testId = getTestId(req);
|
|
332
338
|
const fixture = matchFixture(fixtures, body, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
@@ -338,18 +344,40 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
338
344
|
const snippet = typeof lastUserMsg?.content === "string" ? lastUserMsg.content.slice(0, 80) : "";
|
|
339
345
|
defaults.logger.debug(`No fixture matched for request (model=${body.model ?? "?"}, msg="${snippet}")`);
|
|
340
346
|
}
|
|
341
|
-
const
|
|
342
|
-
const
|
|
343
|
-
const flatHeaders = flattenHeaders(req.headers);
|
|
344
|
-
if (applyChaos(res, fixture, defaults.chaos, req.headers, journal, {
|
|
347
|
+
const chaosAction = evaluateChaos(fixture, defaults.chaos, req.headers, defaults.logger);
|
|
348
|
+
const chaosContext = {
|
|
345
349
|
method,
|
|
346
350
|
path,
|
|
347
351
|
headers: flatHeaders,
|
|
348
352
|
body
|
|
349
|
-
}
|
|
353
|
+
};
|
|
354
|
+
if (chaosAction === "drop" || chaosAction === "disconnect") {
|
|
355
|
+
applyChaosAction(chaosAction, res, fixture, journal, chaosContext, fixture ? "fixture" : "proxy", defaults.registry);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (fixture && chaosAction === "malformed") {
|
|
359
|
+
applyChaosAction(chaosAction, res, fixture, journal, chaosContext, "fixture", defaults.registry);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
350
362
|
if (!fixture) {
|
|
351
363
|
if (defaults.record && providerKey) {
|
|
352
|
-
|
|
364
|
+
const hookOptions = chaosAction === "malformed" ? {
|
|
365
|
+
beforeWriteResponse: () => {
|
|
366
|
+
applyChaosAction(chaosAction, res, null, journal, chaosContext, "proxy", defaults.registry);
|
|
367
|
+
return true;
|
|
368
|
+
},
|
|
369
|
+
onHookBypassed: (reason) => {
|
|
370
|
+
defaults.logger.warn(`[chaos] malformed bypassed on proxy: upstream returned SSE (${reason})`);
|
|
371
|
+
defaults.registry?.incrementCounter("aimock_chaos_bypassed_total", {
|
|
372
|
+
action: "malformed",
|
|
373
|
+
source: "proxy",
|
|
374
|
+
reason
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
} : void 0;
|
|
378
|
+
const outcome = await proxyAndRecord(req, res, body, providerKey, req.url ?? COMPLETIONS_PATH, fixtures, defaults, raw, hookOptions);
|
|
379
|
+
if (outcome === "handled_by_hook") return;
|
|
380
|
+
if (outcome === "relayed") {
|
|
353
381
|
journal.add({
|
|
354
382
|
method: req.method ?? "POST",
|
|
355
383
|
path: req.url ?? COMPLETIONS_PATH,
|
|
@@ -866,7 +894,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
866
894
|
const videoStatusMatch = pathname.match(VIDEOS_STATUS_RE);
|
|
867
895
|
if (videoStatusMatch && req.method === "GET") {
|
|
868
896
|
const videoId = videoStatusMatch[1];
|
|
869
|
-
handleVideoStatus(req, res, videoId, journal, setCorsHeaders, videoStates);
|
|
897
|
+
handleVideoStatus(req, res, videoId, journal, defaults, setCorsHeaders, videoStates);
|
|
870
898
|
return;
|
|
871
899
|
}
|
|
872
900
|
const geminiPredictMatch = pathname.match(GEMINI_PREDICT_RE);
|
|
@@ -1095,15 +1123,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1095
1123
|
setCorsHeaders(res);
|
|
1096
1124
|
try {
|
|
1097
1125
|
const raw = await readBody(req);
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1126
|
+
const chaosAction = evaluateChaos(null, defaults.chaos, req.headers, defaults.logger);
|
|
1127
|
+
if (chaosAction) {
|
|
1128
|
+
applyChaosAction(chaosAction, res, null, journal, {
|
|
1129
|
+
method: req.method ?? "POST",
|
|
1130
|
+
path: pathname,
|
|
1131
|
+
headers: flattenHeaders(req.headers),
|
|
1132
|
+
body: {
|
|
1133
|
+
model: "",
|
|
1134
|
+
messages: []
|
|
1135
|
+
}
|
|
1136
|
+
}, "fixture", defaults.registry);
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1107
1139
|
await handleElevenLabsAudio(req, res, raw, fixtures, defaults, journal, "sound-generation");
|
|
1108
1140
|
} catch (err) {
|
|
1109
1141
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
@@ -1121,15 +1153,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1121
1153
|
const musicSubType = musicMatch[1] ?? "music";
|
|
1122
1154
|
try {
|
|
1123
1155
|
const raw = await readBody(req);
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1156
|
+
const chaosAction = evaluateChaos(null, defaults.chaos, req.headers, defaults.logger);
|
|
1157
|
+
if (chaosAction) {
|
|
1158
|
+
applyChaosAction(chaosAction, res, null, journal, {
|
|
1159
|
+
method: req.method ?? "POST",
|
|
1160
|
+
path: pathname,
|
|
1161
|
+
headers: flattenHeaders(req.headers),
|
|
1162
|
+
body: {
|
|
1163
|
+
model: "",
|
|
1164
|
+
messages: []
|
|
1165
|
+
}
|
|
1166
|
+
}, "fixture", defaults.registry);
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1133
1169
|
await handleElevenLabsAudio(req, res, raw, fixtures, defaults, journal, musicSubType);
|
|
1134
1170
|
} catch (err) {
|
|
1135
1171
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
@@ -1141,19 +1177,51 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1141
1177
|
}
|
|
1142
1178
|
return;
|
|
1143
1179
|
}
|
|
1180
|
+
if (FAL_PREFIX_RE.test(pathname) && req.headers["x-fal-target-host"]) {
|
|
1181
|
+
setCorsHeaders(res);
|
|
1182
|
+
try {
|
|
1183
|
+
const raw = req.method === "POST" || req.method === "PUT" ? await readBody(req) : "";
|
|
1184
|
+
const chaosAction = evaluateChaos(null, defaults.chaos, req.headers, defaults.logger);
|
|
1185
|
+
if (chaosAction) {
|
|
1186
|
+
applyChaosAction(chaosAction, res, null, journal, {
|
|
1187
|
+
method: req.method ?? "GET",
|
|
1188
|
+
path: pathname,
|
|
1189
|
+
headers: flattenHeaders(req.headers),
|
|
1190
|
+
body: {
|
|
1191
|
+
model: "",
|
|
1192
|
+
messages: []
|
|
1193
|
+
}
|
|
1194
|
+
}, "fixture", defaults.registry);
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
if (await handleFal(req, res, raw, pathname, fixtures, defaults, journal) === "handled") return;
|
|
1198
|
+
} catch (err) {
|
|
1199
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1200
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1201
|
+
message: msg,
|
|
1202
|
+
type: "server_error"
|
|
1203
|
+
} }));
|
|
1204
|
+
else if (!res.writableEnded) res.destroy();
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1144
1208
|
if (pathname.match(FAL_QUEUE_SUBMIT_RE) && req.method === "POST") {
|
|
1145
1209
|
setCorsHeaders(res);
|
|
1146
1210
|
try {
|
|
1147
1211
|
const raw = await readBody(req);
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1212
|
+
const chaosAction = evaluateChaos(null, defaults.chaos, req.headers, defaults.logger);
|
|
1213
|
+
if (chaosAction) {
|
|
1214
|
+
applyChaosAction(chaosAction, res, null, journal, {
|
|
1215
|
+
method: req.method ?? "POST",
|
|
1216
|
+
path: pathname,
|
|
1217
|
+
headers: flattenHeaders(req.headers),
|
|
1218
|
+
body: {
|
|
1219
|
+
model: "",
|
|
1220
|
+
messages: []
|
|
1221
|
+
}
|
|
1222
|
+
}, "fixture", defaults.registry);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1157
1225
|
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1158
1226
|
} catch (err) {
|
|
1159
1227
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
@@ -1169,15 +1237,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1169
1237
|
setCorsHeaders(res);
|
|
1170
1238
|
try {
|
|
1171
1239
|
const raw = req.method === "POST" ? await readBody(req) : "{}";
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1240
|
+
const chaosAction = evaluateChaos(null, defaults.chaos, req.headers, defaults.logger);
|
|
1241
|
+
if (chaosAction) {
|
|
1242
|
+
applyChaosAction(chaosAction, res, null, journal, {
|
|
1243
|
+
method: req.method ?? "GET",
|
|
1244
|
+
path: pathname,
|
|
1245
|
+
headers: flattenHeaders(req.headers),
|
|
1246
|
+
body: {
|
|
1247
|
+
model: "",
|
|
1248
|
+
messages: []
|
|
1249
|
+
}
|
|
1250
|
+
}, "fixture", defaults.registry);
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1181
1253
|
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1182
1254
|
} catch (err) {
|
|
1183
1255
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
@@ -1193,15 +1265,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1193
1265
|
setCorsHeaders(res);
|
|
1194
1266
|
try {
|
|
1195
1267
|
const raw = await readBody(req);
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1268
|
+
const chaosAction = evaluateChaos(null, defaults.chaos, req.headers, defaults.logger);
|
|
1269
|
+
if (chaosAction) {
|
|
1270
|
+
applyChaosAction(chaosAction, res, null, journal, {
|
|
1271
|
+
method: req.method ?? "POST",
|
|
1272
|
+
path: pathname,
|
|
1273
|
+
headers: flattenHeaders(req.headers),
|
|
1274
|
+
body: {
|
|
1275
|
+
model: "",
|
|
1276
|
+
messages: []
|
|
1277
|
+
}
|
|
1278
|
+
}, "fixture", defaults.registry);
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1205
1281
|
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1206
1282
|
} catch (err) {
|
|
1207
1283
|
const msg = err instanceof Error ? err.message : "Internal error";
|