@plur-ai/core 0.2.4 → 0.2.5

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.
@@ -0,0 +1,52 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __glob = (map) => (path) => {
14
+ var fn = map[path];
15
+ if (fn) return fn();
16
+ throw new Error("Module not found in bundle: " + path);
17
+ };
18
+ var __esm = (fn, res) => function __init() {
19
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
20
+ };
21
+ var __commonJS = (cb, mod) => function __require2() {
22
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
23
+ };
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
+ mod
43
+ ));
44
+
45
+ export {
46
+ __require,
47
+ __glob,
48
+ __esm,
49
+ __commonJS,
50
+ __export,
51
+ __toESM
52
+ };
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import "./chunk-2ZDO52B4.js";
2
+
1
3
  // src/storage.ts
2
4
  import { existsSync, mkdirSync } from "fs";
3
5
  import { join } from "path";
@@ -732,17 +734,25 @@ Rules:
732
734
  import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3, mkdirSync as mkdirSync2 } from "fs";
733
735
  import { join as join2 } from "path";
734
736
  var embedPipeline = null;
737
+ var transformersUnavailable = false;
735
738
  async function getEmbedder() {
739
+ if (transformersUnavailable) return null;
736
740
  if (!embedPipeline) {
737
- const { pipeline } = await import("@huggingface/transformers");
738
- embedPipeline = await pipeline("feature-extraction", "Xenova/bge-small-en-v1.5", {
739
- dtype: "fp32"
740
- });
741
+ try {
742
+ const { pipeline } = await import("./transformers.node-PH5YK5EA.js");
743
+ embedPipeline = await pipeline("feature-extraction", "Xenova/bge-small-en-v1.5", {
744
+ dtype: "fp32"
745
+ });
746
+ } catch {
747
+ transformersUnavailable = true;
748
+ return null;
749
+ }
741
750
  }
742
751
  return embedPipeline;
743
752
  }
744
753
  async function embed(text) {
745
754
  const embedder = await getEmbedder();
755
+ if (!embedder) return null;
746
756
  const result = await embedder(text, { pooling: "cls", normalize: true });
747
757
  return new Float32Array(result.data);
748
758
  }
@@ -776,6 +786,9 @@ async function embeddingSearch(engrams, query, limit, storagePath) {
776
786
  const cachePath = storagePath ? join2(storagePath, ".embeddings-cache.json") : ".embeddings-cache.json";
777
787
  const cache2 = loadCache(cachePath);
778
788
  const queryEmbedding = await embed(query);
789
+ if (!queryEmbedding) {
790
+ return [];
791
+ }
779
792
  const similarities = [];
780
793
  for (const engram of engrams) {
781
794
  const searchText = engramSearchText(engram);
@@ -784,7 +797,9 @@ async function embeddingSearch(engrams, query, limit, storagePath) {
784
797
  if (cache2[engram.id]?.hash === hash) {
785
798
  engramEmbedding = new Float32Array(cache2[engram.id].embedding);
786
799
  } else {
787
- engramEmbedding = await embed(searchText);
800
+ const emb = await embed(searchText);
801
+ if (!emb) return [];
802
+ engramEmbedding = emb;
788
803
  cache2[engram.id] = {
789
804
  hash,
790
805
  embedding: Array.from(engramEmbedding)