@copilotkit/aimock 1.24.0 → 1.25.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 +17 -11
- package/dist/agui-types.d.cts.map +1 -1
- package/dist/agui-types.d.ts.map +1 -1
- package/dist/bedrock-converse.cjs +2 -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 +2 -2
- package/dist/bedrock-converse.js.map +1 -1
- package/dist/bedrock.cjs +2 -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 +2 -2
- package/dist/bedrock.js.map +1 -1
- package/dist/cli.cjs +25 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +25 -1
- package/dist/cli.js.map +1 -1
- package/dist/cohere.cjs +198 -1
- 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 +199 -3
- package/dist/cohere.js.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/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 +1 -1
- package/dist/gemini-interactions.cjs.map +1 -1
- package/dist/gemini-interactions.js +1 -1
- package/dist/gemini-interactions.js.map +1 -1
- package/dist/gemini.cjs +5 -3
- 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 +5 -3
- 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 +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 +1 -1
- package/dist/messages.cjs.map +1 -1
- package/dist/messages.js +1 -1
- 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/ollama.cjs +189 -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 +190 -4
- package/dist/ollama.js.map +1 -1
- package/dist/recorder.cjs +11 -4
- package/dist/recorder.cjs.map +1 -1
- package/dist/recorder.js +11 -4
- package/dist/recorder.js.map +1 -1
- package/dist/responses.cjs +1 -1
- package/dist/responses.cjs.map +1 -1
- package/dist/responses.js +1 -1
- package/dist/responses.js.map +1 -1
- package/dist/server.cjs +188 -48
- 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 +193 -53
- 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 +20 -2
- package/dist/sse-writer.cjs.map +1 -1
- package/dist/sse-writer.d.cts +8 -2
- package/dist/sse-writer.d.cts.map +1 -1
- package/dist/sse-writer.d.ts +8 -2
- package/dist/sse-writer.d.ts.map +1 -1
- package/dist/sse-writer.js +20 -2
- 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 +28 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +28 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-types.d.cts.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.d.ts +2 -2
- package/dist/ws-realtime.d.ts +2 -2
- 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";
|
|
@@ -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,28 @@ 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
|
|
495
518
|
})) {
|
|
496
519
|
if (!res.writableEnded) res.destroy();
|
|
497
520
|
journalEntry.response.interrupted = true;
|
|
@@ -515,17 +538,27 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
515
538
|
}
|
|
516
539
|
});
|
|
517
540
|
if (body.stream !== true) {
|
|
518
|
-
const completion = require_helpers.buildTextCompletion(response.content, body.model, response.reasoning, overrides);
|
|
541
|
+
const completion = require_helpers.buildTextCompletion(response.content, body.model, response.reasoning, overrides, body.messages);
|
|
519
542
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
520
543
|
res.end(JSON.stringify(completion));
|
|
521
544
|
} else {
|
|
522
545
|
const chunks = require_helpers.buildTextChunks(response.content, body.model, chunkSize, response.reasoning, overrides);
|
|
546
|
+
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 ? {
|
|
547
|
+
prompt_tokens: overrides.usage.prompt_tokens ?? 0,
|
|
548
|
+
completion_tokens: overrides.usage.completion_tokens ?? 0,
|
|
549
|
+
total_tokens: overrides.usage.total_tokens ?? (overrides.usage.prompt_tokens ?? 0) + (overrides.usage.completion_tokens ?? 0)
|
|
550
|
+
} : {
|
|
551
|
+
prompt_tokens: require_helpers.estimatePromptTokens(body.messages),
|
|
552
|
+
completion_tokens: require_helpers.estimateTokens(response.content),
|
|
553
|
+
total_tokens: require_helpers.estimatePromptTokens(body.messages) + require_helpers.estimateTokens(response.content)
|
|
554
|
+
}, overrides?.systemFingerprint) : void 0;
|
|
523
555
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
524
556
|
if (!await require_sse_writer.writeSSEStream(res, chunks, {
|
|
525
557
|
latency,
|
|
526
558
|
streamingProfile: fixture.streamingProfile,
|
|
527
559
|
signal: interruption?.signal,
|
|
528
|
-
onChunkSent: interruption?.tick
|
|
560
|
+
onChunkSent: interruption?.tick,
|
|
561
|
+
usageChunk
|
|
529
562
|
})) {
|
|
530
563
|
if (!res.writableEnded) res.destroy();
|
|
531
564
|
journalEntry.response.interrupted = true;
|
|
@@ -549,17 +582,28 @@ async function handleCompletions(req, res, fixtures, journal, defaults, modelFal
|
|
|
549
582
|
}
|
|
550
583
|
});
|
|
551
584
|
if (body.stream !== true) {
|
|
552
|
-
const completion = require_helpers.buildToolCallCompletion(response.toolCalls, body.model, overrides);
|
|
585
|
+
const completion = require_helpers.buildToolCallCompletion(response.toolCalls, body.model, overrides, body.messages);
|
|
553
586
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
554
587
|
res.end(JSON.stringify(completion));
|
|
555
588
|
} else {
|
|
556
589
|
const chunks = require_helpers.buildToolCallChunks(response.toolCalls, body.model, chunkSize, overrides);
|
|
590
|
+
const completionText = response.toolCalls.map((tc) => tc.name + tc.arguments).join("");
|
|
591
|
+
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 ? {
|
|
592
|
+
prompt_tokens: overrides.usage.prompt_tokens ?? 0,
|
|
593
|
+
completion_tokens: overrides.usage.completion_tokens ?? 0,
|
|
594
|
+
total_tokens: overrides.usage.total_tokens ?? (overrides.usage.prompt_tokens ?? 0) + (overrides.usage.completion_tokens ?? 0)
|
|
595
|
+
} : {
|
|
596
|
+
prompt_tokens: require_helpers.estimatePromptTokens(body.messages),
|
|
597
|
+
completion_tokens: require_helpers.estimateTokens(completionText),
|
|
598
|
+
total_tokens: require_helpers.estimatePromptTokens(body.messages) + require_helpers.estimateTokens(completionText)
|
|
599
|
+
}, overrides?.systemFingerprint) : void 0;
|
|
557
600
|
const interruption = require_interruption.createInterruptionSignal(fixture);
|
|
558
601
|
if (!await require_sse_writer.writeSSEStream(res, chunks, {
|
|
559
602
|
latency,
|
|
560
603
|
streamingProfile: fixture.streamingProfile,
|
|
561
604
|
signal: interruption?.signal,
|
|
562
|
-
onChunkSent: interruption?.tick
|
|
605
|
+
onChunkSent: interruption?.tick,
|
|
606
|
+
usageChunk
|
|
563
607
|
})) {
|
|
564
608
|
if (!res.writableEnded) res.destroy();
|
|
565
609
|
journalEntry.response.interrupted = true;
|
|
@@ -688,6 +732,61 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
688
732
|
if (await handler.handleRequest(req, res, subPath)) return;
|
|
689
733
|
}
|
|
690
734
|
}
|
|
735
|
+
if (pathname === OLLAMA_CHAT_PATH && req.method === "POST") {
|
|
736
|
+
try {
|
|
737
|
+
await require_ollama.handleOllama(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
738
|
+
} catch (err) {
|
|
739
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
740
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
741
|
+
message: msg,
|
|
742
|
+
type: "server_error"
|
|
743
|
+
} }));
|
|
744
|
+
else if (!res.writableEnded) res.destroy();
|
|
745
|
+
}
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
if (pathname === OLLAMA_GENERATE_PATH && req.method === "POST") {
|
|
749
|
+
try {
|
|
750
|
+
await require_ollama.handleOllamaGenerate(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
751
|
+
} catch (err) {
|
|
752
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
753
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
754
|
+
message: msg,
|
|
755
|
+
type: "server_error"
|
|
756
|
+
} }));
|
|
757
|
+
else if (!res.writableEnded) res.destroy();
|
|
758
|
+
}
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (pathname === OLLAMA_EMBEDDINGS_PATH && req.method === "POST") {
|
|
762
|
+
try {
|
|
763
|
+
await require_ollama.handleOllamaEmbeddings(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
764
|
+
} catch (err) {
|
|
765
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
766
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
767
|
+
message: msg,
|
|
768
|
+
type: "server_error"
|
|
769
|
+
} }));
|
|
770
|
+
else if (!res.writableEnded) res.destroy();
|
|
771
|
+
}
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
if (pathname === OLLAMA_TAGS_PATH && req.method === "GET") {
|
|
775
|
+
setCorsHeaders(res);
|
|
776
|
+
const modelIds = /* @__PURE__ */ new Set();
|
|
777
|
+
for (const f of fixtures) if (f.match.model && typeof f.match.model === "string") modelIds.add(f.match.model);
|
|
778
|
+
const models = (modelIds.size > 0 ? [...modelIds] : DEFAULT_MODELS).map((name) => ({
|
|
779
|
+
name,
|
|
780
|
+
model: name,
|
|
781
|
+
modified_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
782
|
+
size: 0,
|
|
783
|
+
digest: "",
|
|
784
|
+
details: {}
|
|
785
|
+
}));
|
|
786
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
787
|
+
res.end(JSON.stringify({ models }));
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
691
790
|
let azureDeploymentId;
|
|
692
791
|
const azureMatch = pathname.match(AZURE_DEPLOYMENT_RE);
|
|
693
792
|
if (azureMatch && req.method === "POST") {
|
|
@@ -834,6 +933,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
834
933
|
}
|
|
835
934
|
return;
|
|
836
935
|
}
|
|
936
|
+
if (pathname === COHERE_EMBED_PATH && req.method === "POST") {
|
|
937
|
+
try {
|
|
938
|
+
await require_cohere.handleCohereEmbed(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
939
|
+
} catch (err) {
|
|
940
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
941
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
942
|
+
message: msg,
|
|
943
|
+
type: "server_error"
|
|
944
|
+
} }));
|
|
945
|
+
else if (!res.writableEnded) res.destroy();
|
|
946
|
+
}
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
837
949
|
if (pathname === EMBEDDINGS_PATH && req.method === "POST") {
|
|
838
950
|
try {
|
|
839
951
|
const deploymentId = azureDeploymentId;
|
|
@@ -872,6 +984,32 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
872
984
|
}
|
|
873
985
|
return;
|
|
874
986
|
}
|
|
987
|
+
if (pathname === IMAGES_EDIT_PATH && req.method === "POST") {
|
|
988
|
+
try {
|
|
989
|
+
await require_images.handleImageEdit(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
990
|
+
} catch (err) {
|
|
991
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
992
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
993
|
+
message: msg,
|
|
994
|
+
type: "server_error"
|
|
995
|
+
} }));
|
|
996
|
+
else if (!res.writableEnded) res.destroy();
|
|
997
|
+
}
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (pathname === IMAGES_VARIATIONS_PATH && req.method === "POST") {
|
|
1001
|
+
try {
|
|
1002
|
+
await require_images.handleImageVariations(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
1003
|
+
} catch (err) {
|
|
1004
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1005
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1006
|
+
message: msg,
|
|
1007
|
+
type: "server_error"
|
|
1008
|
+
} }));
|
|
1009
|
+
else if (!res.writableEnded) res.destroy();
|
|
1010
|
+
}
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
875
1013
|
if (pathname === SPEECH_PATH && req.method === "POST") {
|
|
876
1014
|
try {
|
|
877
1015
|
await require_speech.handleSpeech(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders);
|
|
@@ -898,6 +1036,19 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
898
1036
|
}
|
|
899
1037
|
return;
|
|
900
1038
|
}
|
|
1039
|
+
if (pathname === TRANSLATIONS_PATH && req.method === "POST") {
|
|
1040
|
+
try {
|
|
1041
|
+
await require_transcription.handleTranscription(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders, "translation");
|
|
1042
|
+
} catch (err) {
|
|
1043
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1044
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1045
|
+
message: msg,
|
|
1046
|
+
type: "server_error"
|
|
1047
|
+
} }));
|
|
1048
|
+
else if (!res.writableEnded) res.destroy();
|
|
1049
|
+
}
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
901
1052
|
if (pathname === VIDEOS_PATH && req.method === "POST") {
|
|
902
1053
|
try {
|
|
903
1054
|
await require_video.handleVideoCreate(req, res, await require_helpers.readBody(req), fixtures, journal, defaults, setCorsHeaders, videoStates);
|
|
@@ -950,6 +1101,21 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
950
1101
|
}
|
|
951
1102
|
return;
|
|
952
1103
|
}
|
|
1104
|
+
const geminiEmbedMatch = pathname.match(GEMINI_EMBED_RE);
|
|
1105
|
+
if (geminiEmbedMatch && req.method === "POST") {
|
|
1106
|
+
const embedModel = geminiEmbedMatch[1];
|
|
1107
|
+
try {
|
|
1108
|
+
await require_gemini_embeddings.handleGeminiEmbedContent(req, res, await require_helpers.readBody(req), embedModel, fixtures, journal, defaults, setCorsHeaders);
|
|
1109
|
+
} catch (err) {
|
|
1110
|
+
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1111
|
+
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
1112
|
+
message: msg,
|
|
1113
|
+
type: "server_error"
|
|
1114
|
+
} }));
|
|
1115
|
+
else if (!res.writableEnded) res.destroy();
|
|
1116
|
+
}
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
953
1119
|
const geminiMatch = pathname.match(GEMINI_PATH_RE);
|
|
954
1120
|
if (geminiMatch && req.method === "POST") {
|
|
955
1121
|
const geminiModel = geminiMatch[1];
|
|
@@ -1052,22 +1218,9 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1052
1218
|
}
|
|
1053
1219
|
return;
|
|
1054
1220
|
}
|
|
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") {
|
|
1221
|
+
if (pathname === SEARCH_PATH && req.method === "POST") {
|
|
1069
1222
|
try {
|
|
1070
|
-
await
|
|
1223
|
+
await require_search.handleSearch(req, res, await require_helpers.readBody(req), serviceFixtures?.search ?? [], journal, defaults, setCorsHeaders);
|
|
1071
1224
|
} catch (err) {
|
|
1072
1225
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1073
1226
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1078,25 +1231,9 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1078
1231
|
}
|
|
1079
1232
|
return;
|
|
1080
1233
|
}
|
|
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") {
|
|
1234
|
+
if (pathname === RERANK_PATH && req.method === "POST") {
|
|
1098
1235
|
try {
|
|
1099
|
-
await
|
|
1236
|
+
await require_rerank.handleRerank(req, res, await require_helpers.readBody(req), serviceFixtures?.rerank ?? [], journal, defaults, setCorsHeaders);
|
|
1100
1237
|
} catch (err) {
|
|
1101
1238
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1102
1239
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1107,9 +1244,9 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1107
1244
|
}
|
|
1108
1245
|
return;
|
|
1109
1246
|
}
|
|
1110
|
-
if (pathname ===
|
|
1247
|
+
if (pathname === MODERATIONS_PATH && req.method === "POST") {
|
|
1111
1248
|
try {
|
|
1112
|
-
await
|
|
1249
|
+
await require_moderation.handleModeration(req, res, await require_helpers.readBody(req), serviceFixtures?.moderation ?? [], journal, defaults, setCorsHeaders);
|
|
1113
1250
|
} catch (err) {
|
|
1114
1251
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1115
1252
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1120,9 +1257,10 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1120
1257
|
}
|
|
1121
1258
|
return;
|
|
1122
1259
|
}
|
|
1123
|
-
if (pathname ===
|
|
1260
|
+
if (pathname === ELEVENLABS_SOUND_GENERATION_PATH && req.method === "POST") {
|
|
1261
|
+
setCorsHeaders(res);
|
|
1124
1262
|
try {
|
|
1125
|
-
await
|
|
1263
|
+
await require_elevenlabs_audio.handleElevenLabsAudio(req, res, await require_helpers.readBody(req), fixtures, defaults, journal, "sound-generation");
|
|
1126
1264
|
} catch (err) {
|
|
1127
1265
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1128
1266
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|
|
@@ -1133,10 +1271,12 @@ async function createServer(fixtures, options, mounts, serviceFixtures) {
|
|
|
1133
1271
|
}
|
|
1134
1272
|
return;
|
|
1135
1273
|
}
|
|
1136
|
-
|
|
1274
|
+
const elevenLabsTTSMatch = pathname.match(ELEVENLABS_TTS_RE);
|
|
1275
|
+
if (elevenLabsTTSMatch && req.method === "POST") {
|
|
1137
1276
|
setCorsHeaders(res);
|
|
1277
|
+
const voiceId = elevenLabsTTSMatch[1];
|
|
1138
1278
|
try {
|
|
1139
|
-
await require_elevenlabs_audio.
|
|
1279
|
+
await require_elevenlabs_audio.handleElevenLabsTTS(req, res, await require_helpers.readBody(req), fixtures, defaults, journal, voiceId);
|
|
1140
1280
|
} catch (err) {
|
|
1141
1281
|
const msg = err instanceof Error ? err.message : "Internal error";
|
|
1142
1282
|
if (!res.headersSent) require_sse_writer.writeErrorResponse(res, 500, JSON.stringify({ error: {
|