@mastra/pg 0.3.1-alpha.3 → 0.3.1-alpha.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.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +18 -0
- package/dist/_tsup-dts-rollup.d.cts +20 -12
- package/dist/_tsup-dts-rollup.d.ts +20 -12
- package/dist/index.cjs +210 -48
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +210 -49
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/storage/index.test.ts +216 -45
- package/src/storage/index.ts +143 -66
- package/src/vector/index.ts +1 -0
- package/src/vector/prompt.ts +101 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.3.1-alpha.
|
|
2
|
+
> @mastra/pg@0.3.1-alpha.5 build /home/runner/work/mastra/mastra/stores/pg
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 11112ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
|
-
Analysis will use the bundled TypeScript version 5.8.
|
|
12
|
+
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
|
-
Analysis will use the bundled TypeScript version 5.8.
|
|
14
|
+
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 12313ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m54.79 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1406ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m54.31 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1407ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.3.1-alpha.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3e7b69d: Dynamic agent props
|
|
8
|
+
- 5f826d9: Moved vector store specific prompts from @mastra/rag to be exported from the store that the prompt belongs to, ie @mastra/pg
|
|
9
|
+
- Updated dependencies [3e7b69d]
|
|
10
|
+
- @mastra/core@0.9.1-alpha.5
|
|
11
|
+
|
|
12
|
+
## 0.3.1-alpha.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 479f490: [MASTRA-3131] Add getWorkflowRunByID and add resourceId as filter for getWorkflowRuns
|
|
17
|
+
- Updated dependencies [e4943b8]
|
|
18
|
+
- Updated dependencies [479f490]
|
|
19
|
+
- @mastra/core@0.9.1-alpha.4
|
|
20
|
+
|
|
3
21
|
## 0.3.1-alpha.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -25,6 +25,8 @@ import type { StorageThreadType } from '@mastra/core/memory';
|
|
|
25
25
|
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
26
26
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
27
27
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
28
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
29
|
+
import type { WorkflowRuns } from '@mastra/core/storage';
|
|
28
30
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
29
31
|
|
|
30
32
|
export declare const baseTestConfigs: {
|
|
@@ -247,6 +249,14 @@ declare class PgVector extends MastraVector {
|
|
|
247
249
|
export { PgVector }
|
|
248
250
|
export { PgVector as PgVector_alias_1 }
|
|
249
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
254
|
+
* This prompt helps users construct valid filters for PG Vector.
|
|
255
|
+
*/
|
|
256
|
+
declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Direct RegExp patterns will throw an error\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Basic operators handle array values as JSON strings\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$contains\": \"value\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
257
|
+
export { PGVECTOR_PROMPT }
|
|
258
|
+
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
259
|
+
|
|
250
260
|
declare type PostgresConfig = {
|
|
251
261
|
schemaName?: string;
|
|
252
262
|
/**
|
|
@@ -321,7 +331,7 @@ declare class PostgresStore extends MastraStorage {
|
|
|
321
331
|
deleteThread({ threadId }: {
|
|
322
332
|
threadId: string;
|
|
323
333
|
}): Promise<void>;
|
|
324
|
-
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
334
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
|
|
325
335
|
saveMessages({ messages }: {
|
|
326
336
|
messages: MessageType[];
|
|
327
337
|
}): Promise<MessageType[]>;
|
|
@@ -334,22 +344,20 @@ declare class PostgresStore extends MastraStorage {
|
|
|
334
344
|
workflowName: string;
|
|
335
345
|
runId: string;
|
|
336
346
|
}): Promise<WorkflowRunState | null>;
|
|
337
|
-
|
|
347
|
+
private hasColumn;
|
|
348
|
+
private parseWorkflowRun;
|
|
349
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
|
|
338
350
|
workflowName?: string;
|
|
339
351
|
fromDate?: Date;
|
|
340
352
|
toDate?: Date;
|
|
341
353
|
limit?: number;
|
|
342
354
|
offset?: number;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
updatedAt: Date;
|
|
350
|
-
}>;
|
|
351
|
-
total: number;
|
|
352
|
-
}>;
|
|
355
|
+
resourceId?: string;
|
|
356
|
+
}): Promise<WorkflowRuns>;
|
|
357
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
358
|
+
runId: string;
|
|
359
|
+
workflowName?: string;
|
|
360
|
+
}): Promise<WorkflowRun | null>;
|
|
353
361
|
close(): Promise<void>;
|
|
354
362
|
}
|
|
355
363
|
export { PostgresStore }
|
|
@@ -25,6 +25,8 @@ import type { StorageThreadType } from '@mastra/core/memory';
|
|
|
25
25
|
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
26
26
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
27
27
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
28
|
+
import type { WorkflowRun } from '@mastra/core/storage';
|
|
29
|
+
import type { WorkflowRuns } from '@mastra/core/storage';
|
|
28
30
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
29
31
|
|
|
30
32
|
export declare const baseTestConfigs: {
|
|
@@ -247,6 +249,14 @@ declare class PgVector extends MastraVector {
|
|
|
247
249
|
export { PgVector }
|
|
248
250
|
export { PgVector as PgVector_alias_1 }
|
|
249
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
254
|
+
* This prompt helps users construct valid filters for PG Vector.
|
|
255
|
+
*/
|
|
256
|
+
declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Direct RegExp patterns will throw an error\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Basic operators handle array values as JSON strings\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$contains\": \"value\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
257
|
+
export { PGVECTOR_PROMPT }
|
|
258
|
+
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
259
|
+
|
|
250
260
|
declare type PostgresConfig = {
|
|
251
261
|
schemaName?: string;
|
|
252
262
|
/**
|
|
@@ -321,7 +331,7 @@ declare class PostgresStore extends MastraStorage {
|
|
|
321
331
|
deleteThread({ threadId }: {
|
|
322
332
|
threadId: string;
|
|
323
333
|
}): Promise<void>;
|
|
324
|
-
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T>;
|
|
334
|
+
getMessages<T = unknown>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
|
|
325
335
|
saveMessages({ messages }: {
|
|
326
336
|
messages: MessageType[];
|
|
327
337
|
}): Promise<MessageType[]>;
|
|
@@ -334,22 +344,20 @@ declare class PostgresStore extends MastraStorage {
|
|
|
334
344
|
workflowName: string;
|
|
335
345
|
runId: string;
|
|
336
346
|
}): Promise<WorkflowRunState | null>;
|
|
337
|
-
|
|
347
|
+
private hasColumn;
|
|
348
|
+
private parseWorkflowRun;
|
|
349
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
|
|
338
350
|
workflowName?: string;
|
|
339
351
|
fromDate?: Date;
|
|
340
352
|
toDate?: Date;
|
|
341
353
|
limit?: number;
|
|
342
354
|
offset?: number;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
updatedAt: Date;
|
|
350
|
-
}>;
|
|
351
|
-
total: number;
|
|
352
|
-
}>;
|
|
355
|
+
resourceId?: string;
|
|
356
|
+
}): Promise<WorkflowRuns>;
|
|
357
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
358
|
+
runId: string;
|
|
359
|
+
workflowName?: string;
|
|
360
|
+
}): Promise<WorkflowRun | null>;
|
|
353
361
|
close(): Promise<void>;
|
|
354
362
|
}
|
|
355
363
|
export { PostgresStore }
|
package/dist/index.cjs
CHANGED
|
@@ -1416,71 +1416,233 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
1416
1416
|
throw error;
|
|
1417
1417
|
}
|
|
1418
1418
|
}
|
|
1419
|
+
async hasColumn(table, column) {
|
|
1420
|
+
const schema = this.schema || "public";
|
|
1421
|
+
const result = await this.db.oneOrNone(
|
|
1422
|
+
`SELECT 1 FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4)`,
|
|
1423
|
+
[schema, table, column, column.toLowerCase()]
|
|
1424
|
+
);
|
|
1425
|
+
return !!result;
|
|
1426
|
+
}
|
|
1427
|
+
parseWorkflowRun(row) {
|
|
1428
|
+
let parsedSnapshot = row.snapshot;
|
|
1429
|
+
if (typeof parsedSnapshot === "string") {
|
|
1430
|
+
try {
|
|
1431
|
+
parsedSnapshot = JSON.parse(row.snapshot);
|
|
1432
|
+
} catch (e) {
|
|
1433
|
+
console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
return {
|
|
1437
|
+
workflowName: row.workflow_name,
|
|
1438
|
+
runId: row.run_id,
|
|
1439
|
+
snapshot: parsedSnapshot,
|
|
1440
|
+
createdAt: row.createdAt,
|
|
1441
|
+
updatedAt: row.updatedAt,
|
|
1442
|
+
resourceId: row.resourceId
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1419
1445
|
async getWorkflowRuns({
|
|
1420
1446
|
workflowName,
|
|
1421
1447
|
fromDate,
|
|
1422
1448
|
toDate,
|
|
1423
1449
|
limit,
|
|
1424
|
-
offset
|
|
1450
|
+
offset,
|
|
1451
|
+
resourceId
|
|
1425
1452
|
} = {}) {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
)
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1453
|
+
try {
|
|
1454
|
+
const conditions = [];
|
|
1455
|
+
const values = [];
|
|
1456
|
+
let paramIndex = 1;
|
|
1457
|
+
if (workflowName) {
|
|
1458
|
+
conditions.push(`workflow_name = $${paramIndex}`);
|
|
1459
|
+
values.push(workflowName);
|
|
1460
|
+
paramIndex++;
|
|
1461
|
+
}
|
|
1462
|
+
if (resourceId) {
|
|
1463
|
+
const hasResourceId = await this.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
|
|
1464
|
+
if (hasResourceId) {
|
|
1465
|
+
conditions.push(`"resourceId" = $${paramIndex}`);
|
|
1466
|
+
values.push(resourceId);
|
|
1467
|
+
paramIndex++;
|
|
1468
|
+
} else {
|
|
1469
|
+
console.warn(`[${storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (fromDate) {
|
|
1473
|
+
conditions.push(`"createdAt" >= $${paramIndex}`);
|
|
1474
|
+
values.push(fromDate);
|
|
1475
|
+
paramIndex++;
|
|
1476
|
+
}
|
|
1477
|
+
if (toDate) {
|
|
1478
|
+
conditions.push(`"createdAt" <= $${paramIndex}`);
|
|
1479
|
+
values.push(toDate);
|
|
1480
|
+
paramIndex++;
|
|
1481
|
+
}
|
|
1482
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1483
|
+
let total = 0;
|
|
1484
|
+
if (limit !== void 0 && offset !== void 0) {
|
|
1485
|
+
const countResult = await this.db.one(
|
|
1486
|
+
`SELECT COUNT(*) as count FROM ${this.getTableName(storage.TABLE_WORKFLOW_SNAPSHOT)} ${whereClause}`,
|
|
1487
|
+
values
|
|
1488
|
+
);
|
|
1489
|
+
total = Number(countResult.count);
|
|
1490
|
+
}
|
|
1491
|
+
const query = `
|
|
1454
1492
|
SELECT * FROM ${this.getTableName(storage.TABLE_WORKFLOW_SNAPSHOT)}
|
|
1455
1493
|
${whereClause}
|
|
1456
1494
|
ORDER BY "createdAt" DESC
|
|
1457
1495
|
${limit !== void 0 && offset !== void 0 ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
|
|
1458
1496
|
`;
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1497
|
+
const queryValues = limit !== void 0 && offset !== void 0 ? [...values, limit, offset] : values;
|
|
1498
|
+
const result = await this.db.manyOrNone(query, queryValues);
|
|
1499
|
+
const runs = (result || []).map((row) => {
|
|
1500
|
+
return this.parseWorkflowRun(row);
|
|
1501
|
+
});
|
|
1502
|
+
return { runs, total: total || runs.length };
|
|
1503
|
+
} catch (error) {
|
|
1504
|
+
console.error("Error getting workflow runs:", error);
|
|
1505
|
+
throw error;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
async getWorkflowRunById({
|
|
1509
|
+
runId,
|
|
1510
|
+
workflowName
|
|
1511
|
+
}) {
|
|
1512
|
+
try {
|
|
1513
|
+
const conditions = [];
|
|
1514
|
+
const values = [];
|
|
1515
|
+
let paramIndex = 1;
|
|
1516
|
+
if (runId) {
|
|
1517
|
+
conditions.push(`run_id = $${paramIndex}`);
|
|
1518
|
+
values.push(runId);
|
|
1519
|
+
paramIndex++;
|
|
1469
1520
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1521
|
+
if (workflowName) {
|
|
1522
|
+
conditions.push(`workflow_name = $${paramIndex}`);
|
|
1523
|
+
values.push(workflowName);
|
|
1524
|
+
paramIndex++;
|
|
1525
|
+
}
|
|
1526
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1527
|
+
const query = `
|
|
1528
|
+
SELECT * FROM ${this.getTableName(storage.TABLE_WORKFLOW_SNAPSHOT)}
|
|
1529
|
+
${whereClause}
|
|
1530
|
+
`;
|
|
1531
|
+
const queryValues = values;
|
|
1532
|
+
const result = await this.db.oneOrNone(query, queryValues);
|
|
1533
|
+
if (!result) {
|
|
1534
|
+
return null;
|
|
1535
|
+
}
|
|
1536
|
+
return this.parseWorkflowRun(result);
|
|
1537
|
+
} catch (error) {
|
|
1538
|
+
console.error("Error getting workflow run by ID:", error);
|
|
1539
|
+
throw error;
|
|
1540
|
+
}
|
|
1479
1541
|
}
|
|
1480
1542
|
async close() {
|
|
1481
1543
|
this.pgp.end();
|
|
1482
1544
|
}
|
|
1483
1545
|
};
|
|
1484
1546
|
|
|
1547
|
+
// src/vector/prompt.ts
|
|
1548
|
+
var PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
1549
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
1550
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
1551
|
+
|
|
1552
|
+
Basic Comparison Operators:
|
|
1553
|
+
- $eq: Exact match (default when using field: value)
|
|
1554
|
+
Example: { "category": "electronics" }
|
|
1555
|
+
- $ne: Not equal
|
|
1556
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
1557
|
+
- $gt: Greater than
|
|
1558
|
+
Example: { "price": { "$gt": 100 } }
|
|
1559
|
+
- $gte: Greater than or equal
|
|
1560
|
+
Example: { "price": { "$gte": 100 } }
|
|
1561
|
+
- $lt: Less than
|
|
1562
|
+
Example: { "price": { "$lt": 100 } }
|
|
1563
|
+
- $lte: Less than or equal
|
|
1564
|
+
Example: { "price": { "$lte": 100 } }
|
|
1565
|
+
|
|
1566
|
+
Array Operators:
|
|
1567
|
+
- $in: Match any value in array
|
|
1568
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
1569
|
+
- $nin: Does not match any value in array
|
|
1570
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
1571
|
+
- $all: Match all values in array
|
|
1572
|
+
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
1573
|
+
- $elemMatch: Match array elements that meet all specified conditions
|
|
1574
|
+
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
|
|
1575
|
+
- $contains: Check if array contains value
|
|
1576
|
+
Example: { "tags": { "$contains": "premium" } }
|
|
1577
|
+
|
|
1578
|
+
Logical Operators:
|
|
1579
|
+
- $and: Logical AND (implicit when using multiple conditions)
|
|
1580
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
1581
|
+
- $or: Logical OR
|
|
1582
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
1583
|
+
- $not: Logical NOT
|
|
1584
|
+
Example: { "$not": { "category": "electronics" } }
|
|
1585
|
+
- $nor: Logical NOR
|
|
1586
|
+
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
1587
|
+
|
|
1588
|
+
Element Operators:
|
|
1589
|
+
- $exists: Check if field exists
|
|
1590
|
+
Example: { "rating": { "$exists": true } }
|
|
1591
|
+
|
|
1592
|
+
Special Operators:
|
|
1593
|
+
- $size: Array length check
|
|
1594
|
+
Example: { "tags": { "$size": 2 } }
|
|
1595
|
+
|
|
1596
|
+
Restrictions:
|
|
1597
|
+
- Regex patterns are not supported
|
|
1598
|
+
- Direct RegExp patterns will throw an error
|
|
1599
|
+
- Nested fields are supported using dot notation
|
|
1600
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
1601
|
+
- Array operations work on array fields only
|
|
1602
|
+
- Basic operators handle array values as JSON strings
|
|
1603
|
+
- Empty arrays in conditions are handled gracefully
|
|
1604
|
+
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
1605
|
+
- All other operators must be used within a field condition
|
|
1606
|
+
Valid: { "field": { "$gt": 100 } }
|
|
1607
|
+
Valid: { "$and": [...] }
|
|
1608
|
+
Invalid: { "$gt": 100 }
|
|
1609
|
+
Invalid: { "$contains": "value" }
|
|
1610
|
+
- Logical operators must contain field conditions, not direct operators
|
|
1611
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
1612
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
1613
|
+
- $not operator:
|
|
1614
|
+
- Must be an object
|
|
1615
|
+
- Cannot be empty
|
|
1616
|
+
- Can be used at field level or top level
|
|
1617
|
+
- Valid: { "$not": { "field": "value" } }
|
|
1618
|
+
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
1619
|
+
- Other logical operators ($and, $or, $nor):
|
|
1620
|
+
- Can only be used at top level or nested within other logical operators
|
|
1621
|
+
- Can not be used on a field level, or be nested inside a field
|
|
1622
|
+
- Can not be used inside an operator
|
|
1623
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
1624
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
1625
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
1626
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
1627
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
1628
|
+
- $elemMatch requires an object with conditions
|
|
1629
|
+
Valid: { "array": { "$elemMatch": { "field": "value" } } }
|
|
1630
|
+
Invalid: { "array": { "$elemMatch": "value" } }
|
|
1631
|
+
|
|
1632
|
+
Example Complex Query:
|
|
1633
|
+
{
|
|
1634
|
+
"$and": [
|
|
1635
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
1636
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
1637
|
+
{ "tags": { "$all": ["premium"] } },
|
|
1638
|
+
{ "rating": { "$exists": true, "$gt": 4 } },
|
|
1639
|
+
{ "$or": [
|
|
1640
|
+
{ "stock": { "$gt": 0 } },
|
|
1641
|
+
{ "preorder": true }
|
|
1642
|
+
]}
|
|
1643
|
+
]
|
|
1644
|
+
}`;
|
|
1645
|
+
|
|
1646
|
+
exports.PGVECTOR_PROMPT = PGVECTOR_PROMPT;
|
|
1485
1647
|
exports.PgVector = PgVector;
|
|
1486
1648
|
exports.PostgresStore = PostgresStore;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED