@codemem/core 0.21.0 → 0.21.1
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 +1 -1
- package/dist/index.js +622 -599
- package/dist/index.js.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,7 @@ function Zo(e, t) {
|
|
|
4886
4909
|
}
|
|
4887
4910
|
return n;
|
|
4888
4911
|
}
|
|
4889
|
-
async function
|
|
4912
|
+
async function ns(e, t, n) {
|
|
4890
4913
|
let r = e.cwd ?? process.cwd(), i = e.events ?? [];
|
|
4891
4914
|
if (!Array.isArray(i) || i.length === 0) return;
|
|
4892
4915
|
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 +4927,11 @@ async function Qo(e, t, n) {
|
|
|
4904
4927
|
}).returning({ id: U.id }).all()[0]?.id;
|
|
4905
4928
|
if (p == null) throw Error("session insert returned no id");
|
|
4906
4929
|
try {
|
|
4907
|
-
let e = Oo(i), d = Do(e), m = d.length > 0 ? d[d.length - 1]?.promptNumber ?? d.length : null, h =
|
|
4930
|
+
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
4931
|
h = ao(h, g, 30);
|
|
4909
4932
|
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
4933
|
if (b && xo(b) && h.length === 0 && !y && (x = !1), !x) {
|
|
4911
|
-
|
|
4934
|
+
rs(t, p, i.length, a);
|
|
4912
4935
|
return;
|
|
4913
4936
|
}
|
|
4914
4937
|
let S = wo(e), C = [];
|
|
@@ -4932,25 +4955,25 @@ async function Qo(e, t, n) {
|
|
|
4932
4955
|
if (!te.raw) {
|
|
4933
4956
|
if (a?.flusher === "raw_events") throw Error("observer failed during raw-event flush");
|
|
4934
4957
|
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.`),
|
|
4958
|
+
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.`), rs(t, p, i.length, a);
|
|
4936
4959
|
return;
|
|
4937
4960
|
}
|
|
4938
4961
|
let D = te.raw, O = Ro(D), k = [];
|
|
4939
4962
|
if (s && zo(O.observations)) for (let e of O.observations) {
|
|
4940
4963
|
let t = e.kind.trim().toLowerCase();
|
|
4941
|
-
|
|
4964
|
+
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
4965
|
}
|
|
4943
4966
|
let A = null;
|
|
4944
4967
|
if (o && O.summary && !O.skipSummaryReason) {
|
|
4945
4968
|
let e = O.summary;
|
|
4946
4969
|
if (e.request || e.investigated || e.learned || e.completed || e.nextSteps || e.notes) {
|
|
4947
|
-
e.filesRead =
|
|
4970
|
+
e.filesRead = $o(e.filesRead, r), e.filesModified = $o(e.filesModified, r);
|
|
4948
4971
|
let t = e.request;
|
|
4949
4972
|
if (xo(t)) {
|
|
4950
4973
|
let n = Co(e);
|
|
4951
4974
|
n && (t = n);
|
|
4952
4975
|
}
|
|
4953
|
-
let n =
|
|
4976
|
+
let n = es(e);
|
|
4954
4977
|
n && !Kt(So(n)) && (A = {
|
|
4955
4978
|
summary: e,
|
|
4956
4979
|
request: t,
|
|
@@ -5028,17 +5051,17 @@ async function Qo(e, t, n) {
|
|
|
5028
5051
|
}).run();
|
|
5029
5052
|
})();
|
|
5030
5053
|
for (let e of ne) try {
|
|
5031
|
-
await
|
|
5054
|
+
await Jo(t.db, e.memoryId, e.title, e.bodyText);
|
|
5032
5055
|
} catch {}
|
|
5033
|
-
|
|
5056
|
+
rs(t, p, i.length, a);
|
|
5034
5057
|
} catch (e) {
|
|
5035
5058
|
try {
|
|
5036
|
-
|
|
5059
|
+
rs(t, p, i.length, a);
|
|
5037
5060
|
} catch {}
|
|
5038
5061
|
throw e;
|
|
5039
5062
|
}
|
|
5040
5063
|
}
|
|
5041
|
-
function
|
|
5064
|
+
function rs(e, t, n, r) {
|
|
5042
5065
|
e.endSession(t, {
|
|
5043
5066
|
post: {},
|
|
5044
5067
|
source: "plugin",
|
|
@@ -5046,11 +5069,11 @@ function $o(e, t, n, r) {
|
|
|
5046
5069
|
session_context: r
|
|
5047
5070
|
});
|
|
5048
5071
|
}
|
|
5049
|
-
function
|
|
5072
|
+
function is(e, t = 24) {
|
|
5050
5073
|
let n = N(e.db, { schema: H }), r = (/* @__PURE__ */ new Date(Date.now() - t * 36e5)).toISOString();
|
|
5051
5074
|
return n.update(U).set({ ended_at: r }).where(D(ie(U.ended_at), oe(U.started_at, r))).run().changes;
|
|
5052
5075
|
}
|
|
5053
|
-
async function
|
|
5076
|
+
async function as(e, t) {
|
|
5054
5077
|
let n = [];
|
|
5055
5078
|
for await (let e of process.stdin) n.push(String(e));
|
|
5056
5079
|
let r = n.join("");
|
|
@@ -5061,30 +5084,30 @@ async function ts(e, t) {
|
|
|
5061
5084
|
} catch (e) {
|
|
5062
5085
|
throw Error(`codemem: invalid payload: ${e}`);
|
|
5063
5086
|
}
|
|
5064
|
-
await
|
|
5087
|
+
await ns(i, e, { observer: t });
|
|
5065
5088
|
}
|
|
5066
5089
|
//#endregion
|
|
5067
5090
|
//#region src/integers.ts
|
|
5068
|
-
var
|
|
5069
|
-
function
|
|
5091
|
+
var os = BigInt(2 ** 53 - 1), ss = BigInt(-(2 ** 53 - 1));
|
|
5092
|
+
function cs(e) {
|
|
5070
5093
|
if (e == null) return null;
|
|
5071
5094
|
let t = e.trim();
|
|
5072
5095
|
if (!/^[+-]?\d+$/.test(t)) return null;
|
|
5073
5096
|
try {
|
|
5074
5097
|
let e = BigInt(t);
|
|
5075
|
-
return e <
|
|
5098
|
+
return e < ss || e > os ? null : Number(e);
|
|
5076
5099
|
} catch {
|
|
5077
5100
|
return null;
|
|
5078
5101
|
}
|
|
5079
5102
|
}
|
|
5080
|
-
function
|
|
5103
|
+
function ls(e) {
|
|
5081
5104
|
if (typeof e == "boolean") return null;
|
|
5082
5105
|
if (typeof e == "number") return !Number.isInteger(e) || !Number.isSafeInteger(e) || e <= 0 ? null : e;
|
|
5083
5106
|
if (typeof e == "string") {
|
|
5084
5107
|
if (!/^\d+$/.test(e)) return null;
|
|
5085
5108
|
try {
|
|
5086
5109
|
let t = BigInt(e);
|
|
5087
|
-
return t <= 0n || t >
|
|
5110
|
+
return t <= 0n || t > os ? null : Number(t);
|
|
5088
5111
|
} catch {
|
|
5089
5112
|
return null;
|
|
5090
5113
|
}
|
|
@@ -5093,24 +5116,24 @@ function as(e) {
|
|
|
5093
5116
|
}
|
|
5094
5117
|
//#endregion
|
|
5095
5118
|
//#region src/observer-auth.ts
|
|
5096
|
-
var
|
|
5097
|
-
function
|
|
5119
|
+
var us = "0.0.1", ds = [/sk-[A-Za-z0-9]{10,}/g, /Bearer\s+[A-Za-z0-9._-]{10,}/g];
|
|
5120
|
+
function fs(e, t = 400) {
|
|
5098
5121
|
let n = e;
|
|
5099
|
-
for (let e of
|
|
5122
|
+
for (let e of ds) n = n.replace(new RegExp(e.source, e.flags), "[redacted]");
|
|
5100
5123
|
return n.length > t ? `${n.slice(0, t)}…` : n;
|
|
5101
5124
|
}
|
|
5102
|
-
function
|
|
5125
|
+
function ps() {
|
|
5103
5126
|
return {
|
|
5104
5127
|
token: null,
|
|
5105
5128
|
authType: "none",
|
|
5106
5129
|
source: "none"
|
|
5107
5130
|
};
|
|
5108
5131
|
}
|
|
5109
|
-
function
|
|
5132
|
+
function ms() {
|
|
5110
5133
|
return T(v(), ".local", "share", "opencode", "auth.json");
|
|
5111
5134
|
}
|
|
5112
|
-
function
|
|
5113
|
-
let e =
|
|
5135
|
+
function hs() {
|
|
5136
|
+
let e = ms();
|
|
5114
5137
|
if (!l(e)) return {};
|
|
5115
5138
|
try {
|
|
5116
5139
|
let t = JSON.parse(f(e, "utf-8"));
|
|
@@ -5119,55 +5142,55 @@ function ds() {
|
|
|
5119
5142
|
return {};
|
|
5120
5143
|
}
|
|
5121
5144
|
}
|
|
5122
|
-
function
|
|
5145
|
+
function gs(e, t) {
|
|
5123
5146
|
return e && ["openai", "anthropic"].includes(e.toLowerCase()) ? e.toLowerCase() : t.toLowerCase().startsWith("claude") ? "anthropic" : "openai";
|
|
5124
5147
|
}
|
|
5125
|
-
function
|
|
5148
|
+
function _s(e, t) {
|
|
5126
5149
|
let n = e[t];
|
|
5127
5150
|
return typeof n == "object" && n && !Array.isArray(n) ? n : null;
|
|
5128
5151
|
}
|
|
5129
|
-
function
|
|
5130
|
-
let n =
|
|
5152
|
+
function vs(e, t) {
|
|
5153
|
+
let n = _s(e, t);
|
|
5131
5154
|
if (!n) return null;
|
|
5132
5155
|
let r = n.access;
|
|
5133
5156
|
return typeof r == "string" && r ? r : null;
|
|
5134
5157
|
}
|
|
5135
|
-
function
|
|
5136
|
-
let n =
|
|
5158
|
+
function ys(e, t) {
|
|
5159
|
+
let n = _s(e, t);
|
|
5137
5160
|
if (!n) return null;
|
|
5138
5161
|
let r = n.key;
|
|
5139
5162
|
return typeof r == "string" && r ? r : null;
|
|
5140
5163
|
}
|
|
5141
|
-
function
|
|
5142
|
-
let e =
|
|
5164
|
+
function bs() {
|
|
5165
|
+
let e = hs(), t = Date.now(), n = !!process.env.CODEMEM_OBSERVER_API_KEY, r = [
|
|
5143
5166
|
["openai", "OPENAI_API_KEY"],
|
|
5144
5167
|
["anthropic", "ANTHROPIC_API_KEY"],
|
|
5145
5168
|
["opencode", null]
|
|
5146
5169
|
], i = {};
|
|
5147
5170
|
for (let [a, o] of r) {
|
|
5148
|
-
let r =
|
|
5171
|
+
let r = vs(e, a), s = Ss(e, a);
|
|
5149
5172
|
i[a] = {
|
|
5150
|
-
oauth: a === "opencode" ? !!
|
|
5173
|
+
oauth: a === "opencode" ? !!ys(e, a) : !!r && (s == null || s > t),
|
|
5151
5174
|
api_key: n,
|
|
5152
5175
|
env_var: o ? !!process.env[o] : !1
|
|
5153
5176
|
};
|
|
5154
5177
|
}
|
|
5155
5178
|
return i;
|
|
5156
5179
|
}
|
|
5157
|
-
function
|
|
5158
|
-
let n =
|
|
5180
|
+
function xs(e, t) {
|
|
5181
|
+
let n = _s(e, t);
|
|
5159
5182
|
if (!n) return null;
|
|
5160
5183
|
let r = n.accountId;
|
|
5161
5184
|
return typeof r == "string" && r ? r : null;
|
|
5162
5185
|
}
|
|
5163
|
-
function
|
|
5164
|
-
let n =
|
|
5186
|
+
function Ss(e, t) {
|
|
5187
|
+
let n = _s(e, t);
|
|
5165
5188
|
if (!n) return null;
|
|
5166
5189
|
let r = n.expires;
|
|
5167
5190
|
return typeof r == "number" ? r : null;
|
|
5168
5191
|
}
|
|
5169
|
-
function
|
|
5170
|
-
let n = process.env.CODEMEM_CODEX_ORIGINATOR ?? "opencode", r = process.env.CODEMEM_CODEX_USER_AGENT ?? `codemem/${
|
|
5192
|
+
function Cs(e, t) {
|
|
5193
|
+
let n = process.env.CODEMEM_CODEX_ORIGINATOR ?? "opencode", r = process.env.CODEMEM_CODEX_USER_AGENT ?? `codemem/${us} (${b()} ${x()}; ${_()})`, i = {
|
|
5171
5194
|
authorization: `Bearer ${e}`,
|
|
5172
5195
|
originator: n,
|
|
5173
5196
|
"User-Agent": r,
|
|
@@ -5175,7 +5198,7 @@ function ys(e, t) {
|
|
|
5175
5198
|
};
|
|
5176
5199
|
return t && (i["ChatGPT-Account-Id"] = t), i;
|
|
5177
5200
|
}
|
|
5178
|
-
function
|
|
5201
|
+
function ws(e, t) {
|
|
5179
5202
|
let n = e[0];
|
|
5180
5203
|
if (!n) return null;
|
|
5181
5204
|
let r = Math.max(100, t);
|
|
@@ -5193,7 +5216,7 @@ function bs(e, t) {
|
|
|
5193
5216
|
return null;
|
|
5194
5217
|
}
|
|
5195
5218
|
}
|
|
5196
|
-
function
|
|
5219
|
+
function Ts(e) {
|
|
5197
5220
|
if (!e) return null;
|
|
5198
5221
|
let t = e.replace(/^~/, v());
|
|
5199
5222
|
t = t.replace(/\$\{([^}]+)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (e, t, n) => {
|
|
@@ -5206,7 +5229,7 @@ function xs(e) {
|
|
|
5206
5229
|
return null;
|
|
5207
5230
|
}
|
|
5208
5231
|
}
|
|
5209
|
-
var
|
|
5232
|
+
var Es = new Set([
|
|
5210
5233
|
"",
|
|
5211
5234
|
"auto",
|
|
5212
5235
|
"env",
|
|
@@ -5214,47 +5237,47 @@ var Ss = new Set([
|
|
|
5214
5237
|
"command",
|
|
5215
5238
|
"none"
|
|
5216
5239
|
]);
|
|
5217
|
-
function
|
|
5240
|
+
function Ds(e) {
|
|
5218
5241
|
let t = (e ?? "").trim().toLowerCase();
|
|
5219
|
-
return
|
|
5242
|
+
return Es.has(t) && t || "auto";
|
|
5220
5243
|
}
|
|
5221
|
-
var
|
|
5244
|
+
var Os = class {
|
|
5222
5245
|
source;
|
|
5223
5246
|
filePath;
|
|
5224
5247
|
command;
|
|
5225
5248
|
timeoutMs;
|
|
5226
5249
|
cacheTtlS;
|
|
5227
|
-
cached =
|
|
5250
|
+
cached = ps();
|
|
5228
5251
|
cachedAtMs = 0;
|
|
5229
5252
|
constructor(e) {
|
|
5230
5253
|
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
5254
|
}
|
|
5232
5255
|
resolve(e) {
|
|
5233
|
-
let t =
|
|
5234
|
-
if (t === "none") return
|
|
5256
|
+
let t = Ds(this.source), n = e?.explicitToken ?? null, r = e?.envTokens ?? [], i = e?.oauthToken ?? null, a = e?.forceRefresh ?? !1;
|
|
5257
|
+
if (t === "none") return ps();
|
|
5235
5258
|
if (!a && (t === "command" || t === "file") && this.cacheTtlS > 0) {
|
|
5236
5259
|
let e = performance.now() - this.cachedAtMs;
|
|
5237
5260
|
if (this.cachedAtMs > 0 && e <= this.cacheTtlS * 1e3) return this.cached;
|
|
5238
5261
|
}
|
|
5239
5262
|
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 =
|
|
5263
|
+
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 = Ts(this.filePath), o && (s = "file")), (t === "auto" || t === "command") && !o && (o = ws(this.command, this.timeoutMs), o && (s = "command"));
|
|
5241
5264
|
let c = o ? {
|
|
5242
5265
|
token: o,
|
|
5243
5266
|
authType: "bearer",
|
|
5244
5267
|
source: s
|
|
5245
|
-
} :
|
|
5268
|
+
} : ps(), l = t === "command" || t === "file";
|
|
5246
5269
|
return l && c.token ? (this.cached = c, this.cachedAtMs = performance.now()) : l && this.invalidateCache(), c;
|
|
5247
5270
|
}
|
|
5248
5271
|
invalidateCache() {
|
|
5249
|
-
this.cached =
|
|
5272
|
+
this.cached = ps(), this.cachedAtMs = 0;
|
|
5250
5273
|
}
|
|
5251
|
-
},
|
|
5252
|
-
function
|
|
5274
|
+
}, ks = /\$\{auth\.token\}/g, As = /\$\{auth\.type\}/g, js = /\$\{auth\.source\}/g;
|
|
5275
|
+
function Ms(e, t) {
|
|
5253
5276
|
let n = t.token ?? "", r = {};
|
|
5254
5277
|
for (let [i, a] of Object.entries(e)) {
|
|
5255
5278
|
if (typeof i != "string" || typeof a != "string") continue;
|
|
5256
|
-
let e = a.replace(
|
|
5257
|
-
if (e = e.replace(
|
|
5279
|
+
let e = a.replace(ks, n);
|
|
5280
|
+
if (e = e.replace(As, t.authType), e = e.replace(js, t.source), a.includes("${auth.token}") && !n) continue;
|
|
5258
5281
|
let o = e.trim();
|
|
5259
5282
|
o && (r[i] = o);
|
|
5260
5283
|
}
|
|
@@ -5262,7 +5285,7 @@ function Os(e, t) {
|
|
|
5262
5285
|
}
|
|
5263
5286
|
//#endregion
|
|
5264
5287
|
//#region src/observer-client.ts
|
|
5265
|
-
var
|
|
5288
|
+
var Ns = "claude-sonnet-4-20250514", Ps = "gpt-5.1-codex-mini", Fs = "https://api.anthropic.com/v1/messages", Is = "2023-06-01", Ls = "https://chatgpt.com/backend-api/codex/responses", Rs = 6e4, zs = {
|
|
5266
5289
|
"claude-4.5-haiku": "claude-haiku-4-5",
|
|
5267
5290
|
"claude-4.5-sonnet": "claude-sonnet-4-5",
|
|
5268
5291
|
"claude-4.5-opus": "claude-opus-4-5",
|
|
@@ -5272,12 +5295,12 @@ var ks = "claude-sonnet-4-20250514", As = "gpt-5.1-codex-mini", js = "https://ap
|
|
|
5272
5295
|
"claude-4.0-sonnet": "claude-sonnet-4-0",
|
|
5273
5296
|
"claude-4.0-opus": "claude-opus-4-0"
|
|
5274
5297
|
};
|
|
5275
|
-
function
|
|
5298
|
+
function Bs(e, t) {
|
|
5276
5299
|
if (e == null) return t;
|
|
5277
5300
|
let n = typeof e == "string" ? Number.parseInt(e, 10) : Number(e);
|
|
5278
5301
|
return Number.isFinite(n) ? n : t;
|
|
5279
5302
|
}
|
|
5280
|
-
function
|
|
5303
|
+
function Vs(e) {
|
|
5281
5304
|
if (e == null) return null;
|
|
5282
5305
|
if (typeof e == "string") {
|
|
5283
5306
|
let t = e.trim();
|
|
@@ -5291,7 +5314,7 @@ function Ls(e) {
|
|
|
5291
5314
|
}
|
|
5292
5315
|
return typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
5293
5316
|
}
|
|
5294
|
-
function
|
|
5317
|
+
function Hs(e) {
|
|
5295
5318
|
if (e == null) return null;
|
|
5296
5319
|
if (Array.isArray(e)) return e.every((e) => typeof e == "string") ? e : null;
|
|
5297
5320
|
if (typeof e == "string") {
|
|
@@ -5305,7 +5328,7 @@ function Rs(e) {
|
|
|
5305
5328
|
}
|
|
5306
5329
|
return null;
|
|
5307
5330
|
}
|
|
5308
|
-
function
|
|
5331
|
+
function Us() {
|
|
5309
5332
|
let e = {
|
|
5310
5333
|
observerProvider: null,
|
|
5311
5334
|
observerModel: null,
|
|
@@ -5337,41 +5360,41 @@ function zs() {
|
|
|
5337
5360
|
i = {};
|
|
5338
5361
|
}
|
|
5339
5362
|
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 =
|
|
5363
|
+
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 = Bs(i.observer_max_chars, a.observerMaxChars), a.observerMaxTokens = Bs(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 = Bs(i.observer_auth_timeout_ms, a.observerAuthTimeoutMs), a.observerAuthCacheTtlS = Bs(i.observer_auth_cache_ttl_s, a.observerAuthCacheTtlS);
|
|
5364
|
+
let o = Vs(i.observer_headers);
|
|
5342
5365
|
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 =
|
|
5366
|
+
let s = Hs(i.observer_auth_command);
|
|
5367
|
+
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 = Bs(process.env.CODEMEM_OBSERVER_MAX_CHARS, a.observerMaxChars), a.observerMaxTokens = Bs(process.env.CODEMEM_OBSERVER_MAX_TOKENS, a.observerMaxTokens), a.observerAuthTimeoutMs = Bs(process.env.CODEMEM_OBSERVER_AUTH_TIMEOUT_MS, a.observerAuthTimeoutMs), a.observerAuthCacheTtlS = Bs(process.env.CODEMEM_OBSERVER_AUTH_CACHE_TTL_S, a.observerAuthCacheTtlS);
|
|
5368
|
+
let c = Vs(process.env.CODEMEM_OBSERVER_HEADERS);
|
|
5346
5369
|
c && (a.observerHeaders = c);
|
|
5347
|
-
let u =
|
|
5370
|
+
let u = Hs(process.env.CODEMEM_OBSERVER_AUTH_COMMAND);
|
|
5348
5371
|
return u && (a.observerAuthCommand = u), a;
|
|
5349
5372
|
}
|
|
5350
|
-
var
|
|
5373
|
+
var Ws = class extends Error {
|
|
5351
5374
|
constructor(e) {
|
|
5352
5375
|
super(e), this.name = "ObserverAuthError";
|
|
5353
5376
|
}
|
|
5354
5377
|
};
|
|
5355
|
-
function
|
|
5378
|
+
function Gs(e) {
|
|
5356
5379
|
return e === 401 || e === 403;
|
|
5357
5380
|
}
|
|
5358
|
-
function
|
|
5381
|
+
function Ks(e) {
|
|
5359
5382
|
let t = e.trim();
|
|
5360
|
-
return t && (
|
|
5383
|
+
return t && (zs[t.toLowerCase()] ?? t);
|
|
5361
5384
|
}
|
|
5362
|
-
function
|
|
5363
|
-
return process.env.CODEMEM_ANTHROPIC_ENDPOINT ??
|
|
5385
|
+
function qs() {
|
|
5386
|
+
return process.env.CODEMEM_ANTHROPIC_ENDPOINT ?? Fs;
|
|
5364
5387
|
}
|
|
5365
|
-
function
|
|
5388
|
+
function Js(e, t) {
|
|
5366
5389
|
let n = {
|
|
5367
|
-
"anthropic-version":
|
|
5390
|
+
"anthropic-version": Is,
|
|
5368
5391
|
"content-type": "application/json"
|
|
5369
5392
|
};
|
|
5370
5393
|
return t ? (n.authorization = `Bearer ${e}`, n["anthropic-beta"] = "oauth-2025-04-20") : n["x-api-key"] = e, n;
|
|
5371
5394
|
}
|
|
5372
|
-
function
|
|
5395
|
+
function Ys(e, t, n, r) {
|
|
5373
5396
|
return {
|
|
5374
|
-
model:
|
|
5397
|
+
model: Ks(e),
|
|
5375
5398
|
max_tokens: r,
|
|
5376
5399
|
system: t,
|
|
5377
5400
|
messages: [{
|
|
@@ -5380,7 +5403,7 @@ function Gs(e, t, n, r) {
|
|
|
5380
5403
|
}]
|
|
5381
5404
|
};
|
|
5382
5405
|
}
|
|
5383
|
-
function
|
|
5406
|
+
function Xs(e) {
|
|
5384
5407
|
let t = e.content;
|
|
5385
5408
|
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
5409
|
let n = [];
|
|
@@ -5394,13 +5417,13 @@ function Ks(e) {
|
|
|
5394
5417
|
}
|
|
5395
5418
|
return n.length > 0 ? n.join("") : null;
|
|
5396
5419
|
}
|
|
5397
|
-
function
|
|
5420
|
+
function Zs(e) {
|
|
5398
5421
|
return {
|
|
5399
5422
|
authorization: `Bearer ${e}`,
|
|
5400
5423
|
"content-type": "application/json"
|
|
5401
5424
|
};
|
|
5402
5425
|
}
|
|
5403
|
-
function
|
|
5426
|
+
function Qs(e, t) {
|
|
5404
5427
|
let n = { ...e };
|
|
5405
5428
|
for (let [e, r] of Object.entries(t)) {
|
|
5406
5429
|
let t = e.toLowerCase();
|
|
@@ -5409,12 +5432,12 @@ function Js(e, t) {
|
|
|
5409
5432
|
}
|
|
5410
5433
|
return n;
|
|
5411
5434
|
}
|
|
5412
|
-
function
|
|
5413
|
-
let n =
|
|
5435
|
+
function $s(e, t) {
|
|
5436
|
+
let n = Qs(e, t);
|
|
5414
5437
|
for (let t of Object.keys(e)) delete e[t];
|
|
5415
5438
|
Object.assign(e, n);
|
|
5416
5439
|
}
|
|
5417
|
-
function
|
|
5440
|
+
function ec(e, t, n, r) {
|
|
5418
5441
|
return {
|
|
5419
5442
|
model: e,
|
|
5420
5443
|
max_tokens: r,
|
|
@@ -5428,7 +5451,7 @@ function Xs(e, t, n, r) {
|
|
|
5428
5451
|
}]
|
|
5429
5452
|
};
|
|
5430
5453
|
}
|
|
5431
|
-
function
|
|
5454
|
+
function tc(e) {
|
|
5432
5455
|
let t = e.choices;
|
|
5433
5456
|
if (!Array.isArray(t) || t.length === 0) return null;
|
|
5434
5457
|
let n = t[0];
|
|
@@ -5438,10 +5461,10 @@ function Zs(e) {
|
|
|
5438
5461
|
let i = r.content;
|
|
5439
5462
|
return typeof i == "string" ? i : null;
|
|
5440
5463
|
}
|
|
5441
|
-
function
|
|
5442
|
-
return process.env.CODEMEM_CODEX_ENDPOINT ??
|
|
5464
|
+
function nc() {
|
|
5465
|
+
return process.env.CODEMEM_CODEX_ENDPOINT ?? Ls;
|
|
5443
5466
|
}
|
|
5444
|
-
function
|
|
5467
|
+
function rc(e, t) {
|
|
5445
5468
|
return {
|
|
5446
5469
|
model: e,
|
|
5447
5470
|
instructions: "You are a memory observer.",
|
|
@@ -5456,7 +5479,7 @@ function $s(e, t) {
|
|
|
5456
5479
|
stream: !0
|
|
5457
5480
|
};
|
|
5458
5481
|
}
|
|
5459
|
-
function
|
|
5482
|
+
function ic(e, t) {
|
|
5460
5483
|
let n = [];
|
|
5461
5484
|
for (let r of e.split("\n")) {
|
|
5462
5485
|
if (!r.startsWith("data:")) continue;
|
|
@@ -5468,14 +5491,14 @@ function ec(e, t) {
|
|
|
5468
5491
|
}
|
|
5469
5492
|
return n.length > 0 ? n.join("").trim() : null;
|
|
5470
5493
|
}
|
|
5471
|
-
function
|
|
5494
|
+
function ac(e) {
|
|
5472
5495
|
if (e.type === "response.output_text.delta") {
|
|
5473
5496
|
let t = e.delta;
|
|
5474
5497
|
return typeof t == "string" && t ? t : null;
|
|
5475
5498
|
}
|
|
5476
5499
|
return null;
|
|
5477
5500
|
}
|
|
5478
|
-
function
|
|
5501
|
+
function oc(e) {
|
|
5479
5502
|
if (e.type === "content_block_delta") {
|
|
5480
5503
|
let t = e.delta;
|
|
5481
5504
|
if (t && t.type === "text_delta") {
|
|
@@ -5485,10 +5508,10 @@ function nc(e) {
|
|
|
5485
5508
|
}
|
|
5486
5509
|
return null;
|
|
5487
5510
|
}
|
|
5488
|
-
function
|
|
5511
|
+
function sc() {
|
|
5489
5512
|
return Date.now();
|
|
5490
5513
|
}
|
|
5491
|
-
var
|
|
5514
|
+
var cc = class {
|
|
5492
5515
|
provider;
|
|
5493
5516
|
model;
|
|
5494
5517
|
runtime;
|
|
@@ -5505,7 +5528,7 @@ var ic = class {
|
|
|
5505
5528
|
_lastErrorCode = null;
|
|
5506
5529
|
_lastErrorMessage = null;
|
|
5507
5530
|
constructor(e) {
|
|
5508
|
-
let t = e ??
|
|
5531
|
+
let t = e ?? Us(), n = (t.observerProvider ?? "").toLowerCase(), r = (t.observerModel ?? "").trim(), i = lt();
|
|
5509
5532
|
n && n !== "openai" && n !== "anthropic" && i.add(n);
|
|
5510
5533
|
let a = n;
|
|
5511
5534
|
if (!a) {
|
|
@@ -5516,11 +5539,11 @@ var ic = class {
|
|
|
5516
5539
|
let e = dt(r);
|
|
5517
5540
|
e && (a = e);
|
|
5518
5541
|
}
|
|
5519
|
-
a ||=
|
|
5542
|
+
a ||= gs(null, r || Ps), a !== "openai" && a !== "anthropic" && a !== "opencode" && !i.has(a) && (a = "openai"), this.provider = a;
|
|
5520
5543
|
let o = t.observerRuntime;
|
|
5521
|
-
this.runtime = (typeof o == "string" && o.trim().toLowerCase(), "api_http"), r ? this.model = r : a === "anthropic" ? this.model =
|
|
5544
|
+
this.runtime = (typeof o == "string" && o.trim().toLowerCase(), "api_http"), r ? this.model = r : a === "anthropic" ? this.model = Ns : a === "openai" ? this.model = Ps : this.model = ft(a) ?? St(a) ?? "", this.maxChars = t.observerMaxChars, this.maxTokens = t.observerMaxTokens, this._observerHeaders = { ...t.observerHeaders }, this._apiKey = t.observerApiKey ?? null;
|
|
5522
5545
|
let s = t.observerBaseUrl;
|
|
5523
|
-
this._customBaseUrl = typeof s == "string" && s.trim() ? s.trim() : null, this.authAdapter = new
|
|
5546
|
+
this._customBaseUrl = typeof s == "string" && s.trim() ? s.trim() : null, this.authAdapter = new Os({
|
|
5524
5547
|
source: t.observerAuthSource,
|
|
5525
5548
|
filePath: t.observerAuthFile,
|
|
5526
5549
|
command: t.observerAuthCommand,
|
|
@@ -5559,18 +5582,18 @@ var ic = class {
|
|
|
5559
5582
|
let e = await this._callOnce(a, s);
|
|
5560
5583
|
return e && this._clearLastError(), {
|
|
5561
5584
|
raw: e,
|
|
5562
|
-
parsed: e ?
|
|
5585
|
+
parsed: e ? uc(e) : null,
|
|
5563
5586
|
provider: this.provider,
|
|
5564
5587
|
model: this.model
|
|
5565
5588
|
};
|
|
5566
5589
|
} catch (e) {
|
|
5567
|
-
if (e instanceof
|
|
5590
|
+
if (e instanceof Ws) {
|
|
5568
5591
|
if (this.refreshAuth(), !this.auth.token) throw e;
|
|
5569
5592
|
try {
|
|
5570
5593
|
let e = await this._callOnce(a, s);
|
|
5571
5594
|
return e && this._clearLastError(), {
|
|
5572
5595
|
raw: e,
|
|
5573
|
-
parsed: e ?
|
|
5596
|
+
parsed: e ? uc(e) : null,
|
|
5574
5597
|
provider: this.provider,
|
|
5575
5598
|
model: this.model
|
|
5576
5599
|
};
|
|
@@ -5583,11 +5606,11 @@ var ic = class {
|
|
|
5583
5606
|
}
|
|
5584
5607
|
_initProvider(e) {
|
|
5585
5608
|
this._codexAccess = null, this._codexAccountId = null, this._anthropicOAuthAccess = null;
|
|
5586
|
-
let t =
|
|
5609
|
+
let t = hs(), n = null, r = null;
|
|
5587
5610
|
if (this.provider === "openai" || this.provider === "anthropic") {
|
|
5588
|
-
r =
|
|
5589
|
-
let e =
|
|
5590
|
-
n && e != null && e <=
|
|
5611
|
+
r = gs(this.provider, this.model), n = vs(t, r);
|
|
5612
|
+
let e = Ss(t, r);
|
|
5613
|
+
n && e != null && e <= sc() && (n = null);
|
|
5591
5614
|
}
|
|
5592
5615
|
if (this.provider !== "openai" && this.provider !== "anthropic") {
|
|
5593
5616
|
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 +5618,7 @@ var ic = class {
|
|
|
5595
5618
|
...this._observerHeaders,
|
|
5596
5619
|
...a
|
|
5597
5620
|
}), !this._customBaseUrl) return;
|
|
5598
|
-
let o = this.provider === "opencode" ?
|
|
5621
|
+
let o = this.provider === "opencode" ? ys(t, this.provider) : null, s = xt(n) || this._apiKey || o;
|
|
5599
5622
|
this.auth = this.authAdapter.resolve({
|
|
5600
5623
|
explicitToken: s,
|
|
5601
5624
|
envTokens: [process.env.CODEMEM_OBSERVER_API_KEY ?? ""],
|
|
@@ -5615,7 +5638,7 @@ var ic = class {
|
|
|
5615
5638
|
],
|
|
5616
5639
|
oauthToken: n,
|
|
5617
5640
|
forceRefresh: e
|
|
5618
|
-
}), this.auth.source === "oauth" && n && (this._codexAccess = n, this._codexAccountId =
|
|
5641
|
+
}), this.auth.source === "oauth" && n && (this._codexAccess = n, this._codexAccountId = xs(t, r ?? "openai")));
|
|
5619
5642
|
}
|
|
5620
5643
|
async _callOnce(e, t) {
|
|
5621
5644
|
if (this._codexAccess) return this._callCodexConsumer(t);
|
|
@@ -5623,59 +5646,59 @@ var ic = class {
|
|
|
5623
5646
|
if (!this.auth.token) {
|
|
5624
5647
|
if (this._initProvider(!0), this._codexAccess) return this._callCodexConsumer(t);
|
|
5625
5648
|
if (this._anthropicOAuthAccess) return this._callAnthropicConsumer(e, t);
|
|
5626
|
-
if (!this.auth.token) return this._setLastError(`${
|
|
5649
|
+
if (!this.auth.token) return this._setLastError(`${lc(this.provider)} credentials are missing.`, "auth_missing"), null;
|
|
5627
5650
|
}
|
|
5628
5651
|
return this.provider === "anthropic" ? this._callAnthropicDirect(e, t) : this._callOpenAIDirect(e, t);
|
|
5629
5652
|
}
|
|
5630
5653
|
async _callAnthropicDirect(e, t) {
|
|
5631
|
-
let n =
|
|
5654
|
+
let n = qs(), r = Qs(Js(this.auth.token ?? "", !1), Ms(this._observerHeaders, this.auth)), i = Ys(this.model, e, t, this.maxTokens);
|
|
5632
5655
|
return this._fetchJSON(n, r, i, {
|
|
5633
|
-
parseResponse:
|
|
5656
|
+
parseResponse: Xs,
|
|
5634
5657
|
providerLabel: "Anthropic"
|
|
5635
5658
|
});
|
|
5636
5659
|
}
|
|
5637
5660
|
async _callOpenAIDirect(e, t) {
|
|
5638
5661
|
let n;
|
|
5639
5662
|
n = this._customBaseUrl ? `${this._customBaseUrl.replace(/\/+$/, "")}/chat/completions` : "https://api.openai.com/v1/chat/completions";
|
|
5640
|
-
let r =
|
|
5663
|
+
let r = Qs(Zs(this.auth.token ?? ""), Ms(this._observerHeaders, this.auth)), i = ec(this.model, e, t, this.maxTokens);
|
|
5641
5664
|
return this._fetchJSON(n, r, i, {
|
|
5642
|
-
parseResponse:
|
|
5643
|
-
providerLabel:
|
|
5665
|
+
parseResponse: tc,
|
|
5666
|
+
providerLabel: lc(this.provider)
|
|
5644
5667
|
});
|
|
5645
5668
|
}
|
|
5646
5669
|
async _callCodexConsumer(e) {
|
|
5647
5670
|
if (!this._codexAccess) return null;
|
|
5648
|
-
let t =
|
|
5671
|
+
let t = Cs(this._codexAccess, this._codexAccountId);
|
|
5649
5672
|
if (Object.keys(this._observerHeaders).length > 0) {
|
|
5650
5673
|
let e = {
|
|
5651
5674
|
token: this._codexAccess,
|
|
5652
5675
|
authType: "bearer",
|
|
5653
5676
|
source: this.auth.source
|
|
5654
5677
|
};
|
|
5655
|
-
|
|
5678
|
+
$s(t, Ms(this._observerHeaders, e));
|
|
5656
5679
|
}
|
|
5657
5680
|
t["content-type"] = "application/json";
|
|
5658
|
-
let n =
|
|
5659
|
-
return this._fetchSSE(r, t, n,
|
|
5681
|
+
let n = rc(this.model, e), r = nc();
|
|
5682
|
+
return this._fetchSSE(r, t, n, ac, {
|
|
5660
5683
|
providerLabel: "OpenAI",
|
|
5661
5684
|
authErrorMessage: "OpenAI authentication failed. Refresh credentials and retry."
|
|
5662
5685
|
});
|
|
5663
5686
|
}
|
|
5664
5687
|
async _callAnthropicConsumer(e, t) {
|
|
5665
5688
|
if (!this._anthropicOAuthAccess) return null;
|
|
5666
|
-
let n =
|
|
5689
|
+
let n = Js(this._anthropicOAuthAccess, !0);
|
|
5667
5690
|
if (Object.keys(this._observerHeaders).length > 0) {
|
|
5668
5691
|
let e = {
|
|
5669
5692
|
token: this._anthropicOAuthAccess,
|
|
5670
5693
|
authType: "bearer",
|
|
5671
5694
|
source: this.auth.source
|
|
5672
5695
|
};
|
|
5673
|
-
|
|
5696
|
+
$s(n, Ms(this._observerHeaders, e));
|
|
5674
5697
|
}
|
|
5675
|
-
let r =
|
|
5698
|
+
let r = qs(), i = new URL(r);
|
|
5676
5699
|
i.searchParams.set("beta", "true");
|
|
5677
5700
|
let a = i.toString(), o = {
|
|
5678
|
-
model:
|
|
5701
|
+
model: Ks(this.model),
|
|
5679
5702
|
max_tokens: this.maxTokens,
|
|
5680
5703
|
stream: !0,
|
|
5681
5704
|
messages: [{
|
|
@@ -5684,7 +5707,7 @@ var ic = class {
|
|
|
5684
5707
|
}],
|
|
5685
5708
|
system: e
|
|
5686
5709
|
};
|
|
5687
|
-
return this._fetchSSE(a, n, o,
|
|
5710
|
+
return this._fetchSSE(a, n, o, oc, {
|
|
5688
5711
|
providerLabel: "Anthropic",
|
|
5689
5712
|
authErrorMessage: "Anthropic authentication failed. Refresh credentials and retry."
|
|
5690
5713
|
});
|
|
@@ -5695,7 +5718,7 @@ var ic = class {
|
|
|
5695
5718
|
method: "POST",
|
|
5696
5719
|
headers: t,
|
|
5697
5720
|
body: JSON.stringify(n),
|
|
5698
|
-
signal: AbortSignal.timeout(
|
|
5721
|
+
signal: AbortSignal.timeout(Rs)
|
|
5699
5722
|
});
|
|
5700
5723
|
if (!i.ok) {
|
|
5701
5724
|
let e = await i.text().catch(() => "");
|
|
@@ -5704,7 +5727,7 @@ var ic = class {
|
|
|
5704
5727
|
let a = await i.json(), o = r.parseResponse(a);
|
|
5705
5728
|
return o === null && this._setLastError(`${r.providerLabel} returned 200 but response contained no extractable text.`, "empty_response"), o;
|
|
5706
5729
|
} catch (e) {
|
|
5707
|
-
if (e instanceof
|
|
5730
|
+
if (e instanceof Ws) throw e;
|
|
5708
5731
|
return this._setLastError(`${r.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
5709
5732
|
}
|
|
5710
5733
|
}
|
|
@@ -5714,21 +5737,21 @@ var ic = class {
|
|
|
5714
5737
|
method: "POST",
|
|
5715
5738
|
headers: t,
|
|
5716
5739
|
body: JSON.stringify(n),
|
|
5717
|
-
signal: AbortSignal.timeout(
|
|
5740
|
+
signal: AbortSignal.timeout(Rs)
|
|
5718
5741
|
});
|
|
5719
5742
|
if (!a.ok) {
|
|
5720
|
-
if (await a.text().catch(() => ""),
|
|
5743
|
+
if (await a.text().catch(() => ""), Gs(a.status)) throw this._setLastError(i.authErrorMessage, "auth_failed"), new Ws(`${i.providerLabel} auth error: ${a.status}`);
|
|
5721
5744
|
return this._setLastError(`${i.providerLabel} request failed during observer processing.`, "provider_request_failed"), null;
|
|
5722
5745
|
}
|
|
5723
|
-
return
|
|
5746
|
+
return ic(await a.text(), r);
|
|
5724
5747
|
} catch (e) {
|
|
5725
|
-
if (e instanceof
|
|
5748
|
+
if (e instanceof Ws) throw e;
|
|
5726
5749
|
return this._setLastError(`${i.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
5727
5750
|
}
|
|
5728
5751
|
}
|
|
5729
5752
|
_handleHttpError(e, t, n) {
|
|
5730
|
-
let r =
|
|
5731
|
-
if (
|
|
5753
|
+
let r = fs(t);
|
|
5754
|
+
if (Gs(e)) throw this._setLastError(`${n} authentication failed. Refresh credentials and retry.`, "auth_failed"), new Ws(`${n} auth error: ${e}: ${r}`);
|
|
5732
5755
|
if (e === 429) {
|
|
5733
5756
|
this._setLastError(`${n} rate limited. Retry later.`, "rate_limited");
|
|
5734
5757
|
return;
|
|
@@ -5753,10 +5776,10 @@ var ic = class {
|
|
|
5753
5776
|
this._lastErrorCode = null, this._lastErrorMessage = null;
|
|
5754
5777
|
}
|
|
5755
5778
|
};
|
|
5756
|
-
function
|
|
5779
|
+
function lc(e) {
|
|
5757
5780
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
5758
5781
|
}
|
|
5759
|
-
function
|
|
5782
|
+
function uc(e) {
|
|
5760
5783
|
try {
|
|
5761
5784
|
let t = JSON.parse(e);
|
|
5762
5785
|
return typeof t == "object" && t && !Array.isArray(t) ? t : null;
|
|
@@ -5766,10 +5789,10 @@ function oc(e) {
|
|
|
5766
5789
|
}
|
|
5767
5790
|
//#endregion
|
|
5768
5791
|
//#region src/search.ts
|
|
5769
|
-
function
|
|
5792
|
+
function dc(e) {
|
|
5770
5793
|
return N(e, { schema: H });
|
|
5771
5794
|
}
|
|
5772
|
-
var
|
|
5795
|
+
var fc = {
|
|
5773
5796
|
session_summary: .25,
|
|
5774
5797
|
decision: .2,
|
|
5775
5798
|
feature: .18,
|
|
@@ -5781,32 +5804,32 @@ var cc = {
|
|
|
5781
5804
|
observation: .1,
|
|
5782
5805
|
exploration: .1,
|
|
5783
5806
|
entities: .05
|
|
5784
|
-
},
|
|
5807
|
+
}, pc = .45, mc = .18, hc = .12, gc = 3, _c = 0, vc = 2, yc = [
|
|
5785
5808
|
/\bwhat did i\b/i,
|
|
5786
5809
|
/\bmy notes\b/i,
|
|
5787
5810
|
/\bmy last session\b/i,
|
|
5788
5811
|
/\bmy machine\b/i
|
|
5789
|
-
],
|
|
5812
|
+
], bc = new Set([
|
|
5790
5813
|
"or",
|
|
5791
5814
|
"and",
|
|
5792
5815
|
"not",
|
|
5793
5816
|
"near",
|
|
5794
5817
|
"phrase"
|
|
5795
5818
|
]);
|
|
5796
|
-
function
|
|
5819
|
+
function xc(e) {
|
|
5797
5820
|
let t = e.match(/[A-Za-z0-9_]+/g);
|
|
5798
5821
|
if (!t) return "";
|
|
5799
|
-
let n = t.filter((e) => !
|
|
5822
|
+
let n = t.filter((e) => !bc.has(e.toLowerCase()));
|
|
5800
5823
|
return n.length === 0 ? "" : n.length === 1 ? n[0] : n.join(" OR ");
|
|
5801
5824
|
}
|
|
5802
|
-
function
|
|
5825
|
+
function Sc(e, t) {
|
|
5803
5826
|
let n = Date.parse(e);
|
|
5804
5827
|
return Number.isNaN(n) ? 0 : 1 / (1 + Math.max(0, Math.floor(((t ?? /* @__PURE__ */ new Date()).getTime() - n) / 864e5)) / 7);
|
|
5805
5828
|
}
|
|
5806
|
-
function
|
|
5807
|
-
return e ?
|
|
5829
|
+
function Cc(e) {
|
|
5830
|
+
return e ? fc[e.trim().toLowerCase()] ?? 0 : 0;
|
|
5808
5831
|
}
|
|
5809
|
-
function
|
|
5832
|
+
function wc(e) {
|
|
5810
5833
|
if (!e || e.personal_first === void 0) return !0;
|
|
5811
5834
|
let t = e.personal_first;
|
|
5812
5835
|
if (typeof t == "string") {
|
|
@@ -5826,10 +5849,10 @@ function bc(e) {
|
|
|
5826
5849
|
}
|
|
5827
5850
|
return !!t;
|
|
5828
5851
|
}
|
|
5829
|
-
function
|
|
5852
|
+
function Tc(e) {
|
|
5830
5853
|
return String(e?.trust_bias ?? "off").trim().toLowerCase() === "soft" ? "soft" : "off";
|
|
5831
5854
|
}
|
|
5832
|
-
function
|
|
5855
|
+
function Ec(e) {
|
|
5833
5856
|
if (!e || e.widen_shared_when_weak === void 0) return !1;
|
|
5834
5857
|
let t = e.widen_shared_when_weak;
|
|
5835
5858
|
if (typeof t == "string") {
|
|
@@ -5849,25 +5872,25 @@ function Sc(e) {
|
|
|
5849
5872
|
}
|
|
5850
5873
|
return !!t;
|
|
5851
5874
|
}
|
|
5852
|
-
function
|
|
5875
|
+
function Dc(e) {
|
|
5853
5876
|
let t = e?.widen_shared_min_personal_results;
|
|
5854
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5877
|
+
return typeof t != "number" || !Number.isFinite(t) ? gc : Math.max(1, Math.trunc(t));
|
|
5855
5878
|
}
|
|
5856
|
-
function
|
|
5879
|
+
function Oc(e) {
|
|
5857
5880
|
let t = e?.widen_shared_min_personal_score;
|
|
5858
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5881
|
+
return typeof t != "number" || !Number.isFinite(t) ? _c : Math.max(0, t);
|
|
5859
5882
|
}
|
|
5860
|
-
function
|
|
5861
|
-
return
|
|
5883
|
+
function kc(e) {
|
|
5884
|
+
return yc.some((t) => t.test(e));
|
|
5862
5885
|
}
|
|
5863
|
-
function
|
|
5886
|
+
function Ac(e) {
|
|
5864
5887
|
if (!e) return !1;
|
|
5865
5888
|
let t = String(e.ownership_scope ?? "").trim().toLowerCase();
|
|
5866
5889
|
if (t === "mine" || t === "theirs") return !0;
|
|
5867
5890
|
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
5891
|
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
5892
|
}
|
|
5870
|
-
function
|
|
5893
|
+
function jc(e) {
|
|
5871
5894
|
return {
|
|
5872
5895
|
...e ?? {},
|
|
5873
5896
|
visibility: void 0,
|
|
@@ -5878,7 +5901,7 @@ function Dc(e) {
|
|
|
5878
5901
|
widen_shared_when_weak: !1
|
|
5879
5902
|
};
|
|
5880
5903
|
}
|
|
5881
|
-
function
|
|
5904
|
+
function Mc(e) {
|
|
5882
5905
|
return e.map((e) => ({
|
|
5883
5906
|
...e,
|
|
5884
5907
|
metadata: {
|
|
@@ -5887,83 +5910,83 @@ function Oc(e) {
|
|
|
5887
5910
|
}
|
|
5888
5911
|
}));
|
|
5889
5912
|
}
|
|
5890
|
-
function
|
|
5891
|
-
return
|
|
5913
|
+
function Nc(e, t, n) {
|
|
5914
|
+
return wc(n) && e.memoryOwnedBySelf(t) ? pc : 0;
|
|
5892
5915
|
}
|
|
5893
|
-
function
|
|
5894
|
-
if (
|
|
5916
|
+
function Pc(e, t, n) {
|
|
5917
|
+
if (Tc(n) !== "soft" || e.memoryOwnedBySelf(t)) return 0;
|
|
5895
5918
|
let r = t.metadata ?? {}, i = String(r.visibility ?? "").trim().toLowerCase(), a = String(r.workspace_kind ?? "").trim().toLowerCase();
|
|
5896
5919
|
if (i !== "shared" && a !== "shared") return 0;
|
|
5897
5920
|
let o = String(r.trust_state ?? "trusted").trim().toLowerCase();
|
|
5898
|
-
return o === "legacy_unknown" ?
|
|
5921
|
+
return o === "legacy_unknown" ? mc : o === "unreviewed" ? hc : 0;
|
|
5899
5922
|
}
|
|
5900
|
-
function
|
|
5923
|
+
function Fc(e) {
|
|
5901
5924
|
let t = e.trim().replaceAll("\\", "/");
|
|
5902
5925
|
t.startsWith("./") && (t = t.slice(2));
|
|
5903
5926
|
let n = t.split("/").filter((e) => e && e !== ".");
|
|
5904
5927
|
return n.length === 0 ? "" : n.join("/").toLowerCase();
|
|
5905
5928
|
}
|
|
5906
|
-
function
|
|
5907
|
-
let t =
|
|
5929
|
+
function Ic(e) {
|
|
5930
|
+
let t = Fc(e);
|
|
5908
5931
|
return t ? t.split("/") : [];
|
|
5909
5932
|
}
|
|
5910
|
-
function
|
|
5911
|
-
let t =
|
|
5933
|
+
function Lc(e) {
|
|
5934
|
+
let t = Ic(e);
|
|
5912
5935
|
return t.length === 0 ? "" : t[t.length - 1] ?? "";
|
|
5913
5936
|
}
|
|
5914
|
-
function
|
|
5937
|
+
function Rc(e, t) {
|
|
5915
5938
|
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
5939
|
}
|
|
5917
|
-
function
|
|
5940
|
+
function zc(e) {
|
|
5918
5941
|
if (!Array.isArray(e)) return [];
|
|
5919
5942
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
5920
5943
|
for (let r of e) {
|
|
5921
5944
|
if (typeof r != "string") continue;
|
|
5922
|
-
let e =
|
|
5945
|
+
let e = Fc(r);
|
|
5923
5946
|
!e || n.has(e) || (n.add(e), t.push(e));
|
|
5924
5947
|
}
|
|
5925
5948
|
return t;
|
|
5926
5949
|
}
|
|
5927
|
-
function
|
|
5950
|
+
function Bc(e) {
|
|
5928
5951
|
let t = (e.metadata ?? {}).files_modified;
|
|
5929
5952
|
if (!Array.isArray(t)) return [];
|
|
5930
5953
|
let n = [];
|
|
5931
5954
|
for (let e of t) {
|
|
5932
5955
|
if (typeof e != "string") continue;
|
|
5933
|
-
let t =
|
|
5956
|
+
let t = Fc(e);
|
|
5934
5957
|
t && n.push(t);
|
|
5935
5958
|
}
|
|
5936
5959
|
return n;
|
|
5937
5960
|
}
|
|
5938
|
-
function
|
|
5961
|
+
function Vc(e, t) {
|
|
5939
5962
|
if (t.length === 0) return 0;
|
|
5940
|
-
let n =
|
|
5963
|
+
let n = Bc(e);
|
|
5941
5964
|
if (n.length === 0) return 0;
|
|
5942
|
-
let r = [...new Set(n)].map((e) =>
|
|
5943
|
-
for (let e of r) i.some((t) =>
|
|
5965
|
+
let r = [...new Set(n)].map((e) => Ic(e)), i = [...new Set(t)].map((e) => Ic(e)), a = new Set(n.map((e) => Lc(e)).filter(Boolean)), o = new Set(t.map((e) => Lc(e)).filter(Boolean)), s = 0;
|
|
5966
|
+
for (let e of r) i.some((t) => Rc(e, t)) && (s += 1);
|
|
5944
5967
|
let c = 0;
|
|
5945
5968
|
for (let e of a) o.has(e) && (c += 1);
|
|
5946
5969
|
let l = s * .16 + c * .06;
|
|
5947
5970
|
return Math.min(.32, l);
|
|
5948
5971
|
}
|
|
5949
|
-
function
|
|
5950
|
-
let i = /* @__PURE__ */ new Date(), a =
|
|
5972
|
+
function Hc(e, t, n, r) {
|
|
5973
|
+
let i = /* @__PURE__ */ new Date(), a = zc(r?.working_set_paths), o = t.map((t) => ({
|
|
5951
5974
|
item: t,
|
|
5952
|
-
combinedScore: t.score * 1.5 +
|
|
5975
|
+
combinedScore: t.score * 1.5 + Sc(t.created_at, i) + Cc(t.kind) + Vc(t, a) + Nc(e, t, r) - Pc(e, t, r)
|
|
5953
5976
|
}));
|
|
5954
5977
|
return o.sort((e, t) => t.combinedScore - e.combinedScore), o.slice(0, n).map((e) => e.item);
|
|
5955
5978
|
}
|
|
5956
|
-
function
|
|
5957
|
-
let i =
|
|
5958
|
-
if (!
|
|
5979
|
+
function Uc(e, t, n = 10, r) {
|
|
5980
|
+
let i = Wc(e, t, n, r);
|
|
5981
|
+
if (!Ec(r) || !t || kc(t) || Ac(r)) return i;
|
|
5959
5982
|
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 >=
|
|
5983
|
+
if (a.length >= Dc(r) && o >= Oc(r)) return i;
|
|
5984
|
+
let s = Mc(Wc(e, t, vc, jc(r)).filter((t) => !e.memoryOwnedBySelf(t))), c = new Set(i.map((e) => e.id)), l = [...i], u = 0;
|
|
5985
|
+
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >= vc)) break;
|
|
5963
5986
|
return l;
|
|
5964
5987
|
}
|
|
5965
|
-
function
|
|
5966
|
-
let i = Math.max(1, Math.trunc(n)), a =
|
|
5988
|
+
function Wc(e, t, n = 10, r) {
|
|
5989
|
+
let i = Math.max(1, Math.trunc(n)), a = xc(t);
|
|
5967
5990
|
if (!a) return [];
|
|
5968
5991
|
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
5992
|
actorId: e.actorId,
|
|
@@ -5981,7 +6004,7 @@ function Bc(e, t, n = 10, r) {
|
|
|
5981
6004
|
ORDER BY (score * 1.5 + recency) DESC, memory_items.created_at DESC, memory_items.id DESC
|
|
5982
6005
|
LIMIT ?
|
|
5983
6006
|
`;
|
|
5984
|
-
return s.push(o),
|
|
6007
|
+
return s.push(o), Hc(e, e.db.prepare(d).all(...s).map((e) => {
|
|
5985
6008
|
let t = { ...z(e.metadata_json) };
|
|
5986
6009
|
for (let n of [
|
|
5987
6010
|
"actor_id",
|
|
@@ -6015,7 +6038,7 @@ function Bc(e, t, n = 10, r) {
|
|
|
6015
6038
|
};
|
|
6016
6039
|
}), i, r);
|
|
6017
6040
|
}
|
|
6018
|
-
function
|
|
6041
|
+
function Gc(e, t, n, r = 3, i = 3, a) {
|
|
6019
6042
|
let o = null;
|
|
6020
6043
|
if (n != null) {
|
|
6021
6044
|
let t = e.get(n);
|
|
@@ -6026,7 +6049,7 @@ function Vc(e, t, n, r = 3, i = 3, a) {
|
|
|
6026
6049
|
});
|
|
6027
6050
|
}
|
|
6028
6051
|
if (o == null && t) {
|
|
6029
|
-
let n =
|
|
6052
|
+
let n = Uc(e, t, 1, a ?? void 0);
|
|
6030
6053
|
if (n.length > 0) {
|
|
6031
6054
|
let e = n[0];
|
|
6032
6055
|
o = {
|
|
@@ -6036,9 +6059,9 @@ function Vc(e, t, n, r = 3, i = 3, a) {
|
|
|
6036
6059
|
};
|
|
6037
6060
|
}
|
|
6038
6061
|
}
|
|
6039
|
-
return o == null ? [] :
|
|
6062
|
+
return o == null ? [] : Kc(e, o, r, i, a);
|
|
6040
6063
|
}
|
|
6041
|
-
function
|
|
6064
|
+
function Kc(e, t, n, r, i) {
|
|
6042
6065
|
let a = t.id, o = t.created_at, s = t.session_id;
|
|
6043
6066
|
if (!a || !o) return [];
|
|
6044
6067
|
let c = Na(i, {
|
|
@@ -6056,7 +6079,7 @@ function Hc(e, t, n, r, i) {
|
|
|
6056
6079
|
${f}
|
|
6057
6080
|
WHERE ${d} AND memory_items.created_at > ?
|
|
6058
6081
|
ORDER BY memory_items.created_at ASC
|
|
6059
|
-
LIMIT ?`).all(...u, o, r), h =
|
|
6082
|
+
LIMIT ?`).all(...u, o, r), h = dc(e.db).select().from(W).where(D(k(W.id, a), k(W.active, 1))).get(), g = [...p.reverse()];
|
|
6060
6083
|
return h && g.push(h), g.push(...m), g.map((e) => {
|
|
6061
6084
|
let { metadata_json: t, ...n } = e;
|
|
6062
6085
|
return {
|
|
@@ -6066,10 +6089,10 @@ function Hc(e, t, n, r, i) {
|
|
|
6066
6089
|
};
|
|
6067
6090
|
});
|
|
6068
6091
|
}
|
|
6069
|
-
function
|
|
6092
|
+
function qc(e) {
|
|
6070
6093
|
let t = /* @__PURE__ */ new Set(), n = [], r = [];
|
|
6071
6094
|
for (let i of e) {
|
|
6072
|
-
let e =
|
|
6095
|
+
let e = ls(i);
|
|
6073
6096
|
if (e == null) {
|
|
6074
6097
|
r.push(String(i));
|
|
6075
6098
|
continue;
|
|
@@ -6081,8 +6104,8 @@ function Uc(e) {
|
|
|
6081
6104
|
invalid: r
|
|
6082
6105
|
};
|
|
6083
6106
|
}
|
|
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 =
|
|
6107
|
+
function Jc(e, t, n, r, i, a, o, s) {
|
|
6108
|
+
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 = Sc(e.created_at, s), f = Cc(e.kind), p = null;
|
|
6086
6109
|
return u != null && (p = u * 1.5 + d + f), {
|
|
6087
6110
|
id: e.id,
|
|
6088
6111
|
kind: e.kind,
|
|
@@ -6113,14 +6136,14 @@ function Wc(e, t, n, r, i, a, o, s) {
|
|
|
6113
6136
|
} : null
|
|
6114
6137
|
};
|
|
6115
6138
|
}
|
|
6116
|
-
function
|
|
6139
|
+
function Yc(e, t, n) {
|
|
6117
6140
|
if (t.length === 0) return {
|
|
6118
6141
|
items: [],
|
|
6119
6142
|
missingNotFound: [],
|
|
6120
6143
|
missingProjectMismatch: [],
|
|
6121
6144
|
missingFilterMismatch: []
|
|
6122
6145
|
};
|
|
6123
|
-
let r =
|
|
6146
|
+
let r = dc(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
6147
|
if (n.project) {
|
|
6125
6148
|
let r = Na({ project: n.project }, {
|
|
6126
6149
|
actorId: e.actorId,
|
|
@@ -6166,16 +6189,16 @@ function Gc(e, t, n) {
|
|
|
6166
6189
|
missingFilterMismatch: m
|
|
6167
6190
|
};
|
|
6168
6191
|
}
|
|
6169
|
-
function
|
|
6192
|
+
function Xc(e, t) {
|
|
6170
6193
|
if (t.size === 0) return /* @__PURE__ */ new Map();
|
|
6171
|
-
let n = [...t].sort((e, t) => e - t), r =
|
|
6194
|
+
let n = [...t].sort((e, t) => e - t), r = dc(e.db).select({
|
|
6172
6195
|
id: U.id,
|
|
6173
6196
|
project: U.project
|
|
6174
6197
|
}).from(U).where(j(U.id, n)).all();
|
|
6175
6198
|
return new Map(r.map((e) => [e.id, e.project]));
|
|
6176
6199
|
}
|
|
6177
|
-
function
|
|
6178
|
-
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } =
|
|
6200
|
+
function Zc(e, t, n, r = 10, i, a) {
|
|
6201
|
+
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } = qc(n ?? []), u = [];
|
|
6179
6202
|
if (l.length > 0 && u.push({
|
|
6180
6203
|
code: "INVALID_ARGUMENT",
|
|
6181
6204
|
field: "ids",
|
|
@@ -6198,10 +6221,10 @@ function qc(e, t, n, r = 10, i, a) {
|
|
|
6198
6221
|
}
|
|
6199
6222
|
};
|
|
6200
6223
|
let d = [];
|
|
6201
|
-
s && (d =
|
|
6224
|
+
s && (d = Uc(e, s, Math.max(1, Math.trunc(r)), i ?? void 0));
|
|
6202
6225
|
let f = /* @__PURE__ */ new Map();
|
|
6203
6226
|
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 } =
|
|
6227
|
+
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } = Yc(e, c, i ?? {}), _ = new Map(p.map((e) => [e.id, e])), v = new Set(c), y = /* @__PURE__ */ new Set(), b = [];
|
|
6205
6228
|
for (let e of d) {
|
|
6206
6229
|
y.add(e.id);
|
|
6207
6230
|
let t = v.has(e.id) ? "query+id_lookup" : "query";
|
|
@@ -6220,7 +6243,7 @@ function qc(e, t, n, r = 10, i, a) {
|
|
|
6220
6243
|
rank: null
|
|
6221
6244
|
}), y.add(e));
|
|
6222
6245
|
}
|
|
6223
|
-
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S =
|
|
6246
|
+
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S = Xc(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 }) => Jc(e, t, n, x, i?.project ?? null, S.get(e.session_id) ?? null, o, C)), T = c.filter((e) => !y.has(e));
|
|
6224
6247
|
return m.length > 0 && u.push({
|
|
6225
6248
|
code: "NOT_FOUND",
|
|
6226
6249
|
field: "ids",
|
|
@@ -6251,7 +6274,7 @@ function qc(e, t, n, r = 10, i, a) {
|
|
|
6251
6274
|
}
|
|
6252
6275
|
//#endregion
|
|
6253
6276
|
//#region src/pack.ts
|
|
6254
|
-
var
|
|
6277
|
+
var Qc = {
|
|
6255
6278
|
decision: 0,
|
|
6256
6279
|
feature: 1,
|
|
6257
6280
|
bugfix: 2,
|
|
@@ -6260,11 +6283,11 @@ var Jc = {
|
|
|
6260
6283
|
discovery: 5,
|
|
6261
6284
|
exploration: 6,
|
|
6262
6285
|
note: 7
|
|
6263
|
-
},
|
|
6264
|
-
function
|
|
6286
|
+
}, $c = 365, el = "todo todos task tasks pending follow up follow-up next resume continue backlog pick up pick-up", tl = "session summary recap remember last time previous work";
|
|
6287
|
+
function nl(e) {
|
|
6265
6288
|
return Math.ceil(e.length / 4);
|
|
6266
6289
|
}
|
|
6267
|
-
function
|
|
6290
|
+
function rl(e) {
|
|
6268
6291
|
let t = [
|
|
6269
6292
|
`[${e.id}]`,
|
|
6270
6293
|
`(${e.kind})`,
|
|
@@ -6272,11 +6295,11 @@ function $c(e) {
|
|
|
6272
6295
|
];
|
|
6273
6296
|
return e.body_text && t.push("-", e.body_text), t.join(" ");
|
|
6274
6297
|
}
|
|
6275
|
-
function
|
|
6298
|
+
function il(e, t) {
|
|
6276
6299
|
let n = `## ${e}`;
|
|
6277
|
-
return t.length === 0 ? `${n}\n` : [n, ...t.map(
|
|
6300
|
+
return t.length === 0 ? `${n}\n` : [n, ...t.map(rl)].join("\n");
|
|
6278
6301
|
}
|
|
6279
|
-
function
|
|
6302
|
+
function al(e, t) {
|
|
6280
6303
|
let n = t?.duplicateIds.get(e.id), r = {
|
|
6281
6304
|
id: e.id,
|
|
6282
6305
|
kind: e.kind,
|
|
@@ -6288,18 +6311,18 @@ function tl(e, t) {
|
|
|
6288
6311
|
};
|
|
6289
6312
|
return n && n.size > 0 && (r.support_count = 1 + n.size, r.duplicate_ids = [...n].sort((e, t) => e - t)), r;
|
|
6290
6313
|
}
|
|
6291
|
-
function
|
|
6314
|
+
function ol(e) {
|
|
6292
6315
|
return e.trim().toLowerCase().split(/\s+/).join(" ");
|
|
6293
6316
|
}
|
|
6294
|
-
function
|
|
6317
|
+
function sl(e) {
|
|
6295
6318
|
if (e.kind === "session_summary") return null;
|
|
6296
|
-
let t =
|
|
6319
|
+
let t = ol(e.title), n = ol(e.body_text);
|
|
6297
6320
|
return !t && !n ? null : `${e.kind.length}:${e.kind}|${t.length}:${t}|${n.length}:${n}`;
|
|
6298
6321
|
}
|
|
6299
|
-
function
|
|
6322
|
+
function cl(e, t) {
|
|
6300
6323
|
let n = [];
|
|
6301
6324
|
for (let r of e) {
|
|
6302
|
-
let e =
|
|
6325
|
+
let e = sl(r);
|
|
6303
6326
|
if (e === null) {
|
|
6304
6327
|
n.push(r);
|
|
6305
6328
|
continue;
|
|
@@ -6318,19 +6341,19 @@ function il(e, t) {
|
|
|
6318
6341
|
}
|
|
6319
6342
|
return n;
|
|
6320
6343
|
}
|
|
6321
|
-
function
|
|
6344
|
+
function ll(e, t) {
|
|
6322
6345
|
let n = new Set((t.toLowerCase().match(/[a-z0-9_]+/g) ?? []).filter(Boolean));
|
|
6323
6346
|
return n.size === 0 ? e : [...e].sort((e, t) => {
|
|
6324
|
-
let r =
|
|
6347
|
+
let r = ul(e.tags_text, n), i = ul(t.tags_text, n);
|
|
6325
6348
|
return i === r ? (t.created_at ?? "").localeCompare(e.created_at ?? "") : i - r;
|
|
6326
6349
|
});
|
|
6327
6350
|
}
|
|
6328
|
-
function
|
|
6351
|
+
function ul(e, t) {
|
|
6329
6352
|
let n = new Set(e.split(/\s+/).filter(Boolean)), r = 0;
|
|
6330
6353
|
for (let e of t) n.has(e) && r++;
|
|
6331
6354
|
return r;
|
|
6332
6355
|
}
|
|
6333
|
-
function
|
|
6356
|
+
function dl(e) {
|
|
6334
6357
|
let t = e.toLowerCase();
|
|
6335
6358
|
for (let e of [
|
|
6336
6359
|
"todo",
|
|
@@ -6357,7 +6380,7 @@ function sl(e) {
|
|
|
6357
6380
|
]) if (t.includes(e)) return !0;
|
|
6358
6381
|
return !1;
|
|
6359
6382
|
}
|
|
6360
|
-
function
|
|
6383
|
+
function fl(e) {
|
|
6361
6384
|
let t = e.toLowerCase();
|
|
6362
6385
|
for (let e of [
|
|
6363
6386
|
"remember",
|
|
@@ -6381,7 +6404,7 @@ function cl(e) {
|
|
|
6381
6404
|
]) if (t.includes(e)) return !0;
|
|
6382
6405
|
return !1;
|
|
6383
6406
|
}
|
|
6384
|
-
function
|
|
6407
|
+
function pl(e) {
|
|
6385
6408
|
return {
|
|
6386
6409
|
id: e.id,
|
|
6387
6410
|
kind: e.kind,
|
|
@@ -6396,57 +6419,57 @@ function ll(e) {
|
|
|
6396
6419
|
metadata: e.metadata_json
|
|
6397
6420
|
};
|
|
6398
6421
|
}
|
|
6399
|
-
function
|
|
6422
|
+
function ml(e) {
|
|
6400
6423
|
let t = Date.parse(e);
|
|
6401
6424
|
return Number.isNaN(t) ? -Infinity : t;
|
|
6402
6425
|
}
|
|
6403
|
-
function
|
|
6426
|
+
function hl(e, t) {
|
|
6404
6427
|
let n = Date.now() - t * 864e5;
|
|
6405
|
-
return e.filter((e) =>
|
|
6428
|
+
return e.filter((e) => ml(e.created_at) >= n);
|
|
6406
6429
|
}
|
|
6407
|
-
function
|
|
6430
|
+
function gl(e, t) {
|
|
6408
6431
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6409
6432
|
return n.sort((e, t) => {
|
|
6410
6433
|
let n = (e) => e === "note" ? 0 : e === "decision" ? 1 : e === "observation" ? 2 : 3;
|
|
6411
6434
|
return n(e.kind) - n(t.kind);
|
|
6412
6435
|
}), n.slice(0, t);
|
|
6413
6436
|
}
|
|
6414
|
-
function
|
|
6437
|
+
function _l(e, t) {
|
|
6415
6438
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6416
6439
|
return n.sort((e, t) => {
|
|
6417
6440
|
let n = (e) => e === "session_summary" ? 0 : e === "decision" ? 1 : e === "note" ? 2 : e === "observation" ? 3 : e === "entities" ? 4 : 5;
|
|
6418
6441
|
return n(e.kind) - n(t.kind);
|
|
6419
6442
|
}), n.slice(0, t);
|
|
6420
6443
|
}
|
|
6421
|
-
function
|
|
6444
|
+
function vl(e, t, n) {
|
|
6422
6445
|
let r = Math.max(t * 3, t);
|
|
6423
|
-
return
|
|
6446
|
+
return gl(e.recent(r, n ?? null).map(pl), t);
|
|
6424
6447
|
}
|
|
6425
|
-
function
|
|
6448
|
+
function yl(e, t, n) {
|
|
6426
6449
|
let r = {
|
|
6427
6450
|
...n ?? {},
|
|
6428
6451
|
kind: "session_summary"
|
|
6429
|
-
}, i = e.recent(t, r).map(
|
|
6452
|
+
}, i = e.recent(t, r).map(pl);
|
|
6430
6453
|
if (i.length >= t) return i.slice(0, t);
|
|
6431
|
-
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(
|
|
6454
|
+
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(pl), s = new Set(i.map((e) => e.id)), c = gl(o.filter((e) => !s.has(e.id)), t - i.length);
|
|
6432
6455
|
return [...i, ...c];
|
|
6433
6456
|
}
|
|
6434
|
-
function
|
|
6457
|
+
function bl(e) {
|
|
6435
6458
|
if (e == null || typeof e == "boolean") return null;
|
|
6436
6459
|
let t = Number(e);
|
|
6437
6460
|
if (!Number.isFinite(t)) return null;
|
|
6438
6461
|
let n = Math.trunc(t);
|
|
6439
6462
|
return n < 0 ? null : n;
|
|
6440
6463
|
}
|
|
6441
|
-
function
|
|
6464
|
+
function xl(e) {
|
|
6442
6465
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
6443
6466
|
for (let r of e) {
|
|
6444
|
-
let e =
|
|
6467
|
+
let e = bl(r);
|
|
6445
6468
|
e == null || e <= 0 || n.has(e) || (n.add(e), t.push(e));
|
|
6446
6469
|
}
|
|
6447
6470
|
return t;
|
|
6448
6471
|
}
|
|
6449
|
-
function
|
|
6472
|
+
function Sl(e) {
|
|
6450
6473
|
if (!Array.isArray(e)) return {
|
|
6451
6474
|
ids: [],
|
|
6452
6475
|
valid: !1
|
|
@@ -6456,11 +6479,11 @@ function vl(e) {
|
|
|
6456
6479
|
valid: !1
|
|
6457
6480
|
};
|
|
6458
6481
|
return {
|
|
6459
|
-
ids:
|
|
6482
|
+
ids: xl(e),
|
|
6460
6483
|
valid: !0
|
|
6461
6484
|
};
|
|
6462
6485
|
}
|
|
6463
|
-
function
|
|
6486
|
+
function Cl(e) {
|
|
6464
6487
|
if (!e) return {};
|
|
6465
6488
|
if (typeof e == "string") try {
|
|
6466
6489
|
let t = JSON.parse(e);
|
|
@@ -6470,7 +6493,7 @@ function yl(e) {
|
|
|
6470
6493
|
}
|
|
6471
6494
|
return typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
6472
6495
|
}
|
|
6473
|
-
function
|
|
6496
|
+
function wl(e, t) {
|
|
6474
6497
|
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
6498
|
FROM usage_events
|
|
6476
6499
|
WHERE event = 'pack'
|
|
@@ -6478,15 +6501,15 @@ function bl(e, t) {
|
|
|
6478
6501
|
ORDER BY created_at DESC
|
|
6479
6502
|
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
6503
|
for (let e of i) {
|
|
6481
|
-
let r =
|
|
6504
|
+
let r = Cl(e.metadata_json);
|
|
6482
6505
|
if (t != null) {
|
|
6483
6506
|
let e = typeof r.project == "string" ? r.project : null;
|
|
6484
6507
|
if (e !== t && e !== n) continue;
|
|
6485
6508
|
}
|
|
6486
6509
|
if (!("pack_item_ids" in r)) continue;
|
|
6487
|
-
let { ids: i, valid: a } =
|
|
6510
|
+
let { ids: i, valid: a } = Sl(r.pack_item_ids);
|
|
6488
6511
|
if (!a) continue;
|
|
6489
|
-
let o =
|
|
6512
|
+
let o = bl(r.pack_tokens) ?? bl(e.tokens_read);
|
|
6490
6513
|
if (o != null) return {
|
|
6491
6514
|
previousPackIds: i,
|
|
6492
6515
|
previousPackTokens: o
|
|
@@ -6497,20 +6520,20 @@ function bl(e, t) {
|
|
|
6497
6520
|
previousPackTokens: null
|
|
6498
6521
|
};
|
|
6499
6522
|
}
|
|
6500
|
-
function
|
|
6523
|
+
function Tl(e, t) {
|
|
6501
6524
|
if (!t) return null;
|
|
6502
6525
|
let n = qt(t);
|
|
6503
6526
|
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
6527
|
}
|
|
6505
|
-
function
|
|
6506
|
-
return
|
|
6528
|
+
function El(e) {
|
|
6529
|
+
return bl(Cl(e.metadata).discovery_tokens) ?? Math.max(2e3, nl(`${e.title} ${e.body_text}`.trim()));
|
|
6507
6530
|
}
|
|
6508
|
-
function
|
|
6509
|
-
let t =
|
|
6531
|
+
function Dl(e) {
|
|
6532
|
+
let t = Cl(e.metadata).discovery_group;
|
|
6510
6533
|
return typeof t == "string" && t.trim().length > 0 ? t.trim() : `memory:${e.id}`;
|
|
6511
6534
|
}
|
|
6512
|
-
function
|
|
6513
|
-
let t =
|
|
6535
|
+
function Ol(e) {
|
|
6536
|
+
let t = Cl(e.metadata), n = bl(t.discovery_tokens);
|
|
6514
6537
|
return n != null && n > 0 ? {
|
|
6515
6538
|
tokens: n,
|
|
6516
6539
|
source: typeof t.discovery_source == "string" && t.discovery_source ? t.discovery_source : "known"
|
|
@@ -6519,16 +6542,16 @@ function wl(e) {
|
|
|
6519
6542
|
source: "unknown"
|
|
6520
6543
|
};
|
|
6521
6544
|
}
|
|
6522
|
-
function
|
|
6523
|
-
return
|
|
6545
|
+
function kl(e) {
|
|
6546
|
+
return Cl(e.metadata).discovery_source === "usage" ? "usage" : "estimate";
|
|
6524
6547
|
}
|
|
6525
|
-
function
|
|
6526
|
-
let n = (/* @__PURE__ */ new Date()).toISOString(), r =
|
|
6548
|
+
function Al(e, t) {
|
|
6549
|
+
let n = (/* @__PURE__ */ new Date()).toISOString(), r = bl(t.pack_tokens) ?? 0, i = bl(t.tokens_saved) ?? 0, a = Tl(e, typeof t.project == "string" ? t.project : null);
|
|
6527
6550
|
try {
|
|
6528
6551
|
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
6552
|
} catch {}
|
|
6530
6553
|
}
|
|
6531
|
-
function
|
|
6554
|
+
function jl(e, t, n, r, i) {
|
|
6532
6555
|
let a = /* @__PURE__ */ new Map();
|
|
6533
6556
|
for (let e of t) {
|
|
6534
6557
|
let t = a.get(e.id);
|
|
@@ -6541,46 +6564,46 @@ function Dl(e, t, n, r, i) {
|
|
|
6541
6564
|
(!t || e.score > t.score) && a.set(e.id, e);
|
|
6542
6565
|
}
|
|
6543
6566
|
return {
|
|
6544
|
-
merged:
|
|
6567
|
+
merged: Hc(e, [...a.values()], r, i),
|
|
6545
6568
|
ftsCount: t.length,
|
|
6546
6569
|
semanticCount: o
|
|
6547
6570
|
};
|
|
6548
6571
|
}
|
|
6549
|
-
function
|
|
6550
|
-
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d =
|
|
6572
|
+
function Ml(e, t, n = 10, r = null, i, a) {
|
|
6573
|
+
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d = dl(t), f = !d && fl(t);
|
|
6551
6574
|
if (d) {
|
|
6552
|
-
let n =
|
|
6575
|
+
let n = Uc(e, `${t} ${el}`.trim(), o, i);
|
|
6553
6576
|
if (c = n.length, a && a.length > 0) {
|
|
6554
|
-
let t =
|
|
6577
|
+
let t = jl(e, n, a, o, i);
|
|
6555
6578
|
n = t.merged, l = t.semanticCount;
|
|
6556
6579
|
}
|
|
6557
|
-
if (n.length === 0) s = !0, u =
|
|
6580
|
+
if (n.length === 0) s = !0, u = vl(e, o, i);
|
|
6558
6581
|
else {
|
|
6559
|
-
let e =
|
|
6560
|
-
u =
|
|
6582
|
+
let e = hl(n, $c);
|
|
6583
|
+
u = gl(e.length > 0 ? e : n, o);
|
|
6561
6584
|
}
|
|
6562
6585
|
} else if (f) {
|
|
6563
|
-
let n =
|
|
6564
|
-
if (c = n.length, n.length === 0 && (n =
|
|
6586
|
+
let n = Uc(e, t.trim().length > 0 ? t : tl, o, i);
|
|
6587
|
+
if (c = n.length, n.length === 0 && (n = Uc(e, tl, o, {
|
|
6565
6588
|
...i ?? {},
|
|
6566
6589
|
kind: "session_summary"
|
|
6567
6590
|
}), c = n.length), a && a.length > 0) {
|
|
6568
|
-
let t =
|
|
6591
|
+
let t = jl(e, n, a, o, i);
|
|
6569
6592
|
n = t.merged, l = t.semanticCount;
|
|
6570
6593
|
}
|
|
6571
|
-
u =
|
|
6594
|
+
u = _l(n, o), u.length === 0 && (s = !0, u = yl(e, o, i));
|
|
6572
6595
|
let r = u[0]?.id;
|
|
6573
6596
|
if (r != null) {
|
|
6574
|
-
let t = Math.max(0, Math.floor(o / 2)), n =
|
|
6575
|
-
n.length > 0 && (u = n.map(
|
|
6597
|
+
let t = Math.max(0, Math.floor(o / 2)), n = Gc(e, void 0, r, t, Math.max(0, o - t - 1), i ?? null);
|
|
6598
|
+
n.length > 0 && (u = n.map(pl));
|
|
6576
6599
|
}
|
|
6577
6600
|
} else {
|
|
6578
|
-
let n =
|
|
6601
|
+
let n = Uc(e, t, o, i);
|
|
6579
6602
|
if (a && a.length > 0) {
|
|
6580
|
-
let t =
|
|
6603
|
+
let t = jl(e, n, a, o, i);
|
|
6581
6604
|
u = t.merged, c = t.ftsCount, l = t.semanticCount;
|
|
6582
6605
|
} else u = n, c = u.length;
|
|
6583
|
-
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(
|
|
6606
|
+
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(pl));
|
|
6584
6607
|
}
|
|
6585
6608
|
let p = u.filter((e) => e.kind === "session_summary").slice(0, 1);
|
|
6586
6609
|
if (p.length === 0) {
|
|
@@ -6605,7 +6628,7 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6605
6628
|
}];
|
|
6606
6629
|
}
|
|
6607
6630
|
}
|
|
6608
|
-
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(
|
|
6631
|
+
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(Qc), _ = [...u].filter((e) => e.kind !== "session_summary" && !h.has(e.id)).sort((e, t) => (Qc[e.kind] ?? 99) - (Qc[t.kind] ?? 99));
|
|
6609
6632
|
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
6633
|
id: e.id,
|
|
6611
6634
|
kind: e.kind,
|
|
@@ -6618,55 +6641,55 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6618
6641
|
score: 0,
|
|
6619
6642
|
session_id: e.session_id,
|
|
6620
6643
|
metadata: e.metadata_json
|
|
6621
|
-
}))), _.length === 0 && (_ = [...m]), _ =
|
|
6644
|
+
}))), _.length === 0 && (_ = [...m]), _ = ll(_, t);
|
|
6622
6645
|
let v = {
|
|
6623
6646
|
canonicalByKey: /* @__PURE__ */ new Map(),
|
|
6624
6647
|
duplicateIds: /* @__PURE__ */ new Map()
|
|
6625
6648
|
};
|
|
6626
|
-
p =
|
|
6649
|
+
p = cl(p, v), m = cl(m, v), _ = cl(_, v);
|
|
6627
6650
|
let y = p, b = m, x = _;
|
|
6628
6651
|
if (r != null && r > 0) {
|
|
6629
6652
|
let e = 0;
|
|
6630
6653
|
y = [];
|
|
6631
6654
|
for (let t of p) {
|
|
6632
|
-
let n =
|
|
6655
|
+
let n = nl(rl(t));
|
|
6633
6656
|
if (e + n > r) break;
|
|
6634
6657
|
e += n, y.push(t);
|
|
6635
6658
|
}
|
|
6636
6659
|
b = [];
|
|
6637
6660
|
for (let t of m) {
|
|
6638
|
-
let n =
|
|
6661
|
+
let n = nl(rl(t));
|
|
6639
6662
|
if (e + n > r) break;
|
|
6640
6663
|
e += n, b.push(t);
|
|
6641
6664
|
}
|
|
6642
6665
|
x = [];
|
|
6643
6666
|
for (let t of _) {
|
|
6644
|
-
let n =
|
|
6667
|
+
let n = nl(rl(t));
|
|
6645
6668
|
if (e + n > r) break;
|
|
6646
6669
|
e += n, x.push(t);
|
|
6647
6670
|
}
|
|
6648
6671
|
}
|
|
6649
6672
|
let S = [
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
].join("\n\n"), C =
|
|
6673
|
+
il("Summary", y),
|
|
6674
|
+
il("Timeline", b),
|
|
6675
|
+
il("Observations", x)
|
|
6676
|
+
].join("\n\n"), C = nl(S), w = /* @__PURE__ */ new Set(), T = [], E = [], ee = [];
|
|
6654
6677
|
for (let e of [
|
|
6655
6678
|
...y,
|
|
6656
6679
|
...b,
|
|
6657
6680
|
...x
|
|
6658
|
-
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(
|
|
6659
|
-
let { previousPackIds: te, previousPackTokens: D } =
|
|
6681
|
+
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(al(e, v)), ee.push(e.id));
|
|
6682
|
+
let { previousPackIds: te, previousPackTokens: D } = wl(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 + El(t), 0), oe = /* @__PURE__ */ new Map();
|
|
6660
6683
|
for (let e of E) {
|
|
6661
|
-
let t =
|
|
6684
|
+
let t = Dl(e), n = El(e);
|
|
6662
6685
|
n > (oe.get(t) ?? 0) && oe.set(t, n);
|
|
6663
6686
|
}
|
|
6664
6687
|
let se = [...oe.values()].reduce((e, t) => e + t, 0), ce = Math.max(0, se - C), M = 0, N = 0, P = 0, F = {};
|
|
6665
6688
|
for (let e of E) {
|
|
6666
|
-
let t =
|
|
6689
|
+
let t = Ol(e);
|
|
6667
6690
|
t.tokens > 0 ? (M += t.tokens, N += 1, F[t.source] = (F[t.source] ?? 0) + 1) : P += 1;
|
|
6668
6691
|
}
|
|
6669
|
-
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(
|
|
6692
|
+
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(kl), 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
6693
|
total_items: T.length,
|
|
6671
6694
|
pack_tokens: C,
|
|
6672
6695
|
fallback_used: s,
|
|
@@ -6702,7 +6725,7 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6702
6725
|
fuzzy: 0
|
|
6703
6726
|
}
|
|
6704
6727
|
};
|
|
6705
|
-
return
|
|
6728
|
+
return Al(e, _e), {
|
|
6706
6729
|
context: t,
|
|
6707
6730
|
items: T,
|
|
6708
6731
|
item_ids: ee,
|
|
@@ -6710,10 +6733,10 @@ function Ol(e, t, n = 10, r = null, i, a) {
|
|
|
6710
6733
|
metrics: _e
|
|
6711
6734
|
};
|
|
6712
6735
|
}
|
|
6713
|
-
async function
|
|
6736
|
+
async function Nl(e, t, n = 10, r = null, i) {
|
|
6714
6737
|
let a = [];
|
|
6715
6738
|
try {
|
|
6716
|
-
a = (await
|
|
6739
|
+
a = (await Xo(e.db, t, n, { project: i?.project })).map((e) => {
|
|
6717
6740
|
let t = {};
|
|
6718
6741
|
if (e.metadata_json) try {
|
|
6719
6742
|
let n = JSON.parse(e.metadata_json);
|
|
@@ -6734,24 +6757,24 @@ async function kl(e, t, n = 10, r = null, i) {
|
|
|
6734
6757
|
};
|
|
6735
6758
|
});
|
|
6736
6759
|
} catch {}
|
|
6737
|
-
return
|
|
6760
|
+
return Ml(e, t, n, r, i, a);
|
|
6738
6761
|
}
|
|
6739
6762
|
//#endregion
|
|
6740
6763
|
//#region src/raw-event-flush.ts
|
|
6741
|
-
var
|
|
6742
|
-
function
|
|
6764
|
+
var Pl = "raw_events_v1";
|
|
6765
|
+
function Fl(e, t = 280) {
|
|
6743
6766
|
let n = e.replace(/\s+/g, " ").trim();
|
|
6744
6767
|
return n.length <= t ? n : `${n.slice(0, t - 3).trimEnd()}...`;
|
|
6745
6768
|
}
|
|
6746
|
-
function
|
|
6769
|
+
function Il(e) {
|
|
6747
6770
|
let t = (e ?? "").trim().toLowerCase();
|
|
6748
6771
|
return t === "openai" ? "OpenAI" : t === "anthropic" ? "Anthropic" : t ? t.charAt(0).toUpperCase() + t.slice(1) : "Observer";
|
|
6749
6772
|
}
|
|
6750
|
-
function
|
|
6751
|
-
let n =
|
|
6752
|
-
return e instanceof
|
|
6773
|
+
function Ll(e, t) {
|
|
6774
|
+
let n = Il(t), r = String(e.message ?? "").trim().toLowerCase();
|
|
6775
|
+
return e instanceof Ws ? `${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
6776
|
}
|
|
6754
|
-
function
|
|
6777
|
+
function Rl(e) {
|
|
6755
6778
|
let t = 0, n = 0;
|
|
6756
6779
|
for (let r of e) r.type === "user_prompt" && t++, r.type === "tool.execute.after" && n++;
|
|
6757
6780
|
let r = [];
|
|
@@ -6796,7 +6819,7 @@ function Pl(e) {
|
|
|
6796
6819
|
filesRead: [...o].sort()
|
|
6797
6820
|
};
|
|
6798
6821
|
}
|
|
6799
|
-
async function
|
|
6822
|
+
async function zl(e, t, n) {
|
|
6800
6823
|
let { source: r = "opencode", cwd: i, project: a, startedAt: o } = n, { opencodeSessionId: s, maxEvents: c } = n, l = n.allowEmptyFlush ?? !1;
|
|
6801
6824
|
r = (r ?? "").trim().toLowerCase() || "opencode";
|
|
6802
6825
|
let u = e.rawEventSessionMeta(s, r);
|
|
@@ -6826,7 +6849,7 @@ async function Fl(e, t, n) {
|
|
|
6826
6849
|
flushed: 0,
|
|
6827
6850
|
updatedState: 0
|
|
6828
6851
|
};
|
|
6829
|
-
let { batchId: g, status: _ } = e.getOrCreateRawEventFlushBatch(s, r, m, h,
|
|
6852
|
+
let { batchId: g, status: _ } = e.getOrCreateRawEventFlushBatch(s, r, m, h, Pl);
|
|
6830
6853
|
if (_ === "completed") return e.updateRawEventFlushState(s, h, r), {
|
|
6831
6854
|
flushed: 0,
|
|
6832
6855
|
updatedState: 1
|
|
@@ -6835,7 +6858,7 @@ async function Fl(e, t, n) {
|
|
|
6835
6858
|
flushed: 0,
|
|
6836
6859
|
updatedState: 0
|
|
6837
6860
|
};
|
|
6838
|
-
let v =
|
|
6861
|
+
let v = Rl(f);
|
|
6839
6862
|
v.opencodeSessionId = s, v.source = r, v.streamId = s, v.flusher = "raw_events", v.flushBatch = {
|
|
6840
6863
|
batch_id: g,
|
|
6841
6864
|
start_event_seq: m,
|
|
@@ -6849,17 +6872,17 @@ async function Fl(e, t, n) {
|
|
|
6849
6872
|
sessionContext: v
|
|
6850
6873
|
};
|
|
6851
6874
|
try {
|
|
6852
|
-
await
|
|
6875
|
+
await ns(y, e, t);
|
|
6853
6876
|
} catch (n) {
|
|
6854
6877
|
let i = n instanceof Error ? n : Error(String(n));
|
|
6855
6878
|
if (l && i.message === "observer produced no storable output for raw-event flush") return e.updateRawEventFlushBatchStatus(g, "completed"), e.updateRawEventFlushState(s, h, r), {
|
|
6856
6879
|
flushed: f.length,
|
|
6857
6880
|
updatedState: 1
|
|
6858
6881
|
};
|
|
6859
|
-
let a = t.observer?.getStatus?.()?.provider, o =
|
|
6882
|
+
let a = t.observer?.getStatus?.()?.provider, o = Fl(Ll(i, a));
|
|
6860
6883
|
throw e.recordRawEventFlushBatchFailure(g, {
|
|
6861
6884
|
message: o,
|
|
6862
|
-
errorType: i instanceof
|
|
6885
|
+
errorType: i instanceof Ws ? "ObserverAuthError" : i.name,
|
|
6863
6886
|
observerProvider: a ?? null,
|
|
6864
6887
|
observerModel: t.observer?.getStatus?.()?.model ?? null,
|
|
6865
6888
|
observerRuntime: null
|
|
@@ -6872,18 +6895,18 @@ async function Fl(e, t, n) {
|
|
|
6872
6895
|
}
|
|
6873
6896
|
//#endregion
|
|
6874
6897
|
//#region src/raw-event-sweeper.ts
|
|
6875
|
-
var
|
|
6876
|
-
function
|
|
6898
|
+
var Bl = 60;
|
|
6899
|
+
function Vl(e, t) {
|
|
6877
6900
|
let n = process.env[e];
|
|
6878
6901
|
if (n == null) return t;
|
|
6879
6902
|
let r = Number.parseInt(n, 10);
|
|
6880
6903
|
return Number.isFinite(r) ? r : t;
|
|
6881
6904
|
}
|
|
6882
|
-
function
|
|
6905
|
+
function Hl(e) {
|
|
6883
6906
|
let t = (process.env[e] ?? "1").trim().toLowerCase();
|
|
6884
6907
|
return t === "0" || t === "false" || t === "off";
|
|
6885
6908
|
}
|
|
6886
|
-
var
|
|
6909
|
+
var Ul = class {
|
|
6887
6910
|
store;
|
|
6888
6911
|
ingestOpts;
|
|
6889
6912
|
active = !1;
|
|
@@ -6901,7 +6924,7 @@ var zl = class {
|
|
|
6901
6924
|
this.store = e, this.ingestOpts = t;
|
|
6902
6925
|
}
|
|
6903
6926
|
enabled() {
|
|
6904
|
-
return !
|
|
6927
|
+
return !Hl("CODEMEM_RAW_EVENTS_SWEEPER");
|
|
6905
6928
|
}
|
|
6906
6929
|
intervalMs() {
|
|
6907
6930
|
let e = process.env.CODEMEM_RAW_EVENTS_SWEEPER_INTERVAL_MS;
|
|
@@ -6913,31 +6936,31 @@ var zl = class {
|
|
|
6913
6936
|
return Number.isFinite(n) && n > 0 ? Math.max(1e3, n * 1e3) : 3e4;
|
|
6914
6937
|
}
|
|
6915
6938
|
idleMs() {
|
|
6916
|
-
return
|
|
6939
|
+
return Vl("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
|
|
6917
6940
|
}
|
|
6918
6941
|
limit() {
|
|
6919
|
-
return
|
|
6942
|
+
return Vl("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
|
|
6920
6943
|
}
|
|
6921
6944
|
workerMaxEvents() {
|
|
6922
|
-
let e =
|
|
6945
|
+
let e = Vl("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 250);
|
|
6923
6946
|
return e <= 0 ? null : e;
|
|
6924
6947
|
}
|
|
6925
6948
|
retentionMs() {
|
|
6926
|
-
return
|
|
6949
|
+
return Vl("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
|
|
6927
6950
|
}
|
|
6928
6951
|
autoFlushEnabled() {
|
|
6929
6952
|
return (process.env.CODEMEM_RAW_EVENTS_AUTO_FLUSH ?? "").trim() === "1";
|
|
6930
6953
|
}
|
|
6931
6954
|
debounceMs() {
|
|
6932
|
-
return
|
|
6955
|
+
return Vl("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
|
|
6933
6956
|
}
|
|
6934
6957
|
stuckBatchMs() {
|
|
6935
|
-
return
|
|
6958
|
+
return Vl("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
|
|
6936
6959
|
}
|
|
6937
6960
|
handleAuthError(e) {
|
|
6938
|
-
if (this.authBackoffUntil = Date.now() / 1e3 +
|
|
6961
|
+
if (this.authBackoffUntil = Date.now() / 1e3 + Bl, !this.authErrorLogged) {
|
|
6939
6962
|
this.authErrorLogged = !0;
|
|
6940
|
-
let t = `codemem: observer auth error — backing off for ${
|
|
6963
|
+
let t = `codemem: observer auth error — backing off for ${Bl}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
|
|
6941
6964
|
console.error(t);
|
|
6942
6965
|
}
|
|
6943
6966
|
}
|
|
@@ -7017,7 +7040,7 @@ var zl = class {
|
|
|
7017
7040
|
let r = this.autoFlushTimers.get(n);
|
|
7018
7041
|
r && (clearTimeout(r), this.autoFlushTimers.delete(n));
|
|
7019
7042
|
try {
|
|
7020
|
-
await
|
|
7043
|
+
await zl(this.store, this.ingestOpts, {
|
|
7021
7044
|
opencodeSessionId: e,
|
|
7022
7045
|
source: t,
|
|
7023
7046
|
cwd: null,
|
|
@@ -7027,7 +7050,7 @@ var zl = class {
|
|
|
7027
7050
|
allowEmptyFlush: !0
|
|
7028
7051
|
});
|
|
7029
7052
|
} catch (t) {
|
|
7030
|
-
if (t instanceof
|
|
7053
|
+
if (t instanceof Ws) {
|
|
7031
7054
|
this.handleAuthError(t);
|
|
7032
7055
|
return;
|
|
7033
7056
|
}
|
|
@@ -7075,7 +7098,7 @@ var zl = class {
|
|
|
7075
7098
|
if (!this.sessionFlushing.has(r)) {
|
|
7076
7099
|
this.sessionFlushing.add(r);
|
|
7077
7100
|
try {
|
|
7078
|
-
await
|
|
7101
|
+
await zl(this.store, this.ingestOpts, {
|
|
7079
7102
|
opencodeSessionId: n,
|
|
7080
7103
|
source: t,
|
|
7081
7104
|
cwd: null,
|
|
@@ -7085,7 +7108,7 @@ var zl = class {
|
|
|
7085
7108
|
allowEmptyFlush: !0
|
|
7086
7109
|
}), o.add(`${t}:${n}`);
|
|
7087
7110
|
} catch (e) {
|
|
7088
|
-
if (e instanceof
|
|
7111
|
+
if (e instanceof Ws) {
|
|
7089
7112
|
this.handleAuthError(e);
|
|
7090
7113
|
return;
|
|
7091
7114
|
}
|
|
@@ -7103,7 +7126,7 @@ var zl = class {
|
|
|
7103
7126
|
if (!this.sessionFlushing.has(r)) {
|
|
7104
7127
|
this.sessionFlushing.add(r);
|
|
7105
7128
|
try {
|
|
7106
|
-
await
|
|
7129
|
+
await zl(this.store, this.ingestOpts, {
|
|
7107
7130
|
opencodeSessionId: n,
|
|
7108
7131
|
source: t,
|
|
7109
7132
|
cwd: null,
|
|
@@ -7113,7 +7136,7 @@ var zl = class {
|
|
|
7113
7136
|
allowEmptyFlush: !0
|
|
7114
7137
|
});
|
|
7115
7138
|
} catch (e) {
|
|
7116
|
-
if (e instanceof
|
|
7139
|
+
if (e instanceof Ws) {
|
|
7117
7140
|
this.handleAuthError(e);
|
|
7118
7141
|
return;
|
|
7119
7142
|
}
|
|
@@ -7127,7 +7150,7 @@ var zl = class {
|
|
|
7127
7150
|
};
|
|
7128
7151
|
//#endregion
|
|
7129
7152
|
//#region src/sync-replication.ts
|
|
7130
|
-
function
|
|
7153
|
+
function Wl(e) {
|
|
7131
7154
|
if (e == null) return null;
|
|
7132
7155
|
if (typeof e == "number" && Number.isFinite(e)) return e;
|
|
7133
7156
|
if (typeof e == "string" && e.trim().length > 0) {
|
|
@@ -7139,7 +7162,7 @@ function Bl(e) {
|
|
|
7139
7162
|
function Q(e) {
|
|
7140
7163
|
return e == null ? null : String(e);
|
|
7141
7164
|
}
|
|
7142
|
-
function
|
|
7165
|
+
function Gl(e, t) {
|
|
7143
7166
|
if (!e.payload_json) return null;
|
|
7144
7167
|
let n;
|
|
7145
7168
|
try {
|
|
@@ -7149,14 +7172,14 @@ function Vl(e, t) {
|
|
|
7149
7172
|
}
|
|
7150
7173
|
let r = n.metadata_json, i = r && typeof r == "object" && !Array.isArray(r) ? { ...r } : {};
|
|
7151
7174
|
return {
|
|
7152
|
-
session_id:
|
|
7175
|
+
session_id: Wl(n.session_id),
|
|
7153
7176
|
kind: Q(n.kind),
|
|
7154
7177
|
title: Q(n.title),
|
|
7155
7178
|
subtitle: Q(n.subtitle),
|
|
7156
7179
|
body_text: Q(n.body_text),
|
|
7157
|
-
confidence:
|
|
7180
|
+
confidence: Wl(n.confidence),
|
|
7158
7181
|
tags_text: Q(n.tags_text),
|
|
7159
|
-
active:
|
|
7182
|
+
active: Wl(n.active),
|
|
7160
7183
|
created_at: Q(n.created_at),
|
|
7161
7184
|
updated_at: Q(n.updated_at),
|
|
7162
7185
|
metadata_json: i,
|
|
@@ -7173,19 +7196,19 @@ function Vl(e, t) {
|
|
|
7173
7196
|
concepts: n.concepts ?? null,
|
|
7174
7197
|
files_read: n.files_read ?? null,
|
|
7175
7198
|
files_modified: n.files_modified ?? null,
|
|
7176
|
-
user_prompt_id:
|
|
7177
|
-
prompt_number:
|
|
7199
|
+
user_prompt_id: Wl(n.user_prompt_id),
|
|
7200
|
+
prompt_number: Wl(n.prompt_number),
|
|
7178
7201
|
deleted_at: Q(n.deleted_at),
|
|
7179
|
-
rev:
|
|
7202
|
+
rev: Wl(n.rev) ?? 0,
|
|
7180
7203
|
import_key: Q(n.import_key)
|
|
7181
7204
|
};
|
|
7182
7205
|
}
|
|
7183
|
-
function
|
|
7206
|
+
function Kl(e) {
|
|
7184
7207
|
let t = String(e ?? "").trim();
|
|
7185
7208
|
return t.length > 0 ? t : null;
|
|
7186
7209
|
}
|
|
7187
|
-
function
|
|
7188
|
-
let t =
|
|
7210
|
+
function ql(e) {
|
|
7211
|
+
let t = Kl(e);
|
|
7189
7212
|
if (!t) return null;
|
|
7190
7213
|
let n = t.lastIndexOf("|");
|
|
7191
7214
|
if (n <= 0) return null;
|
|
@@ -7195,20 +7218,20 @@ function Ul(e) {
|
|
|
7195
7218
|
id: i
|
|
7196
7219
|
};
|
|
7197
7220
|
}
|
|
7198
|
-
function
|
|
7221
|
+
function Jl(e, t) {
|
|
7199
7222
|
return `${e}|${t}`;
|
|
7200
7223
|
}
|
|
7201
|
-
function
|
|
7224
|
+
function Yl(e) {
|
|
7202
7225
|
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
7226
|
}
|
|
7204
|
-
function
|
|
7205
|
-
|
|
7227
|
+
function Xl(e) {
|
|
7228
|
+
Yl(e);
|
|
7206
7229
|
let t = N(e, { schema: H }), n = t.select().from(cn).where(k(cn.id, 1)).get();
|
|
7207
7230
|
if (n) return {
|
|
7208
7231
|
generation: Number(n.generation ?? 1),
|
|
7209
7232
|
snapshot_id: String(n.snapshot_id),
|
|
7210
|
-
baseline_cursor:
|
|
7211
|
-
retained_floor_cursor:
|
|
7233
|
+
baseline_cursor: Kl(n.baseline_cursor),
|
|
7234
|
+
retained_floor_cursor: Kl(n.retained_floor_cursor)
|
|
7212
7235
|
};
|
|
7213
7236
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
7214
7237
|
id: 1,
|
|
@@ -7225,12 +7248,12 @@ function Kl(e) {
|
|
|
7225
7248
|
retained_floor_cursor: i.retained_floor_cursor
|
|
7226
7249
|
};
|
|
7227
7250
|
}
|
|
7228
|
-
function
|
|
7229
|
-
let n =
|
|
7251
|
+
function Zl(e, t) {
|
|
7252
|
+
let n = Xl(e), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
7230
7253
|
generation: t.generation ?? n.generation,
|
|
7231
7254
|
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 :
|
|
7255
|
+
baseline_cursor: t.baseline_cursor === void 0 ? n.baseline_cursor : Kl(t.baseline_cursor),
|
|
7256
|
+
retained_floor_cursor: t.retained_floor_cursor === void 0 ? n.retained_floor_cursor : Kl(t.retained_floor_cursor)
|
|
7234
7257
|
};
|
|
7235
7258
|
return N(e, { schema: H }).insert(cn).values({
|
|
7236
7259
|
id: 1,
|
|
@@ -7247,7 +7270,7 @@ function ql(e, t) {
|
|
|
7247
7270
|
}
|
|
7248
7271
|
}).run(), i;
|
|
7249
7272
|
}
|
|
7250
|
-
function
|
|
7273
|
+
function Ql(e, t) {
|
|
7251
7274
|
return {
|
|
7252
7275
|
reset_required: !0,
|
|
7253
7276
|
reset: {
|
|
@@ -7257,17 +7280,17 @@ function Jl(e, t) {
|
|
|
7257
7280
|
}
|
|
7258
7281
|
};
|
|
7259
7282
|
}
|
|
7260
|
-
function
|
|
7283
|
+
function $l(e, t) {
|
|
7261
7284
|
return {
|
|
7262
7285
|
...e,
|
|
7263
7286
|
clock_device_id: t
|
|
7264
7287
|
};
|
|
7265
7288
|
}
|
|
7266
|
-
function
|
|
7289
|
+
function eu(e) {
|
|
7267
7290
|
let t = z(e);
|
|
7268
7291
|
return typeof t.clock_device_id == "string" ? t.clock_device_id : "";
|
|
7269
7292
|
}
|
|
7270
|
-
function
|
|
7293
|
+
function tu(e, t) {
|
|
7271
7294
|
let n = new TextEncoder(), r = [], i = [], a = 9;
|
|
7272
7295
|
for (let o of e) {
|
|
7273
7296
|
let e = n.encode(JSON.stringify(o)).byteLength, s = i.length === 0 ? e : e + 1;
|
|
@@ -7279,14 +7302,14 @@ function Zl(e, t) {
|
|
|
7279
7302
|
}
|
|
7280
7303
|
return i.length > 0 && r.push(i), r;
|
|
7281
7304
|
}
|
|
7282
|
-
function
|
|
7305
|
+
function nu(e, t) {
|
|
7283
7306
|
let n = N(e, { schema: H }).select({
|
|
7284
7307
|
last_applied_cursor: an.last_applied_cursor,
|
|
7285
7308
|
last_acked_cursor: an.last_acked_cursor
|
|
7286
7309
|
}).from(an).where(k(an.peer_device_id, t)).get();
|
|
7287
7310
|
return n ? [n.last_applied_cursor, n.last_acked_cursor] : [null, null];
|
|
7288
7311
|
}
|
|
7289
|
-
function
|
|
7312
|
+
function ru(e, t, n = {}) {
|
|
7290
7313
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = n.lastApplied ?? null, a = n.lastAcked ?? null;
|
|
7291
7314
|
N(e, { schema: H }).insert(an).values({
|
|
7292
7315
|
peer_device_id: t,
|
|
@@ -7302,7 +7325,7 @@ function $l(e, t, n = {}) {
|
|
|
7302
7325
|
}
|
|
7303
7326
|
}).run();
|
|
7304
7327
|
}
|
|
7305
|
-
var
|
|
7328
|
+
var iu = [
|
|
7306
7329
|
"op_id",
|
|
7307
7330
|
"entity_type",
|
|
7308
7331
|
"entity_id",
|
|
@@ -7313,26 +7336,26 @@ var eu = [
|
|
|
7313
7336
|
"device_id",
|
|
7314
7337
|
"created_at"
|
|
7315
7338
|
];
|
|
7316
|
-
function
|
|
7339
|
+
function au(e) {
|
|
7317
7340
|
if (typeof e != "object" || !e) return [];
|
|
7318
7341
|
let t = e.ops;
|
|
7319
7342
|
return Array.isArray(t) ? t.filter((e) => {
|
|
7320
7343
|
if (typeof e != "object" || !e) return !1;
|
|
7321
7344
|
let t = e;
|
|
7322
|
-
return
|
|
7345
|
+
return iu.every((e) => t[e] !== void 0 && t[e] !== null);
|
|
7323
7346
|
}) : [];
|
|
7324
7347
|
}
|
|
7325
|
-
function
|
|
7348
|
+
function ou(e, t, n) {
|
|
7326
7349
|
return [
|
|
7327
7350
|
e,
|
|
7328
7351
|
t,
|
|
7329
7352
|
n
|
|
7330
7353
|
];
|
|
7331
7354
|
}
|
|
7332
|
-
function
|
|
7355
|
+
function su(e, t) {
|
|
7333
7356
|
return e[0] === t[0] ? e[1] === t[1] ? e[2] > t[2] : e[1] > t[1] : e[0] > t[0];
|
|
7334
7357
|
}
|
|
7335
|
-
function
|
|
7358
|
+
function cu(e, t) {
|
|
7336
7359
|
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
7360
|
if (t.payload) f = B(t.payload);
|
|
7338
7361
|
else if (o && t.opType === "upsert") {
|
|
@@ -7387,17 +7410,17 @@ function iu(e, t) {
|
|
|
7387
7410
|
created_at: i
|
|
7388
7411
|
}).run(), r;
|
|
7389
7412
|
}
|
|
7390
|
-
function
|
|
7413
|
+
function lu(e) {
|
|
7391
7414
|
let t = e.indexOf("|");
|
|
7392
7415
|
return t < 0 ? null : [e.slice(0, t), e.slice(t + 1)];
|
|
7393
7416
|
}
|
|
7394
|
-
function
|
|
7417
|
+
function uu(e, t) {
|
|
7395
7418
|
return `${e}|${t}`;
|
|
7396
7419
|
}
|
|
7397
|
-
function
|
|
7420
|
+
function du(e, t, n = 100, r) {
|
|
7398
7421
|
let i = N(e, { schema: H }), a = J, o = [];
|
|
7399
7422
|
if (t) {
|
|
7400
|
-
let e =
|
|
7423
|
+
let e = lu(t);
|
|
7401
7424
|
if (e) {
|
|
7402
7425
|
let [t, n] = e;
|
|
7403
7426
|
o.push(ce(A(a.created_at, t), D(k(a.created_at, t), A(a.op_id, n))));
|
|
@@ -7418,17 +7441,17 @@ function su(e, t, n = 100, r) {
|
|
|
7418
7441
|
})), u = null;
|
|
7419
7442
|
if (c.length > 0) {
|
|
7420
7443
|
let e = c.at(-1);
|
|
7421
|
-
e && (u =
|
|
7444
|
+
e && (u = uu(e.created_at, e.op_id));
|
|
7422
7445
|
}
|
|
7423
7446
|
return [l, u];
|
|
7424
7447
|
}
|
|
7425
|
-
function
|
|
7426
|
-
let n =
|
|
7427
|
-
if (i != null && i !== n.generation) return
|
|
7448
|
+
function fu(e, t) {
|
|
7449
|
+
let n = Xl(e), r = Kl(t.since), i = t.generation ?? null, a = Kl(t.snapshotId), o = Kl(t.baselineCursor), s = i != null || a != null || o != null;
|
|
7450
|
+
if (i != null && i !== n.generation) return Ql(n, "generation_mismatch");
|
|
7428
7451
|
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] =
|
|
7452
|
+
if (!s || !c || a !== n.snapshot_id || o !== n.baseline_cursor) return Ql(n, "boundary_mismatch");
|
|
7453
|
+
if (r != null && n.retained_floor_cursor != null && r < n.retained_floor_cursor) return Ql(n, "stale_cursor");
|
|
7454
|
+
let [l, u] = du(e, r, t.limit, t.deviceId);
|
|
7432
7455
|
return {
|
|
7433
7456
|
reset_required: !1,
|
|
7434
7457
|
boundary: n,
|
|
@@ -7436,11 +7459,11 @@ function cu(e, t) {
|
|
|
7436
7459
|
nextCursor: u
|
|
7437
7460
|
};
|
|
7438
7461
|
}
|
|
7439
|
-
function
|
|
7440
|
-
let n =
|
|
7462
|
+
function pu(e, t) {
|
|
7463
|
+
let n = Xl(e);
|
|
7441
7464
|
if (t.generation !== n.generation) throw Error("generation_mismatch");
|
|
7442
|
-
if (
|
|
7443
|
-
let r = Math.max(1, Math.min(t.limit ?? 200, 1e3)), i =
|
|
7465
|
+
if (Kl(t.snapshotId) !== n.snapshot_id || Kl(t.baselineCursor) !== n.baseline_cursor) throw Error("boundary_mismatch");
|
|
7466
|
+
let r = Math.max(1, Math.min(t.limit ?? 200, 1e3)), i = ql(t.pageToken), a = N(e, { schema: H }), o = Math.min(Math.max(r * 3, r), 1e3), s = (e, t) => a.select({
|
|
7444
7467
|
memory: W,
|
|
7445
7468
|
sessionProject: U.project
|
|
7446
7469
|
}).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 +7475,12 @@ function lu(e, t) {
|
|
|
7452
7475
|
if (!a) continue;
|
|
7453
7476
|
let o = String(a.memory.import_key ?? "").trim();
|
|
7454
7477
|
if (!o) continue;
|
|
7455
|
-
u =
|
|
7478
|
+
u = Jl(o, Number(a.memory.id)), l = {
|
|
7456
7479
|
importKey: o,
|
|
7457
7480
|
id: Number(a.memory.id)
|
|
7458
7481
|
};
|
|
7459
|
-
let f =
|
|
7460
|
-
if (!
|
|
7482
|
+
let f = Pu(a.memory);
|
|
7483
|
+
if (!Tu(f) && !Eu(e, t.peerDeviceId ?? null) || !wu(e, a.sessionProject, t.peerDeviceId ?? null)) continue;
|
|
7461
7484
|
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
7485
|
if (c.push({
|
|
7463
7486
|
entity_id: o,
|
|
@@ -7480,10 +7503,10 @@ function lu(e, t) {
|
|
|
7480
7503
|
hasMore: d && u != null
|
|
7481
7504
|
};
|
|
7482
7505
|
}
|
|
7483
|
-
function
|
|
7506
|
+
function mu(e, t = 25) {
|
|
7484
7507
|
let n = N(e, { schema: H }), r = n.select().from(W).orderBy(W.updated_at).all(), i = 0;
|
|
7485
7508
|
for (let e of r) {
|
|
7486
|
-
if (!e.import_key || !
|
|
7509
|
+
if (!e.import_key || !Tu(Pu(e))) continue;
|
|
7487
7510
|
let r = e.deleted_at || e.active === 0 ? "delete" : "upsert";
|
|
7488
7511
|
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
7512
|
}
|
|
@@ -7492,10 +7515,10 @@ function uu(e, t = 25) {
|
|
|
7492
7515
|
count: i
|
|
7493
7516
|
};
|
|
7494
7517
|
}
|
|
7495
|
-
function
|
|
7518
|
+
function hu(e, t) {
|
|
7496
7519
|
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
7520
|
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 =
|
|
7521
|
+
let d = e.prepare("DELETE FROM replication_ops WHERE created_at < ? OR (created_at = ? AND op_id <= ?)"), f = vu(e);
|
|
7499
7522
|
if (f == null) throw Error("replication_ops_size_unavailable");
|
|
7500
7523
|
let p = !1, m = () => l >= i || Date.now() - c >= a;
|
|
7501
7524
|
for (;;) {
|
|
@@ -7510,7 +7533,7 @@ function du(e, t) {
|
|
|
7510
7533
|
if (n.length === 0) break;
|
|
7511
7534
|
let r = n[n.length - 1];
|
|
7512
7535
|
if (!r) break;
|
|
7513
|
-
if (u =
|
|
7536
|
+
if (u = uu(String(r.created_at), String(r.op_id)), l += d.run(r.created_at, r.created_at, r.op_id).changes ?? 0, m()) {
|
|
7514
7537
|
p = !0;
|
|
7515
7538
|
break;
|
|
7516
7539
|
}
|
|
@@ -7527,13 +7550,13 @@ function du(e, t) {
|
|
|
7527
7550
|
created_at: J.created_at
|
|
7528
7551
|
}).from(J).orderBy(J.created_at, J.op_id).limit(n).all(), a = r[r.length - 1];
|
|
7529
7552
|
if (!a) break;
|
|
7530
|
-
u =
|
|
7531
|
-
let s =
|
|
7553
|
+
u = uu(String(a.created_at), String(a.op_id)), l += d.run(a.created_at, a.created_at, a.op_id).changes ?? 0;
|
|
7554
|
+
let s = vu(e);
|
|
7532
7555
|
if (s == null) throw Error("replication_ops_size_unavailable");
|
|
7533
7556
|
h = s;
|
|
7534
7557
|
}
|
|
7535
|
-
let g =
|
|
7536
|
-
return
|
|
7558
|
+
let g = Xl(e), _ = l > 0 ? u : g.retained_floor_cursor;
|
|
7559
|
+
return Zl(e, { retained_floor_cursor: _ }), {
|
|
7537
7560
|
deleted: l,
|
|
7538
7561
|
retained_floor_cursor: _,
|
|
7539
7562
|
estimated_bytes_before: f,
|
|
@@ -7541,8 +7564,8 @@ function du(e, t) {
|
|
|
7541
7564
|
stopped_by_budget: p
|
|
7542
7565
|
};
|
|
7543
7566
|
}
|
|
7544
|
-
function
|
|
7545
|
-
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date(Date.now() - Math.max(1, Math.floor(t)) * 24 * 60 * 60 * 1e3)).toISOString(), a =
|
|
7567
|
+
function gu(e, t, n = 2 ** 53 - 1) {
|
|
7568
|
+
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date(Date.now() - Math.max(1, Math.floor(t)) * 24 * 60 * 60 * 1e3)).toISOString(), a = vu(e);
|
|
7546
7569
|
if (a == null) throw Error("replication_ops_size_unavailable");
|
|
7547
7570
|
let o = r.select({
|
|
7548
7571
|
op_id: J.op_id,
|
|
@@ -7550,14 +7573,14 @@ function fu(e, t, n = 2 ** 53 - 1) {
|
|
|
7550
7573
|
}).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
7574
|
if (!s) return {
|
|
7552
7575
|
deleted: 0,
|
|
7553
|
-
retained_floor_cursor:
|
|
7576
|
+
retained_floor_cursor: Xl(e).retained_floor_cursor,
|
|
7554
7577
|
estimated_bytes_before: a,
|
|
7555
7578
|
estimated_bytes_after: a,
|
|
7556
7579
|
stopped_by_budget: !1
|
|
7557
7580
|
};
|
|
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 =
|
|
7581
|
+
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 = uu(String(s.created_at), String(s.op_id));
|
|
7582
|
+
Zl(e, { retained_floor_cursor: l });
|
|
7583
|
+
let u = vu(e);
|
|
7561
7584
|
if (u == null) throw Error("replication_ops_size_unavailable");
|
|
7562
7585
|
return {
|
|
7563
7586
|
deleted: c,
|
|
@@ -7567,19 +7590,19 @@ function fu(e, t, n = 2 ** 53 - 1) {
|
|
|
7567
7590
|
stopped_by_budget: !1
|
|
7568
7591
|
};
|
|
7569
7592
|
}
|
|
7570
|
-
function
|
|
7593
|
+
function _u(e, t, n) {
|
|
7571
7594
|
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
7595
|
op_id: J.op_id,
|
|
7573
7596
|
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 =
|
|
7597
|
+
}).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 = vu(e) ?? 0, d = l > 0 ? Math.round(u * c / l) : 0;
|
|
7575
7598
|
return {
|
|
7576
7599
|
candidate_ops: c,
|
|
7577
7600
|
estimated_candidate_bytes: Math.max(0, d),
|
|
7578
|
-
cutoff_cursor: s ?
|
|
7601
|
+
cutoff_cursor: s ? uu(String(s.created_at), String(s.op_id)) : null,
|
|
7579
7602
|
estimated_batches: c > 0 ? Math.ceil(c / Math.max(1, n)) : 0
|
|
7580
7603
|
};
|
|
7581
7604
|
}
|
|
7582
|
-
function
|
|
7605
|
+
function vu(e) {
|
|
7583
7606
|
try {
|
|
7584
7607
|
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
7608
|
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
@@ -7587,7 +7610,7 @@ function mu(e) {
|
|
|
7587
7610
|
return null;
|
|
7588
7611
|
}
|
|
7589
7612
|
}
|
|
7590
|
-
function
|
|
7613
|
+
function yu(e) {
|
|
7591
7614
|
if (!Array.isArray(e)) return [];
|
|
7592
7615
|
let t = [];
|
|
7593
7616
|
for (let n of e) {
|
|
@@ -7596,25 +7619,25 @@ function hu(e) {
|
|
|
7596
7619
|
}
|
|
7597
7620
|
return t;
|
|
7598
7621
|
}
|
|
7599
|
-
function
|
|
7600
|
-
return Array.isArray(e) ?
|
|
7622
|
+
function bu(e) {
|
|
7623
|
+
return Array.isArray(e) ? yu(e) : typeof e == "string" ? e.split(",").map((e) => e.trim()).filter(Boolean) : [];
|
|
7601
7624
|
}
|
|
7602
|
-
function
|
|
7625
|
+
function xu(e) {
|
|
7603
7626
|
if (!e) return [];
|
|
7604
7627
|
try {
|
|
7605
|
-
return
|
|
7628
|
+
return yu(JSON.parse(e));
|
|
7606
7629
|
} catch {
|
|
7607
7630
|
return [];
|
|
7608
7631
|
}
|
|
7609
7632
|
}
|
|
7610
|
-
function
|
|
7633
|
+
function Su(e) {
|
|
7611
7634
|
let t = String(e ?? "").trim().replaceAll("\\", "/");
|
|
7612
7635
|
if (!t) return "";
|
|
7613
7636
|
let n = t.split("/").filter(Boolean);
|
|
7614
7637
|
return n.length > 0 ? n[n.length - 1] ?? "" : "";
|
|
7615
7638
|
}
|
|
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 =
|
|
7639
|
+
function Cu(e, t) {
|
|
7640
|
+
let n = N(e, { schema: H }), r = tt(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o = bu(i === void 0 ? r.sync_projects_include : i), s = bu(a === void 0 ? r.sync_projects_exclude : a);
|
|
7618
7641
|
if (!t) return {
|
|
7619
7642
|
include: o,
|
|
7620
7643
|
exclude: s
|
|
@@ -7627,15 +7650,15 @@ function yu(e, t) {
|
|
|
7627
7650
|
include: o,
|
|
7628
7651
|
exclude: s
|
|
7629
7652
|
} : {
|
|
7630
|
-
include:
|
|
7631
|
-
exclude:
|
|
7653
|
+
include: xu(c.projects_include_json),
|
|
7654
|
+
exclude: xu(c.projects_exclude_json)
|
|
7632
7655
|
};
|
|
7633
7656
|
}
|
|
7634
|
-
function
|
|
7635
|
-
let { include: r, exclude: i } =
|
|
7657
|
+
function wu(e, t, n) {
|
|
7658
|
+
let { include: r, exclude: i } = Cu(e, n), a = String(t ?? "").trim(), o = Su(a);
|
|
7636
7659
|
return i.some((e) => e === a || e === o) ? !1 : r.length === 0 ? !0 : r.some((e) => e === a || e === o);
|
|
7637
7660
|
}
|
|
7638
|
-
function
|
|
7661
|
+
function Tu(e) {
|
|
7639
7662
|
if (!e) return !1;
|
|
7640
7663
|
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
7664
|
if (!t && r && (t = r), !t) {
|
|
@@ -7645,10 +7668,10 @@ function xu(e) {
|
|
|
7645
7668
|
}
|
|
7646
7669
|
return t === "shared";
|
|
7647
7670
|
}
|
|
7648
|
-
function
|
|
7671
|
+
function Eu(e, t) {
|
|
7649
7672
|
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
7673
|
}
|
|
7651
|
-
function
|
|
7674
|
+
function Du(e) {
|
|
7652
7675
|
if (!e || !e.trim()) return null;
|
|
7653
7676
|
try {
|
|
7654
7677
|
let t = JSON.parse(e);
|
|
@@ -7657,16 +7680,16 @@ function Cu(e) {
|
|
|
7657
7680
|
return null;
|
|
7658
7681
|
}
|
|
7659
7682
|
}
|
|
7660
|
-
function
|
|
7683
|
+
function Ou(e, t, n) {
|
|
7661
7684
|
let r = [], i = null, a = 0, o = null;
|
|
7662
7685
|
for (let s of t) {
|
|
7663
7686
|
if (s.entity_type === "memory_item") {
|
|
7664
|
-
let t =
|
|
7687
|
+
let t = Du(s.payload_json);
|
|
7665
7688
|
if (s.op_type === "delete" && t == null) {
|
|
7666
|
-
r.push(s), i =
|
|
7689
|
+
r.push(s), i = uu(s.created_at, s.op_id);
|
|
7667
7690
|
continue;
|
|
7668
7691
|
}
|
|
7669
|
-
if (!
|
|
7692
|
+
if (!Tu(t) && !Eu(e, n)) {
|
|
7670
7693
|
a += 1, o ||= {
|
|
7671
7694
|
reason: "visibility_filter",
|
|
7672
7695
|
op_id: s.op_id,
|
|
@@ -7675,11 +7698,11 @@ function wu(e, t, n) {
|
|
|
7675
7698
|
entity_id: s.entity_id,
|
|
7676
7699
|
visibility: typeof t?.visibility == "string" ? String(t.visibility) : null,
|
|
7677
7700
|
skipped_count: 0
|
|
7678
|
-
}, i =
|
|
7701
|
+
}, i = uu(s.created_at, s.op_id);
|
|
7679
7702
|
continue;
|
|
7680
7703
|
}
|
|
7681
7704
|
let c = typeof t?.project == "string" && t.project.trim() ? t.project.trim() : null;
|
|
7682
|
-
if (!
|
|
7705
|
+
if (!wu(e, c, n)) {
|
|
7683
7706
|
a += 1, o ||= {
|
|
7684
7707
|
reason: "project_filter",
|
|
7685
7708
|
op_id: s.op_id,
|
|
@@ -7688,11 +7711,11 @@ function wu(e, t, n) {
|
|
|
7688
7711
|
entity_id: s.entity_id,
|
|
7689
7712
|
project: c,
|
|
7690
7713
|
skipped_count: 0
|
|
7691
|
-
}, i =
|
|
7714
|
+
}, i = uu(s.created_at, s.op_id);
|
|
7692
7715
|
continue;
|
|
7693
7716
|
}
|
|
7694
7717
|
}
|
|
7695
|
-
r.push(s), i =
|
|
7718
|
+
r.push(s), i = uu(s.created_at, s.op_id);
|
|
7696
7719
|
}
|
|
7697
7720
|
return o && (o.skipped_count = a), [
|
|
7698
7721
|
r,
|
|
@@ -7700,12 +7723,12 @@ function wu(e, t, n) {
|
|
|
7700
7723
|
o
|
|
7701
7724
|
];
|
|
7702
7725
|
}
|
|
7703
|
-
function
|
|
7704
|
-
let [r, i] =
|
|
7726
|
+
function ku(e, t, n) {
|
|
7727
|
+
let [r, i] = Ou(e, t, n);
|
|
7705
7728
|
return [r, i];
|
|
7706
7729
|
}
|
|
7707
|
-
var
|
|
7708
|
-
function
|
|
7730
|
+
var Au = /^legacy:memory_item:(.+)$/;
|
|
7731
|
+
function ju(e, t = 2e3) {
|
|
7709
7732
|
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
7733
|
if (!i) return 0;
|
|
7711
7734
|
let a = n.select({
|
|
@@ -7719,7 +7742,7 @@ function Du(e, t = 2e3) {
|
|
|
7719
7742
|
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
7743
|
if (!r) c = `legacy:${i}:memory_item:${t}`;
|
|
7721
7744
|
else {
|
|
7722
|
-
let e = r.match(
|
|
7745
|
+
let e = r.match(Au);
|
|
7723
7746
|
if (!e) continue;
|
|
7724
7747
|
let t = e[1] ?? "", n = s && s !== "local" ? s : i;
|
|
7725
7748
|
c = n ? `legacy:${n}:memory_item:${t}` : "";
|
|
@@ -7730,9 +7753,9 @@ function Du(e, t = 2e3) {
|
|
|
7730
7753
|
}
|
|
7731
7754
|
return o;
|
|
7732
7755
|
}
|
|
7733
|
-
function
|
|
7756
|
+
function Mu(e, t = 200) {
|
|
7734
7757
|
if (t <= 0) return 0;
|
|
7735
|
-
|
|
7758
|
+
ju(e, 2e3);
|
|
7736
7759
|
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
7760
|
SELECT 1
|
|
7738
7761
|
FROM replication_ops ro
|
|
@@ -7757,7 +7780,7 @@ function Ou(e, t = 200) {
|
|
|
7757
7780
|
for (let e of s) {
|
|
7758
7781
|
let t = Number(e.id ?? 0);
|
|
7759
7782
|
if (!t) continue;
|
|
7760
|
-
let r = typeof e.metadata_json == "string" ? z(e.metadata_json) :
|
|
7783
|
+
let r = typeof e.metadata_json == "string" ? z(e.metadata_json) : Nu(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
7784
|
if (!s) {
|
|
7762
7785
|
if (!o) continue;
|
|
7763
7786
|
s = `legacy:${o}:memory_item:${t}`, n.update(W).set({ import_key: s }).where(k(W.id, t)).run();
|
|
@@ -7766,7 +7789,7 @@ function Ou(e, t = 200) {
|
|
|
7766
7789
|
if (n.select({ one: M`1` }).from(J).where(k(J.op_id, p)).limit(1).get()) continue;
|
|
7767
7790
|
let m = o;
|
|
7768
7791
|
if (!m) continue;
|
|
7769
|
-
let h =
|
|
7792
|
+
let h = Pu(e);
|
|
7770
7793
|
n.insert(J).values({
|
|
7771
7794
|
op_id: p,
|
|
7772
7795
|
entity_type: "memory_item",
|
|
@@ -7782,10 +7805,10 @@ function Ou(e, t = 200) {
|
|
|
7782
7805
|
}
|
|
7783
7806
|
return l;
|
|
7784
7807
|
}
|
|
7785
|
-
function
|
|
7808
|
+
function Nu(e) {
|
|
7786
7809
|
return typeof e == "string" ? z(e) : e && typeof e == "object" ? e : {};
|
|
7787
7810
|
}
|
|
7788
|
-
function
|
|
7811
|
+
function Pu(e) {
|
|
7789
7812
|
let t = (e) => {
|
|
7790
7813
|
if (typeof e != "string") return e ?? null;
|
|
7791
7814
|
try {
|
|
@@ -7826,7 +7849,7 @@ function Au(e) {
|
|
|
7826
7849
|
import_key: e.import_key ?? null
|
|
7827
7850
|
};
|
|
7828
7851
|
}
|
|
7829
|
-
function
|
|
7852
|
+
function Fu(e, t, n) {
|
|
7830
7853
|
let r = N(e, { schema: H }), i = {
|
|
7831
7854
|
applied: 0,
|
|
7832
7855
|
skipped: 0,
|
|
@@ -7851,14 +7874,14 @@ function ju(e, t, n) {
|
|
|
7851
7874
|
metadata_json: W.metadata_json
|
|
7852
7875
|
}).from(W).where(k(W.import_key, t)).get();
|
|
7853
7876
|
if (n) {
|
|
7854
|
-
let a =
|
|
7855
|
-
if (!
|
|
7856
|
-
i.conflicts++,
|
|
7877
|
+
let a = eu(n.metadata_json), o = ou(n.rev ?? 0, n.updated_at ?? "", a);
|
|
7878
|
+
if (!su(ou(e.clock_rev, e.clock_updated_at, e.clock_device_id), o)) {
|
|
7879
|
+
i.conflicts++, Iu(r, e);
|
|
7857
7880
|
continue;
|
|
7858
7881
|
}
|
|
7859
|
-
let s =
|
|
7882
|
+
let s = Gl(e, i.errors);
|
|
7860
7883
|
if (!s) continue;
|
|
7861
|
-
let c =
|
|
7884
|
+
let c = $l(s.metadata_json, e.clock_device_id);
|
|
7862
7885
|
r.update(W).set({
|
|
7863
7886
|
kind: M`COALESCE(${s.kind}, ${W.kind})`,
|
|
7864
7887
|
title: M`COALESCE(${s.title}, ${W.title})`,
|
|
@@ -7886,9 +7909,9 @@ function ju(e, t, n) {
|
|
|
7886
7909
|
files_modified: V(s.files_modified)
|
|
7887
7910
|
}).where(k(W.import_key, t)).run();
|
|
7888
7911
|
} else {
|
|
7889
|
-
let n =
|
|
7912
|
+
let n = Gl(e, i.errors);
|
|
7890
7913
|
if (!n) continue;
|
|
7891
|
-
let a =
|
|
7914
|
+
let a = Lu(r, null, e.clock_updated_at), o = $l(n.metadata_json, e.clock_device_id);
|
|
7892
7915
|
r.insert(W).values({
|
|
7893
7916
|
session_id: a,
|
|
7894
7917
|
kind: n.kind ?? "discovery",
|
|
@@ -7927,9 +7950,9 @@ function ju(e, t, n) {
|
|
|
7927
7950
|
metadata_json: W.metadata_json
|
|
7928
7951
|
}).from(W).where(k(W.import_key, t)).limit(1).get();
|
|
7929
7952
|
if (n) {
|
|
7930
|
-
let t =
|
|
7931
|
-
if (!
|
|
7932
|
-
i.conflicts++,
|
|
7953
|
+
let t = ou(n.rev ?? 1, n.updated_at ?? "", eu(n.metadata_json));
|
|
7954
|
+
if (!su(ou(e.clock_rev, e.clock_updated_at, e.clock_device_id), t)) {
|
|
7955
|
+
i.conflicts++, Iu(r, e);
|
|
7933
7956
|
continue;
|
|
7934
7957
|
}
|
|
7935
7958
|
let a = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -7941,16 +7964,16 @@ function ju(e, t, n) {
|
|
|
7941
7964
|
}).where(k(W.id, n.id)).run();
|
|
7942
7965
|
}
|
|
7943
7966
|
} else {
|
|
7944
|
-
i.skipped++,
|
|
7967
|
+
i.skipped++, Iu(r, e);
|
|
7945
7968
|
continue;
|
|
7946
7969
|
}
|
|
7947
|
-
|
|
7970
|
+
Iu(r, e), i.applied++;
|
|
7948
7971
|
} catch (t) {
|
|
7949
7972
|
i.errors.push(`op ${e.op_id}: ${t instanceof Error ? t.message : String(t)}`);
|
|
7950
7973
|
}
|
|
7951
7974
|
})(), i;
|
|
7952
7975
|
}
|
|
7953
|
-
function
|
|
7976
|
+
function Iu(e, t) {
|
|
7954
7977
|
e.insert(J).values({
|
|
7955
7978
|
op_id: t.op_id,
|
|
7956
7979
|
entity_type: t.entity_type,
|
|
@@ -7964,7 +7987,7 @@ function Mu(e, t) {
|
|
|
7964
7987
|
created_at: t.created_at
|
|
7965
7988
|
}).onConflictDoNothing().run();
|
|
7966
7989
|
}
|
|
7967
|
-
function
|
|
7990
|
+
function Lu(e, t, n) {
|
|
7968
7991
|
if (t != null && e.select({ id: U.id }).from(U).where(k(U.id, t)).get()) return t;
|
|
7969
7992
|
let r = n || (/* @__PURE__ */ new Date()).toISOString(), i = e.insert(U).values({
|
|
7970
7993
|
started_at: r,
|
|
@@ -7977,7 +8000,7 @@ function Nu(e, t, n) {
|
|
|
7977
8000
|
}
|
|
7978
8001
|
//#endregion
|
|
7979
8002
|
//#region src/store.ts
|
|
7980
|
-
var
|
|
8003
|
+
var Ru = new Set([
|
|
7981
8004
|
"discovery",
|
|
7982
8005
|
"change",
|
|
7983
8006
|
"feature",
|
|
@@ -7986,27 +8009,27 @@ var Pu = new Set([
|
|
|
7986
8009
|
"decision",
|
|
7987
8010
|
"exploration"
|
|
7988
8011
|
]);
|
|
7989
|
-
function
|
|
8012
|
+
function zu(e) {
|
|
7990
8013
|
let t = e.trim().toLowerCase();
|
|
7991
|
-
if (!
|
|
8014
|
+
if (!Ru.has(t)) throw Error(`Invalid memory kind "${e}". Allowed: ${[...Ru].join(", ")}`);
|
|
7992
8015
|
return t;
|
|
7993
8016
|
}
|
|
7994
|
-
function
|
|
8017
|
+
function Bu() {
|
|
7995
8018
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
7996
8019
|
}
|
|
7997
|
-
function
|
|
8020
|
+
function Vu(e) {
|
|
7998
8021
|
return (e.match(/\?/g) ?? []).length;
|
|
7999
8022
|
}
|
|
8000
|
-
function
|
|
8023
|
+
function Hu(e, t) {
|
|
8001
8024
|
let n = e.split("?"), r = M.raw(n[0] ?? "");
|
|
8002
8025
|
for (let e = 1; e < n.length; e++) r = M`${r}${t[e - 1]}${M.raw(n[e] ?? "")}`;
|
|
8003
8026
|
return r;
|
|
8004
8027
|
}
|
|
8005
|
-
function
|
|
8028
|
+
function Uu(e, t) {
|
|
8006
8029
|
let n = [], r = 0;
|
|
8007
8030
|
for (let i of e) {
|
|
8008
|
-
let e =
|
|
8009
|
-
n.push(
|
|
8031
|
+
let e = Vu(i), a = t.slice(r, r + e);
|
|
8032
|
+
n.push(Hu(i, a)), r += e;
|
|
8010
8033
|
}
|
|
8011
8034
|
if (r !== t.length) throw Error("filter parameter mismatch while building SQL clauses");
|
|
8012
8035
|
if (n.length === 1) return n[0] ?? M`1=1`;
|
|
@@ -8019,7 +8042,7 @@ function $(e) {
|
|
|
8019
8042
|
let t = e.trim();
|
|
8020
8043
|
return t.length > 0 ? t : null;
|
|
8021
8044
|
}
|
|
8022
|
-
function
|
|
8045
|
+
function Wu(e) {
|
|
8023
8046
|
if (typeof e != "string" || !e.trim()) return [];
|
|
8024
8047
|
try {
|
|
8025
8048
|
let t = JSON.parse(e);
|
|
@@ -8028,21 +8051,21 @@ function Bu(e) {
|
|
|
8028
8051
|
return [];
|
|
8029
8052
|
}
|
|
8030
8053
|
}
|
|
8031
|
-
function
|
|
8054
|
+
function Gu(e) {
|
|
8032
8055
|
let t = $(e);
|
|
8033
8056
|
if (!t) return "";
|
|
8034
8057
|
let n = t.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
8035
8058
|
return n[n.length - 1] ?? t;
|
|
8036
8059
|
}
|
|
8037
|
-
var
|
|
8038
|
-
function
|
|
8060
|
+
var Ku = "Legacy synced peer", qu = "shared:legacy";
|
|
8061
|
+
function Ju(e) {
|
|
8039
8062
|
let { metadata_json: t, ...n } = e;
|
|
8040
8063
|
return {
|
|
8041
8064
|
...n,
|
|
8042
8065
|
metadata_json: z(t)
|
|
8043
8066
|
};
|
|
8044
8067
|
}
|
|
8045
|
-
var
|
|
8068
|
+
var Yu = class {
|
|
8046
8069
|
db;
|
|
8047
8070
|
dbPath;
|
|
8048
8071
|
deviceId;
|
|
@@ -8075,7 +8098,7 @@ var Gu = class {
|
|
|
8075
8098
|
enqueueVectorWrite(e, t, n) {
|
|
8076
8099
|
if (this.db.inTransaction) return;
|
|
8077
8100
|
let r = null;
|
|
8078
|
-
r =
|
|
8101
|
+
r = Jo(this.db, e, t, n).catch(() => {}).finally(() => {
|
|
8079
8102
|
r && this.pendingVectorWrites.delete(r);
|
|
8080
8103
|
}), this.pendingVectorWrites.add(r);
|
|
8081
8104
|
}
|
|
@@ -8084,10 +8107,10 @@ var Gu = class {
|
|
|
8084
8107
|
}
|
|
8085
8108
|
get(e) {
|
|
8086
8109
|
let t = this.d.select().from(W).where(k(W.id, e)).get();
|
|
8087
|
-
return t ?
|
|
8110
|
+
return t ? Ju(t) : null;
|
|
8088
8111
|
}
|
|
8089
8112
|
startSession(e) {
|
|
8090
|
-
let t =
|
|
8113
|
+
let t = Bu(), n = this.d.insert(U).values({
|
|
8091
8114
|
started_at: t,
|
|
8092
8115
|
cwd: e.cwd ?? process.cwd(),
|
|
8093
8116
|
project: e.project ?? null,
|
|
@@ -8101,7 +8124,7 @@ var Gu = class {
|
|
|
8101
8124
|
return n;
|
|
8102
8125
|
}
|
|
8103
8126
|
endSession(e, t) {
|
|
8104
|
-
let n =
|
|
8127
|
+
let n = Bu();
|
|
8105
8128
|
if (t) {
|
|
8106
8129
|
let r = {
|
|
8107
8130
|
...z(this.d.select({ metadata_json: U.metadata_json }).from(U).where(k(U.id, e)).get()?.metadata_json),
|
|
@@ -8114,7 +8137,7 @@ var Gu = class {
|
|
|
8114
8137
|
} else this.d.update(U).set({ ended_at: n }).where(k(U.id, e)).run();
|
|
8115
8138
|
}
|
|
8116
8139
|
remember(e, t, n, r, i = .5, o, s) {
|
|
8117
|
-
let c =
|
|
8140
|
+
let c = zu(t), l = Bu(), u = o ? [...new Set(o)].sort().join(" ") : "", d = { ...s ?? {} };
|
|
8118
8141
|
d.clock_device_id ??= this.deviceId;
|
|
8119
8142
|
let f = d.import_key || a();
|
|
8120
8143
|
d.import_key = f;
|
|
@@ -8151,7 +8174,7 @@ var Gu = class {
|
|
|
8151
8174
|
}).returning({ id: W.id }).all()[0]?.id;
|
|
8152
8175
|
if (S == null) throw Error("memory insert returned no id");
|
|
8153
8176
|
try {
|
|
8154
|
-
|
|
8177
|
+
cu(this.db, {
|
|
8155
8178
|
memoryId: S,
|
|
8156
8179
|
opType: "upsert",
|
|
8157
8180
|
deviceId: this.deviceId
|
|
@@ -8199,7 +8222,7 @@ var Gu = class {
|
|
|
8199
8222
|
if (!t) return;
|
|
8200
8223
|
let n = z(t.metadata_json);
|
|
8201
8224
|
n.clock_device_id = this.deviceId;
|
|
8202
|
-
let r =
|
|
8225
|
+
let r = Bu(), i = (t.rev ?? 0) + 1;
|
|
8203
8226
|
this.d.update(W).set({
|
|
8204
8227
|
active: 0,
|
|
8205
8228
|
deleted_at: r,
|
|
@@ -8208,7 +8231,7 @@ var Gu = class {
|
|
|
8208
8231
|
rev: i
|
|
8209
8232
|
}).where(k(W.id, e)).run();
|
|
8210
8233
|
try {
|
|
8211
|
-
|
|
8234
|
+
cu(this.db, {
|
|
8212
8235
|
memoryId: e,
|
|
8213
8236
|
opType: "delete",
|
|
8214
8237
|
deviceId: this.deviceId
|
|
@@ -8217,20 +8240,20 @@ var Gu = class {
|
|
|
8217
8240
|
}).immediate();
|
|
8218
8241
|
}
|
|
8219
8242
|
recent(e = 10, t, n = 0) {
|
|
8220
|
-
let r = ["memory_items.active = 1"], i = Ma(t), a =
|
|
8243
|
+
let r = ["memory_items.active = 1"], i = Ma(t), a = Uu([...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
8244
|
return this.d.all(M`SELECT memory_items.* FROM ${o}
|
|
8222
8245
|
WHERE ${a}
|
|
8223
8246
|
ORDER BY created_at DESC
|
|
8224
|
-
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) =>
|
|
8247
|
+
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) => Ju(e));
|
|
8225
8248
|
}
|
|
8226
8249
|
recentByKinds(e, t = 10, n, r = 0) {
|
|
8227
8250
|
let i = e.filter((e) => e.length > 0);
|
|
8228
8251
|
if (i.length === 0) return [];
|
|
8229
|
-
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Ma(n), s =
|
|
8252
|
+
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Ma(n), s = Uu([...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
8253
|
return this.d.all(M`SELECT memory_items.* FROM ${c}
|
|
8231
8254
|
WHERE ${s}
|
|
8232
8255
|
ORDER BY created_at DESC
|
|
8233
|
-
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) =>
|
|
8256
|
+
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) => Ju(e));
|
|
8234
8257
|
}
|
|
8235
8258
|
stats() {
|
|
8236
8259
|
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 +8318,7 @@ var Gu = class {
|
|
|
8295
8318
|
if (!this.memoryOwnedBySelf(t)) throw Error("memory not owned by this device");
|
|
8296
8319
|
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
8320
|
o.visibility = n, o.workspace_kind = i, o.workspace_id = a, o.clock_device_id = this.deviceId;
|
|
8298
|
-
let s =
|
|
8321
|
+
let s = Bu(), c = (t.rev ?? 0) + 1;
|
|
8299
8322
|
this.d.update(W).set({
|
|
8300
8323
|
visibility: n,
|
|
8301
8324
|
workspace_kind: i,
|
|
@@ -8305,7 +8328,7 @@ var Gu = class {
|
|
|
8305
8328
|
rev: c
|
|
8306
8329
|
}).where(k(W.id, e)).run();
|
|
8307
8330
|
try {
|
|
8308
|
-
|
|
8331
|
+
cu(this.db, {
|
|
8309
8332
|
memoryId: e,
|
|
8310
8333
|
opType: "upsert",
|
|
8311
8334
|
deviceId: this.deviceId
|
|
@@ -8317,19 +8340,19 @@ var Gu = class {
|
|
|
8317
8340
|
}).immediate();
|
|
8318
8341
|
}
|
|
8319
8342
|
search(e, t = 10, n) {
|
|
8320
|
-
return
|
|
8343
|
+
return Uc(this, e, t, n);
|
|
8321
8344
|
}
|
|
8322
8345
|
timeline(e, t, n = 3, r = 3, i) {
|
|
8323
|
-
return
|
|
8346
|
+
return Gc(this, e, t, n, r, i);
|
|
8324
8347
|
}
|
|
8325
8348
|
explain(e, t, n = 10, r, i) {
|
|
8326
|
-
return
|
|
8349
|
+
return Zc(this, e, t, n, r, i);
|
|
8327
8350
|
}
|
|
8328
8351
|
buildMemoryPack(e, t, n, r) {
|
|
8329
|
-
return
|
|
8352
|
+
return Ml(this, e, t, n ?? null, r);
|
|
8330
8353
|
}
|
|
8331
8354
|
async buildMemoryPackAsync(e, t, n, r) {
|
|
8332
|
-
return
|
|
8355
|
+
return Nl(this, e, t, n ?? null, r);
|
|
8333
8356
|
}
|
|
8334
8357
|
normalizeStreamIdentity(e, t) {
|
|
8335
8358
|
let n = e.trim().toLowerCase() || "opencode", r = t.trim();
|
|
@@ -8513,7 +8536,7 @@ var Gu = class {
|
|
|
8513
8536
|
}).run();
|
|
8514
8537
|
}
|
|
8515
8538
|
updateRawEventIngestStats(e, t, n, r) {
|
|
8516
|
-
let i =
|
|
8539
|
+
let i = Bu(), a = t + n + r;
|
|
8517
8540
|
this.d.insert(un).values({
|
|
8518
8541
|
created_at: i,
|
|
8519
8542
|
inserted_events: e,
|
|
@@ -8546,7 +8569,7 @@ var Gu = class {
|
|
|
8546
8569
|
if (!e.eventType.trim()) throw Error("event_type is required");
|
|
8547
8570
|
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId);
|
|
8548
8571
|
return this.db.transaction(() => {
|
|
8549
|
-
let r =
|
|
8572
|
+
let r = Bu();
|
|
8550
8573
|
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
8574
|
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
8575
|
opencode_session_id: n,
|
|
@@ -8578,7 +8601,7 @@ var Gu = class {
|
|
|
8578
8601
|
if (!e.trim()) throw Error("opencode_session_id is required");
|
|
8579
8602
|
let [n, r] = this.normalizeStreamIdentity("opencode", e);
|
|
8580
8603
|
return this.db.transaction(() => {
|
|
8581
|
-
let e =
|
|
8604
|
+
let e = Bu();
|
|
8582
8605
|
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
8606
|
opencode_session_id: r,
|
|
8584
8607
|
source: n,
|
|
@@ -8647,7 +8670,7 @@ var Gu = class {
|
|
|
8647
8670
|
})();
|
|
8648
8671
|
}
|
|
8649
8672
|
updateRawEventSessionMeta(e) {
|
|
8650
|
-
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r =
|
|
8673
|
+
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r = Bu(), i = K;
|
|
8651
8674
|
this.d.insert(i).values({
|
|
8652
8675
|
opencode_session_id: n,
|
|
8653
8676
|
source: t,
|
|
@@ -8747,8 +8770,8 @@ var Gu = class {
|
|
|
8747
8770
|
${W.actor_id} IS NULL
|
|
8748
8771
|
OR TRIM(${W.actor_id}) = ''
|
|
8749
8772
|
OR ${W.actor_id} LIKE 'legacy-sync:%'
|
|
8750
|
-
OR ${W.actor_display_name} = ${
|
|
8751
|
-
OR ${W.workspace_id} = ${
|
|
8773
|
+
OR ${W.actor_display_name} = ${Ku}
|
|
8774
|
+
OR ${W.workspace_id} = ${qu}
|
|
8752
8775
|
OR ${W.trust_state} = 'legacy_unknown'
|
|
8753
8776
|
)
|
|
8754
8777
|
)`, M`${W.origin_device_id} != ${this.deviceId}`, M`${W.origin_device_id} NOT IN (
|
|
@@ -8762,13 +8785,13 @@ var Gu = class {
|
|
|
8762
8785
|
}));
|
|
8763
8786
|
}
|
|
8764
8787
|
effectiveSyncProjectFilters(e) {
|
|
8765
|
-
let t = tt(), n =
|
|
8788
|
+
let t = tt(), n = Wu(JSON.stringify(t.sync_projects_include ?? [])), r = Wu(JSON.stringify(t.sync_projects_exclude ?? []));
|
|
8766
8789
|
if (e) {
|
|
8767
8790
|
let t = this.d.select({
|
|
8768
8791
|
projects_include_json: Y.projects_include_json,
|
|
8769
8792
|
projects_exclude_json: Y.projects_exclude_json
|
|
8770
8793
|
}).from(Y).where(k(Y.peer_device_id, e)).limit(1).get();
|
|
8771
|
-
t && (t.projects_include_json != null && (n =
|
|
8794
|
+
t && (t.projects_include_json != null && (n = Wu(t.projects_include_json)), t.projects_exclude_json != null && (r = Wu(t.projects_exclude_json)));
|
|
8772
8795
|
}
|
|
8773
8796
|
return {
|
|
8774
8797
|
include: n,
|
|
@@ -8776,7 +8799,7 @@ var Gu = class {
|
|
|
8776
8799
|
};
|
|
8777
8800
|
}
|
|
8778
8801
|
syncProjectAllowed(e, t) {
|
|
8779
|
-
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a =
|
|
8802
|
+
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a = Gu(i);
|
|
8780
8803
|
return !(n.length > 0 && !n.some((e) => e === i || e === a) || r.some((e) => e === i || e === a));
|
|
8781
8804
|
}
|
|
8782
8805
|
sharingReviewSummary(e) {
|
|
@@ -8796,7 +8819,7 @@ var Gu = class {
|
|
|
8796
8819
|
if (!n || !r || r === this.actorId) continue;
|
|
8797
8820
|
let i = $(e.project);
|
|
8798
8821
|
if (t) {
|
|
8799
|
-
let e =
|
|
8822
|
+
let e = Gu(t), n = Gu(i);
|
|
8800
8823
|
if (i !== t && n !== e) continue;
|
|
8801
8824
|
}
|
|
8802
8825
|
if (!this.syncProjectAllowed(i, n)) continue;
|
|
@@ -8820,11 +8843,11 @@ var Gu = class {
|
|
|
8820
8843
|
close() {
|
|
8821
8844
|
this.db.pragma("optimize"), this.db.close();
|
|
8822
8845
|
}
|
|
8823
|
-
},
|
|
8824
|
-
function
|
|
8846
|
+
}, Xu = "_codemem._tcp.local.";
|
|
8847
|
+
function Zu(e) {
|
|
8825
8848
|
return e.mdns.length === 0 ? Ii(e.stored, []) : Ii(e.mdns, e.stored);
|
|
8826
8849
|
}
|
|
8827
|
-
function
|
|
8850
|
+
function Qu(e, t) {
|
|
8828
8851
|
let n = N(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get();
|
|
8829
8852
|
if (!n?.addresses_json) return [];
|
|
8830
8853
|
try {
|
|
@@ -8834,8 +8857,8 @@ function Ju(e, t) {
|
|
|
8834
8857
|
return [];
|
|
8835
8858
|
}
|
|
8836
8859
|
}
|
|
8837
|
-
function
|
|
8838
|
-
let i = Ii(
|
|
8860
|
+
function $u(e, t, n, r) {
|
|
8861
|
+
let i = Ii(Qu(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
|
|
8839
8862
|
return N(e, { schema: H }).insert(Y).values({
|
|
8840
8863
|
peer_device_id: t,
|
|
8841
8864
|
name: r?.name ?? null,
|
|
@@ -8855,7 +8878,7 @@ function Yu(e, t, n, r) {
|
|
|
8855
8878
|
}
|
|
8856
8879
|
}).run(), i;
|
|
8857
8880
|
}
|
|
8858
|
-
function
|
|
8881
|
+
function ed(e, t, n) {
|
|
8859
8882
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8860
8883
|
r.insert(Z).values({
|
|
8861
8884
|
peer_device_id: t,
|
|
@@ -8870,32 +8893,32 @@ function Xu(e, t, n) {
|
|
|
8870
8893
|
last_error: null
|
|
8871
8894
|
}).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
8895
|
}
|
|
8873
|
-
function
|
|
8874
|
-
let r =
|
|
8896
|
+
function td(e, t, n) {
|
|
8897
|
+
let r = Qu(e, t), i = Pi(n ?? ""), a = r;
|
|
8875
8898
|
return i && (a = [i, ...r.filter((e) => Pi(e) !== i)], N(e, { schema: H }).update(Y).set({
|
|
8876
8899
|
addresses_json: JSON.stringify(a),
|
|
8877
8900
|
last_sync_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8878
8901
|
last_error: null
|
|
8879
8902
|
}).where(k(Y.peer_device_id, t)).run()), a;
|
|
8880
8903
|
}
|
|
8881
|
-
function
|
|
8904
|
+
function nd(e, t, n) {
|
|
8882
8905
|
let r = n.include === null ? null : JSON.stringify(n.include), i = n.exclude === null ? null : JSON.stringify(n.exclude);
|
|
8883
8906
|
N(e, { schema: H }).update(Y).set({
|
|
8884
8907
|
projects_include_json: r,
|
|
8885
8908
|
projects_exclude_json: i
|
|
8886
8909
|
}).where(k(Y.peer_device_id, t)).run();
|
|
8887
8910
|
}
|
|
8888
|
-
function
|
|
8911
|
+
function rd(e, t, n) {
|
|
8889
8912
|
N(e, { schema: H }).update(Y).set({ claimed_local_actor: n ? 1 : 0 }).where(k(Y.peer_device_id, t)).run();
|
|
8890
8913
|
}
|
|
8891
|
-
function
|
|
8914
|
+
function id(e) {
|
|
8892
8915
|
try {
|
|
8893
8916
|
return fe("which", [e], { stdio: "pipe" }), !0;
|
|
8894
8917
|
} catch {
|
|
8895
8918
|
return !1;
|
|
8896
8919
|
}
|
|
8897
8920
|
}
|
|
8898
|
-
function
|
|
8921
|
+
function ad(e, t = 1200) {
|
|
8899
8922
|
try {
|
|
8900
8923
|
return fe("dns-sd", e, {
|
|
8901
8924
|
encoding: "utf8",
|
|
@@ -8914,8 +8937,8 @@ function td(e, t = 1200) {
|
|
|
8914
8937
|
return "";
|
|
8915
8938
|
}
|
|
8916
8939
|
}
|
|
8917
|
-
function
|
|
8918
|
-
let e =
|
|
8940
|
+
function od() {
|
|
8941
|
+
let e = ad([
|
|
8919
8942
|
"-B",
|
|
8920
8943
|
"_codemem._tcp",
|
|
8921
8944
|
"local."
|
|
@@ -8934,8 +8957,8 @@ function nd() {
|
|
|
8934
8957
|
}
|
|
8935
8958
|
return [...t];
|
|
8936
8959
|
}
|
|
8937
|
-
function
|
|
8938
|
-
let t =
|
|
8960
|
+
function sd(e) {
|
|
8961
|
+
let t = ad([
|
|
8939
8962
|
"-L",
|
|
8940
8963
|
e,
|
|
8941
8964
|
"_codemem._tcp",
|
|
@@ -8952,12 +8975,12 @@ function rd(e) {
|
|
|
8952
8975
|
properties: s
|
|
8953
8976
|
};
|
|
8954
8977
|
}
|
|
8955
|
-
function
|
|
8978
|
+
function cd() {
|
|
8956
8979
|
let e = process.env.CODEMEM_SYNC_MDNS;
|
|
8957
8980
|
return e ? e === "1" || e.toLowerCase() === "true" : !1;
|
|
8958
8981
|
}
|
|
8959
|
-
function
|
|
8960
|
-
if (!
|
|
8982
|
+
function ld(e, t) {
|
|
8983
|
+
if (!cd() || process.platform !== "darwin" || !id("dns-sd")) return { close() {} };
|
|
8961
8984
|
let n = pe("dns-sd", [
|
|
8962
8985
|
"-R",
|
|
8963
8986
|
`codemem-${e.slice(0, 12)}`,
|
|
@@ -8975,18 +8998,18 @@ function ad(e, t) {
|
|
|
8975
8998
|
} catch {}
|
|
8976
8999
|
} };
|
|
8977
9000
|
}
|
|
8978
|
-
function
|
|
8979
|
-
if (!
|
|
8980
|
-
let e =
|
|
9001
|
+
function ud() {
|
|
9002
|
+
if (!cd() || process.platform !== "darwin" || !id("dns-sd")) return [];
|
|
9003
|
+
let e = od();
|
|
8981
9004
|
if (e.length === 0) return [];
|
|
8982
9005
|
let t = [];
|
|
8983
9006
|
for (let n of e) {
|
|
8984
|
-
let e =
|
|
9007
|
+
let e = sd(n);
|
|
8985
9008
|
e && t.push(e);
|
|
8986
9009
|
}
|
|
8987
9010
|
return t;
|
|
8988
9011
|
}
|
|
8989
|
-
function
|
|
9012
|
+
function dd(e, t) {
|
|
8990
9013
|
let n = [];
|
|
8991
9014
|
for (let r of t) {
|
|
8992
9015
|
let t = r.properties ?? {}, i = t.device_id ?? t.device_id;
|
|
@@ -9000,40 +9023,40 @@ function sd(e, t) {
|
|
|
9000
9023
|
}
|
|
9001
9024
|
//#endregion
|
|
9002
9025
|
//#region src/sync-pass.ts
|
|
9003
|
-
var
|
|
9004
|
-
function
|
|
9026
|
+
var fd = 1048576, pd = 200, md = "2";
|
|
9027
|
+
function hd(e, t) {
|
|
9005
9028
|
return !t || !t.includes("|") ? !1 : e ? t > e : !0;
|
|
9006
9029
|
}
|
|
9007
|
-
function
|
|
9030
|
+
function gd(e) {
|
|
9008
9031
|
if (!e) return null;
|
|
9009
9032
|
let t = e.error, n = e.reason;
|
|
9010
9033
|
return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
|
|
9011
9034
|
}
|
|
9012
|
-
function
|
|
9035
|
+
function _d(e) {
|
|
9013
9036
|
return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
|
|
9014
9037
|
}
|
|
9015
|
-
function
|
|
9038
|
+
function vd(e) {
|
|
9016
9039
|
if (typeof e != "string") return null;
|
|
9017
9040
|
let t = e.trim();
|
|
9018
9041
|
return t.length > 0 ? t : null;
|
|
9019
9042
|
}
|
|
9020
|
-
function
|
|
9043
|
+
function yd(e) {
|
|
9021
9044
|
let t = e?.sync_reset;
|
|
9022
9045
|
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
9023
9046
|
let n = t;
|
|
9024
9047
|
if (!Number.isFinite(n.generation) || typeof n.snapshot_id != "string" || n.snapshot_id.trim().length === 0) return null;
|
|
9025
|
-
let r =
|
|
9048
|
+
let r = vd(n.baseline_cursor);
|
|
9026
9049
|
return {
|
|
9027
9050
|
generation: Number(n.generation),
|
|
9028
9051
|
snapshot_id: n.snapshot_id.trim(),
|
|
9029
9052
|
baseline_cursor: r,
|
|
9030
|
-
retained_floor_cursor:
|
|
9053
|
+
retained_floor_cursor: vd(n.retained_floor_cursor)
|
|
9031
9054
|
};
|
|
9032
9055
|
}
|
|
9033
|
-
function
|
|
9056
|
+
function bd(e) {
|
|
9034
9057
|
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
9058
|
}
|
|
9036
|
-
function
|
|
9059
|
+
function xd(e, t, n) {
|
|
9037
9060
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
9038
9061
|
r.insert(Z).values({
|
|
9039
9062
|
peer_device_id: t,
|
|
@@ -9045,7 +9068,7 @@ function _d(e, t, n) {
|
|
|
9045
9068
|
error: n.error ?? null
|
|
9046
9069
|
}).run();
|
|
9047
9070
|
}
|
|
9048
|
-
function
|
|
9071
|
+
function Sd(e, t) {
|
|
9049
9072
|
let n = N(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
9050
9073
|
n.update(Y).set({
|
|
9051
9074
|
last_sync_at: r,
|
|
@@ -9053,7 +9076,7 @@ function vd(e, t) {
|
|
|
9053
9076
|
last_error: null
|
|
9054
9077
|
}).where(k(Y.peer_device_id, t)).run();
|
|
9055
9078
|
}
|
|
9056
|
-
function
|
|
9079
|
+
function Cd(e, t, n, r) {
|
|
9057
9080
|
let i = N(e, { schema: H }), { replicationOps: a } = H, o;
|
|
9058
9081
|
if (t) {
|
|
9059
9082
|
let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
|
|
@@ -9065,8 +9088,8 @@ function yd(e, t, n, r) {
|
|
|
9065
9088
|
let c = `${s.created_at}|${s.op_id}`;
|
|
9066
9089
|
return [o, c];
|
|
9067
9090
|
}
|
|
9068
|
-
var
|
|
9069
|
-
async function
|
|
9091
|
+
var wd = 8;
|
|
9092
|
+
async function Td(e, t, n, r, i = 0) {
|
|
9070
9093
|
if (n.length === 0) return;
|
|
9071
9094
|
let a = { ops: n }, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await jn("POST", e, {
|
|
9072
9095
|
headers: xi({
|
|
@@ -9080,20 +9103,20 @@ async function xd(e, t, n, r, i = 0) {
|
|
|
9080
9103
|
bodyBytes: o
|
|
9081
9104
|
});
|
|
9082
9105
|
if (s === 200 && c != null) return;
|
|
9083
|
-
let l =
|
|
9084
|
-
if (s === 413 && n.length > 1 && i <
|
|
9106
|
+
let l = gd(c);
|
|
9107
|
+
if (s === 413 && n.length > 1 && i < wd && (l === "payload_too_large" || l === "too_many_ops")) {
|
|
9085
9108
|
let a = Math.floor(n.length / 2);
|
|
9086
|
-
await
|
|
9109
|
+
await Td(e, t, n.slice(0, a), r, i + 1), await Td(e, t, n.slice(a), r, i + 1);
|
|
9087
9110
|
return;
|
|
9088
9111
|
}
|
|
9089
9112
|
let u = l ? ` (${s}: ${l})` : ` (${s})`;
|
|
9090
9113
|
throw Error(`peer ops push failed${u}`);
|
|
9091
9114
|
}
|
|
9092
|
-
function
|
|
9093
|
-
|
|
9115
|
+
function Ed(e) {
|
|
9116
|
+
ju(e, 2e3), Mu(e, 200);
|
|
9094
9117
|
}
|
|
9095
|
-
async function
|
|
9096
|
-
let i = r?.limit ??
|
|
9118
|
+
async function Dd(e, t, n, r) {
|
|
9119
|
+
let i = r?.limit ?? pd, 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
9120
|
if (!o) return {
|
|
9098
9121
|
ok: !1,
|
|
9099
9122
|
error: "peer not pinned",
|
|
@@ -9101,12 +9124,12 @@ async function Cd(e, t, n, r) {
|
|
|
9101
9124
|
opsOut: 0,
|
|
9102
9125
|
addressErrors: []
|
|
9103
9126
|
};
|
|
9104
|
-
let [s, c] =
|
|
9127
|
+
let [s, c] = nu(e, t), l;
|
|
9105
9128
|
try {
|
|
9106
9129
|
[l] = Qn(e, { keysDir: a });
|
|
9107
9130
|
} catch (n) {
|
|
9108
9131
|
let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
|
|
9109
|
-
return
|
|
9132
|
+
return xd(e, t, {
|
|
9110
9133
|
ok: !1,
|
|
9111
9134
|
error: r
|
|
9112
9135
|
}), {
|
|
@@ -9131,12 +9154,12 @@ async function Cd(e, t, n, r) {
|
|
|
9131
9154
|
keysDir: a
|
|
9132
9155
|
}) });
|
|
9133
9156
|
if (u !== 200 || !d) {
|
|
9134
|
-
let e =
|
|
9157
|
+
let e = gd(d), t = e ? ` (${u}: ${e})` : ` (${u})`;
|
|
9135
9158
|
throw Error(`peer status failed${t}`);
|
|
9136
9159
|
}
|
|
9137
9160
|
if (d.fingerprint !== o) throw Error("peer fingerprint mismatch");
|
|
9138
|
-
if (String(d.protocol_version ?? "") !==
|
|
9139
|
-
let f =
|
|
9161
|
+
if (String(d.protocol_version ?? "") !== md) throw Error(`peer protocol mismatch (expected ${md}, got ${String(d.protocol_version ?? "missing")})`);
|
|
9162
|
+
let f = yd(d);
|
|
9140
9163
|
if (!f) throw Error("peer status missing sync_reset boundary");
|
|
9141
9164
|
let p = new URLSearchParams({
|
|
9142
9165
|
since: s ?? "",
|
|
@@ -9153,7 +9176,7 @@ async function Cd(e, t, n, r) {
|
|
|
9153
9176
|
keysDir: a
|
|
9154
9177
|
}) });
|
|
9155
9178
|
if (h === 409 && g?.reset_required === !0) {
|
|
9156
|
-
let r =
|
|
9179
|
+
let r = mu(e), i = {
|
|
9157
9180
|
reset_required: !0,
|
|
9158
9181
|
reason: g.reason === "generation_mismatch" || g.reason === "boundary_mismatch" ? g.reason : "stale_cursor",
|
|
9159
9182
|
generation: Number(g.generation ?? 1),
|
|
@@ -9161,7 +9184,7 @@ async function Cd(e, t, n, r) {
|
|
|
9161
9184
|
baseline_cursor: typeof g.baseline_cursor == "string" && g.baseline_cursor.trim() ? g.baseline_cursor.trim() : null,
|
|
9162
9185
|
retained_floor_cursor: typeof g.retained_floor_cursor == "string" && g.retained_floor_cursor.trim() ? g.retained_floor_cursor.trim() : null
|
|
9163
9186
|
};
|
|
9164
|
-
return
|
|
9187
|
+
return xd(e, t, {
|
|
9165
9188
|
ok: !1,
|
|
9166
9189
|
error: r.dirty ? `needs_attention:local_unsynced_shared_memory:${r.count}` : `reset_required:${i.reason}`
|
|
9167
9190
|
}), {
|
|
@@ -9175,19 +9198,19 @@ async function Cd(e, t, n, r) {
|
|
|
9175
9198
|
};
|
|
9176
9199
|
}
|
|
9177
9200
|
if (h !== 200 || g == null) {
|
|
9178
|
-
let e =
|
|
9201
|
+
let e = gd(g), t = e ? ` (${h}: ${e})` : ` (${h})`;
|
|
9179
9202
|
throw Error(`peer ops fetch failed${t}`);
|
|
9180
9203
|
}
|
|
9181
|
-
if (!
|
|
9182
|
-
let [_, v] =
|
|
9183
|
-
|
|
9184
|
-
let [x, S] =
|
|
9204
|
+
if (!bd(g)) throw Error("invalid ops response");
|
|
9205
|
+
let [_, v] = Ou(e, au(g), t), y = Fu(e, _, l), b = v || vd(g.next_cursor);
|
|
9206
|
+
hd(s, b) && (ru(e, t, { lastApplied: b }), s = b);
|
|
9207
|
+
let [x, S] = Cd(e, c, l, i), [C, w] = ku(e, x, t), T = `${n}/v1/ops`;
|
|
9185
9208
|
if (C.length > 0) {
|
|
9186
|
-
let e =
|
|
9187
|
-
for (let t of e) await
|
|
9209
|
+
let e = tu(C, fd);
|
|
9210
|
+
for (let t of e) await Td(T, l, t, a);
|
|
9188
9211
|
}
|
|
9189
9212
|
let E = w ?? S;
|
|
9190
|
-
return E &&
|
|
9213
|
+
return E && hd(c, E) && (ru(e, t, { lastAcked: E }), c = E), Sd(e, t), xd(e, t, {
|
|
9191
9214
|
ok: !0,
|
|
9192
9215
|
opsIn: y.applied,
|
|
9193
9216
|
opsOut: C.length
|
|
@@ -9207,8 +9230,8 @@ async function Cd(e, t, n, r) {
|
|
|
9207
9230
|
}
|
|
9208
9231
|
}
|
|
9209
9232
|
}
|
|
9210
|
-
let f =
|
|
9211
|
-
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail",
|
|
9233
|
+
let f = _d(u);
|
|
9234
|
+
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail", xd(e, t, {
|
|
9212
9235
|
ok: !1,
|
|
9213
9236
|
error: f
|
|
9214
9237
|
}), {
|
|
@@ -9219,15 +9242,15 @@ async function Cd(e, t, n, r) {
|
|
|
9219
9242
|
addressErrors: u
|
|
9220
9243
|
};
|
|
9221
9244
|
}
|
|
9222
|
-
async function
|
|
9245
|
+
async function Od(e, t, n) {
|
|
9223
9246
|
let r = N(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get(), i = [];
|
|
9224
9247
|
if (r?.addresses_json) try {
|
|
9225
9248
|
let e = JSON.parse(r.addresses_json);
|
|
9226
9249
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
9227
9250
|
} catch {}
|
|
9228
|
-
return
|
|
9251
|
+
return Dd(e, t, i, n);
|
|
9229
9252
|
}
|
|
9230
|
-
var
|
|
9253
|
+
var kd = [
|
|
9231
9254
|
"no route to host",
|
|
9232
9255
|
"connection refused",
|
|
9233
9256
|
"network is unreachable",
|
|
@@ -9238,33 +9261,33 @@ var Td = [
|
|
|
9238
9261
|
"errno 61",
|
|
9239
9262
|
"errno 60",
|
|
9240
9263
|
"errno 111"
|
|
9241
|
-
],
|
|
9242
|
-
function
|
|
9264
|
+
], Ad = 120, jd = 1800;
|
|
9265
|
+
function Md(e) {
|
|
9243
9266
|
if (!e) return !1;
|
|
9244
9267
|
let t = e.toLowerCase();
|
|
9245
|
-
return
|
|
9268
|
+
return kd.some((e) => t.includes(e));
|
|
9246
9269
|
}
|
|
9247
|
-
function
|
|
9270
|
+
function Nd(e, t, n = 10) {
|
|
9248
9271
|
let r = N(e, { schema: H }).select({
|
|
9249
9272
|
ok: Z.ok,
|
|
9250
9273
|
error: Z.error
|
|
9251
9274
|
}).from(Z).where(k(Z.peer_device_id, t)).orderBy(O(Z.started_at)).limit(n).all(), i = 0;
|
|
9252
9275
|
for (let e of r) {
|
|
9253
9276
|
if (e.ok) break;
|
|
9254
|
-
if (
|
|
9277
|
+
if (Md(e.error)) i++;
|
|
9255
9278
|
else break;
|
|
9256
9279
|
}
|
|
9257
9280
|
return i;
|
|
9258
9281
|
}
|
|
9259
|
-
function
|
|
9282
|
+
function Pd(e) {
|
|
9260
9283
|
if (e <= 1) return 0;
|
|
9261
9284
|
let t = Math.min(e - 1, 8);
|
|
9262
|
-
return Math.min(
|
|
9285
|
+
return Math.min(Ad * 2 ** (t - 1), jd) * (.5 + Math.random() * .5);
|
|
9263
9286
|
}
|
|
9264
|
-
function
|
|
9265
|
-
let n =
|
|
9287
|
+
function Fd(e, t) {
|
|
9288
|
+
let n = Nd(e, t);
|
|
9266
9289
|
if (n < 2) return !1;
|
|
9267
|
-
let r =
|
|
9290
|
+
let r = Pd(n);
|
|
9268
9291
|
if (r <= 0) return !1;
|
|
9269
9292
|
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
9293
|
if (!i?.started_at) return !1;
|
|
@@ -9277,7 +9300,7 @@ function jd(e, t) {
|
|
|
9277
9300
|
}
|
|
9278
9301
|
//#endregion
|
|
9279
9302
|
//#region src/sync-daemon.ts
|
|
9280
|
-
function
|
|
9303
|
+
function Id(e) {
|
|
9281
9304
|
let t = N(e, { schema: H }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
9282
9305
|
t.insert(sn).values({
|
|
9283
9306
|
id: 1,
|
|
@@ -9287,7 +9310,7 @@ function Md(e) {
|
|
|
9287
9310
|
set: { last_ok_at: M`excluded.last_ok_at` }
|
|
9288
9311
|
}).run();
|
|
9289
9312
|
}
|
|
9290
|
-
function
|
|
9313
|
+
function Ld(e, t, n) {
|
|
9291
9314
|
let r = N(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
9292
9315
|
r.insert(sn).values({
|
|
9293
9316
|
id: 1,
|
|
@@ -9303,14 +9326,14 @@ function Nd(e, t, n) {
|
|
|
9303
9326
|
}
|
|
9304
9327
|
}).run();
|
|
9305
9328
|
}
|
|
9306
|
-
async function
|
|
9329
|
+
async function Rd(e, t) {
|
|
9307
9330
|
let n = N(e, { schema: H }).select({ peer_device_id: Y.peer_device_id }).from(Y).all();
|
|
9308
9331
|
if (n.length === 0) return [];
|
|
9309
|
-
|
|
9332
|
+
Ed(e);
|
|
9310
9333
|
let r = [];
|
|
9311
9334
|
for (let i of n) {
|
|
9312
9335
|
let n = i.peer_device_id;
|
|
9313
|
-
if (
|
|
9336
|
+
if (Fd(e, n)) {
|
|
9314
9337
|
r.push({
|
|
9315
9338
|
ok: !1,
|
|
9316
9339
|
skipped: !0,
|
|
@@ -9318,7 +9341,7 @@ async function Pd(e, t) {
|
|
|
9318
9341
|
});
|
|
9319
9342
|
continue;
|
|
9320
9343
|
}
|
|
9321
|
-
let a = await
|
|
9344
|
+
let a = await Od(e, n, { keysDir: t });
|
|
9322
9345
|
r.push({
|
|
9323
9346
|
ok: a.ok,
|
|
9324
9347
|
error: a.error,
|
|
@@ -9328,13 +9351,13 @@ async function Pd(e, t) {
|
|
|
9328
9351
|
}
|
|
9329
9352
|
return r;
|
|
9330
9353
|
}
|
|
9331
|
-
async function
|
|
9354
|
+
async function zd(e) {
|
|
9332
9355
|
let t = e?.intervalS ?? 120, n = Ot(e?.dbPath), r = e?.keysDir, i = e?.signal, a = e?.onPhaseChange;
|
|
9333
9356
|
a?.("starting");
|
|
9334
9357
|
let o = Nt(n), s = null;
|
|
9335
9358
|
try {
|
|
9336
9359
|
let [t] = Qn(o, { keysDir: r });
|
|
9337
|
-
|
|
9360
|
+
cd() && e?.port && (s = ld(t, e.port));
|
|
9338
9361
|
} finally {
|
|
9339
9362
|
o.close();
|
|
9340
9363
|
}
|
|
@@ -9344,7 +9367,7 @@ async function Fd(e) {
|
|
|
9344
9367
|
}
|
|
9345
9368
|
return new Promise((e) => {
|
|
9346
9369
|
let o = !1, c = !1, l = () => {
|
|
9347
|
-
o || (o = !0,
|
|
9370
|
+
o || (o = !0, Bd(n, r).finally(() => {
|
|
9348
9371
|
o = !1, c || (c = !0, a?.("running"));
|
|
9349
9372
|
}));
|
|
9350
9373
|
}, u = setInterval(l, t * 1e3);
|
|
@@ -9361,19 +9384,19 @@ async function Fd(e) {
|
|
|
9361
9384
|
}
|
|
9362
9385
|
});
|
|
9363
9386
|
}
|
|
9364
|
-
async function
|
|
9387
|
+
async function Bd(e, t) {
|
|
9365
9388
|
let n = Nt(e);
|
|
9366
9389
|
try {
|
|
9367
|
-
await
|
|
9390
|
+
await Rd(n, t), Id(n);
|
|
9368
9391
|
} catch (e) {
|
|
9369
|
-
|
|
9392
|
+
Ld(n, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
9370
9393
|
} finally {
|
|
9371
9394
|
n.close();
|
|
9372
9395
|
}
|
|
9373
9396
|
}
|
|
9374
9397
|
//#endregion
|
|
9375
9398
|
//#region src/sync-retention-runner.ts
|
|
9376
|
-
var
|
|
9399
|
+
var Vd = class {
|
|
9377
9400
|
dbPath;
|
|
9378
9401
|
signal;
|
|
9379
9402
|
active = !1;
|
|
@@ -9405,7 +9428,7 @@ var Ld = class {
|
|
|
9405
9428
|
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
9429
|
let n = N(t, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
9407
9430
|
try {
|
|
9408
|
-
let i =
|
|
9431
|
+
let i = hu(t, {
|
|
9409
9432
|
maxAgeDays: e.syncRetentionMaxAgeDays,
|
|
9410
9433
|
maxSizeBytes: e.syncRetentionMaxSizeMb * 1024 * 1024,
|
|
9411
9434
|
maxDeleteOps: e.syncRetentionMaxOpsPerPass,
|
|
@@ -9462,18 +9485,18 @@ var Ld = class {
|
|
|
9462
9485
|
t.close();
|
|
9463
9486
|
}
|
|
9464
9487
|
}
|
|
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(
|
|
9488
|
+
}, Hd = "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`);", Ud = "\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";
|
|
9489
|
+
function Wd(e) {
|
|
9490
|
+
e.exec(Hd), e.exec(Ud), e.pragma("user_version = 6");
|
|
9468
9491
|
}
|
|
9469
|
-
function
|
|
9492
|
+
function Gd(e) {
|
|
9470
9493
|
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
9494
|
return Number(n.lastInsertRowid);
|
|
9472
9495
|
}
|
|
9473
9496
|
//#endregion
|
|
9474
9497
|
//#region src/index.ts
|
|
9475
|
-
var
|
|
9498
|
+
var Kd = "0.21.1";
|
|
9476
9499
|
//#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,
|
|
9500
|
+
export { ge as Api, $e as CODEMEM_CONFIG_ENV_OVERRIDES, R as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH, Xu 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, Yu as MemoryStore, Os as ObserverAuthAdapter, Ws as ObserverAuthError, cc as ObserverClient, Ul as RawEventSweeper, wt as SCHEMA_VERSION, hi as SIGNATURE_VERSION, Vd as SyncRetentionRunner, yo as TRIVIAL_REQUESTS, Kd as VERSION, ta as _resetEmbeddingClient, Fi as addressDedupeKey, ld as advertiseMdns, Fu as applyReplicationOps, zt as assertSchemaReady, Mu as backfillReplicationOps, Tn as backfillTagsText, Yo as backfillVectors, ao as budgetToolEvents, xi as buildAuthHeaders, An as buildBaseUrl, _i as buildCanonicalRequest, Cs as buildCodexHeaders, Ma as buildFilterClauses, Na as buildFilterClausesWithContext, fa as buildImportKey, Fe as buildIngestPayloadFromHook, Ml as buildMemoryPack, Nl as buildMemoryPackAsync, vo as buildObserverPrompt, Pe as buildRawEventEnvelopeFromHook, Rl as buildSessionContext, wo as buildTranscript, gu as bulkPruneReplicationOpsByAgeCutoff, tu as chunkOpsBySize, $i as chunkText, is as cleanOrphanSessions, Ci as cleanupNonces, ou as clockTuple, Nt as connect, Je as connectCoordinator, Nd as consecutiveConnectivityFailures, nr as coordinatorCreateInviteAction, Ki as coordinatorEnabled, rr as coordinatorImportInviteAction, ir as coordinatorListJoinRequestsAction, ar as coordinatorReviewJoinRequestAction, Xi as coordinatorStatusSnapshot, Mi as createCoordinatorApp, hd as cursorAdvances, kn as deactivateLowSignalMemories, On as deactivateLowSignalObservations, Le as decodeInvitePayload, qc as dedupeOrderedIds, Co as deriveRequest, Uo as deriveTags, ud as discoverPeersViaMdns, ra as embedTexts, Ie as encodeInvitePayload, Qn as ensureDeviceIdentity, nl as estimateTokens, Qa as eventToToolEvent, xc as expandQuery, Zc as explain, va as exportMemories, eo as extractAdapterEvent, To as extractAssistantMessages, Eo as extractAssistantUsage, ze as extractInvitePayload, vs as extractOAuthAccess, xs as extractOAuthAccountId, Ss as extractOAuthExpires, Do as extractPrompts, ys as extractProviderApiKey, au as extractReplicationOps, $a as extractToolEvents, Ho as fileTags, ku as filterReplicationOpsForSync, Ou as filterReplicationOpsForSyncWithStatus, In as fingerprintPublicKey, So as firstSentence, zl 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, nu as getReplicationCursor, Rt as getSchemaVersion, Xl as getSyncResetState, zo as hasMeaningfulObservation, mu as hasUnsyncedSharedMemoryChanges, Qi as hashText, Ea as importMemories, ns as ingest, as as ingestMain, hn as initDatabase, Wd as initTestSchema, Gd as insertTestSession, Re as inviteLink, Md as isConnectivityError, Lt as isEmbeddingDisabled, Ja as isInternalMemoryTool, Kt as isLowSignalObservation, su as isNewerClock, Ba as isSensitiveFieldName, xo as isTrivialRequest, Cc as kindBonus, lt as listConfiguredOpenCodeProviders, Zi as listCoordinatorJoinRequests, ot as listCustomProviders, ut as listObserverProviderOptions, pu as loadMemorySnapshotPageForPeer, Us as loadObserverConfig, Ze as loadOpenCodeConfig, hs as loadOpenCodeOAuthCache, Qu as loadPeerAddresses, Wn as loadPrivateKey, Vn as loadPrivateKeyKeychain, Un as loadPublicKey, fu as loadReplicationOpsForPeer, du as loadReplicationOpsSince, It as loadSqliteVec, Yi as lookupCoordinatorPeers, Me as mapClaudeHookPayload, dd as mdnsAddressesForPeer, cd as mdnsEnabled, Ii as mergeAddresses, pa as mergeSummaryMetadata, Mt as migrateLegacyDbPath, ju 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, ls as parsePositiveMemoryId, cs as parseStrictInteger, Pd as peerBackoffSeconds, _u as planReplicationOpsAgePrune, bs as probeAvailableCredentials, to as projectAdapterToolEvent, qt as projectBasename, Yt as projectClause, Jt as projectColumnClause, Xt as projectMatchesFilter, hu as pruneReplicationOps, yn as rawEventsGate, Ts as readAuthFile, tt as readCodememConfigFile, Gi as readCoordinatorSyncConfig, ya as readImportPayload, Sc as recencyScore, Si as recordNonce, td as recordPeerSuccess, cu as recordReplicationOp, ed as recordSyncAttempt, fs as redactText, Ji as registerCoordinatorPresence, Ms as renderObserverHeaders, jn as requestJson, Hc 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, gs as resolveOAuthProvider, ht as resolvePlaceholder, Qt as resolveProject, bn as retryRawEventFailures, ws as runAuthCommand, zd as runSyncDaemon, Od as runSyncPass, Ua as sanitizePayload, Ka as sanitizeToolOutput, H as schema, Uc as search, Zu as selectDialAddresses, Xo as semanticSearch, aa as serializeFloat32, rd as setPeerLocalActorClaim, nd as setPeerProjectFilter, ru as setReplicationCursor, Ld as setSyncDaemonError, Id as setSyncDaemonOk, Zl as setSyncResetState, Fd as shouldSkipOfflinePeer, vi as signRequest, Bn as storePrivateKeyKeychain, Jo as storeVectors, Ye as stripJsonComments, La as stripPrivate, Va as stripPrivateObj, Xe as stripTrailingCommas, Rd as syncDaemonTick, Dd as syncOnce, Ed as syncPassPreflight, Bt as tableExists, Gc as timeline, B as toJson, V as toJsonNullable, $u as updatePeerAddresses, gn as vacuumDatabase, Zn as validateExistingKeypair, yi as verifySignature, nt as writeCodememConfigFile };
|
|
9478
9501
|
|
|
9479
9502
|
//# sourceMappingURL=index.js.map
|