@recapt/mcp 0.0.31 → 0.0.34

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/dist/index.js CHANGED
@@ -309,11 +309,30 @@ async function getEmbedder() {
309
309
  }
310
310
  return loadingPromise;
311
311
  }
312
- async function embedText(text) {
312
+ async function embedTextLocally(text) {
313
313
  const model = await getEmbedder();
314
314
  const output = await model(text, { pooling: "mean", normalize: true });
315
315
  return Array.from(output.data);
316
316
  }
317
+ async function embedTextViaApi(text) {
318
+ if (!isApiConfigured()) {
319
+ throw new Error("API not configured for remote embedding");
320
+ }
321
+ const { data, error } = await apiPost("/embed", {
322
+ text
323
+ });
324
+ if (error || !data?.embedding) {
325
+ throw new Error(error || "No embedding returned from API");
326
+ }
327
+ return data.embedding;
328
+ }
329
+ async function embedText(text) {
330
+ try {
331
+ return await embedTextLocally(text);
332
+ } catch {
333
+ return await embedTextViaApi(text);
334
+ }
335
+ }
317
336
  function cosineSimilarity(a, b) {
318
337
  if (a.length === 0 || b.length === 0 || a.length !== b.length)
319
338
  return 0;
@@ -421,14 +440,19 @@ async function searchBySemantic(limit, queryEmbedding) {
421
440
  }
422
441
  async function searchTools(query, limit = 5, queryEmbedding) {
423
442
  if (queryEmbedding && queryEmbedding.length > 0) {
424
- return searchBySemantic(limit, queryEmbedding);
443
+ const results = await searchBySemantic(limit, queryEmbedding);
444
+ if (results.length > 0)
445
+ return results;
446
+ return searchByKeyword(query, limit);
425
447
  }
426
448
  try {
427
449
  const embedding = await embedText(query);
428
- return searchBySemantic(limit, embedding);
450
+ const results = await searchBySemantic(limit, embedding);
451
+ if (results.length > 0)
452
+ return results;
429
453
  } catch {
430
- return searchByKeyword(query, limit);
431
454
  }
455
+ return searchByKeyword(query, limit);
432
456
  }
433
457
 
434
458
  // ../../node_modules/zod-to-json-schema/dist/esm/selectParser.js