@mastra/clickhouse 0.15.8-alpha.0 → 0.15.9-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createClient } from '@clickhouse/client';
2
2
  import { MastraError, ErrorCategory, ErrorDomain } from '@mastra/core/error';
3
- import { TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, StoreOperations, TABLE_SCHEMAS, WorkflowsStorage, ScoresStorage, safelyParseJSON, LegacyEvalsStorage, TracesStorage, MemoryStorage, resolveMessageLimit } from '@mastra/core/storage';
3
+ import { TABLE_AI_SPANS, TABLE_RESOURCES, TABLE_SCORERS, TABLE_EVALS, TABLE_THREADS, TABLE_TRACES, TABLE_WORKFLOW_SNAPSHOT, TABLE_MESSAGES, MastraStorage, StoreOperations, TABLE_SCHEMAS, WorkflowsStorage, ScoresStorage, safelyParseJSON, SCORERS_SCHEMA, LegacyEvalsStorage, TracesStorage, MemoryStorage, resolveMessageLimit } from '@mastra/core/storage';
4
4
  import { MessageList } from '@mastra/core/agent';
5
5
  import { saveScorePayloadSchema } from '@mastra/core/scores';
6
6
 
@@ -1002,11 +1002,11 @@ var MemoryStorageClickhouse = class extends MemoryStorage {
1002
1002
  const rows = await result.json();
1003
1003
  const paginatedMessages = transformRows(rows.data);
1004
1004
  messages.push(...paginatedMessages);
1005
- if (selectBy?.last) {
1006
- messages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
1007
- }
1005
+ const list = new MessageList().add(messages, "memory");
1006
+ let finalMessages = format === "v2" ? list.get.all.v2() : list.get.all.v1();
1007
+ finalMessages = finalMessages.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
1008
1008
  return {
1009
- messages: format === "v2" ? messages : messages,
1009
+ messages: finalMessages,
1010
1010
  total,
1011
1011
  page,
1012
1012
  perPage,
@@ -1731,18 +1731,16 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1731
1731
  const scorer = safelyParseJSON(row.scorer);
1732
1732
  const preprocessStepResult = safelyParseJSON(row.preprocessStepResult);
1733
1733
  const analyzeStepResult = safelyParseJSON(row.analyzeStepResult);
1734
- const metadata = safelyParseJSON(row.metadata);
1735
1734
  const input = safelyParseJSON(row.input);
1736
1735
  const output = safelyParseJSON(row.output);
1737
1736
  const additionalContext = safelyParseJSON(row.additionalContext);
1738
1737
  const runtimeContext = safelyParseJSON(row.runtimeContext);
1739
1738
  const entity = safelyParseJSON(row.entity);
1740
- return {
1739
+ const data = {
1741
1740
  ...row,
1742
1741
  scorer,
1743
1742
  preprocessStepResult,
1744
1743
  analyzeStepResult,
1745
- metadata,
1746
1744
  input,
1747
1745
  output,
1748
1746
  additionalContext,
@@ -1751,6 +1749,14 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1751
1749
  createdAt: new Date(row.createdAt),
1752
1750
  updatedAt: new Date(row.updatedAt)
1753
1751
  };
1752
+ const result = {};
1753
+ for (const [key, value] of Object.entries(data)) {
1754
+ if (value === "_null_") {
1755
+ continue;
1756
+ }
1757
+ result[key] = value;
1758
+ }
1759
+ return result;
1754
1760
  }
1755
1761
  async getScoreById({ id }) {
1756
1762
  try {
@@ -1799,9 +1805,15 @@ var ScoresStorageClickhouse = class extends ScoresStorage {
1799
1805
  );
1800
1806
  }
1801
1807
  try {
1802
- const record = {
1803
- ...parsedScore
1804
- };
1808
+ const record = {};
1809
+ for (const key of Object.keys(SCORERS_SCHEMA)) {
1810
+ const value = parsedScore[key];
1811
+ if (key === "createdAt" || key === "updatedAt") {
1812
+ record[key] = (/* @__PURE__ */ new Date()).toISOString();
1813
+ continue;
1814
+ }
1815
+ record[key] = value === void 0 || value === null ? "_null_" : value;
1816
+ }
1805
1817
  await this.client.insert({
1806
1818
  table: TABLE_SCORERS,
1807
1819
  values: [record],