@absolutejs/rag 0.0.8 → 0.0.10

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,7 +1,44 @@
1
1
  // @bun
2
2
  // src/ai/rag/quality.ts
3
- import { mkdir, readFile, writeFile } from "fs/promises";
3
+ import { mkdir, readFile } from "fs/promises";
4
+
5
+ // src/ai/rag/atomicWrite.ts
6
+ import { open, rename, unlink } from "fs/promises";
4
7
  import { dirname } from "path";
8
+ var writeFileAtomic = async (path, data, encoding = "utf8") => {
9
+ const tmpPath = `${path}.tmp.${process.pid}.${Math.random().toString(36).slice(2, 10)}`;
10
+ const buffer = Buffer.from(data, encoding);
11
+ let renamed = false;
12
+ try {
13
+ const fileHandle = await open(tmpPath, "w");
14
+ try {
15
+ await fileHandle.writeFile(buffer);
16
+ await fileHandle.sync();
17
+ } finally {
18
+ await fileHandle.close();
19
+ }
20
+ await rename(tmpPath, path);
21
+ renamed = true;
22
+ try {
23
+ const dirHandle = await open(dirname(path), "r");
24
+ try {
25
+ await dirHandle.sync();
26
+ } finally {
27
+ await dirHandle.close();
28
+ }
29
+ } catch {}
30
+ } catch (error) {
31
+ if (!renamed) {
32
+ try {
33
+ await unlink(tmpPath);
34
+ } catch {}
35
+ }
36
+ throw error;
37
+ }
38
+ };
39
+
40
+ // src/ai/rag/quality.ts
41
+ import { dirname as dirname2 } from "path";
5
42
  import { generateId } from "@absolutejs/ai";
6
43
 
7
44
  // src/ai/rag/grounding.ts
@@ -6504,8 +6541,8 @@ var createRAGFileEvaluationHistoryStore = (path) => ({
6504
6541
  run,
6505
6542
  ...existing.filter((entry) => entry.id !== run.id)
6506
6543
  ]);
6507
- await mkdir(dirname(path), { recursive: true });
6508
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6544
+ await mkdir(dirname2(path), { recursive: true });
6545
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6509
6546
  `, "utf8");
6510
6547
  },
6511
6548
  pruneRuns: async (input) => {
@@ -6524,8 +6561,8 @@ var createRAGFileEvaluationHistoryStore = (path) => ({
6524
6561
  runs: existing,
6525
6562
  sort: normalizeHistoryRuns
6526
6563
  });
6527
- await mkdir(dirname(path), { recursive: true });
6528
- await writeFile(path, JSON.stringify(pruned.next, null, "\t") + `
6564
+ await mkdir(dirname2(path), { recursive: true });
6565
+ await writeFileAtomic(path, JSON.stringify(pruned.next, null, "\t") + `
6529
6566
  `, "utf8");
6530
6567
  return {
6531
6568
  keptCount: pruned.keptCount,
@@ -6575,8 +6612,8 @@ var createRAGFileEvaluationSuiteSnapshotHistoryStore = (path) => ({
6575
6612
  snapshot,
6576
6613
  ...existing.filter((entry) => entry.id !== snapshot.id)
6577
6614
  ]);
6578
- await mkdir(dirname(path), { recursive: true });
6579
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6615
+ await mkdir(dirname2(path), { recursive: true });
6616
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6580
6617
  `, "utf8");
6581
6618
  },
6582
6619
  pruneSnapshots: async (input) => {
@@ -6595,8 +6632,8 @@ var createRAGFileEvaluationSuiteSnapshotHistoryStore = (path) => ({
6595
6632
  runs: existing,
6596
6633
  sort: normalizeEvaluationSuiteSnapshots
6597
6634
  });
6598
- await mkdir(dirname(path), { recursive: true });
6599
- await writeFile(path, JSON.stringify(pruned.next, null, "\t") + `
6635
+ await mkdir(dirname2(path), { recursive: true });
6636
+ await writeFileAtomic(path, JSON.stringify(pruned.next, null, "\t") + `
6600
6637
  `, "utf8");
6601
6638
  return {
6602
6639
  keptCount: pruned.keptCount,
@@ -6638,8 +6675,8 @@ var createRAGFileRetrievalComparisonHistoryStore = (path) => ({
6638
6675
  run,
6639
6676
  ...existing.filter((entry) => entry.id !== run.id)
6640
6677
  ]);
6641
- await mkdir(dirname(path), { recursive: true });
6642
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6678
+ await mkdir(dirname2(path), { recursive: true });
6679
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6643
6680
  `, "utf8");
6644
6681
  }
6645
6682
  });
@@ -6692,8 +6729,8 @@ var createRAGFileRetrievalBaselineStore = (path) => {
6692
6729
  },
6693
6730
  ...existing.map((entry) => entry.groupKey === record.groupKey && (entry.rolloutLabel ?? undefined) === (record.rolloutLabel ?? undefined) ? { ...entry, status: "superseded" } : entry)
6694
6731
  ]);
6695
- await mkdir(dirname(path), { recursive: true });
6696
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6732
+ await mkdir(dirname2(path), { recursive: true });
6733
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6697
6734
  `, "utf8");
6698
6735
  }
6699
6736
  };
@@ -6731,8 +6768,8 @@ var createRAGFileRetrievalReleaseDecisionStore = (path) => ({
6731
6768
  record,
6732
6769
  ...existing.filter((entry) => entry.id !== record.id)
6733
6770
  ]);
6734
- await mkdir(dirname(path), { recursive: true });
6735
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6771
+ await mkdir(dirname2(path), { recursive: true });
6772
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6736
6773
  `, "utf8");
6737
6774
  }
6738
6775
  });
@@ -6775,8 +6812,8 @@ var createRAGFileRetrievalLaneHandoffDecisionStore = (path) => ({
6775
6812
  record,
6776
6813
  ...existing.filter((entry) => entry.id !== record.id)
6777
6814
  ]);
6778
- await mkdir(dirname(path), { recursive: true });
6779
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6815
+ await mkdir(dirname2(path), { recursive: true });
6816
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6780
6817
  `, "utf8");
6781
6818
  }
6782
6819
  });
@@ -6820,8 +6857,8 @@ var createRAGFileRetrievalReleaseIncidentStore = (path) => ({
6820
6857
  record,
6821
6858
  ...existing.filter((entry) => entry.id !== record.id)
6822
6859
  ]);
6823
- await mkdir(dirname(path), { recursive: true });
6824
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6860
+ await mkdir(dirname2(path), { recursive: true });
6861
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6825
6862
  `, "utf8");
6826
6863
  }
6827
6864
  });
@@ -6864,8 +6901,8 @@ var createRAGFileRetrievalLaneHandoffIncidentStore = (path) => ({
6864
6901
  record,
6865
6902
  ...existing.filter((entry) => entry.id !== record.id)
6866
6903
  ]);
6867
- await mkdir(dirname(path), { recursive: true });
6868
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6904
+ await mkdir(dirname2(path), { recursive: true });
6905
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6869
6906
  `, "utf8");
6870
6907
  }
6871
6908
  });
@@ -6904,8 +6941,8 @@ var createRAGFileRetrievalLaneHandoffIncidentHistoryStore = (path) => ({
6904
6941
  }
6905
6942
  })();
6906
6943
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
6907
- await mkdir(dirname(path), { recursive: true });
6908
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6944
+ await mkdir(dirname2(path), { recursive: true });
6945
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6909
6946
  `, "utf8");
6910
6947
  }
6911
6948
  });
@@ -6948,8 +6985,8 @@ var createRAGFileRetrievalIncidentRemediationDecisionStore = (path) => ({
6948
6985
  record,
6949
6986
  ...existing
6950
6987
  ]);
6951
- await mkdir(dirname(path), { recursive: true });
6952
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6988
+ await mkdir(dirname2(path), { recursive: true });
6989
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6953
6990
  `, "utf8");
6954
6991
  }
6955
6992
  });
@@ -6994,8 +7031,8 @@ var createRAGFileRetrievalIncidentRemediationExecutionHistoryStore = (path) => (
6994
7031
  record,
6995
7032
  ...existing
6996
7033
  ]);
6997
- await mkdir(dirname(path), { recursive: true });
6998
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7034
+ await mkdir(dirname2(path), { recursive: true });
7035
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6999
7036
  `, "utf8");
7000
7037
  }
7001
7038
  });
@@ -7028,8 +7065,8 @@ var createRAGFileRetrievalLaneHandoffAutoCompletePolicyHistoryStore = (path) =>
7028
7065
  }
7029
7066
  })();
7030
7067
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7031
- await mkdir(dirname(path), { recursive: true });
7032
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7068
+ await mkdir(dirname2(path), { recursive: true });
7069
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7033
7070
  `, "utf8");
7034
7071
  }
7035
7072
  });
@@ -7062,8 +7099,8 @@ var createRAGFileRetrievalReleaseLanePolicyHistoryStore = (path) => ({
7062
7099
  }
7063
7100
  })();
7064
7101
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7065
- await mkdir(dirname(path), { recursive: true });
7066
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7102
+ await mkdir(dirname2(path), { recursive: true });
7103
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7067
7104
  `, "utf8");
7068
7105
  }
7069
7106
  });
@@ -7096,8 +7133,8 @@ var createRAGFileRetrievalBaselineGatePolicyHistoryStore = (path) => ({
7096
7133
  }
7097
7134
  })();
7098
7135
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7099
- await mkdir(dirname(path), { recursive: true });
7100
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7136
+ await mkdir(dirname2(path), { recursive: true });
7137
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7101
7138
  `, "utf8");
7102
7139
  }
7103
7140
  });
@@ -7130,8 +7167,8 @@ var createRAGFileRetrievalReleaseLaneEscalationPolicyHistoryStore = (path) => ({
7130
7167
  }
7131
7168
  })();
7132
7169
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7133
- await mkdir(dirname(path), { recursive: true });
7134
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7170
+ await mkdir(dirname2(path), { recursive: true });
7171
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7135
7172
  `, "utf8");
7136
7173
  }
7137
7174
  });
@@ -7176,8 +7213,8 @@ var createRAGFileSearchTraceStore = (path) => ({
7176
7213
  trace,
7177
7214
  ...traces.filter((entry) => entry.id !== trace.id)
7178
7215
  ]);
7179
- await mkdir(dirname(path), { recursive: true });
7180
- await writeFile(path, JSON.stringify({
7216
+ await mkdir(dirname2(path), { recursive: true });
7217
+ await writeFileAtomic(path, JSON.stringify({
7181
7218
  traces: nextTraces
7182
7219
  }, null, 2));
7183
7220
  },
@@ -7196,8 +7233,8 @@ var createRAGFileSearchTraceStore = (path) => ({
7196
7233
  input,
7197
7234
  traces
7198
7235
  });
7199
- await mkdir(dirname(path), { recursive: true });
7200
- await writeFile(path, JSON.stringify({
7236
+ await mkdir(dirname2(path), { recursive: true });
7237
+ await writeFileAtomic(path, JSON.stringify({
7201
7238
  traces: pruned.next
7202
7239
  }, null, 2));
7203
7240
  return {
@@ -7239,8 +7276,8 @@ var createRAGFileSearchTracePruneHistoryStore = (path) => ({
7239
7276
  run,
7240
7277
  ...existing.filter((entry) => entry.id !== run.id)
7241
7278
  ]);
7242
- await mkdir(dirname(path), { recursive: true });
7243
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7279
+ await mkdir(dirname2(path), { recursive: true });
7280
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7244
7281
  `, "utf8");
7245
7282
  }
7246
7283
  });
@@ -8868,8 +8905,8 @@ var createRAGFileAnswerGroundingEvaluationHistoryStore = (path) => ({
8868
8905
  run,
8869
8906
  ...runs.filter((entry) => entry.id !== run.id)
8870
8907
  ]);
8871
- await mkdir(dirname(path), { recursive: true });
8872
- await writeFile(path, JSON.stringify({
8908
+ await mkdir(dirname2(path), { recursive: true });
8909
+ await writeFileAtomic(path, JSON.stringify({
8873
8910
  runs: nextRuns
8874
8911
  }, null, 2));
8875
8912
  },
@@ -8889,8 +8926,8 @@ var createRAGFileAnswerGroundingEvaluationHistoryStore = (path) => ({
8889
8926
  runs,
8890
8927
  sort: normalizeGroundingHistoryRuns
8891
8928
  });
8892
- await mkdir(dirname(path), { recursive: true });
8893
- await writeFile(path, JSON.stringify({
8929
+ await mkdir(dirname2(path), { recursive: true });
8930
+ await writeFileAtomic(path, JSON.stringify({
8894
8931
  runs: pruned.next
8895
8932
  }, null, 2));
8896
8933
  return {
@@ -8929,8 +8966,8 @@ var createRAGFileAnswerGroundingCaseDifficultyHistoryStore = (path) => ({
8929
8966
  run,
8930
8967
  ...runs.filter((entry) => entry.id !== run.id)
8931
8968
  ]);
8932
- await mkdir(dirname(path), { recursive: true });
8933
- await writeFile(path, JSON.stringify({
8969
+ await mkdir(dirname2(path), { recursive: true });
8970
+ await writeFileAtomic(path, JSON.stringify({
8934
8971
  runs: nextRuns
8935
8972
  }, null, 2));
8936
8973
  }
@@ -11204,5 +11241,5 @@ export {
11204
11241
  buildRAGAnswerWorkflowState
11205
11242
  };
11206
11243
 
11207
- //# debugId=BBD54682699ADBB064756E2164756E21
11244
+ //# debugId=54241FE5D0E8F13464756E2164756E21
11208
11245
  //# sourceMappingURL=ui.js.map