@agentskit/memory 0.8.1 → 0.8.3

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.cjs CHANGED
@@ -49,7 +49,11 @@ async function openDatabase(path) {
49
49
  const Database = mod.default ?? mod;
50
50
  return new Database(path);
51
51
  } catch {
52
- throw new Error("Install better-sqlite3 to use sqliteChatMemory: npm install better-sqlite3");
52
+ throw new core.MemoryError({
53
+ code: core.ErrorCodes.AK_MEMORY_PEER_MISSING,
54
+ message: "Install better-sqlite3 to use sqliteChatMemory: npm install better-sqlite3",
55
+ hint: 'sqliteChatMemory uses the optional peer "better-sqlite3".'
56
+ });
53
57
  }
54
58
  }
55
59
  function sqliteChatMemory(config) {
@@ -100,7 +104,11 @@ async function loadSdk() {
100
104
  moduleId
101
105
  );
102
106
  } catch {
103
- throw new Error("Install @libsql/client to use tursoChatMemory: npm install @libsql/client");
107
+ throw new core.MemoryError({
108
+ code: core.ErrorCodes.AK_MEMORY_PEER_MISSING,
109
+ message: "Install @libsql/client to use tursoChatMemory: npm install @libsql/client",
110
+ hint: 'tursoChatMemory uses the optional peer "@libsql/client".'
111
+ });
104
112
  }
105
113
  })();
106
114
  }
@@ -161,14 +169,16 @@ function tursoChatMemory(config) {
161
169
  }
162
170
  };
163
171
  }
164
-
165
- // src/redis-client.ts
166
172
  async function createRedisClientAdapter(url) {
167
173
  let redis;
168
174
  try {
169
175
  redis = await import('redis');
170
176
  } catch {
171
- throw new Error("Install redis to use Redis memory backends: npm install redis");
177
+ throw new core.MemoryError({
178
+ code: core.ErrorCodes.AK_MEMORY_PEER_MISSING,
179
+ message: "Install redis to use Redis memory backends: npm install redis",
180
+ hint: 'redisChatMemory and redisVectorMemory use the optional peer "redis".'
181
+ });
172
182
  }
173
183
  const client = redis.createClient({ url });
174
184
  await client.connect();
@@ -394,9 +404,11 @@ function requireVectra() {
394
404
  try {
395
405
  return __require("vectra");
396
406
  } catch {
397
- throw new Error(
398
- "Install vectra to use fileVectorMemory: npm install vectra"
399
- );
407
+ throw new core.MemoryError({
408
+ code: core.ErrorCodes.AK_MEMORY_PEER_MISSING,
409
+ message: "Install vectra to use fileVectorMemory: npm install vectra",
410
+ hint: 'fileVectorMemory uses the optional peer "vectra" for the on-disk index.'
411
+ });
400
412
  }
401
413
  }
402
414
  function createVectraStore(dirPath) {
@@ -634,8 +646,6 @@ function pgvector(config) {
634
646
  }
635
647
  };
636
648
  }
637
-
638
- // src/vector/pinecone.ts
639
649
  async function call(config, path, body) {
640
650
  const fetchImpl = config.fetch ?? globalThis.fetch;
641
651
  const response = await fetchImpl(`${config.indexUrl}${path}`, {
@@ -647,7 +657,13 @@ async function call(config, path, body) {
647
657
  body: JSON.stringify(body)
648
658
  });
649
659
  const text = await response.text();
650
- if (!response.ok) throw new Error(`pinecone ${response.status}: ${text.slice(0, 200)}`);
660
+ if (!response.ok) {
661
+ throw new core.MemoryError({
662
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
663
+ message: `pinecone ${response.status}: ${text.slice(0, 200)}`,
664
+ hint: `URL ${config.indexUrl}${path}. Check api-key + index URL/namespace.`
665
+ });
666
+ }
651
667
  return text.length > 0 ? JSON.parse(text) : {};
652
668
  }
653
669
  function pinecone(config) {
@@ -687,8 +703,6 @@ function pinecone(config) {
687
703
  }
688
704
  };
689
705
  }
690
-
691
- // src/vector/qdrant.ts
692
706
  async function call2(config, method, path, body) {
693
707
  const fetchImpl = config.fetch ?? globalThis.fetch;
694
708
  const response = await fetchImpl(`${config.url}${path}`, {
@@ -700,7 +714,13 @@ async function call2(config, method, path, body) {
700
714
  body: body === void 0 ? void 0 : JSON.stringify(body)
701
715
  });
702
716
  const text = await response.text();
703
- if (!response.ok) throw new Error(`qdrant ${response.status}: ${text.slice(0, 200)}`);
717
+ if (!response.ok) {
718
+ throw new core.MemoryError({
719
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
720
+ message: `qdrant ${response.status}: ${text.slice(0, 200)}`,
721
+ hint: `URL ${config.url}${path}. Check api-key + collection "${config.collection}".`
722
+ });
723
+ }
704
724
  return text.length > 0 ? JSON.parse(text) : {};
705
725
  }
706
726
  function qdrant(config) {
@@ -739,8 +759,6 @@ function qdrant(config) {
739
759
  }
740
760
  };
741
761
  }
742
-
743
- // src/vector/chroma.ts
744
762
  async function call3(config, method, path, body) {
745
763
  const fetchImpl = config.fetch ?? globalThis.fetch;
746
764
  const response = await fetchImpl(`${config.url}${path}`, {
@@ -749,7 +767,13 @@ async function call3(config, method, path, body) {
749
767
  body: body === void 0 ? void 0 : JSON.stringify(body)
750
768
  });
751
769
  const text = await response.text();
752
- if (!response.ok) throw new Error(`chroma ${response.status}: ${text.slice(0, 200)}`);
770
+ if (!response.ok) {
771
+ throw new core.MemoryError({
772
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
773
+ message: `chroma ${response.status}: ${text.slice(0, 200)}`,
774
+ hint: `URL ${config.url}${path}. Check Chroma server health + collection name.`
775
+ });
776
+ }
753
777
  return text.length > 0 ? JSON.parse(text) : {};
754
778
  }
755
779
  function chroma(config) {
@@ -788,8 +812,6 @@ function chroma(config) {
788
812
  }
789
813
  };
790
814
  }
791
-
792
- // src/vector/upstash.ts
793
815
  async function call4(config, path, body) {
794
816
  const fetchImpl = config.fetch ?? globalThis.fetch;
795
817
  const response = await fetchImpl(`${config.url}${path}`, {
@@ -801,7 +823,13 @@ async function call4(config, path, body) {
801
823
  body: JSON.stringify(body)
802
824
  });
803
825
  const text = await response.text();
804
- if (!response.ok) throw new Error(`upstash-vector ${response.status}: ${text.slice(0, 200)}`);
826
+ if (!response.ok) {
827
+ throw new core.MemoryError({
828
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
829
+ message: `upstash-vector ${response.status}: ${text.slice(0, 200)}`,
830
+ hint: `URL ${config.url}${path}. Check token + index URL.`
831
+ });
832
+ }
805
833
  return text.length > 0 ? JSON.parse(text) : {};
806
834
  }
807
835
  function upstashVector(config) {
@@ -836,8 +864,6 @@ function upstashVector(config) {
836
864
  }
837
865
  };
838
866
  }
839
-
840
- // src/vector/supabase.ts
841
867
  var cachedSdk2 = null;
842
868
  async function loadSdk2() {
843
869
  if (!cachedSdk2) {
@@ -849,9 +875,11 @@ async function loadSdk2() {
849
875
  moduleId
850
876
  );
851
877
  } catch {
852
- throw new Error(
853
- "Install @supabase/supabase-js to use supabaseVectorStore: npm install @supabase/supabase-js"
854
- );
878
+ throw new core.MemoryError({
879
+ code: core.ErrorCodes.AK_MEMORY_PEER_MISSING,
880
+ message: "Install @supabase/supabase-js to use supabaseVectorStore: npm install @supabase/supabase-js",
881
+ hint: 'supabaseVectorStore uses the optional peer "@supabase/supabase-js".'
882
+ });
855
883
  }
856
884
  })();
857
885
  }
@@ -861,7 +889,13 @@ function buildRunner(client) {
861
889
  return {
862
890
  async query(sql, params) {
863
891
  const result = await client.rpc("agentskit_execute_sql", { sql, params });
864
- if (result.error) throw new Error(`supabase: ${result.error.message}`);
892
+ if (result.error) {
893
+ throw new core.MemoryError({
894
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
895
+ message: `supabase: ${result.error.message}`,
896
+ hint: "Check the agentskit_execute_sql RPC + service role key permissions."
897
+ });
898
+ }
865
899
  return { rows: result.data ?? [] };
866
900
  }
867
901
  };
@@ -905,8 +939,6 @@ function supabaseVectorStore(config) {
905
939
  }
906
940
  };
907
941
  }
908
-
909
- // src/vector/weaviate.ts
910
942
  async function call5(config, method, path, body) {
911
943
  const fetchImpl = config.fetch ?? globalThis.fetch;
912
944
  const response = await fetchImpl(`${config.url}${path}`, {
@@ -918,7 +950,13 @@ async function call5(config, method, path, body) {
918
950
  body: body === void 0 ? void 0 : JSON.stringify(body)
919
951
  });
920
952
  const text = await response.text();
921
- if (!response.ok) throw new Error(`weaviate ${response.status}: ${text.slice(0, 200)}`);
953
+ if (!response.ok) {
954
+ throw new core.MemoryError({
955
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
956
+ message: `weaviate ${response.status}: ${text.slice(0, 200)}`,
957
+ hint: `URL ${config.url}${path}. Check API key + class name "${config.className}".`
958
+ });
959
+ }
922
960
  return text.length > 0 ? JSON.parse(text) : {};
923
961
  }
924
962
  function weaviateVectorStore(config) {
@@ -963,8 +1001,6 @@ function weaviateVectorStore(config) {
963
1001
  }
964
1002
  };
965
1003
  }
966
-
967
- // src/vector/milvus.ts
968
1004
  async function call6(config, path, body) {
969
1005
  const fetchImpl = config.fetch ?? globalThis.fetch;
970
1006
  const response = await fetchImpl(`${config.url}${path}`, {
@@ -976,7 +1012,13 @@ async function call6(config, path, body) {
976
1012
  body: JSON.stringify(body)
977
1013
  });
978
1014
  const text = await response.text();
979
- if (!response.ok) throw new Error(`milvus ${response.status}: ${text.slice(0, 200)}`);
1015
+ if (!response.ok) {
1016
+ throw new core.MemoryError({
1017
+ code: core.ErrorCodes.AK_MEMORY_REMOTE_HTTP,
1018
+ message: `milvus ${response.status}: ${text.slice(0, 200)}`,
1019
+ hint: `URL ${config.url}${path}. Check token + collection "${config.collection}".`
1020
+ });
1021
+ }
980
1022
  return text.length > 0 ? JSON.parse(text) : {};
981
1023
  }
982
1024
  function milvusVectorStore(config) {
@@ -1066,8 +1108,6 @@ function mongoAtlasVectorStore(config) {
1066
1108
  }
1067
1109
  };
1068
1110
  }
1069
-
1070
- // src/encrypted.ts
1071
1111
  function toBase64(bytes) {
1072
1112
  if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
1073
1113
  let binary = "";
@@ -1085,14 +1125,24 @@ async function resolveKey(subtle, material) {
1085
1125
  if ("type" in material && material.type === "secret") return material;
1086
1126
  const raw = material;
1087
1127
  if (raw.byteLength !== 32) {
1088
- throw new Error(`createEncryptedMemory: key must be 32 bytes (got ${raw.byteLength})`);
1128
+ throw new core.ConfigError({
1129
+ code: core.ErrorCodes.AK_CONFIG_INVALID,
1130
+ message: `createEncryptedMemory: key must be 32 bytes (got ${raw.byteLength})`,
1131
+ hint: "Generate a 32-byte key, e.g. crypto.getRandomValues(new Uint8Array(32))."
1132
+ });
1089
1133
  }
1090
1134
  return subtle.importKey("raw", raw, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
1091
1135
  }
1092
1136
  async function createEncryptedMemory(options) {
1093
1137
  const subtle = options.subtle ?? globalThis.crypto?.subtle;
1094
1138
  const random = options.getRandomValues ?? ((v) => globalThis.crypto.getRandomValues(v));
1095
- if (!subtle) throw new Error("createEncryptedMemory: SubtleCrypto not available");
1139
+ if (!subtle) {
1140
+ throw new core.MemoryError({
1141
+ code: core.ErrorCodes.AK_MEMORY_LOAD_FAILED,
1142
+ message: "createEncryptedMemory: SubtleCrypto not available",
1143
+ hint: "Run on Node \u2265 20 / a modern browser, or pass options.subtle explicitly."
1144
+ });
1145
+ }
1096
1146
  const key = await resolveKey(subtle, options.key);
1097
1147
  const aad = options.aad;
1098
1148
  const encrypt = async (plain) => {