MCPcopy Create free account
hub / github.com/CopilotKit/aimock / handleCohereEmbed

Function handleCohereEmbed

src/cohere.ts:1331–1616  ·  view source on GitHub ↗
(
  req: http.IncomingMessage,
  res: http.ServerResponse,
  raw: string,
  fixtures: Fixture[],
  journal: Journal,
  defaults: HandlerDefaults,
  setCorsHeaders: (res: http.ServerResponse) => void,
)

Source from the content-addressed store, hash-verified

1329// ─── Cohere Embed handler ─────────────────────────────────────────────────
1330
1331export async function handleCohereEmbed(
1332 req: http.IncomingMessage,
1333 res: http.ServerResponse,
1334 raw: string,
1335 fixtures: Fixture[],
1336 journal: Journal,
1337 defaults: HandlerDefaults,
1338 setCorsHeaders: (res: http.ServerResponse) => void,
1339): Promise<void> {
1340 const { logger } = defaults;
1341 setCorsHeaders(res);
1342
1343 let embedReq: CohereEmbedRequest;
1344 try {
1345 embedReq = JSON.parse(raw) as CohereEmbedRequest;
1346 } catch (parseErr) {
1347 const detail = parseErr instanceof Error ? parseErr.message : "unknown";
1348 journal.add({
1349 method: req.method ?? "POST",
1350 path: req.url ?? "/v2/embed",
1351 headers: flattenHeaders(req.headers),
1352 body: null,
1353 response: { status: 400, fixture: null },
1354 });
1355 writeErrorResponse(
1356 res,
1357 400,
1358 JSON.stringify({
1359 error: {
1360 message: `Malformed JSON body: ${detail}`,
1361 type: "invalid_request_error",
1362 },
1363 }),
1364 );
1365 return;
1366 }
1367
1368 // Validate required fields
1369 if (!embedReq.model) {
1370 journal.add({
1371 method: req.method ?? "POST",
1372 path: req.url ?? "/v2/embed",
1373 headers: flattenHeaders(req.headers),
1374 body: null,
1375 response: { status: 400, fixture: null },
1376 });
1377 writeErrorResponse(
1378 res,
1379 400,
1380 JSON.stringify({
1381 error: {
1382 message: "model is required",
1383 type: "invalid_request_error",
1384 },
1385 }),
1386 );
1387 return;
1388 }

Callers 1

handleHttpRequestFunction · 0.85

Calls 15

setCorsHeadersFunction · 0.85
flattenHeadersFunction · 0.85
writeErrorResponseFunction · 0.85
getContextFunction · 0.85
getTestIdFunction · 0.85
matchFixtureDiagnosticFunction · 0.85
recordMatchOptionsFunction · 0.85
applyChaosFunction · 0.85
resolveResponseFunction · 0.85
isErrorResponseFunction · 0.85
serializeErrorResponseFunction · 0.85
isEmbeddingResponseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…