@copilotkit/aimock 1.16.4 → 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 +35 -0
- package/README.md +10 -10
- package/dist/a2a-mock.d.cts +2 -2
- package/dist/a2a-mock.d.cts.map +1 -1
- package/dist/a2a-mock.d.ts +2 -2
- package/dist/a2a-mock.d.ts.map +1 -1
- package/dist/a2a-mock.js +2 -2
- package/dist/a2a-mock.js.map +1 -1
- package/dist/agui-handler.cjs +120 -5
- package/dist/agui-handler.cjs.map +1 -1
- package/dist/agui-handler.d.cts +41 -5
- package/dist/agui-handler.d.cts.map +1 -1
- package/dist/agui-handler.d.ts +41 -5
- package/dist/agui-handler.d.ts.map +1 -1
- package/dist/agui-handler.js +114 -6
- package/dist/agui-handler.js.map +1 -1
- package/dist/agui-mock.cjs +18 -7
- package/dist/agui-mock.cjs.map +1 -1
- package/dist/agui-mock.d.cts +2 -2
- package/dist/agui-mock.d.cts.map +1 -1
- package/dist/agui-mock.d.ts +2 -2
- package/dist/agui-mock.d.ts.map +1 -1
- package/dist/agui-mock.js +20 -9
- package/dist/agui-mock.js.map +1 -1
- package/dist/agui-recorder.cjs +43 -22
- package/dist/agui-recorder.cjs.map +1 -1
- package/dist/agui-recorder.d.cts +4 -3
- package/dist/agui-recorder.d.cts.map +1 -1
- package/dist/agui-recorder.d.ts +4 -3
- package/dist/agui-recorder.d.ts.map +1 -1
- package/dist/agui-recorder.js +45 -24
- package/dist/agui-recorder.js.map +1 -1
- package/dist/agui-stub.cjs +28 -0
- package/dist/agui-stub.d.cts +5 -0
- package/dist/agui-stub.d.ts +5 -0
- package/dist/agui-stub.js +5 -0
- package/dist/agui-types.d.cts +33 -6
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/agui-types.d.ts +33 -6
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/aimock-cli.cjs +1 -1
- package/dist/aimock-cli.js +1 -1
- package/dist/aws-event-stream.d.cts +2 -2
- package/dist/aws-event-stream.d.cts.map +1 -1
- package/dist/aws-event-stream.d.ts +2 -2
- package/dist/aws-event-stream.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 +3 -3
- package/dist/bedrock-converse.d.cts.map +1 -1
- package/dist/bedrock-converse.d.ts +3 -3
- 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 +3 -3
- package/dist/bedrock.d.cts.map +1 -1
- package/dist/bedrock.d.ts +3 -3
- 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 +19 -4
- package/dist/chaos.d.cts.map +1 -1
- package/dist/chaos.d.ts +19 -4
- package/dist/chaos.d.ts.map +1 -1
- package/dist/chaos.js +35 -10
- package/dist/chaos.js.map +1 -1
- package/dist/cli.cjs +6 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +6 -5
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +2 -2
- package/dist/cohere.cjs.map +1 -1
- package/dist/cohere.d.cts +2 -2
- package/dist/cohere.d.cts.map +1 -1
- package/dist/cohere.d.ts +2 -2
- package/dist/cohere.d.ts.map +1 -1
- package/dist/cohere.js +2 -2
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.cjs +3 -3
- package/dist/config-loader.d.cts +1 -1
- package/dist/config-loader.d.cts.map +1 -1
- package/dist/config-loader.d.ts +1 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +2 -2
- package/dist/convert-vidaimock.cjs +1 -1
- package/dist/convert-vidaimock.js +1 -1
- package/dist/convert.cjs +1 -1
- package/dist/convert.js +1 -1
- package/dist/elevenlabs-audio.cjs +212 -0
- package/dist/elevenlabs-audio.cjs.map +1 -0
- package/dist/elevenlabs-audio.d.cts +11 -0
- package/dist/elevenlabs-audio.d.cts.map +1 -0
- package/dist/elevenlabs-audio.d.ts +11 -0
- package/dist/elevenlabs-audio.d.ts.map +1 -0
- package/dist/elevenlabs-audio.js +212 -0
- package/dist/elevenlabs-audio.js.map +1 -0
- package/dist/embeddings.cjs +2 -2
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +2 -2
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +2 -2
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +2 -2
- package/dist/embeddings.js.map +1 -1
- package/dist/fal-audio.cjs +484 -0
- package/dist/fal-audio.cjs.map +1 -0
- package/dist/fal-audio.d.cts +10 -0
- package/dist/fal-audio.d.cts.map +1 -0
- package/dist/fal-audio.d.ts +10 -0
- package/dist/fal-audio.d.ts.map +1 -0
- package/dist/fal-audio.js +480 -0
- package/dist/fal-audio.js.map +1 -0
- 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 +16 -3
- 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 +17 -4
- package/dist/fixture-loader.js.map +1 -1
- package/dist/fixtures-remote.cjs +1 -1
- package/dist/fixtures-remote.js +1 -1
- package/dist/gemini-interactions.cjs +619 -0
- package/dist/gemini-interactions.cjs.map +1 -0
- package/dist/gemini-interactions.d.cts +46 -0
- package/dist/gemini-interactions.d.cts.map +1 -0
- package/dist/gemini-interactions.d.ts +46 -0
- package/dist/gemini-interactions.d.ts.map +1 -0
- package/dist/gemini-interactions.js +618 -0
- package/dist/gemini-interactions.js.map +1 -0
- package/dist/gemini.cjs +78 -2
- package/dist/gemini.cjs.map +1 -1
- package/dist/gemini.d.cts +2 -2
- package/dist/gemini.d.cts.map +1 -1
- package/dist/gemini.d.ts +2 -2
- package/dist/gemini.d.ts.map +1 -1
- package/dist/gemini.js +79 -3
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +28 -1
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +13 -3
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +13 -3
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +26 -2
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +2 -2
- package/dist/images.cjs.map +1 -1
- package/dist/images.d.cts +2 -2
- package/dist/images.d.cts.map +1 -1
- package/dist/images.d.ts +2 -2
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +2 -2
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +24 -4
- package/dist/index.d.cts +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +11 -7
- package/dist/jest.cjs +1 -1
- package/dist/jest.js +1 -1
- package/dist/jsonrpc.d.cts +3 -3
- package/dist/jsonrpc.d.cts.map +1 -1
- package/dist/jsonrpc.d.ts +3 -3
- package/dist/jsonrpc.d.ts.map +1 -1
- package/dist/llmock.cjs +53 -2
- package/dist/llmock.cjs.map +1 -1
- package/dist/llmock.d.cts +6 -0
- package/dist/llmock.d.cts.map +1 -1
- package/dist/llmock.d.ts +6 -0
- package/dist/llmock.d.ts.map +1 -1
- package/dist/llmock.js +53 -2
- package/dist/llmock.js.map +1 -1
- package/dist/logger.cjs +5 -4
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.cts.map +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +5 -4
- package/dist/logger.js.map +1 -1
- package/dist/mcp-mock.d.cts +2 -2
- package/dist/mcp-mock.d.cts.map +1 -1
- package/dist/mcp-mock.d.ts +2 -2
- package/dist/mcp-mock.d.ts.map +1 -1
- package/dist/mcp-mock.js +2 -2
- package/dist/mcp-mock.js.map +1 -1
- package/dist/messages.cjs +2 -2
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.d.cts +2 -2
- package/dist/messages.d.cts.map +1 -1
- package/dist/messages.d.ts +2 -2
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +2 -2
- package/dist/messages.js.map +1 -1
- package/dist/moderation.d.cts +3 -3
- package/dist/moderation.d.cts.map +1 -1
- package/dist/moderation.d.ts +3 -3
- package/dist/moderation.d.ts.map +1 -1
- package/dist/ndjson-writer.d.cts +2 -2
- package/dist/ndjson-writer.d.cts.map +1 -1
- package/dist/ndjson-writer.d.ts +2 -2
- package/dist/ndjson-writer.d.ts.map +1 -1
- package/dist/ollama.cjs +4 -4
- package/dist/ollama.cjs.map +1 -1
- package/dist/ollama.d.cts +3 -3
- package/dist/ollama.d.cts.map +1 -1
- package/dist/ollama.d.ts +3 -3
- 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 +106 -38
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.d.cts +52 -7
- package/dist/recorder.d.cts.map +1 -1
- package/dist/recorder.d.ts +52 -7
- package/dist/recorder.d.ts.map +1 -1
- package/dist/recorder.js +108 -40
- package/dist/recorder.js.map +1 -1
- package/dist/rerank.d.cts +3 -3
- package/dist/rerank.d.cts.map +1 -1
- package/dist/rerank.d.ts +3 -3
- package/dist/rerank.d.ts.map +1 -1
- package/dist/responses.cjs +2 -2
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts +2 -2
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts +2 -2
- package/dist/responses.d.ts.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/search.d.cts +3 -3
- package/dist/search.d.cts.map +1 -1
- package/dist/search.d.ts +3 -3
- package/dist/search.d.ts.map +1 -1
- package/dist/server.cjs +253 -8
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +2 -2
- package/dist/server.d.cts.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +257 -12
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +20 -11
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.d.cts +2 -2
- package/dist/speech.d.cts.map +1 -1
- package/dist/speech.d.ts +2 -2
- package/dist/speech.d.ts.map +1 -1
- package/dist/speech.js +20 -11
- package/dist/speech.js.map +1 -1
- package/dist/sse-writer.d.cts +3 -3
- package/dist/sse-writer.d.cts.map +1 -1
- package/dist/sse-writer.d.ts +3 -3
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/stream-collapse.cjs +80 -9
- package/dist/stream-collapse.cjs.map +1 -1
- package/dist/stream-collapse.d.cts +11 -1
- package/dist/stream-collapse.d.cts.map +1 -1
- package/dist/stream-collapse.d.ts +11 -1
- package/dist/stream-collapse.d.ts.map +1 -1
- package/dist/stream-collapse.js +80 -10
- package/dist/stream-collapse.js.map +1 -1
- package/dist/suite.cjs +1 -1
- package/dist/suite.d.cts +2 -2
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +1 -1
- package/dist/transcription.cjs +2 -2
- package/dist/transcription.cjs.map +1 -1
- package/dist/transcription.d.cts +2 -2
- package/dist/transcription.d.cts.map +1 -1
- package/dist/transcription.d.ts +2 -2
- package/dist/transcription.d.ts.map +1 -1
- package/dist/transcription.js +2 -2
- package/dist/transcription.js.map +1 -1
- package/dist/types.d.cts +38 -11
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +38 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-mock.d.cts +2 -2
- package/dist/vector-mock.d.cts.map +1 -1
- package/dist/vector-mock.d.ts +2 -2
- package/dist/vector-mock.d.ts.map +1 -1
- package/dist/vector-mock.js +2 -2
- package/dist/vector-mock.js.map +1 -1
- package/dist/vector-types.d.cts.map +1 -1
- package/dist/vector-types.d.ts.map +1 -1
- package/dist/video.cjs +9 -3
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts +3 -3
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts +3 -3
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +9 -3
- package/dist/video.js.map +1 -1
- package/dist/vitest.cjs +1 -1
- package/dist/vitest.js +1 -1
- package/dist/ws-framing.d.cts +2 -2
- package/dist/ws-framing.d.cts.map +1 -1
- package/dist/ws-framing.d.ts +2 -2
- package/dist/ws-framing.d.ts.map +1 -1
- package/dist/ws-gemini-live.cjs +145 -2
- package/dist/ws-gemini-live.cjs.map +1 -1
- 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 +146 -3
- package/dist/ws-gemini-live.js.map +1 -1
- package/package.json +16 -2
- package/skills/write-fixtures/SKILL.md +10 -10
package/dist/server.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import { buildContentWithToolCallsChunks, buildContentWithToolCallsCompletion, buildTextChunks, buildTextCompletion, buildToolCallChunks, buildToolCallCompletion, extractOverrides, flattenHeaders, getTestId, isContentWithToolCallsResponse, isErrorResponse, isTextResponse, isToolCallResponse } from "./helpers.js";
|
|
1
|
+
import { buildContentWithToolCallsChunks, buildContentWithToolCallsCompletion, buildTextChunks, buildTextCompletion, buildToolCallChunks, buildToolCallCompletion, extractOverrides, flattenHeaders, getTestId, isAudioResponse, isContentWithToolCallsResponse, isErrorResponse, isTextResponse, isToolCallResponse } from "./helpers.js";
|
|
2
|
+
import { Logger } from "./logger.js";
|
|
2
3
|
import { Journal } from "./journal.js";
|
|
3
4
|
import { matchFixture } from "./router.js";
|
|
4
5
|
import { entryToFixture, validateFixtures } from "./fixture-loader.js";
|
|
5
6
|
import { writeErrorResponse, writeSSEStream } from "./sse-writer.js";
|
|
6
7
|
import { createInterruptionSignal } from "./interruption.js";
|
|
7
|
-
import {
|
|
8
|
+
import { applyChaosAction, evaluateChaos } from "./chaos.js";
|
|
8
9
|
import { proxyAndRecord } from "./recorder.js";
|
|
9
10
|
import { handleResponses } from "./responses.js";
|
|
10
11
|
import { handleMessages } from "./messages.js";
|
|
11
12
|
import { handleGemini } from "./gemini.js";
|
|
12
13
|
import { handleBedrock, handleBedrockStream } from "./bedrock.js";
|
|
13
14
|
import { handleConverse, handleConverseStream } from "./bedrock-converse.js";
|
|
15
|
+
import { handleGeminiInteractions } from "./gemini-interactions.js";
|
|
14
16
|
import { handleEmbeddings } from "./embeddings.js";
|
|
15
17
|
import { handleImages } from "./images.js";
|
|
16
18
|
import { handleSpeech } from "./speech.js";
|
|
17
19
|
import { handleTranscription } from "./transcription.js";
|
|
18
20
|
import { VideoStateMap, handleVideoCreate, handleVideoStatus } from "./video.js";
|
|
21
|
+
import { handleElevenLabsAudio } from "./elevenlabs-audio.js";
|
|
22
|
+
import { falJobs, handleFalQueue } from "./fal-audio.js";
|
|
23
|
+
import { falQueueStates, handleFal } from "./fal.js";
|
|
19
24
|
import { handleOllama, handleOllamaGenerate } from "./ollama.js";
|
|
20
25
|
import { handleCohere } from "./cohere.js";
|
|
21
26
|
import { handleSearch } from "./search.js";
|
|
@@ -25,9 +30,8 @@ import { upgradeToWebSocket } from "./ws-framing.js";
|
|
|
25
30
|
import { handleWebSocketResponses } from "./ws-responses.js";
|
|
26
31
|
import { handleWebSocketRealtime } from "./ws-realtime.js";
|
|
27
32
|
import { handleWebSocketGeminiLive } from "./ws-gemini-live.js";
|
|
28
|
-
import { Logger } from "./logger.js";
|
|
29
33
|
import { createMetricsRegistry, normalizePathLabel } from "./metrics.js";
|
|
30
|
-
import * as http from "node:http";
|
|
34
|
+
import * as http$1 from "node:http";
|
|
31
35
|
|
|
32
36
|
//#region src/server.ts
|
|
33
37
|
const COMPLETIONS_PATH = "/v1/chat/completions";
|
|
@@ -46,6 +50,12 @@ const TRANSCRIPTIONS_PATH = "/v1/audio/transcriptions";
|
|
|
46
50
|
const VIDEOS_PATH = "/v1/videos";
|
|
47
51
|
const VIDEOS_STATUS_RE = /^\/v1\/videos\/([^/]+)$/;
|
|
48
52
|
const GEMINI_PREDICT_RE = /^\/v1beta\/models\/([^:]+):predict$/;
|
|
53
|
+
const ELEVENLABS_SOUND_GENERATION_PATH = "/v1/sound-generation";
|
|
54
|
+
const ELEVENLABS_MUSIC_RE = /^\/v1\/music(?:\/(.+))?$/;
|
|
55
|
+
const FAL_QUEUE_SUBMIT_RE = /^\/fal\/queue\/submit\/(.+)$/;
|
|
56
|
+
const FAL_QUEUE_REQUESTS_RE = /^\/fal\/queue\/requests\/(.+)$/;
|
|
57
|
+
const FAL_RUN_RE = /^\/fal\/run\/(.+)$/;
|
|
58
|
+
const FAL_PREFIX_RE = /^\/fal(?:\/.*)?$/;
|
|
49
59
|
const DEFAULT_CHUNK_SIZE = 20;
|
|
50
60
|
const COMPAT_SUFFIXES = [
|
|
51
61
|
"/chat/completions",
|
|
@@ -71,6 +81,7 @@ function normalizeCompatPath(pathname, logger) {
|
|
|
71
81
|
}
|
|
72
82
|
return pathname;
|
|
73
83
|
}
|
|
84
|
+
const GEMINI_INTERACTIONS_PATH = "/v1beta/interactions";
|
|
74
85
|
const GEMINI_PATH_RE = /^\/v1beta\/models\/([^:]+):(generateContent|streamGenerateContent)$/;
|
|
75
86
|
const AZURE_DEPLOYMENT_RE = /^\/openai\/deployments\/([^/]+)\/(chat\/completions|embeddings)$/;
|
|
76
87
|
const BEDROCK_INVOKE_RE = /^\/model\/([^/]+)\/invoke$/;
|
|
@@ -199,6 +210,8 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
|
|
|
199
210
|
fixtures.length = 0;
|
|
200
211
|
journal.clear();
|
|
201
212
|
videoStates.clear();
|
|
213
|
+
falJobs.clear();
|
|
214
|
+
falQueueStates.clear();
|
|
202
215
|
if (defaults.registry) defaults.registry.setGauge("aimock_fixtures_loaded", {}, fixtures.length);
|
|
203
216
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
204
217
|
res.end(JSON.stringify({ reset: true }));
|
|
@@ -317,6 +330,9 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
317
330
|
} }));
|
|
318
331
|
return;
|
|
319
332
|
}
|
|
333
|
+
const method = req.method ?? "POST";
|
|
334
|
+
const path = req.url ?? COMPLETIONS_PATH;
|
|
335
|
+
const flatHeaders = flattenHeaders(req.headers);
|
|
320
336
|
body._endpointType = "chat";
|
|
321
337
|
const testId = getTestId(req);
|
|
322
338
|
const fixture = matchFixture(fixtures, body, journal.getFixtureMatchCountsForTest(testId), defaults.requestTransform);
|
|
@@ -328,18 +344,40 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
328
344
|
const snippet = typeof lastUserMsg?.content === "string" ? lastUserMsg.content.slice(0, 80) : "";
|
|
329
345
|
defaults.logger.debug(`No fixture matched for request (model=${body.model ?? "?"}, msg="${snippet}")`);
|
|
330
346
|
}
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
const flatHeaders = flattenHeaders(req.headers);
|
|
334
|
-
if (applyChaos(res, fixture, defaults.chaos, req.headers, journal, {
|
|
347
|
+
const chaosAction = evaluateChaos(fixture, defaults.chaos, req.headers, defaults.logger);
|
|
348
|
+
const chaosContext = {
|
|
335
349
|
method,
|
|
336
350
|
path,
|
|
337
351
|
headers: flatHeaders,
|
|
338
352
|
body
|
|
339
|
-
}
|
|
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
|
+
}
|
|
340
362
|
if (!fixture) {
|
|
341
363
|
if (defaults.record && providerKey) {
|
|
342
|
-
|
|
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") {
|
|
343
381
|
journal.add({
|
|
344
382
|
method: req.method ?? "POST",
|
|
345
383
|
path: req.url ?? COMPLETIONS_PATH,
|
|
@@ -392,6 +430,23 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
392
430
|
writeErrorResponse(res, status, JSON.stringify(response));
|
|
393
431
|
return;
|
|
394
432
|
}
|
|
433
|
+
if (isAudioResponse(response)) {
|
|
434
|
+
journal.add({
|
|
435
|
+
method: req.method ?? "POST",
|
|
436
|
+
path: req.url ?? COMPLETIONS_PATH,
|
|
437
|
+
headers: flattenHeaders(req.headers),
|
|
438
|
+
body,
|
|
439
|
+
response: {
|
|
440
|
+
status: 422,
|
|
441
|
+
fixture
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
writeErrorResponse(res, 422, JSON.stringify({ error: {
|
|
445
|
+
message: "Audio responses are not supported on the chat completions endpoint. Use Gemini generateContent or a dedicated audio endpoint.",
|
|
446
|
+
type: "invalid_request_error"
|
|
447
|
+
} }));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
395
450
|
if (isContentWithToolCallsResponse(response)) {
|
|
396
451
|
if (response.webSearches?.length) defaults.logger.warn("webSearches in fixture response are not supported for Chat Completions API — ignoring");
|
|
397
452
|
const overrides = extractOverrides(response);
|
|
@@ -559,7 +614,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
559
614
|
if (registry && handler.setRegistry) handler.setRegistry(registry);
|
|
560
615
|
}
|
|
561
616
|
if (registry) registry.setGauge("aimock_fixtures_loaded", {}, fixtures.length);
|
|
562
|
-
const server = http.createServer((req, res) => {
|
|
617
|
+
const server = http$1.createServer((req, res) => {
|
|
563
618
|
handleHttpRequest(req, res).catch((err) => {
|
|
564
619
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
565
620
|
defaults.logger.warn(`Unhandled request error: ${msg}`);
|
|
@@ -839,7 +894,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
839
894
|
const videoStatusMatch = pathname.match(VIDEOS_STATUS_RE);
|
|
840
895
|
if (videoStatusMatch && req.method === "GET") {
|
|
841
896
|
const videoId = videoStatusMatch[1];
|
|
842
|
-
handleVideoStatus(req, res, videoId, journal, setCorsHeaders, videoStates);
|
|
897
|
+
handleVideoStatus(req, res, videoId, journal, defaults, setCorsHeaders, videoStates);
|
|
843
898
|
return;
|
|
844
899
|
}
|
|
845
900
|
const geminiPredictMatch = pathname.match(GEMINI_PREDICT_RE);
|
|
@@ -857,6 +912,26 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
857
912
|
}
|
|
858
913
|
return;
|
|
859
914
|
}
|
|
915
|
+
if (pathname === GEMINI_INTERACTIONS_PATH && req.method === "POST") {
|
|
916
|
+
try {
|
|
917
|
+
await handleGeminiInteractions(req, res, await readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
918
|
+
} catch (err) {
|
|
919
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
920
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
921
|
+
message: msg,
|
|
922
|
+
type: "server_error"
|
|
923
|
+
} }));
|
|
924
|
+
else if (!res.writableEnded) {
|
|
925
|
+
try {
|
|
926
|
+
res.write(`data: ${JSON.stringify({ error: { message: msg } })}\n\n`);
|
|
927
|
+
} catch (writeErr) {
|
|
928
|
+
logger.debug("Failed to write error recovery response:", writeErr);
|
|
929
|
+
}
|
|
930
|
+
res.end();
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
860
935
|
const geminiMatch = pathname.match(GEMINI_PATH_RE);
|
|
861
936
|
if (geminiMatch && req.method === "POST") {
|
|
862
937
|
const geminiModel = geminiMatch[1];
|
|
@@ -1044,6 +1119,176 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1044
1119
|
}
|
|
1045
1120
|
return;
|
|
1046
1121
|
}
|
|
1122
|
+
if (pathname === ELEVENLABS_SOUND_GENERATION_PATH && req.method === "POST") {
|
|
1123
|
+
setCorsHeaders(res);
|
|
1124
|
+
try {
|
|
1125
|
+
const raw = await readBody(req);
|
|
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
|
+
}
|
|
1139
|
+
await handleElevenLabsAudio(req, res, raw, fixtures, defaults, journal, "sound-generation");
|
|
1140
|
+
} catch (err) {
|
|
1141
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1142
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1143
|
+
message: msg,
|
|
1144
|
+
type: "server_error"
|
|
1145
|
+
} }));
|
|
1146
|
+
else if (!res.writableEnded) res.destroy();
|
|
1147
|
+
}
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
const musicMatch = pathname.match(ELEVENLABS_MUSIC_RE);
|
|
1151
|
+
if (musicMatch && req.method === "POST") {
|
|
1152
|
+
setCorsHeaders(res);
|
|
1153
|
+
const musicSubType = musicMatch[1] ?? "music";
|
|
1154
|
+
try {
|
|
1155
|
+
const raw = await readBody(req);
|
|
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
|
+
}
|
|
1169
|
+
await handleElevenLabsAudio(req, res, raw, fixtures, defaults, journal, musicSubType);
|
|
1170
|
+
} catch (err) {
|
|
1171
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1172
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1173
|
+
message: msg,
|
|
1174
|
+
type: "server_error"
|
|
1175
|
+
} }));
|
|
1176
|
+
else if (!res.writableEnded) res.destroy();
|
|
1177
|
+
}
|
|
1178
|
+
return;
|
|
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
|
+
}
|
|
1208
|
+
if (pathname.match(FAL_QUEUE_SUBMIT_RE) && req.method === "POST") {
|
|
1209
|
+
setCorsHeaders(res);
|
|
1210
|
+
try {
|
|
1211
|
+
const raw = await readBody(req);
|
|
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
|
+
}
|
|
1225
|
+
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1226
|
+
} catch (err) {
|
|
1227
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1228
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1229
|
+
message: msg,
|
|
1230
|
+
type: "server_error"
|
|
1231
|
+
} }));
|
|
1232
|
+
else if (!res.writableEnded) res.destroy();
|
|
1233
|
+
}
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
if (pathname.match(FAL_QUEUE_REQUESTS_RE) && (req.method === "GET" || req.method === "POST" || req.method === "PUT")) {
|
|
1237
|
+
setCorsHeaders(res);
|
|
1238
|
+
try {
|
|
1239
|
+
const raw = req.method === "POST" ? await readBody(req) : "{}";
|
|
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
|
+
}
|
|
1253
|
+
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1254
|
+
} catch (err) {
|
|
1255
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1256
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1257
|
+
message: msg,
|
|
1258
|
+
type: "server_error"
|
|
1259
|
+
} }));
|
|
1260
|
+
else if (!res.writableEnded) res.destroy();
|
|
1261
|
+
}
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
if (pathname.match(FAL_RUN_RE) && req.method === "POST") {
|
|
1265
|
+
setCorsHeaders(res);
|
|
1266
|
+
try {
|
|
1267
|
+
const raw = await readBody(req);
|
|
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
|
+
}
|
|
1281
|
+
await handleFalQueue(req, res, raw, pathname, fixtures, defaults, journal);
|
|
1282
|
+
} catch (err) {
|
|
1283
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1284
|
+
if (!res.headersSent) writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1285
|
+
message: msg,
|
|
1286
|
+
type: "server_error"
|
|
1287
|
+
} }));
|
|
1288
|
+
else if (!res.writableEnded) res.destroy();
|
|
1289
|
+
}
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1047
1292
|
if (pathname !== COMPLETIONS_PATH) {
|
|
1048
1293
|
handleNotFound(res, "Not found");
|
|
1049
1294
|
return;
|