@mastra/clickhouse 1.30.0-alpha.1 → 1.30.0-alpha.3

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
@@ -5070,7 +5070,7 @@ async function queryJson$2(client, query, params, settings = {}) {
5070
5070
  }
5071
5071
  })).json();
5072
5072
  }
5073
- async function feedbackRowsWithWriteVersions(client, feedbacks) {
5073
+ async function feedbackRowsWithWriteVersions(client, feedbacks, onConflict) {
5074
5074
  const identifiedFeedback = feedbacks.map((feedback) => ({
5075
5075
  ...feedback,
5076
5076
  feedbackId: feedback.feedbackId ?? ""
@@ -5081,23 +5081,29 @@ async function feedbackRowsWithWriteVersions(client, feedbacks) {
5081
5081
  WHERE feedbackId IN ({feedbackIds:Array(String)})
5082
5082
  GROUP BY feedbackId`, { feedbackIds });
5083
5083
  const versions = new Map(existingVersions.map((row) => [row.feedbackId, BigInt(row.writeVersion)]));
5084
- return identifiedFeedback.map((feedback) => {
5084
+ return identifiedFeedback.flatMap((feedback) => {
5085
+ if (onConflict === "ignore" && versions.has(feedback.feedbackId)) return [];
5085
5086
  const writeVersion = (versions.get(feedback.feedbackId) ?? 0n) + 1n;
5086
5087
  versions.set(feedback.feedbackId, writeVersion);
5087
- return {
5088
+ return [{
5088
5089
  ...feedbackRecordToRow(feedback),
5089
5090
  writeVersion: writeVersion.toString()
5090
- };
5091
+ }];
5091
5092
  });
5092
5093
  }
5093
5094
  async function createFeedback(client, args) {
5094
- await batchCreateFeedback(client, { feedbacks: [args.feedback] });
5095
+ await batchCreateFeedback(client, {
5096
+ feedbacks: [args.feedback],
5097
+ onConflict: args.onConflict
5098
+ });
5095
5099
  }
5096
5100
  async function batchCreateFeedback(client, args) {
5097
5101
  if (args.feedbacks.length === 0) return;
5102
+ const values = await feedbackRowsWithWriteVersions(client, args.feedbacks, args.onConflict);
5103
+ if (values.length === 0) return;
5098
5104
  await client.insert({
5099
5105
  table: TABLE_FEEDBACK_EVENTS,
5100
- values: await feedbackRowsWithWriteVersions(client, args.feedbacks),
5106
+ values,
5101
5107
  format: "JSONEachRow",
5102
5108
  clickhouse_settings: CH_INSERT_SETTINGS
5103
5109
  });
@@ -8210,7 +8216,7 @@ function afterCursor$1(plan, parameters) {
8210
8216
  const equal = [];
8211
8217
  if (cursor.sortValue === null) equal.push(`isNull(${field})`);
8212
8218
  else {
8213
- const numeric = plan.orderBy.field === "timeToFirstChunkMs" || plan.orderBy.field === "timeToFirstTokenMs";
8219
+ const numeric = typeof cursor.sortValue === "number";
8214
8220
  const value = parameters.add(cursor.sortValue, numeric ? "Float64" : "DateTime64(3, 'UTC')");
8215
8221
  terms.push(`${field} ${plan.orderBy.direction === "asc" ? ">" : "<"} ${value}`);
8216
8222
  if (numeric) terms.push(`isNull(${field})`);
@@ -8438,7 +8444,8 @@ async function querySpans(client, plan, timeoutMs) {
8438
8444
  const selected = (await run(compileClickHouseSpanQuery(plan))).map((row) => ({
8439
8445
  ...row,
8440
8446
  startedAt: iso$1(row.startedAt),
8441
- endedAt: iso$1(row.endedAt)
8447
+ endedAt: iso$1(row.endedAt),
8448
+ ...row.durationMs === void 0 ? {} : { durationMs: Number(row.durationMs) }
8442
8449
  }));
8443
8450
  const page = selected.slice(0, plan.limit);
8444
8451
  if (!page.length) return {
@@ -10035,6 +10042,7 @@ function buildBranchCursor(row) {
10035
10042
  const spanQueryFeatures = typeof coreStorage.planSpanQuery === "function" ? [
10036
10043
  "span-query",
10037
10044
  "span-query-context-fields",
10045
+ ...coreStorage.SPAN_QUERY_ORDER_FIELDS?.includes("durationMs") ? ["span-query-duration-sort"] : [],
10038
10046
  ..."model" in (coreStorage.SPAN_QUERY_FIELD_REGISTRY ?? {}) ? ["span-query-model-fields"] : []
10039
10047
  ] : [];
10040
10048
  const spanAggregateFeatures = typeof coreStorage.planSpanAggregate === "function" ? ["span-aggregate", ..."model" in (coreStorage.SPAN_AGGREGATE_DIMENSION_REGISTRY ?? {}) ? ["span-aggregate-model-dimensions"] : []] : [];
@@ -10475,6 +10483,7 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
10475
10483
  "thread-query",
10476
10484
  "trace-query-tenant-scope",
10477
10485
  "feedback",
10486
+ "feedback-replacement",
10478
10487
  "trace-query-context-ids",
10479
10488
  ...contextFieldFeatures,
10480
10489
  ...timingFeatures,
@@ -10503,6 +10512,7 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
10503
10512
  "thread-query",
10504
10513
  "trace-query-tenant-scope",
10505
10514
  "feedback",
10515
+ "feedback-replacement",
10506
10516
  "trace-query-context-ids",
10507
10517
  ...contextFieldFeatures,
10508
10518
  ...timingFeatures,