@mastra/libsql 0.0.0-declaration-maps-20250730185206 → 0.0.0-experimental-agent-builder-20250815195917

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/CHANGELOG.md CHANGED
@@ -1,13 +1,132 @@
1
1
  # @mastra/libsql
2
2
 
3
- ## 0.0.0-declaration-maps-20250730185206
3
+ ## 0.0.0-experimental-agent-builder-20250815195917
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [33dcb07]
8
- - Updated dependencies [d30b1a0]
9
- - Updated dependencies [bff87f7]
10
- - @mastra/core@0.0.0-declaration-maps-20250730185206
7
+ - Updated dependencies [8e59433]
8
+ - Updated dependencies [49281f5]
9
+ - Updated dependencies [6faaee5]
10
+ - Updated dependencies [4232b14]
11
+ - Updated dependencies [6720c51]
12
+ - Updated dependencies [2256977]
13
+ - Updated dependencies [c597dc5]
14
+ - Updated dependencies [a722c0b]
15
+ - Updated dependencies [c30bca8]
16
+ - Updated dependencies [7444737]
17
+ - Updated dependencies [83d180b]
18
+ - Updated dependencies [3b5fec7]
19
+ - @mastra/core@0.0.0-experimental-agent-builder-20250815195917
20
+
21
+ ## 0.13.2
22
+
23
+ ### Patch Changes
24
+
25
+ - b5cf2a3: make system message always available during agent calls
26
+ - b32c50d: Filter scores by source
27
+ - Updated dependencies [d5330bf]
28
+ - Updated dependencies [2e74797]
29
+ - Updated dependencies [8388649]
30
+ - Updated dependencies [a239d41]
31
+ - Updated dependencies [dd94a26]
32
+ - Updated dependencies [3ba6772]
33
+ - Updated dependencies [b5cf2a3]
34
+ - Updated dependencies [2fff911]
35
+ - Updated dependencies [b32c50d]
36
+ - Updated dependencies [63449d0]
37
+ - Updated dependencies [121a3f8]
38
+ - Updated dependencies [ec510e7]
39
+ - @mastra/core@0.13.2
40
+
41
+ ## 0.13.2-alpha.1
42
+
43
+ ### Patch Changes
44
+
45
+ - b5cf2a3: make system message always available during agent calls
46
+ - Updated dependencies [b5cf2a3]
47
+ - @mastra/core@0.13.2-alpha.3
48
+
49
+ ## 0.13.2-alpha.0
50
+
51
+ ### Patch Changes
52
+
53
+ - b32c50d: Filter scores by source
54
+ - Updated dependencies [d5330bf]
55
+ - Updated dependencies [a239d41]
56
+ - Updated dependencies [b32c50d]
57
+ - Updated dependencies [121a3f8]
58
+ - Updated dependencies [ec510e7]
59
+ - @mastra/core@0.13.2-alpha.2
60
+
61
+ ## 0.13.1
62
+
63
+ ### Patch Changes
64
+
65
+ - 8888b57: Fix LibSQL vector metadata filtering for Memory system - corrected JSON path syntax for simple fields and changed default minScore to -1 to include all similarity results
66
+ - Updated dependencies [cd0042e]
67
+ - @mastra/core@0.13.1
68
+
69
+ ## 0.13.1-alpha.0
70
+
71
+ ### Patch Changes
72
+
73
+ - 8888b57: Fix LibSQL vector metadata filtering for Memory system - corrected JSON path syntax for simple fields and changed default minScore to -1 to include all similarity results
74
+ - Updated dependencies [cd0042e]
75
+ - @mastra/core@0.13.1-alpha.0
76
+
77
+ ## 0.13.0
78
+
79
+ ### Minor Changes
80
+
81
+ - ea0c5f2: Add store support to new score api
82
+
83
+ ### Patch Changes
84
+
85
+ - 2871020: update safelyParseJSON to check for value of param when handling parse
86
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
87
+ - Updated dependencies [cb36de0]
88
+ - Updated dependencies [d0496e6]
89
+ - Updated dependencies [a82b851]
90
+ - Updated dependencies [ea0c5f2]
91
+ - Updated dependencies [41a0a0e]
92
+ - Updated dependencies [2871020]
93
+ - Updated dependencies [94f4812]
94
+ - Updated dependencies [e202b82]
95
+ - Updated dependencies [e00f6a0]
96
+ - Updated dependencies [4a406ec]
97
+ - Updated dependencies [b0e43c1]
98
+ - Updated dependencies [5d377e5]
99
+ - Updated dependencies [1fb812e]
100
+ - Updated dependencies [35c5798]
101
+ - @mastra/core@0.13.0
102
+
103
+ ## 0.13.0-alpha.1
104
+
105
+ ### Patch Changes
106
+
107
+ - 2871020: update safelyParseJSON to check for value of param when handling parse
108
+ - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
109
+ - Updated dependencies [cb36de0]
110
+ - Updated dependencies [a82b851]
111
+ - Updated dependencies [41a0a0e]
112
+ - Updated dependencies [2871020]
113
+ - Updated dependencies [4a406ec]
114
+ - Updated dependencies [5d377e5]
115
+ - @mastra/core@0.13.0-alpha.2
116
+
117
+ ## 0.13.0-alpha.0
118
+
119
+ ### Minor Changes
120
+
121
+ - ea0c5f2: Add store support to new score api
122
+
123
+ ### Patch Changes
124
+
125
+ - Updated dependencies [ea0c5f2]
126
+ - Updated dependencies [b0e43c1]
127
+ - Updated dependencies [1fb812e]
128
+ - Updated dependencies [35c5798]
129
+ - @mastra/core@0.13.0-alpha.1
11
130
 
12
131
  ## 0.12.0
13
132
 
package/dist/index.cjs CHANGED
@@ -78,11 +78,11 @@ var LibSQLFilterTranslator = class extends filter.BaseFilterTranslator {
78
78
  };
79
79
  var createBasicOperator = (symbol) => {
80
80
  return (key, value) => {
81
- const jsonPathKey = parseJsonPathKey(key);
81
+ const jsonPath = getJsonPath(key);
82
82
  return {
83
83
  sql: `CASE
84
- WHEN ? IS NULL THEN json_extract(metadata, '$."${jsonPathKey}"') IS ${symbol === "=" ? "" : "NOT"} NULL
85
- ELSE json_extract(metadata, '$."${jsonPathKey}"') ${symbol} ?
84
+ WHEN ? IS NULL THEN json_extract(metadata, ${jsonPath}) IS ${symbol === "=" ? "" : "NOT"} NULL
85
+ ELSE json_extract(metadata, ${jsonPath}) ${symbol} ?
86
86
  END`,
87
87
  needsValue: true,
88
88
  transformValue: () => {
@@ -93,16 +93,19 @@ var createBasicOperator = (symbol) => {
93
93
  };
94
94
  var createNumericOperator = (symbol) => {
95
95
  return (key) => {
96
- const jsonPathKey = parseJsonPathKey(key);
96
+ const jsonPath = getJsonPath(key);
97
97
  return {
98
- sql: `CAST(json_extract(metadata, '$."${jsonPathKey}"') AS NUMERIC) ${symbol} ?`,
98
+ sql: `CAST(json_extract(metadata, ${jsonPath}) AS NUMERIC) ${symbol} ?`,
99
99
  needsValue: true
100
100
  };
101
101
  };
102
102
  };
103
- var validateJsonArray = (key) => `json_valid(json_extract(metadata, '$."${key}"'))
104
- AND json_type(json_extract(metadata, '$."${key}"')) = 'array'`;
105
- var pattern = /json_extract\(metadata, '\$\."[^"]*"(\."[^"]*")*'\)/g;
103
+ var validateJsonArray = (key) => {
104
+ const jsonPath = getJsonPath(key);
105
+ return `json_valid(json_extract(metadata, ${jsonPath}))
106
+ AND json_type(json_extract(metadata, ${jsonPath})) = 'array'`;
107
+ };
108
+ var pattern = /json_extract\(metadata, '\$\.(?:"[^"]*"(?:\."[^"]*")*|[^']+)'\)/g;
106
109
  function buildElemMatchConditions(value) {
107
110
  const conditions = Object.entries(value).map(([field, fieldValue]) => {
108
111
  if (field.startsWith("$")) {
@@ -111,12 +114,13 @@ function buildElemMatchConditions(value) {
111
114
  return { sql: elemSql, values };
112
115
  } else if (typeof fieldValue === "object" && !Array.isArray(fieldValue)) {
113
116
  const { sql, values } = buildCondition(field, fieldValue);
114
- const elemSql = sql.replace(pattern, `json_extract(elem.value, '$."${field}"')`);
117
+ const jsonPath = parseJsonPathKey(field);
118
+ const elemSql = sql.replace(pattern, `json_extract(elem.value, '$.${jsonPath}')`);
115
119
  return { sql: elemSql, values };
116
120
  } else {
117
- const parsedFieldKey = utils.parseFieldKey(field);
121
+ const jsonPath = parseJsonPathKey(field);
118
122
  return {
119
- sql: `json_extract(elem.value, '$."${parsedFieldKey}"') = ?`,
123
+ sql: `json_extract(elem.value, '$.${jsonPath}') = ?`,
120
124
  values: [fieldValue]
121
125
  };
122
126
  }
@@ -132,7 +136,7 @@ var FILTER_OPERATORS = {
132
136
  $lte: createNumericOperator("<="),
133
137
  // Array Operators
134
138
  $in: (key, value) => {
135
- const jsonPathKey = parseJsonPathKey(key);
139
+ const jsonPath = getJsonPath(key);
136
140
  const arr = Array.isArray(value) ? value : [value];
137
141
  if (arr.length === 0) {
138
142
  return { sql: "1 = 0", needsValue: true, transformValue: () => [] };
@@ -141,12 +145,12 @@ var FILTER_OPERATORS = {
141
145
  return {
142
146
  sql: `(
143
147
  CASE
144
- WHEN ${validateJsonArray(jsonPathKey)} THEN
148
+ WHEN ${validateJsonArray(key)} THEN
145
149
  EXISTS (
146
- SELECT 1 FROM json_each(json_extract(metadata, '$."${jsonPathKey}"')) as elem
150
+ SELECT 1 FROM json_each(json_extract(metadata, ${jsonPath})) as elem
147
151
  WHERE elem.value IN (SELECT value FROM json_each(?))
148
152
  )
149
- ELSE json_extract(metadata, '$."${jsonPathKey}"') IN (${paramPlaceholders})
153
+ ELSE json_extract(metadata, ${jsonPath}) IN (${paramPlaceholders})
150
154
  END
151
155
  )`,
152
156
  needsValue: true,
@@ -154,7 +158,7 @@ var FILTER_OPERATORS = {
154
158
  };
155
159
  },
156
160
  $nin: (key, value) => {
157
- const jsonPathKey = parseJsonPathKey(key);
161
+ const jsonPath = getJsonPath(key);
158
162
  const arr = Array.isArray(value) ? value : [value];
159
163
  if (arr.length === 0) {
160
164
  return { sql: "1 = 1", needsValue: true, transformValue: () => [] };
@@ -163,12 +167,12 @@ var FILTER_OPERATORS = {
163
167
  return {
164
168
  sql: `(
165
169
  CASE
166
- WHEN ${validateJsonArray(jsonPathKey)} THEN
170
+ WHEN ${validateJsonArray(key)} THEN
167
171
  NOT EXISTS (
168
- SELECT 1 FROM json_each(json_extract(metadata, '$."${jsonPathKey}"')) as elem
172
+ SELECT 1 FROM json_each(json_extract(metadata, ${jsonPath})) as elem
169
173
  WHERE elem.value IN (SELECT value FROM json_each(?))
170
174
  )
171
- ELSE json_extract(metadata, '$."${jsonPathKey}"') NOT IN (${paramPlaceholders})
175
+ ELSE json_extract(metadata, ${jsonPath}) NOT IN (${paramPlaceholders})
172
176
  END
173
177
  )`,
174
178
  needsValue: true,
@@ -176,7 +180,7 @@ var FILTER_OPERATORS = {
176
180
  };
177
181
  },
178
182
  $all: (key, value) => {
179
- const jsonPathKey = parseJsonPathKey(key);
183
+ const jsonPath = getJsonPath(key);
180
184
  let sql;
181
185
  const arrayValue = Array.isArray(value) ? value : [value];
182
186
  if (arrayValue.length === 0) {
@@ -184,13 +188,13 @@ var FILTER_OPERATORS = {
184
188
  } else {
185
189
  sql = `(
186
190
  CASE
187
- WHEN ${validateJsonArray(jsonPathKey)} THEN
191
+ WHEN ${validateJsonArray(key)} THEN
188
192
  NOT EXISTS (
189
193
  SELECT value
190
194
  FROM json_each(?)
191
195
  WHERE value NOT IN (
192
196
  SELECT value
193
- FROM json_each(json_extract(metadata, '$."${jsonPathKey}"'))
197
+ FROM json_each(json_extract(metadata, ${jsonPath}))
194
198
  )
195
199
  )
196
200
  ELSE FALSE
@@ -209,7 +213,7 @@ var FILTER_OPERATORS = {
209
213
  };
210
214
  },
211
215
  $elemMatch: (key, value) => {
212
- const jsonPathKey = parseJsonPathKey(key);
216
+ const jsonPath = getJsonPath(key);
213
217
  if (typeof value !== "object" || Array.isArray(value)) {
214
218
  throw new Error("$elemMatch requires an object with conditions");
215
219
  }
@@ -217,10 +221,10 @@ var FILTER_OPERATORS = {
217
221
  return {
218
222
  sql: `(
219
223
  CASE
220
- WHEN ${validateJsonArray(jsonPathKey)} THEN
224
+ WHEN ${validateJsonArray(key)} THEN
221
225
  EXISTS (
222
226
  SELECT 1
223
- FROM json_each(json_extract(metadata, '$."${jsonPathKey}"')) as elem
227
+ FROM json_each(json_extract(metadata, ${jsonPath})) as elem
224
228
  WHERE ${conditions.map((c) => c.sql).join(" AND ")}
225
229
  )
226
230
  ELSE FALSE
@@ -232,9 +236,9 @@ var FILTER_OPERATORS = {
232
236
  },
233
237
  // Element Operators
234
238
  $exists: (key) => {
235
- const jsonPathKey = parseJsonPathKey(key);
239
+ const jsonPath = getJsonPath(key);
236
240
  return {
237
- sql: `json_extract(metadata, '$."${jsonPathKey}"') IS NOT NULL`,
241
+ sql: `json_extract(metadata, ${jsonPath}) IS NOT NULL`,
238
242
  needsValue: false
239
243
  };
240
244
  },
@@ -253,12 +257,12 @@ var FILTER_OPERATORS = {
253
257
  needsValue: false
254
258
  }),
255
259
  $size: (key, paramIndex) => {
256
- const jsonPathKey = parseJsonPathKey(key);
260
+ const jsonPath = getJsonPath(key);
257
261
  return {
258
262
  sql: `(
259
263
  CASE
260
- WHEN json_type(json_extract(metadata, '$."${jsonPathKey}"')) = 'array' THEN
261
- json_array_length(json_extract(metadata, '$."${jsonPathKey}"')) = $${paramIndex}
264
+ WHEN json_type(json_extract(metadata, ${jsonPath})) = 'array' THEN
265
+ json_array_length(json_extract(metadata, ${jsonPath})) = $${paramIndex}
262
266
  ELSE FALSE
263
267
  END
264
268
  )`,
@@ -377,7 +381,14 @@ function isFilterResult(obj) {
377
381
  }
378
382
  var parseJsonPathKey = (key) => {
379
383
  const parsedKey = utils.parseFieldKey(key);
380
- return parsedKey.replace(/\./g, '"."');
384
+ if (parsedKey.includes(".")) {
385
+ return parsedKey.split(".").map((segment) => `"${segment}"`).join(".");
386
+ }
387
+ return parsedKey;
388
+ };
389
+ var getJsonPath = (key) => {
390
+ const jsonPathKey = parseJsonPathKey(key);
391
+ return `'$.${jsonPathKey}'`;
381
392
  };
382
393
  function escapeLikePattern(str) {
383
394
  return str.replace(/([%_\\])/g, "\\$1");
@@ -402,8 +413,9 @@ function buildCondition(key, value, parentPath) {
402
413
  return handleLogicalOperator(key, value);
403
414
  }
404
415
  if (!value || typeof value !== "object") {
416
+ const jsonPath = getJsonPath(key);
405
417
  return {
406
- sql: `json_extract(metadata, '$."${key.replace(/\./g, '"."')}"') = ?`,
418
+ sql: `json_extract(metadata, ${jsonPath}) = ?`,
407
419
  values: [value]
408
420
  };
409
421
  }
@@ -549,7 +561,8 @@ var LibSQLVector = class extends vector.MastraVector {
549
561
  topK = 10,
550
562
  filter,
551
563
  includeVector = false,
552
- minScore = 0
564
+ minScore = -1
565
+ // Default to -1 to include all results (cosine similarity ranges from -1 to 1)
553
566
  }) {
554
567
  try {
555
568
  if (!Number.isInteger(topK) || topK <= 0) {
@@ -1447,7 +1460,6 @@ var MemoryLibSQL = class extends storage.MemoryStorage {
1447
1460
  };
1448
1461
  }
1449
1462
  async saveResource({ resource }) {
1450
- console.log("resource", resource);
1451
1463
  await this.operations.insert({
1452
1464
  tableName: storage.TABLE_RESOURCES,
1453
1465
  record: {
@@ -2047,6 +2059,7 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2047
2059
  scorerId,
2048
2060
  entityId,
2049
2061
  entityType,
2062
+ source,
2050
2063
  pagination
2051
2064
  }) {
2052
2065
  try {
@@ -2064,6 +2077,10 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2064
2077
  conditions.push(`entityType = ?`);
2065
2078
  queryParams.push(entityType);
2066
2079
  }
2080
+ if (source) {
2081
+ conditions.push(`source = ?`);
2082
+ queryParams.push(source);
2083
+ }
2067
2084
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
2068
2085
  const result = await this.client.execute({
2069
2086
  sql: `SELECT * FROM ${storage.TABLE_SCORERS} ${whereClause} ORDER BY createdAt DESC LIMIT ? OFFSET ?`,
@@ -2090,15 +2107,15 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2090
2107
  }
2091
2108
  }
2092
2109
  transformScoreRow(row) {
2093
- const scorerValue = JSON.parse(row.scorer ?? "{}");
2094
- const inputValue = JSON.parse(row.input ?? "{}");
2095
- const outputValue = JSON.parse(row.output ?? "{}");
2096
- const additionalLLMContextValue = row.additionalLLMContext ? JSON.parse(row.additionalLLMContext) : null;
2097
- const runtimeContextValue = row.runtimeContext ? JSON.parse(row.runtimeContext) : null;
2098
- const metadataValue = row.metadata ? JSON.parse(row.metadata) : null;
2099
- const entityValue = row.entity ? JSON.parse(row.entity) : null;
2100
- const extractStepResultValue = row.extractStepResult ? JSON.parse(row.extractStepResult) : null;
2101
- const analyzeStepResultValue = row.analyzeStepResult ? JSON.parse(row.analyzeStepResult) : null;
2110
+ const scorerValue = storage.safelyParseJSON(row.scorer);
2111
+ const inputValue = storage.safelyParseJSON(row.input ?? "{}");
2112
+ const outputValue = storage.safelyParseJSON(row.output ?? "{}");
2113
+ const additionalLLMContextValue = row.additionalLLMContext ? storage.safelyParseJSON(row.additionalLLMContext) : null;
2114
+ const runtimeContextValue = row.runtimeContext ? storage.safelyParseJSON(row.runtimeContext) : null;
2115
+ const metadataValue = row.metadata ? storage.safelyParseJSON(row.metadata) : null;
2116
+ const entityValue = row.entity ? storage.safelyParseJSON(row.entity) : null;
2117
+ const preprocessStepResultValue = row.preprocessStepResult ? storage.safelyParseJSON(row.preprocessStepResult) : null;
2118
+ const analyzeStepResultValue = row.analyzeStepResult ? storage.safelyParseJSON(row.analyzeStepResult) : null;
2102
2119
  return {
2103
2120
  id: row.id,
2104
2121
  traceId: row.traceId,
@@ -2106,10 +2123,12 @@ var ScoresLibSQL = class extends storage.ScoresStorage {
2106
2123
  scorer: scorerValue,
2107
2124
  score: row.score,
2108
2125
  reason: row.reason,
2109
- extractStepResult: extractStepResultValue,
2126
+ preprocessStepResult: preprocessStepResultValue,
2110
2127
  analyzeStepResult: analyzeStepResultValue,
2111
2128
  analyzePrompt: row.analyzePrompt,
2112
- extractPrompt: row.extractPrompt,
2129
+ preprocessPrompt: row.preprocessPrompt,
2130
+ generateScorePrompt: row.generateScorePrompt,
2131
+ generateReasonPrompt: row.generateReasonPrompt,
2113
2132
  metadata: metadataValue,
2114
2133
  input: inputValue,
2115
2134
  output: outputValue,
@@ -2617,9 +2636,10 @@ var LibSQLStore = class extends storage.MastraStorage {
2617
2636
  scorerId,
2618
2637
  entityId,
2619
2638
  entityType,
2639
+ source,
2620
2640
  pagination
2621
2641
  }) {
2622
- return this.stores.scores.getScoresByScorerId({ scorerId, entityId, entityType, pagination });
2642
+ return this.stores.scores.getScoresByScorerId({ scorerId, entityId, entityType, source, pagination });
2623
2643
  }
2624
2644
  async getScoresByRunId({
2625
2645
  runId,