@copilotkit/aimock 1.24.1 → 1.26.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 +38 -0
- package/README.md +21 -11
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/aws-event-stream.cjs +2 -1
- package/dist/aws-event-stream.cjs.map +1 -1
- package/dist/aws-event-stream.d.cts +3 -1
- package/dist/aws-event-stream.d.cts.map +1 -1
- package/dist/aws-event-stream.d.ts +3 -1
- package/dist/aws-event-stream.d.ts.map +1 -1
- package/dist/aws-event-stream.js +2 -1
- package/dist/aws-event-stream.js.map +1 -1
- package/dist/bedrock-converse.cjs +8 -2
- 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 +8 -2
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +8 -2
- 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 +8 -2
- package/dist/bedrock.js.map +1 -1
- package/dist/cli.cjs +36 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +36 -1
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +206 -2
- 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 +207 -4
- package/dist/cohere.js.map +1 -1
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/elevenlabs-audio.cjs +173 -1
- 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 +173 -2
- package/dist/elevenlabs-audio.js.map +1 -1
- package/dist/embeddings.cjs +1 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.js +1 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/fal-audio.cjs +2 -4
- package/dist/fal-audio.cjs.map +1 -1
- package/dist/fal-audio.js +2 -4
- package/dist/fal-audio.js.map +1 -1
- package/dist/fal.cjs +2 -2
- 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 +2 -2
- package/dist/fal.js.map +1 -1
- 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 +16 -3
- package/dist/fixture-loader.js.map +1 -1
- package/dist/gemini-embeddings.cjs +166 -0
- package/dist/gemini-embeddings.cjs.map +1 -0
- package/dist/gemini-embeddings.js +166 -0
- package/dist/gemini-embeddings.js.map +1 -0
- package/dist/gemini-interactions.cjs +10 -2
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.d.cts.map +1 -1
- package/dist/gemini-interactions.d.ts.map +1 -1
- package/dist/gemini-interactions.js +10 -2
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +12 -2
- 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 +12 -2
- package/dist/gemini.js.map +1 -1
- package/dist/helpers.cjs +70 -33
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +9 -5
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.ts +9 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +68 -34
- package/dist/helpers.js.map +1 -1
- package/dist/images.cjs +295 -13
- package/dist/images.cjs.map +1 -1
- package/dist/images.d.cts +9 -1
- package/dist/images.d.cts.map +1 -1
- package/dist/images.d.ts +9 -1
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +294 -14
- package/dist/images.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/llmock.cjs +16 -1
- 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 +16 -1
- package/dist/llmock.js.map +1 -1
- package/dist/messages.cjs +9 -2
- 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 +9 -2
- package/dist/messages.js.map +1 -1
- package/dist/metrics.cjs +2 -0
- package/dist/metrics.cjs.map +1 -1
- package/dist/metrics.d.cts.map +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +2 -0
- package/dist/metrics.js.map +1 -1
- package/dist/ndjson-writer.cjs +2 -1
- package/dist/ndjson-writer.cjs.map +1 -1
- package/dist/ndjson-writer.d.cts +3 -2
- package/dist/ndjson-writer.d.cts.map +1 -1
- package/dist/ndjson-writer.d.ts +3 -2
- package/dist/ndjson-writer.d.ts.map +1 -1
- package/dist/ndjson-writer.js +2 -1
- package/dist/ndjson-writer.js.map +1 -1
- package/dist/ollama.cjs +197 -2
- 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 +198 -4
- package/dist/ollama.js.map +1 -1
- package/dist/recorder.cjs +49 -5
- 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 +49 -5
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +11 -2
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.d.cts.map +1 -1
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +11 -2
- package/dist/responses.js.map +1 -1
- package/dist/server.cjs +196 -49
- 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 +201 -54
- package/dist/server.js.map +1 -1
- package/dist/speech.cjs +1 -1
- package/dist/speech.cjs.map +1 -1
- package/dist/speech.js +1 -1
- package/dist/speech.js.map +1 -1
- package/dist/sse-writer.cjs +48 -10
- package/dist/sse-writer.cjs.map +1 -1
- package/dist/sse-writer.d.cts +12 -4
- package/dist/sse-writer.d.cts.map +1 -1
- package/dist/sse-writer.d.ts +12 -4
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/sse-writer.js +48 -10
- package/dist/sse-writer.js.map +1 -1
- package/dist/transcription.cjs +9 -6
- 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 +8 -7
- package/dist/transcription.js.map +1 -1
- package/dist/types.d.cts +45 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +45 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/video.cjs +1 -1
- package/dist/video.cjs.map +1 -1
- package/dist/video.d.cts.map +1 -1
- package/dist/video.d.ts.map +1 -1
- package/dist/video.js +1 -1
- package/dist/video.js.map +1 -1
- package/dist/ws-gemini-live.cjs +14 -4
- package/dist/ws-gemini-live.cjs.map +1 -1
- package/dist/ws-gemini-live.d.cts +1 -0
- package/dist/ws-gemini-live.d.cts.map +1 -1
- package/dist/ws-gemini-live.d.ts +1 -0
- package/dist/ws-gemini-live.d.ts.map +1 -1
- package/dist/ws-gemini-live.js +15 -5
- package/dist/ws-gemini-live.js.map +1 -1
- package/dist/ws-realtime.cjs +21 -4
- package/dist/ws-realtime.cjs.map +1 -1
- package/dist/ws-realtime.d.cts +1 -0
- package/dist/ws-realtime.d.cts.map +1 -1
- package/dist/ws-realtime.d.ts +1 -0
- package/dist/ws-realtime.d.ts.map +1 -1
- package/dist/ws-realtime.js +22 -5
- package/dist/ws-realtime.js.map +1 -1
- package/dist/ws-responses.cjs +8 -5
- package/dist/ws-responses.cjs.map +1 -1
- package/dist/ws-responses.d.cts +1 -0
- package/dist/ws-responses.d.cts.map +1 -1
- package/dist/ws-responses.d.ts +1 -0
- package/dist/ws-responses.d.ts.map +1 -1
- package/dist/ws-responses.js +9 -6
- package/dist/ws-responses.js.map +1 -1
- package/package.json +2 -2
package/dist/server.cjs
CHANGED
|
@@ -11,13 +11,14 @@ const require_recorder = require('./recorder.cjs');
|
|
|
11
11
|
const require_responses = require('./responses.cjs');
|
|
12
12
|
const require_messages = require('./messages.cjs');
|
|
13
13
|
const require_gemini = require('./gemini.cjs');
|
|
14
|
+
const require_gemini_embeddings = require('./gemini-embeddings.cjs');
|
|
14
15
|
const require_bedrock = require('./bedrock.cjs');
|
|
15
16
|
const require_bedrock_converse = require('./bedrock-converse.cjs');
|
|
16
17
|
const require_gemini_interactions = require('./gemini-interactions.cjs');
|
|
17
18
|
const require_embeddings = require('./embeddings.cjs');
|
|
19
|
+
const require_transcription = require('./transcription.cjs');
|
|
18
20
|
const require_images = require('./images.cjs');
|
|
19
21
|
const require_speech = require('./speech.cjs');
|
|
20
|
-
const require_transcription = require('./transcription.cjs');
|
|
21
22
|
const require_video = require('./video.cjs');
|
|
22
23
|
const require_elevenlabs_audio = require('./elevenlabs-audio.cjs');
|
|
23
24
|
const require_fal = require('./fal.cjs');
|
|
@@ -43,16 +44,21 @@ const GEMINI_LIVE_PATH = "/ws/google.ai.generativelanguage.v1beta.GenerativeServ
|
|
|
43
44
|
const MESSAGES_PATH = "/v1/messages";
|
|
44
45
|
const EMBEDDINGS_PATH = "/v1/embeddings";
|
|
45
46
|
const COHERE_CHAT_PATH = "/v2/chat";
|
|
47
|
+
const COHERE_EMBED_PATH = "/v2/embed";
|
|
46
48
|
const SEARCH_PATH = "/search";
|
|
47
49
|
const RERANK_PATH = "/v2/rerank";
|
|
48
50
|
const MODERATIONS_PATH = "/v1/moderations";
|
|
49
51
|
const IMAGES_PATH = "/v1/images/generations";
|
|
52
|
+
const IMAGES_EDIT_PATH = "/v1/images/edit";
|
|
53
|
+
const IMAGES_VARIATIONS_PATH = "/v1/images/variations";
|
|
50
54
|
const SPEECH_PATH = "/v1/audio/speech";
|
|
51
55
|
const TRANSCRIPTIONS_PATH = "/v1/audio/transcriptions";
|
|
56
|
+
const TRANSLATIONS_PATH = "/v1/audio/translations";
|
|
52
57
|
const VIDEOS_PATH = "/v1/videos";
|
|
53
58
|
const VIDEOS_STATUS_RE = /^\/v1\/videos\/([^/]+)$/;
|
|
54
59
|
const GEMINI_PREDICT_RE = /^\/v1beta\/models\/([^:]+):predict$/;
|
|
55
60
|
const ELEVENLABS_SOUND_GENERATION_PATH = "/v1/sound-generation";
|
|
61
|
+
const ELEVENLABS_TTS_RE = /^\/v1\/text-to-speech\/([^/]+)$/;
|
|
56
62
|
const ELEVENLABS_MUSIC_RE = /^\/v1\/music(?:\/(.+))?$/;
|
|
57
63
|
const FAL_QUEUE_SUBMIT_RE = /^\/fal\/queue\/submit\/(.+)$/;
|
|
58
64
|
const FAL_QUEUE_REQUESTS_RE = /^\/fal\/queue\/requests\/(.+)$/;
|
|
@@ -65,7 +71,10 @@ const COMPAT_SUFFIXES = [
|
|
|
65
71
|
"/responses",
|
|
66
72
|
"/audio/speech",
|
|
67
73
|
"/audio/transcriptions",
|
|
68
|
-
"/
|
|
74
|
+
"/audio/translations",
|
|
75
|
+
"/images/generations",
|
|
76
|
+
"/images/edit",
|
|
77
|
+
"/images/variations"
|
|
69
78
|
];
|
|
70
79
|
/**
|
|
71
80
|
* Normalize OpenAI-compatible paths with arbitrary prefixes.
|
|
@@ -85,6 +94,7 @@ function normalizeCompatPath(pathname, logger) {
|
|
|
85
94
|
}
|
|
86
95
|
const GEMINI_INTERACTIONS_PATH = "/v1beta/interactions";
|
|
87
96
|
const GEMINI_PATH_RE = /^\/v1beta\/models\/([^:]+):(generateContent|streamGenerateContent)$/;
|
|
97
|
+
const GEMINI_EMBED_RE = /^\/v1beta\/models\/([^:]+):embedContent$/;
|
|
88
98
|
const AZURE_DEPLOYMENT_RE = /^\/openai\/deployments\/([^/]+)\/(chat\/completions|embeddings)$/;
|
|
89
99
|
const BEDROCK_INVOKE_RE = /^\/model\/([^/]+)\/invoke$/;
|
|
90
100
|
const BEDROCK_STREAM_RE = /^\/model\/([^/]+)\/invoke-with-response-stream$/;
|
|
@@ -93,6 +103,7 @@ const BEDROCK_CONVERSE_STREAM_RE = /^\/model\/([^/]+)\/converse-stream$/;
|
|
|
93
103
|
const VERTEX_AI_RE = /^\/v1\/projects\/[^/]+\/locations\/[^/]+\/publishers\/google\/models\/([^/:]+):(generateContent|streamGenerateContent)$/;
|
|
94
104
|
const OLLAMA_CHAT_PATH = "/api/chat";
|
|
95
105
|
const OLLAMA_GENERATE_PATH = "/api/generate";
|
|
106
|
+
const OLLAMA_EMBEDDINGS_PATH = "/api/embeddings";
|
|
96
107
|
const OLLAMA_TAGS_PATH = "/api/tags";
|
|
97
108
|
const HEALTH_PATH = "/health";
|
|
98
109
|
const READY_PATH = "/ready";
|
|
@@ -170,7 +181,7 @@ async function handleControlAPI(req, res, pathname, fixtures, journal, videoStat
|
|
|
170
181
|
res.end(JSON.stringify({ error: "Missing or invalid \"fixtures\" array" }));
|
|
171
182
|
return true;
|
|
172
183
|
}
|
|
173
|
-
const converted = parsed.fixtures.map(require_fixture_loader.entryToFixture);
|
|
184
|
+
const converted = parsed.fixtures.map((e) => require_fixture_loader.entryToFixture(e));
|
|
174
185
|
const errors = require_fixture_loader.validateFixtures(converted).filter((i) => i.severity === "error");
|
|
175
186
|
if (errors.length > 0) {
|
|
176
187
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
@@ -435,6 +446,7 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
435
446
|
const response = await require_helpers.resolveResponse(fixture, body);
|
|
436
447
|
const latency = fixture.latency ?? defaults.latency;
|
|
437
448
|
const chunkSize = Math.max(1, fixture.chunkSize ?? defaults.chunkSize);
|
|
449
|
+
const includeUsage = body.stream === true && body.stream_options?.include_usage === true;
|
|
438
450
|
if (require_helpers.isErrorResponse(response)) {
|
|
439
451
|
const status = response.status ?? 500;
|
|
440
452
|
journal.add({
|
|
@@ -447,7 +459,7 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
447
459
|
fixture
|
|
448
460
|
}
|
|
449
461
|
});
|
|
450
|
-
require_sse_writer.writeErrorResponse(res, status, require_helpers.serializeErrorResponse(response));
|
|
462
|
+
require_sse_writer.writeErrorResponse(res, status, require_helpers.serializeErrorResponse(response), { retryAfter: response.retryAfter });
|
|
451
463
|
return;
|
|
452
464
|
}
|
|
453
465
|
if (require_helpers.isAudioResponse(response)) {
|
|
@@ -481,17 +493,30 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
481
493
|
}
|
|
482
494
|
});
|
|
483
495
|
if (body.stream !== true) {
|
|
484
|
-
const completion = require_helpers.buildContentWithToolCallsCompletion(response.content, response.toolCalls, body.model, response.reasoning, overrides);
|
|
496
|
+
const completion = require_helpers.buildContentWithToolCallsCompletion(response.content, response.toolCalls, body.model, response.reasoning, overrides, body.messages);
|
|
485
497
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
486
498
|
res.end(JSON.stringify(completion));
|
|
487
499
|
} else {
|
|
488
500
|
const chunks = require_helpers.buildContentWithToolCallsChunks(response.content, response.toolCalls, body.model, chunkSize, response.reasoning, overrides);
|
|
501
|
+
const completionText = response.content + response.toolCalls.map((tc) => tc.name + tc.arguments).join("");
|
|
502
|
+
const usageChunk = includeUsage ? require_helpers.buildUsageChunk(chunks[0]?.id ?? "chatcmpl-unknown", overrides?.model ?? body.model, chunks[0]?.created ?? Math.floor(Date.now() / 1e3), overrides?.usage ? {
|
|
503
|
+
prompt_tokens: overrides.usage.prompt_tokens ?? 0,
|
|
504
|
+
completion_tokens: overrides.usage.completion_tokens ?? 0,
|
|
505
|
+
total_tokens: overrides.usage.total_tokens ?? (overrides.usage.prompt_tokens ?? 0) + (overrides.usage.completion_tokens ?? 0)
|
|
506
|
+
} : {
|
|
507
|
+
prompt_tokens: require_helpers.estimatePromptTokens(body.messages),
|
|
508
|
+
completion_tokens: require_helpers.estimateTokens(completionText),
|
|
509
|
+
total_tokens: require_helpers.estimatePromptTokens(body.messages) + require_helpers.estimateTokens(completionText)
|
|
510
|
+
}, overrides?.systemFingerprint) : void 0;
|
|
489
511
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
490
512
|
if (!await require_sse_writer.writeSSEStream(res, chunks, {
|
|
491
513
|
latency,
|
|
492
514
|
streamingProfile: fixture.streamingProfile,
|
|
493
515
|
signal: interruption?.signal,
|
|
494
|
-
onChunkSent: interruption?.tick
|
|
516
|
+
onChunkSent: interruption?.tick,
|
|
517
|
+
usageChunk,
|
|
518
|
+
recordedTimings: fixture.recordedTimings,
|
|
519
|
+
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed
|
|
495
520
|
})) {
|
|
496
521
|
if (!res.writableEnded) res.destroy();
|
|
497
522
|
journalEntry.response.interrupted = true;
|
|
@@ -515,17 +540,29 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
515
540
|
}
|
|
516
541
|
});
|
|
517
542
|
if (body.stream !== true) {
|
|
518
|
-
const completion = require_helpers.buildTextCompletion(response.content, body.model, response.reasoning, overrides);
|
|
543
|
+
const completion = require_helpers.buildTextCompletion(response.content, body.model, response.reasoning, overrides, body.messages);
|
|
519
544
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
520
545
|
res.end(JSON.stringify(completion));
|
|
521
546
|
} else {
|
|
522
547
|
const chunks = require_helpers.buildTextChunks(response.content, body.model, chunkSize, response.reasoning, overrides);
|
|
548
|
+
const usageChunk = includeUsage ? require_helpers.buildUsageChunk(chunks[0]?.id ?? "chatcmpl-unknown", overrides?.model ?? body.model, chunks[0]?.created ?? Math.floor(Date.now() / 1e3), overrides?.usage ? {
|
|
549
|
+
prompt_tokens: overrides.usage.prompt_tokens ?? 0,
|
|
550
|
+
completion_tokens: overrides.usage.completion_tokens ?? 0,
|
|
551
|
+
total_tokens: overrides.usage.total_tokens ?? (overrides.usage.prompt_tokens ?? 0) + (overrides.usage.completion_tokens ?? 0)
|
|
552
|
+
} : {
|
|
553
|
+
prompt_tokens: require_helpers.estimatePromptTokens(body.messages),
|
|
554
|
+
completion_tokens: require_helpers.estimateTokens(response.content),
|
|
555
|
+
total_tokens: require_helpers.estimatePromptTokens(body.messages) + require_helpers.estimateTokens(response.content)
|
|
556
|
+
}, overrides?.systemFingerprint) : void 0;
|
|
523
557
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
524
558
|
if (!await require_sse_writer.writeSSEStream(res, chunks, {
|
|
525
559
|
latency,
|
|
526
560
|
streamingProfile: fixture.streamingProfile,
|
|
527
561
|
signal: interruption?.signal,
|
|
528
|
-
onChunkSent: interruption?.tick
|
|
562
|
+
onChunkSent: interruption?.tick,
|
|
563
|
+
usageChunk,
|
|
564
|
+
recordedTimings: fixture.recordedTimings,
|
|
565
|
+
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed
|
|
529
566
|
})) {
|
|
530
567
|
if (!res.writableEnded) res.destroy();
|
|
531
568
|
journalEntry.response.interrupted = true;
|
|
@@ -549,17 +586,30 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
549
586
|
}
|
|
550
587
|
});
|
|
551
588
|
if (body.stream !== true) {
|
|
552
|
-
const completion = require_helpers.buildToolCallCompletion(response.toolCalls, body.model, overrides);
|
|
589
|
+
const completion = require_helpers.buildToolCallCompletion(response.toolCalls, body.model, overrides, body.messages);
|
|
553
590
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
554
591
|
res.end(JSON.stringify(completion));
|
|
555
592
|
} else {
|
|
556
593
|
const chunks = require_helpers.buildToolCallChunks(response.toolCalls, body.model, chunkSize, overrides);
|
|
594
|
+
const completionText = response.toolCalls.map((tc) => tc.name + tc.arguments).join("");
|
|
595
|
+
const usageChunk = includeUsage ? require_helpers.buildUsageChunk(chunks[0]?.id ?? "chatcmpl-unknown", overrides?.model ?? body.model, chunks[0]?.created ?? Math.floor(Date.now() / 1e3), overrides?.usage ? {
|
|
596
|
+
prompt_tokens: overrides.usage.prompt_tokens ?? 0,
|
|
597
|
+
completion_tokens: overrides.usage.completion_tokens ?? 0,
|
|
598
|
+
total_tokens: overrides.usage.total_tokens ?? (overrides.usage.prompt_tokens ?? 0) + (overrides.usage.completion_tokens ?? 0)
|
|
599
|
+
} : {
|
|
600
|
+
prompt_tokens: require_helpers.estimatePromptTokens(body.messages),
|
|
601
|
+
completion_tokens: require_helpers.estimateTokens(completionText),
|
|
602
|
+
total_tokens: require_helpers.estimatePromptTokens(body.messages) + require_helpers.estimateTokens(completionText)
|
|
603
|
+
}, overrides?.systemFingerprint) : void 0;
|
|
557
604
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
558
605
|
if (!await require_sse_writer.writeSSEStream(res, chunks, {
|
|
559
606
|
latency,
|
|
560
607
|
streamingProfile: fixture.streamingProfile,
|
|
561
608
|
signal: interruption?.signal,
|
|
562
|
-
onChunkSent: interruption?.tick
|
|
609
|
+
onChunkSent: interruption?.tick,
|
|
610
|
+
usageChunk,
|
|
611
|
+
recordedTimings: fixture.recordedTimings,
|
|
612
|
+
replaySpeed: fixture.replaySpeed ?? defaults.replaySpeed
|
|
563
613
|
})) {
|
|
564
614
|
if (!res.writableEnded) res.destroy();
|
|
565
615
|
journalEntry.response.interrupted = true;
|
|
@@ -593,6 +643,7 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
593
643
|
const defaults = {
|
|
594
644
|
latency: serverOptions.latency ?? 0,
|
|
595
645
|
chunkSize: Math.max(1, serverOptions.chunkSize ?? DEFAULT_CHUNK_SIZE),
|
|
646
|
+
replaySpeed: serverOptions.replaySpeed ?? 1,
|
|
596
647
|
logger,
|
|
597
648
|
get chaos() {
|
|
598
649
|
return serverOptions.chaos;
|
|
@@ -688,6 +739,61 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
688
739
|
if (await handler.handleRequest(req, res, subPath)) return;
|
|
689
740
|
}
|
|
690
741
|
}
|
|
742
|
+
if (pathname === OLLAMA_CHAT_PATH && req.method === "POST") {
|
|
743
|
+
try {
|
|
744
|
+
await require_ollama.handleOllama(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
745
|
+
} catch (err) {
|
|
746
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
747
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
748
|
+
message: msg,
|
|
749
|
+
type: "server_error"
|
|
750
|
+
} }));
|
|
751
|
+
else if (!res.writableEnded) res.destroy();
|
|
752
|
+
}
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (pathname === OLLAMA_GENERATE_PATH && req.method === "POST") {
|
|
756
|
+
try {
|
|
757
|
+
await require_ollama.handleOllamaGenerate(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
758
|
+
} catch (err) {
|
|
759
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
760
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
761
|
+
message: msg,
|
|
762
|
+
type: "server_error"
|
|
763
|
+
} }));
|
|
764
|
+
else if (!res.writableEnded) res.destroy();
|
|
765
|
+
}
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
if (pathname === OLLAMA_EMBEDDINGS_PATH && req.method === "POST") {
|
|
769
|
+
try {
|
|
770
|
+
await require_ollama.handleOllamaEmbeddings(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
771
|
+
} catch (err) {
|
|
772
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
773
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
774
|
+
message: msg,
|
|
775
|
+
type: "server_error"
|
|
776
|
+
} }));
|
|
777
|
+
else if (!res.writableEnded) res.destroy();
|
|
778
|
+
}
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
if (pathname === OLLAMA_TAGS_PATH && req.method === "GET") {
|
|
782
|
+
setCorsHeaders(res);
|
|
783
|
+
const modelIds = /* @__PURE__ */ new Set();
|
|
784
|
+
for (const f of fixtures) if (f.match.model && typeof f.match.model === "string") modelIds.add(f.match.model);
|
|
785
|
+
const models = (modelIds.size > 0 ? [...modelIds] : DEFAULT_MODELS).map((name) => ({
|
|
786
|
+
name,
|
|
787
|
+
model: name,
|
|
788
|
+
modified_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
789
|
+
size: 0,
|
|
790
|
+
digest: "",
|
|
791
|
+
details: {}
|
|
792
|
+
}));
|
|
793
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
794
|
+
res.end(JSON.stringify({ models }));
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
691
797
|
let azureDeploymentId;
|
|
692
798
|
const azureMatch = pathname.match(AZURE_DEPLOYMENT_RE);
|
|
693
799
|
if (azureMatch && req.method === "POST") {
|
|
@@ -834,6 +940,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
834
940
|
}
|
|
835
941
|
return;
|
|
836
942
|
}
|
|
943
|
+
if (pathname === COHERE_EMBED_PATH && req.method === "POST") {
|
|
944
|
+
try {
|
|
945
|
+
await require_cohere.handleCohereEmbed(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
946
|
+
} catch (err) {
|
|
947
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
948
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
949
|
+
message: msg,
|
|
950
|
+
type: "server_error"
|
|
951
|
+
} }));
|
|
952
|
+
else if (!res.writableEnded) res.destroy();
|
|
953
|
+
}
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
837
956
|
if (pathname === EMBEDDINGS_PATH && req.method === "POST") {
|
|
838
957
|
try {
|
|
839
958
|
const deploymentId = azureDeploymentId;
|
|
@@ -872,6 +991,32 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
872
991
|
}
|
|
873
992
|
return;
|
|
874
993
|
}
|
|
994
|
+
if (pathname === IMAGES_EDIT_PATH && req.method === "POST") {
|
|
995
|
+
try {
|
|
996
|
+
await require_images.handleImageEdit(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
997
|
+
} catch (err) {
|
|
998
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
999
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1000
|
+
message: msg,
|
|
1001
|
+
type: "server_error"
|
|
1002
|
+
} }));
|
|
1003
|
+
else if (!res.writableEnded) res.destroy();
|
|
1004
|
+
}
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
if (pathname === IMAGES_VARIATIONS_PATH && req.method === "POST") {
|
|
1008
|
+
try {
|
|
1009
|
+
await require_images.handleImageVariations(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
1010
|
+
} catch (err) {
|
|
1011
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1012
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1013
|
+
message: msg,
|
|
1014
|
+
type: "server_error"
|
|
1015
|
+
} }));
|
|
1016
|
+
else if (!res.writableEnded) res.destroy();
|
|
1017
|
+
}
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
875
1020
|
if (pathname === SPEECH_PATH && req.method === "POST") {
|
|
876
1021
|
try {
|
|
877
1022
|
await require_speech.handleSpeech(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
@@ -898,6 +1043,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
898
1043
|
}
|
|
899
1044
|
return;
|
|
900
1045
|
}
|
|
1046
|
+
if (pathname === TRANSLATIONS_PATH && req.method === "POST") {
|
|
1047
|
+
try {
|
|
1048
|
+
await require_transcription.handleTranscription(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders, "translation");
|
|
1049
|
+
} catch (err) {
|
|
1050
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1051
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1052
|
+
message: msg,
|
|
1053
|
+
type: "server_error"
|
|
1054
|
+
} }));
|
|
1055
|
+
else if (!res.writableEnded) res.destroy();
|
|
1056
|
+
}
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
901
1059
|
if (pathname === VIDEOS_PATH && req.method === "POST") {
|
|
902
1060
|
try {
|
|
903
1061
|
await require_video.handleVideoCreate(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders, videoStates);
|
|
@@ -950,6 +1108,21 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
950
1108
|
}
|
|
951
1109
|
return;
|
|
952
1110
|
}
|
|
1111
|
+
const geminiEmbedMatch = pathname.match(GEMINI_EMBED_RE);
|
|
1112
|
+
if (geminiEmbedMatch && req.method === "POST") {
|
|
1113
|
+
const embedModel = geminiEmbedMatch[1];
|
|
1114
|
+
try {
|
|
1115
|
+
await require_gemini_embeddings.handleGeminiEmbedContent(req, res, await require_helpers.readBody(req), embedModel, fixtures, journal, defaults, setCorsHeaders);
|
|
1116
|
+
} catch (err) {
|
|
1117
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1118
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1119
|
+
message: msg,
|
|
1120
|
+
type: "server_error"
|
|
1121
|
+
} }));
|
|
1122
|
+
else if (!res.writableEnded) res.destroy();
|
|
1123
|
+
}
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
953
1126
|
const geminiMatch = pathname.match(GEMINI_PATH_RE);
|
|
954
1127
|
if (geminiMatch && req.method === "POST") {
|
|
955
1128
|
const geminiModel = geminiMatch[1];
|
|
@@ -1052,22 +1225,9 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1052
1225
|
}
|
|
1053
1226
|
return;
|
|
1054
1227
|
}
|
|
1055
|
-
if (pathname ===
|
|
1056
|
-
try {
|
|
1057
|
-
await require_ollama.handleOllama(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
1058
|
-
} catch (err) {
|
|
1059
|
-
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1060
|
-
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1061
|
-
message: msg,
|
|
1062
|
-
type: "server_error"
|
|
1063
|
-
} }));
|
|
1064
|
-
else if (!res.writableEnded) res.destroy();
|
|
1065
|
-
}
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
if (pathname === OLLAMA_GENERATE_PATH && req.method === "POST") {
|
|
1228
|
+
if (pathname === SEARCH_PATH && req.method === "POST") {
|
|
1069
1229
|
try {
|
|
1070
|
-
await
|
|
1230
|
+
await require_search.handleSearch(req, res, await require_helpers.readBody(req), serviceFixtures?.search ?? [], journal, defaults, setCorsHeaders);
|
|
1071
1231
|
} catch (err) {
|
|
1072
1232
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1073
1233
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1078,25 +1238,9 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1078
1238
|
}
|
|
1079
1239
|
return;
|
|
1080
1240
|
}
|
|
1081
|
-
if (pathname ===
|
|
1082
|
-
setCorsHeaders(res);
|
|
1083
|
-
const modelIds = /* @__PURE__ */ new Set();
|
|
1084
|
-
for (const f of fixtures) if (f.match.model && typeof f.match.model === "string") modelIds.add(f.match.model);
|
|
1085
|
-
const models = (modelIds.size > 0 ? [...modelIds] : DEFAULT_MODELS).map((name) => ({
|
|
1086
|
-
name,
|
|
1087
|
-
model: name,
|
|
1088
|
-
modified_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1089
|
-
size: 0,
|
|
1090
|
-
digest: "",
|
|
1091
|
-
details: {}
|
|
1092
|
-
}));
|
|
1093
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
1094
|
-
res.end(JSON.stringify({ models }));
|
|
1095
|
-
return;
|
|
1096
|
-
}
|
|
1097
|
-
if (pathname === SEARCH_PATH && req.method === "POST") {
|
|
1241
|
+
if (pathname === RERANK_PATH && req.method === "POST") {
|
|
1098
1242
|
try {
|
|
1099
|
-
await
|
|
1243
|
+
await require_rerank.handleRerank(req, res, await require_helpers.readBody(req), serviceFixtures?.rerank ?? [], journal, defaults, setCorsHeaders);
|
|
1100
1244
|
} catch (err) {
|
|
1101
1245
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1102
1246
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1107,9 +1251,9 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1107
1251
|
}
|
|
1108
1252
|
return;
|
|
1109
1253
|
}
|
|
1110
|
-
if (pathname ===
|
|
1254
|
+
if (pathname === MODERATIONS_PATH && req.method === "POST") {
|
|
1111
1255
|
try {
|
|
1112
|
-
await
|
|
1256
|
+
await require_moderation.handleModeration(req, res, await require_helpers.readBody(req), serviceFixtures?.moderation ?? [], journal, defaults, setCorsHeaders);
|
|
1113
1257
|
} catch (err) {
|
|
1114
1258
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1115
1259
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1120,9 +1264,10 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1120
1264
|
}
|
|
1121
1265
|
return;
|
|
1122
1266
|
}
|
|
1123
|
-
if (pathname ===
|
|
1267
|
+
if (pathname === ELEVENLABS_SOUND_GENERATION_PATH && req.method === "POST") {
|
|
1268
|
+
setCorsHeaders(res);
|
|
1124
1269
|
try {
|
|
1125
|
-
await
|
|
1270
|
+
await require_elevenlabs_audio.handleElevenLabsAudio(req, res, await require_helpers.readBody(req), fixtures, defaults, journal, "sound-generation");
|
|
1126
1271
|
} catch (err) {
|
|
1127
1272
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1128
1273
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1133,10 +1278,12 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1133
1278
|
}
|
|
1134
1279
|
return;
|
|
1135
1280
|
}
|
|
1136
|
-
|
|
1281
|
+
const elevenLabsTTSMatch = pathname.match(ELEVENLABS_TTS_RE);
|
|
1282
|
+
if (elevenLabsTTSMatch && req.method === "POST") {
|
|
1137
1283
|
setCorsHeaders(res);
|
|
1284
|
+
const voiceId = elevenLabsTTSMatch[1];
|
|
1138
1285
|
try {
|
|
1139
|
-
await require_elevenlabs_audio.
|
|
1286
|
+
await require_elevenlabs_audio.handleElevenLabsTTS(req, res, await require_helpers.readBody(req), fixtures, defaults, journal, voiceId);
|
|
1140
1287
|
} catch (err) {
|
|
1141
1288
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1142
1289
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|