@copilotkit/aimock 1.22.0 → 1.23.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 +37 -0
- package/README.md +10 -10
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +0 -0
- package/dist/aimock-cli.js +0 -0
- package/dist/bedrock-converse.cjs +62 -22
- 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 +62 -22
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +59 -20
- 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 +59 -20
- package/dist/bedrock.js.map +1 -1
- package/dist/cli.cjs +8 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +8 -2
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +29 -9
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +30 -10
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/constants.cjs +8 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +8 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/elevenlabs-audio.cjs +41 -18
- package/dist/elevenlabs-audio.cjs.map +1 -1
- package/dist/elevenlabs-audio.d.cts.map +1 -1
- package/dist/elevenlabs-audio.d.ts.map +1 -1
- package/dist/elevenlabs-audio.js +42 -19
- package/dist/elevenlabs-audio.js.map +1 -1
- package/dist/embeddings.cjs +19 -17
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +20 -18
- package/dist/embeddings.js.map +1 -1
- package/dist/fal-audio.cjs +128 -39
- package/dist/fal-audio.cjs.map +1 -1
- package/dist/fal-audio.d.cts.map +1 -1
- package/dist/fal-audio.d.ts.map +1 -1
- package/dist/fal-audio.js +129 -40
- package/dist/fal-audio.js.map +1 -1
- package/dist/fal.cjs +25 -8
- package/dist/fal.cjs.map +1 -1
- package/dist/fal.d.cts.map +1 -1
- package/dist/fal.d.ts.map +1 -1
- package/dist/fal.js +26 -9
- package/dist/fal.js.map +1 -1
- package/dist/fixture-loader.cjs +11 -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 +11 -2
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-interactions.cjs +29 -7
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.js +28 -8
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +45 -19
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +45 -19
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +52 -8
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +6 -0
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +52 -9
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +26 -8
- package/dist/images.cjs.map +1 -1
- package/dist/images.d.cts.map +1 -1
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +27 -9
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/journal.cjs +17 -7
- package/dist/journal.cjs.map +1 -1
- package/dist/journal.d.cts +2 -3
- package/dist/journal.d.cts.map +1 -1
- package/dist/journal.d.ts +2 -3
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +15 -4
- package/dist/journal.js.map +1 -1
- package/dist/messages.cjs +33 -12
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +33 -12
- package/dist/messages.js.map +1 -1
- package/dist/model-utils.cjs +11 -0
- package/dist/model-utils.cjs.map +1 -0
- package/dist/model-utils.js +10 -0
- package/dist/model-utils.js.map +1 -0
- package/dist/ollama.cjs +59 -18
- 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 +60 -19
- package/dist/ollama.js.map +1 -1
- package/dist/recorder.cjs +30 -11
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +30 -11
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +61 -52
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +62 -53
- package/dist/responses.js.map +1 -1
- package/dist/router.cjs +7 -3
- package/dist/router.cjs.map +1 -1
- package/dist/router.js +7 -3
- package/dist/router.js.map +1 -1
- package/dist/server.cjs +64 -180
- 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 +40 -156
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +26 -8
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.d.cts.map +1 -1
- package/dist/speech.d.ts.map +1 -1
- package/dist/speech.js +27 -9
- package/dist/speech.js.map +1 -1
- package/dist/transcription.cjs +57 -19
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.cts.map +1 -1
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +58 -20
- package/dist/transcription.js.map +1 -1
- package/dist/types.d.cts +19 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +19 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/video.cjs +50 -14
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts +8 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts +8 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +51 -15
- package/dist/video.js.map +1 -1
- package/dist/ws-gemini-live.cjs +34 -27
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +2 -2
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +34 -27
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +776 -175
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts +2 -2
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +776 -175
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +48 -12
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +49 -13
- package/dist/ws-responses.js.map +1 -1
- package/package.json +2 -2
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildContentWithToolCallsChunks, buildContentWithToolCallsCompletion, buildTextChunks, buildTextCompletion, buildToolCallChunks, buildToolCallCompletion, extractOverrides, flattenHeaders, getTestId, isAudioResponse, isContentWithToolCallsResponse, isErrorResponse, isTextResponse, isToolCallResponse, resolveResponse, resolveStrictMode, strictOverrideField } from "./helpers.js";
|
|
1
|
+
import { buildContentWithToolCallsChunks, buildContentWithToolCallsCompletion, buildTextChunks, buildTextCompletion, buildToolCallChunks, buildToolCallCompletion, extractOverrides, flattenHeaders, getTestId, isAudioResponse, isContentWithToolCallsResponse, isErrorResponse, isTextResponse, isToolCallResponse, readBody, resolveResponse, resolveStrictMode, serializeErrorResponse, strictOverrideField } from "./helpers.js";
|
|
2
2
|
import { Logger } from "./logger.js";
|
|
3
3
|
import { Journal } from "./journal.js";
|
|
4
4
|
import { matchFixture } from "./router.js";
|
|
@@ -12,7 +12,7 @@ import { handleMessages } from "./messages.js";
|
|
|
12
12
|
import { handleGemini } from "./gemini.js";
|
|
13
13
|
import { handleBedrock, handleBedrockStream } from "./bedrock.js";
|
|
14
14
|
import { handleConverse, handleConverseStream } from "./bedrock-converse.js";
|
|
15
|
-
import { handleGeminiInteractions } from "./gemini-interactions.js";
|
|
15
|
+
import { handleGeminiInteractions, resetEventIdCounter, resetInteractionCounter } from "./gemini-interactions.js";
|
|
16
16
|
import { handleEmbeddings } from "./embeddings.js";
|
|
17
17
|
import { handleImages } from "./images.js";
|
|
18
18
|
import { handleSpeech } from "./speech.js";
|
|
@@ -111,21 +111,6 @@ const CORS_HEADERS = {
|
|
|
111
111
|
function setCorsHeaders(res) {
|
|
112
112
|
for (const [key, value] of Object.entries(CORS_HEADERS)) res.setHeader(key, value);
|
|
113
113
|
}
|
|
114
|
-
const DEFAULT_MAX_BODY_BYTES = 10 * 1024 * 1024;
|
|
115
|
-
async function readBody(req, maxBytes = DEFAULT_MAX_BODY_BYTES) {
|
|
116
|
-
const buffers = [];
|
|
117
|
-
let totalBytes = 0;
|
|
118
|
-
for await (const chunk of req) {
|
|
119
|
-
const buf = chunk;
|
|
120
|
-
totalBytes += buf.length;
|
|
121
|
-
if (totalBytes > maxBytes) {
|
|
122
|
-
req.destroy();
|
|
123
|
-
throw new Error(`Request body exceeded size limit of ${maxBytes} bytes`);
|
|
124
|
-
}
|
|
125
|
-
buffers.push(buf);
|
|
126
|
-
}
|
|
127
|
-
return Buffer.concat(buffers).toString();
|
|
128
|
-
}
|
|
129
114
|
function handleOptions(res) {
|
|
130
115
|
setCorsHeaders(res);
|
|
131
116
|
res.writeHead(204);
|
|
@@ -212,6 +197,8 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
|
|
|
212
197
|
videoStates.clear();
|
|
213
198
|
falJobs.clear();
|
|
214
199
|
falQueueStates.clear();
|
|
200
|
+
resetInteractionCounter();
|
|
201
|
+
resetEventIdCounter();
|
|
215
202
|
if (defaults.registry) defaults.registry.setGauge("aimock_fixtures_loaded", {}, fixtures.length);
|
|
216
203
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
217
204
|
res.end(JSON.stringify({ reset: true }));
|
|
@@ -369,6 +356,29 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
369
356
|
return;
|
|
370
357
|
}
|
|
371
358
|
if (!fixture) {
|
|
359
|
+
if (resolveStrictMode(defaults.strict, req.headers)) {
|
|
360
|
+
const strictStatus = 503;
|
|
361
|
+
const strictMessage = "Strict mode: no fixture matched";
|
|
362
|
+
defaults.logger.error(`STRICT: No fixture matched for ${req.method ?? "POST"} ${req.url ?? COMPLETIONS_PATH}`);
|
|
363
|
+
journal.add({
|
|
364
|
+
method: req.method ?? "POST",
|
|
365
|
+
path: req.url ?? COMPLETIONS_PATH,
|
|
366
|
+
headers: flattenHeaders(req.headers),
|
|
367
|
+
body,
|
|
368
|
+
response: {
|
|
369
|
+
status: strictStatus,
|
|
370
|
+
fixture: null,
|
|
371
|
+
...strictOverrideField(defaults.strict, req.headers)
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
writeErrorResponse(res, strictStatus, JSON.stringify({ error: {
|
|
375
|
+
message: strictMessage,
|
|
376
|
+
type: "invalid_request_error",
|
|
377
|
+
param: null,
|
|
378
|
+
code: "no_fixture_match"
|
|
379
|
+
} }));
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
372
382
|
if (defaults.record && providerKey) {
|
|
373
383
|
const hookOptions = chaosAction === "malformed" ? {
|
|
374
384
|
beforeWriteResponse: () => {
|
|
@@ -386,7 +396,7 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
386
396
|
} : void 0;
|
|
387
397
|
const outcome = await proxyAndRecord(req, res, body, providerKey, req.url ?? COMPLETIONS_PATH, fixtures, defaults, raw, hookOptions);
|
|
388
398
|
if (outcome === "handled_by_hook") return;
|
|
389
|
-
if (outcome
|
|
399
|
+
if (outcome !== "not_configured") {
|
|
390
400
|
journal.add({
|
|
391
401
|
method: req.method ?? "POST",
|
|
392
402
|
path: req.url ?? COMPLETIONS_PATH,
|
|
@@ -401,23 +411,19 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
401
411
|
return;
|
|
402
412
|
}
|
|
403
413
|
}
|
|
404
|
-
const effectiveStrict = resolveStrictMode(defaults.strict, req.headers);
|
|
405
|
-
const strictStatus = effectiveStrict ? 503 : 404;
|
|
406
|
-
const strictMessage = effectiveStrict ? "Strict mode: no fixture matched" : "No fixture matched";
|
|
407
|
-
if (effectiveStrict) defaults.logger.error(`STRICT: No fixture matched for ${req.method ?? "POST"} ${req.url ?? COMPLETIONS_PATH}`);
|
|
408
414
|
journal.add({
|
|
409
415
|
method: req.method ?? "POST",
|
|
410
416
|
path: req.url ?? COMPLETIONS_PATH,
|
|
411
417
|
headers: flattenHeaders(req.headers),
|
|
412
418
|
body,
|
|
413
419
|
response: {
|
|
414
|
-
status:
|
|
420
|
+
status: 404,
|
|
415
421
|
fixture: null,
|
|
416
422
|
...strictOverrideField(defaults.strict, req.headers)
|
|
417
423
|
}
|
|
418
424
|
});
|
|
419
|
-
writeErrorResponse(res,
|
|
420
|
-
message:
|
|
425
|
+
writeErrorResponse(res, 404, JSON.stringify({ error: {
|
|
426
|
+
message: "No fixture matched",
|
|
421
427
|
type: "invalid_request_error",
|
|
422
428
|
param: null,
|
|
423
429
|
code: "no_fixture_match"
|
|
@@ -439,13 +445,7 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
439
445
|
fixture
|
|
440
446
|
}
|
|
441
447
|
});
|
|
442
|
-
|
|
443
|
-
message: response.error.message,
|
|
444
|
-
type: response.error.type ?? "server_error",
|
|
445
|
-
param: null,
|
|
446
|
-
code: response.error.code ?? null
|
|
447
|
-
} };
|
|
448
|
-
writeErrorResponse(res, status, JSON.stringify(errorBody));
|
|
448
|
+
writeErrorResponse(res, status, serializeErrorResponse(response));
|
|
449
449
|
return;
|
|
450
450
|
}
|
|
451
451
|
if (isAudioResponse(response)) {
|
|
@@ -534,6 +534,7 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
534
534
|
return;
|
|
535
535
|
}
|
|
536
536
|
if (isToolCallResponse(response)) {
|
|
537
|
+
if (response.webSearches?.length) defaults.logger.warn("webSearches in fixture response are not supported for Chat Completions API — ignoring");
|
|
537
538
|
const overrides = extractOverrides(response);
|
|
538
539
|
const journalEntry = journal.add({
|
|
539
540
|
method: req.method ?? "POST",
|
|
@@ -1130,35 +1131,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1130
1131
|
if (pathname === ELEVENLABS_SOUND_GENERATION_PATH && req.method === "POST") {
|
|
1131
1132
|
setCorsHeaders(res);
|
|
1132
1133
|
try {
|
|
1133
|
-
|
|
1134
|
-
let elSoundFixture = null;
|
|
1135
|
-
try {
|
|
1136
|
-
const parsed = JSON.parse(raw);
|
|
1137
|
-
const syntheticReq = {
|
|
1138
|
-
model: parsed.model_id ?? "eleven_text_to_sound_v2",
|
|
1139
|
-
messages: [{
|
|
1140
|
-
role: "user",
|
|
1141
|
-
content: parsed.text ?? ""
|
|
1142
|
-
}],
|
|
1143
|
-
_endpointType: "audio-gen"
|
|
1144
|
-
};
|
|
1145
|
-
const testId = getTestId(req);
|
|
1146
|
-
elSoundFixture = matchFixture(fixtures, syntheticReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
1147
|
-
} catch {}
|
|
1148
|
-
const chaosAction = evaluateChaos(elSoundFixture, defaults.chaos, req.headers, defaults.logger);
|
|
1149
|
-
if (chaosAction) {
|
|
1150
|
-
applyChaosAction(chaosAction, res, elSoundFixture, journal, {
|
|
1151
|
-
method: req.method ?? "POST",
|
|
1152
|
-
path: pathname,
|
|
1153
|
-
headers: flattenHeaders(req.headers),
|
|
1154
|
-
body: {
|
|
1155
|
-
model: "",
|
|
1156
|
-
messages: []
|
|
1157
|
-
}
|
|
1158
|
-
}, "fixture", defaults.registry);
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
await handleElevenLabsAudio(req, res, raw, fixtures, defaults, journal, "sound-generation");
|
|
1134
|
+
await handleElevenLabsAudio(req, res, await readBody(req), fixtures, defaults, journal, "sound-generation");
|
|
1162
1135
|
} catch (err) {
|
|
1163
1136
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1164
1137
|
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1174,36 +1147,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1174
1147
|
setCorsHeaders(res);
|
|
1175
1148
|
const musicSubType = musicMatch[1] ?? "music";
|
|
1176
1149
|
try {
|
|
1177
|
-
|
|
1178
|
-
let elMusicFixture = null;
|
|
1179
|
-
try {
|
|
1180
|
-
const parsed = JSON.parse(raw);
|
|
1181
|
-
const prompt = (typeof parsed.prompt === "string" ? parsed.prompt : null) ?? (parsed.composition_plan != null ? typeof parsed.composition_plan === "string" ? parsed.composition_plan : JSON.stringify(parsed.composition_plan) : "");
|
|
1182
|
-
const syntheticReq = {
|
|
1183
|
-
model: parsed.model_id ?? "music_v1",
|
|
1184
|
-
messages: [{
|
|
1185
|
-
role: "user",
|
|
1186
|
-
content: prompt
|
|
1187
|
-
}],
|
|
1188
|
-
_endpointType: "audio-gen"
|
|
1189
|
-
};
|
|
1190
|
-
const testId = getTestId(req);
|
|
1191
|
-
elMusicFixture = matchFixture(fixtures, syntheticReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
1192
|
-
} catch {}
|
|
1193
|
-
const chaosAction = evaluateChaos(elMusicFixture, defaults.chaos, req.headers, defaults.logger);
|
|
1194
|
-
if (chaosAction) {
|
|
1195
|
-
applyChaosAction(chaosAction, res, elMusicFixture, journal, {
|
|
1196
|
-
method: req.method ?? "POST",
|
|
1197
|
-
path: pathname,
|
|
1198
|
-
headers: flattenHeaders(req.headers),
|
|
1199
|
-
body: {
|
|
1200
|
-
model: "",
|
|
1201
|
-
messages: []
|
|
1202
|
-
}
|
|
1203
|
-
}, "fixture", defaults.registry);
|
|
1204
|
-
return;
|
|
1205
|
-
}
|
|
1206
|
-
await handleElevenLabsAudio(req, res, raw, fixtures, defaults, journal, musicSubType);
|
|
1150
|
+
await handleElevenLabsAudio(req, res, await readBody(req), fixtures, defaults, journal, musicSubType);
|
|
1207
1151
|
} catch (err) {
|
|
1208
1152
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1209
1153
|
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1244,40 +1188,10 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1244
1188
|
return;
|
|
1245
1189
|
}
|
|
1246
1190
|
}
|
|
1247
|
-
|
|
1248
|
-
if (falQueueSubmitMatch && req.method === "POST") {
|
|
1191
|
+
if (pathname.match(FAL_QUEUE_SUBMIT_RE) && req.method === "POST") {
|
|
1249
1192
|
setCorsHeaders(res);
|
|
1250
1193
|
try {
|
|
1251
|
-
|
|
1252
|
-
let falSubmitFixture = null;
|
|
1253
|
-
try {
|
|
1254
|
-
const parsed = raw.trim() ? JSON.parse(raw) : {};
|
|
1255
|
-
const prompt = (typeof parsed.prompt === "string" ? parsed.prompt : null) ?? (typeof parsed.text === "string" ? parsed.text : null) ?? "";
|
|
1256
|
-
const syntheticReq = {
|
|
1257
|
-
model: falQueueSubmitMatch[1],
|
|
1258
|
-
messages: [{
|
|
1259
|
-
role: "user",
|
|
1260
|
-
content: prompt
|
|
1261
|
-
}],
|
|
1262
|
-
_endpointType: "fal-audio"
|
|
1263
|
-
};
|
|
1264
|
-
const testId = getTestId(req);
|
|
1265
|
-
falSubmitFixture = matchFixture(fixtures, syntheticReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
1266
|
-
} catch {}
|
|
1267
|
-
const chaosAction = evaluateChaos(falSubmitFixture, defaults.chaos, req.headers, defaults.logger);
|
|
1268
|
-
if (chaosAction) {
|
|
1269
|
-
applyChaosAction(chaosAction, res, falSubmitFixture, journal, {
|
|
1270
|
-
method: req.method ?? "POST",
|
|
1271
|
-
path: pathname,
|
|
1272
|
-
headers: flattenHeaders(req.headers),
|
|
1273
|
-
body: {
|
|
1274
|
-
model: "",
|
|
1275
|
-
messages: []
|
|
1276
|
-
}
|
|
1277
|
-
}, "fixture", defaults.registry);
|
|
1278
|
-
return;
|
|
1279
|
-
}
|
|
1280
|
-
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1194
|
+
await handleFalQueue(req, res, falBody ?? await readBody(req), pathname, fixtures, defaults, journal);
|
|
1281
1195
|
} catch (err) {
|
|
1282
1196
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1283
1197
|
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1316,40 +1230,10 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1316
1230
|
}
|
|
1317
1231
|
return;
|
|
1318
1232
|
}
|
|
1319
|
-
|
|
1320
|
-
if (falRunMatch && req.method === "POST") {
|
|
1233
|
+
if (pathname.match(FAL_RUN_RE) && req.method === "POST") {
|
|
1321
1234
|
setCorsHeaders(res);
|
|
1322
1235
|
try {
|
|
1323
|
-
|
|
1324
|
-
let falRunFixture = null;
|
|
1325
|
-
try {
|
|
1326
|
-
const parsed = raw.trim() ? JSON.parse(raw) : {};
|
|
1327
|
-
const prompt = (typeof parsed.prompt === "string" ? parsed.prompt : null) ?? (typeof parsed.text === "string" ? parsed.text : null) ?? "";
|
|
1328
|
-
const syntheticReq = {
|
|
1329
|
-
model: falRunMatch[1],
|
|
1330
|
-
messages: [{
|
|
1331
|
-
role: "user",
|
|
1332
|
-
content: prompt
|
|
1333
|
-
}],
|
|
1334
|
-
_endpointType: "fal-audio"
|
|
1335
|
-
};
|
|
1336
|
-
const testId = getTestId(req);
|
|
1337
|
-
falRunFixture = matchFixture(fixtures, syntheticReq, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
1338
|
-
} catch {}
|
|
1339
|
-
const chaosAction = evaluateChaos(falRunFixture, defaults.chaos, req.headers, defaults.logger);
|
|
1340
|
-
if (chaosAction) {
|
|
1341
|
-
applyChaosAction(chaosAction, res, falRunFixture, journal, {
|
|
1342
|
-
method: req.method ?? "POST",
|
|
1343
|
-
path: pathname,
|
|
1344
|
-
headers: flattenHeaders(req.headers),
|
|
1345
|
-
body: {
|
|
1346
|
-
model: "",
|
|
1347
|
-
messages: []
|
|
1348
|
-
}
|
|
1349
|
-
}, "fixture", defaults.registry);
|
|
1350
|
-
return;
|
|
1351
|
-
}
|
|
1352
|
-
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1236
|
+
await handleFalQueue(req, res, falBody ?? await readBody(req), pathname, fixtures, defaults, journal);
|
|
1353
1237
|
} catch (err) {
|
|
1354
1238
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1355
1239
|
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1437,7 +1321,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1437
1321
|
upgradeHeaders: req.headers
|
|
1438
1322
|
});
|
|
1439
1323
|
else if (pathname === REALTIME_PATH) {
|
|
1440
|
-
const model = parsedUrl.searchParams.get("model") ?? "gpt-
|
|
1324
|
+
const model = parsedUrl.searchParams.get("model") ?? "gpt-realtime-2";
|
|
1441
1325
|
handleWebSocketRealtime(ws, fixtures, journal, {
|
|
1442
1326
|
...defaults,
|
|
1443
1327
|
model,
|