@workglow/storage 0.0.101 → 0.0.103
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/browser.js +161 -34
- package/dist/browser.js.map +15 -14
- package/dist/bun.js +207 -69
- package/dist/bun.js.map +19 -18
- package/dist/common-server.d.ts +1 -0
- package/dist/common-server.d.ts.map +1 -1
- package/dist/kv/InMemoryKvStorage.d.ts.map +1 -1
- package/dist/kv/KvStorage.d.ts.map +1 -1
- package/dist/node.js +207 -69
- package/dist/node.js.map +19 -18
- package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -1
- package/dist/tabular/BaseSqlTabularStorage.d.ts.map +1 -1
- package/dist/tabular/BaseTabularStorage.d.ts.map +1 -1
- package/dist/tabular/HuggingFaceTabularStorage.d.ts.map +1 -1
- package/dist/tabular/PostgresTabularStorage.d.ts.map +1 -1
- package/dist/tabular/SqliteTabularStorage.d.ts.map +1 -1
- package/dist/tabular/SupabaseTabularStorage.d.ts.map +1 -1
- package/dist/util/IndexedDbTable.d.ts.map +1 -1
- package/dist/vector/IndexedDbVectorStorage.d.ts +55 -0
- package/dist/vector/IndexedDbVectorStorage.d.ts.map +1 -0
- package/dist/vector/PostgresVectorStorage.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/browser.js
CHANGED
|
@@ -189,11 +189,12 @@ class BaseTabularStorage {
|
|
|
189
189
|
const valueNames = this.valueColumns();
|
|
190
190
|
const value = {};
|
|
191
191
|
const key = {};
|
|
192
|
+
const objRecord = obj;
|
|
192
193
|
for (const k of primaryKeyNames) {
|
|
193
|
-
key[k] =
|
|
194
|
+
key[k] = objRecord[k];
|
|
194
195
|
}
|
|
195
196
|
for (const k of valueNames) {
|
|
196
|
-
value[k] =
|
|
197
|
+
value[k] = objRecord[k];
|
|
197
198
|
}
|
|
198
199
|
return { value, key };
|
|
199
200
|
}
|
|
@@ -1030,7 +1031,14 @@ class InMemoryKvStorage extends KvViaTabularStorage {
|
|
|
1030
1031
|
}
|
|
1031
1032
|
}
|
|
1032
1033
|
// src/queue/InMemoryQueueStorage.ts
|
|
1033
|
-
import {
|
|
1034
|
+
import {
|
|
1035
|
+
createServiceToken as createServiceToken9,
|
|
1036
|
+
EventEmitter as EventEmitter3,
|
|
1037
|
+
getLogger,
|
|
1038
|
+
makeFingerprint as makeFingerprint4,
|
|
1039
|
+
sleep,
|
|
1040
|
+
uuid4 as uuid42
|
|
1041
|
+
} from "@workglow/util";
|
|
1034
1042
|
|
|
1035
1043
|
// src/queue/IQueueStorage.ts
|
|
1036
1044
|
import { createServiceToken as createServiceToken8 } from "@workglow/util";
|
|
@@ -1124,11 +1132,23 @@ class InMemoryQueueStorage {
|
|
|
1124
1132
|
await sleep(0);
|
|
1125
1133
|
const job = this.jobQueue.find((j) => j.id === id && this.matchesPrefixes(j));
|
|
1126
1134
|
if (!job) {
|
|
1127
|
-
|
|
1135
|
+
const jobWithAnyPrefix = this.jobQueue.find((j) => j.id === id);
|
|
1136
|
+
getLogger().warn("Job not found for progress update", {
|
|
1137
|
+
id,
|
|
1138
|
+
reason: jobWithAnyPrefix ? "prefix_mismatch" : "missing",
|
|
1139
|
+
existingStatus: jobWithAnyPrefix?.status,
|
|
1140
|
+
queueName: this.queueName,
|
|
1141
|
+
prefixValues: this.prefixValues
|
|
1142
|
+
});
|
|
1128
1143
|
return;
|
|
1129
1144
|
}
|
|
1130
1145
|
if (job.status === JobStatus.COMPLETED || job.status === JobStatus.FAILED) {
|
|
1131
|
-
|
|
1146
|
+
getLogger().warn("Job already completed or failed for progress update", {
|
|
1147
|
+
id,
|
|
1148
|
+
status: job.status,
|
|
1149
|
+
completedAt: job.completed_at,
|
|
1150
|
+
error: job.error
|
|
1151
|
+
});
|
|
1132
1152
|
return;
|
|
1133
1153
|
}
|
|
1134
1154
|
const oldJob = { ...job };
|
|
@@ -2761,17 +2781,16 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
|
|
|
2761
2781
|
return value;
|
|
2762
2782
|
}
|
|
2763
2783
|
if (actualType.contentEncoding === "blob") {
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
return v;
|
|
2784
|
+
if (value instanceof Uint8Array) {
|
|
2785
|
+
return value;
|
|
2767
2786
|
}
|
|
2768
|
-
if (typeof Buffer !== "undefined" &&
|
|
2769
|
-
return new Uint8Array(
|
|
2787
|
+
if (typeof Buffer !== "undefined" && value instanceof Buffer) {
|
|
2788
|
+
return new Uint8Array(value);
|
|
2770
2789
|
}
|
|
2771
|
-
if (Array.isArray(
|
|
2772
|
-
return new Uint8Array(
|
|
2790
|
+
if (Array.isArray(value)) {
|
|
2791
|
+
return new Uint8Array(value);
|
|
2773
2792
|
}
|
|
2774
|
-
return
|
|
2793
|
+
return value;
|
|
2775
2794
|
} else if (value instanceof Date) {
|
|
2776
2795
|
return value.toISOString();
|
|
2777
2796
|
} else {
|
|
@@ -2791,14 +2810,13 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
|
|
|
2791
2810
|
return value;
|
|
2792
2811
|
}
|
|
2793
2812
|
if (actualType.contentEncoding === "blob") {
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
return new Uint8Array(v);
|
|
2813
|
+
if (typeof Buffer !== "undefined" && value instanceof Buffer) {
|
|
2814
|
+
return new Uint8Array(value);
|
|
2797
2815
|
}
|
|
2798
|
-
if (
|
|
2799
|
-
return
|
|
2816
|
+
if (value instanceof Uint8Array) {
|
|
2817
|
+
return value;
|
|
2800
2818
|
}
|
|
2801
|
-
return
|
|
2819
|
+
return value;
|
|
2802
2820
|
} else {
|
|
2803
2821
|
return value;
|
|
2804
2822
|
}
|
|
@@ -3006,11 +3024,10 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3006
3024
|
}
|
|
3007
3025
|
const actualType = this.getNonNullType(typeDef);
|
|
3008
3026
|
if (typeof actualType !== "boolean" && (actualType.type === "number" || actualType.type === "integer")) {
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
const parsed = Number(v);
|
|
3027
|
+
if (typeof value === "number")
|
|
3028
|
+
return value;
|
|
3029
|
+
if (typeof value === "string") {
|
|
3030
|
+
const parsed = Number(value);
|
|
3014
3031
|
if (!isNaN(parsed))
|
|
3015
3032
|
return parsed;
|
|
3016
3033
|
}
|
|
@@ -3032,7 +3049,8 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3032
3049
|
let entityToInsert = { ...entity };
|
|
3033
3050
|
if (this.hasAutoGeneratedKey() && this.autoGeneratedKeyName) {
|
|
3034
3051
|
const keyName = String(this.autoGeneratedKeyName);
|
|
3035
|
-
const
|
|
3052
|
+
const entityRecord = entity;
|
|
3053
|
+
const clientProvidedValue = entityRecord[keyName];
|
|
3036
3054
|
const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
|
|
3037
3055
|
let shouldOmitKey = false;
|
|
3038
3056
|
if (this.clientProvidedKeys === "never") {
|
|
@@ -3062,8 +3080,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3062
3080
|
if (error)
|
|
3063
3081
|
throw error;
|
|
3064
3082
|
const updatedEntity = data;
|
|
3083
|
+
const updatedRecord = updatedEntity;
|
|
3065
3084
|
for (const key in this.schema.properties) {
|
|
3066
|
-
|
|
3085
|
+
updatedRecord[key] = this.sqlToJsValue(key, updatedRecord[key]);
|
|
3067
3086
|
}
|
|
3068
3087
|
this.events.emit("put", updatedEntity);
|
|
3069
3088
|
return updatedEntity;
|
|
@@ -3075,8 +3094,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3075
3094
|
}
|
|
3076
3095
|
async get(key) {
|
|
3077
3096
|
let query = this.client.from(this.table).select("*");
|
|
3097
|
+
const keyRecord = key;
|
|
3078
3098
|
for (const pkName of this.primaryKeyNames) {
|
|
3079
|
-
query = query.eq(String(pkName),
|
|
3099
|
+
query = query.eq(String(pkName), keyRecord[String(pkName)]);
|
|
3080
3100
|
}
|
|
3081
3101
|
const { data, error } = await query.single();
|
|
3082
3102
|
if (error) {
|
|
@@ -3088,8 +3108,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3088
3108
|
}
|
|
3089
3109
|
const val = data;
|
|
3090
3110
|
if (val) {
|
|
3111
|
+
const valRecord = val;
|
|
3091
3112
|
for (const key2 in this.schema.properties) {
|
|
3092
|
-
|
|
3113
|
+
valRecord[key2] = this.sqlToJsValue(key2, valRecord[key2]);
|
|
3093
3114
|
}
|
|
3094
3115
|
}
|
|
3095
3116
|
this.events.emit("get", key, val);
|
|
@@ -3118,8 +3139,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3118
3139
|
throw error;
|
|
3119
3140
|
if (data && data.length > 0) {
|
|
3120
3141
|
for (const row of data) {
|
|
3142
|
+
const record = row;
|
|
3121
3143
|
for (const key in this.schema.properties) {
|
|
3122
|
-
|
|
3144
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
3123
3145
|
}
|
|
3124
3146
|
}
|
|
3125
3147
|
this.events.emit("search", searchCriteria, data);
|
|
@@ -3132,8 +3154,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3132
3154
|
async delete(value) {
|
|
3133
3155
|
const { key } = this.separateKeyValueFromCombined(value);
|
|
3134
3156
|
let query = this.client.from(this.table).delete();
|
|
3157
|
+
const deleteKeyRecord = key;
|
|
3135
3158
|
for (const pkName of this.primaryKeyNames) {
|
|
3136
|
-
query = query.eq(String(pkName),
|
|
3159
|
+
query = query.eq(String(pkName), deleteKeyRecord[String(pkName)]);
|
|
3137
3160
|
}
|
|
3138
3161
|
const { error } = await query;
|
|
3139
3162
|
if (error)
|
|
@@ -3146,8 +3169,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3146
3169
|
throw error;
|
|
3147
3170
|
if (data && data.length) {
|
|
3148
3171
|
for (const row of data) {
|
|
3172
|
+
const record = row;
|
|
3149
3173
|
for (const key in this.schema.properties) {
|
|
3150
|
-
|
|
3174
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
3151
3175
|
}
|
|
3152
3176
|
}
|
|
3153
3177
|
return data;
|
|
@@ -3179,8 +3203,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3179
3203
|
return;
|
|
3180
3204
|
}
|
|
3181
3205
|
for (const row of data) {
|
|
3206
|
+
const record = row;
|
|
3182
3207
|
for (const key in this.schema.properties) {
|
|
3183
|
-
|
|
3208
|
+
record[key] = this.sqlToJsValue(key, record[key]);
|
|
3184
3209
|
}
|
|
3185
3210
|
}
|
|
3186
3211
|
return data;
|
|
@@ -3229,8 +3254,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
|
|
|
3229
3254
|
}
|
|
3230
3255
|
convertRealtimeRow(row) {
|
|
3231
3256
|
const entity = { ...row };
|
|
3257
|
+
const record = entity;
|
|
3232
3258
|
for (const key in this.schema.properties) {
|
|
3233
|
-
|
|
3259
|
+
record[key] = this.sqlToJsValue(key, row[key]);
|
|
3234
3260
|
}
|
|
3235
3261
|
return entity;
|
|
3236
3262
|
}
|
|
@@ -4733,6 +4759,105 @@ class SupabaseRateLimiterStorage {
|
|
|
4733
4759
|
throw nextError;
|
|
4734
4760
|
}
|
|
4735
4761
|
}
|
|
4762
|
+
// src/vector/IndexedDbVectorStorage.ts
|
|
4763
|
+
import { cosineSimilarity as cosineSimilarity2, createServiceToken as createServiceToken21 } from "@workglow/util";
|
|
4764
|
+
var IDB_VECTOR_REPOSITORY = createServiceToken21("storage.vectorRepository.indexedDb");
|
|
4765
|
+
function matchesFilter2(metadata, filter) {
|
|
4766
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
4767
|
+
if (metadata[key] !== value) {
|
|
4768
|
+
return false;
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
return true;
|
|
4772
|
+
}
|
|
4773
|
+
function textRelevance2(text, query) {
|
|
4774
|
+
const textLower = text.toLowerCase();
|
|
4775
|
+
const queryLower = query.toLowerCase();
|
|
4776
|
+
const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
|
|
4777
|
+
if (queryWords.length === 0) {
|
|
4778
|
+
return 0;
|
|
4779
|
+
}
|
|
4780
|
+
let matches = 0;
|
|
4781
|
+
for (const word of queryWords) {
|
|
4782
|
+
if (textLower.includes(word)) {
|
|
4783
|
+
matches++;
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
return matches / queryWords.length;
|
|
4787
|
+
}
|
|
4788
|
+
|
|
4789
|
+
class IndexedDbVectorStorage extends IndexedDbTabularStorage {
|
|
4790
|
+
vectorDimensions;
|
|
4791
|
+
VectorType;
|
|
4792
|
+
vectorPropertyName;
|
|
4793
|
+
metadataPropertyName;
|
|
4794
|
+
constructor(table = "vectors", schema, primaryKeyNames, indexes = [], dimensions, VectorType = Float32Array, migrationOptions = {}, clientProvidedKeys = "if-missing") {
|
|
4795
|
+
super(table, schema, primaryKeyNames, indexes, migrationOptions, clientProvidedKeys);
|
|
4796
|
+
this.vectorDimensions = dimensions;
|
|
4797
|
+
this.VectorType = VectorType;
|
|
4798
|
+
const vectorProp = getVectorProperty(schema);
|
|
4799
|
+
if (!vectorProp) {
|
|
4800
|
+
throw new Error("Schema must have a property with type array and format TypedArray");
|
|
4801
|
+
}
|
|
4802
|
+
this.vectorPropertyName = vectorProp;
|
|
4803
|
+
this.metadataPropertyName = getMetadataProperty(schema);
|
|
4804
|
+
}
|
|
4805
|
+
getVectorDimensions() {
|
|
4806
|
+
return this.vectorDimensions;
|
|
4807
|
+
}
|
|
4808
|
+
async similaritySearch(query, options = {}) {
|
|
4809
|
+
const { topK = 10, filter, scoreThreshold = 0 } = options;
|
|
4810
|
+
const results = [];
|
|
4811
|
+
const allEntities = await this.getAll() || [];
|
|
4812
|
+
for (const entity of allEntities) {
|
|
4813
|
+
const vector = entity[this.vectorPropertyName];
|
|
4814
|
+
const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
|
|
4815
|
+
if (filter && !matchesFilter2(metadata, filter)) {
|
|
4816
|
+
continue;
|
|
4817
|
+
}
|
|
4818
|
+
const score = cosineSimilarity2(query, vector);
|
|
4819
|
+
if (score < scoreThreshold) {
|
|
4820
|
+
continue;
|
|
4821
|
+
}
|
|
4822
|
+
results.push({
|
|
4823
|
+
...entity,
|
|
4824
|
+
score
|
|
4825
|
+
});
|
|
4826
|
+
}
|
|
4827
|
+
results.sort((a, b) => b.score - a.score);
|
|
4828
|
+
const topResults = results.slice(0, topK);
|
|
4829
|
+
return topResults;
|
|
4830
|
+
}
|
|
4831
|
+
async hybridSearch(query, options) {
|
|
4832
|
+
const { topK = 10, filter, scoreThreshold = 0, textQuery, vectorWeight = 0.7 } = options;
|
|
4833
|
+
if (!textQuery || textQuery.trim().length === 0) {
|
|
4834
|
+
return this.similaritySearch(query, { topK, filter, scoreThreshold });
|
|
4835
|
+
}
|
|
4836
|
+
const results = [];
|
|
4837
|
+
const allEntities = await this.getAll() || [];
|
|
4838
|
+
for (const entity of allEntities) {
|
|
4839
|
+
const vector = entity[this.vectorPropertyName];
|
|
4840
|
+
const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
|
|
4841
|
+
if (filter && !matchesFilter2(metadata, filter)) {
|
|
4842
|
+
continue;
|
|
4843
|
+
}
|
|
4844
|
+
const vectorScore = cosineSimilarity2(query, vector);
|
|
4845
|
+
const metadataText = Object.values(metadata).join(" ").toLowerCase();
|
|
4846
|
+
const textScore = textRelevance2(metadataText, textQuery);
|
|
4847
|
+
const combinedScore = vectorWeight * vectorScore + (1 - vectorWeight) * textScore;
|
|
4848
|
+
if (combinedScore < scoreThreshold) {
|
|
4849
|
+
continue;
|
|
4850
|
+
}
|
|
4851
|
+
results.push({
|
|
4852
|
+
...entity,
|
|
4853
|
+
score: combinedScore
|
|
4854
|
+
});
|
|
4855
|
+
}
|
|
4856
|
+
results.sort((a, b) => b.score - a.score);
|
|
4857
|
+
const topResults = results.slice(0, topK);
|
|
4858
|
+
return topResults;
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4736
4861
|
export {
|
|
4737
4862
|
registerTabularRepository,
|
|
4738
4863
|
isSearchCondition,
|
|
@@ -4763,6 +4888,7 @@ export {
|
|
|
4763
4888
|
KvStorage,
|
|
4764
4889
|
KV_REPOSITORY,
|
|
4765
4890
|
JobStatus,
|
|
4891
|
+
IndexedDbVectorStorage,
|
|
4766
4892
|
IndexedDbTabularStorage,
|
|
4767
4893
|
IndexedDbRateLimiterStorage,
|
|
4768
4894
|
IndexedDbQueueStorage,
|
|
@@ -4776,6 +4902,7 @@ export {
|
|
|
4776
4902
|
IN_MEMORY_QUEUE_STORAGE,
|
|
4777
4903
|
INDEXED_DB_RATE_LIMITER_STORAGE,
|
|
4778
4904
|
INDEXED_DB_QUEUE_STORAGE,
|
|
4905
|
+
IDB_VECTOR_REPOSITORY,
|
|
4779
4906
|
IDB_TABULAR_REPOSITORY,
|
|
4780
4907
|
IDB_KV_REPOSITORY,
|
|
4781
4908
|
HybridSubscriptionManager,
|
|
@@ -4788,4 +4915,4 @@ export {
|
|
|
4788
4915
|
BaseTabularStorage
|
|
4789
4916
|
};
|
|
4790
4917
|
|
|
4791
|
-
//# debugId=
|
|
4918
|
+
//# debugId=E59320A7A95CC7EE64756E2164756E21
|