@codemem/core 0.21.0 → 0.21.2
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.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +810 -711
- package/dist/index.js.map +1 -1
- package/dist/ingest-pipeline.d.ts.map +1 -1
- package/dist/observer-client.d.ts.map +1 -1
- package/dist/raw-event-flush.d.ts +0 -1
- package/dist/raw-event-flush.d.ts.map +1 -1
- package/dist/raw-event-sweeper.d.ts.map +1 -1
- package/dist/sync-replication.d.ts +21 -0
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-retention-runner.d.ts +11 -0
- package/dist/sync-retention-runner.d.ts.map +1 -1
- package/dist/vectors.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4730,20 +4730,43 @@ function Uo(e) {
|
|
|
4730
4730
|
}
|
|
4731
4731
|
//#endregion
|
|
4732
4732
|
//#region src/vectors.ts
|
|
4733
|
-
|
|
4733
|
+
function Wo(e) {
|
|
4734
|
+
return `'${e.replaceAll("'", "''")}'`;
|
|
4735
|
+
}
|
|
4736
|
+
function Go(e) {
|
|
4737
|
+
return `vec_f32(${Wo(JSON.stringify(Array.from(e)))})`;
|
|
4738
|
+
}
|
|
4739
|
+
function Ko(e) {
|
|
4740
|
+
if (!Number.isFinite(e)) throw TypeError(`Expected finite integer, received ${String(e)}`);
|
|
4741
|
+
if (!Number.isInteger(e)) throw TypeError(`Expected integer, received ${String(e)}`);
|
|
4742
|
+
return String(e);
|
|
4743
|
+
}
|
|
4744
|
+
function qo(e, t, n, r, i, a) {
|
|
4745
|
+
e.exec(`
|
|
4746
|
+
INSERT INTO memory_vectors(embedding, memory_id, chunk_index, content_hash, model)
|
|
4747
|
+
VALUES (
|
|
4748
|
+
${Go(t)},
|
|
4749
|
+
${Ko(n)},
|
|
4750
|
+
${Ko(r)},
|
|
4751
|
+
${Wo(i)},
|
|
4752
|
+
${Wo(a)}
|
|
4753
|
+
)
|
|
4754
|
+
`);
|
|
4755
|
+
}
|
|
4756
|
+
async function Jo(e, t, n, r) {
|
|
4734
4757
|
let i = await na();
|
|
4735
4758
|
if (!i) return;
|
|
4736
4759
|
let a = $i(`${n}\n${r}`.trim());
|
|
4737
4760
|
if (a.length === 0) return;
|
|
4738
4761
|
let o = await ra(a);
|
|
4739
4762
|
if (o.length === 0) return;
|
|
4740
|
-
let s = i.model
|
|
4741
|
-
for (let
|
|
4742
|
-
let
|
|
4743
|
-
!
|
|
4763
|
+
let s = i.model;
|
|
4764
|
+
for (let n = 0; n < a.length && n < o.length; n++) {
|
|
4765
|
+
let r = o[n], i = a[n];
|
|
4766
|
+
!r || r.length === 0 || i && qo(e, r, t, n, Qi(i), s);
|
|
4744
4767
|
}
|
|
4745
4768
|
}
|
|
4746
|
-
async function
|
|
4769
|
+
async function Yo(e, t = {}) {
|
|
4747
4770
|
let n = await na();
|
|
4748
4771
|
if (!n) return {
|
|
4749
4772
|
checked: 0,
|
|
@@ -4781,15 +4804,15 @@ async function Go(e, t = {}) {
|
|
|
4781
4804
|
}
|
|
4782
4805
|
if (a.length === 0) continue;
|
|
4783
4806
|
let c = await ra(a);
|
|
4784
|
-
if (c.length
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4807
|
+
if (c.length !== 0) {
|
|
4808
|
+
if (_ += c.length, s) {
|
|
4809
|
+
v += c.length;
|
|
4810
|
+
continue;
|
|
4811
|
+
}
|
|
4812
|
+
for (let n = 0; n < c.length; n++) {
|
|
4813
|
+
let r = c[n], i = o[n];
|
|
4814
|
+
!r || r.length === 0 || i && (qo(e, r, t.id, n, i, h), v++);
|
|
4815
|
+
}
|
|
4793
4816
|
}
|
|
4794
4817
|
}
|
|
4795
4818
|
return {
|
|
@@ -4799,7 +4822,7 @@ async function Go(e, t = {}) {
|
|
|
4799
4822
|
skipped: y
|
|
4800
4823
|
};
|
|
4801
4824
|
}
|
|
4802
|
-
async function
|
|
4825
|
+
async function Xo(e, t, n = 10, r) {
|
|
4803
4826
|
if (t.trim().length < 3) return [];
|
|
4804
4827
|
let i = await ra([t]);
|
|
4805
4828
|
if (i.length === 0) return [];
|
|
@@ -4837,7 +4860,7 @@ async function Ko(e, t, n = 10, r) {
|
|
|
4837
4860
|
}
|
|
4838
4861
|
//#endregion
|
|
4839
4862
|
//#region src/ingest-pipeline.ts
|
|
4840
|
-
var
|
|
4863
|
+
var Zo = new Set([
|
|
4841
4864
|
"bugfix",
|
|
4842
4865
|
"feature",
|
|
4843
4866
|
"refactor",
|
|
@@ -4846,17 +4869,17 @@ var qo = new Set([
|
|
|
4846
4869
|
"decision",
|
|
4847
4870
|
"exploration"
|
|
4848
4871
|
]);
|
|
4849
|
-
function
|
|
4872
|
+
function Qo(e, t) {
|
|
4850
4873
|
if (!e) return "";
|
|
4851
4874
|
let n = e.trim();
|
|
4852
4875
|
if (!t) return n;
|
|
4853
4876
|
let r = t.replace(/\/+$/, "");
|
|
4854
4877
|
return n === r ? "." : n.startsWith(`${r}/`) ? n.slice(r.length + 1) : n;
|
|
4855
4878
|
}
|
|
4856
|
-
function
|
|
4857
|
-
return e.map((e) =>
|
|
4879
|
+
function $o(e, t) {
|
|
4880
|
+
return e.map((e) => Qo(e, t)).filter(Boolean);
|
|
4858
4881
|
}
|
|
4859
|
-
function
|
|
4882
|
+
function es(e) {
|
|
4860
4883
|
return [
|
|
4861
4884
|
["Request", e.request],
|
|
4862
4885
|
["Completed", e.completed],
|
|
@@ -4866,7 +4889,7 @@ function Xo(e) {
|
|
|
4866
4889
|
["Notes", e.notes]
|
|
4867
4890
|
].filter(([, e]) => e).map(([e, t]) => `## ${e}\n${t}`).join("\n\n");
|
|
4868
4891
|
}
|
|
4869
|
-
function
|
|
4892
|
+
function ts(e, t) {
|
|
4870
4893
|
let n = [];
|
|
4871
4894
|
for (let r of e) {
|
|
4872
4895
|
let e = eo(r);
|
|
@@ -4886,7 +4909,34 @@ function Zo(e, t) {
|
|
|
4886
4909
|
}
|
|
4887
4910
|
return n;
|
|
4888
4911
|
}
|
|
4889
|
-
|
|
4912
|
+
function ns(e) {
|
|
4913
|
+
return e.observations.length > 0 || e.summary !== null || e.skipSummaryReason !== null;
|
|
4914
|
+
}
|
|
4915
|
+
async function rs(e, t, n) {
|
|
4916
|
+
let r = await e.observe(t, n), i = r.raw ? Ro(r.raw) : {
|
|
4917
|
+
observations: [],
|
|
4918
|
+
summary: null,
|
|
4919
|
+
skipSummaryReason: null
|
|
4920
|
+
};
|
|
4921
|
+
if (!r.raw || ns(i)) return {
|
|
4922
|
+
raw: r.raw,
|
|
4923
|
+
parsed: i,
|
|
4924
|
+
provider: r.provider,
|
|
4925
|
+
model: r.model
|
|
4926
|
+
};
|
|
4927
|
+
let a = `${t}\n\nYour previous reply was invalid because it did not follow the required XML-only schema. Rewrite the same analysis as valid XML only. Do not include prose outside XML.`, o = `${n}\n\nPrevious invalid response to rewrite as valid XML:\n${r.raw}`, s = await e.observe(a, o), c = s.raw ? Ro(s.raw) : {
|
|
4928
|
+
observations: [],
|
|
4929
|
+
summary: null,
|
|
4930
|
+
skipSummaryReason: null
|
|
4931
|
+
};
|
|
4932
|
+
return {
|
|
4933
|
+
raw: s.raw,
|
|
4934
|
+
parsed: c,
|
|
4935
|
+
provider: s.provider,
|
|
4936
|
+
model: s.model
|
|
4937
|
+
};
|
|
4938
|
+
}
|
|
4939
|
+
async function is(e, t, n) {
|
|
4890
4940
|
let r = e.cwd ?? process.cwd(), i = e.events ?? [];
|
|
4891
4941
|
if (!Array.isArray(i) || i.length === 0) return;
|
|
4892
4942
|
let a = e.sessionContext ?? {}, o = n.storeSummary ?? !0, s = n.storeTyped ?? !0, c = n.maxChars ?? 12e3, l = n.observerMaxChars ?? 12e3, u = N(t.db, { schema: H }), d = (/* @__PURE__ */ new Date()).toISOString(), f = Ce(e.project) ?? Qt(r) ?? null, p = u.insert(U).values({
|
|
@@ -4904,11 +4954,11 @@ async function Qo(e, t, n) {
|
|
|
4904
4954
|
}).returning({ id: U.id }).all()[0]?.id;
|
|
4905
4955
|
if (p == null) throw Error("session insert returned no id");
|
|
4906
4956
|
try {
|
|
4907
|
-
let e = Oo(i), d = Do(e), m = d.length > 0 ? d[d.length - 1]?.promptNumber ?? d.length : null, h =
|
|
4957
|
+
let e = Oo(i), d = Do(e), m = d.length > 0 ? d[d.length - 1]?.promptNumber ?? d.length : null, h = ts(i, c), g = Math.max(2e3, Math.min(8e3, l - 5e3));
|
|
4908
4958
|
h = ao(h, g, 30);
|
|
4909
4959
|
let _ = To(e), v = Eo(e), y = _.at(-1) ?? null, b = a.firstPrompt ?? (d.length > 0 ? d[d.length - 1]?.promptText : null) ?? null, x = h.length > 0 || !!b || o && !!y;
|
|
4910
4960
|
if (b && xo(b) && h.length === 0 && !y && (x = !1), !x) {
|
|
4911
|
-
|
|
4961
|
+
as(t, p, i.length, a);
|
|
4912
4962
|
return;
|
|
4913
4963
|
}
|
|
4914
4964
|
let S = wo(e), C = [];
|
|
@@ -4928,29 +4978,29 @@ async function Qo(e, t, n) {
|
|
|
4928
4978
|
includeSummary: o,
|
|
4929
4979
|
diffSummary: "",
|
|
4930
4980
|
recentFiles: ""
|
|
4931
|
-
}), te = await n.observer
|
|
4981
|
+
}), te = await rs(n.observer, E, ee);
|
|
4932
4982
|
if (!te.raw) {
|
|
4933
4983
|
if (a?.flusher === "raw_events") throw Error("observer failed during raw-event flush");
|
|
4934
4984
|
let e = n.observer.getStatus();
|
|
4935
|
-
console.warn(`[codemem] Observer returned no output (provider=${te.provider}, model=${te.model}${e.lastError ? `, error=${e.lastError}` : ""}). No memories will be created for this session.`),
|
|
4985
|
+
console.warn(`[codemem] Observer returned no output (provider=${te.provider}, model=${te.model}${e.lastError ? `, error=${e.lastError}` : ""}). No memories will be created for this session.`), as(t, p, i.length, a);
|
|
4936
4986
|
return;
|
|
4937
4987
|
}
|
|
4938
|
-
let D = te.raw, O =
|
|
4988
|
+
let D = te.raw, O = te.parsed, k = [];
|
|
4939
4989
|
if (s && zo(O.observations)) for (let e of O.observations) {
|
|
4940
4990
|
let t = e.kind.trim().toLowerCase();
|
|
4941
|
-
|
|
4991
|
+
Zo.has(t) && (!e.title && !e.narrative || Kt(e.title) || Kt(e.narrative) || (e.filesRead = $o(e.filesRead, r), e.filesModified = $o(e.filesModified, r), k.push(e)));
|
|
4942
4992
|
}
|
|
4943
4993
|
let A = null;
|
|
4944
4994
|
if (o && O.summary && !O.skipSummaryReason) {
|
|
4945
4995
|
let e = O.summary;
|
|
4946
4996
|
if (e.request || e.investigated || e.learned || e.completed || e.nextSteps || e.notes) {
|
|
4947
|
-
e.filesRead =
|
|
4997
|
+
e.filesRead = $o(e.filesRead, r), e.filesModified = $o(e.filesModified, r);
|
|
4948
4998
|
let t = e.request;
|
|
4949
4999
|
if (xo(t)) {
|
|
4950
5000
|
let n = Co(e);
|
|
4951
5001
|
n && (t = n);
|
|
4952
5002
|
}
|
|
4953
|
-
let n =
|
|
5003
|
+
let n = es(e);
|
|
4954
5004
|
n && !Kt(So(n)) && (A = {
|
|
4955
5005
|
summary: e,
|
|
4956
5006
|
request: t,
|
|
@@ -5028,17 +5078,17 @@ async function Qo(e, t, n) {
|
|
|
5028
5078
|
}).run();
|
|
5029
5079
|
})();
|
|
5030
5080
|
for (let e of ne) try {
|
|
5031
|
-
await
|
|
5081
|
+
await Jo(t.db, e.memoryId, e.title, e.bodyText);
|
|
5032
5082
|
} catch {}
|
|
5033
|
-
|
|
5083
|
+
as(t, p, i.length, a);
|
|
5034
5084
|
} catch (e) {
|
|
5035
5085
|
try {
|
|
5036
|
-
|
|
5086
|
+
as(t, p, i.length, a);
|
|
5037
5087
|
} catch {}
|
|
5038
5088
|
throw e;
|
|
5039
5089
|
}
|
|
5040
5090
|
}
|
|
5041
|
-
function
|
|
5091
|
+
function as(e, t, n, r) {
|
|
5042
5092
|
e.endSession(t, {
|
|
5043
5093
|
post: {},
|
|
5044
5094
|
source: "plugin",
|
|
@@ -5046,11 +5096,11 @@ function $o(e, t, n, r) {
|
|
|
5046
5096
|
session_context: r
|
|
5047
5097
|
});
|
|
5048
5098
|
}
|
|
5049
|
-
function
|
|
5099
|
+
function os(e, t = 24) {
|
|
5050
5100
|
let n = N(e.db, { schema: H }), r = (/* @__PURE__ */ new Date(Date.now() - t * 36e5)).toISOString();
|
|
5051
5101
|
return n.update(U).set({ ended_at: r }).where(D(ie(U.ended_at), oe(U.started_at, r))).run().changes;
|
|
5052
5102
|
}
|
|
5053
|
-
async function
|
|
5103
|
+
async function ss(e, t) {
|
|
5054
5104
|
let n = [];
|
|
5055
5105
|
for await (let e of process.stdin) n.push(String(e));
|
|
5056
5106
|
let r = n.join("");
|
|
@@ -5061,30 +5111,30 @@ async function ts(e, t) {
|
|
|
5061
5111
|
} catch (e) {
|
|
5062
5112
|
throw Error(`codemem: invalid payload: ${e}`);
|
|
5063
5113
|
}
|
|
5064
|
-
await
|
|
5114
|
+
await is(i, e, { observer: t });
|
|
5065
5115
|
}
|
|
5066
5116
|
//#endregion
|
|
5067
5117
|
//#region src/integers.ts
|
|
5068
|
-
var
|
|
5069
|
-
function
|
|
5118
|
+
var cs = BigInt(2 ** 53 - 1), ls = BigInt(-(2 ** 53 - 1));
|
|
5119
|
+
function us(e) {
|
|
5070
5120
|
if (e == null) return null;
|
|
5071
5121
|
let t = e.trim();
|
|
5072
5122
|
if (!/^[+-]?\d+$/.test(t)) return null;
|
|
5073
5123
|
try {
|
|
5074
5124
|
let e = BigInt(t);
|
|
5075
|
-
return e <
|
|
5125
|
+
return e < ls || e > cs ? null : Number(e);
|
|
5076
5126
|
} catch {
|
|
5077
5127
|
return null;
|
|
5078
5128
|
}
|
|
5079
5129
|
}
|
|
5080
|
-
function
|
|
5130
|
+
function ds(e) {
|
|
5081
5131
|
if (typeof e == "boolean") return null;
|
|
5082
5132
|
if (typeof e == "number") return !Number.isInteger(e) || !Number.isSafeInteger(e) || e <= 0 ? null : e;
|
|
5083
5133
|
if (typeof e == "string") {
|
|
5084
5134
|
if (!/^\d+$/.test(e)) return null;
|
|
5085
5135
|
try {
|
|
5086
5136
|
let t = BigInt(e);
|
|
5087
|
-
return t <= 0n || t >
|
|
5137
|
+
return t <= 0n || t > cs ? null : Number(t);
|
|
5088
5138
|
} catch {
|
|
5089
5139
|
return null;
|
|
5090
5140
|
}
|
|
@@ -5093,24 +5143,24 @@ function as(e) {
|
|
|
5093
5143
|
}
|
|
5094
5144
|
//#endregion
|
|
5095
5145
|
//#region src/observer-auth.ts
|
|
5096
|
-
var
|
|
5097
|
-
function
|
|
5146
|
+
var fs = "0.0.1", ps = [/sk-[A-Za-z0-9]{10,}/g, /Bearer\s+[A-Za-z0-9._-]{10,}/g];
|
|
5147
|
+
function ms(e, t = 400) {
|
|
5098
5148
|
let n = e;
|
|
5099
|
-
for (let e of
|
|
5149
|
+
for (let e of ps) n = n.replace(new RegExp(e.source, e.flags), "[redacted]");
|
|
5100
5150
|
return n.length > t ? `${n.slice(0, t)}…` : n;
|
|
5101
5151
|
}
|
|
5102
|
-
function
|
|
5152
|
+
function hs() {
|
|
5103
5153
|
return {
|
|
5104
5154
|
token: null,
|
|
5105
5155
|
authType: "none",
|
|
5106
5156
|
source: "none"
|
|
5107
5157
|
};
|
|
5108
5158
|
}
|
|
5109
|
-
function
|
|
5159
|
+
function gs() {
|
|
5110
5160
|
return T(v(), ".local", "share", "opencode", "auth.json");
|
|
5111
5161
|
}
|
|
5112
|
-
function
|
|
5113
|
-
let e =
|
|
5162
|
+
function _s() {
|
|
5163
|
+
let e = gs();
|
|
5114
5164
|
if (!l(e)) return {};
|
|
5115
5165
|
try {
|
|
5116
5166
|
let t = JSON.parse(f(e, "utf-8"));
|
|
@@ -5119,55 +5169,55 @@ function ds() {
|
|
|
5119
5169
|
return {};
|
|
5120
5170
|
}
|
|
5121
5171
|
}
|
|
5122
|
-
function
|
|
5172
|
+
function vs(e, t) {
|
|
5123
5173
|
return e && ["openai", "anthropic"].includes(e.toLowerCase()) ? e.toLowerCase() : t.toLowerCase().startsWith("claude") ? "anthropic" : "openai";
|
|
5124
5174
|
}
|
|
5125
|
-
function
|
|
5175
|
+
function ys(e, t) {
|
|
5126
5176
|
let n = e[t];
|
|
5127
5177
|
return typeof n == "object" && n && !Array.isArray(n) ? n : null;
|
|
5128
5178
|
}
|
|
5129
|
-
function
|
|
5130
|
-
let n =
|
|
5179
|
+
function bs(e, t) {
|
|
5180
|
+
let n = ys(e, t);
|
|
5131
5181
|
if (!n) return null;
|
|
5132
5182
|
let r = n.access;
|
|
5133
5183
|
return typeof r == "string" && r ? r : null;
|
|
5134
5184
|
}
|
|
5135
|
-
function
|
|
5136
|
-
let n =
|
|
5185
|
+
function xs(e, t) {
|
|
5186
|
+
let n = ys(e, t);
|
|
5137
5187
|
if (!n) return null;
|
|
5138
5188
|
let r = n.key;
|
|
5139
5189
|
return typeof r == "string" && r ? r : null;
|
|
5140
5190
|
}
|
|
5141
|
-
function
|
|
5142
|
-
let e =
|
|
5191
|
+
function Ss() {
|
|
5192
|
+
let e = _s(), t = Date.now(), n = !!process.env.CODEMEM_OBSERVER_API_KEY, r = [
|
|
5143
5193
|
["openai", "OPENAI_API_KEY"],
|
|
5144
5194
|
["anthropic", "ANTHROPIC_API_KEY"],
|
|
5145
5195
|
["opencode", null]
|
|
5146
5196
|
], i = {};
|
|
5147
5197
|
for (let [a, o] of r) {
|
|
5148
|
-
let r =
|
|
5198
|
+
let r = bs(e, a), s = ws(e, a);
|
|
5149
5199
|
i[a] = {
|
|
5150
|
-
oauth: a === "opencode" ? !!
|
|
5200
|
+
oauth: a === "opencode" ? !!xs(e, a) : !!r && (s == null || s > t),
|
|
5151
5201
|
api_key: n,
|
|
5152
5202
|
env_var: o ? !!process.env[o] : !1
|
|
5153
5203
|
};
|
|
5154
5204
|
}
|
|
5155
5205
|
return i;
|
|
5156
5206
|
}
|
|
5157
|
-
function
|
|
5158
|
-
let n =
|
|
5207
|
+
function Cs(e, t) {
|
|
5208
|
+
let n = ys(e, t);
|
|
5159
5209
|
if (!n) return null;
|
|
5160
5210
|
let r = n.accountId;
|
|
5161
5211
|
return typeof r == "string" && r ? r : null;
|
|
5162
5212
|
}
|
|
5163
|
-
function
|
|
5164
|
-
let n =
|
|
5213
|
+
function ws(e, t) {
|
|
5214
|
+
let n = ys(e, t);
|
|
5165
5215
|
if (!n) return null;
|
|
5166
5216
|
let r = n.expires;
|
|
5167
5217
|
return typeof r == "number" ? r : null;
|
|
5168
5218
|
}
|
|
5169
|
-
function
|
|
5170
|
-
let n = process.env.CODEMEM_CODEX_ORIGINATOR ?? "opencode", r = process.env.CODEMEM_CODEX_USER_AGENT ?? `codemem/${
|
|
5219
|
+
function Ts(e, t) {
|
|
5220
|
+
let n = process.env.CODEMEM_CODEX_ORIGINATOR ?? "opencode", r = process.env.CODEMEM_CODEX_USER_AGENT ?? `codemem/${fs} (${b()} ${x()}; ${_()})`, i = {
|
|
5171
5221
|
authorization: `Bearer ${e}`,
|
|
5172
5222
|
originator: n,
|
|
5173
5223
|
"User-Agent": r,
|
|
@@ -5175,7 +5225,7 @@ function ys(e, t) {
|
|
|
5175
5225
|
};
|
|
5176
5226
|
return t && (i["ChatGPT-Account-Id"] = t), i;
|
|
5177
5227
|
}
|
|
5178
|
-
function
|
|
5228
|
+
function Es(e, t) {
|
|
5179
5229
|
let n = e[0];
|
|
5180
5230
|
if (!n) return null;
|
|
5181
5231
|
let r = Math.max(100, t);
|
|
@@ -5193,7 +5243,7 @@ function bs(e, t) {
|
|
|
5193
5243
|
return null;
|
|
5194
5244
|
}
|
|
5195
5245
|
}
|
|
5196
|
-
function
|
|
5246
|
+
function Ds(e) {
|
|
5197
5247
|
if (!e) return null;
|
|
5198
5248
|
let t = e.replace(/^~/, v());
|
|
5199
5249
|
t = t.replace(/\$\{([^}]+)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (e, t, n) => {
|
|
@@ -5206,7 +5256,7 @@ function xs(e) {
|
|
|
5206
5256
|
return null;
|
|
5207
5257
|
}
|
|
5208
5258
|
}
|
|
5209
|
-
var
|
|
5259
|
+
var Os = new Set([
|
|
5210
5260
|
"",
|
|
5211
5261
|
"auto",
|
|
5212
5262
|
"env",
|
|
@@ -5214,47 +5264,47 @@ var Ss = new Set([
|
|
|
5214
5264
|
"command",
|
|
5215
5265
|
"none"
|
|
5216
5266
|
]);
|
|
5217
|
-
function
|
|
5267
|
+
function ks(e) {
|
|
5218
5268
|
let t = (e ?? "").trim().toLowerCase();
|
|
5219
|
-
return
|
|
5269
|
+
return Os.has(t) && t || "auto";
|
|
5220
5270
|
}
|
|
5221
|
-
var
|
|
5271
|
+
var As = class {
|
|
5222
5272
|
source;
|
|
5223
5273
|
filePath;
|
|
5224
5274
|
command;
|
|
5225
5275
|
timeoutMs;
|
|
5226
5276
|
cacheTtlS;
|
|
5227
|
-
cached =
|
|
5277
|
+
cached = hs();
|
|
5228
5278
|
cachedAtMs = 0;
|
|
5229
5279
|
constructor(e) {
|
|
5230
5280
|
this.source = e?.source ?? "auto", this.filePath = e?.filePath ?? null, this.command = e?.command ?? [], this.timeoutMs = e?.timeoutMs ?? 1500, this.cacheTtlS = e?.cacheTtlS ?? 300;
|
|
5231
5281
|
}
|
|
5232
5282
|
resolve(e) {
|
|
5233
|
-
let t =
|
|
5234
|
-
if (t === "none") return
|
|
5283
|
+
let t = ks(this.source), n = e?.explicitToken ?? null, r = e?.envTokens ?? [], i = e?.oauthToken ?? null, a = e?.forceRefresh ?? !1;
|
|
5284
|
+
if (t === "none") return hs();
|
|
5235
5285
|
if (!a && (t === "command" || t === "file") && this.cacheTtlS > 0) {
|
|
5236
5286
|
let e = performance.now() - this.cachedAtMs;
|
|
5237
5287
|
if (this.cachedAtMs > 0 && e <= this.cacheTtlS * 1e3) return this.cached;
|
|
5238
5288
|
}
|
|
5239
5289
|
let o = null, s = "none";
|
|
5240
|
-
t === "auto" ? (n && (o = n, s = "explicit"), o || (o = r.find((e) => !!e) ?? null, o && (s = "env")), !o && i && (o = i, s = "oauth")) : t === "env" && (o = r.find((e) => !!e) ?? null, o && (s = "env")), (t === "auto" || t === "file") && !o && (o =
|
|
5290
|
+
t === "auto" ? (n && (o = n, s = "explicit"), o || (o = r.find((e) => !!e) ?? null, o && (s = "env")), !o && i && (o = i, s = "oauth")) : t === "env" && (o = r.find((e) => !!e) ?? null, o && (s = "env")), (t === "auto" || t === "file") && !o && (o = Ds(this.filePath), o && (s = "file")), (t === "auto" || t === "command") && !o && (o = Es(this.command, this.timeoutMs), o && (s = "command"));
|
|
5241
5291
|
let c = o ? {
|
|
5242
5292
|
token: o,
|
|
5243
5293
|
authType: "bearer",
|
|
5244
5294
|
source: s
|
|
5245
|
-
} :
|
|
5295
|
+
} : hs(), l = t === "command" || t === "file";
|
|
5246
5296
|
return l && c.token ? (this.cached = c, this.cachedAtMs = performance.now()) : l && this.invalidateCache(), c;
|
|
5247
5297
|
}
|
|
5248
5298
|
invalidateCache() {
|
|
5249
|
-
this.cached =
|
|
5299
|
+
this.cached = hs(), this.cachedAtMs = 0;
|
|
5250
5300
|
}
|
|
5251
|
-
},
|
|
5252
|
-
function
|
|
5301
|
+
}, js = /\$\{auth\.token\}/g, Ms = /\$\{auth\.type\}/g, Ns = /\$\{auth\.source\}/g;
|
|
5302
|
+
function Ps(e, t) {
|
|
5253
5303
|
let n = t.token ?? "", r = {};
|
|
5254
5304
|
for (let [i, a] of Object.entries(e)) {
|
|
5255
5305
|
if (typeof i != "string" || typeof a != "string") continue;
|
|
5256
|
-
let e = a.replace(
|
|
5257
|
-
if (e = e.replace(
|
|
5306
|
+
let e = a.replace(js, n);
|
|
5307
|
+
if (e = e.replace(Ms, t.authType), e = e.replace(Ns, t.source), a.includes("${auth.token}") && !n) continue;
|
|
5258
5308
|
let o = e.trim();
|
|
5259
5309
|
o && (r[i] = o);
|
|
5260
5310
|
}
|
|
@@ -5262,7 +5312,7 @@ function Os(e, t) {
|
|
|
5262
5312
|
}
|
|
5263
5313
|
//#endregion
|
|
5264
5314
|
//#region src/observer-client.ts
|
|
5265
|
-
var
|
|
5315
|
+
var Fs = "claude-sonnet-4-20250514", Is = "gpt-5.1-codex-mini", Ls = "https://api.anthropic.com/v1/messages", Rs = "2023-06-01", zs = "https://chatgpt.com/backend-api/codex/responses", Bs = 6e4, Vs = {
|
|
5266
5316
|
"claude-4.5-haiku": "claude-haiku-4-5",
|
|
5267
5317
|
"claude-4.5-sonnet": "claude-sonnet-4-5",
|
|
5268
5318
|
"claude-4.5-opus": "claude-opus-4-5",
|
|
@@ -5272,12 +5322,12 @@ var ks = "claude-sonnet-4-20250514", As = "gpt-5.1-codex-mini", js = "https://ap
|
|
|
5272
5322
|
"claude-4.0-sonnet": "claude-sonnet-4-0",
|
|
5273
5323
|
"claude-4.0-opus": "claude-opus-4-0"
|
|
5274
5324
|
};
|
|
5275
|
-
function
|
|
5325
|
+
function Hs(e, t) {
|
|
5276
5326
|
if (e == null) return t;
|
|
5277
5327
|
let n = typeof e == "string" ? Number.parseInt(e, 10) : Number(e);
|
|
5278
5328
|
return Number.isFinite(n) ? n : t;
|
|
5279
5329
|
}
|
|
5280
|
-
function
|
|
5330
|
+
function Us(e) {
|
|
5281
5331
|
if (e == null) return null;
|
|
5282
5332
|
if (typeof e == "string") {
|
|
5283
5333
|
let t = e.trim();
|
|
@@ -5291,7 +5341,7 @@ function Ls(e) {
|
|
|
5291
5341
|
}
|
|
5292
5342
|
return typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
5293
5343
|
}
|
|
5294
|
-
function
|
|
5344
|
+
function Ws(e) {
|
|
5295
5345
|
if (e == null) return null;
|
|
5296
5346
|
if (Array.isArray(e)) return e.every((e) => typeof e == "string") ? e : null;
|
|
5297
5347
|
if (typeof e == "string") {
|
|
@@ -5305,7 +5355,7 @@ function Rs(e) {
|
|
|
5305
5355
|
}
|
|
5306
5356
|
return null;
|
|
5307
5357
|
}
|
|
5308
|
-
function
|
|
5358
|
+
function Gs() {
|
|
5309
5359
|
let e = {
|
|
5310
5360
|
observerProvider: null,
|
|
5311
5361
|
observerModel: null,
|
|
@@ -5337,41 +5387,41 @@ function zs() {
|
|
|
5337
5387
|
i = {};
|
|
5338
5388
|
}
|
|
5339
5389
|
let a = { ...e };
|
|
5340
|
-
typeof i.observer_provider == "string" && (a.observerProvider = i.observer_provider), typeof i.observer_model == "string" && (a.observerModel = i.observer_model), typeof i.observer_runtime == "string" && (a.observerRuntime = i.observer_runtime), typeof i.observer_api_key == "string" && (a.observerApiKey = i.observer_api_key), typeof i.observer_base_url == "string" && (a.observerBaseUrl = i.observer_base_url), a.observerMaxChars =
|
|
5341
|
-
let o =
|
|
5390
|
+
typeof i.observer_provider == "string" && (a.observerProvider = i.observer_provider), typeof i.observer_model == "string" && (a.observerModel = i.observer_model), typeof i.observer_runtime == "string" && (a.observerRuntime = i.observer_runtime), typeof i.observer_api_key == "string" && (a.observerApiKey = i.observer_api_key), typeof i.observer_base_url == "string" && (a.observerBaseUrl = i.observer_base_url), a.observerMaxChars = Hs(i.observer_max_chars, a.observerMaxChars), a.observerMaxTokens = Hs(i.observer_max_tokens, a.observerMaxTokens), typeof i.observer_auth_source == "string" && (a.observerAuthSource = i.observer_auth_source), typeof i.observer_auth_file == "string" && (a.observerAuthFile = i.observer_auth_file), a.observerAuthTimeoutMs = Hs(i.observer_auth_timeout_ms, a.observerAuthTimeoutMs), a.observerAuthCacheTtlS = Hs(i.observer_auth_cache_ttl_s, a.observerAuthCacheTtlS);
|
|
5391
|
+
let o = Us(i.observer_headers);
|
|
5342
5392
|
o && (a.observerHeaders = o);
|
|
5343
|
-
let s =
|
|
5344
|
-
s && (a.observerAuthCommand = s), a.observerProvider = process.env.CODEMEM_OBSERVER_PROVIDER ?? a.observerProvider, a.observerModel = process.env.CODEMEM_OBSERVER_MODEL ?? a.observerModel, a.observerRuntime = process.env.CODEMEM_OBSERVER_RUNTIME ?? a.observerRuntime, a.observerApiKey = process.env.CODEMEM_OBSERVER_API_KEY ?? a.observerApiKey, a.observerBaseUrl = process.env.CODEMEM_OBSERVER_BASE_URL ?? a.observerBaseUrl, a.observerAuthSource = process.env.CODEMEM_OBSERVER_AUTH_SOURCE ?? a.observerAuthSource, a.observerAuthFile = process.env.CODEMEM_OBSERVER_AUTH_FILE ?? a.observerAuthFile, a.observerMaxChars =
|
|
5345
|
-
let c =
|
|
5393
|
+
let s = Ws(i.observer_auth_command);
|
|
5394
|
+
s && (a.observerAuthCommand = s), a.observerProvider = process.env.CODEMEM_OBSERVER_PROVIDER ?? a.observerProvider, a.observerModel = process.env.CODEMEM_OBSERVER_MODEL ?? a.observerModel, a.observerRuntime = process.env.CODEMEM_OBSERVER_RUNTIME ?? a.observerRuntime, a.observerApiKey = process.env.CODEMEM_OBSERVER_API_KEY ?? a.observerApiKey, a.observerBaseUrl = process.env.CODEMEM_OBSERVER_BASE_URL ?? a.observerBaseUrl, a.observerAuthSource = process.env.CODEMEM_OBSERVER_AUTH_SOURCE ?? a.observerAuthSource, a.observerAuthFile = process.env.CODEMEM_OBSERVER_AUTH_FILE ?? a.observerAuthFile, a.observerMaxChars = Hs(process.env.CODEMEM_OBSERVER_MAX_CHARS, a.observerMaxChars), a.observerMaxTokens = Hs(process.env.CODEMEM_OBSERVER_MAX_TOKENS, a.observerMaxTokens), a.observerAuthTimeoutMs = Hs(process.env.CODEMEM_OBSERVER_AUTH_TIMEOUT_MS, a.observerAuthTimeoutMs), a.observerAuthCacheTtlS = Hs(process.env.CODEMEM_OBSERVER_AUTH_CACHE_TTL_S, a.observerAuthCacheTtlS);
|
|
5395
|
+
let c = Us(process.env.CODEMEM_OBSERVER_HEADERS);
|
|
5346
5396
|
c && (a.observerHeaders = c);
|
|
5347
|
-
let u =
|
|
5397
|
+
let u = Ws(process.env.CODEMEM_OBSERVER_AUTH_COMMAND);
|
|
5348
5398
|
return u && (a.observerAuthCommand = u), a;
|
|
5349
5399
|
}
|
|
5350
|
-
var
|
|
5400
|
+
var Ks = class extends Error {
|
|
5351
5401
|
constructor(e) {
|
|
5352
5402
|
super(e), this.name = "ObserverAuthError";
|
|
5353
5403
|
}
|
|
5354
5404
|
};
|
|
5355
|
-
function
|
|
5405
|
+
function qs(e) {
|
|
5356
5406
|
return e === 401 || e === 403;
|
|
5357
5407
|
}
|
|
5358
|
-
function
|
|
5408
|
+
function Js(e) {
|
|
5359
5409
|
let t = e.trim();
|
|
5360
|
-
return t && (
|
|
5410
|
+
return t && (Vs[t.toLowerCase()] ?? t);
|
|
5361
5411
|
}
|
|
5362
|
-
function
|
|
5363
|
-
return process.env.CODEMEM_ANTHROPIC_ENDPOINT ??
|
|
5412
|
+
function Ys() {
|
|
5413
|
+
return process.env.CODEMEM_ANTHROPIC_ENDPOINT ?? Ls;
|
|
5364
5414
|
}
|
|
5365
|
-
function
|
|
5415
|
+
function Xs(e, t) {
|
|
5366
5416
|
let n = {
|
|
5367
|
-
"anthropic-version":
|
|
5417
|
+
"anthropic-version": Rs,
|
|
5368
5418
|
"content-type": "application/json"
|
|
5369
5419
|
};
|
|
5370
5420
|
return t ? (n.authorization = `Bearer ${e}`, n["anthropic-beta"] = "oauth-2025-04-20") : n["x-api-key"] = e, n;
|
|
5371
5421
|
}
|
|
5372
|
-
function
|
|
5422
|
+
function Zs(e, t, n, r) {
|
|
5373
5423
|
return {
|
|
5374
|
-
model:
|
|
5424
|
+
model: Js(e),
|
|
5375
5425
|
max_tokens: r,
|
|
5376
5426
|
system: t,
|
|
5377
5427
|
messages: [{
|
|
@@ -5380,7 +5430,7 @@ function Gs(e, t, n, r) {
|
|
|
5380
5430
|
}]
|
|
5381
5431
|
};
|
|
5382
5432
|
}
|
|
5383
|
-
function
|
|
5433
|
+
function Qs(e) {
|
|
5384
5434
|
let t = e.content;
|
|
5385
5435
|
if (!Array.isArray(t)) return console.warn(`[codemem] Anthropic response has no content array (stop_reason=${e.stop_reason ?? "unknown"}, keys=${Object.keys(e).join(",")})`), null;
|
|
5386
5436
|
let n = [];
|
|
@@ -5394,13 +5444,13 @@ function Ks(e) {
|
|
|
5394
5444
|
}
|
|
5395
5445
|
return n.length > 0 ? n.join("") : null;
|
|
5396
5446
|
}
|
|
5397
|
-
function
|
|
5447
|
+
function $s(e) {
|
|
5398
5448
|
return {
|
|
5399
5449
|
authorization: `Bearer ${e}`,
|
|
5400
5450
|
"content-type": "application/json"
|
|
5401
5451
|
};
|
|
5402
5452
|
}
|
|
5403
|
-
function
|
|
5453
|
+
function ec(e, t) {
|
|
5404
5454
|
let n = { ...e };
|
|
5405
5455
|
for (let [e, r] of Object.entries(t)) {
|
|
5406
5456
|
let t = e.toLowerCase();
|
|
@@ -5409,12 +5459,12 @@ function Js(e, t) {
|
|
|
5409
5459
|
}
|
|
5410
5460
|
return n;
|
|
5411
5461
|
}
|
|
5412
|
-
function
|
|
5413
|
-
let n =
|
|
5462
|
+
function tc(e, t) {
|
|
5463
|
+
let n = ec(e, t);
|
|
5414
5464
|
for (let t of Object.keys(e)) delete e[t];
|
|
5415
5465
|
Object.assign(e, n);
|
|
5416
5466
|
}
|
|
5417
|
-
function
|
|
5467
|
+
function nc(e, t, n, r) {
|
|
5418
5468
|
return {
|
|
5419
5469
|
model: e,
|
|
5420
5470
|
max_tokens: r,
|
|
@@ -5428,7 +5478,7 @@ function Xs(e, t, n, r) {
|
|
|
5428
5478
|
}]
|
|
5429
5479
|
};
|
|
5430
5480
|
}
|
|
5431
|
-
function
|
|
5481
|
+
function rc(e) {
|
|
5432
5482
|
let t = e.choices;
|
|
5433
5483
|
if (!Array.isArray(t) || t.length === 0) return null;
|
|
5434
5484
|
let n = t[0];
|
|
@@ -5438,25 +5488,25 @@ function Zs(e) {
|
|
|
5438
5488
|
let i = r.content;
|
|
5439
5489
|
return typeof i == "string" ? i : null;
|
|
5440
5490
|
}
|
|
5441
|
-
function
|
|
5442
|
-
return process.env.CODEMEM_CODEX_ENDPOINT ??
|
|
5491
|
+
function ic() {
|
|
5492
|
+
return process.env.CODEMEM_CODEX_ENDPOINT ?? zs;
|
|
5443
5493
|
}
|
|
5444
|
-
function
|
|
5494
|
+
function ac(e, t, n) {
|
|
5445
5495
|
return {
|
|
5446
5496
|
model: e,
|
|
5447
|
-
instructions:
|
|
5497
|
+
instructions: t,
|
|
5448
5498
|
input: [{
|
|
5449
5499
|
role: "user",
|
|
5450
5500
|
content: [{
|
|
5451
5501
|
type: "input_text",
|
|
5452
|
-
text:
|
|
5502
|
+
text: n
|
|
5453
5503
|
}]
|
|
5454
5504
|
}],
|
|
5455
5505
|
store: !1,
|
|
5456
5506
|
stream: !0
|
|
5457
5507
|
};
|
|
5458
5508
|
}
|
|
5459
|
-
function
|
|
5509
|
+
function oc(e, t) {
|
|
5460
5510
|
let n = [];
|
|
5461
5511
|
for (let r of e.split("\n")) {
|
|
5462
5512
|
if (!r.startsWith("data:")) continue;
|
|
@@ -5468,14 +5518,14 @@ function ec(e, t) {
|
|
|
5468
5518
|
}
|
|
5469
5519
|
return n.length > 0 ? n.join("").trim() : null;
|
|
5470
5520
|
}
|
|
5471
|
-
function
|
|
5521
|
+
function sc(e) {
|
|
5472
5522
|
if (e.type === "response.output_text.delta") {
|
|
5473
5523
|
let t = e.delta;
|
|
5474
5524
|
return typeof t == "string" && t ? t : null;
|
|
5475
5525
|
}
|
|
5476
5526
|
return null;
|
|
5477
5527
|
}
|
|
5478
|
-
function
|
|
5528
|
+
function cc(e) {
|
|
5479
5529
|
if (e.type === "content_block_delta") {
|
|
5480
5530
|
let t = e.delta;
|
|
5481
5531
|
if (t && t.type === "text_delta") {
|
|
@@ -5485,10 +5535,10 @@ function nc(e) {
|
|
|
5485
5535
|
}
|
|
5486
5536
|
return null;
|
|
5487
5537
|
}
|
|
5488
|
-
function
|
|
5538
|
+
function lc() {
|
|
5489
5539
|
return Date.now();
|
|
5490
5540
|
}
|
|
5491
|
-
var
|
|
5541
|
+
var uc = class {
|
|
5492
5542
|
provider;
|
|
5493
5543
|
model;
|
|
5494
5544
|
runtime;
|
|
@@ -5505,7 +5555,7 @@ var ic = class {
|
|
|
5505
5555
|
_lastErrorCode = null;
|
|
5506
5556
|
_lastErrorMessage = null;
|
|
5507
5557
|
constructor(e) {
|
|
5508
|
-
let t = e ??
|
|
5558
|
+
let t = e ?? Gs(), n = (t.observerProvider ?? "").toLowerCase(), r = (t.observerModel ?? "").trim(), i = lt();
|
|
5509
5559
|
n && n !== "openai" && n !== "anthropic" && i.add(n);
|
|
5510
5560
|
let a = n;
|
|
5511
5561
|
if (!a) {
|
|
@@ -5516,11 +5566,11 @@ var ic = class {
|
|
|
5516
5566
|
let e = dt(r);
|
|
5517
5567
|
e && (a = e);
|
|
5518
5568
|
}
|
|
5519
|
-
a ||=
|
|
5569
|
+
a ||= vs(null, r || Is), a !== "openai" && a !== "anthropic" && a !== "opencode" && !i.has(a) && (a = "openai"), this.provider = a;
|
|
5520
5570
|
let o = t.observerRuntime;
|
|
5521
|
-
this.runtime = (typeof o == "string" && o.trim().toLowerCase(), "api_http"), r ? this.model = r : a === "anthropic" ? this.model =
|
|
5571
|
+
this.runtime = (typeof o == "string" && o.trim().toLowerCase(), "api_http"), r ? this.model = r : a === "anthropic" ? this.model = Fs : a === "openai" ? this.model = Is : this.model = ft(a) ?? St(a) ?? "", this.maxChars = t.observerMaxChars, this.maxTokens = t.observerMaxTokens, this._observerHeaders = { ...t.observerHeaders }, this._apiKey = t.observerApiKey ?? null;
|
|
5522
5572
|
let s = t.observerBaseUrl;
|
|
5523
|
-
this._customBaseUrl = typeof s == "string" && s.trim() ? s.trim() : null, this.authAdapter = new
|
|
5573
|
+
this._customBaseUrl = typeof s == "string" && s.trim() ? s.trim() : null, this.authAdapter = new As({
|
|
5524
5574
|
source: t.observerAuthSource,
|
|
5525
5575
|
filePath: t.observerAuthFile,
|
|
5526
5576
|
command: t.observerAuthCommand,
|
|
@@ -5559,18 +5609,18 @@ var ic = class {
|
|
|
5559
5609
|
let e = await this._callOnce(a, s);
|
|
5560
5610
|
return e && this._clearLastError(), {
|
|
5561
5611
|
raw: e,
|
|
5562
|
-
parsed: e ?
|
|
5612
|
+
parsed: e ? fc(e) : null,
|
|
5563
5613
|
provider: this.provider,
|
|
5564
5614
|
model: this.model
|
|
5565
5615
|
};
|
|
5566
5616
|
} catch (e) {
|
|
5567
|
-
if (e instanceof
|
|
5617
|
+
if (e instanceof Ks) {
|
|
5568
5618
|
if (this.refreshAuth(), !this.auth.token) throw e;
|
|
5569
5619
|
try {
|
|
5570
5620
|
let e = await this._callOnce(a, s);
|
|
5571
5621
|
return e && this._clearLastError(), {
|
|
5572
5622
|
raw: e,
|
|
5573
|
-
parsed: e ?
|
|
5623
|
+
parsed: e ? fc(e) : null,
|
|
5574
5624
|
provider: this.provider,
|
|
5575
5625
|
model: this.model
|
|
5576
5626
|
};
|
|
@@ -5583,11 +5633,11 @@ var ic = class {
|
|
|
5583
5633
|
}
|
|
5584
5634
|
_initProvider(e) {
|
|
5585
5635
|
this._codexAccess = null, this._codexAccountId = null, this._anthropicOAuthAccess = null;
|
|
5586
|
-
let t =
|
|
5636
|
+
let t = _s(), n = null, r = null;
|
|
5587
5637
|
if (this.provider === "openai" || this.provider === "anthropic") {
|
|
5588
|
-
r =
|
|
5589
|
-
let e =
|
|
5590
|
-
n && e != null && e <=
|
|
5638
|
+
r = vs(this.provider, this.model), n = bs(t, r);
|
|
5639
|
+
let e = ws(t, r);
|
|
5640
|
+
n && e != null && e <= lc() && (n = null);
|
|
5591
5641
|
}
|
|
5592
5642
|
if (this.provider !== "openai" && this.provider !== "anthropic") {
|
|
5593
5643
|
let n = at(this.provider), [r, i, a] = Object.keys(n).length > 0 ? Ct(this.provider, this.model) : pt(this.provider, this.model);
|
|
@@ -5595,7 +5645,7 @@ var ic = class {
|
|
|
5595
5645
|
...this._observerHeaders,
|
|
5596
5646
|
...a
|
|
5597
5647
|
}), !this._customBaseUrl) return;
|
|
5598
|
-
let o = this.provider === "opencode" ?
|
|
5648
|
+
let o = this.provider === "opencode" ? xs(t, this.provider) : null, s = xt(n) || this._apiKey || o;
|
|
5599
5649
|
this.auth = this.authAdapter.resolve({
|
|
5600
5650
|
explicitToken: s,
|
|
5601
5651
|
envTokens: [process.env.CODEMEM_OBSERVER_API_KEY ?? ""],
|
|
@@ -5615,67 +5665,67 @@ var ic = class {
|
|
|
5615
5665
|
],
|
|
5616
5666
|
oauthToken: n,
|
|
5617
5667
|
forceRefresh: e
|
|
5618
|
-
}), this.auth.source === "oauth" && n && (this._codexAccess = n, this._codexAccountId =
|
|
5668
|
+
}), this.auth.source === "oauth" && n && (this._codexAccess = n, this._codexAccountId = Cs(t, r ?? "openai")));
|
|
5619
5669
|
}
|
|
5620
5670
|
async _callOnce(e, t) {
|
|
5621
|
-
if (this._codexAccess) return this._callCodexConsumer(t);
|
|
5671
|
+
if (this._codexAccess) return this._callCodexConsumer(e, t);
|
|
5622
5672
|
if (this._anthropicOAuthAccess) return this._callAnthropicConsumer(e, t);
|
|
5623
5673
|
if (!this.auth.token) {
|
|
5624
|
-
if (this._initProvider(!0), this._codexAccess) return this._callCodexConsumer(t);
|
|
5674
|
+
if (this._initProvider(!0), this._codexAccess) return this._callCodexConsumer(e, t);
|
|
5625
5675
|
if (this._anthropicOAuthAccess) return this._callAnthropicConsumer(e, t);
|
|
5626
|
-
if (!this.auth.token) return this._setLastError(`${
|
|
5676
|
+
if (!this.auth.token) return this._setLastError(`${dc(this.provider)} credentials are missing.`, "auth_missing"), null;
|
|
5627
5677
|
}
|
|
5628
5678
|
return this.provider === "anthropic" ? this._callAnthropicDirect(e, t) : this._callOpenAIDirect(e, t);
|
|
5629
5679
|
}
|
|
5630
5680
|
async _callAnthropicDirect(e, t) {
|
|
5631
|
-
let n =
|
|
5681
|
+
let n = Ys(), r = ec(Xs(this.auth.token ?? "", !1), Ps(this._observerHeaders, this.auth)), i = Zs(this.model, e, t, this.maxTokens);
|
|
5632
5682
|
return this._fetchJSON(n, r, i, {
|
|
5633
|
-
parseResponse:
|
|
5683
|
+
parseResponse: Qs,
|
|
5634
5684
|
providerLabel: "Anthropic"
|
|
5635
5685
|
});
|
|
5636
5686
|
}
|
|
5637
5687
|
async _callOpenAIDirect(e, t) {
|
|
5638
5688
|
let n;
|
|
5639
5689
|
n = this._customBaseUrl ? `${this._customBaseUrl.replace(/\/+$/, "")}/chat/completions` : "https://api.openai.com/v1/chat/completions";
|
|
5640
|
-
let r =
|
|
5690
|
+
let r = ec($s(this.auth.token ?? ""), Ps(this._observerHeaders, this.auth)), i = nc(this.model, e, t, this.maxTokens);
|
|
5641
5691
|
return this._fetchJSON(n, r, i, {
|
|
5642
|
-
parseResponse:
|
|
5643
|
-
providerLabel:
|
|
5692
|
+
parseResponse: rc,
|
|
5693
|
+
providerLabel: dc(this.provider)
|
|
5644
5694
|
});
|
|
5645
5695
|
}
|
|
5646
|
-
async _callCodexConsumer(e) {
|
|
5696
|
+
async _callCodexConsumer(e, t) {
|
|
5647
5697
|
if (!this._codexAccess) return null;
|
|
5648
|
-
let
|
|
5698
|
+
let n = Ts(this._codexAccess, this._codexAccountId);
|
|
5649
5699
|
if (Object.keys(this._observerHeaders).length > 0) {
|
|
5650
5700
|
let e = {
|
|
5651
5701
|
token: this._codexAccess,
|
|
5652
5702
|
authType: "bearer",
|
|
5653
5703
|
source: this.auth.source
|
|
5654
5704
|
};
|
|
5655
|
-
|
|
5705
|
+
tc(n, Ps(this._observerHeaders, e));
|
|
5656
5706
|
}
|
|
5657
|
-
|
|
5658
|
-
let
|
|
5659
|
-
return this._fetchSSE(
|
|
5707
|
+
n["content-type"] = "application/json";
|
|
5708
|
+
let r = ac(this.model, e, t), i = ic();
|
|
5709
|
+
return this._fetchSSE(i, n, r, sc, {
|
|
5660
5710
|
providerLabel: "OpenAI",
|
|
5661
5711
|
authErrorMessage: "OpenAI authentication failed. Refresh credentials and retry."
|
|
5662
5712
|
});
|
|
5663
5713
|
}
|
|
5664
5714
|
async _callAnthropicConsumer(e, t) {
|
|
5665
5715
|
if (!this._anthropicOAuthAccess) return null;
|
|
5666
|
-
let n =
|
|
5716
|
+
let n = Xs(this._anthropicOAuthAccess, !0);
|
|
5667
5717
|
if (Object.keys(this._observerHeaders).length > 0) {
|
|
5668
5718
|
let e = {
|
|
5669
5719
|
token: this._anthropicOAuthAccess,
|
|
5670
5720
|
authType: "bearer",
|
|
5671
5721
|
source: this.auth.source
|
|
5672
5722
|
};
|
|
5673
|
-
|
|
5723
|
+
tc(n, Ps(this._observerHeaders, e));
|
|
5674
5724
|
}
|
|
5675
|
-
let r =
|
|
5725
|
+
let r = Ys(), i = new URL(r);
|
|
5676
5726
|
i.searchParams.set("beta", "true");
|
|
5677
5727
|
let a = i.toString(), o = {
|
|
5678
|
-
model:
|
|
5728
|
+
model: Js(this.model),
|
|
5679
5729
|
max_tokens: this.maxTokens,
|
|
5680
5730
|
stream: !0,
|
|
5681
5731
|
messages: [{
|
|
@@ -5684,7 +5734,7 @@ var ic = class {
|
|
|
5684
5734
|
}],
|
|
5685
5735
|
system: e
|
|
5686
5736
|
};
|
|
5687
|
-
return this._fetchSSE(a, n, o,
|
|
5737
|
+
return this._fetchSSE(a, n, o, cc, {
|
|
5688
5738
|
providerLabel: "Anthropic",
|
|
5689
5739
|
authErrorMessage: "Anthropic authentication failed. Refresh credentials and retry."
|
|
5690
5740
|
});
|
|
@@ -5695,7 +5745,7 @@ var ic = class {
|
|
|
5695
5745
|
method: "POST",
|
|
5696
5746
|
headers: t,
|
|
5697
5747
|
body: JSON.stringify(n),
|
|
5698
|
-
signal: AbortSignal.timeout(
|
|
5748
|
+
signal: AbortSignal.timeout(Bs)
|
|
5699
5749
|
});
|
|
5700
5750
|
if (!i.ok) {
|
|
5701
5751
|
let e = await i.text().catch(() => "");
|
|
@@ -5704,7 +5754,7 @@ var ic = class {
|
|
|
5704
5754
|
let a = await i.json(), o = r.parseResponse(a);
|
|
5705
5755
|
return o === null && this._setLastError(`${r.providerLabel} returned 200 but response contained no extractable text.`, "empty_response"), o;
|
|
5706
5756
|
} catch (e) {
|
|
5707
|
-
if (e instanceof
|
|
5757
|
+
if (e instanceof Ks) throw e;
|
|
5708
5758
|
return this._setLastError(`${r.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
5709
5759
|
}
|
|
5710
5760
|
}
|
|
@@ -5714,21 +5764,21 @@ var ic = class {
|
|
|
5714
5764
|
method: "POST",
|
|
5715
5765
|
headers: t,
|
|
5716
5766
|
body: JSON.stringify(n),
|
|
5717
|
-
signal: AbortSignal.timeout(
|
|
5767
|
+
signal: AbortSignal.timeout(Bs)
|
|
5718
5768
|
});
|
|
5719
5769
|
if (!a.ok) {
|
|
5720
|
-
if (await a.text().catch(() => ""),
|
|
5770
|
+
if (await a.text().catch(() => ""), qs(a.status)) throw this._setLastError(i.authErrorMessage, "auth_failed"), new Ks(`${i.providerLabel} auth error: ${a.status}`);
|
|
5721
5771
|
return this._setLastError(`${i.providerLabel} request failed during observer processing.`, "provider_request_failed"), null;
|
|
5722
5772
|
}
|
|
5723
|
-
return
|
|
5773
|
+
return oc(await a.text(), r);
|
|
5724
5774
|
} catch (e) {
|
|
5725
|
-
if (e instanceof
|
|
5775
|
+
if (e instanceof Ks) throw e;
|
|
5726
5776
|
return this._setLastError(`${i.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
5727
5777
|
}
|
|
5728
5778
|
}
|
|
5729
5779
|
_handleHttpError(e, t, n) {
|
|
5730
|
-
let r =
|
|
5731
|
-
if (
|
|
5780
|
+
let r = ms(t);
|
|
5781
|
+
if (qs(e)) throw this._setLastError(`${n} authentication failed. Refresh credentials and retry.`, "auth_failed"), new Ks(`${n} auth error: ${e}: ${r}`);
|
|
5732
5782
|
if (e === 429) {
|
|
5733
5783
|
this._setLastError(`${n} rate limited. Retry later.`, "rate_limited");
|
|
5734
5784
|
return;
|
|
@@ -5753,10 +5803,10 @@ var ic = class {
|
|
|
5753
5803
|
this._lastErrorCode = null, this._lastErrorMessage = null;
|
|
5754
5804
|
}
|
|
5755
5805
|
};
|
|
5756
|
-
function
|
|
5806
|
+
function dc(e) {
|
|
5757
5807
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
5758
5808
|
}
|
|
5759
|
-
function
|
|
5809
|
+
function fc(e) {
|
|
5760
5810
|
try {
|
|
5761
5811
|
let t = JSON.parse(e);
|
|
5762
5812
|
return typeof t == "object" && t && !Array.isArray(t) ? t : null;
|
|
@@ -5766,10 +5816,10 @@ function oc(e) {
|
|
|
5766
5816
|
}
|
|
5767
5817
|
//#endregion
|
|
5768
5818
|
//#region src/search.ts
|
|
5769
|
-
function
|
|
5819
|
+
function pc(e) {
|
|
5770
5820
|
return N(e, { schema: H });
|
|
5771
5821
|
}
|
|
5772
|
-
var
|
|
5822
|
+
var mc = {
|
|
5773
5823
|
session_summary: .25,
|
|
5774
5824
|
decision: .2,
|
|
5775
5825
|
feature: .18,
|
|
@@ -5781,32 +5831,32 @@ var cc = {
|
|
|
5781
5831
|
observation: .1,
|
|
5782
5832
|
exploration: .1,
|
|
5783
5833
|
entities: .05
|
|
5784
|
-
},
|
|
5834
|
+
}, hc = .45, gc = .18, _c = .12, vc = 3, yc = 0, bc = 2, xc = [
|
|
5785
5835
|
/\bwhat did i\b/i,
|
|
5786
5836
|
/\bmy notes\b/i,
|
|
5787
5837
|
/\bmy last session\b/i,
|
|
5788
5838
|
/\bmy machine\b/i
|
|
5789
|
-
],
|
|
5839
|
+
], Sc = new Set([
|
|
5790
5840
|
"or",
|
|
5791
5841
|
"and",
|
|
5792
5842
|
"not",
|
|
5793
5843
|
"near",
|
|
5794
5844
|
"phrase"
|
|
5795
5845
|
]);
|
|
5796
|
-
function
|
|
5846
|
+
function Cc(e) {
|
|
5797
5847
|
let t = e.match(/[A-Za-z0-9_]+/g);
|
|
5798
5848
|
if (!t) return "";
|
|
5799
|
-
let n = t.filter((e) => !
|
|
5849
|
+
let n = t.filter((e) => !Sc.has(e.toLowerCase()));
|
|
5800
5850
|
return n.length === 0 ? "" : n.length === 1 ? n[0] : n.join(" OR ");
|
|
5801
5851
|
}
|
|
5802
|
-
function
|
|
5852
|
+
function wc(e, t) {
|
|
5803
5853
|
let n = Date.parse(e);
|
|
5804
5854
|
return Number.isNaN(n) ? 0 : 1 / (1 + Math.max(0, Math.floor(((t ?? /* @__PURE__ */ new Date()).getTime() - n) / 864e5)) / 7);
|
|
5805
5855
|
}
|
|
5806
|
-
function
|
|
5807
|
-
return e ?
|
|
5856
|
+
function Tc(e) {
|
|
5857
|
+
return e ? mc[e.trim().toLowerCase()] ?? 0 : 0;
|
|
5808
5858
|
}
|
|
5809
|
-
function
|
|
5859
|
+
function Ec(e) {
|
|
5810
5860
|
if (!e || e.personal_first === void 0) return !0;
|
|
5811
5861
|
let t = e.personal_first;
|
|
5812
5862
|
if (typeof t == "string") {
|
|
@@ -5826,10 +5876,10 @@ function bc(e) {
|
|
|
5826
5876
|
}
|
|
5827
5877
|
return !!t;
|
|
5828
5878
|
}
|
|
5829
|
-
function
|
|
5879
|
+
function Dc(e) {
|
|
5830
5880
|
return String(e?.trust_bias ?? "off").trim().toLowerCase() === "soft" ? "soft" : "off";
|
|
5831
5881
|
}
|
|
5832
|
-
function
|
|
5882
|
+
function Oc(e) {
|
|
5833
5883
|
if (!e || e.widen_shared_when_weak === void 0) return !1;
|
|
5834
5884
|
let t = e.widen_shared_when_weak;
|
|
5835
5885
|
if (typeof t == "string") {
|
|
@@ -5849,25 +5899,25 @@ function Sc(e) {
|
|
|
5849
5899
|
}
|
|
5850
5900
|
return !!t;
|
|
5851
5901
|
}
|
|
5852
|
-
function
|
|
5902
|
+
function kc(e) {
|
|
5853
5903
|
let t = e?.widen_shared_min_personal_results;
|
|
5854
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5904
|
+
return typeof t != "number" || !Number.isFinite(t) ? vc : Math.max(1, Math.trunc(t));
|
|
5855
5905
|
}
|
|
5856
|
-
function
|
|
5906
|
+
function Ac(e) {
|
|
5857
5907
|
let t = e?.widen_shared_min_personal_score;
|
|
5858
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5908
|
+
return typeof t != "number" || !Number.isFinite(t) ? yc : Math.max(0, t);
|
|
5859
5909
|
}
|
|
5860
|
-
function
|
|
5861
|
-
return
|
|
5910
|
+
function jc(e) {
|
|
5911
|
+
return xc.some((t) => t.test(e));
|
|
5862
5912
|
}
|
|
5863
|
-
function
|
|
5913
|
+
function Mc(e) {
|
|
5864
5914
|
if (!e) return !1;
|
|
5865
5915
|
let t = String(e.ownership_scope ?? "").trim().toLowerCase();
|
|
5866
5916
|
if (t === "mine" || t === "theirs") return !0;
|
|
5867
5917
|
let n = ka(e.include_visibility ?? e.visibility), r = ka(e.exclude_visibility), i = Da(e.include_workspace_ids), a = Da(e.exclude_workspace_ids), o = Oa(e.include_workspace_kinds), s = Oa(e.exclude_workspace_kinds);
|
|
5868
5918
|
return n.length || i.length || o.length || r.includes("private") || r.includes("shared") || s.includes("shared") || s.includes("personal") ? !0 : a.some((e) => e.startsWith("personal:") || e.startsWith("shared:"));
|
|
5869
5919
|
}
|
|
5870
|
-
function
|
|
5920
|
+
function Nc(e) {
|
|
5871
5921
|
return {
|
|
5872
5922
|
...e ?? {},
|
|
5873
5923
|
visibility: void 0,
|
|
@@ -5878,7 +5928,7 @@ function Dc(e) {
|
|
|
5878
5928
|
widen_shared_when_weak: !1
|
|
5879
5929
|
};
|
|
5880
5930
|
}
|
|
5881
|
-
function
|
|
5931
|
+
function Pc(e) {
|
|
5882
5932
|
return e.map((e) => ({
|
|
5883
5933
|
...e,
|
|
5884
5934
|
metadata: {
|
|
@@ -5887,83 +5937,83 @@ function Oc(e) {
|
|
|
5887
5937
|
}
|
|
5888
5938
|
}));
|
|
5889
5939
|
}
|
|
5890
|
-
function
|
|
5891
|
-
return
|
|
5940
|
+
function Fc(e, t, n) {
|
|
5941
|
+
return Ec(n) && e.memoryOwnedBySelf(t) ? hc : 0;
|
|
5892
5942
|
}
|
|
5893
|
-
function
|
|
5894
|
-
if (
|
|
5943
|
+
function Ic(e, t, n) {
|
|
5944
|
+
if (Dc(n) !== "soft" || e.memoryOwnedBySelf(t)) return 0;
|
|
5895
5945
|
let r = t.metadata ?? {}, i = String(r.visibility ?? "").trim().toLowerCase(), a = String(r.workspace_kind ?? "").trim().toLowerCase();
|
|
5896
5946
|
if (i !== "shared" && a !== "shared") return 0;
|
|
5897
5947
|
let o = String(r.trust_state ?? "trusted").trim().toLowerCase();
|
|
5898
|
-
return o === "legacy_unknown" ?
|
|
5948
|
+
return o === "legacy_unknown" ? gc : o === "unreviewed" ? _c : 0;
|
|
5899
5949
|
}
|
|
5900
|
-
function
|
|
5950
|
+
function Lc(e) {
|
|
5901
5951
|
let t = e.trim().replaceAll("\\", "/");
|
|
5902
5952
|
t.startsWith("./") && (t = t.slice(2));
|
|
5903
5953
|
let n = t.split("/").filter((e) => e && e !== ".");
|
|
5904
5954
|
return n.length === 0 ? "" : n.join("/").toLowerCase();
|
|
5905
5955
|
}
|
|
5906
|
-
function
|
|
5907
|
-
let t =
|
|
5956
|
+
function Rc(e) {
|
|
5957
|
+
let t = Lc(e);
|
|
5908
5958
|
return t ? t.split("/") : [];
|
|
5909
5959
|
}
|
|
5910
|
-
function
|
|
5911
|
-
let t =
|
|
5960
|
+
function zc(e) {
|
|
5961
|
+
let t = Rc(e);
|
|
5912
5962
|
return t.length === 0 ? "" : t[t.length - 1] ?? "";
|
|
5913
5963
|
}
|
|
5914
|
-
function
|
|
5964
|
+
function Bc(e, t) {
|
|
5915
5965
|
return e.length === 0 || t.length === 0 ? !1 : e.length <= t.length ? t.slice(t.length - e.length).join("/") === e.join("/") : e.slice(e.length - t.length).join("/") === t.join("/");
|
|
5916
5966
|
}
|
|
5917
|
-
function
|
|
5967
|
+
function Vc(e) {
|
|
5918
5968
|
if (!Array.isArray(e)) return [];
|
|
5919
5969
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
5920
5970
|
for (let r of e) {
|
|
5921
5971
|
if (typeof r != "string") continue;
|
|
5922
|
-
let e =
|
|
5972
|
+
let e = Lc(r);
|
|
5923
5973
|
!e || n.has(e) || (n.add(e), t.push(e));
|
|
5924
5974
|
}
|
|
5925
5975
|
return t;
|
|
5926
5976
|
}
|
|
5927
|
-
function
|
|
5977
|
+
function Hc(e) {
|
|
5928
5978
|
let t = (e.metadata ?? {}).files_modified;
|
|
5929
5979
|
if (!Array.isArray(t)) return [];
|
|
5930
5980
|
let n = [];
|
|
5931
5981
|
for (let e of t) {
|
|
5932
5982
|
if (typeof e != "string") continue;
|
|
5933
|
-
let t =
|
|
5983
|
+
let t = Lc(e);
|
|
5934
5984
|
t && n.push(t);
|
|
5935
5985
|
}
|
|
5936
5986
|
return n;
|
|
5937
5987
|
}
|
|
5938
|
-
function
|
|
5988
|
+
function Uc(e, t) {
|
|
5939
5989
|
if (t.length === 0) return 0;
|
|
5940
|
-
let n =
|
|
5990
|
+
let n = Hc(e);
|
|
5941
5991
|
if (n.length === 0) return 0;
|
|
5942
|
-
let r = [...new Set(n)].map((e) =>
|
|
5943
|
-
for (let e of r) i.some((t) =>
|
|
5992
|
+
let r = [...new Set(n)].map((e) => Rc(e)), i = [...new Set(t)].map((e) => Rc(e)), a = new Set(n.map((e) => zc(e)).filter(Boolean)), o = new Set(t.map((e) => zc(e)).filter(Boolean)), s = 0;
|
|
5993
|
+
for (let e of r) i.some((t) => Bc(e, t)) && (s += 1);
|
|
5944
5994
|
let c = 0;
|
|
5945
5995
|
for (let e of a) o.has(e) && (c += 1);
|
|
5946
5996
|
let l = s * .16 + c * .06;
|
|
5947
5997
|
return Math.min(.32, l);
|
|
5948
5998
|
}
|
|
5949
|
-
function
|
|
5950
|
-
let i = /* @__PURE__ */ new Date(), a =
|
|
5999
|
+
function Wc(e, t, n, r) {
|
|
6000
|
+
let i = /* @__PURE__ */ new Date(), a = Vc(r?.working_set_paths), o = t.map((t) => ({
|
|
5951
6001
|
item: t,
|
|
5952
|
-
combinedScore: t.score * 1.5 +
|
|
6002
|
+
combinedScore: t.score * 1.5 + wc(t.created_at, i) + Tc(t.kind) + Uc(t, a) + Fc(e, t, r) - Ic(e, t, r)
|
|
5953
6003
|
}));
|
|
5954
6004
|
return o.sort((e, t) => t.combinedScore - e.combinedScore), o.slice(0, n).map((e) => e.item);
|
|
5955
6005
|
}
|
|
5956
|
-
function
|
|
5957
|
-
let i =
|
|
5958
|
-
if (!
|
|
6006
|
+
function Gc(e, t, n = 10, r) {
|
|
6007
|
+
let i = Kc(e, t, n, r);
|
|
6008
|
+
if (!Oc(r) || !t || jc(t) || Mc(r)) return i;
|
|
5959
6009
|
let a = i.filter((t) => e.memoryOwnedBySelf(t)), o = a[0]?.score ?? -Infinity;
|
|
5960
|
-
if (a.length >=
|
|
5961
|
-
let s =
|
|
5962
|
-
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >=
|
|
6010
|
+
if (a.length >= kc(r) && o >= Ac(r)) return i;
|
|
6011
|
+
let s = Pc(Kc(e, t, bc, Nc(r)).filter((t) => !e.memoryOwnedBySelf(t))), c = new Set(i.map((e) => e.id)), l = [...i], u = 0;
|
|
6012
|
+
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >= bc)) break;
|
|
5963
6013
|
return l;
|
|
5964
6014
|
}
|
|
5965
|
-
function
|
|
5966
|
-
let i = Math.max(1, Math.trunc(n)), a =
|
|
6015
|
+
function Kc(e, t, n = 10, r) {
|
|
6016
|
+
let i = Math.max(1, Math.trunc(n)), a = Cc(t);
|
|
5967
6017
|
if (!a) return [];
|
|
5968
6018
|
let o = Math.min(Math.max(i * 4, i + 8), 200), s = [a], c = ["memory_items.active = 1", "memory_fts MATCH ?"], l = Na(r, {
|
|
5969
6019
|
actorId: e.actorId,
|
|
@@ -5981,7 +6031,7 @@ function Bc(e, t, n = 10, r) {
|
|
|
5981
6031
|
ORDER BY (score * 1.5 + recency) DESC, memory_items.created_at DESC, memory_items.id DESC
|
|
5982
6032
|
LIMIT ?
|
|
5983
6033
|
`;
|
|
5984
|
-
return s.push(o),
|
|
6034
|
+
return s.push(o), Wc(e, e.db.prepare(d).all(...s).map((e) => {
|
|
5985
6035
|
let t = { ...z(e.metadata_json) };
|
|
5986
6036
|
for (let n of [
|
|
5987
6037
|
"actor_id",
|
|
@@ -6015,7 +6065,7 @@ function Bc(e, t, n = 10, r) {
|
|
|
6015
6065
|
};
|
|
6016
6066
|
}), i, r);
|
|
6017
6067
|
}
|
|
6018
|
-
function
|
|
6068
|
+
function qc(e, t, n, r = 3, i = 3, a) {
|
|
6019
6069
|
let o = null;
|
|
6020
6070
|
if (n != null) {
|
|
6021
6071
|
let t = e.get(n);
|
|
@@ -6026,7 +6076,7 @@ function Vc(e, t, n, r = 3, i = 3, a) {
|
|
|
6026
6076
|
});
|
|
6027
6077
|
}
|
|
6028
6078
|
if (o == null && t) {
|
|
6029
|
-
let n =
|
|
6079
|
+
let n = Gc(e, t, 1, a ?? void 0);
|
|
6030
6080
|
if (n.length > 0) {
|
|
6031
6081
|
let e = n[0];
|
|
6032
6082
|
o = {
|
|
@@ -6036,9 +6086,9 @@ function Vc(e, t, n, r = 3, i = 3, a) {
|
|
|
6036
6086
|
};
|
|
6037
6087
|
}
|
|
6038
6088
|
}
|
|
6039
|
-
return o == null ? [] :
|
|
6089
|
+
return o == null ? [] : Jc(e, o, r, i, a);
|
|
6040
6090
|
}
|
|
6041
|
-
function
|
|
6091
|
+
function Jc(e, t, n, r, i) {
|
|
6042
6092
|
let a = t.id, o = t.created_at, s = t.session_id;
|
|
6043
6093
|
if (!a || !o) return [];
|
|
6044
6094
|
let c = Na(i, {
|
|
@@ -6056,7 +6106,7 @@ function Hc(e, t, n, r, i) {
|
|
|
6056
6106
|
${f}
|
|
6057
6107
|
WHERE ${d} AND memory_items.created_at > ?
|
|
6058
6108
|
ORDER BY memory_items.created_at ASC
|
|
6059
|
-
LIMIT ?`).all(...u, o, r), h =
|
|
6109
|
+
LIMIT ?`).all(...u, o, r), h = pc(e.db).select().from(W).where(D(k(W.id, a), k(W.active, 1))).get(), g = [...p.reverse()];
|
|
6060
6110
|
return h && g.push(h), g.push(...m), g.map((e) => {
|
|
6061
6111
|
let { metadata_json: t, ...n } = e;
|
|
6062
6112
|
return {
|
|
@@ -6066,10 +6116,10 @@ function Hc(e, t, n, r, i) {
|
|
|
6066
6116
|
};
|
|
6067
6117
|
});
|
|
6068
6118
|
}
|
|
6069
|
-
function
|
|
6119
|
+
function Yc(e) {
|
|
6070
6120
|
let t = /* @__PURE__ */ new Set(), n = [], r = [];
|
|
6071
6121
|
for (let i of e) {
|
|
6072
|
-
let e =
|
|
6122
|
+
let e = ds(i);
|
|
6073
6123
|
if (e == null) {
|
|
6074
6124
|
r.push(String(i));
|
|
6075
6125
|
continue;
|
|
@@ -6081,8 +6131,8 @@ function Uc(e) {
|
|
|
6081
6131
|
invalid: r
|
|
6082
6132
|
};
|
|
6083
6133
|
}
|
|
6084
|
-
function
|
|
6085
|
-
let c = `${e.title} ${e.body_text} ${e.tags_text}`.toLowerCase(), l = r.filter((e) => c.includes(e)), u = t === "query" || t === "query+id_lookup" ? e.score : null, d =
|
|
6134
|
+
function Xc(e, t, n, r, i, a, o, s) {
|
|
6135
|
+
let c = `${e.title} ${e.body_text} ${e.tags_text}`.toLowerCase(), l = r.filter((e) => c.includes(e)), u = t === "query" || t === "query+id_lookup" ? e.score : null, d = wc(e.created_at, s), f = Tc(e.kind), p = null;
|
|
6086
6136
|
return u != null && (p = u * 1.5 + d + f), {
|
|
6087
6137
|
id: e.id,
|
|
6088
6138
|
kind: e.kind,
|
|
@@ -6113,14 +6163,14 @@ function Wc(e, t, n, r, i, a, o, s) {
|
|
|
6113
6163
|
} : null
|
|
6114
6164
|
};
|
|
6115
6165
|
}
|
|
6116
|
-
function
|
|
6166
|
+
function Zc(e, t, n) {
|
|
6117
6167
|
if (t.length === 0) return {
|
|
6118
6168
|
items: [],
|
|
6119
6169
|
missingNotFound: [],
|
|
6120
6170
|
missingProjectMismatch: [],
|
|
6121
6171
|
missingFilterMismatch: []
|
|
6122
6172
|
};
|
|
6123
|
-
let r =
|
|
6173
|
+
let r = pc(e.db).select().from(W).where(D(k(W.active, 1), j(W.id, t))).all(), i = new Set(r.map((e) => e.id)), a = t.map(() => "?").join(", "), o = r, s = new Set(i);
|
|
6124
6174
|
if (n.project) {
|
|
6125
6175
|
let r = Na({ project: n.project }, {
|
|
6126
6176
|
actorId: e.actorId,
|
|
@@ -6166,16 +6216,16 @@ function Gc(e, t, n) {
|
|
|
6166
6216
|
missingFilterMismatch: m
|
|
6167
6217
|
};
|
|
6168
6218
|
}
|
|
6169
|
-
function
|
|
6219
|
+
function Qc(e, t) {
|
|
6170
6220
|
if (t.size === 0) return /* @__PURE__ */ new Map();
|
|
6171
|
-
let n = [...t].sort((e, t) => e - t), r =
|
|
6221
|
+
let n = [...t].sort((e, t) => e - t), r = pc(e.db).select({
|
|
6172
6222
|
id: U.id,
|
|
6173
6223
|
project: U.project
|
|
6174
6224
|
}).from(U).where(j(U.id, n)).all();
|
|
6175
6225
|
return new Map(r.map((e) => [e.id, e.project]));
|
|
6176
6226
|
}
|
|
6177
|
-
function
|
|
6178
|
-
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } =
|
|
6227
|
+
function $c(e, t, n, r = 10, i, a) {
|
|
6228
|
+
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } = Yc(n ?? []), u = [];
|
|
6179
6229
|
if (l.length > 0 && u.push({
|
|
6180
6230
|
code: "INVALID_ARGUMENT",
|
|
6181
6231
|
field: "ids",
|
|
@@ -6198,10 +6248,10 @@ function qc(e, t, n, r = 10, i, a) {
|
|
|
6198
6248
|
}
|
|
6199
6249
|
};
|
|
6200
6250
|
let d = [];
|
|
6201
|
-
s && (d =
|
|
6251
|
+
s && (d = Gc(e, s, Math.max(1, Math.trunc(r)), i ?? void 0));
|
|
6202
6252
|
let f = /* @__PURE__ */ new Map();
|
|
6203
6253
|
for (let e = 0; e < d.length; e++) f.set(d[e].id, e + 1);
|
|
6204
|
-
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } =
|
|
6254
|
+
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } = Zc(e, c, i ?? {}), _ = new Map(p.map((e) => [e.id, e])), v = new Set(c), y = /* @__PURE__ */ new Set(), b = [];
|
|
6205
6255
|
for (let e of d) {
|
|
6206
6256
|
y.add(e.id);
|
|
6207
6257
|
let t = v.has(e.id) ? "query+id_lookup" : "query";
|
|
@@ -6220,7 +6270,7 @@ function qc(e, t, n, r = 10, i, a) {
|
|
|
6220
6270
|
rank: null
|
|
6221
6271
|
}), y.add(e));
|
|
6222
6272
|
}
|
|
6223
|
-
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S =
|
|
6273
|
+
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S = Qc(e, new Set(b.map(({ item: e }) => e.session_id).filter((e) => e > 0))), C = /* @__PURE__ */ new Date(), w = b.map(({ item: e, source: t, rank: n }) => Xc(e, t, n, x, i?.project ?? null, S.get(e.session_id) ?? null, o, C)), T = c.filter((e) => !y.has(e));
|
|
6224
6274
|
return m.length > 0 && u.push({
|
|
6225
6275
|
code: "NOT_FOUND",
|
|
6226
6276
|
field: "ids",
|
|
@@ -6251,7 +6301,7 @@ function qc(e, t, n, r = 10, i, a) {
|
|
|
6251
6301
|
}
|
|
6252
6302
|
//#endregion
|
|
6253
6303
|
//#region src/pack.ts
|
|
6254
|
-
var
|
|
6304
|
+
var el = {
|
|
6255
6305
|
decision: 0,
|
|
6256
6306
|
feature: 1,
|
|
6257
6307
|
bugfix: 2,
|
|
@@ -6260,11 +6310,11 @@ var Jc = {
|
|
|
6260
6310
|
discovery: 5,
|
|
6261
6311
|
exploration: 6,
|
|
6262
6312
|
note: 7
|
|
6263
|
-
},
|
|
6264
|
-
function
|
|
6313
|
+
}, tl = 365, nl = "todo todos task tasks pending follow up follow-up next resume continue backlog pick up pick-up", rl = "session summary recap remember last time previous work";
|
|
6314
|
+
function il(e) {
|
|
6265
6315
|
return Math.ceil(e.length / 4);
|
|
6266
6316
|
}
|
|
6267
|
-
function
|
|
6317
|
+
function al(e) {
|
|
6268
6318
|
let t = [
|
|
6269
6319
|
`[${e.id}]`,
|
|
6270
6320
|
`(${e.kind})`,
|
|
@@ -6272,11 +6322,11 @@ function $c(e) {
|
|
|
6272
6322
|
];
|
|
6273
6323
|
return e.body_text && t.push("-", e.body_text), t.join(" ");
|
|
6274
6324
|
}
|
|
6275
|
-
function
|
|
6325
|
+
function ol(e, t) {
|
|
6276
6326
|
let n = `## ${e}`;
|
|
6277
|
-
return t.length === 0 ? `${n}\n` : [n, ...t.map(
|
|
6327
|
+
return t.length === 0 ? `${n}\n` : [n, ...t.map(al)].join("\n");
|
|
6278
6328
|
}
|
|
6279
|
-
function
|
|
6329
|
+
function sl(e, t) {
|
|
6280
6330
|
let n = t?.duplicateIds.get(e.id), r = {
|
|
6281
6331
|
id: e.id,
|
|
6282
6332
|
kind: e.kind,
|
|
@@ -6288,18 +6338,18 @@ function tl(e, t) {
|
|
|
6288
6338
|
};
|
|
6289
6339
|
return n && n.size > 0 && (r.support_count = 1 + n.size, r.duplicate_ids = [...n].sort((e, t) => e - t)), r;
|
|
6290
6340
|
}
|
|
6291
|
-
function
|
|
6341
|
+
function cl(e) {
|
|
6292
6342
|
return e.trim().toLowerCase().split(/\s+/).join(" ");
|
|
6293
6343
|
}
|
|
6294
|
-
function
|
|
6344
|
+
function ll(e) {
|
|
6295
6345
|
if (e.kind === "session_summary") return null;
|
|
6296
|
-
let t =
|
|
6346
|
+
let t = cl(e.title), n = cl(e.body_text);
|
|
6297
6347
|
return !t && !n ? null : `${e.kind.length}:${e.kind}|${t.length}:${t}|${n.length}:${n}`;
|
|
6298
6348
|
}
|
|
6299
|
-
function
|
|
6349
|
+
function ul(e, t) {
|
|
6300
6350
|
let n = [];
|
|
6301
6351
|
for (let r of e) {
|
|
6302
|
-
let e =
|
|
6352
|
+
let e = ll(r);
|
|
6303
6353
|
if (e === null) {
|
|
6304
6354
|
n.push(r);
|
|
6305
6355
|
continue;
|
|
@@ -6318,19 +6368,19 @@ function il(e, t) {
|
|
|
6318
6368
|
}
|
|
6319
6369
|
return n;
|
|
6320
6370
|
}
|
|
6321
|
-
function
|
|
6371
|
+
function dl(e, t) {
|
|
6322
6372
|
let n = new Set((t.toLowerCase().match(/[a-z0-9_]+/g) ?? []).filter(Boolean));
|
|
6323
6373
|
return n.size === 0 ? e : [...e].sort((e, t) => {
|
|
6324
|
-
let r =
|
|
6374
|
+
let r = fl(e.tags_text, n), i = fl(t.tags_text, n);
|
|
6325
6375
|
return i === r ? (t.created_at ?? "").localeCompare(e.created_at ?? "") : i - r;
|
|
6326
6376
|
});
|
|
6327
6377
|
}
|
|
6328
|
-
function
|
|
6378
|
+
function fl(e, t) {
|
|
6329
6379
|
let n = new Set(e.split(/\s+/).filter(Boolean)), r = 0;
|
|
6330
6380
|
for (let e of t) n.has(e) && r++;
|
|
6331
6381
|
return r;
|
|
6332
6382
|
}
|
|
6333
|
-
function
|
|
6383
|
+
function pl(e) {
|
|
6334
6384
|
let t = e.toLowerCase();
|
|
6335
6385
|
for (let e of [
|
|
6336
6386
|
"todo",
|
|
@@ -6357,7 +6407,7 @@ function sl(e) {
|
|
|
6357
6407
|
]) if (t.includes(e)) return !0;
|
|
6358
6408
|
return !1;
|
|
6359
6409
|
}
|
|
6360
|
-
function
|
|
6410
|
+
function ml(e) {
|
|
6361
6411
|
let t = e.toLowerCase();
|
|
6362
6412
|
for (let e of [
|
|
6363
6413
|
"remember",
|
|
@@ -6381,7 +6431,7 @@ function cl(e) {
|
|
|
6381
6431
|
]) if (t.includes(e)) return !0;
|
|
6382
6432
|
return !1;
|
|
6383
6433
|
}
|
|
6384
|
-
function
|
|
6434
|
+
function hl(e) {
|
|
6385
6435
|
return {
|
|
6386
6436
|
id: e.id,
|
|
6387
6437
|
kind: e.kind,
|
|
@@ -6396,57 +6446,57 @@ function ll(e) {
|
|
|
6396
6446
|
metadata: e.metadata_json
|
|
6397
6447
|
};
|
|
6398
6448
|
}
|
|
6399
|
-
function
|
|
6449
|
+
function gl(e) {
|
|
6400
6450
|
let t = Date.parse(e);
|
|
6401
6451
|
return Number.isNaN(t) ? -Infinity : t;
|
|
6402
6452
|
}
|
|
6403
|
-
function
|
|
6453
|
+
function _l(e, t) {
|
|
6404
6454
|
let n = Date.now() - t * 864e5;
|
|
6405
|
-
return e.filter((e) =>
|
|
6455
|
+
return e.filter((e) => gl(e.created_at) >= n);
|
|
6406
6456
|
}
|
|
6407
|
-
function
|
|
6457
|
+
function vl(e, t) {
|
|
6408
6458
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6409
6459
|
return n.sort((e, t) => {
|
|
6410
6460
|
let n = (e) => e === "note" ? 0 : e === "decision" ? 1 : e === "observation" ? 2 : 3;
|
|
6411
6461
|
return n(e.kind) - n(t.kind);
|
|
6412
6462
|
}), n.slice(0, t);
|
|
6413
6463
|
}
|
|
6414
|
-
function
|
|
6464
|
+
function yl(e, t) {
|
|
6415
6465
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6416
6466
|
return n.sort((e, t) => {
|
|
6417
6467
|
let n = (e) => e === "session_summary" ? 0 : e === "decision" ? 1 : e === "note" ? 2 : e === "observation" ? 3 : e === "entities" ? 4 : 5;
|
|
6418
6468
|
return n(e.kind) - n(t.kind);
|
|
6419
6469
|
}), n.slice(0, t);
|
|
6420
6470
|
}
|
|
6421
|
-
function
|
|
6471
|
+
function bl(e, t, n) {
|
|
6422
6472
|
let r = Math.max(t * 3, t);
|
|
6423
|
-
return
|
|
6473
|
+
return vl(e.recent(r, n ?? null).map(hl), t);
|
|
6424
6474
|
}
|
|
6425
|
-
function
|
|
6475
|
+
function xl(e, t, n) {
|
|
6426
6476
|
let r = {
|
|
6427
6477
|
...n ?? {},
|
|
6428
6478
|
kind: "session_summary"
|
|
6429
|
-
}, i = e.recent(t, r).map(
|
|
6479
|
+
}, i = e.recent(t, r).map(hl);
|
|
6430
6480
|
if (i.length >= t) return i.slice(0, t);
|
|
6431
|
-
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(
|
|
6481
|
+
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(hl), s = new Set(i.map((e) => e.id)), c = vl(o.filter((e) => !s.has(e.id)), t - i.length);
|
|
6432
6482
|
return [...i, ...c];
|
|
6433
6483
|
}
|
|
6434
|
-
function
|
|
6484
|
+
function Sl(e) {
|
|
6435
6485
|
if (e == null || typeof e == "boolean") return null;
|
|
6436
6486
|
let t = Number(e);
|
|
6437
6487
|
if (!Number.isFinite(t)) return null;
|
|
6438
6488
|
let n = Math.trunc(t);
|
|
6439
6489
|
return n < 0 ? null : n;
|
|
6440
6490
|
}
|
|
6441
|
-
function
|
|
6491
|
+
function Cl(e) {
|
|
6442
6492
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
6443
6493
|
for (let r of e) {
|
|
6444
|
-
let e =
|
|
6494
|
+
let e = Sl(r);
|
|
6445
6495
|
e == null || e <= 0 || n.has(e) || (n.add(e), t.push(e));
|
|
6446
6496
|
}
|
|
6447
6497
|
return t;
|
|
6448
6498
|
}
|
|
6449
|
-
function
|
|
6499
|
+
function wl(e) {
|
|
6450
6500
|
if (!Array.isArray(e)) return {
|
|
6451
6501
|
ids: [],
|
|
6452
6502
|
valid: !1
|
|
@@ -6456,11 +6506,11 @@ function vl(e) {
|
|
|
6456
6506
|
valid: !1
|
|
6457
6507
|
};
|
|
6458
6508
|
return {
|
|
6459
|
-
ids:
|
|
6509
|
+
ids: Cl(e),
|
|
6460
6510
|
valid: !0
|
|
6461
6511
|
};
|
|
6462
6512
|
}
|
|
6463
|
-
function
|
|
6513
|
+
function Tl(e) {
|
|
6464
6514
|
if (!e) return {};
|
|
6465
6515
|
if (typeof e == "string") try {
|
|
6466
6516
|
let t = JSON.parse(e);
|
|
@@ -6470,7 +6520,7 @@ function yl(e) {
|
|
|
6470
6520
|
}
|
|
6471
6521
|
return typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
6472
6522
|
}
|
|
6473
|
-
function
|
|
6523
|
+
function El(e, t) {
|
|
6474
6524
|
let n = t ? qt(t) : null, r = "CASE WHEN json_valid(metadata_json) = 1 THEN json_extract(metadata_json, '$.project') ELSE NULL END", i = t ? e.db.prepare(`SELECT metadata_json, tokens_read
|
|
6475
6525
|
FROM usage_events
|
|
6476
6526
|
WHERE event = 'pack'
|
|
@@ -6478,15 +6528,15 @@ function bl(e, t) {
|
|
|
6478
6528
|
ORDER BY created_at DESC
|
|
6479
6529
|
LIMIT 25`).all(t, n ?? t) : e.db.prepare("SELECT metadata_json, tokens_read\n FROM usage_events\n WHERE event = 'pack'\n ORDER BY created_at DESC\n LIMIT 25").all();
|
|
6480
6530
|
for (let e of i) {
|
|
6481
|
-
let r =
|
|
6531
|
+
let r = Tl(e.metadata_json);
|
|
6482
6532
|
if (t != null) {
|
|
6483
6533
|
let e = typeof r.project == "string" ? r.project : null;
|
|
6484
6534
|
if (e !== t && e !== n) continue;
|
|
6485
6535
|
}
|
|
6486
6536
|
if (!("pack_item_ids" in r)) continue;
|
|
6487
|
-
let { ids: i, valid: a } =
|
|
6537
|
+
let { ids: i, valid: a } = wl(r.pack_item_ids);
|
|
6488
6538
|
if (!a) continue;
|
|
6489
|
-
let o =
|
|
6539
|
+
let o = Sl(r.pack_tokens) ?? Sl(e.tokens_read);
|
|
6490
6540
|
if (o != null) return {
|
|
6491
6541
|
previousPackIds: i,
|
|
6492
6542
|
previousPackTokens: o
|
|
@@ -6497,20 +6547,20 @@ function bl(e, t) {
|
|
|
6497
6547
|
previousPackTokens: null
|
|
6498
6548
|
};
|
|
6499
6549
|
}
|
|
6500
|
-
function
|
|
6550
|
+
function Dl(e, t) {
|
|
6501
6551
|
if (!t) return null;
|
|
6502
6552
|
let n = qt(t);
|
|
6503
6553
|
return e.db.prepare("SELECT id\n FROM sessions\n WHERE project = ? OR project = ?\n ORDER BY started_at DESC, id DESC\n LIMIT 1").get(t, n)?.id ?? null;
|
|
6504
6554
|
}
|
|
6505
|
-
function
|
|
6506
|
-
return
|
|
6555
|
+
function Ol(e) {
|
|
6556
|
+
return Sl(Tl(e.metadata).discovery_tokens) ?? Math.max(2e3, il(`${e.title} ${e.body_text}`.trim()));
|
|
6507
6557
|
}
|
|
6508
|
-
function
|
|
6509
|
-
let t =
|
|
6558
|
+
function kl(e) {
|
|
6559
|
+
let t = Tl(e.metadata).discovery_group;
|
|
6510
6560
|
return typeof t == "string" && t.trim().length > 0 ? t.trim() : `memory:${e.id}`;
|
|
6511
6561
|
}
|
|
6512
|
-
function
|
|
6513
|
-
let t =
|
|
6562
|
+
function Al(e) {
|
|
6563
|
+
let t = Tl(e.metadata), n = Sl(t.discovery_tokens);
|
|
6514
6564
|
return n != null && n > 0 ? {
|
|
6515
6565
|
tokens: n,
|
|
6516
6566
|
source: typeof t.discovery_source == "string" && t.discovery_source ? t.discovery_source : "known"
|
|
@@ -6519,16 +6569,16 @@ function wl(e) {
|
|
|
6519
6569
|
source: "unknown"
|
|
6520
6570
|
};
|
|
6521
6571
|
}
|
|
6522
|
-
function
|
|
6523
|
-
return
|
|
6572
|
+
function jl(e) {
|
|
6573
|
+
return Tl(e.metadata).discovery_source === "usage" ? "usage" : "estimate";
|
|
6524
6574
|
}
|
|
6525
|
-
function
|
|
6526
|
-
let n = (/* @__PURE__ */ new Date()).toISOString(), r =
|
|
6575
|
+
function Ml(e, t) {
|
|
6576
|
+
let n = (/* @__PURE__ */ new Date()).toISOString(), r = Sl(t.pack_tokens) ?? 0, i = Sl(t.tokens_saved) ?? 0, a = Dl(e, typeof t.project == "string" ? t.project : null);
|
|
6527
6577
|
try {
|
|
6528
6578
|
e.db.prepare("INSERT INTO usage_events(session_id, event, tokens_read, tokens_written, tokens_saved, created_at, metadata_json)\n VALUES (?, 'pack', ?, 0, ?, ?, ?)").run(a, r, i, n, JSON.stringify(t));
|
|
6529
6579
|
} catch {}
|
|
6530
6580
|
}
|
|
6531
|
-
function
|
|
6581
|
+
function Nl(e, t, n, r, i) {
|
|
6532
6582
|
let a = /* @__PURE__ */ new Map();
|
|
6533
6583
|
for (let e of t) {
|
|
6534
6584
|
let t = a.get(e.id);
|
|
@@ -6541,46 +6591,46 @@ function Dl(e, t, n, r, i) {
|
|
|
6541
6591
|
(!t || e.score > t.score) && a.set(e.id, e);
|
|
6542
6592
|
}
|
|
6543
6593
|
return {
|
|
6544
|
-
merged:
|
|
6594
|
+
merged: Wc(e, [...a.values()], r, i),
|
|
6545
6595
|
ftsCount: t.length,
|
|
6546
6596
|
semanticCount: o
|
|
6547
6597
|
};
|
|
6548
6598
|
}
|
|
6549
|
-
function
|
|
6550
|
-
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d =
|
|
6599
|
+
function Pl(e, t, n = 10, r = null, i, a) {
|
|
6600
|
+
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d = pl(t), f = !d && ml(t);
|
|
6551
6601
|
if (d) {
|
|
6552
|
-
let n =
|
|
6602
|
+
let n = Gc(e, `${t} ${nl}`.trim(), o, i);
|
|
6553
6603
|
if (c = n.length, a && a.length > 0) {
|
|
6554
|
-
let t =
|
|
6604
|
+
let t = Nl(e, n, a, o, i);
|
|
6555
6605
|
n = t.merged, l = t.semanticCount;
|
|
6556
6606
|
}
|
|
6557
|
-
if (n.length === 0) s = !0, u =
|
|
6607
|
+
if (n.length === 0) s = !0, u = bl(e, o, i);
|
|
6558
6608
|
else {
|
|
6559
|
-
let e =
|
|
6560
|
-
u =
|
|
6609
|
+
let e = _l(n, tl);
|
|
6610
|
+
u = vl(e.length > 0 ? e : n, o);
|
|
6561
6611
|
}
|
|
6562
6612
|
} else if (f) {
|
|
6563
|
-
let n =
|
|
6564
|
-
if (c = n.length, n.length === 0 && (n =
|
|
6613
|
+
let n = Gc(e, t.trim().length > 0 ? t : rl, o, i);
|
|
6614
|
+
if (c = n.length, n.length === 0 && (n = Gc(e, rl, o, {
|
|
6565
6615
|
...i ?? {},
|
|
6566
6616
|
kind: "session_summary"
|
|
6567
6617
|
}), c = n.length), a && a.length > 0) {
|
|
6568
|
-
let t =
|
|
6618
|
+
let t = Nl(e, n, a, o, i);
|
|
6569
6619
|
n = t.merged, l = t.semanticCount;
|
|
6570
6620
|
}
|
|
6571
|
-
u =
|
|
6621
|
+
u = yl(n, o), u.length === 0 && (s = !0, u = xl(e, o, i));
|
|
6572
6622
|
let r = u[0]?.id;
|
|
6573
6623
|
if (r != null) {
|
|
6574
|
-
let t = Math.max(0, Math.floor(o / 2)), n =
|
|
6575
|
-
n.length > 0 && (u = n.map(
|
|
6624
|
+
let t = Math.max(0, Math.floor(o / 2)), n = qc(e, void 0, r, t, Math.max(0, o - t - 1), i ?? null);
|
|
6625
|
+
n.length > 0 && (u = n.map(hl));
|
|
6576
6626
|
}
|
|
6577
6627
|
} else {
|
|
6578
|
-
let n =
|
|
6628
|
+
let n = Gc(e, t, o, i);
|
|
6579
6629
|
if (a && a.length > 0) {
|
|
6580
|
-
let t =
|
|
6630
|
+
let t = Nl(e, n, a, o, i);
|
|
6581
6631
|
u = t.merged, c = t.ftsCount, l = t.semanticCount;
|
|
6582
6632
|
} else u = n, c = u.length;
|
|
6583
|
-
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(
|
|
6633
|
+
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(hl));
|
|
6584
6634
|
}
|
|
6585
6635
|
let p = u.filter((e) => e.kind === "session_summary").slice(0, 1);
|
|
6586
6636
|
if (p.length === 0) {
|
|
@@ -6605,7 +6655,7 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6605
6655
|
}];
|
|
6606
6656
|
}
|
|
6607
6657
|
}
|
|
6608
|
-
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(
|
|
6658
|
+
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(el), _ = [...u].filter((e) => e.kind !== "session_summary" && !h.has(e.id)).sort((e, t) => (el[e.kind] ?? 99) - (el[t.kind] ?? 99));
|
|
6609
6659
|
f && _.length === 0 && (_ = u.filter((e) => e.kind !== "session_summary")), _.length === 0 && (_ = e.recentByKinds(g, Math.max(o * 3, 10), i ?? null).map((e) => ({
|
|
6610
6660
|
id: e.id,
|
|
6611
6661
|
kind: e.kind,
|
|
@@ -6618,55 +6668,55 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6618
6668
|
score: 0,
|
|
6619
6669
|
session_id: e.session_id,
|
|
6620
6670
|
metadata: e.metadata_json
|
|
6621
|
-
}))), _.length === 0 && (_ = [...m]), _ =
|
|
6671
|
+
}))), _.length === 0 && (_ = [...m]), _ = dl(_, t);
|
|
6622
6672
|
let v = {
|
|
6623
6673
|
canonicalByKey: /* @__PURE__ */ new Map(),
|
|
6624
6674
|
duplicateIds: /* @__PURE__ */ new Map()
|
|
6625
6675
|
};
|
|
6626
|
-
p =
|
|
6676
|
+
p = ul(p, v), m = ul(m, v), _ = ul(_, v);
|
|
6627
6677
|
let y = p, b = m, x = _;
|
|
6628
6678
|
if (r != null && r > 0) {
|
|
6629
6679
|
let e = 0;
|
|
6630
6680
|
y = [];
|
|
6631
6681
|
for (let t of p) {
|
|
6632
|
-
let n =
|
|
6682
|
+
let n = il(al(t));
|
|
6633
6683
|
if (e + n > r) break;
|
|
6634
6684
|
e += n, y.push(t);
|
|
6635
6685
|
}
|
|
6636
6686
|
b = [];
|
|
6637
6687
|
for (let t of m) {
|
|
6638
|
-
let n =
|
|
6688
|
+
let n = il(al(t));
|
|
6639
6689
|
if (e + n > r) break;
|
|
6640
6690
|
e += n, b.push(t);
|
|
6641
6691
|
}
|
|
6642
6692
|
x = [];
|
|
6643
6693
|
for (let t of _) {
|
|
6644
|
-
let n =
|
|
6694
|
+
let n = il(al(t));
|
|
6645
6695
|
if (e + n > r) break;
|
|
6646
6696
|
e += n, x.push(t);
|
|
6647
6697
|
}
|
|
6648
6698
|
}
|
|
6649
6699
|
let S = [
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
].join("\n\n"), C =
|
|
6700
|
+
ol("Summary", y),
|
|
6701
|
+
ol("Timeline", b),
|
|
6702
|
+
ol("Observations", x)
|
|
6703
|
+
].join("\n\n"), C = il(S), w = /* @__PURE__ */ new Set(), T = [], E = [], ee = [];
|
|
6654
6704
|
for (let e of [
|
|
6655
6705
|
...y,
|
|
6656
6706
|
...b,
|
|
6657
6707
|
...x
|
|
6658
|
-
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(
|
|
6659
|
-
let { previousPackIds: te, previousPackTokens: D } =
|
|
6708
|
+
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(sl(e, v)), ee.push(e.id));
|
|
6709
|
+
let { previousPackIds: te, previousPackTokens: D } = El(e, i?.project ?? null), O = te != null && D != null, k = new Set(te ?? []), A = new Set(ee), ne = O ? ee.filter((e) => !k.has(e)) : [], j = O ? (te ?? []).filter((e) => !A.has(e)) : [], re = O ? ee.filter((e) => k.has(e)) : [], ie = O ? C - (D ?? 0) : 0, ae = E.reduce((e, t) => e + Ol(t), 0), oe = /* @__PURE__ */ new Map();
|
|
6660
6710
|
for (let e of E) {
|
|
6661
|
-
let t =
|
|
6711
|
+
let t = kl(e), n = Ol(e);
|
|
6662
6712
|
n > (oe.get(t) ?? 0) && oe.set(t, n);
|
|
6663
6713
|
}
|
|
6664
6714
|
let se = [...oe.values()].reduce((e, t) => e + t, 0), ce = Math.max(0, se - C), M = 0, N = 0, P = 0, F = {};
|
|
6665
6715
|
for (let e of E) {
|
|
6666
|
-
let t =
|
|
6716
|
+
let t = Al(e);
|
|
6667
6717
|
t.tokens > 0 ? (M += t.tokens, N += 1, F[t.source] = (F[t.source] ?? 0) + 1) : P += 1;
|
|
6668
6718
|
}
|
|
6669
|
-
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(
|
|
6719
|
+
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(jl), L = I.filter((e) => e === "usage").length, de = I.length - L, fe = L > 0 && de > 0 ? "mixed" : L > 0 ? "usage" : "estimate", pe = se > 0 ? C / se : null, me = se > 0 ? C - se : null, he = s ? "recent" : null, ge = d ? "task" : f ? "recall" : "default", _e = {
|
|
6670
6720
|
total_items: T.length,
|
|
6671
6721
|
pack_tokens: C,
|
|
6672
6722
|
fallback_used: s,
|
|
@@ -6702,7 +6752,7 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6702
6752
|
fuzzy: 0
|
|
6703
6753
|
}
|
|
6704
6754
|
};
|
|
6705
|
-
return
|
|
6755
|
+
return Ml(e, _e), {
|
|
6706
6756
|
context: t,
|
|
6707
6757
|
items: T,
|
|
6708
6758
|
item_ids: ee,
|
|
@@ -6710,10 +6760,10 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6710
6760
|
metrics: _e
|
|
6711
6761
|
};
|
|
6712
6762
|
}
|
|
6713
|
-
async function
|
|
6763
|
+
async function Fl(e, t, n = 10, r = null, i) {
|
|
6714
6764
|
let a = [];
|
|
6715
6765
|
try {
|
|
6716
|
-
a = (await
|
|
6766
|
+
a = (await Xo(e.db, t, n, { project: i?.project })).map((e) => {
|
|
6717
6767
|
let t = {};
|
|
6718
6768
|
if (e.metadata_json) try {
|
|
6719
6769
|
let n = JSON.parse(e.metadata_json);
|
|
@@ -6734,24 +6784,24 @@ async function kl(e, t, n = 10, r = null, i) {
|
|
|
6734
6784
|
};
|
|
6735
6785
|
});
|
|
6736
6786
|
} catch {}
|
|
6737
|
-
return
|
|
6787
|
+
return Pl(e, t, n, r, i, a);
|
|
6738
6788
|
}
|
|
6739
6789
|
//#endregion
|
|
6740
6790
|
//#region src/raw-event-flush.ts
|
|
6741
|
-
var
|
|
6742
|
-
function
|
|
6791
|
+
var Il = "raw_events_v1";
|
|
6792
|
+
function Ll(e, t = 280) {
|
|
6743
6793
|
let n = e.replace(/\s+/g, " ").trim();
|
|
6744
6794
|
return n.length <= t ? n : `${n.slice(0, t - 3).trimEnd()}...`;
|
|
6745
6795
|
}
|
|
6746
|
-
function
|
|
6796
|
+
function Rl(e) {
|
|
6747
6797
|
let t = (e ?? "").trim().toLowerCase();
|
|
6748
6798
|
return t === "openai" ? "OpenAI" : t === "anthropic" ? "Anthropic" : t ? t.charAt(0).toUpperCase() + t.slice(1) : "Observer";
|
|
6749
6799
|
}
|
|
6750
|
-
function
|
|
6751
|
-
let n =
|
|
6752
|
-
return e instanceof
|
|
6800
|
+
function zl(e, t) {
|
|
6801
|
+
let n = Rl(t), r = String(e.message ?? "").trim().toLowerCase();
|
|
6802
|
+
return e instanceof Ks ? `${n} authentication failed. Refresh credentials and retry.` : e.name === "TimeoutError" || r.includes("timeout") ? `${n} request timed out during raw-event processing.` : r === "observer failed during raw-event flush" || r === "observer produced no storable output for raw-event flush" ? `${n} returned no usable output for raw-event processing.` : /parse|xml|json/i.test(r) ? `${n} response could not be processed.` : `${n} processing failed during raw-event ingestion.`;
|
|
6753
6803
|
}
|
|
6754
|
-
function
|
|
6804
|
+
function Bl(e) {
|
|
6755
6805
|
let t = 0, n = 0;
|
|
6756
6806
|
for (let r of e) r.type === "user_prompt" && t++, r.type === "tool.execute.after" && n++;
|
|
6757
6807
|
let r = [];
|
|
@@ -6763,12 +6813,11 @@ function Pl(e) {
|
|
|
6763
6813
|
}
|
|
6764
6814
|
let i = 0;
|
|
6765
6815
|
if (r.length > 0) {
|
|
6766
|
-
let e = r[0]
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
i = Math.max(0, t - e);
|
|
6816
|
+
let e = r[0];
|
|
6817
|
+
if (e == null) throw Error("Expected timestamp when tsValues is non-empty");
|
|
6818
|
+
let t = r.slice(1), n = e, a = e;
|
|
6819
|
+
for (let e of t) e < n && (n = e), e > a && (a = e);
|
|
6820
|
+
i = Math.max(0, a - n);
|
|
6772
6821
|
}
|
|
6773
6822
|
let a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
|
|
6774
6823
|
for (let t of e) {
|
|
@@ -6796,94 +6845,117 @@ function Pl(e) {
|
|
|
6796
6845
|
filesRead: [...o].sort()
|
|
6797
6846
|
};
|
|
6798
6847
|
}
|
|
6799
|
-
|
|
6800
|
-
let
|
|
6848
|
+
function Vl(e, t) {
|
|
6849
|
+
let n = t.promptCount ?? 0, r = t.toolCount ?? 0;
|
|
6850
|
+
if (n > 0 || r > 0 || t.firstPrompt || e.length > 4 || Oo(e).some((e) => {
|
|
6851
|
+
let t = String(e.type ?? "");
|
|
6852
|
+
return t === "user_prompt" || t === "assistant_message";
|
|
6853
|
+
}) || e.some((e) => {
|
|
6854
|
+
let t = eo(e);
|
|
6855
|
+
return t ? to(t, e) != null : String(e.type ?? "") === "tool.execute.after";
|
|
6856
|
+
})) return !1;
|
|
6857
|
+
let i = new Set([
|
|
6858
|
+
"session.started",
|
|
6859
|
+
"session.idle",
|
|
6860
|
+
"session.ended"
|
|
6861
|
+
]), a = new Set([
|
|
6862
|
+
"session_start",
|
|
6863
|
+
"session_end",
|
|
6864
|
+
"error"
|
|
6865
|
+
]);
|
|
6866
|
+
return e.every((e) => {
|
|
6867
|
+
let t = eo(e);
|
|
6868
|
+
return t ? a.has(String(t.event_type ?? "")) : i.has(String(e.type ?? ""));
|
|
6869
|
+
});
|
|
6870
|
+
}
|
|
6871
|
+
async function Hl(e, t, n) {
|
|
6872
|
+
let { source: r = "opencode", cwd: i, project: a, startedAt: o } = n, { opencodeSessionId: s, maxEvents: c } = n;
|
|
6801
6873
|
r = (r ?? "").trim().toLowerCase() || "opencode";
|
|
6802
|
-
let
|
|
6803
|
-
i ??=
|
|
6804
|
-
let
|
|
6805
|
-
if (
|
|
6874
|
+
let l = e.rawEventSessionMeta(s, r);
|
|
6875
|
+
i ??= l.cwd ?? process.cwd(), a ??= l.project ?? null, o ??= l.started_at ?? null;
|
|
6876
|
+
let u = e.rawEventFlushState(s, r), d = e.rawEventsSinceBySeq(s, r, u, c);
|
|
6877
|
+
if (d.length === 0) return {
|
|
6806
6878
|
flushed: 0,
|
|
6807
6879
|
updatedState: 0
|
|
6808
6880
|
};
|
|
6809
|
-
let
|
|
6810
|
-
for (let e of
|
|
6881
|
+
let f = [];
|
|
6882
|
+
for (let e of d) {
|
|
6811
6883
|
let t = e.event_seq;
|
|
6812
6884
|
if (t == null) continue;
|
|
6813
6885
|
let n = Number(t);
|
|
6814
|
-
Number.isFinite(n) &&
|
|
6886
|
+
Number.isFinite(n) && f.push(n);
|
|
6815
6887
|
}
|
|
6816
|
-
if (
|
|
6888
|
+
if (f.length === 0) return {
|
|
6817
6889
|
flushed: 0,
|
|
6818
6890
|
updatedState: 0
|
|
6819
6891
|
};
|
|
6820
|
-
let
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
}
|
|
6825
|
-
|
|
6892
|
+
let p = f[0];
|
|
6893
|
+
if (p == null) return {
|
|
6894
|
+
flushed: 0,
|
|
6895
|
+
updatedState: 0
|
|
6896
|
+
};
|
|
6897
|
+
let m = f.slice(1), h = p, g = p;
|
|
6898
|
+
for (let e of m) e < h && (h = e), e > g && (g = e);
|
|
6899
|
+
if (g < h) return {
|
|
6826
6900
|
flushed: 0,
|
|
6827
6901
|
updatedState: 0
|
|
6828
6902
|
};
|
|
6829
|
-
let { batchId:
|
|
6830
|
-
if (
|
|
6903
|
+
let { batchId: _, status: v } = e.getOrCreateRawEventFlushBatch(s, r, h, g, Il);
|
|
6904
|
+
if (v === "completed") return e.updateRawEventFlushState(s, g, r), {
|
|
6831
6905
|
flushed: 0,
|
|
6832
6906
|
updatedState: 1
|
|
6833
6907
|
};
|
|
6834
|
-
if (!e.claimRawEventFlushBatch(
|
|
6908
|
+
if (!e.claimRawEventFlushBatch(_)) return {
|
|
6835
6909
|
flushed: 0,
|
|
6836
6910
|
updatedState: 0
|
|
6837
6911
|
};
|
|
6838
|
-
let
|
|
6839
|
-
|
|
6840
|
-
batch_id:
|
|
6841
|
-
start_event_seq:
|
|
6842
|
-
end_event_seq:
|
|
6912
|
+
let y = Bl(d);
|
|
6913
|
+
if (y.opencodeSessionId = s, y.source = r, y.streamId = s, y.flusher = "raw_events", y.flushBatch = {
|
|
6914
|
+
batch_id: _,
|
|
6915
|
+
start_event_seq: h,
|
|
6916
|
+
end_event_seq: g
|
|
6917
|
+
}, Vl(d, y)) return e.updateRawEventFlushBatchStatus(_, "completed"), e.updateRawEventFlushState(s, g, r), {
|
|
6918
|
+
flushed: d.length,
|
|
6919
|
+
updatedState: 1
|
|
6843
6920
|
};
|
|
6844
|
-
let
|
|
6921
|
+
let b = {
|
|
6845
6922
|
cwd: i ?? void 0,
|
|
6846
6923
|
project: a ?? void 0,
|
|
6847
6924
|
startedAt: o ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
6848
|
-
events:
|
|
6849
|
-
sessionContext:
|
|
6925
|
+
events: d,
|
|
6926
|
+
sessionContext: y
|
|
6850
6927
|
};
|
|
6851
6928
|
try {
|
|
6852
|
-
await
|
|
6929
|
+
await is(b, e, t);
|
|
6853
6930
|
} catch (n) {
|
|
6854
|
-
let
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
let a = t.observer?.getStatus?.()?.provider, o = jl(Nl(i, a));
|
|
6860
|
-
throw e.recordRawEventFlushBatchFailure(g, {
|
|
6861
|
-
message: o,
|
|
6862
|
-
errorType: i instanceof Bs ? "ObserverAuthError" : i.name,
|
|
6863
|
-
observerProvider: a ?? null,
|
|
6931
|
+
let r = n instanceof Error ? n : Error(String(n)), i = t.observer?.getStatus?.()?.provider, a = Ll(zl(r, i));
|
|
6932
|
+
throw e.recordRawEventFlushBatchFailure(_, {
|
|
6933
|
+
message: a,
|
|
6934
|
+
errorType: r instanceof Ks ? "ObserverAuthError" : r.name,
|
|
6935
|
+
observerProvider: i ?? null,
|
|
6864
6936
|
observerModel: t.observer?.getStatus?.()?.model ?? null,
|
|
6865
6937
|
observerRuntime: null
|
|
6866
6938
|
}), n;
|
|
6867
6939
|
}
|
|
6868
|
-
return e.updateRawEventFlushBatchStatus(
|
|
6869
|
-
flushed:
|
|
6940
|
+
return e.updateRawEventFlushBatchStatus(_, "completed"), e.updateRawEventFlushState(s, g, r), {
|
|
6941
|
+
flushed: d.length,
|
|
6870
6942
|
updatedState: 1
|
|
6871
6943
|
};
|
|
6872
6944
|
}
|
|
6873
6945
|
//#endregion
|
|
6874
6946
|
//#region src/raw-event-sweeper.ts
|
|
6875
|
-
var
|
|
6876
|
-
function
|
|
6947
|
+
var Ul = 60;
|
|
6948
|
+
function Wl(e, t) {
|
|
6877
6949
|
let n = process.env[e];
|
|
6878
6950
|
if (n == null) return t;
|
|
6879
6951
|
let r = Number.parseInt(n, 10);
|
|
6880
6952
|
return Number.isFinite(r) ? r : t;
|
|
6881
6953
|
}
|
|
6882
|
-
function
|
|
6954
|
+
function Gl(e) {
|
|
6883
6955
|
let t = (process.env[e] ?? "1").trim().toLowerCase();
|
|
6884
6956
|
return t === "0" || t === "false" || t === "off";
|
|
6885
6957
|
}
|
|
6886
|
-
var
|
|
6958
|
+
var Kl = class {
|
|
6887
6959
|
store;
|
|
6888
6960
|
ingestOpts;
|
|
6889
6961
|
active = !1;
|
|
@@ -6901,7 +6973,7 @@ var zl = class {
|
|
|
6901
6973
|
this.store = e, this.ingestOpts = t;
|
|
6902
6974
|
}
|
|
6903
6975
|
enabled() {
|
|
6904
|
-
return !
|
|
6976
|
+
return !Gl("CODEMEM_RAW_EVENTS_SWEEPER");
|
|
6905
6977
|
}
|
|
6906
6978
|
intervalMs() {
|
|
6907
6979
|
let e = process.env.CODEMEM_RAW_EVENTS_SWEEPER_INTERVAL_MS;
|
|
@@ -6913,31 +6985,31 @@ var zl = class {
|
|
|
6913
6985
|
return Number.isFinite(n) && n > 0 ? Math.max(1e3, n * 1e3) : 3e4;
|
|
6914
6986
|
}
|
|
6915
6987
|
idleMs() {
|
|
6916
|
-
return
|
|
6988
|
+
return Wl("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
|
|
6917
6989
|
}
|
|
6918
6990
|
limit() {
|
|
6919
|
-
return
|
|
6991
|
+
return Wl("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
|
|
6920
6992
|
}
|
|
6921
6993
|
workerMaxEvents() {
|
|
6922
|
-
let e =
|
|
6994
|
+
let e = Wl("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 250);
|
|
6923
6995
|
return e <= 0 ? null : e;
|
|
6924
6996
|
}
|
|
6925
6997
|
retentionMs() {
|
|
6926
|
-
return
|
|
6998
|
+
return Wl("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
|
|
6927
6999
|
}
|
|
6928
7000
|
autoFlushEnabled() {
|
|
6929
7001
|
return (process.env.CODEMEM_RAW_EVENTS_AUTO_FLUSH ?? "").trim() === "1";
|
|
6930
7002
|
}
|
|
6931
7003
|
debounceMs() {
|
|
6932
|
-
return
|
|
7004
|
+
return Wl("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
|
|
6933
7005
|
}
|
|
6934
7006
|
stuckBatchMs() {
|
|
6935
|
-
return
|
|
7007
|
+
return Wl("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
|
|
6936
7008
|
}
|
|
6937
7009
|
handleAuthError(e) {
|
|
6938
|
-
if (this.authBackoffUntil = Date.now() / 1e3 +
|
|
7010
|
+
if (this.authBackoffUntil = Date.now() / 1e3 + Ul, !this.authErrorLogged) {
|
|
6939
7011
|
this.authErrorLogged = !0;
|
|
6940
|
-
let t = `codemem: observer auth error — backing off for ${
|
|
7012
|
+
let t = `codemem: observer auth error — backing off for ${Ul}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
|
|
6941
7013
|
console.error(t);
|
|
6942
7014
|
}
|
|
6943
7015
|
}
|
|
@@ -7017,17 +7089,16 @@ var zl = class {
|
|
|
7017
7089
|
let r = this.autoFlushTimers.get(n);
|
|
7018
7090
|
r && (clearTimeout(r), this.autoFlushTimers.delete(n));
|
|
7019
7091
|
try {
|
|
7020
|
-
await
|
|
7092
|
+
await Hl(this.store, this.ingestOpts, {
|
|
7021
7093
|
opencodeSessionId: e,
|
|
7022
7094
|
source: t,
|
|
7023
7095
|
cwd: null,
|
|
7024
7096
|
project: null,
|
|
7025
7097
|
startedAt: null,
|
|
7026
|
-
maxEvents: null
|
|
7027
|
-
allowEmptyFlush: !0
|
|
7098
|
+
maxEvents: null
|
|
7028
7099
|
});
|
|
7029
7100
|
} catch (t) {
|
|
7030
|
-
if (t instanceof
|
|
7101
|
+
if (t instanceof Ks) {
|
|
7031
7102
|
this.handleAuthError(t);
|
|
7032
7103
|
return;
|
|
7033
7104
|
}
|
|
@@ -7075,17 +7146,16 @@ var zl = class {
|
|
|
7075
7146
|
if (!this.sessionFlushing.has(r)) {
|
|
7076
7147
|
this.sessionFlushing.add(r);
|
|
7077
7148
|
try {
|
|
7078
|
-
await
|
|
7149
|
+
await Hl(this.store, this.ingestOpts, {
|
|
7079
7150
|
opencodeSessionId: n,
|
|
7080
7151
|
source: t,
|
|
7081
7152
|
cwd: null,
|
|
7082
7153
|
project: null,
|
|
7083
7154
|
startedAt: null,
|
|
7084
|
-
maxEvents: i
|
|
7085
|
-
allowEmptyFlush: !0
|
|
7155
|
+
maxEvents: i
|
|
7086
7156
|
}), o.add(`${t}:${n}`);
|
|
7087
7157
|
} catch (e) {
|
|
7088
|
-
if (e instanceof
|
|
7158
|
+
if (e instanceof Ks) {
|
|
7089
7159
|
this.handleAuthError(e);
|
|
7090
7160
|
return;
|
|
7091
7161
|
}
|
|
@@ -7103,17 +7173,16 @@ var zl = class {
|
|
|
7103
7173
|
if (!this.sessionFlushing.has(r)) {
|
|
7104
7174
|
this.sessionFlushing.add(r);
|
|
7105
7175
|
try {
|
|
7106
|
-
await
|
|
7176
|
+
await Hl(this.store, this.ingestOpts, {
|
|
7107
7177
|
opencodeSessionId: n,
|
|
7108
7178
|
source: t,
|
|
7109
7179
|
cwd: null,
|
|
7110
7180
|
project: null,
|
|
7111
7181
|
startedAt: null,
|
|
7112
|
-
maxEvents: i
|
|
7113
|
-
allowEmptyFlush: !0
|
|
7182
|
+
maxEvents: i
|
|
7114
7183
|
});
|
|
7115
7184
|
} catch (e) {
|
|
7116
|
-
if (e instanceof
|
|
7185
|
+
if (e instanceof Ks) {
|
|
7117
7186
|
this.handleAuthError(e);
|
|
7118
7187
|
return;
|
|
7119
7188
|
}
|
|
@@ -7127,7 +7196,7 @@ var zl = class {
|
|
|
7127
7196
|
};
|
|
7128
7197
|
//#endregion
|
|
7129
7198
|
//#region src/sync-replication.ts
|
|
7130
|
-
function
|
|
7199
|
+
function ql(e) {
|
|
7131
7200
|
if (e == null) return null;
|
|
7132
7201
|
if (typeof e == "number" && Number.isFinite(e)) return e;
|
|
7133
7202
|
if (typeof e == "string" && e.trim().length > 0) {
|
|
@@ -7139,7 +7208,7 @@ function Bl(e) {
|
|
|
7139
7208
|
function Q(e) {
|
|
7140
7209
|
return e == null ? null : String(e);
|
|
7141
7210
|
}
|
|
7142
|
-
function
|
|
7211
|
+
function Jl(e, t) {
|
|
7143
7212
|
if (!e.payload_json) return null;
|
|
7144
7213
|
let n;
|
|
7145
7214
|
try {
|
|
@@ -7149,14 +7218,14 @@ function Vl(e, t) {
|
|
|
7149
7218
|
}
|
|
7150
7219
|
let r = n.metadata_json, i = r && typeof r == "object" && !Array.isArray(r) ? { ...r } : {};
|
|
7151
7220
|
return {
|
|
7152
|
-
session_id:
|
|
7221
|
+
session_id: ql(n.session_id),
|
|
7153
7222
|
kind: Q(n.kind),
|
|
7154
7223
|
title: Q(n.title),
|
|
7155
7224
|
subtitle: Q(n.subtitle),
|
|
7156
7225
|
body_text: Q(n.body_text),
|
|
7157
|
-
confidence:
|
|
7226
|
+
confidence: ql(n.confidence),
|
|
7158
7227
|
tags_text: Q(n.tags_text),
|
|
7159
|
-
active:
|
|
7228
|
+
active: ql(n.active),
|
|
7160
7229
|
created_at: Q(n.created_at),
|
|
7161
7230
|
updated_at: Q(n.updated_at),
|
|
7162
7231
|
metadata_json: i,
|
|
@@ -7173,19 +7242,19 @@ function Vl(e, t) {
|
|
|
7173
7242
|
concepts: n.concepts ?? null,
|
|
7174
7243
|
files_read: n.files_read ?? null,
|
|
7175
7244
|
files_modified: n.files_modified ?? null,
|
|
7176
|
-
user_prompt_id:
|
|
7177
|
-
prompt_number:
|
|
7245
|
+
user_prompt_id: ql(n.user_prompt_id),
|
|
7246
|
+
prompt_number: ql(n.prompt_number),
|
|
7178
7247
|
deleted_at: Q(n.deleted_at),
|
|
7179
|
-
rev:
|
|
7248
|
+
rev: ql(n.rev) ?? 0,
|
|
7180
7249
|
import_key: Q(n.import_key)
|
|
7181
7250
|
};
|
|
7182
7251
|
}
|
|
7183
|
-
function
|
|
7252
|
+
function Yl(e) {
|
|
7184
7253
|
let t = String(e ?? "").trim();
|
|
7185
7254
|
return t.length > 0 ? t : null;
|
|
7186
7255
|
}
|
|
7187
|
-
function
|
|
7188
|
-
let t =
|
|
7256
|
+
function Xl(e) {
|
|
7257
|
+
let t = Yl(e);
|
|
7189
7258
|
if (!t) return null;
|
|
7190
7259
|
let n = t.lastIndexOf("|");
|
|
7191
7260
|
if (n <= 0) return null;
|
|
@@ -7195,20 +7264,20 @@ function Ul(e) {
|
|
|
7195
7264
|
id: i
|
|
7196
7265
|
};
|
|
7197
7266
|
}
|
|
7198
|
-
function
|
|
7267
|
+
function Zl(e, t) {
|
|
7199
7268
|
return `${e}|${t}`;
|
|
7200
7269
|
}
|
|
7201
|
-
function
|
|
7270
|
+
function Ql(e) {
|
|
7202
7271
|
e.exec("\n CREATE TABLE IF NOT EXISTS sync_reset_state (\n id INTEGER PRIMARY KEY,\n generation INTEGER NOT NULL,\n snapshot_id TEXT NOT NULL,\n baseline_cursor TEXT,\n retained_floor_cursor TEXT,\n updated_at TEXT NOT NULL\n )\n ");
|
|
7203
7272
|
}
|
|
7204
|
-
function
|
|
7205
|
-
|
|
7273
|
+
function $l(e) {
|
|
7274
|
+
Ql(e);
|
|
7206
7275
|
let t = N(e, { schema: H }), n = t.select().from(cn).where(k(cn.id, 1)).get();
|
|
7207
7276
|
if (n) return {
|
|
7208
7277
|
generation: Number(n.generation ?? 1),
|
|
7209
7278
|
snapshot_id: String(n.snapshot_id),
|
|
7210
|
-
baseline_cursor:
|
|
7211
|
-
retained_floor_cursor:
|
|
7279
|
+
baseline_cursor: Yl(n.baseline_cursor),
|
|
7280
|
+
retained_floor_cursor: Yl(n.retained_floor_cursor)
|
|
7212
7281
|
};
|
|
7213
7282
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
7214
7283
|
id: 1,
|
|
@@ -7225,12 +7294,12 @@ function Kl(e) {
|
|
|
7225
7294
|
retained_floor_cursor: i.retained_floor_cursor
|
|
7226
7295
|
};
|
|
7227
7296
|
}
|
|
7228
|
-
function
|
|
7229
|
-
let n =
|
|
7297
|
+
function eu(e, t) {
|
|
7298
|
+
let n = $l(e), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
7230
7299
|
generation: t.generation ?? n.generation,
|
|
7231
7300
|
snapshot_id: t.snapshot_id ?? n.snapshot_id,
|
|
7232
|
-
baseline_cursor: t.baseline_cursor === void 0 ? n.baseline_cursor :
|
|
7233
|
-
retained_floor_cursor: t.retained_floor_cursor === void 0 ? n.retained_floor_cursor :
|
|
7301
|
+
baseline_cursor: t.baseline_cursor === void 0 ? n.baseline_cursor : Yl(t.baseline_cursor),
|
|
7302
|
+
retained_floor_cursor: t.retained_floor_cursor === void 0 ? n.retained_floor_cursor : Yl(t.retained_floor_cursor)
|
|
7234
7303
|
};
|
|
7235
7304
|
return N(e, { schema: H }).insert(cn).values({
|
|
7236
7305
|
id: 1,
|
|
@@ -7247,7 +7316,7 @@ function ql(e, t) {
|
|
|
7247
7316
|
}
|
|
7248
7317
|
}).run(), i;
|
|
7249
7318
|
}
|
|
7250
|
-
function
|
|
7319
|
+
function tu(e, t) {
|
|
7251
7320
|
return {
|
|
7252
7321
|
reset_required: !0,
|
|
7253
7322
|
reset: {
|
|
@@ -7257,17 +7326,17 @@ function Jl(e, t) {
|
|
|
7257
7326
|
}
|
|
7258
7327
|
};
|
|
7259
7328
|
}
|
|
7260
|
-
function
|
|
7329
|
+
function nu(e, t) {
|
|
7261
7330
|
return {
|
|
7262
7331
|
...e,
|
|
7263
7332
|
clock_device_id: t
|
|
7264
7333
|
};
|
|
7265
7334
|
}
|
|
7266
|
-
function
|
|
7335
|
+
function ru(e) {
|
|
7267
7336
|
let t = z(e);
|
|
7268
7337
|
return typeof t.clock_device_id == "string" ? t.clock_device_id : "";
|
|
7269
7338
|
}
|
|
7270
|
-
function
|
|
7339
|
+
function iu(e, t) {
|
|
7271
7340
|
let n = new TextEncoder(), r = [], i = [], a = 9;
|
|
7272
7341
|
for (let o of e) {
|
|
7273
7342
|
let e = n.encode(JSON.stringify(o)).byteLength, s = i.length === 0 ? e : e + 1;
|
|
@@ -7279,14 +7348,14 @@ function Zl(e, t) {
|
|
|
7279
7348
|
}
|
|
7280
7349
|
return i.length > 0 && r.push(i), r;
|
|
7281
7350
|
}
|
|
7282
|
-
function
|
|
7351
|
+
function au(e, t) {
|
|
7283
7352
|
let n = N(e, { schema: H }).select({
|
|
7284
7353
|
last_applied_cursor: an.last_applied_cursor,
|
|
7285
7354
|
last_acked_cursor: an.last_acked_cursor
|
|
7286
7355
|
}).from(an).where(k(an.peer_device_id, t)).get();
|
|
7287
7356
|
return n ? [n.last_applied_cursor, n.last_acked_cursor] : [null, null];
|
|
7288
7357
|
}
|
|
7289
|
-
function
|
|
7358
|
+
function ou(e, t, n = {}) {
|
|
7290
7359
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = n.lastApplied ?? null, a = n.lastAcked ?? null;
|
|
7291
7360
|
N(e, { schema: H }).insert(an).values({
|
|
7292
7361
|
peer_device_id: t,
|
|
@@ -7302,7 +7371,7 @@ function $l(e, t, n = {}) {
|
|
|
7302
7371
|
}
|
|
7303
7372
|
}).run();
|
|
7304
7373
|
}
|
|
7305
|
-
var
|
|
7374
|
+
var su = [
|
|
7306
7375
|
"op_id",
|
|
7307
7376
|
"entity_type",
|
|
7308
7377
|
"entity_id",
|
|
@@ -7313,26 +7382,26 @@ var eu = [
|
|
|
7313
7382
|
"device_id",
|
|
7314
7383
|
"created_at"
|
|
7315
7384
|
];
|
|
7316
|
-
function
|
|
7385
|
+
function cu(e) {
|
|
7317
7386
|
if (typeof e != "object" || !e) return [];
|
|
7318
7387
|
let t = e.ops;
|
|
7319
7388
|
return Array.isArray(t) ? t.filter((e) => {
|
|
7320
7389
|
if (typeof e != "object" || !e) return !1;
|
|
7321
7390
|
let t = e;
|
|
7322
|
-
return
|
|
7391
|
+
return su.every((e) => t[e] !== void 0 && t[e] !== null);
|
|
7323
7392
|
}) : [];
|
|
7324
7393
|
}
|
|
7325
|
-
function
|
|
7394
|
+
function lu(e, t, n) {
|
|
7326
7395
|
return [
|
|
7327
7396
|
e,
|
|
7328
7397
|
t,
|
|
7329
7398
|
n
|
|
7330
7399
|
];
|
|
7331
7400
|
}
|
|
7332
|
-
function
|
|
7401
|
+
function uu(e, t) {
|
|
7333
7402
|
return e[0] === t[0] ? e[1] === t[1] ? e[2] > t[2] : e[1] > t[1] : e[0] > t[0];
|
|
7334
7403
|
}
|
|
7335
|
-
function
|
|
7404
|
+
function du(e, t) {
|
|
7336
7405
|
let n = N(e, { schema: H }), r = a(), i = (/* @__PURE__ */ new Date()).toISOString(), o = n.select().from(W).where(k(W.id, t.memoryId)).get(), s = Number(o?.rev ?? 0), c = o?.updated_at ?? i, l = o?.import_key ?? String(t.memoryId), u = z(o?.metadata_json), d = typeof u.clock_device_id == "string" && u.clock_device_id.trim().length > 0 ? u.clock_device_id : t.deviceId, f;
|
|
7337
7406
|
if (t.payload) f = B(t.payload);
|
|
7338
7407
|
else if (o && t.opType === "upsert") {
|
|
@@ -7387,17 +7456,17 @@ function iu(e, t) {
|
|
|
7387
7456
|
created_at: i
|
|
7388
7457
|
}).run(), r;
|
|
7389
7458
|
}
|
|
7390
|
-
function
|
|
7459
|
+
function fu(e) {
|
|
7391
7460
|
let t = e.indexOf("|");
|
|
7392
7461
|
return t < 0 ? null : [e.slice(0, t), e.slice(t + 1)];
|
|
7393
7462
|
}
|
|
7394
|
-
function
|
|
7463
|
+
function pu(e, t) {
|
|
7395
7464
|
return `${e}|${t}`;
|
|
7396
7465
|
}
|
|
7397
|
-
function
|
|
7466
|
+
function mu(e, t, n = 100, r) {
|
|
7398
7467
|
let i = N(e, { schema: H }), a = J, o = [];
|
|
7399
7468
|
if (t) {
|
|
7400
|
-
let e =
|
|
7469
|
+
let e = fu(t);
|
|
7401
7470
|
if (e) {
|
|
7402
7471
|
let [t, n] = e;
|
|
7403
7472
|
o.push(ce(A(a.created_at, t), D(k(a.created_at, t), A(a.op_id, n))));
|
|
@@ -7418,17 +7487,17 @@ function su(e, t, n = 100, r) {
|
|
|
7418
7487
|
})), u = null;
|
|
7419
7488
|
if (c.length > 0) {
|
|
7420
7489
|
let e = c.at(-1);
|
|
7421
|
-
e && (u =
|
|
7490
|
+
e && (u = pu(e.created_at, e.op_id));
|
|
7422
7491
|
}
|
|
7423
7492
|
return [l, u];
|
|
7424
7493
|
}
|
|
7425
|
-
function
|
|
7426
|
-
let n =
|
|
7427
|
-
if (i != null && i !== n.generation) return
|
|
7494
|
+
function hu(e, t) {
|
|
7495
|
+
let n = $l(e), r = Yl(t.since), i = t.generation ?? null, a = Yl(t.snapshotId), o = Yl(t.baselineCursor), s = i != null || a != null || o != null;
|
|
7496
|
+
if (i != null && i !== n.generation) return tu(n, "generation_mismatch");
|
|
7428
7497
|
let c = i != null && a != null && o === n.baseline_cursor;
|
|
7429
|
-
if (!s || !c || a !== n.snapshot_id || o !== n.baseline_cursor) return
|
|
7430
|
-
if (r != null && n.retained_floor_cursor != null && r < n.retained_floor_cursor) return
|
|
7431
|
-
let [l, u] =
|
|
7498
|
+
if (!s || !c || a !== n.snapshot_id || o !== n.baseline_cursor) return tu(n, "boundary_mismatch");
|
|
7499
|
+
if (r != null && n.retained_floor_cursor != null && r < n.retained_floor_cursor) return tu(n, "stale_cursor");
|
|
7500
|
+
let [l, u] = mu(e, r, t.limit, t.deviceId);
|
|
7432
7501
|
return {
|
|
7433
7502
|
reset_required: !1,
|
|
7434
7503
|
boundary: n,
|
|
@@ -7436,11 +7505,11 @@ function cu(e, t) {
|
|
|
7436
7505
|
nextCursor: u
|
|
7437
7506
|
};
|
|
7438
7507
|
}
|
|
7439
|
-
function
|
|
7440
|
-
let n =
|
|
7508
|
+
function gu(e, t) {
|
|
7509
|
+
let n = $l(e);
|
|
7441
7510
|
if (t.generation !== n.generation) throw Error("generation_mismatch");
|
|
7442
|
-
if (
|
|
7443
|
-
let r = Math.max(1, Math.min(t.limit ?? 200, 1e3)), i =
|
|
7511
|
+
if (Yl(t.snapshotId) !== n.snapshot_id || Yl(t.baselineCursor) !== n.baseline_cursor) throw Error("boundary_mismatch");
|
|
7512
|
+
let r = Math.max(1, Math.min(t.limit ?? 200, 1e3)), i = Xl(t.pageToken), a = N(e, { schema: H }), o = Math.min(Math.max(r * 3, r), 1e3), s = (e, t) => a.select({
|
|
7444
7513
|
memory: W,
|
|
7445
7514
|
sessionProject: U.project
|
|
7446
7515
|
}).from(W).innerJoin(U, k(U.id, W.session_id)).where(D(re(W.import_key), e ? ce(A(W.import_key, e.importKey), D(k(W.import_key, e.importKey), A(W.id, e.id))) : void 0)).orderBy(W.import_key, W.id).limit(t).all(), c = [], l = i, u = null, d = !1;
|
|
@@ -7452,12 +7521,12 @@ function lu(e, t) {
|
|
|
7452
7521
|
if (!a) continue;
|
|
7453
7522
|
let o = String(a.memory.import_key ?? "").trim();
|
|
7454
7523
|
if (!o) continue;
|
|
7455
|
-
u =
|
|
7524
|
+
u = Zl(o, Number(a.memory.id)), l = {
|
|
7456
7525
|
importKey: o,
|
|
7457
7526
|
id: Number(a.memory.id)
|
|
7458
7527
|
};
|
|
7459
|
-
let f =
|
|
7460
|
-
if (!
|
|
7528
|
+
let f = Ru(a.memory);
|
|
7529
|
+
if (!ku(f) && !Au(e, t.peerDeviceId ?? null) || !Ou(e, a.sessionProject, t.peerDeviceId ?? null)) continue;
|
|
7461
7530
|
let p = f.metadata_json && typeof f.metadata_json == "object" ? f.metadata_json : {}, m = typeof p.clock_device_id == "string" && p.clock_device_id.trim() ? p.clock_device_id.trim() : String(a.memory.origin_device_id ?? "local");
|
|
7462
7531
|
if (c.push({
|
|
7463
7532
|
entity_id: o,
|
|
@@ -7480,10 +7549,10 @@ function lu(e, t) {
|
|
|
7480
7549
|
hasMore: d && u != null
|
|
7481
7550
|
};
|
|
7482
7551
|
}
|
|
7483
|
-
function
|
|
7552
|
+
function _u(e, t = 25) {
|
|
7484
7553
|
let n = N(e, { schema: H }), r = n.select().from(W).orderBy(W.updated_at).all(), i = 0;
|
|
7485
7554
|
for (let e of r) {
|
|
7486
|
-
if (!e.import_key || !
|
|
7555
|
+
if (!e.import_key || !ku(Ru(e))) continue;
|
|
7487
7556
|
let r = e.deleted_at || e.active === 0 ? "delete" : "upsert";
|
|
7488
7557
|
if (!n.select({ one: M`1` }).from(J).where(D(k(J.entity_type, "memory_item"), k(J.entity_id, e.import_key), k(J.op_type, r), k(J.clock_rev, Number(e.rev ?? 0)))).limit(1).get() && (i += 1, i >= t)) break;
|
|
7489
7558
|
}
|
|
@@ -7492,10 +7561,8 @@ function uu(e, t = 25) {
|
|
|
7492
7561
|
count: i
|
|
7493
7562
|
};
|
|
7494
7563
|
}
|
|
7495
|
-
function
|
|
7496
|
-
let n = Math.max(1, Math.floor(t?.maxAgeDays ?? 30)), r = Math.max(1, Math.floor(t?.maxSizeBytes ?? 512 * 1024 * 1024)), i = Math.max(1, Math.floor(t?.maxDeleteOps ?? 2 ** 53 - 1)), a = Math.max(1, Math.floor(t?.maxRuntimeMs ?? 2 ** 53 - 1)), o = N(e, { schema: H }), s = (/* @__PURE__ */ new Date(Date.now() - n * 24 * 60 * 60 * 1e3)).toISOString(), c = Date.now(), l = 0, u = null;
|
|
7497
|
-
e.prepare("DELETE FROM replication_ops WHERE op_id = ?");
|
|
7498
|
-
let d = e.prepare("DELETE FROM replication_ops WHERE created_at < ? OR (created_at = ? AND op_id <= ?)"), f = mu(e);
|
|
7564
|
+
function vu(e, t) {
|
|
7565
|
+
let n = Math.max(1, Math.floor(t?.maxAgeDays ?? 30)), r = Math.max(1, Math.floor(t?.maxSizeBytes ?? 512 * 1024 * 1024)), i = Math.max(1, Math.floor(t?.maxDeleteOps ?? 2 ** 53 - 1)), a = Math.max(1, Math.floor(t?.maxRuntimeMs ?? 2 ** 53 - 1)), o = N(e, { schema: H }), s = (/* @__PURE__ */ new Date(Date.now() - n * 24 * 60 * 60 * 1e3)).toISOString(), c = Date.now(), l = 0, u = null, d = e.prepare("DELETE FROM replication_ops WHERE created_at < ? OR (created_at = ? AND op_id <= ?)"), f = Su(e);
|
|
7499
7566
|
if (f == null) throw Error("replication_ops_size_unavailable");
|
|
7500
7567
|
let p = !1, m = () => l >= i || Date.now() - c >= a;
|
|
7501
7568
|
for (;;) {
|
|
@@ -7510,7 +7577,7 @@ function du(e, t) {
|
|
|
7510
7577
|
if (n.length === 0) break;
|
|
7511
7578
|
let r = n[n.length - 1];
|
|
7512
7579
|
if (!r) break;
|
|
7513
|
-
if (u =
|
|
7580
|
+
if (u = pu(String(r.created_at), String(r.op_id)), l += d.run(r.created_at, r.created_at, r.op_id).changes ?? 0, m()) {
|
|
7514
7581
|
p = !0;
|
|
7515
7582
|
break;
|
|
7516
7583
|
}
|
|
@@ -7527,13 +7594,13 @@ function du(e, t) {
|
|
|
7527
7594
|
created_at: J.created_at
|
|
7528
7595
|
}).from(J).orderBy(J.created_at, J.op_id).limit(n).all(), a = r[r.length - 1];
|
|
7529
7596
|
if (!a) break;
|
|
7530
|
-
u =
|
|
7531
|
-
let s =
|
|
7597
|
+
u = pu(String(a.created_at), String(a.op_id)), l += d.run(a.created_at, a.created_at, a.op_id).changes ?? 0;
|
|
7598
|
+
let s = Su(e);
|
|
7532
7599
|
if (s == null) throw Error("replication_ops_size_unavailable");
|
|
7533
7600
|
h = s;
|
|
7534
7601
|
}
|
|
7535
|
-
let g =
|
|
7536
|
-
return
|
|
7602
|
+
let g = $l(e), _ = l > 0 ? u : g.retained_floor_cursor;
|
|
7603
|
+
return eu(e, { retained_floor_cursor: _ }), {
|
|
7537
7604
|
deleted: l,
|
|
7538
7605
|
retained_floor_cursor: _,
|
|
7539
7606
|
estimated_bytes_before: f,
|
|
@@ -7541,8 +7608,31 @@ function du(e, t) {
|
|
|
7541
7608
|
stopped_by_budget: p
|
|
7542
7609
|
};
|
|
7543
7610
|
}
|
|
7544
|
-
function
|
|
7545
|
-
let
|
|
7611
|
+
function yu(e, t) {
|
|
7612
|
+
let n = Math.max(1, Math.floor(t.maxPasses ?? 25)), r = 0, i = 0, a = null, o = Su(e) ?? 0, s = !1;
|
|
7613
|
+
for (;;) {
|
|
7614
|
+
if (t.signal?.aborted || i >= n) {
|
|
7615
|
+
s = !0;
|
|
7616
|
+
break;
|
|
7617
|
+
}
|
|
7618
|
+
let c = vu(e, t);
|
|
7619
|
+
if (i += 1, r += c.deleted, a = c.retained_floor_cursor, o = c.estimated_bytes_after ?? Su(e) ?? 0, s = c.stopped_by_budget ?? !1, t.onPass?.({
|
|
7620
|
+
passNumber: i,
|
|
7621
|
+
deleted: c.deleted,
|
|
7622
|
+
afterBytes: o,
|
|
7623
|
+
stoppedByBudget: s
|
|
7624
|
+
}), c.deleted === 0 || !c.stopped_by_budget) break;
|
|
7625
|
+
}
|
|
7626
|
+
return {
|
|
7627
|
+
totalDeleted: r,
|
|
7628
|
+
passes: i,
|
|
7629
|
+
lastFloor: a,
|
|
7630
|
+
afterBytes: o,
|
|
7631
|
+
stoppedByBudget: s
|
|
7632
|
+
};
|
|
7633
|
+
}
|
|
7634
|
+
function bu(e, t, n = 2 ** 53 - 1) {
|
|
7635
|
+
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date(Date.now() - Math.max(1, Math.floor(t)) * 24 * 60 * 60 * 1e3)).toISOString(), a = Su(e);
|
|
7546
7636
|
if (a == null) throw Error("replication_ops_size_unavailable");
|
|
7547
7637
|
let o = r.select({
|
|
7548
7638
|
op_id: J.op_id,
|
|
@@ -7550,14 +7640,14 @@ function fu(e, t, n = 2 ** 53 - 1) {
|
|
|
7550
7640
|
}).from(J).where(M`${J.created_at} < ${i}`).orderBy(J.created_at, J.op_id).limit(Math.max(1, n)).all(), s = o[o.length - 1];
|
|
7551
7641
|
if (!s) return {
|
|
7552
7642
|
deleted: 0,
|
|
7553
|
-
retained_floor_cursor:
|
|
7643
|
+
retained_floor_cursor: $l(e).retained_floor_cursor,
|
|
7554
7644
|
estimated_bytes_before: a,
|
|
7555
7645
|
estimated_bytes_after: a,
|
|
7556
7646
|
stopped_by_budget: !1
|
|
7557
7647
|
};
|
|
7558
|
-
let c = e.prepare("DELETE FROM replication_ops WHERE created_at < ? OR (created_at = ? AND op_id <= ?)").run(s.created_at, s.created_at, s.op_id).changes ?? 0, l =
|
|
7559
|
-
|
|
7560
|
-
let u =
|
|
7648
|
+
let c = e.prepare("DELETE FROM replication_ops WHERE created_at < ? OR (created_at = ? AND op_id <= ?)").run(s.created_at, s.created_at, s.op_id).changes ?? 0, l = pu(String(s.created_at), String(s.op_id));
|
|
7649
|
+
eu(e, { retained_floor_cursor: l });
|
|
7650
|
+
let u = Su(e);
|
|
7561
7651
|
if (u == null) throw Error("replication_ops_size_unavailable");
|
|
7562
7652
|
return {
|
|
7563
7653
|
deleted: c,
|
|
@@ -7567,19 +7657,19 @@ function fu(e, t, n = 2 ** 53 - 1) {
|
|
|
7567
7657
|
stopped_by_budget: !1
|
|
7568
7658
|
};
|
|
7569
7659
|
}
|
|
7570
|
-
function
|
|
7660
|
+
function xu(e, t, n) {
|
|
7571
7661
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date(Date.now() - Math.max(1, Math.floor(t)) * 24 * 60 * 60 * 1e3)).toISOString(), a = r.select({ total: M`COUNT(*)` }).from(J).where(M`${J.created_at} < ${i}`).get(), o = r.select({ total: M`COUNT(*)` }).from(J).get(), s = r.select({
|
|
7572
7662
|
op_id: J.op_id,
|
|
7573
7663
|
created_at: J.created_at
|
|
7574
|
-
}).from(J).where(M`${J.created_at} < ${i}`).orderBy(O(J.created_at), O(J.op_id)).limit(1).get(), c = Number(a?.total ?? 0), l = Number(o?.total ?? 0), u =
|
|
7664
|
+
}).from(J).where(M`${J.created_at} < ${i}`).orderBy(O(J.created_at), O(J.op_id)).limit(1).get(), c = Number(a?.total ?? 0), l = Number(o?.total ?? 0), u = Su(e) ?? 0, d = l > 0 ? Math.round(u * c / l) : 0;
|
|
7575
7665
|
return {
|
|
7576
7666
|
candidate_ops: c,
|
|
7577
7667
|
estimated_candidate_bytes: Math.max(0, d),
|
|
7578
|
-
cutoff_cursor: s ?
|
|
7668
|
+
cutoff_cursor: s ? pu(String(s.created_at), String(s.op_id)) : null,
|
|
7579
7669
|
estimated_batches: c > 0 ? Math.ceil(c / Math.max(1, n)) : 0
|
|
7580
7670
|
};
|
|
7581
7671
|
}
|
|
7582
|
-
function
|
|
7672
|
+
function Su(e) {
|
|
7583
7673
|
try {
|
|
7584
7674
|
let t = e.prepare("SELECT COALESCE(SUM(pgsize), 0) AS total_bytes\n FROM dbstat\n WHERE name = 'replication_ops'\n OR name LIKE 'idx_replication_ops_%'\n OR name LIKE 'sqlite_autoindex_replication_ops_%'").get(), n = Number(t?.total_bytes ?? 0);
|
|
7585
7675
|
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
@@ -7587,7 +7677,7 @@ function mu(e) {
|
|
|
7587
7677
|
return null;
|
|
7588
7678
|
}
|
|
7589
7679
|
}
|
|
7590
|
-
function
|
|
7680
|
+
function Cu(e) {
|
|
7591
7681
|
if (!Array.isArray(e)) return [];
|
|
7592
7682
|
let t = [];
|
|
7593
7683
|
for (let n of e) {
|
|
@@ -7596,25 +7686,25 @@ function hu(e) {
|
|
|
7596
7686
|
}
|
|
7597
7687
|
return t;
|
|
7598
7688
|
}
|
|
7599
|
-
function
|
|
7600
|
-
return Array.isArray(e) ?
|
|
7689
|
+
function wu(e) {
|
|
7690
|
+
return Array.isArray(e) ? Cu(e) : typeof e == "string" ? e.split(",").map((e) => e.trim()).filter(Boolean) : [];
|
|
7601
7691
|
}
|
|
7602
|
-
function
|
|
7692
|
+
function Tu(e) {
|
|
7603
7693
|
if (!e) return [];
|
|
7604
7694
|
try {
|
|
7605
|
-
return
|
|
7695
|
+
return Cu(JSON.parse(e));
|
|
7606
7696
|
} catch {
|
|
7607
7697
|
return [];
|
|
7608
7698
|
}
|
|
7609
7699
|
}
|
|
7610
|
-
function
|
|
7700
|
+
function Eu(e) {
|
|
7611
7701
|
let t = String(e ?? "").trim().replaceAll("\\", "/");
|
|
7612
7702
|
if (!t) return "";
|
|
7613
7703
|
let n = t.split("/").filter(Boolean);
|
|
7614
7704
|
return n.length > 0 ? n[n.length - 1] ?? "" : "";
|
|
7615
7705
|
}
|
|
7616
|
-
function
|
|
7617
|
-
let n = N(e, { schema: H }), r = tt(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o =
|
|
7706
|
+
function Du(e, t) {
|
|
7707
|
+
let n = N(e, { schema: H }), r = tt(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o = wu(i === void 0 ? r.sync_projects_include : i), s = wu(a === void 0 ? r.sync_projects_exclude : a);
|
|
7618
7708
|
if (!t) return {
|
|
7619
7709
|
include: o,
|
|
7620
7710
|
exclude: s
|
|
@@ -7627,15 +7717,15 @@ function yu(e, t) {
|
|
|
7627
7717
|
include: o,
|
|
7628
7718
|
exclude: s
|
|
7629
7719
|
} : {
|
|
7630
|
-
include:
|
|
7631
|
-
exclude:
|
|
7720
|
+
include: Tu(c.projects_include_json),
|
|
7721
|
+
exclude: Tu(c.projects_exclude_json)
|
|
7632
7722
|
};
|
|
7633
7723
|
}
|
|
7634
|
-
function
|
|
7635
|
-
let { include: r, exclude: i } =
|
|
7724
|
+
function Ou(e, t, n) {
|
|
7725
|
+
let { include: r, exclude: i } = Du(e, n), a = String(t ?? "").trim(), o = Eu(a);
|
|
7636
7726
|
return i.some((e) => e === a || e === o) ? !1 : r.length === 0 ? !0 : r.some((e) => e === a || e === o);
|
|
7637
7727
|
}
|
|
7638
|
-
function
|
|
7728
|
+
function ku(e) {
|
|
7639
7729
|
if (!e) return !1;
|
|
7640
7730
|
let t = String(e.visibility ?? "").trim().toLowerCase(), n = e.metadata_json && typeof e.metadata_json == "object" && !Array.isArray(e.metadata_json) ? e.metadata_json : {}, r = String(n.visibility ?? "").trim().toLowerCase();
|
|
7641
7731
|
if (!t && r && (t = r), !t) {
|
|
@@ -7645,10 +7735,10 @@ function xu(e) {
|
|
|
7645
7735
|
}
|
|
7646
7736
|
return t === "shared";
|
|
7647
7737
|
}
|
|
7648
|
-
function
|
|
7738
|
+
function Au(e, t) {
|
|
7649
7739
|
return t ? !!N(e, { schema: H }).select({ claimed_local_actor: Y.claimed_local_actor }).from(Y).where(k(Y.peer_device_id, t)).limit(1).get()?.claimed_local_actor : !1;
|
|
7650
7740
|
}
|
|
7651
|
-
function
|
|
7741
|
+
function ju(e) {
|
|
7652
7742
|
if (!e || !e.trim()) return null;
|
|
7653
7743
|
try {
|
|
7654
7744
|
let t = JSON.parse(e);
|
|
@@ -7657,16 +7747,16 @@ function Cu(e) {
|
|
|
7657
7747
|
return null;
|
|
7658
7748
|
}
|
|
7659
7749
|
}
|
|
7660
|
-
function
|
|
7750
|
+
function Mu(e, t, n) {
|
|
7661
7751
|
let r = [], i = null, a = 0, o = null;
|
|
7662
7752
|
for (let s of t) {
|
|
7663
7753
|
if (s.entity_type === "memory_item") {
|
|
7664
|
-
let t =
|
|
7754
|
+
let t = ju(s.payload_json);
|
|
7665
7755
|
if (s.op_type === "delete" && t == null) {
|
|
7666
|
-
r.push(s), i =
|
|
7756
|
+
r.push(s), i = pu(s.created_at, s.op_id);
|
|
7667
7757
|
continue;
|
|
7668
7758
|
}
|
|
7669
|
-
if (!
|
|
7759
|
+
if (!ku(t) && !Au(e, n)) {
|
|
7670
7760
|
a += 1, o ||= {
|
|
7671
7761
|
reason: "visibility_filter",
|
|
7672
7762
|
op_id: s.op_id,
|
|
@@ -7675,11 +7765,11 @@ function wu(e, t, n) {
|
|
|
7675
7765
|
entity_id: s.entity_id,
|
|
7676
7766
|
visibility: typeof t?.visibility == "string" ? String(t.visibility) : null,
|
|
7677
7767
|
skipped_count: 0
|
|
7678
|
-
}, i =
|
|
7768
|
+
}, i = pu(s.created_at, s.op_id);
|
|
7679
7769
|
continue;
|
|
7680
7770
|
}
|
|
7681
7771
|
let c = typeof t?.project == "string" && t.project.trim() ? t.project.trim() : null;
|
|
7682
|
-
if (!
|
|
7772
|
+
if (!Ou(e, c, n)) {
|
|
7683
7773
|
a += 1, o ||= {
|
|
7684
7774
|
reason: "project_filter",
|
|
7685
7775
|
op_id: s.op_id,
|
|
@@ -7688,11 +7778,11 @@ function wu(e, t, n) {
|
|
|
7688
7778
|
entity_id: s.entity_id,
|
|
7689
7779
|
project: c,
|
|
7690
7780
|
skipped_count: 0
|
|
7691
|
-
}, i =
|
|
7781
|
+
}, i = pu(s.created_at, s.op_id);
|
|
7692
7782
|
continue;
|
|
7693
7783
|
}
|
|
7694
7784
|
}
|
|
7695
|
-
r.push(s), i =
|
|
7785
|
+
r.push(s), i = pu(s.created_at, s.op_id);
|
|
7696
7786
|
}
|
|
7697
7787
|
return o && (o.skipped_count = a), [
|
|
7698
7788
|
r,
|
|
@@ -7700,12 +7790,12 @@ function wu(e, t, n) {
|
|
|
7700
7790
|
o
|
|
7701
7791
|
];
|
|
7702
7792
|
}
|
|
7703
|
-
function
|
|
7704
|
-
let [r, i] =
|
|
7793
|
+
function Nu(e, t, n) {
|
|
7794
|
+
let [r, i] = Mu(e, t, n);
|
|
7705
7795
|
return [r, i];
|
|
7706
7796
|
}
|
|
7707
|
-
var
|
|
7708
|
-
function
|
|
7797
|
+
var Pu = /^legacy:memory_item:(.+)$/;
|
|
7798
|
+
function Fu(e, t = 2e3) {
|
|
7709
7799
|
let n = N(e, { schema: H }), r = n.select({ device_id: X.device_id }).from(X).limit(1).get(), i = String(r?.device_id ?? "").trim();
|
|
7710
7800
|
if (!i) return 0;
|
|
7711
7801
|
let a = n.select({
|
|
@@ -7719,7 +7809,7 @@ function Du(e, t = 2e3) {
|
|
|
7719
7809
|
let t = Number(e.id), r = String(e.import_key ?? "").trim(), a = z(e.metadata_json), s = typeof a.clock_device_id == "string" ? a.clock_device_id.trim() : "", c = "";
|
|
7720
7810
|
if (!r) c = `legacy:${i}:memory_item:${t}`;
|
|
7721
7811
|
else {
|
|
7722
|
-
let e = r.match(
|
|
7812
|
+
let e = r.match(Pu);
|
|
7723
7813
|
if (!e) continue;
|
|
7724
7814
|
let t = e[1] ?? "", n = s && s !== "local" ? s : i;
|
|
7725
7815
|
c = n ? `legacy:${n}:memory_item:${t}` : "";
|
|
@@ -7730,9 +7820,9 @@ function Du(e, t = 2e3) {
|
|
|
7730
7820
|
}
|
|
7731
7821
|
return o;
|
|
7732
7822
|
}
|
|
7733
|
-
function
|
|
7823
|
+
function Iu(e, t = 200) {
|
|
7734
7824
|
if (t <= 0) return 0;
|
|
7735
|
-
|
|
7825
|
+
Fu(e, 2e3);
|
|
7736
7826
|
let n = N(e, { schema: H }), r = n.select({ device_id: X.device_id }).from(X).limit(1).get(), i = String(r?.device_id ?? "").trim(), a = n.select().from(W).where(D(ce(re(W.deleted_at), k(W.active, 0)), M`NOT EXISTS (
|
|
7737
7827
|
SELECT 1
|
|
7738
7828
|
FROM replication_ops ro
|
|
@@ -7757,7 +7847,7 @@ function Ou(e, t = 200) {
|
|
|
7757
7847
|
for (let e of s) {
|
|
7758
7848
|
let t = Number(e.id ?? 0);
|
|
7759
7849
|
if (!t) continue;
|
|
7760
|
-
let r = typeof e.metadata_json == "string" ? z(e.metadata_json) :
|
|
7850
|
+
let r = typeof e.metadata_json == "string" ? z(e.metadata_json) : Lu(e.metadata_json), a = typeof r.clock_device_id == "string" ? r.clock_device_id.trim() : "", o = a && a !== "local" ? a : i, s = String(e.import_key ?? "").trim();
|
|
7761
7851
|
if (!s) {
|
|
7762
7852
|
if (!o) continue;
|
|
7763
7853
|
s = `legacy:${o}:memory_item:${t}`, n.update(W).set({ import_key: s }).where(k(W.id, t)).run();
|
|
@@ -7766,7 +7856,7 @@ function Ou(e, t = 200) {
|
|
|
7766
7856
|
if (n.select({ one: M`1` }).from(J).where(k(J.op_id, p)).limit(1).get()) continue;
|
|
7767
7857
|
let m = o;
|
|
7768
7858
|
if (!m) continue;
|
|
7769
|
-
let h =
|
|
7859
|
+
let h = Ru(e);
|
|
7770
7860
|
n.insert(J).values({
|
|
7771
7861
|
op_id: p,
|
|
7772
7862
|
entity_type: "memory_item",
|
|
@@ -7782,10 +7872,10 @@ function Ou(e, t = 200) {
|
|
|
7782
7872
|
}
|
|
7783
7873
|
return l;
|
|
7784
7874
|
}
|
|
7785
|
-
function
|
|
7875
|
+
function Lu(e) {
|
|
7786
7876
|
return typeof e == "string" ? z(e) : e && typeof e == "object" ? e : {};
|
|
7787
7877
|
}
|
|
7788
|
-
function
|
|
7878
|
+
function Ru(e) {
|
|
7789
7879
|
let t = (e) => {
|
|
7790
7880
|
if (typeof e != "string") return e ?? null;
|
|
7791
7881
|
try {
|
|
@@ -7826,7 +7916,7 @@ function Au(e) {
|
|
|
7826
7916
|
import_key: e.import_key ?? null
|
|
7827
7917
|
};
|
|
7828
7918
|
}
|
|
7829
|
-
function
|
|
7919
|
+
function zu(e, t, n) {
|
|
7830
7920
|
let r = N(e, { schema: H }), i = {
|
|
7831
7921
|
applied: 0,
|
|
7832
7922
|
skipped: 0,
|
|
@@ -7851,14 +7941,14 @@ function ju(e, t, n) {
|
|
|
7851
7941
|
metadata_json: W.metadata_json
|
|
7852
7942
|
}).from(W).where(k(W.import_key, t)).get();
|
|
7853
7943
|
if (n) {
|
|
7854
|
-
let a =
|
|
7855
|
-
if (!
|
|
7856
|
-
i.conflicts++,
|
|
7944
|
+
let a = ru(n.metadata_json), o = lu(n.rev ?? 0, n.updated_at ?? "", a);
|
|
7945
|
+
if (!uu(lu(e.clock_rev, e.clock_updated_at, e.clock_device_id), o)) {
|
|
7946
|
+
i.conflicts++, Bu(r, e);
|
|
7857
7947
|
continue;
|
|
7858
7948
|
}
|
|
7859
|
-
let s =
|
|
7949
|
+
let s = Jl(e, i.errors);
|
|
7860
7950
|
if (!s) continue;
|
|
7861
|
-
let c =
|
|
7951
|
+
let c = nu(s.metadata_json, e.clock_device_id);
|
|
7862
7952
|
r.update(W).set({
|
|
7863
7953
|
kind: M`COALESCE(${s.kind}, ${W.kind})`,
|
|
7864
7954
|
title: M`COALESCE(${s.title}, ${W.title})`,
|
|
@@ -7886,9 +7976,9 @@ function ju(e, t, n) {
|
|
|
7886
7976
|
files_modified: V(s.files_modified)
|
|
7887
7977
|
}).where(k(W.import_key, t)).run();
|
|
7888
7978
|
} else {
|
|
7889
|
-
let n =
|
|
7979
|
+
let n = Jl(e, i.errors);
|
|
7890
7980
|
if (!n) continue;
|
|
7891
|
-
let a =
|
|
7981
|
+
let a = Vu(r, null, e.clock_updated_at), o = nu(n.metadata_json, e.clock_device_id);
|
|
7892
7982
|
r.insert(W).values({
|
|
7893
7983
|
session_id: a,
|
|
7894
7984
|
kind: n.kind ?? "discovery",
|
|
@@ -7927,9 +8017,9 @@ function ju(e, t, n) {
|
|
|
7927
8017
|
metadata_json: W.metadata_json
|
|
7928
8018
|
}).from(W).where(k(W.import_key, t)).limit(1).get();
|
|
7929
8019
|
if (n) {
|
|
7930
|
-
let t =
|
|
7931
|
-
if (!
|
|
7932
|
-
i.conflicts++,
|
|
8020
|
+
let t = lu(n.rev ?? 1, n.updated_at ?? "", ru(n.metadata_json));
|
|
8021
|
+
if (!uu(lu(e.clock_rev, e.clock_updated_at, e.clock_device_id), t)) {
|
|
8022
|
+
i.conflicts++, Bu(r, e);
|
|
7933
8023
|
continue;
|
|
7934
8024
|
}
|
|
7935
8025
|
let a = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -7941,16 +8031,16 @@ function ju(e, t, n) {
|
|
|
7941
8031
|
}).where(k(W.id, n.id)).run();
|
|
7942
8032
|
}
|
|
7943
8033
|
} else {
|
|
7944
|
-
i.skipped++,
|
|
8034
|
+
i.skipped++, Bu(r, e);
|
|
7945
8035
|
continue;
|
|
7946
8036
|
}
|
|
7947
|
-
|
|
8037
|
+
Bu(r, e), i.applied++;
|
|
7948
8038
|
} catch (t) {
|
|
7949
8039
|
i.errors.push(`op ${e.op_id}: ${t instanceof Error ? t.message : String(t)}`);
|
|
7950
8040
|
}
|
|
7951
8041
|
})(), i;
|
|
7952
8042
|
}
|
|
7953
|
-
function
|
|
8043
|
+
function Bu(e, t) {
|
|
7954
8044
|
e.insert(J).values({
|
|
7955
8045
|
op_id: t.op_id,
|
|
7956
8046
|
entity_type: t.entity_type,
|
|
@@ -7964,7 +8054,7 @@ function Mu(e, t) {
|
|
|
7964
8054
|
created_at: t.created_at
|
|
7965
8055
|
}).onConflictDoNothing().run();
|
|
7966
8056
|
}
|
|
7967
|
-
function
|
|
8057
|
+
function Vu(e, t, n) {
|
|
7968
8058
|
if (t != null && e.select({ id: U.id }).from(U).where(k(U.id, t)).get()) return t;
|
|
7969
8059
|
let r = n || (/* @__PURE__ */ new Date()).toISOString(), i = e.insert(U).values({
|
|
7970
8060
|
started_at: r,
|
|
@@ -7977,7 +8067,7 @@ function Nu(e, t, n) {
|
|
|
7977
8067
|
}
|
|
7978
8068
|
//#endregion
|
|
7979
8069
|
//#region src/store.ts
|
|
7980
|
-
var
|
|
8070
|
+
var Hu = new Set([
|
|
7981
8071
|
"discovery",
|
|
7982
8072
|
"change",
|
|
7983
8073
|
"feature",
|
|
@@ -7986,27 +8076,27 @@ var Pu = new Set([
|
|
|
7986
8076
|
"decision",
|
|
7987
8077
|
"exploration"
|
|
7988
8078
|
]);
|
|
7989
|
-
function
|
|
8079
|
+
function Uu(e) {
|
|
7990
8080
|
let t = e.trim().toLowerCase();
|
|
7991
|
-
if (!
|
|
8081
|
+
if (!Hu.has(t)) throw Error(`Invalid memory kind "${e}". Allowed: ${[...Hu].join(", ")}`);
|
|
7992
8082
|
return t;
|
|
7993
8083
|
}
|
|
7994
|
-
function
|
|
8084
|
+
function Wu() {
|
|
7995
8085
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
7996
8086
|
}
|
|
7997
|
-
function
|
|
8087
|
+
function Gu(e) {
|
|
7998
8088
|
return (e.match(/\?/g) ?? []).length;
|
|
7999
8089
|
}
|
|
8000
|
-
function
|
|
8090
|
+
function Ku(e, t) {
|
|
8001
8091
|
let n = e.split("?"), r = M.raw(n[0] ?? "");
|
|
8002
8092
|
for (let e = 1; e < n.length; e++) r = M`${r}${t[e - 1]}${M.raw(n[e] ?? "")}`;
|
|
8003
8093
|
return r;
|
|
8004
8094
|
}
|
|
8005
|
-
function
|
|
8095
|
+
function qu(e, t) {
|
|
8006
8096
|
let n = [], r = 0;
|
|
8007
8097
|
for (let i of e) {
|
|
8008
|
-
let e =
|
|
8009
|
-
n.push(
|
|
8098
|
+
let e = Gu(i), a = t.slice(r, r + e);
|
|
8099
|
+
n.push(Ku(i, a)), r += e;
|
|
8010
8100
|
}
|
|
8011
8101
|
if (r !== t.length) throw Error("filter parameter mismatch while building SQL clauses");
|
|
8012
8102
|
if (n.length === 1) return n[0] ?? M`1=1`;
|
|
@@ -8019,7 +8109,7 @@ function $(e) {
|
|
|
8019
8109
|
let t = e.trim();
|
|
8020
8110
|
return t.length > 0 ? t : null;
|
|
8021
8111
|
}
|
|
8022
|
-
function
|
|
8112
|
+
function Ju(e) {
|
|
8023
8113
|
if (typeof e != "string" || !e.trim()) return [];
|
|
8024
8114
|
try {
|
|
8025
8115
|
let t = JSON.parse(e);
|
|
@@ -8028,21 +8118,21 @@ function Bu(e) {
|
|
|
8028
8118
|
return [];
|
|
8029
8119
|
}
|
|
8030
8120
|
}
|
|
8031
|
-
function
|
|
8121
|
+
function Yu(e) {
|
|
8032
8122
|
let t = $(e);
|
|
8033
8123
|
if (!t) return "";
|
|
8034
8124
|
let n = t.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
8035
8125
|
return n[n.length - 1] ?? t;
|
|
8036
8126
|
}
|
|
8037
|
-
var
|
|
8038
|
-
function
|
|
8127
|
+
var Xu = "Legacy synced peer", Zu = "shared:legacy";
|
|
8128
|
+
function Qu(e) {
|
|
8039
8129
|
let { metadata_json: t, ...n } = e;
|
|
8040
8130
|
return {
|
|
8041
8131
|
...n,
|
|
8042
8132
|
metadata_json: z(t)
|
|
8043
8133
|
};
|
|
8044
8134
|
}
|
|
8045
|
-
var
|
|
8135
|
+
var $u = class {
|
|
8046
8136
|
db;
|
|
8047
8137
|
dbPath;
|
|
8048
8138
|
deviceId;
|
|
@@ -8075,7 +8165,7 @@ var Gu = class {
|
|
|
8075
8165
|
enqueueVectorWrite(e, t, n) {
|
|
8076
8166
|
if (this.db.inTransaction) return;
|
|
8077
8167
|
let r = null;
|
|
8078
|
-
r =
|
|
8168
|
+
r = Jo(this.db, e, t, n).catch(() => {}).finally(() => {
|
|
8079
8169
|
r && this.pendingVectorWrites.delete(r);
|
|
8080
8170
|
}), this.pendingVectorWrites.add(r);
|
|
8081
8171
|
}
|
|
@@ -8084,10 +8174,10 @@ var Gu = class {
|
|
|
8084
8174
|
}
|
|
8085
8175
|
get(e) {
|
|
8086
8176
|
let t = this.d.select().from(W).where(k(W.id, e)).get();
|
|
8087
|
-
return t ?
|
|
8177
|
+
return t ? Qu(t) : null;
|
|
8088
8178
|
}
|
|
8089
8179
|
startSession(e) {
|
|
8090
|
-
let t =
|
|
8180
|
+
let t = Wu(), n = this.d.insert(U).values({
|
|
8091
8181
|
started_at: t,
|
|
8092
8182
|
cwd: e.cwd ?? process.cwd(),
|
|
8093
8183
|
project: e.project ?? null,
|
|
@@ -8101,7 +8191,7 @@ var Gu = class {
|
|
|
8101
8191
|
return n;
|
|
8102
8192
|
}
|
|
8103
8193
|
endSession(e, t) {
|
|
8104
|
-
let n =
|
|
8194
|
+
let n = Wu();
|
|
8105
8195
|
if (t) {
|
|
8106
8196
|
let r = {
|
|
8107
8197
|
...z(this.d.select({ metadata_json: U.metadata_json }).from(U).where(k(U.id, e)).get()?.metadata_json),
|
|
@@ -8114,7 +8204,7 @@ var Gu = class {
|
|
|
8114
8204
|
} else this.d.update(U).set({ ended_at: n }).where(k(U.id, e)).run();
|
|
8115
8205
|
}
|
|
8116
8206
|
remember(e, t, n, r, i = .5, o, s) {
|
|
8117
|
-
let c =
|
|
8207
|
+
let c = Uu(t), l = Wu(), u = o ? [...new Set(o)].sort().join(" ") : "", d = { ...s ?? {} };
|
|
8118
8208
|
d.clock_device_id ??= this.deviceId;
|
|
8119
8209
|
let f = d.import_key || a();
|
|
8120
8210
|
d.import_key = f;
|
|
@@ -8151,7 +8241,7 @@ var Gu = class {
|
|
|
8151
8241
|
}).returning({ id: W.id }).all()[0]?.id;
|
|
8152
8242
|
if (S == null) throw Error("memory insert returned no id");
|
|
8153
8243
|
try {
|
|
8154
|
-
|
|
8244
|
+
du(this.db, {
|
|
8155
8245
|
memoryId: S,
|
|
8156
8246
|
opType: "upsert",
|
|
8157
8247
|
deviceId: this.deviceId
|
|
@@ -8199,7 +8289,7 @@ var Gu = class {
|
|
|
8199
8289
|
if (!t) return;
|
|
8200
8290
|
let n = z(t.metadata_json);
|
|
8201
8291
|
n.clock_device_id = this.deviceId;
|
|
8202
|
-
let r =
|
|
8292
|
+
let r = Wu(), i = (t.rev ?? 0) + 1;
|
|
8203
8293
|
this.d.update(W).set({
|
|
8204
8294
|
active: 0,
|
|
8205
8295
|
deleted_at: r,
|
|
@@ -8208,7 +8298,7 @@ var Gu = class {
|
|
|
8208
8298
|
rev: i
|
|
8209
8299
|
}).where(k(W.id, e)).run();
|
|
8210
8300
|
try {
|
|
8211
|
-
|
|
8301
|
+
du(this.db, {
|
|
8212
8302
|
memoryId: e,
|
|
8213
8303
|
opType: "delete",
|
|
8214
8304
|
deviceId: this.deviceId
|
|
@@ -8217,20 +8307,20 @@ var Gu = class {
|
|
|
8217
8307
|
}).immediate();
|
|
8218
8308
|
}
|
|
8219
8309
|
recent(e = 10, t, n = 0) {
|
|
8220
|
-
let r = ["memory_items.active = 1"], i = Ma(t), a =
|
|
8310
|
+
let r = ["memory_items.active = 1"], i = Ma(t), a = qu([...r, ...i.clauses], i.params), o = i.joinSessions ? M.raw("memory_items JOIN sessions ON sessions.id = memory_items.session_id") : M.raw("memory_items");
|
|
8221
8311
|
return this.d.all(M`SELECT memory_items.* FROM ${o}
|
|
8222
8312
|
WHERE ${a}
|
|
8223
8313
|
ORDER BY created_at DESC
|
|
8224
|
-
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) =>
|
|
8314
|
+
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) => Qu(e));
|
|
8225
8315
|
}
|
|
8226
8316
|
recentByKinds(e, t = 10, n, r = 0) {
|
|
8227
8317
|
let i = e.filter((e) => e.length > 0);
|
|
8228
8318
|
if (i.length === 0) return [];
|
|
8229
|
-
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Ma(n), s =
|
|
8319
|
+
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Ma(n), s = qu([...a, ...o.clauses], [...i, ...o.params]), c = o.joinSessions ? M.raw("memory_items JOIN sessions ON sessions.id = memory_items.session_id") : M.raw("memory_items");
|
|
8230
8320
|
return this.d.all(M`SELECT memory_items.* FROM ${c}
|
|
8231
8321
|
WHERE ${s}
|
|
8232
8322
|
ORDER BY created_at DESC
|
|
8233
|
-
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) =>
|
|
8323
|
+
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) => Qu(e));
|
|
8234
8324
|
}
|
|
8235
8325
|
stats() {
|
|
8236
8326
|
let e = (e) => this.d.select({ c: M`COUNT(*)` }).from(e).get()?.c ?? 0, t = e(W), n = this.d.select({ c: M`COUNT(*)` }).from(W).where(k(W.active, 1)).get()?.c ?? 0, r = e(U), i = e($t), a = e(G), o = 0;
|
|
@@ -8295,7 +8385,7 @@ var Gu = class {
|
|
|
8295
8385
|
if (!this.memoryOwnedBySelf(t)) throw Error("memory not owned by this device");
|
|
8296
8386
|
let r = $(t.actor_id) ?? this.actorId, i = n === "shared" ? "shared" : "personal", a = n === "shared" && t.workspace_id?.startsWith("shared:") ? t.workspace_id : i === "personal" ? `personal:${r}` : "shared:default", o = z(t.metadata_json);
|
|
8297
8387
|
o.visibility = n, o.workspace_kind = i, o.workspace_id = a, o.clock_device_id = this.deviceId;
|
|
8298
|
-
let s =
|
|
8388
|
+
let s = Wu(), c = (t.rev ?? 0) + 1;
|
|
8299
8389
|
this.d.update(W).set({
|
|
8300
8390
|
visibility: n,
|
|
8301
8391
|
workspace_kind: i,
|
|
@@ -8305,7 +8395,7 @@ var Gu = class {
|
|
|
8305
8395
|
rev: c
|
|
8306
8396
|
}).where(k(W.id, e)).run();
|
|
8307
8397
|
try {
|
|
8308
|
-
|
|
8398
|
+
du(this.db, {
|
|
8309
8399
|
memoryId: e,
|
|
8310
8400
|
opType: "upsert",
|
|
8311
8401
|
deviceId: this.deviceId
|
|
@@ -8317,19 +8407,19 @@ var Gu = class {
|
|
|
8317
8407
|
}).immediate();
|
|
8318
8408
|
}
|
|
8319
8409
|
search(e, t = 10, n) {
|
|
8320
|
-
return
|
|
8410
|
+
return Gc(this, e, t, n);
|
|
8321
8411
|
}
|
|
8322
8412
|
timeline(e, t, n = 3, r = 3, i) {
|
|
8323
|
-
return
|
|
8413
|
+
return qc(this, e, t, n, r, i);
|
|
8324
8414
|
}
|
|
8325
8415
|
explain(e, t, n = 10, r, i) {
|
|
8326
|
-
return
|
|
8416
|
+
return $c(this, e, t, n, r, i);
|
|
8327
8417
|
}
|
|
8328
8418
|
buildMemoryPack(e, t, n, r) {
|
|
8329
|
-
return
|
|
8419
|
+
return Pl(this, e, t, n ?? null, r);
|
|
8330
8420
|
}
|
|
8331
8421
|
async buildMemoryPackAsync(e, t, n, r) {
|
|
8332
|
-
return
|
|
8422
|
+
return Fl(this, e, t, n ?? null, r);
|
|
8333
8423
|
}
|
|
8334
8424
|
normalizeStreamIdentity(e, t) {
|
|
8335
8425
|
let n = e.trim().toLowerCase() || "opencode", r = t.trim();
|
|
@@ -8513,7 +8603,7 @@ var Gu = class {
|
|
|
8513
8603
|
}).run();
|
|
8514
8604
|
}
|
|
8515
8605
|
updateRawEventIngestStats(e, t, n, r) {
|
|
8516
|
-
let i =
|
|
8606
|
+
let i = Wu(), a = t + n + r;
|
|
8517
8607
|
this.d.insert(un).values({
|
|
8518
8608
|
created_at: i,
|
|
8519
8609
|
inserted_events: e,
|
|
@@ -8546,7 +8636,7 @@ var Gu = class {
|
|
|
8546
8636
|
if (!e.eventType.trim()) throw Error("event_type is required");
|
|
8547
8637
|
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId);
|
|
8548
8638
|
return this.db.transaction(() => {
|
|
8549
|
-
let r =
|
|
8639
|
+
let r = Wu();
|
|
8550
8640
|
if (this.d.select({ one: M`1` }).from(G).where(D(k(G.source, t), k(G.stream_id, n), k(G.event_id, e.eventId))).get() != null) return this.updateRawEventIngestStats(0, 0, 1, 0), !1;
|
|
8551
8641
|
this.d.select({ one: M`1` }).from(K).where(D(k(K.source, t), k(K.stream_id, n))).get() ?? this.d.insert(K).values({
|
|
8552
8642
|
opencode_session_id: n,
|
|
@@ -8578,7 +8668,7 @@ var Gu = class {
|
|
|
8578
8668
|
if (!e.trim()) throw Error("opencode_session_id is required");
|
|
8579
8669
|
let [n, r] = this.normalizeStreamIdentity("opencode", e);
|
|
8580
8670
|
return this.db.transaction(() => {
|
|
8581
|
-
let e =
|
|
8671
|
+
let e = Wu();
|
|
8582
8672
|
this.d.select({ one: M`1` }).from(K).where(D(k(K.source, n), k(K.stream_id, r))).get() ?? this.d.insert(K).values({
|
|
8583
8673
|
opencode_session_id: r,
|
|
8584
8674
|
source: n,
|
|
@@ -8647,7 +8737,7 @@ var Gu = class {
|
|
|
8647
8737
|
})();
|
|
8648
8738
|
}
|
|
8649
8739
|
updateRawEventSessionMeta(e) {
|
|
8650
|
-
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r =
|
|
8740
|
+
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r = Wu(), i = K;
|
|
8651
8741
|
this.d.insert(i).values({
|
|
8652
8742
|
opencode_session_id: n,
|
|
8653
8743
|
source: t,
|
|
@@ -8747,8 +8837,8 @@ var Gu = class {
|
|
|
8747
8837
|
${W.actor_id} IS NULL
|
|
8748
8838
|
OR TRIM(${W.actor_id}) = ''
|
|
8749
8839
|
OR ${W.actor_id} LIKE 'legacy-sync:%'
|
|
8750
|
-
OR ${W.actor_display_name} = ${
|
|
8751
|
-
OR ${W.workspace_id} = ${
|
|
8840
|
+
OR ${W.actor_display_name} = ${Xu}
|
|
8841
|
+
OR ${W.workspace_id} = ${Zu}
|
|
8752
8842
|
OR ${W.trust_state} = 'legacy_unknown'
|
|
8753
8843
|
)
|
|
8754
8844
|
)`, M`${W.origin_device_id} != ${this.deviceId}`, M`${W.origin_device_id} NOT IN (
|
|
@@ -8762,13 +8852,13 @@ var Gu = class {
|
|
|
8762
8852
|
}));
|
|
8763
8853
|
}
|
|
8764
8854
|
effectiveSyncProjectFilters(e) {
|
|
8765
|
-
let t = tt(), n =
|
|
8855
|
+
let t = tt(), n = Ju(JSON.stringify(t.sync_projects_include ?? [])), r = Ju(JSON.stringify(t.sync_projects_exclude ?? []));
|
|
8766
8856
|
if (e) {
|
|
8767
8857
|
let t = this.d.select({
|
|
8768
8858
|
projects_include_json: Y.projects_include_json,
|
|
8769
8859
|
projects_exclude_json: Y.projects_exclude_json
|
|
8770
8860
|
}).from(Y).where(k(Y.peer_device_id, e)).limit(1).get();
|
|
8771
|
-
t && (t.projects_include_json != null && (n =
|
|
8861
|
+
t && (t.projects_include_json != null && (n = Ju(t.projects_include_json)), t.projects_exclude_json != null && (r = Ju(t.projects_exclude_json)));
|
|
8772
8862
|
}
|
|
8773
8863
|
return {
|
|
8774
8864
|
include: n,
|
|
@@ -8776,7 +8866,7 @@ var Gu = class {
|
|
|
8776
8866
|
};
|
|
8777
8867
|
}
|
|
8778
8868
|
syncProjectAllowed(e, t) {
|
|
8779
|
-
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a =
|
|
8869
|
+
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a = Yu(i);
|
|
8780
8870
|
return !(n.length > 0 && !n.some((e) => e === i || e === a) || r.some((e) => e === i || e === a));
|
|
8781
8871
|
}
|
|
8782
8872
|
sharingReviewSummary(e) {
|
|
@@ -8796,7 +8886,7 @@ var Gu = class {
|
|
|
8796
8886
|
if (!n || !r || r === this.actorId) continue;
|
|
8797
8887
|
let i = $(e.project);
|
|
8798
8888
|
if (t) {
|
|
8799
|
-
let e =
|
|
8889
|
+
let e = Yu(t), n = Yu(i);
|
|
8800
8890
|
if (i !== t && n !== e) continue;
|
|
8801
8891
|
}
|
|
8802
8892
|
if (!this.syncProjectAllowed(i, n)) continue;
|
|
@@ -8820,11 +8910,11 @@ var Gu = class {
|
|
|
8820
8910
|
close() {
|
|
8821
8911
|
this.db.pragma("optimize"), this.db.close();
|
|
8822
8912
|
}
|
|
8823
|
-
},
|
|
8824
|
-
function
|
|
8913
|
+
}, ed = "_codemem._tcp.local.";
|
|
8914
|
+
function td(e) {
|
|
8825
8915
|
return e.mdns.length === 0 ? Ii(e.stored, []) : Ii(e.mdns, e.stored);
|
|
8826
8916
|
}
|
|
8827
|
-
function
|
|
8917
|
+
function nd(e, t) {
|
|
8828
8918
|
let n = N(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get();
|
|
8829
8919
|
if (!n?.addresses_json) return [];
|
|
8830
8920
|
try {
|
|
@@ -8834,8 +8924,8 @@ function Ju(e, t) {
|
|
|
8834
8924
|
return [];
|
|
8835
8925
|
}
|
|
8836
8926
|
}
|
|
8837
|
-
function
|
|
8838
|
-
let i = Ii(
|
|
8927
|
+
function rd(e, t, n, r) {
|
|
8928
|
+
let i = Ii(nd(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
|
|
8839
8929
|
return N(e, { schema: H }).insert(Y).values({
|
|
8840
8930
|
peer_device_id: t,
|
|
8841
8931
|
name: r?.name ?? null,
|
|
@@ -8855,7 +8945,7 @@ function Yu(e, t, n, r) {
|
|
|
8855
8945
|
}
|
|
8856
8946
|
}).run(), i;
|
|
8857
8947
|
}
|
|
8858
|
-
function
|
|
8948
|
+
function id(e, t, n) {
|
|
8859
8949
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8860
8950
|
r.insert(Z).values({
|
|
8861
8951
|
peer_device_id: t,
|
|
@@ -8870,32 +8960,32 @@ function Xu(e, t, n) {
|
|
|
8870
8960
|
last_error: null
|
|
8871
8961
|
}).where(k(Y.peer_device_id, t)).run() : r.update(Y).set({ last_error: n.error ?? null }).where(k(Y.peer_device_id, t)).run();
|
|
8872
8962
|
}
|
|
8873
|
-
function
|
|
8874
|
-
let r =
|
|
8963
|
+
function ad(e, t, n) {
|
|
8964
|
+
let r = nd(e, t), i = Pi(n ?? ""), a = r;
|
|
8875
8965
|
return i && (a = [i, ...r.filter((e) => Pi(e) !== i)], N(e, { schema: H }).update(Y).set({
|
|
8876
8966
|
addresses_json: JSON.stringify(a),
|
|
8877
8967
|
last_sync_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8878
8968
|
last_error: null
|
|
8879
8969
|
}).where(k(Y.peer_device_id, t)).run()), a;
|
|
8880
8970
|
}
|
|
8881
|
-
function
|
|
8971
|
+
function od(e, t, n) {
|
|
8882
8972
|
let r = n.include === null ? null : JSON.stringify(n.include), i = n.exclude === null ? null : JSON.stringify(n.exclude);
|
|
8883
8973
|
N(e, { schema: H }).update(Y).set({
|
|
8884
8974
|
projects_include_json: r,
|
|
8885
8975
|
projects_exclude_json: i
|
|
8886
8976
|
}).where(k(Y.peer_device_id, t)).run();
|
|
8887
8977
|
}
|
|
8888
|
-
function
|
|
8978
|
+
function sd(e, t, n) {
|
|
8889
8979
|
N(e, { schema: H }).update(Y).set({ claimed_local_actor: n ? 1 : 0 }).where(k(Y.peer_device_id, t)).run();
|
|
8890
8980
|
}
|
|
8891
|
-
function
|
|
8981
|
+
function cd(e) {
|
|
8892
8982
|
try {
|
|
8893
8983
|
return fe("which", [e], { stdio: "pipe" }), !0;
|
|
8894
8984
|
} catch {
|
|
8895
8985
|
return !1;
|
|
8896
8986
|
}
|
|
8897
8987
|
}
|
|
8898
|
-
function
|
|
8988
|
+
function ld(e, t = 1200) {
|
|
8899
8989
|
try {
|
|
8900
8990
|
return fe("dns-sd", e, {
|
|
8901
8991
|
encoding: "utf8",
|
|
@@ -8914,8 +9004,8 @@ function td(e, t = 1200) {
|
|
|
8914
9004
|
return "";
|
|
8915
9005
|
}
|
|
8916
9006
|
}
|
|
8917
|
-
function
|
|
8918
|
-
let e =
|
|
9007
|
+
function ud() {
|
|
9008
|
+
let e = ld([
|
|
8919
9009
|
"-B",
|
|
8920
9010
|
"_codemem._tcp",
|
|
8921
9011
|
"local."
|
|
@@ -8934,8 +9024,8 @@ function nd() {
|
|
|
8934
9024
|
}
|
|
8935
9025
|
return [...t];
|
|
8936
9026
|
}
|
|
8937
|
-
function
|
|
8938
|
-
let t =
|
|
9027
|
+
function dd(e) {
|
|
9028
|
+
let t = ld([
|
|
8939
9029
|
"-L",
|
|
8940
9030
|
e,
|
|
8941
9031
|
"_codemem._tcp",
|
|
@@ -8952,12 +9042,12 @@ function rd(e) {
|
|
|
8952
9042
|
properties: s
|
|
8953
9043
|
};
|
|
8954
9044
|
}
|
|
8955
|
-
function
|
|
9045
|
+
function fd() {
|
|
8956
9046
|
let e = process.env.CODEMEM_SYNC_MDNS;
|
|
8957
9047
|
return e ? e === "1" || e.toLowerCase() === "true" : !1;
|
|
8958
9048
|
}
|
|
8959
|
-
function
|
|
8960
|
-
if (!
|
|
9049
|
+
function pd(e, t) {
|
|
9050
|
+
if (!fd() || process.platform !== "darwin" || !cd("dns-sd")) return { close() {} };
|
|
8961
9051
|
let n = pe("dns-sd", [
|
|
8962
9052
|
"-R",
|
|
8963
9053
|
`codemem-${e.slice(0, 12)}`,
|
|
@@ -8975,18 +9065,18 @@ function ad(e, t) {
|
|
|
8975
9065
|
} catch {}
|
|
8976
9066
|
} };
|
|
8977
9067
|
}
|
|
8978
|
-
function
|
|
8979
|
-
if (!
|
|
8980
|
-
let e =
|
|
9068
|
+
function md() {
|
|
9069
|
+
if (!fd() || process.platform !== "darwin" || !cd("dns-sd")) return [];
|
|
9070
|
+
let e = ud();
|
|
8981
9071
|
if (e.length === 0) return [];
|
|
8982
9072
|
let t = [];
|
|
8983
9073
|
for (let n of e) {
|
|
8984
|
-
let e =
|
|
9074
|
+
let e = dd(n);
|
|
8985
9075
|
e && t.push(e);
|
|
8986
9076
|
}
|
|
8987
9077
|
return t;
|
|
8988
9078
|
}
|
|
8989
|
-
function
|
|
9079
|
+
function hd(e, t) {
|
|
8990
9080
|
let n = [];
|
|
8991
9081
|
for (let r of t) {
|
|
8992
9082
|
let t = r.properties ?? {}, i = t.device_id ?? t.device_id;
|
|
@@ -9000,40 +9090,40 @@ function sd(e, t) {
|
|
|
9000
9090
|
}
|
|
9001
9091
|
//#endregion
|
|
9002
9092
|
//#region src/sync-pass.ts
|
|
9003
|
-
var
|
|
9004
|
-
function
|
|
9093
|
+
var gd = 1048576, _d = 200, vd = "2";
|
|
9094
|
+
function yd(e, t) {
|
|
9005
9095
|
return !t || !t.includes("|") ? !1 : e ? t > e : !0;
|
|
9006
9096
|
}
|
|
9007
|
-
function
|
|
9097
|
+
function bd(e) {
|
|
9008
9098
|
if (!e) return null;
|
|
9009
9099
|
let t = e.error, n = e.reason;
|
|
9010
9100
|
return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
|
|
9011
9101
|
}
|
|
9012
|
-
function
|
|
9102
|
+
function xd(e) {
|
|
9013
9103
|
return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
|
|
9014
9104
|
}
|
|
9015
|
-
function
|
|
9105
|
+
function Sd(e) {
|
|
9016
9106
|
if (typeof e != "string") return null;
|
|
9017
9107
|
let t = e.trim();
|
|
9018
9108
|
return t.length > 0 ? t : null;
|
|
9019
9109
|
}
|
|
9020
|
-
function
|
|
9110
|
+
function Cd(e) {
|
|
9021
9111
|
let t = e?.sync_reset;
|
|
9022
9112
|
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
9023
9113
|
let n = t;
|
|
9024
9114
|
if (!Number.isFinite(n.generation) || typeof n.snapshot_id != "string" || n.snapshot_id.trim().length === 0) return null;
|
|
9025
|
-
let r =
|
|
9115
|
+
let r = Sd(n.baseline_cursor);
|
|
9026
9116
|
return {
|
|
9027
9117
|
generation: Number(n.generation),
|
|
9028
9118
|
snapshot_id: n.snapshot_id.trim(),
|
|
9029
9119
|
baseline_cursor: r,
|
|
9030
|
-
retained_floor_cursor:
|
|
9120
|
+
retained_floor_cursor: Sd(n.retained_floor_cursor)
|
|
9031
9121
|
};
|
|
9032
9122
|
}
|
|
9033
|
-
function
|
|
9123
|
+
function wd(e) {
|
|
9034
9124
|
return !(!e || e.reset_required !== !1 || !Number.isFinite(e.generation) || typeof e.snapshot_id != "string" || e.snapshot_id.trim().length === 0 || !(e.baseline_cursor == null || typeof e.baseline_cursor == "string") || !(e.retained_floor_cursor == null || typeof e.retained_floor_cursor == "string") || !Array.isArray(e.ops) || !(e.next_cursor == null || typeof e.next_cursor == "string") || !Number.isFinite(e.skipped));
|
|
9035
9125
|
}
|
|
9036
|
-
function
|
|
9126
|
+
function Td(e, t, n) {
|
|
9037
9127
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
9038
9128
|
r.insert(Z).values({
|
|
9039
9129
|
peer_device_id: t,
|
|
@@ -9045,7 +9135,7 @@ function _d(e, t, n) {
|
|
|
9045
9135
|
error: n.error ?? null
|
|
9046
9136
|
}).run();
|
|
9047
9137
|
}
|
|
9048
|
-
function
|
|
9138
|
+
function Ed(e, t) {
|
|
9049
9139
|
let n = N(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
9050
9140
|
n.update(Y).set({
|
|
9051
9141
|
last_sync_at: r,
|
|
@@ -9053,7 +9143,7 @@ function vd(e, t) {
|
|
|
9053
9143
|
last_error: null
|
|
9054
9144
|
}).where(k(Y.peer_device_id, t)).run();
|
|
9055
9145
|
}
|
|
9056
|
-
function
|
|
9146
|
+
function Dd(e, t, n, r) {
|
|
9057
9147
|
let i = N(e, { schema: H }), { replicationOps: a } = H, o;
|
|
9058
9148
|
if (t) {
|
|
9059
9149
|
let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
|
|
@@ -9065,8 +9155,8 @@ function yd(e, t, n, r) {
|
|
|
9065
9155
|
let c = `${s.created_at}|${s.op_id}`;
|
|
9066
9156
|
return [o, c];
|
|
9067
9157
|
}
|
|
9068
|
-
var
|
|
9069
|
-
async function
|
|
9158
|
+
var Od = 8;
|
|
9159
|
+
async function kd(e, t, n, r, i = 0) {
|
|
9070
9160
|
if (n.length === 0) return;
|
|
9071
9161
|
let a = { ops: n }, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await jn("POST", e, {
|
|
9072
9162
|
headers: xi({
|
|
@@ -9080,20 +9170,20 @@ async function xd(e, t, n, r, i = 0) {
|
|
|
9080
9170
|
bodyBytes: o
|
|
9081
9171
|
});
|
|
9082
9172
|
if (s === 200 && c != null) return;
|
|
9083
|
-
let l =
|
|
9084
|
-
if (s === 413 && n.length > 1 && i <
|
|
9173
|
+
let l = bd(c);
|
|
9174
|
+
if (s === 413 && n.length > 1 && i < Od && (l === "payload_too_large" || l === "too_many_ops")) {
|
|
9085
9175
|
let a = Math.floor(n.length / 2);
|
|
9086
|
-
await
|
|
9176
|
+
await kd(e, t, n.slice(0, a), r, i + 1), await kd(e, t, n.slice(a), r, i + 1);
|
|
9087
9177
|
return;
|
|
9088
9178
|
}
|
|
9089
9179
|
let u = l ? ` (${s}: ${l})` : ` (${s})`;
|
|
9090
9180
|
throw Error(`peer ops push failed${u}`);
|
|
9091
9181
|
}
|
|
9092
|
-
function
|
|
9093
|
-
|
|
9182
|
+
function Ad(e) {
|
|
9183
|
+
Fu(e, 2e3), Iu(e, 200);
|
|
9094
9184
|
}
|
|
9095
|
-
async function
|
|
9096
|
-
let i = r?.limit ??
|
|
9185
|
+
async function jd(e, t, n, r) {
|
|
9186
|
+
let i = r?.limit ?? _d, a = r?.keysDir, o = N(e, { schema: H }).select({ pinned_fingerprint: Y.pinned_fingerprint }).from(Y).where(k(Y.peer_device_id, t)).get()?.pinned_fingerprint ?? "";
|
|
9097
9187
|
if (!o) return {
|
|
9098
9188
|
ok: !1,
|
|
9099
9189
|
error: "peer not pinned",
|
|
@@ -9101,12 +9191,12 @@ async function Cd(e, t, n, r) {
|
|
|
9101
9191
|
opsOut: 0,
|
|
9102
9192
|
addressErrors: []
|
|
9103
9193
|
};
|
|
9104
|
-
let [s, c] =
|
|
9194
|
+
let [s, c] = au(e, t), l;
|
|
9105
9195
|
try {
|
|
9106
9196
|
[l] = Qn(e, { keysDir: a });
|
|
9107
9197
|
} catch (n) {
|
|
9108
9198
|
let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
|
|
9109
|
-
return
|
|
9199
|
+
return Td(e, t, {
|
|
9110
9200
|
ok: !1,
|
|
9111
9201
|
error: r
|
|
9112
9202
|
}), {
|
|
@@ -9131,12 +9221,12 @@ async function Cd(e, t, n, r) {
|
|
|
9131
9221
|
keysDir: a
|
|
9132
9222
|
}) });
|
|
9133
9223
|
if (u !== 200 || !d) {
|
|
9134
|
-
let e =
|
|
9224
|
+
let e = bd(d), t = e ? ` (${u}: ${e})` : ` (${u})`;
|
|
9135
9225
|
throw Error(`peer status failed${t}`);
|
|
9136
9226
|
}
|
|
9137
9227
|
if (d.fingerprint !== o) throw Error("peer fingerprint mismatch");
|
|
9138
|
-
if (String(d.protocol_version ?? "") !==
|
|
9139
|
-
let f =
|
|
9228
|
+
if (String(d.protocol_version ?? "") !== vd) throw Error(`peer protocol mismatch (expected ${vd}, got ${String(d.protocol_version ?? "missing")})`);
|
|
9229
|
+
let f = Cd(d);
|
|
9140
9230
|
if (!f) throw Error("peer status missing sync_reset boundary");
|
|
9141
9231
|
let p = new URLSearchParams({
|
|
9142
9232
|
since: s ?? "",
|
|
@@ -9153,7 +9243,7 @@ async function Cd(e, t, n, r) {
|
|
|
9153
9243
|
keysDir: a
|
|
9154
9244
|
}) });
|
|
9155
9245
|
if (h === 409 && g?.reset_required === !0) {
|
|
9156
|
-
let r =
|
|
9246
|
+
let r = _u(e), i = {
|
|
9157
9247
|
reset_required: !0,
|
|
9158
9248
|
reason: g.reason === "generation_mismatch" || g.reason === "boundary_mismatch" ? g.reason : "stale_cursor",
|
|
9159
9249
|
generation: Number(g.generation ?? 1),
|
|
@@ -9161,7 +9251,7 @@ async function Cd(e, t, n, r) {
|
|
|
9161
9251
|
baseline_cursor: typeof g.baseline_cursor == "string" && g.baseline_cursor.trim() ? g.baseline_cursor.trim() : null,
|
|
9162
9252
|
retained_floor_cursor: typeof g.retained_floor_cursor == "string" && g.retained_floor_cursor.trim() ? g.retained_floor_cursor.trim() : null
|
|
9163
9253
|
};
|
|
9164
|
-
return
|
|
9254
|
+
return Td(e, t, {
|
|
9165
9255
|
ok: !1,
|
|
9166
9256
|
error: r.dirty ? `needs_attention:local_unsynced_shared_memory:${r.count}` : `reset_required:${i.reason}`
|
|
9167
9257
|
}), {
|
|
@@ -9175,19 +9265,19 @@ async function Cd(e, t, n, r) {
|
|
|
9175
9265
|
};
|
|
9176
9266
|
}
|
|
9177
9267
|
if (h !== 200 || g == null) {
|
|
9178
|
-
let e =
|
|
9268
|
+
let e = bd(g), t = e ? ` (${h}: ${e})` : ` (${h})`;
|
|
9179
9269
|
throw Error(`peer ops fetch failed${t}`);
|
|
9180
9270
|
}
|
|
9181
|
-
if (!
|
|
9182
|
-
let [_, v] =
|
|
9183
|
-
|
|
9184
|
-
let [x, S] =
|
|
9271
|
+
if (!wd(g)) throw Error("invalid ops response");
|
|
9272
|
+
let [_, v] = Mu(e, cu(g), t), y = zu(e, _, l), b = v || Sd(g.next_cursor);
|
|
9273
|
+
yd(s, b) && (ou(e, t, { lastApplied: b }), s = b);
|
|
9274
|
+
let [x, S] = Dd(e, c, l, i), [C, w] = Nu(e, x, t), T = `${n}/v1/ops`;
|
|
9185
9275
|
if (C.length > 0) {
|
|
9186
|
-
let e =
|
|
9187
|
-
for (let t of e) await
|
|
9276
|
+
let e = iu(C, gd);
|
|
9277
|
+
for (let t of e) await kd(T, l, t, a);
|
|
9188
9278
|
}
|
|
9189
9279
|
let E = w ?? S;
|
|
9190
|
-
return E &&
|
|
9280
|
+
return E && yd(c, E) && (ou(e, t, { lastAcked: E }), c = E), Ed(e, t), Td(e, t, {
|
|
9191
9281
|
ok: !0,
|
|
9192
9282
|
opsIn: y.applied,
|
|
9193
9283
|
opsOut: C.length
|
|
@@ -9207,8 +9297,8 @@ async function Cd(e, t, n, r) {
|
|
|
9207
9297
|
}
|
|
9208
9298
|
}
|
|
9209
9299
|
}
|
|
9210
|
-
let f =
|
|
9211
|
-
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail",
|
|
9300
|
+
let f = xd(u);
|
|
9301
|
+
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail", Td(e, t, {
|
|
9212
9302
|
ok: !1,
|
|
9213
9303
|
error: f
|
|
9214
9304
|
}), {
|
|
@@ -9219,15 +9309,15 @@ async function Cd(e, t, n, r) {
|
|
|
9219
9309
|
addressErrors: u
|
|
9220
9310
|
};
|
|
9221
9311
|
}
|
|
9222
|
-
async function
|
|
9312
|
+
async function Md(e, t, n) {
|
|
9223
9313
|
let r = N(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get(), i = [];
|
|
9224
9314
|
if (r?.addresses_json) try {
|
|
9225
9315
|
let e = JSON.parse(r.addresses_json);
|
|
9226
9316
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
9227
9317
|
} catch {}
|
|
9228
|
-
return
|
|
9318
|
+
return jd(e, t, i, n);
|
|
9229
9319
|
}
|
|
9230
|
-
var
|
|
9320
|
+
var Nd = [
|
|
9231
9321
|
"no route to host",
|
|
9232
9322
|
"connection refused",
|
|
9233
9323
|
"network is unreachable",
|
|
@@ -9238,33 +9328,33 @@ var Td = [
|
|
|
9238
9328
|
"errno 61",
|
|
9239
9329
|
"errno 60",
|
|
9240
9330
|
"errno 111"
|
|
9241
|
-
],
|
|
9242
|
-
function
|
|
9331
|
+
], Pd = 120, Fd = 1800;
|
|
9332
|
+
function Id(e) {
|
|
9243
9333
|
if (!e) return !1;
|
|
9244
9334
|
let t = e.toLowerCase();
|
|
9245
|
-
return
|
|
9335
|
+
return Nd.some((e) => t.includes(e));
|
|
9246
9336
|
}
|
|
9247
|
-
function
|
|
9337
|
+
function Ld(e, t, n = 10) {
|
|
9248
9338
|
let r = N(e, { schema: H }).select({
|
|
9249
9339
|
ok: Z.ok,
|
|
9250
9340
|
error: Z.error
|
|
9251
9341
|
}).from(Z).where(k(Z.peer_device_id, t)).orderBy(O(Z.started_at)).limit(n).all(), i = 0;
|
|
9252
9342
|
for (let e of r) {
|
|
9253
9343
|
if (e.ok) break;
|
|
9254
|
-
if (
|
|
9344
|
+
if (Id(e.error)) i++;
|
|
9255
9345
|
else break;
|
|
9256
9346
|
}
|
|
9257
9347
|
return i;
|
|
9258
9348
|
}
|
|
9259
|
-
function
|
|
9349
|
+
function Rd(e) {
|
|
9260
9350
|
if (e <= 1) return 0;
|
|
9261
9351
|
let t = Math.min(e - 1, 8);
|
|
9262
|
-
return Math.min(
|
|
9352
|
+
return Math.min(Pd * 2 ** (t - 1), Fd) * (.5 + Math.random() * .5);
|
|
9263
9353
|
}
|
|
9264
|
-
function
|
|
9265
|
-
let n =
|
|
9354
|
+
function zd(e, t) {
|
|
9355
|
+
let n = Ld(e, t);
|
|
9266
9356
|
if (n < 2) return !1;
|
|
9267
|
-
let r =
|
|
9357
|
+
let r = Rd(n);
|
|
9268
9358
|
if (r <= 0) return !1;
|
|
9269
9359
|
let i = N(e, { schema: H }).select({ started_at: Z.started_at }).from(Z).where(k(Z.peer_device_id, t)).orderBy(O(Z.started_at)).limit(1).get();
|
|
9270
9360
|
if (!i?.started_at) return !1;
|
|
@@ -9277,7 +9367,7 @@ function jd(e, t) {
|
|
|
9277
9367
|
}
|
|
9278
9368
|
//#endregion
|
|
9279
9369
|
//#region src/sync-daemon.ts
|
|
9280
|
-
function
|
|
9370
|
+
function Bd(e) {
|
|
9281
9371
|
let t = N(e, { schema: H }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
9282
9372
|
t.insert(sn).values({
|
|
9283
9373
|
id: 1,
|
|
@@ -9287,7 +9377,7 @@ function Md(e) {
|
|
|
9287
9377
|
set: { last_ok_at: M`excluded.last_ok_at` }
|
|
9288
9378
|
}).run();
|
|
9289
9379
|
}
|
|
9290
|
-
function
|
|
9380
|
+
function Vd(e, t, n) {
|
|
9291
9381
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
9292
9382
|
r.insert(sn).values({
|
|
9293
9383
|
id: 1,
|
|
@@ -9303,14 +9393,14 @@ function Nd(e, t, n) {
|
|
|
9303
9393
|
}
|
|
9304
9394
|
}).run();
|
|
9305
9395
|
}
|
|
9306
|
-
async function
|
|
9396
|
+
async function Hd(e, t) {
|
|
9307
9397
|
let n = N(e, { schema: H }).select({ peer_device_id: Y.peer_device_id }).from(Y).all();
|
|
9308
9398
|
if (n.length === 0) return [];
|
|
9309
|
-
|
|
9399
|
+
Ad(e);
|
|
9310
9400
|
let r = [];
|
|
9311
9401
|
for (let i of n) {
|
|
9312
9402
|
let n = i.peer_device_id;
|
|
9313
|
-
if (
|
|
9403
|
+
if (zd(e, n)) {
|
|
9314
9404
|
r.push({
|
|
9315
9405
|
ok: !1,
|
|
9316
9406
|
skipped: !0,
|
|
@@ -9318,7 +9408,7 @@ async function Pd(e, t) {
|
|
|
9318
9408
|
});
|
|
9319
9409
|
continue;
|
|
9320
9410
|
}
|
|
9321
|
-
let a = await
|
|
9411
|
+
let a = await Md(e, n, { keysDir: t });
|
|
9322
9412
|
r.push({
|
|
9323
9413
|
ok: a.ok,
|
|
9324
9414
|
error: a.error,
|
|
@@ -9328,13 +9418,13 @@ async function Pd(e, t) {
|
|
|
9328
9418
|
}
|
|
9329
9419
|
return r;
|
|
9330
9420
|
}
|
|
9331
|
-
async function
|
|
9421
|
+
async function Ud(e) {
|
|
9332
9422
|
let t = e?.intervalS ?? 120, n = Ot(e?.dbPath), r = e?.keysDir, i = e?.signal, a = e?.onPhaseChange;
|
|
9333
9423
|
a?.("starting");
|
|
9334
9424
|
let o = Nt(n), s = null;
|
|
9335
9425
|
try {
|
|
9336
9426
|
let [t] = Qn(o, { keysDir: r });
|
|
9337
|
-
|
|
9427
|
+
fd() && e?.port && (s = pd(t, e.port));
|
|
9338
9428
|
} finally {
|
|
9339
9429
|
o.close();
|
|
9340
9430
|
}
|
|
@@ -9344,7 +9434,7 @@ async function Fd(e) {
|
|
|
9344
9434
|
}
|
|
9345
9435
|
return new Promise((e) => {
|
|
9346
9436
|
let o = !1, c = !1, l = () => {
|
|
9347
|
-
o || (o = !0,
|
|
9437
|
+
o || (o = !0, Wd(n, r).finally(() => {
|
|
9348
9438
|
o = !1, c || (c = !0, a?.("running"));
|
|
9349
9439
|
}));
|
|
9350
9440
|
}, u = setInterval(l, t * 1e3);
|
|
@@ -9361,19 +9451,81 @@ async function Fd(e) {
|
|
|
9361
9451
|
}
|
|
9362
9452
|
});
|
|
9363
9453
|
}
|
|
9364
|
-
async function
|
|
9454
|
+
async function Wd(e, t) {
|
|
9365
9455
|
let n = Nt(e);
|
|
9366
9456
|
try {
|
|
9367
|
-
await
|
|
9457
|
+
await Hd(n, t), Bd(n);
|
|
9368
9458
|
} catch (e) {
|
|
9369
|
-
|
|
9459
|
+
Vd(n, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
9370
9460
|
} finally {
|
|
9371
9461
|
n.close();
|
|
9372
9462
|
}
|
|
9373
9463
|
}
|
|
9374
9464
|
//#endregion
|
|
9375
9465
|
//#region src/sync-retention-runner.ts
|
|
9376
|
-
|
|
9466
|
+
async function Gd(e, t) {
|
|
9467
|
+
if (!t.syncRetentionEnabled) return;
|
|
9468
|
+
e.exec("\n CREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n )\n ");
|
|
9469
|
+
let n = N(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
9470
|
+
try {
|
|
9471
|
+
let i = e.prepare("SELECT COALESCE(SUM(pgsize), 0) AS total_bytes\n FROM dbstat\n WHERE name = 'replication_ops'\n OR name LIKE 'idx_replication_ops_%'\n OR name LIKE 'sqlite_autoindex_replication_ops_%'").get(), a = yu(e, {
|
|
9472
|
+
maxAgeDays: t.syncRetentionMaxAgeDays,
|
|
9473
|
+
maxSizeBytes: t.syncRetentionMaxSizeMb * 1024 * 1024,
|
|
9474
|
+
maxDeleteOps: t.syncRetentionMaxOpsPerPass,
|
|
9475
|
+
maxRuntimeMs: t.syncRetentionMaxRuntimeMs,
|
|
9476
|
+
maxPasses: t.maxCatchUpPasses,
|
|
9477
|
+
signal: t.signal
|
|
9478
|
+
});
|
|
9479
|
+
n.insert(ln).values({
|
|
9480
|
+
id: 1,
|
|
9481
|
+
last_run_at: r,
|
|
9482
|
+
last_duration_ms: Date.now() - Date.parse(r),
|
|
9483
|
+
last_deleted_ops: a.totalDeleted,
|
|
9484
|
+
last_estimated_bytes_before: i?.total_bytes ?? null,
|
|
9485
|
+
last_estimated_bytes_after: a.afterBytes,
|
|
9486
|
+
retained_floor_cursor: a.lastFloor,
|
|
9487
|
+
last_error: null,
|
|
9488
|
+
last_error_at: null
|
|
9489
|
+
}).onConflictDoUpdate({
|
|
9490
|
+
target: ln.id,
|
|
9491
|
+
set: {
|
|
9492
|
+
last_run_at: r,
|
|
9493
|
+
last_duration_ms: Date.now() - Date.parse(r),
|
|
9494
|
+
last_deleted_ops: a.totalDeleted,
|
|
9495
|
+
last_estimated_bytes_before: i?.total_bytes ?? null,
|
|
9496
|
+
last_estimated_bytes_after: a.afterBytes,
|
|
9497
|
+
retained_floor_cursor: a.lastFloor,
|
|
9498
|
+
last_error: null,
|
|
9499
|
+
last_error_at: null
|
|
9500
|
+
}
|
|
9501
|
+
}).run();
|
|
9502
|
+
} catch (e) {
|
|
9503
|
+
n.insert(ln).values({
|
|
9504
|
+
id: 1,
|
|
9505
|
+
last_run_at: r,
|
|
9506
|
+
last_duration_ms: Date.now() - Date.parse(r),
|
|
9507
|
+
last_deleted_ops: 0,
|
|
9508
|
+
last_estimated_bytes_before: null,
|
|
9509
|
+
last_estimated_bytes_after: null,
|
|
9510
|
+
retained_floor_cursor: null,
|
|
9511
|
+
last_error: e instanceof Error ? e.message : String(e),
|
|
9512
|
+
last_error_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
9513
|
+
}).onConflictDoUpdate({
|
|
9514
|
+
target: ln.id,
|
|
9515
|
+
set: {
|
|
9516
|
+
last_run_at: r,
|
|
9517
|
+
last_duration_ms: Date.now() - Date.parse(r),
|
|
9518
|
+
last_deleted_ops: 0,
|
|
9519
|
+
last_estimated_bytes_before: null,
|
|
9520
|
+
last_estimated_bytes_after: null,
|
|
9521
|
+
retained_floor_cursor: null,
|
|
9522
|
+
last_error: e instanceof Error ? e.message : String(e),
|
|
9523
|
+
last_error_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
9524
|
+
}
|
|
9525
|
+
}).run();
|
|
9526
|
+
}
|
|
9527
|
+
}
|
|
9528
|
+
var Kd = class {
|
|
9377
9529
|
dbPath;
|
|
9378
9530
|
signal;
|
|
9379
9531
|
active = !1;
|
|
@@ -9399,81 +9551,28 @@ var Ld = class {
|
|
|
9399
9551
|
}
|
|
9400
9552
|
async runOnce() {
|
|
9401
9553
|
if (!this.active || this.signal?.aborted) return;
|
|
9402
|
-
let e = Gi(tt());
|
|
9403
|
-
if (!e.syncRetentionEnabled) return;
|
|
9404
|
-
let t = Nt(this.dbPath);
|
|
9405
|
-
t.exec("\n CREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n )\n ");
|
|
9406
|
-
let n = N(t, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
9554
|
+
let e = Gi(tt()), t = Nt(this.dbPath);
|
|
9407
9555
|
try {
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
maxDeleteOps: e.syncRetentionMaxOpsPerPass,
|
|
9412
|
-
maxRuntimeMs: e.syncRetentionMaxRuntimeMs
|
|
9556
|
+
await Gd(t, {
|
|
9557
|
+
...e,
|
|
9558
|
+
signal: this.signal
|
|
9413
9559
|
});
|
|
9414
|
-
n.insert(ln).values({
|
|
9415
|
-
id: 1,
|
|
9416
|
-
last_run_at: r,
|
|
9417
|
-
last_duration_ms: Date.now() - Date.parse(r),
|
|
9418
|
-
last_deleted_ops: i.deleted,
|
|
9419
|
-
last_estimated_bytes_before: i.estimated_bytes_before ?? null,
|
|
9420
|
-
last_estimated_bytes_after: i.estimated_bytes_after ?? null,
|
|
9421
|
-
retained_floor_cursor: i.retained_floor_cursor,
|
|
9422
|
-
last_error: null,
|
|
9423
|
-
last_error_at: null
|
|
9424
|
-
}).onConflictDoUpdate({
|
|
9425
|
-
target: ln.id,
|
|
9426
|
-
set: {
|
|
9427
|
-
last_run_at: r,
|
|
9428
|
-
last_duration_ms: Date.now() - Date.parse(r),
|
|
9429
|
-
last_deleted_ops: i.deleted,
|
|
9430
|
-
last_estimated_bytes_before: i.estimated_bytes_before ?? null,
|
|
9431
|
-
last_estimated_bytes_after: i.estimated_bytes_after ?? null,
|
|
9432
|
-
retained_floor_cursor: i.retained_floor_cursor,
|
|
9433
|
-
last_error: null,
|
|
9434
|
-
last_error_at: null
|
|
9435
|
-
}
|
|
9436
|
-
}).run();
|
|
9437
|
-
} catch (e) {
|
|
9438
|
-
n.insert(ln).values({
|
|
9439
|
-
id: 1,
|
|
9440
|
-
last_run_at: r,
|
|
9441
|
-
last_duration_ms: Date.now() - Date.parse(r),
|
|
9442
|
-
last_deleted_ops: 0,
|
|
9443
|
-
last_estimated_bytes_before: null,
|
|
9444
|
-
last_estimated_bytes_after: null,
|
|
9445
|
-
retained_floor_cursor: null,
|
|
9446
|
-
last_error: e instanceof Error ? e.message : String(e),
|
|
9447
|
-
last_error_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
9448
|
-
}).onConflictDoUpdate({
|
|
9449
|
-
target: ln.id,
|
|
9450
|
-
set: {
|
|
9451
|
-
last_run_at: r,
|
|
9452
|
-
last_duration_ms: Date.now() - Date.parse(r),
|
|
9453
|
-
last_deleted_ops: 0,
|
|
9454
|
-
last_estimated_bytes_before: null,
|
|
9455
|
-
last_estimated_bytes_after: null,
|
|
9456
|
-
retained_floor_cursor: null,
|
|
9457
|
-
last_error: e instanceof Error ? e.message : String(e),
|
|
9458
|
-
last_error_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
9459
|
-
}
|
|
9460
|
-
}).run();
|
|
9461
9560
|
} finally {
|
|
9462
9561
|
t.close();
|
|
9463
9562
|
}
|
|
9464
9563
|
}
|
|
9465
|
-
}, Rd = "CREATE TABLE IF NOT EXISTS `sessions` (\n `id` integer PRIMARY KEY NOT NULL,\n `started_at` text NOT NULL,\n `ended_at` text,\n `cwd` text,\n `project` text,\n `git_remote` text,\n `git_branch` text,\n `user` text,\n `tool_version` text,\n `metadata_json` text,\n `import_key` text\n);\n\nCREATE TABLE IF NOT EXISTS `artifacts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `path` text,\n `content_text` text,\n `content_hash` text,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_artifacts_session_kind` ON `artifacts` (`session_id`,`kind`);\nCREATE TABLE IF NOT EXISTS `memory_items` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `title` text NOT NULL,\n `subtitle` text,\n `body_text` text NOT NULL,\n `confidence` real DEFAULT 0.5,\n `tags_text` text DEFAULT '',\n `active` integer DEFAULT 1,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL,\n `metadata_json` text,\n `actor_id` text,\n `actor_display_name` text,\n `visibility` text,\n `workspace_id` text,\n `workspace_kind` text,\n `origin_device_id` text,\n `origin_source` text,\n `trust_state` text,\n `facts` text,\n `narrative` text,\n `concepts` text,\n `files_read` text,\n `files_modified` text,\n `user_prompt_id` integer,\n `prompt_number` integer,\n `deleted_at` text,\n `rev` integer DEFAULT 0,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_items_active_created` ON `memory_items` (`active`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_session` ON `memory_items` (`session_id`);\nCREATE TABLE IF NOT EXISTS `usage_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `event` text NOT NULL,\n `tokens_read` integer DEFAULT 0,\n `tokens_written` integer DEFAULT 0,\n `tokens_saved` integer DEFAULT 0,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null\n);\n\nCREATE INDEX IF NOT EXISTS `idx_usage_events_event_created` ON `usage_events` (`event`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_usage_events_session` ON `usage_events` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `event_id` text,\n `event_seq` integer NOT NULL,\n `event_type` text NOT NULL,\n `ts_wall_ms` integer,\n `ts_mono_ms` real,\n `payload_json` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_seq` ON `raw_events` (`source`,`stream_id`,`event_seq`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_event_id` ON `raw_events` (`source`,`stream_id`,`event_id`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_session_seq` ON `raw_events` (`opencode_session_id`,`event_seq`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_created` ON `raw_events` (`created_at`);\nCREATE TABLE IF NOT EXISTS `raw_event_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `cwd` text,\n `project` text,\n `started_at` text,\n `last_seen_ts_wall_ms` integer,\n `last_received_event_seq` integer DEFAULT -1 NOT NULL,\n `last_flushed_event_seq` integer DEFAULT -1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `opencode_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `session_id` integer,\n `created_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`),\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_opencode_sessions_session` ON `opencode_sessions` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_event_flush_batches` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `start_event_seq` integer NOT NULL,\n `end_event_seq` integer NOT NULL,\n `extractor_version` text NOT NULL,\n `status` text NOT NULL,\n `error_message` text,\n `error_type` text,\n `observer_provider` text,\n `observer_model` text,\n `observer_runtime` text,\n `attempt_count` integer DEFAULT 0 NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_flush_batches_source_stream_seq_ver` ON `raw_event_flush_batches` (`source`,`stream_id`,`start_event_seq`,`end_event_seq`,`extractor_version`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_session_created` ON `raw_event_flush_batches` (`opencode_session_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_status_updated` ON `raw_event_flush_batches` (`status`,`updated_at`);\nCREATE TABLE IF NOT EXISTS `user_prompts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `prompt_text` text NOT NULL,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_session` ON `user_prompts` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_project` ON `user_prompts` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_epoch` ON `user_prompts` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `session_summaries` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `request` text,\n `investigated` text,\n `learned` text,\n `completed` text,\n `next_steps` text,\n `notes` text,\n `files_read` text,\n `files_edited` text,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_session` ON `session_summaries` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_project` ON `session_summaries` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_epoch` ON `session_summaries` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `replication_ops` (\n `op_id` text PRIMARY KEY NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `op_type` text NOT NULL,\n `payload_json` text,\n `clock_rev` integer NOT NULL,\n `clock_updated_at` text NOT NULL,\n `clock_device_id` text NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_created` ON `replication_ops` (`created_at`,`op_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_entity` ON `replication_ops` (`entity_type`,`entity_id`);\nCREATE TABLE IF NOT EXISTS `replication_cursors` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_peers` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `name` text,\n `pinned_fingerprint` text,\n `public_key` text,\n `addresses_json` text,\n `claimed_local_actor` integer DEFAULT 0 NOT NULL,\n `actor_id` text,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `created_at` text NOT NULL,\n `last_seen_at` text,\n `last_sync_at` text,\n `last_error` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_nonces` (\n `nonce` text PRIMARY KEY NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_device` (\n `device_id` text PRIMARY KEY NOT NULL,\n `public_key` text NOT NULL,\n `fingerprint` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_attempts` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text NOT NULL,\n `started_at` text NOT NULL,\n `finished_at` text,\n `ok` integer NOT NULL,\n `ops_in` integer NOT NULL,\n `ops_out` integer NOT NULL,\n `error` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_attempts_peer_started` ON `sync_attempts` (`peer_device_id`,`started_at`);\nCREATE TABLE IF NOT EXISTS `sync_daemon_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `last_error` text,\n `last_traceback` text,\n `last_error_at` text,\n `last_ok_at` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_reset_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `generation` integer NOT NULL,\n `snapshot_id` text NOT NULL,\n `baseline_cursor` text,\n `retained_floor_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_samples` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `created_at` text NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_stats` (\n `id` integer PRIMARY KEY NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `actors` (\n `actor_id` text PRIMARY KEY NOT NULL,\n `display_name` text NOT NULL,\n `is_local` integer DEFAULT 0 NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `merged_into_actor_id` text,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_actors_is_local` ON `actors` (`is_local`);\nCREATE INDEX IF NOT EXISTS `idx_actors_status` ON `actors` (`status`);", zd = "\nCREATE INDEX IF NOT EXISTS idx_sync_peers_actor_id ON sync_peers(actor_id);\n\nCREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n);\n\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(\n title, body_text, tags_text,\n content='memory_items',\n content_rowid='id'\n);\n\nCREATE TRIGGER IF NOT EXISTS memory_items_ai AFTER INSERT ON memory_items BEGIN\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_au;\nCREATE TRIGGER memory_items_au AFTER UPDATE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_ad;\nCREATE TRIGGER memory_items_ad AFTER DELETE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\nEND;\n";
|
|
9466
|
-
function
|
|
9467
|
-
e.exec(
|
|
9564
|
+
}, qd = "CREATE TABLE IF NOT EXISTS `sessions` (\n `id` integer PRIMARY KEY NOT NULL,\n `started_at` text NOT NULL,\n `ended_at` text,\n `cwd` text,\n `project` text,\n `git_remote` text,\n `git_branch` text,\n `user` text,\n `tool_version` text,\n `metadata_json` text,\n `import_key` text\n);\n\nCREATE TABLE IF NOT EXISTS `artifacts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `path` text,\n `content_text` text,\n `content_hash` text,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_artifacts_session_kind` ON `artifacts` (`session_id`,`kind`);\nCREATE TABLE IF NOT EXISTS `memory_items` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `title` text NOT NULL,\n `subtitle` text,\n `body_text` text NOT NULL,\n `confidence` real DEFAULT 0.5,\n `tags_text` text DEFAULT '',\n `active` integer DEFAULT 1,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL,\n `metadata_json` text,\n `actor_id` text,\n `actor_display_name` text,\n `visibility` text,\n `workspace_id` text,\n `workspace_kind` text,\n `origin_device_id` text,\n `origin_source` text,\n `trust_state` text,\n `facts` text,\n `narrative` text,\n `concepts` text,\n `files_read` text,\n `files_modified` text,\n `user_prompt_id` integer,\n `prompt_number` integer,\n `deleted_at` text,\n `rev` integer DEFAULT 0,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_items_active_created` ON `memory_items` (`active`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_session` ON `memory_items` (`session_id`);\nCREATE TABLE IF NOT EXISTS `usage_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `event` text NOT NULL,\n `tokens_read` integer DEFAULT 0,\n `tokens_written` integer DEFAULT 0,\n `tokens_saved` integer DEFAULT 0,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null\n);\n\nCREATE INDEX IF NOT EXISTS `idx_usage_events_event_created` ON `usage_events` (`event`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_usage_events_session` ON `usage_events` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `event_id` text,\n `event_seq` integer NOT NULL,\n `event_type` text NOT NULL,\n `ts_wall_ms` integer,\n `ts_mono_ms` real,\n `payload_json` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_seq` ON `raw_events` (`source`,`stream_id`,`event_seq`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_event_id` ON `raw_events` (`source`,`stream_id`,`event_id`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_session_seq` ON `raw_events` (`opencode_session_id`,`event_seq`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_created` ON `raw_events` (`created_at`);\nCREATE TABLE IF NOT EXISTS `raw_event_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `cwd` text,\n `project` text,\n `started_at` text,\n `last_seen_ts_wall_ms` integer,\n `last_received_event_seq` integer DEFAULT -1 NOT NULL,\n `last_flushed_event_seq` integer DEFAULT -1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `opencode_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `session_id` integer,\n `created_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`),\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_opencode_sessions_session` ON `opencode_sessions` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_event_flush_batches` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `start_event_seq` integer NOT NULL,\n `end_event_seq` integer NOT NULL,\n `extractor_version` text NOT NULL,\n `status` text NOT NULL,\n `error_message` text,\n `error_type` text,\n `observer_provider` text,\n `observer_model` text,\n `observer_runtime` text,\n `attempt_count` integer DEFAULT 0 NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_flush_batches_source_stream_seq_ver` ON `raw_event_flush_batches` (`source`,`stream_id`,`start_event_seq`,`end_event_seq`,`extractor_version`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_session_created` ON `raw_event_flush_batches` (`opencode_session_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_status_updated` ON `raw_event_flush_batches` (`status`,`updated_at`);\nCREATE TABLE IF NOT EXISTS `user_prompts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `prompt_text` text NOT NULL,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_session` ON `user_prompts` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_project` ON `user_prompts` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_epoch` ON `user_prompts` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `session_summaries` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `request` text,\n `investigated` text,\n `learned` text,\n `completed` text,\n `next_steps` text,\n `notes` text,\n `files_read` text,\n `files_edited` text,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_session` ON `session_summaries` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_project` ON `session_summaries` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_epoch` ON `session_summaries` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `replication_ops` (\n `op_id` text PRIMARY KEY NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `op_type` text NOT NULL,\n `payload_json` text,\n `clock_rev` integer NOT NULL,\n `clock_updated_at` text NOT NULL,\n `clock_device_id` text NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_created` ON `replication_ops` (`created_at`,`op_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_entity` ON `replication_ops` (`entity_type`,`entity_id`);\nCREATE TABLE IF NOT EXISTS `replication_cursors` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_peers` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `name` text,\n `pinned_fingerprint` text,\n `public_key` text,\n `addresses_json` text,\n `claimed_local_actor` integer DEFAULT 0 NOT NULL,\n `actor_id` text,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `created_at` text NOT NULL,\n `last_seen_at` text,\n `last_sync_at` text,\n `last_error` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_nonces` (\n `nonce` text PRIMARY KEY NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_device` (\n `device_id` text PRIMARY KEY NOT NULL,\n `public_key` text NOT NULL,\n `fingerprint` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_attempts` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text NOT NULL,\n `started_at` text NOT NULL,\n `finished_at` text,\n `ok` integer NOT NULL,\n `ops_in` integer NOT NULL,\n `ops_out` integer NOT NULL,\n `error` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_attempts_peer_started` ON `sync_attempts` (`peer_device_id`,`started_at`);\nCREATE TABLE IF NOT EXISTS `sync_daemon_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `last_error` text,\n `last_traceback` text,\n `last_error_at` text,\n `last_ok_at` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_reset_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `generation` integer NOT NULL,\n `snapshot_id` text NOT NULL,\n `baseline_cursor` text,\n `retained_floor_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_samples` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `created_at` text NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_stats` (\n `id` integer PRIMARY KEY NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `actors` (\n `actor_id` text PRIMARY KEY NOT NULL,\n `display_name` text NOT NULL,\n `is_local` integer DEFAULT 0 NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `merged_into_actor_id` text,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_actors_is_local` ON `actors` (`is_local`);\nCREATE INDEX IF NOT EXISTS `idx_actors_status` ON `actors` (`status`);", Jd = "\nCREATE INDEX IF NOT EXISTS idx_sync_peers_actor_id ON sync_peers(actor_id);\n\nCREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n);\n\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(\n title, body_text, tags_text,\n content='memory_items',\n content_rowid='id'\n);\n\nCREATE TRIGGER IF NOT EXISTS memory_items_ai AFTER INSERT ON memory_items BEGIN\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_au;\nCREATE TRIGGER memory_items_au AFTER UPDATE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_ad;\nCREATE TRIGGER memory_items_ad AFTER DELETE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\nEND;\n";
|
|
9565
|
+
function Yd(e) {
|
|
9566
|
+
e.exec(qd), e.exec(Jd), e.pragma("user_version = 6");
|
|
9468
9567
|
}
|
|
9469
|
-
function
|
|
9568
|
+
function Xd(e) {
|
|
9470
9569
|
let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version) VALUES (?, ?, ?, ?, ?)").run(t, "/tmp/test", "test-project", "test-user", "test");
|
|
9471
9570
|
return Number(n.lastInsertRowid);
|
|
9472
9571
|
}
|
|
9473
9572
|
//#endregion
|
|
9474
9573
|
//#region src/index.ts
|
|
9475
|
-
var
|
|
9574
|
+
var Zd = "0.21.2";
|
|
9476
9575
|
//#endregion
|
|
9477
|
-
export { ge as Api, $e as CODEMEM_CONFIG_ENV_OVERRIDES, R as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH,
|
|
9576
|
+
export { ge as Api, $e as CODEMEM_CONFIG_ENV_OVERRIDES, R as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH, ed as DEFAULT_SERVICE_TYPE, gi as DEFAULT_TIME_WINDOW_S, qa as LOW_SIGNAL_TOOLS, ve as MAPPABLE_CLAUDE_HOOK_EVENTS, Tt as MIN_COMPATIBLE_SCHEMA, $u as MemoryStore, As as ObserverAuthAdapter, Ks as ObserverAuthError, uc as ObserverClient, Kl as RawEventSweeper, wt as SCHEMA_VERSION, hi as SIGNATURE_VERSION, Kd as SyncRetentionRunner, yo as TRIVIAL_REQUESTS, Zd as VERSION, ta as _resetEmbeddingClient, Fi as addressDedupeKey, pd as advertiseMdns, zu as applyReplicationOps, zt as assertSchemaReady, Iu as backfillReplicationOps, Tn as backfillTagsText, Yo as backfillVectors, ao as budgetToolEvents, xi as buildAuthHeaders, An as buildBaseUrl, _i as buildCanonicalRequest, Ts as buildCodexHeaders, Ma as buildFilterClauses, Na as buildFilterClausesWithContext, fa as buildImportKey, Fe as buildIngestPayloadFromHook, Pl as buildMemoryPack, Fl as buildMemoryPackAsync, vo as buildObserverPrompt, Pe as buildRawEventEnvelopeFromHook, Bl as buildSessionContext, wo as buildTranscript, bu as bulkPruneReplicationOpsByAgeCutoff, iu as chunkOpsBySize, $i as chunkText, os as cleanOrphanSessions, Ci as cleanupNonces, lu as clockTuple, Nt as connect, Je as connectCoordinator, Ld as consecutiveConnectivityFailures, nr as coordinatorCreateInviteAction, Ki as coordinatorEnabled, rr as coordinatorImportInviteAction, ir as coordinatorListJoinRequestsAction, ar as coordinatorReviewJoinRequestAction, Xi as coordinatorStatusSnapshot, Mi as createCoordinatorApp, yd as cursorAdvances, kn as deactivateLowSignalMemories, On as deactivateLowSignalObservations, Le as decodeInvitePayload, Yc as dedupeOrderedIds, Co as deriveRequest, Uo as deriveTags, md as discoverPeersViaMdns, ra as embedTexts, Ie as encodeInvitePayload, Qn as ensureDeviceIdentity, il as estimateTokens, Qa as eventToToolEvent, Cc as expandQuery, $c as explain, va as exportMemories, eo as extractAdapterEvent, To as extractAssistantMessages, Eo as extractAssistantUsage, ze as extractInvitePayload, bs as extractOAuthAccess, Cs as extractOAuthAccountId, ws as extractOAuthExpires, Do as extractPrompts, xs as extractProviderApiKey, cu as extractReplicationOps, $a as extractToolEvents, Ho as fileTags, Nu as filterReplicationOpsForSync, Mu as filterReplicationOpsForSyncWithStatus, In as fingerprintPublicKey, So as firstSentence, Hl as flushRawEvents, z as fromJson, Ut as fromJsonStrict, Jn as generateKeypair, et as getCodememConfigPath, rt as getCodememEnvOverrides, na as getEmbeddingClient, at as getOpenCodeProviderConfig, xt as getProviderApiKey, yt as getProviderBaseUrl, bt as getProviderHeaders, vt as getProviderOptions, _n as getRawEventStatus, vn as getReliabilityMetrics, au as getReplicationCursor, Rt as getSchemaVersion, $l as getSyncResetState, zo as hasMeaningfulObservation, _u as hasUnsyncedSharedMemoryChanges, Qi as hashText, Ea as importMemories, is as ingest, ss as ingestMain, hn as initDatabase, Yd as initTestSchema, Xd as insertTestSession, Re as inviteLink, Id as isConnectivityError, Lt as isEmbeddingDisabled, Ja as isInternalMemoryTool, Kt as isLowSignalObservation, uu as isNewerClock, Ba as isSensitiveFieldName, xo as isTrivialRequest, Tc as kindBonus, lt as listConfiguredOpenCodeProviders, Zi as listCoordinatorJoinRequests, ot as listCustomProviders, ut as listObserverProviderOptions, gu as loadMemorySnapshotPageForPeer, Gs as loadObserverConfig, Ze as loadOpenCodeConfig, _s as loadOpenCodeOAuthCache, nd as loadPeerAddresses, Wn as loadPrivateKey, Vn as loadPrivateKeyKeychain, Un as loadPublicKey, hu as loadReplicationOpsForPeer, mu as loadReplicationOpsSince, It as loadSqliteVec, Yi as lookupCoordinatorPeers, Me as mapClaudeHookPayload, hd as mdnsAddressesForPeer, fd as mdnsEnabled, Ii as mergeAddresses, pa as mergeSummaryMetadata, Mt as migrateLegacyDbPath, Fu as migrateLegacyImportKeys, Oo as normalizeAdapterEvents, Pi as normalizeAddress, Gt as normalizeObservation, Ce as normalizeProjectLabel, bo as normalizeRequestText, Vo as normalizeTag, Ya as normalizeToolName, Ro as parseObserverResponse, ds as parsePositiveMemoryId, us as parseStrictInteger, Rd as peerBackoffSeconds, xu as planReplicationOpsAgePrune, Ss as probeAvailableCredentials, to as projectAdapterToolEvent, qt as projectBasename, Yt as projectClause, Jt as projectColumnClause, Xt as projectMatchesFilter, vu as pruneReplicationOps, yu as pruneReplicationOpsUntilCaughtUp, yn as rawEventsGate, Ds as readAuthFile, tt as readCodememConfigFile, Gi as readCoordinatorSyncConfig, ya as readImportPayload, wc as recencyScore, Si as recordNonce, ad as recordPeerSuccess, du as recordReplicationOp, id as recordSyncAttempt, ms as redactText, Ji as registerCoordinatorPresence, Ps as renderObserverHeaders, jn as requestJson, Wc as rerankResults, ft as resolveBuiltInProviderDefaultModel, dt as resolveBuiltInProviderFromModel, pt as resolveBuiltInProviderModel, St as resolveCustomProviderDefaultModel, mt as resolveCustomProviderFromModel, Ct as resolveCustomProviderModel, Ot as resolveDbPath, Ee as resolveHookProject, Hn as resolveKeyPaths, vs as resolveOAuthProvider, ht as resolvePlaceholder, Qt as resolveProject, bn as retryRawEventFailures, Es as runAuthCommand, Ud as runSyncDaemon, Md as runSyncPass, Ua as sanitizePayload, Ka as sanitizeToolOutput, H as schema, Gc as search, td as selectDialAddresses, Xo as semanticSearch, aa as serializeFloat32, sd as setPeerLocalActorClaim, od as setPeerProjectFilter, ou as setReplicationCursor, Vd as setSyncDaemonError, Bd as setSyncDaemonOk, eu as setSyncResetState, zd as shouldSkipOfflinePeer, vi as signRequest, Bn as storePrivateKeyKeychain, Jo as storeVectors, Ye as stripJsonComments, La as stripPrivate, Va as stripPrivateObj, Xe as stripTrailingCommas, Hd as syncDaemonTick, jd as syncOnce, Ad as syncPassPreflight, Bt as tableExists, qc as timeline, B as toJson, V as toJsonNullable, rd as updatePeerAddresses, gn as vacuumDatabase, Zn as validateExistingKeypair, yi as verifySignature, nt as writeCodememConfigFile };
|
|
9478
9577
|
|
|
9479
9578
|
//# sourceMappingURL=index.js.map
|