@mastra/libsql 0.0.1-alpha.3 → 0.0.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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/libsql@0.0.1-alpha.3 build /home/runner/work/mastra/mastra/stores/libsql
2
+ > @mastra/libsql@0.0.1-alpha.5 build /home/runner/work/mastra/mastra/stores/libsql
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 9435ms
9
+ TSC ⚡️ Build success in 9438ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
- Analysis will use the bundled TypeScript version 5.8.2
12
+ Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.ts
14
- Analysis will use the bundled TypeScript version 5.8.2
14
+ Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/libsql/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 8455ms
16
+ DTS ⚡️ Build success in 11373ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 35.92 KB
21
- CJS ⚡️ Build success in 767ms
22
- ESM dist/index.js 35.84 KB
23
- ESM ⚡️ Build success in 768ms
20
+ ESM dist/index.js 41.28 KB
21
+ ESM ⚡️ Build success in 1118ms
22
+ CJS dist/index.cjs 41.41 KB
23
+ CJS ⚡️ Build success in 1119ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @mastra/libsql
2
2
 
3
+ ## 0.0.1-alpha.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 5f826d9: Moved vector store specific prompts from @mastra/rag to be exported from the store that the prompt belongs to, ie @mastra/pg
8
+ - Updated dependencies [3e7b69d]
9
+ - @mastra/core@0.9.1-alpha.5
10
+
11
+ ## 0.0.1-alpha.4
12
+
13
+ ### Patch Changes
14
+
15
+ - 479f490: [MASTRA-3131] Add getWorkflowRunByID and add resourceId as filter for getWorkflowRuns
16
+ - Updated dependencies [e4943b8]
17
+ - Updated dependencies [479f490]
18
+ - @mastra/core@0.9.1-alpha.4
19
+
3
20
  ## 0.0.1-alpha.3
4
21
 
5
22
  ### Patch Changes
@@ -23,7 +23,8 @@ import type { StorageThreadType } from '@mastra/core/memory';
23
23
  import type { TABLE_NAMES } from '@mastra/core/storage';
24
24
  import type { UpsertVectorParams } from '@mastra/core/vector';
25
25
  import type { VectorFilter } from '@mastra/core/vector/filter';
26
- import type { WorkflowRunState } from '@mastra/core/workflows';
26
+ import type { WorkflowRun } from '@mastra/core/storage';
27
+ import type { WorkflowRuns } from '@mastra/core/storage';
27
28
 
28
29
  export declare function buildFilterQuery(filter: VectorFilter): FilterResult;
29
30
 
@@ -42,6 +43,14 @@ export declare interface FilterResult {
42
43
 
43
44
  export declare const handleKey: (key: string) => string;
44
45
 
46
+ /**
47
+ * Vector store specific prompt that details supported operators and examples.
48
+ * This prompt helps users construct valid filters for LibSQL Vector.
49
+ */
50
+ declare const LIBSQL_PROMPT = "When querying LibSQL 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\", \"sale\"] } },\n { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 50 }, \"inStock\": true } } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
51
+ export { LIBSQL_PROMPT }
52
+ export { LIBSQL_PROMPT as LIBSQL_PROMPT_alias_1 }
53
+
45
54
  declare interface LibSQLConfig {
46
55
  url: string;
47
56
  authToken?: string;
@@ -127,22 +136,20 @@ declare class LibSQLStore extends MastraStorage {
127
136
  attributes?: Record<string, string>;
128
137
  filters?: Record<string, any>;
129
138
  }): Promise<any[]>;
130
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
139
+ getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
131
140
  workflowName?: string;
132
141
  fromDate?: Date;
133
142
  toDate?: Date;
134
143
  limit?: number;
135
144
  offset?: number;
136
- }): Promise<{
137
- runs: Array<{
138
- workflowName: string;
139
- runId: string;
140
- snapshot: WorkflowRunState | string;
141
- createdAt: Date;
142
- updatedAt: Date;
143
- }>;
144
- total: number;
145
- }>;
145
+ resourceId?: string;
146
+ }): Promise<WorkflowRuns>;
147
+ getWorkflowRunById({ runId, workflowName, }: {
148
+ runId: string;
149
+ workflowName?: string;
150
+ }): Promise<WorkflowRun | null>;
151
+ private hasColumn;
152
+ private parseWorkflowRun;
146
153
  }
147
154
  export { LibSQLStore as DefaultStorage }
148
155
  export { LibSQLStore as DefaultStorage_alias_1 }
@@ -23,7 +23,8 @@ import type { StorageThreadType } from '@mastra/core/memory';
23
23
  import type { TABLE_NAMES } from '@mastra/core/storage';
24
24
  import type { UpsertVectorParams } from '@mastra/core/vector';
25
25
  import type { VectorFilter } from '@mastra/core/vector/filter';
26
- import type { WorkflowRunState } from '@mastra/core/workflows';
26
+ import type { WorkflowRun } from '@mastra/core/storage';
27
+ import type { WorkflowRuns } from '@mastra/core/storage';
27
28
 
28
29
  export declare function buildFilterQuery(filter: VectorFilter): FilterResult;
29
30
 
@@ -42,6 +43,14 @@ export declare interface FilterResult {
42
43
 
43
44
  export declare const handleKey: (key: string) => string;
44
45
 
46
+ /**
47
+ * Vector store specific prompt that details supported operators and examples.
48
+ * This prompt helps users construct valid filters for LibSQL Vector.
49
+ */
50
+ declare const LIBSQL_PROMPT = "When querying LibSQL 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\", \"sale\"] } },\n { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 50 }, \"inStock\": true } } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
51
+ export { LIBSQL_PROMPT }
52
+ export { LIBSQL_PROMPT as LIBSQL_PROMPT_alias_1 }
53
+
45
54
  declare interface LibSQLConfig {
46
55
  url: string;
47
56
  authToken?: string;
@@ -127,22 +136,20 @@ declare class LibSQLStore extends MastraStorage {
127
136
  attributes?: Record<string, string>;
128
137
  filters?: Record<string, any>;
129
138
  }): Promise<any[]>;
130
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, }?: {
139
+ getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
131
140
  workflowName?: string;
132
141
  fromDate?: Date;
133
142
  toDate?: Date;
134
143
  limit?: number;
135
144
  offset?: number;
136
- }): Promise<{
137
- runs: Array<{
138
- workflowName: string;
139
- runId: string;
140
- snapshot: WorkflowRunState | string;
141
- createdAt: Date;
142
- updatedAt: Date;
143
- }>;
144
- total: number;
145
- }>;
145
+ resourceId?: string;
146
+ }): Promise<WorkflowRuns>;
147
+ getWorkflowRunById({ runId, workflowName, }: {
148
+ runId: string;
149
+ workflowName?: string;
150
+ }): Promise<WorkflowRun | null>;
151
+ private hasColumn;
152
+ private parseWorkflowRun;
146
153
  }
147
154
  export { LibSQLStore as DefaultStorage }
148
155
  export { LibSQLStore as DefaultStorage_alias_1 }
package/dist/index.cjs CHANGED
@@ -1088,56 +1088,203 @@ var LibSQLStore = class extends storage.MastraStorage {
1088
1088
  fromDate,
1089
1089
  toDate,
1090
1090
  limit,
1091
- offset
1091
+ offset,
1092
+ resourceId
1092
1093
  } = {}) {
1094
+ try {
1095
+ const conditions = [];
1096
+ const args = [];
1097
+ if (workflowName) {
1098
+ conditions.push("workflow_name = ?");
1099
+ args.push(workflowName);
1100
+ }
1101
+ if (fromDate) {
1102
+ conditions.push("createdAt >= ?");
1103
+ args.push(fromDate.toISOString());
1104
+ }
1105
+ if (toDate) {
1106
+ conditions.push("createdAt <= ?");
1107
+ args.push(toDate.toISOString());
1108
+ }
1109
+ if (resourceId) {
1110
+ const hasResourceId = await this.hasColumn(storage.TABLE_WORKFLOW_SNAPSHOT, "resourceId");
1111
+ if (hasResourceId) {
1112
+ conditions.push("resourceId = ?");
1113
+ args.push(resourceId);
1114
+ } else {
1115
+ console.warn(`[${storage.TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
1116
+ }
1117
+ }
1118
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1119
+ let total = 0;
1120
+ if (limit !== void 0 && offset !== void 0) {
1121
+ const countResult = await this.client.execute({
1122
+ sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1123
+ args
1124
+ });
1125
+ total = Number(countResult.rows?.[0]?.count ?? 0);
1126
+ }
1127
+ const result = await this.client.execute({
1128
+ sql: `SELECT * FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause} ORDER BY createdAt DESC${limit !== void 0 && offset !== void 0 ? ` LIMIT ? OFFSET ?` : ""}`,
1129
+ args: limit !== void 0 && offset !== void 0 ? [...args, limit, offset] : args
1130
+ });
1131
+ const runs = (result.rows || []).map((row) => this.parseWorkflowRun(row));
1132
+ return { runs, total: total || runs.length };
1133
+ } catch (error) {
1134
+ console.error("Error getting workflow runs:", error);
1135
+ throw error;
1136
+ }
1137
+ }
1138
+ async getWorkflowRunById({
1139
+ runId,
1140
+ workflowName
1141
+ }) {
1093
1142
  const conditions = [];
1094
1143
  const args = [];
1144
+ if (runId) {
1145
+ conditions.push("run_id = ?");
1146
+ args.push(runId);
1147
+ }
1095
1148
  if (workflowName) {
1096
1149
  conditions.push("workflow_name = ?");
1097
1150
  args.push(workflowName);
1098
1151
  }
1099
- if (fromDate) {
1100
- conditions.push("createdAt >= ?");
1101
- args.push(fromDate.toISOString());
1102
- }
1103
- if (toDate) {
1104
- conditions.push("createdAt <= ?");
1105
- args.push(toDate.toISOString());
1106
- }
1107
1152
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1108
- let total = 0;
1109
- if (limit !== void 0 && offset !== void 0) {
1110
- const countResult = await this.client.execute({
1111
- sql: `SELECT COUNT(*) as count FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1112
- args
1113
- });
1114
- total = Number(countResult.rows?.[0]?.count ?? 0);
1153
+ const result = await this.client.execute({
1154
+ sql: `SELECT * FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1155
+ args
1156
+ });
1157
+ if (!result.rows?.[0]) {
1158
+ return null;
1115
1159
  }
1160
+ return this.parseWorkflowRun(result.rows[0]);
1161
+ }
1162
+ async hasColumn(table, column) {
1116
1163
  const result = await this.client.execute({
1117
- sql: `SELECT * FROM ${storage.TABLE_WORKFLOW_SNAPSHOT} ${whereClause} ORDER BY createdAt DESC${limit !== void 0 && offset !== void 0 ? ` LIMIT ? OFFSET ?` : ""}`,
1118
- args: limit !== void 0 && offset !== void 0 ? [...args, limit, offset] : args
1164
+ sql: `PRAGMA table_info(${table})`
1119
1165
  });
1120
- const runs = (result.rows || []).map((row) => {
1121
- let parsedSnapshot = row.snapshot;
1122
- if (typeof parsedSnapshot === "string") {
1123
- try {
1124
- parsedSnapshot = JSON.parse(row.snapshot);
1125
- } catch (e) {
1126
- console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
1127
- }
1166
+ return (await result.rows)?.some((row) => row.name === column);
1167
+ }
1168
+ parseWorkflowRun(row) {
1169
+ let parsedSnapshot = row.snapshot;
1170
+ if (typeof parsedSnapshot === "string") {
1171
+ try {
1172
+ parsedSnapshot = JSON.parse(row.snapshot);
1173
+ } catch (e) {
1174
+ console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
1128
1175
  }
1129
- return {
1130
- workflowName: row.workflow_name,
1131
- runId: row.run_id,
1132
- snapshot: parsedSnapshot,
1133
- createdAt: new Date(row.createdAt),
1134
- updatedAt: new Date(row.updatedAt)
1135
- };
1136
- });
1137
- return { runs, total: total || runs.length };
1176
+ }
1177
+ return {
1178
+ workflowName: row.workflow_name,
1179
+ runId: row.run_id,
1180
+ snapshot: parsedSnapshot,
1181
+ resourceId: row.resourceId,
1182
+ createdAt: new Date(row.created_at),
1183
+ updatedAt: new Date(row.updated_at)
1184
+ };
1138
1185
  }
1139
1186
  };
1140
1187
 
1188
+ // src/vector/prompt.ts
1189
+ var LIBSQL_PROMPT = `When querying LibSQL Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
1190
+ Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
1191
+ 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.
1192
+
1193
+ Basic Comparison Operators:
1194
+ - $eq: Exact match (default when using field: value)
1195
+ Example: { "category": "electronics" }
1196
+ - $ne: Not equal
1197
+ Example: { "category": { "$ne": "electronics" } }
1198
+ - $gt: Greater than
1199
+ Example: { "price": { "$gt": 100 } }
1200
+ - $gte: Greater than or equal
1201
+ Example: { "price": { "$gte": 100 } }
1202
+ - $lt: Less than
1203
+ Example: { "price": { "$lt": 100 } }
1204
+ - $lte: Less than or equal
1205
+ Example: { "price": { "$lte": 100 } }
1206
+
1207
+ Array Operators:
1208
+ - $in: Match any value in array
1209
+ Example: { "category": { "$in": ["electronics", "books"] } }
1210
+ - $nin: Does not match any value in array
1211
+ Example: { "category": { "$nin": ["electronics", "books"] } }
1212
+ - $all: Match all values in array
1213
+ Example: { "tags": { "$all": ["premium", "sale"] } }
1214
+ - $elemMatch: Match array elements that meet all specified conditions
1215
+ Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
1216
+ - $contains: Check if array contains value
1217
+ Example: { "tags": { "$contains": "premium" } }
1218
+
1219
+ Logical Operators:
1220
+ - $and: Logical AND (implicit when using multiple conditions)
1221
+ Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
1222
+ - $or: Logical OR
1223
+ Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
1224
+ - $not: Logical NOT
1225
+ Example: { "$not": { "category": "electronics" } }
1226
+ - $nor: Logical NOR
1227
+ Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
1228
+
1229
+ Element Operators:
1230
+ - $exists: Check if field exists
1231
+ Example: { "rating": { "$exists": true } }
1232
+
1233
+ Special Operators:
1234
+ - $size: Array length check
1235
+ Example: { "tags": { "$size": 2 } }
1236
+
1237
+ Restrictions:
1238
+ - Regex patterns are not supported
1239
+ - Direct RegExp patterns will throw an error
1240
+ - Nested fields are supported using dot notation
1241
+ - Multiple conditions on the same field are supported with both implicit and explicit $and
1242
+ - Array operations work on array fields only
1243
+ - Basic operators handle array values as JSON strings
1244
+ - Empty arrays in conditions are handled gracefully
1245
+ - Only logical operators ($and, $or, $not, $nor) can be used at the top level
1246
+ - All other operators must be used within a field condition
1247
+ Valid: { "field": { "$gt": 100 } }
1248
+ Valid: { "$and": [...] }
1249
+ Invalid: { "$gt": 100 }
1250
+ Invalid: { "$contains": "value" }
1251
+ - Logical operators must contain field conditions, not direct operators
1252
+ Valid: { "$and": [{ "field": { "$gt": 100 } }] }
1253
+ Invalid: { "$and": [{ "$gt": 100 }] }
1254
+ - $not operator:
1255
+ - Must be an object
1256
+ - Cannot be empty
1257
+ - Can be used at field level or top level
1258
+ - Valid: { "$not": { "field": "value" } }
1259
+ - Valid: { "field": { "$not": { "$eq": "value" } } }
1260
+ - Other logical operators ($and, $or, $nor):
1261
+ - Can only be used at top level or nested within other logical operators
1262
+ - Can not be used on a field level, or be nested inside a field
1263
+ - Can not be used inside an operator
1264
+ - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
1265
+ - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
1266
+ - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
1267
+ - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
1268
+ - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
1269
+ - $elemMatch requires an object with conditions
1270
+ Valid: { "array": { "$elemMatch": { "field": "value" } } }
1271
+ Invalid: { "array": { "$elemMatch": "value" } }
1272
+
1273
+ Example Complex Query:
1274
+ {
1275
+ "$and": [
1276
+ { "category": { "$in": ["electronics", "computers"] } },
1277
+ { "price": { "$gte": 100, "$lte": 1000 } },
1278
+ { "tags": { "$all": ["premium", "sale"] } },
1279
+ { "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
1280
+ { "$or": [
1281
+ { "stock": { "$gt": 0 } },
1282
+ { "preorder": true }
1283
+ ]}
1284
+ ]
1285
+ }`;
1286
+
1141
1287
  exports.DefaultStorage = LibSQLStore;
1288
+ exports.LIBSQL_PROMPT = LIBSQL_PROMPT;
1142
1289
  exports.LibSQLStore = LibSQLStore;
1143
1290
  exports.LibSQLVector = LibSQLVector;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ export { LIBSQL_PROMPT } from './_tsup-dts-rollup.cjs';
1
2
  export { LibSQLVector } from './_tsup-dts-rollup.cjs';
2
3
  export { LibSQLConfig } from './_tsup-dts-rollup.cjs';
3
4
  export { LibSQLStore } from './_tsup-dts-rollup.cjs';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { LIBSQL_PROMPT } from './_tsup-dts-rollup.js';
1
2
  export { LibSQLVector } from './_tsup-dts-rollup.js';
2
3
  export { LibSQLConfig } from './_tsup-dts-rollup.js';
3
4
  export { LibSQLStore } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -1086,54 +1086,200 @@ var LibSQLStore = class extends MastraStorage {
1086
1086
  fromDate,
1087
1087
  toDate,
1088
1088
  limit,
1089
- offset
1089
+ offset,
1090
+ resourceId
1090
1091
  } = {}) {
1092
+ try {
1093
+ const conditions = [];
1094
+ const args = [];
1095
+ if (workflowName) {
1096
+ conditions.push("workflow_name = ?");
1097
+ args.push(workflowName);
1098
+ }
1099
+ if (fromDate) {
1100
+ conditions.push("createdAt >= ?");
1101
+ args.push(fromDate.toISOString());
1102
+ }
1103
+ if (toDate) {
1104
+ conditions.push("createdAt <= ?");
1105
+ args.push(toDate.toISOString());
1106
+ }
1107
+ if (resourceId) {
1108
+ const hasResourceId = await this.hasColumn(TABLE_WORKFLOW_SNAPSHOT, "resourceId");
1109
+ if (hasResourceId) {
1110
+ conditions.push("resourceId = ?");
1111
+ args.push(resourceId);
1112
+ } else {
1113
+ console.warn(`[${TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
1114
+ }
1115
+ }
1116
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1117
+ let total = 0;
1118
+ if (limit !== void 0 && offset !== void 0) {
1119
+ const countResult = await this.client.execute({
1120
+ sql: `SELECT COUNT(*) as count FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1121
+ args
1122
+ });
1123
+ total = Number(countResult.rows?.[0]?.count ?? 0);
1124
+ }
1125
+ const result = await this.client.execute({
1126
+ sql: `SELECT * FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause} ORDER BY createdAt DESC${limit !== void 0 && offset !== void 0 ? ` LIMIT ? OFFSET ?` : ""}`,
1127
+ args: limit !== void 0 && offset !== void 0 ? [...args, limit, offset] : args
1128
+ });
1129
+ const runs = (result.rows || []).map((row) => this.parseWorkflowRun(row));
1130
+ return { runs, total: total || runs.length };
1131
+ } catch (error) {
1132
+ console.error("Error getting workflow runs:", error);
1133
+ throw error;
1134
+ }
1135
+ }
1136
+ async getWorkflowRunById({
1137
+ runId,
1138
+ workflowName
1139
+ }) {
1091
1140
  const conditions = [];
1092
1141
  const args = [];
1142
+ if (runId) {
1143
+ conditions.push("run_id = ?");
1144
+ args.push(runId);
1145
+ }
1093
1146
  if (workflowName) {
1094
1147
  conditions.push("workflow_name = ?");
1095
1148
  args.push(workflowName);
1096
1149
  }
1097
- if (fromDate) {
1098
- conditions.push("createdAt >= ?");
1099
- args.push(fromDate.toISOString());
1100
- }
1101
- if (toDate) {
1102
- conditions.push("createdAt <= ?");
1103
- args.push(toDate.toISOString());
1104
- }
1105
1150
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
1106
- let total = 0;
1107
- if (limit !== void 0 && offset !== void 0) {
1108
- const countResult = await this.client.execute({
1109
- sql: `SELECT COUNT(*) as count FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1110
- args
1111
- });
1112
- total = Number(countResult.rows?.[0]?.count ?? 0);
1151
+ const result = await this.client.execute({
1152
+ sql: `SELECT * FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
1153
+ args
1154
+ });
1155
+ if (!result.rows?.[0]) {
1156
+ return null;
1113
1157
  }
1158
+ return this.parseWorkflowRun(result.rows[0]);
1159
+ }
1160
+ async hasColumn(table, column) {
1114
1161
  const result = await this.client.execute({
1115
- sql: `SELECT * FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause} ORDER BY createdAt DESC${limit !== void 0 && offset !== void 0 ? ` LIMIT ? OFFSET ?` : ""}`,
1116
- args: limit !== void 0 && offset !== void 0 ? [...args, limit, offset] : args
1162
+ sql: `PRAGMA table_info(${table})`
1117
1163
  });
1118
- const runs = (result.rows || []).map((row) => {
1119
- let parsedSnapshot = row.snapshot;
1120
- if (typeof parsedSnapshot === "string") {
1121
- try {
1122
- parsedSnapshot = JSON.parse(row.snapshot);
1123
- } catch (e) {
1124
- console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
1125
- }
1164
+ return (await result.rows)?.some((row) => row.name === column);
1165
+ }
1166
+ parseWorkflowRun(row) {
1167
+ let parsedSnapshot = row.snapshot;
1168
+ if (typeof parsedSnapshot === "string") {
1169
+ try {
1170
+ parsedSnapshot = JSON.parse(row.snapshot);
1171
+ } catch (e) {
1172
+ console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
1126
1173
  }
1127
- return {
1128
- workflowName: row.workflow_name,
1129
- runId: row.run_id,
1130
- snapshot: parsedSnapshot,
1131
- createdAt: new Date(row.createdAt),
1132
- updatedAt: new Date(row.updatedAt)
1133
- };
1134
- });
1135
- return { runs, total: total || runs.length };
1174
+ }
1175
+ return {
1176
+ workflowName: row.workflow_name,
1177
+ runId: row.run_id,
1178
+ snapshot: parsedSnapshot,
1179
+ resourceId: row.resourceId,
1180
+ createdAt: new Date(row.created_at),
1181
+ updatedAt: new Date(row.updated_at)
1182
+ };
1136
1183
  }
1137
1184
  };
1138
1185
 
1139
- export { LibSQLStore as DefaultStorage, LibSQLStore, LibSQLVector };
1186
+ // src/vector/prompt.ts
1187
+ var LIBSQL_PROMPT = `When querying LibSQL Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
1188
+ Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
1189
+ 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.
1190
+
1191
+ Basic Comparison Operators:
1192
+ - $eq: Exact match (default when using field: value)
1193
+ Example: { "category": "electronics" }
1194
+ - $ne: Not equal
1195
+ Example: { "category": { "$ne": "electronics" } }
1196
+ - $gt: Greater than
1197
+ Example: { "price": { "$gt": 100 } }
1198
+ - $gte: Greater than or equal
1199
+ Example: { "price": { "$gte": 100 } }
1200
+ - $lt: Less than
1201
+ Example: { "price": { "$lt": 100 } }
1202
+ - $lte: Less than or equal
1203
+ Example: { "price": { "$lte": 100 } }
1204
+
1205
+ Array Operators:
1206
+ - $in: Match any value in array
1207
+ Example: { "category": { "$in": ["electronics", "books"] } }
1208
+ - $nin: Does not match any value in array
1209
+ Example: { "category": { "$nin": ["electronics", "books"] } }
1210
+ - $all: Match all values in array
1211
+ Example: { "tags": { "$all": ["premium", "sale"] } }
1212
+ - $elemMatch: Match array elements that meet all specified conditions
1213
+ Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
1214
+ - $contains: Check if array contains value
1215
+ Example: { "tags": { "$contains": "premium" } }
1216
+
1217
+ Logical Operators:
1218
+ - $and: Logical AND (implicit when using multiple conditions)
1219
+ Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
1220
+ - $or: Logical OR
1221
+ Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
1222
+ - $not: Logical NOT
1223
+ Example: { "$not": { "category": "electronics" } }
1224
+ - $nor: Logical NOR
1225
+ Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
1226
+
1227
+ Element Operators:
1228
+ - $exists: Check if field exists
1229
+ Example: { "rating": { "$exists": true } }
1230
+
1231
+ Special Operators:
1232
+ - $size: Array length check
1233
+ Example: { "tags": { "$size": 2 } }
1234
+
1235
+ Restrictions:
1236
+ - Regex patterns are not supported
1237
+ - Direct RegExp patterns will throw an error
1238
+ - Nested fields are supported using dot notation
1239
+ - Multiple conditions on the same field are supported with both implicit and explicit $and
1240
+ - Array operations work on array fields only
1241
+ - Basic operators handle array values as JSON strings
1242
+ - Empty arrays in conditions are handled gracefully
1243
+ - Only logical operators ($and, $or, $not, $nor) can be used at the top level
1244
+ - All other operators must be used within a field condition
1245
+ Valid: { "field": { "$gt": 100 } }
1246
+ Valid: { "$and": [...] }
1247
+ Invalid: { "$gt": 100 }
1248
+ Invalid: { "$contains": "value" }
1249
+ - Logical operators must contain field conditions, not direct operators
1250
+ Valid: { "$and": [{ "field": { "$gt": 100 } }] }
1251
+ Invalid: { "$and": [{ "$gt": 100 }] }
1252
+ - $not operator:
1253
+ - Must be an object
1254
+ - Cannot be empty
1255
+ - Can be used at field level or top level
1256
+ - Valid: { "$not": { "field": "value" } }
1257
+ - Valid: { "field": { "$not": { "$eq": "value" } } }
1258
+ - Other logical operators ($and, $or, $nor):
1259
+ - Can only be used at top level or nested within other logical operators
1260
+ - Can not be used on a field level, or be nested inside a field
1261
+ - Can not be used inside an operator
1262
+ - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
1263
+ - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
1264
+ - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
1265
+ - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
1266
+ - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
1267
+ - $elemMatch requires an object with conditions
1268
+ Valid: { "array": { "$elemMatch": { "field": "value" } } }
1269
+ Invalid: { "array": { "$elemMatch": "value" } }
1270
+
1271
+ Example Complex Query:
1272
+ {
1273
+ "$and": [
1274
+ { "category": { "$in": ["electronics", "computers"] } },
1275
+ { "price": { "$gte": 100, "$lte": 1000 } },
1276
+ { "tags": { "$all": ["premium", "sale"] } },
1277
+ { "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
1278
+ { "$or": [
1279
+ { "stock": { "$gt": 0 } },
1280
+ { "preorder": true }
1281
+ ]}
1282
+ ]
1283
+ }`;
1284
+
1285
+ export { LibSQLStore as DefaultStorage, LIBSQL_PROMPT, LibSQLStore, LibSQLVector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/libsql",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.5",
4
4
  "description": "Libsql provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,17 +21,17 @@
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "@libsql/client": "^0.15.4",
24
- "@mastra/core": "^0.9.1-alpha.3"
24
+ "@mastra/core": "^0.9.1-alpha.5"
25
25
  },
26
26
  "devDependencies": {
27
- "@microsoft/api-extractor": "^7.52.1",
28
- "@types/node": "^20.17.27",
29
- "eslint": "^9.23.0",
27
+ "@microsoft/api-extractor": "^7.52.5",
28
+ "@types/node": "^20.17.32",
29
+ "eslint": "^9.25.1",
30
30
  "tsup": "^8.4.0",
31
- "typescript": "^5.8.2",
32
- "vitest": "^3.0.9",
33
- "@internal/lint": "0.0.2",
34
- "@internal/storage-test-utils": "0.0.1-alpha.2"
31
+ "typescript": "^5.8.3",
32
+ "vitest": "^3.1.2",
33
+ "@internal/storage-test-utils": "0.0.1-alpha.4",
34
+ "@internal/lint": "0.0.2"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './vector';
2
2
  export * from './storage';
3
+ export { LIBSQL_PROMPT } from './vector/prompt';
@@ -10,7 +10,14 @@ import {
10
10
  TABLE_WORKFLOW_SNAPSHOT,
11
11
  TABLE_EVALS,
12
12
  } from '@mastra/core/storage';
13
- import type { EvalRow, StorageColumn, StorageGetMessagesArg, TABLE_NAMES } from '@mastra/core/storage';
13
+ import type {
14
+ EvalRow,
15
+ StorageColumn,
16
+ StorageGetMessagesArg,
17
+ TABLE_NAMES,
18
+ WorkflowRun,
19
+ WorkflowRuns,
20
+ } from '@mastra/core/storage';
14
21
  import type { WorkflowRunState } from '@mastra/core/workflows';
15
22
 
16
23
  function safelyParseJSON(jsonString: string): any {
@@ -544,80 +551,131 @@ export class LibSQLStore extends MastraStorage {
544
551
  toDate,
545
552
  limit,
546
553
  offset,
554
+ resourceId,
547
555
  }: {
548
556
  workflowName?: string;
549
557
  fromDate?: Date;
550
558
  toDate?: Date;
551
559
  limit?: number;
552
560
  offset?: number;
553
- } = {}): Promise<{
554
- runs: Array<{
555
- workflowName: string;
556
- runId: string;
557
- snapshot: WorkflowRunState | string;
558
- createdAt: Date;
559
- updatedAt: Date;
560
- }>;
561
- total: number;
562
- }> {
563
- const conditions: string[] = [];
564
- const args: InValue[] = [];
561
+ resourceId?: string;
562
+ } = {}): Promise<WorkflowRuns> {
563
+ try {
564
+ const conditions: string[] = [];
565
+ const args: InValue[] = [];
565
566
 
566
- if (workflowName) {
567
- conditions.push('workflow_name = ?');
568
- args.push(workflowName);
567
+ if (workflowName) {
568
+ conditions.push('workflow_name = ?');
569
+ args.push(workflowName);
570
+ }
571
+
572
+ if (fromDate) {
573
+ conditions.push('createdAt >= ?');
574
+ args.push(fromDate.toISOString());
575
+ }
576
+
577
+ if (toDate) {
578
+ conditions.push('createdAt <= ?');
579
+ args.push(toDate.toISOString());
580
+ }
581
+
582
+ if (resourceId) {
583
+ const hasResourceId = await this.hasColumn(TABLE_WORKFLOW_SNAPSHOT, 'resourceId');
584
+ if (hasResourceId) {
585
+ conditions.push('resourceId = ?');
586
+ args.push(resourceId);
587
+ } else {
588
+ console.warn(`[${TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
589
+ }
590
+ }
591
+
592
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
593
+
594
+ let total = 0;
595
+ // Only get total count when using pagination
596
+ if (limit !== undefined && offset !== undefined) {
597
+ const countResult = await this.client.execute({
598
+ sql: `SELECT COUNT(*) as count FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
599
+ args,
600
+ });
601
+ total = Number(countResult.rows?.[0]?.count ?? 0);
602
+ }
603
+
604
+ // Get results
605
+ const result = await this.client.execute({
606
+ sql: `SELECT * FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause} ORDER BY createdAt DESC${limit !== undefined && offset !== undefined ? ` LIMIT ? OFFSET ?` : ''}`,
607
+ args: limit !== undefined && offset !== undefined ? [...args, limit, offset] : args,
608
+ });
609
+
610
+ const runs = (result.rows || []).map(row => this.parseWorkflowRun(row));
611
+
612
+ // Use runs.length as total when not paginating
613
+ return { runs, total: total || runs.length };
614
+ } catch (error) {
615
+ console.error('Error getting workflow runs:', error);
616
+ throw error;
569
617
  }
618
+ }
570
619
 
571
- if (fromDate) {
572
- conditions.push('createdAt >= ?');
573
- args.push(fromDate.toISOString());
620
+ async getWorkflowRunById({
621
+ runId,
622
+ workflowName,
623
+ }: {
624
+ runId: string;
625
+ workflowName?: string;
626
+ }): Promise<WorkflowRun | null> {
627
+ const conditions: string[] = [];
628
+ const args: (string | number)[] = [];
629
+
630
+ if (runId) {
631
+ conditions.push('run_id = ?');
632
+ args.push(runId);
574
633
  }
575
634
 
576
- if (toDate) {
577
- conditions.push('createdAt <= ?');
578
- args.push(toDate.toISOString());
635
+ if (workflowName) {
636
+ conditions.push('workflow_name = ?');
637
+ args.push(workflowName);
579
638
  }
580
639
 
581
640
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
582
641
 
583
- let total = 0;
584
- // Only get total count when using pagination
585
- if (limit !== undefined && offset !== undefined) {
586
- const countResult = await this.client.execute({
587
- sql: `SELECT COUNT(*) as count FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
588
- args,
589
- });
590
- total = Number(countResult.rows?.[0]?.count ?? 0);
591
- }
592
-
593
- // Get results
594
642
  const result = await this.client.execute({
595
- sql: `SELECT * FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause} ORDER BY createdAt DESC${limit !== undefined && offset !== undefined ? ` LIMIT ? OFFSET ?` : ''}`,
596
- args: limit !== undefined && offset !== undefined ? [...args, limit, offset] : args,
643
+ sql: `SELECT * FROM ${TABLE_WORKFLOW_SNAPSHOT} ${whereClause}`,
644
+ args,
597
645
  });
598
646
 
599
- const runs = (result.rows || []).map(row => {
600
- let parsedSnapshot: WorkflowRunState | string = row.snapshot as string;
601
- if (typeof parsedSnapshot === 'string') {
602
- try {
603
- parsedSnapshot = JSON.parse(row.snapshot as string) as WorkflowRunState;
604
- } catch (e) {
605
- // If parsing fails, return the raw snapshot string
606
- console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
607
- }
608
- }
647
+ if (!result.rows?.[0]) {
648
+ return null;
649
+ }
609
650
 
610
- return {
611
- workflowName: row.workflow_name as string,
612
- runId: row.run_id as string,
613
- snapshot: parsedSnapshot,
614
- createdAt: new Date(row.createdAt as string),
615
- updatedAt: new Date(row.updatedAt as string),
616
- };
651
+ return this.parseWorkflowRun(result.rows[0]);
652
+ }
653
+
654
+ private async hasColumn(table: string, column: string): Promise<boolean> {
655
+ const result = await this.client.execute({
656
+ sql: `PRAGMA table_info(${table})`,
617
657
  });
658
+ return (await result.rows)?.some((row: any) => row.name === column);
659
+ }
618
660
 
619
- // Use runs.length as total when not paginating
620
- return { runs, total: total || runs.length };
661
+ private parseWorkflowRun(row: Record<string, any>): WorkflowRun {
662
+ let parsedSnapshot: WorkflowRunState | string = row.snapshot as string;
663
+ if (typeof parsedSnapshot === 'string') {
664
+ try {
665
+ parsedSnapshot = JSON.parse(row.snapshot as string) as WorkflowRunState;
666
+ } catch (e) {
667
+ // If parsing fails, return the raw snapshot string
668
+ console.warn(`Failed to parse snapshot for workflow ${row.workflow_name}: ${e}`);
669
+ }
670
+ }
671
+ return {
672
+ workflowName: row.workflow_name as string,
673
+ runId: row.run_id as string,
674
+ snapshot: parsedSnapshot,
675
+ resourceId: row.resourceId as string,
676
+ createdAt: new Date(row.created_at as string),
677
+ updatedAt: new Date(row.updated_at as string),
678
+ };
621
679
  }
622
680
  }
623
681
 
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Vector store specific prompt that details supported operators and examples.
3
+ * This prompt helps users construct valid filters for LibSQL Vector.
4
+ */
5
+ export const LIBSQL_PROMPT = `When querying LibSQL Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
6
+ Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
7
+ 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.
8
+
9
+ Basic Comparison Operators:
10
+ - $eq: Exact match (default when using field: value)
11
+ Example: { "category": "electronics" }
12
+ - $ne: Not equal
13
+ Example: { "category": { "$ne": "electronics" } }
14
+ - $gt: Greater than
15
+ Example: { "price": { "$gt": 100 } }
16
+ - $gte: Greater than or equal
17
+ Example: { "price": { "$gte": 100 } }
18
+ - $lt: Less than
19
+ Example: { "price": { "$lt": 100 } }
20
+ - $lte: Less than or equal
21
+ Example: { "price": { "$lte": 100 } }
22
+
23
+ Array Operators:
24
+ - $in: Match any value in array
25
+ Example: { "category": { "$in": ["electronics", "books"] } }
26
+ - $nin: Does not match any value in array
27
+ Example: { "category": { "$nin": ["electronics", "books"] } }
28
+ - $all: Match all values in array
29
+ Example: { "tags": { "$all": ["premium", "sale"] } }
30
+ - $elemMatch: Match array elements that meet all specified conditions
31
+ Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
32
+ - $contains: Check if array contains value
33
+ Example: { "tags": { "$contains": "premium" } }
34
+
35
+ Logical Operators:
36
+ - $and: Logical AND (implicit when using multiple conditions)
37
+ Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
38
+ - $or: Logical OR
39
+ Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
40
+ - $not: Logical NOT
41
+ Example: { "$not": { "category": "electronics" } }
42
+ - $nor: Logical NOR
43
+ Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
44
+
45
+ Element Operators:
46
+ - $exists: Check if field exists
47
+ Example: { "rating": { "$exists": true } }
48
+
49
+ Special Operators:
50
+ - $size: Array length check
51
+ Example: { "tags": { "$size": 2 } }
52
+
53
+ Restrictions:
54
+ - Regex patterns are not supported
55
+ - Direct RegExp patterns will throw an error
56
+ - Nested fields are supported using dot notation
57
+ - Multiple conditions on the same field are supported with both implicit and explicit $and
58
+ - Array operations work on array fields only
59
+ - Basic operators handle array values as JSON strings
60
+ - Empty arrays in conditions are handled gracefully
61
+ - Only logical operators ($and, $or, $not, $nor) can be used at the top level
62
+ - All other operators must be used within a field condition
63
+ Valid: { "field": { "$gt": 100 } }
64
+ Valid: { "$and": [...] }
65
+ Invalid: { "$gt": 100 }
66
+ Invalid: { "$contains": "value" }
67
+ - Logical operators must contain field conditions, not direct operators
68
+ Valid: { "$and": [{ "field": { "$gt": 100 } }] }
69
+ Invalid: { "$and": [{ "$gt": 100 }] }
70
+ - $not operator:
71
+ - Must be an object
72
+ - Cannot be empty
73
+ - Can be used at field level or top level
74
+ - Valid: { "$not": { "field": "value" } }
75
+ - Valid: { "field": { "$not": { "$eq": "value" } } }
76
+ - Other logical operators ($and, $or, $nor):
77
+ - Can only be used at top level or nested within other logical operators
78
+ - Can not be used on a field level, or be nested inside a field
79
+ - Can not be used inside an operator
80
+ - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
81
+ - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
82
+ - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
83
+ - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
84
+ - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
85
+ - $elemMatch requires an object with conditions
86
+ Valid: { "array": { "$elemMatch": { "field": "value" } } }
87
+ Invalid: { "array": { "$elemMatch": "value" } }
88
+
89
+ Example Complex Query:
90
+ {
91
+ "$and": [
92
+ { "category": { "$in": ["electronics", "computers"] } },
93
+ { "price": { "$gte": 100, "$lte": 1000 } },
94
+ { "tags": { "$all": ["premium", "sale"] } },
95
+ { "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
96
+ { "$or": [
97
+ { "stock": { "$gt": 0 } },
98
+ { "preorder": true }
99
+ ]}
100
+ ]
101
+ }`;