@agentskit/memory 0.8.0 → 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 +86 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -37
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { serializeMessages, deserializeMessages } from '@agentskit/core';
|
|
1
|
+
import { serializeMessages, deserializeMessages, MemoryError, ErrorCodes, ConfigError } from '@agentskit/core';
|
|
2
2
|
|
|
3
3
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
4
4
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -47,7 +47,11 @@ async function openDatabase(path) {
|
|
|
47
47
|
const Database = mod.default ?? mod;
|
|
48
48
|
return new Database(path);
|
|
49
49
|
} catch {
|
|
50
|
-
throw new
|
|
50
|
+
throw new MemoryError({
|
|
51
|
+
code: ErrorCodes.AK_MEMORY_PEER_MISSING,
|
|
52
|
+
message: "Install better-sqlite3 to use sqliteChatMemory: npm install better-sqlite3",
|
|
53
|
+
hint: 'sqliteChatMemory uses the optional peer "better-sqlite3".'
|
|
54
|
+
});
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
function sqliteChatMemory(config) {
|
|
@@ -98,7 +102,11 @@ async function loadSdk() {
|
|
|
98
102
|
moduleId
|
|
99
103
|
);
|
|
100
104
|
} catch {
|
|
101
|
-
throw new
|
|
105
|
+
throw new MemoryError({
|
|
106
|
+
code: ErrorCodes.AK_MEMORY_PEER_MISSING,
|
|
107
|
+
message: "Install @libsql/client to use tursoChatMemory: npm install @libsql/client",
|
|
108
|
+
hint: 'tursoChatMemory uses the optional peer "@libsql/client".'
|
|
109
|
+
});
|
|
102
110
|
}
|
|
103
111
|
})();
|
|
104
112
|
}
|
|
@@ -159,14 +167,16 @@ function tursoChatMemory(config) {
|
|
|
159
167
|
}
|
|
160
168
|
};
|
|
161
169
|
}
|
|
162
|
-
|
|
163
|
-
// src/redis-client.ts
|
|
164
170
|
async function createRedisClientAdapter(url) {
|
|
165
171
|
let redis;
|
|
166
172
|
try {
|
|
167
173
|
redis = await import('redis');
|
|
168
174
|
} catch {
|
|
169
|
-
throw new
|
|
175
|
+
throw new MemoryError({
|
|
176
|
+
code: ErrorCodes.AK_MEMORY_PEER_MISSING,
|
|
177
|
+
message: "Install redis to use Redis memory backends: npm install redis",
|
|
178
|
+
hint: 'redisChatMemory and redisVectorMemory use the optional peer "redis".'
|
|
179
|
+
});
|
|
170
180
|
}
|
|
171
181
|
const client = redis.createClient({ url });
|
|
172
182
|
await client.connect();
|
|
@@ -392,9 +402,11 @@ function requireVectra() {
|
|
|
392
402
|
try {
|
|
393
403
|
return __require("vectra");
|
|
394
404
|
} catch {
|
|
395
|
-
throw new
|
|
396
|
-
|
|
397
|
-
|
|
405
|
+
throw new MemoryError({
|
|
406
|
+
code: ErrorCodes.AK_MEMORY_PEER_MISSING,
|
|
407
|
+
message: "Install vectra to use fileVectorMemory: npm install vectra",
|
|
408
|
+
hint: 'fileVectorMemory uses the optional peer "vectra" for the on-disk index.'
|
|
409
|
+
});
|
|
398
410
|
}
|
|
399
411
|
}
|
|
400
412
|
function createVectraStore(dirPath) {
|
|
@@ -632,8 +644,6 @@ function pgvector(config) {
|
|
|
632
644
|
}
|
|
633
645
|
};
|
|
634
646
|
}
|
|
635
|
-
|
|
636
|
-
// src/vector/pinecone.ts
|
|
637
647
|
async function call(config, path, body) {
|
|
638
648
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
639
649
|
const response = await fetchImpl(`${config.indexUrl}${path}`, {
|
|
@@ -645,7 +655,13 @@ async function call(config, path, body) {
|
|
|
645
655
|
body: JSON.stringify(body)
|
|
646
656
|
});
|
|
647
657
|
const text = await response.text();
|
|
648
|
-
if (!response.ok)
|
|
658
|
+
if (!response.ok) {
|
|
659
|
+
throw new MemoryError({
|
|
660
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
661
|
+
message: `pinecone ${response.status}: ${text.slice(0, 200)}`,
|
|
662
|
+
hint: `URL ${config.indexUrl}${path}. Check api-key + index URL/namespace.`
|
|
663
|
+
});
|
|
664
|
+
}
|
|
649
665
|
return text.length > 0 ? JSON.parse(text) : {};
|
|
650
666
|
}
|
|
651
667
|
function pinecone(config) {
|
|
@@ -685,8 +701,6 @@ function pinecone(config) {
|
|
|
685
701
|
}
|
|
686
702
|
};
|
|
687
703
|
}
|
|
688
|
-
|
|
689
|
-
// src/vector/qdrant.ts
|
|
690
704
|
async function call2(config, method, path, body) {
|
|
691
705
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
692
706
|
const response = await fetchImpl(`${config.url}${path}`, {
|
|
@@ -698,7 +712,13 @@ async function call2(config, method, path, body) {
|
|
|
698
712
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
699
713
|
});
|
|
700
714
|
const text = await response.text();
|
|
701
|
-
if (!response.ok)
|
|
715
|
+
if (!response.ok) {
|
|
716
|
+
throw new MemoryError({
|
|
717
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
718
|
+
message: `qdrant ${response.status}: ${text.slice(0, 200)}`,
|
|
719
|
+
hint: `URL ${config.url}${path}. Check api-key + collection "${config.collection}".`
|
|
720
|
+
});
|
|
721
|
+
}
|
|
702
722
|
return text.length > 0 ? JSON.parse(text) : {};
|
|
703
723
|
}
|
|
704
724
|
function qdrant(config) {
|
|
@@ -737,8 +757,6 @@ function qdrant(config) {
|
|
|
737
757
|
}
|
|
738
758
|
};
|
|
739
759
|
}
|
|
740
|
-
|
|
741
|
-
// src/vector/chroma.ts
|
|
742
760
|
async function call3(config, method, path, body) {
|
|
743
761
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
744
762
|
const response = await fetchImpl(`${config.url}${path}`, {
|
|
@@ -747,7 +765,13 @@ async function call3(config, method, path, body) {
|
|
|
747
765
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
748
766
|
});
|
|
749
767
|
const text = await response.text();
|
|
750
|
-
if (!response.ok)
|
|
768
|
+
if (!response.ok) {
|
|
769
|
+
throw new MemoryError({
|
|
770
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
771
|
+
message: `chroma ${response.status}: ${text.slice(0, 200)}`,
|
|
772
|
+
hint: `URL ${config.url}${path}. Check Chroma server health + collection name.`
|
|
773
|
+
});
|
|
774
|
+
}
|
|
751
775
|
return text.length > 0 ? JSON.parse(text) : {};
|
|
752
776
|
}
|
|
753
777
|
function chroma(config) {
|
|
@@ -786,8 +810,6 @@ function chroma(config) {
|
|
|
786
810
|
}
|
|
787
811
|
};
|
|
788
812
|
}
|
|
789
|
-
|
|
790
|
-
// src/vector/upstash.ts
|
|
791
813
|
async function call4(config, path, body) {
|
|
792
814
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
793
815
|
const response = await fetchImpl(`${config.url}${path}`, {
|
|
@@ -799,7 +821,13 @@ async function call4(config, path, body) {
|
|
|
799
821
|
body: JSON.stringify(body)
|
|
800
822
|
});
|
|
801
823
|
const text = await response.text();
|
|
802
|
-
if (!response.ok)
|
|
824
|
+
if (!response.ok) {
|
|
825
|
+
throw new MemoryError({
|
|
826
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
827
|
+
message: `upstash-vector ${response.status}: ${text.slice(0, 200)}`,
|
|
828
|
+
hint: `URL ${config.url}${path}. Check token + index URL.`
|
|
829
|
+
});
|
|
830
|
+
}
|
|
803
831
|
return text.length > 0 ? JSON.parse(text) : {};
|
|
804
832
|
}
|
|
805
833
|
function upstashVector(config) {
|
|
@@ -834,8 +862,6 @@ function upstashVector(config) {
|
|
|
834
862
|
}
|
|
835
863
|
};
|
|
836
864
|
}
|
|
837
|
-
|
|
838
|
-
// src/vector/supabase.ts
|
|
839
865
|
var cachedSdk2 = null;
|
|
840
866
|
async function loadSdk2() {
|
|
841
867
|
if (!cachedSdk2) {
|
|
@@ -847,9 +873,11 @@ async function loadSdk2() {
|
|
|
847
873
|
moduleId
|
|
848
874
|
);
|
|
849
875
|
} catch {
|
|
850
|
-
throw new
|
|
851
|
-
|
|
852
|
-
|
|
876
|
+
throw new MemoryError({
|
|
877
|
+
code: ErrorCodes.AK_MEMORY_PEER_MISSING,
|
|
878
|
+
message: "Install @supabase/supabase-js to use supabaseVectorStore: npm install @supabase/supabase-js",
|
|
879
|
+
hint: 'supabaseVectorStore uses the optional peer "@supabase/supabase-js".'
|
|
880
|
+
});
|
|
853
881
|
}
|
|
854
882
|
})();
|
|
855
883
|
}
|
|
@@ -859,7 +887,13 @@ function buildRunner(client) {
|
|
|
859
887
|
return {
|
|
860
888
|
async query(sql, params) {
|
|
861
889
|
const result = await client.rpc("agentskit_execute_sql", { sql, params });
|
|
862
|
-
if (result.error)
|
|
890
|
+
if (result.error) {
|
|
891
|
+
throw new MemoryError({
|
|
892
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
893
|
+
message: `supabase: ${result.error.message}`,
|
|
894
|
+
hint: "Check the agentskit_execute_sql RPC + service role key permissions."
|
|
895
|
+
});
|
|
896
|
+
}
|
|
863
897
|
return { rows: result.data ?? [] };
|
|
864
898
|
}
|
|
865
899
|
};
|
|
@@ -903,8 +937,6 @@ function supabaseVectorStore(config) {
|
|
|
903
937
|
}
|
|
904
938
|
};
|
|
905
939
|
}
|
|
906
|
-
|
|
907
|
-
// src/vector/weaviate.ts
|
|
908
940
|
async function call5(config, method, path, body) {
|
|
909
941
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
910
942
|
const response = await fetchImpl(`${config.url}${path}`, {
|
|
@@ -916,7 +948,13 @@ async function call5(config, method, path, body) {
|
|
|
916
948
|
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
917
949
|
});
|
|
918
950
|
const text = await response.text();
|
|
919
|
-
if (!response.ok)
|
|
951
|
+
if (!response.ok) {
|
|
952
|
+
throw new MemoryError({
|
|
953
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
954
|
+
message: `weaviate ${response.status}: ${text.slice(0, 200)}`,
|
|
955
|
+
hint: `URL ${config.url}${path}. Check API key + class name "${config.className}".`
|
|
956
|
+
});
|
|
957
|
+
}
|
|
920
958
|
return text.length > 0 ? JSON.parse(text) : {};
|
|
921
959
|
}
|
|
922
960
|
function weaviateVectorStore(config) {
|
|
@@ -961,8 +999,6 @@ function weaviateVectorStore(config) {
|
|
|
961
999
|
}
|
|
962
1000
|
};
|
|
963
1001
|
}
|
|
964
|
-
|
|
965
|
-
// src/vector/milvus.ts
|
|
966
1002
|
async function call6(config, path, body) {
|
|
967
1003
|
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
968
1004
|
const response = await fetchImpl(`${config.url}${path}`, {
|
|
@@ -974,7 +1010,13 @@ async function call6(config, path, body) {
|
|
|
974
1010
|
body: JSON.stringify(body)
|
|
975
1011
|
});
|
|
976
1012
|
const text = await response.text();
|
|
977
|
-
if (!response.ok)
|
|
1013
|
+
if (!response.ok) {
|
|
1014
|
+
throw new MemoryError({
|
|
1015
|
+
code: ErrorCodes.AK_MEMORY_REMOTE_HTTP,
|
|
1016
|
+
message: `milvus ${response.status}: ${text.slice(0, 200)}`,
|
|
1017
|
+
hint: `URL ${config.url}${path}. Check token + collection "${config.collection}".`
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
978
1020
|
return text.length > 0 ? JSON.parse(text) : {};
|
|
979
1021
|
}
|
|
980
1022
|
function milvusVectorStore(config) {
|
|
@@ -1064,8 +1106,6 @@ function mongoAtlasVectorStore(config) {
|
|
|
1064
1106
|
}
|
|
1065
1107
|
};
|
|
1066
1108
|
}
|
|
1067
|
-
|
|
1068
|
-
// src/encrypted.ts
|
|
1069
1109
|
function toBase64(bytes) {
|
|
1070
1110
|
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
1071
1111
|
let binary = "";
|
|
@@ -1083,14 +1123,24 @@ async function resolveKey(subtle, material) {
|
|
|
1083
1123
|
if ("type" in material && material.type === "secret") return material;
|
|
1084
1124
|
const raw = material;
|
|
1085
1125
|
if (raw.byteLength !== 32) {
|
|
1086
|
-
throw new
|
|
1126
|
+
throw new ConfigError({
|
|
1127
|
+
code: ErrorCodes.AK_CONFIG_INVALID,
|
|
1128
|
+
message: `createEncryptedMemory: key must be 32 bytes (got ${raw.byteLength})`,
|
|
1129
|
+
hint: "Generate a 32-byte key, e.g. crypto.getRandomValues(new Uint8Array(32))."
|
|
1130
|
+
});
|
|
1087
1131
|
}
|
|
1088
1132
|
return subtle.importKey("raw", raw, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
|
|
1089
1133
|
}
|
|
1090
1134
|
async function createEncryptedMemory(options) {
|
|
1091
1135
|
const subtle = options.subtle ?? globalThis.crypto?.subtle;
|
|
1092
1136
|
const random = options.getRandomValues ?? ((v) => globalThis.crypto.getRandomValues(v));
|
|
1093
|
-
if (!subtle)
|
|
1137
|
+
if (!subtle) {
|
|
1138
|
+
throw new MemoryError({
|
|
1139
|
+
code: ErrorCodes.AK_MEMORY_LOAD_FAILED,
|
|
1140
|
+
message: "createEncryptedMemory: SubtleCrypto not available",
|
|
1141
|
+
hint: "Run on Node \u2265 20 / a modern browser, or pass options.subtle explicitly."
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1094
1144
|
const key = await resolveKey(subtle, options.key);
|
|
1095
1145
|
const aad = options.aad;
|
|
1096
1146
|
const encrypt = async (plain) => {
|