@absolutejs/rag 0.0.8 → 0.0.9

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,6 +1,23 @@
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 { rename, unlink, writeFile } from "fs/promises";
7
+ var writeFileAtomic = async (path, data, encoding = "utf8") => {
8
+ const tmpPath = `${path}.tmp.${process.pid}.${Math.random().toString(36).slice(2, 10)}`;
9
+ try {
10
+ await writeFile(tmpPath, data, encoding);
11
+ await rename(tmpPath, path);
12
+ } catch (error) {
13
+ try {
14
+ await unlink(tmpPath);
15
+ } catch {}
16
+ throw error;
17
+ }
18
+ };
19
+
20
+ // src/ai/rag/quality.ts
4
21
  import { dirname } from "path";
5
22
  import { generateId } from "@absolutejs/ai";
6
23
 
@@ -6505,7 +6522,7 @@ var createRAGFileEvaluationHistoryStore = (path) => ({
6505
6522
  ...existing.filter((entry) => entry.id !== run.id)
6506
6523
  ]);
6507
6524
  await mkdir(dirname(path), { recursive: true });
6508
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6525
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6509
6526
  `, "utf8");
6510
6527
  },
6511
6528
  pruneRuns: async (input) => {
@@ -6525,7 +6542,7 @@ var createRAGFileEvaluationHistoryStore = (path) => ({
6525
6542
  sort: normalizeHistoryRuns
6526
6543
  });
6527
6544
  await mkdir(dirname(path), { recursive: true });
6528
- await writeFile(path, JSON.stringify(pruned.next, null, "\t") + `
6545
+ await writeFileAtomic(path, JSON.stringify(pruned.next, null, "\t") + `
6529
6546
  `, "utf8");
6530
6547
  return {
6531
6548
  keptCount: pruned.keptCount,
@@ -6576,7 +6593,7 @@ var createRAGFileEvaluationSuiteSnapshotHistoryStore = (path) => ({
6576
6593
  ...existing.filter((entry) => entry.id !== snapshot.id)
6577
6594
  ]);
6578
6595
  await mkdir(dirname(path), { recursive: true });
6579
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6596
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6580
6597
  `, "utf8");
6581
6598
  },
6582
6599
  pruneSnapshots: async (input) => {
@@ -6596,7 +6613,7 @@ var createRAGFileEvaluationSuiteSnapshotHistoryStore = (path) => ({
6596
6613
  sort: normalizeEvaluationSuiteSnapshots
6597
6614
  });
6598
6615
  await mkdir(dirname(path), { recursive: true });
6599
- await writeFile(path, JSON.stringify(pruned.next, null, "\t") + `
6616
+ await writeFileAtomic(path, JSON.stringify(pruned.next, null, "\t") + `
6600
6617
  `, "utf8");
6601
6618
  return {
6602
6619
  keptCount: pruned.keptCount,
@@ -6639,7 +6656,7 @@ var createRAGFileRetrievalComparisonHistoryStore = (path) => ({
6639
6656
  ...existing.filter((entry) => entry.id !== run.id)
6640
6657
  ]);
6641
6658
  await mkdir(dirname(path), { recursive: true });
6642
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6659
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6643
6660
  `, "utf8");
6644
6661
  }
6645
6662
  });
@@ -6693,7 +6710,7 @@ var createRAGFileRetrievalBaselineStore = (path) => {
6693
6710
  ...existing.map((entry) => entry.groupKey === record.groupKey && (entry.rolloutLabel ?? undefined) === (record.rolloutLabel ?? undefined) ? { ...entry, status: "superseded" } : entry)
6694
6711
  ]);
6695
6712
  await mkdir(dirname(path), { recursive: true });
6696
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6713
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6697
6714
  `, "utf8");
6698
6715
  }
6699
6716
  };
@@ -6732,7 +6749,7 @@ var createRAGFileRetrievalReleaseDecisionStore = (path) => ({
6732
6749
  ...existing.filter((entry) => entry.id !== record.id)
6733
6750
  ]);
6734
6751
  await mkdir(dirname(path), { recursive: true });
6735
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6752
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6736
6753
  `, "utf8");
6737
6754
  }
6738
6755
  });
@@ -6776,7 +6793,7 @@ var createRAGFileRetrievalLaneHandoffDecisionStore = (path) => ({
6776
6793
  ...existing.filter((entry) => entry.id !== record.id)
6777
6794
  ]);
6778
6795
  await mkdir(dirname(path), { recursive: true });
6779
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6796
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6780
6797
  `, "utf8");
6781
6798
  }
6782
6799
  });
@@ -6821,7 +6838,7 @@ var createRAGFileRetrievalReleaseIncidentStore = (path) => ({
6821
6838
  ...existing.filter((entry) => entry.id !== record.id)
6822
6839
  ]);
6823
6840
  await mkdir(dirname(path), { recursive: true });
6824
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6841
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6825
6842
  `, "utf8");
6826
6843
  }
6827
6844
  });
@@ -6865,7 +6882,7 @@ var createRAGFileRetrievalLaneHandoffIncidentStore = (path) => ({
6865
6882
  ...existing.filter((entry) => entry.id !== record.id)
6866
6883
  ]);
6867
6884
  await mkdir(dirname(path), { recursive: true });
6868
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6885
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6869
6886
  `, "utf8");
6870
6887
  }
6871
6888
  });
@@ -6905,7 +6922,7 @@ var createRAGFileRetrievalLaneHandoffIncidentHistoryStore = (path) => ({
6905
6922
  })();
6906
6923
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
6907
6924
  await mkdir(dirname(path), { recursive: true });
6908
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6925
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6909
6926
  `, "utf8");
6910
6927
  }
6911
6928
  });
@@ -6949,7 +6966,7 @@ var createRAGFileRetrievalIncidentRemediationDecisionStore = (path) => ({
6949
6966
  ...existing
6950
6967
  ]);
6951
6968
  await mkdir(dirname(path), { recursive: true });
6952
- await writeFile(path, JSON.stringify(next, null, "\t") + `
6969
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6953
6970
  `, "utf8");
6954
6971
  }
6955
6972
  });
@@ -6995,7 +7012,7 @@ var createRAGFileRetrievalIncidentRemediationExecutionHistoryStore = (path) => (
6995
7012
  ...existing
6996
7013
  ]);
6997
7014
  await mkdir(dirname(path), { recursive: true });
6998
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7015
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
6999
7016
  `, "utf8");
7000
7017
  }
7001
7018
  });
@@ -7029,7 +7046,7 @@ var createRAGFileRetrievalLaneHandoffAutoCompletePolicyHistoryStore = (path) =>
7029
7046
  })();
7030
7047
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7031
7048
  await mkdir(dirname(path), { recursive: true });
7032
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7049
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7033
7050
  `, "utf8");
7034
7051
  }
7035
7052
  });
@@ -7063,7 +7080,7 @@ var createRAGFileRetrievalReleaseLanePolicyHistoryStore = (path) => ({
7063
7080
  })();
7064
7081
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7065
7082
  await mkdir(dirname(path), { recursive: true });
7066
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7083
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7067
7084
  `, "utf8");
7068
7085
  }
7069
7086
  });
@@ -7097,7 +7114,7 @@ var createRAGFileRetrievalBaselineGatePolicyHistoryStore = (path) => ({
7097
7114
  })();
7098
7115
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7099
7116
  await mkdir(dirname(path), { recursive: true });
7100
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7117
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7101
7118
  `, "utf8");
7102
7119
  }
7103
7120
  });
@@ -7131,7 +7148,7 @@ var createRAGFileRetrievalReleaseLaneEscalationPolicyHistoryStore = (path) => ({
7131
7148
  })();
7132
7149
  const next = [record, ...existing].sort((left, right) => right.recordedAt - left.recordedAt);
7133
7150
  await mkdir(dirname(path), { recursive: true });
7134
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7151
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7135
7152
  `, "utf8");
7136
7153
  }
7137
7154
  });
@@ -7177,7 +7194,7 @@ var createRAGFileSearchTraceStore = (path) => ({
7177
7194
  ...traces.filter((entry) => entry.id !== trace.id)
7178
7195
  ]);
7179
7196
  await mkdir(dirname(path), { recursive: true });
7180
- await writeFile(path, JSON.stringify({
7197
+ await writeFileAtomic(path, JSON.stringify({
7181
7198
  traces: nextTraces
7182
7199
  }, null, 2));
7183
7200
  },
@@ -7197,7 +7214,7 @@ var createRAGFileSearchTraceStore = (path) => ({
7197
7214
  traces
7198
7215
  });
7199
7216
  await mkdir(dirname(path), { recursive: true });
7200
- await writeFile(path, JSON.stringify({
7217
+ await writeFileAtomic(path, JSON.stringify({
7201
7218
  traces: pruned.next
7202
7219
  }, null, 2));
7203
7220
  return {
@@ -7240,7 +7257,7 @@ var createRAGFileSearchTracePruneHistoryStore = (path) => ({
7240
7257
  ...existing.filter((entry) => entry.id !== run.id)
7241
7258
  ]);
7242
7259
  await mkdir(dirname(path), { recursive: true });
7243
- await writeFile(path, JSON.stringify(next, null, "\t") + `
7260
+ await writeFileAtomic(path, JSON.stringify(next, null, "\t") + `
7244
7261
  `, "utf8");
7245
7262
  }
7246
7263
  });
@@ -8869,7 +8886,7 @@ var createRAGFileAnswerGroundingEvaluationHistoryStore = (path) => ({
8869
8886
  ...runs.filter((entry) => entry.id !== run.id)
8870
8887
  ]);
8871
8888
  await mkdir(dirname(path), { recursive: true });
8872
- await writeFile(path, JSON.stringify({
8889
+ await writeFileAtomic(path, JSON.stringify({
8873
8890
  runs: nextRuns
8874
8891
  }, null, 2));
8875
8892
  },
@@ -8890,7 +8907,7 @@ var createRAGFileAnswerGroundingEvaluationHistoryStore = (path) => ({
8890
8907
  sort: normalizeGroundingHistoryRuns
8891
8908
  });
8892
8909
  await mkdir(dirname(path), { recursive: true });
8893
- await writeFile(path, JSON.stringify({
8910
+ await writeFileAtomic(path, JSON.stringify({
8894
8911
  runs: pruned.next
8895
8912
  }, null, 2));
8896
8913
  return {
@@ -8930,7 +8947,7 @@ var createRAGFileAnswerGroundingCaseDifficultyHistoryStore = (path) => ({
8930
8947
  ...runs.filter((entry) => entry.id !== run.id)
8931
8948
  ]);
8932
8949
  await mkdir(dirname(path), { recursive: true });
8933
- await writeFile(path, JSON.stringify({
8950
+ await writeFileAtomic(path, JSON.stringify({
8934
8951
  runs: nextRuns
8935
8952
  }, null, 2));
8936
8953
  }
@@ -32137,7 +32154,7 @@ var createRAGInstagramBusinessConnector = (input) => ({
32137
32154
  // src/ai/rag/sync.ts
32138
32155
  var {S3Client } = globalThis.Bun;
32139
32156
  import { createHash } from "crypto";
32140
- import { mkdir as mkdir2, readFile as readFile3, readdir as readdir2, writeFile as writeFile2 } from "fs/promises";
32157
+ import { mkdir as mkdir2, readFile as readFile3, readdir as readdir2 } from "fs/promises";
32141
32158
  import { basename as basename2, dirname as dirname2, extname as extname2, join as join2, relative as relative2, resolve as resolve2 } from "path";
32142
32159
  var toSyncError = (caught) => caught instanceof Error ? caught.message : String(caught);
32143
32160
  var wait = async (delayMs) => {
@@ -34636,7 +34653,7 @@ var createRAGFileSyncStateStore = (path) => {
34636
34653
  },
34637
34654
  save: async (records) => {
34638
34655
  await mkdir2(dirname2(resolvedPath), { recursive: true });
34639
- await writeFile2(resolvedPath, JSON.stringify(records, null, 2), "utf8");
34656
+ await writeFileAtomic(resolvedPath, JSON.stringify(records, null, 2), "utf8");
34640
34657
  }
34641
34658
  };
34642
34659
  };
@@ -34683,7 +34700,7 @@ var createRAGSyncScheduler = (input) => {
34683
34700
  };
34684
34701
  };
34685
34702
  // src/ai/rag/jobState.ts
34686
- import { mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
34703
+ import { mkdir as mkdir3, readFile as readFile4 } from "fs/promises";
34687
34704
  import { dirname as dirname3, resolve as resolve3 } from "path";
34688
34705
  var parseJobState = (content) => {
34689
34706
  try {
@@ -34720,7 +34737,7 @@ var createRAGFileJobStateStore = (path) => {
34720
34737
  },
34721
34738
  save: async (state) => {
34722
34739
  await mkdir3(dirname3(resolvedPath), { recursive: true });
34723
- await writeFile3(resolvedPath, JSON.stringify(state, null, 2), "utf8");
34740
+ await writeFileAtomic(resolvedPath, JSON.stringify(state, null, 2), "utf8");
34724
34741
  }
34725
34742
  };
34726
34743
  };
@@ -37474,5 +37491,5 @@ export {
37474
37491
  addRAGEvaluationSuiteCase
37475
37492
  };
37476
37493
 
37477
- //# debugId=C60E619F8D901C1764756E2164756E21
37494
+ //# debugId=26E70B5CD574E08C64756E2164756E21
37478
37495
  //# sourceMappingURL=index.js.map