zen-code 4.7.4 → 4.8.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/app.js +271 -0
- package/dist/chunk-0fhpz98a.js +2 -0
- package/dist/chunk-15smn69q.js +31 -0
- package/dist/chunk-3ep2tag7.js +2 -0
- package/dist/chunk-3jek9sxm.js +2 -0
- package/dist/chunk-3n2b4eb4.js +2 -0
- package/dist/chunk-3znrwnd8.js +1 -0
- package/dist/chunk-4b8yaknt.js +1 -0
- package/dist/chunk-5fqt5yg1.js +81 -0
- package/dist/chunk-5nzs0q25.js +1 -0
- package/dist/chunk-5wn1nfqy.js +6 -0
- package/dist/chunk-6ty22kkt.js +4 -0
- package/dist/chunk-70a0e941.js +1 -0
- package/dist/chunk-7dp8kq2f.js +2 -0
- package/dist/chunk-8nhayyat.js +1 -0
- package/dist/chunk-9k57afdm.js +2 -0
- package/dist/chunk-9kc9cea3.js +7 -0
- package/dist/chunk-bgpcx3bm.js +2 -0
- package/dist/chunk-bjywwcgn.js +26 -0
- package/dist/chunk-c9q11tk2.js +88 -0
- package/dist/chunk-cga0m5sy.js +1 -0
- package/dist/chunk-cze71w02.js +2 -0
- package/dist/chunk-czz2fs2w.js +7 -0
- package/dist/chunk-dh3jz71n.js +1 -0
- package/dist/chunk-e0sqjq2h.js +1 -0
- package/dist/chunk-efhkdw2z.js +1 -0
- package/dist/chunk-ew7249h9.js +1 -0
- package/dist/chunk-h5nnz4dy.js +1 -0
- package/dist/chunk-hww94vjn.js +1 -0
- package/dist/chunk-j1n8jp1w.js +253 -0
- package/dist/chunk-j204fejq.js +1 -0
- package/dist/chunk-jkbtx9va.js +2 -0
- package/dist/chunk-k67epfhc.js +1 -0
- package/dist/chunk-kbs4px1b.js +6 -0
- package/dist/chunk-keqk70wm.js +2 -0
- package/dist/chunk-kxk71nn0.js +1 -0
- package/dist/chunk-mg8zpgaz.js +1 -0
- package/dist/chunk-n1d8xx5k.js +2 -0
- package/dist/chunk-ndtwq2zx.js +2 -0
- package/dist/chunk-pdkbrds7.js +1 -0
- package/dist/chunk-q8arjxg1.js +23 -0
- package/dist/chunk-rdc9pxf6.js +1 -0
- package/dist/chunk-rrkzfahh.js +91 -0
- package/dist/chunk-s3fyfrka.js +2 -0
- package/dist/chunk-sft6ep0c.js +310 -0
- package/dist/chunk-vc384abg.js +3 -0
- package/dist/chunk-vjj00e3e.js +6 -0
- package/dist/chunk-vkng13p1.js +424 -0
- package/dist/chunk-wbn1hbxf.js +1 -0
- package/dist/chunk-wwn7gw8g.js +274 -0
- package/dist/chunk-yaa4eesd.js +2 -0
- package/dist/chunk-yvhq458c.js +25 -0
- package/dist/cli.js +2 -0
- package/dist/nonInteractive.js +4 -0
- package/dist/zen-keyboard.js +3 -0
- package/package.json +88 -87
- package/LICENSE +0 -201
- package/dist/FileSystemPluginStore-ChortK7z.mjs +0 -64
- package/dist/FileSystemSkillStore-Dl5briBv.mjs +0 -108
- package/dist/MultiLineTextInput-CL8nm9nv.mjs +0 -24492
- package/dist/_commonjsHelpers-DQNKXVTB.mjs +0 -33
- package/dist/app-CK3nD8Gj.mjs +0 -22428
- package/dist/checkpoint-C5AFBYE--CczNxXBB.mjs +0 -355
- package/dist/checkpoint-DxiUsHMy-B5iaccT2.mjs +0 -394
- package/dist/cli.mjs +0 -57
- package/dist/devtools-CzaVuYnh.mjs +0 -2667
- package/dist/graphBuilder-DJoMXf6J.mjs +0 -28909
- package/dist/index-BPG5Np-8.mjs +0 -144
- package/dist/index-Dxfhvdx8.mjs +0 -23
- package/dist/index-F6_SKYUd.mjs +0 -463
- package/dist/load-iYJqYrjn.mjs +0 -119
- package/dist/memories-CaHDnBK1.mjs +0 -115
- package/dist/metadata-XVTVXthy.mjs +0 -6
- package/dist/nonInteractive.mjs +0 -55
- package/dist/pg-adapter-BFtir1GE-BbUXBpaX.mjs +0 -60
- package/dist/queue-DySatFkr-CG2GdO4P.mjs +0 -106
- package/dist/remote-threads-CrG03ZS7-C9duTCnB.mjs +0 -157
- package/dist/shallow-G4eKoZ7M.mjs +0 -331
- package/dist/shallow-checkpoint-BEhTdp7z-DfHxnfoU.mjs +0 -383
- package/dist/sqlite-adapter-oBA95xba-BrBWorSV.mjs +0 -82
- package/dist/subTasks-DNjIN4eU.mjs +0 -18
- package/dist/zen-code.mjs +0 -3
- package/dist/zen-keyboard.mjs +0 -13
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
import { B as $, u as g } from "./app-CK3nD8Gj.mjs";
|
|
2
|
-
import "./graphBuilder-DJoMXf6J.mjs";
|
|
3
|
-
import { createClient as T } from "redis";
|
|
4
|
-
function k(u) {
|
|
5
|
-
if (u === null || typeof u != "object") return JSON.stringify(u);
|
|
6
|
-
if (Array.isArray(u)) return JSON.stringify(u.map((i) => k(i)));
|
|
7
|
-
const t = {}, e = Object.keys(u).sort();
|
|
8
|
-
for (const i of e) t[i] = u[i];
|
|
9
|
-
return JSON.stringify(t, (i, n) => {
|
|
10
|
-
if (n !== null && typeof n == "object" && !Array.isArray(n)) {
|
|
11
|
-
const s = {}, c = Object.keys(n).sort();
|
|
12
|
-
for (const r of c) s[r] = n[r];
|
|
13
|
-
return s;
|
|
14
|
-
}
|
|
15
|
-
return n;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const S = [{
|
|
19
|
-
index: "checkpoints",
|
|
20
|
-
prefix: "checkpoint:",
|
|
21
|
-
schema: {
|
|
22
|
-
"$.thread_id": {
|
|
23
|
-
type: "TAG",
|
|
24
|
-
AS: "thread_id"
|
|
25
|
-
},
|
|
26
|
-
"$.checkpoint_ns": {
|
|
27
|
-
type: "TAG",
|
|
28
|
-
AS: "checkpoint_ns"
|
|
29
|
-
},
|
|
30
|
-
"$.checkpoint_id": {
|
|
31
|
-
type: "TAG",
|
|
32
|
-
AS: "checkpoint_id"
|
|
33
|
-
},
|
|
34
|
-
"$.parent_checkpoint_id": {
|
|
35
|
-
type: "TAG",
|
|
36
|
-
AS: "parent_checkpoint_id"
|
|
37
|
-
},
|
|
38
|
-
"$.checkpoint_ts": {
|
|
39
|
-
type: "NUMERIC",
|
|
40
|
-
AS: "checkpoint_ts"
|
|
41
|
-
},
|
|
42
|
-
"$.has_writes": {
|
|
43
|
-
type: "TAG",
|
|
44
|
-
AS: "has_writes"
|
|
45
|
-
},
|
|
46
|
-
"$.source": {
|
|
47
|
-
type: "TAG",
|
|
48
|
-
AS: "source"
|
|
49
|
-
},
|
|
50
|
-
"$.step": {
|
|
51
|
-
type: "NUMERIC",
|
|
52
|
-
AS: "step"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}, {
|
|
56
|
-
index: "checkpoint_writes",
|
|
57
|
-
prefix: "checkpoint_write:",
|
|
58
|
-
schema: {
|
|
59
|
-
"$.thread_id": {
|
|
60
|
-
type: "TAG",
|
|
61
|
-
AS: "thread_id"
|
|
62
|
-
},
|
|
63
|
-
"$.checkpoint_ns": {
|
|
64
|
-
type: "TAG",
|
|
65
|
-
AS: "checkpoint_ns"
|
|
66
|
-
},
|
|
67
|
-
"$.checkpoint_id": {
|
|
68
|
-
type: "TAG",
|
|
69
|
-
AS: "checkpoint_id"
|
|
70
|
-
},
|
|
71
|
-
"$.task_id": {
|
|
72
|
-
type: "TAG",
|
|
73
|
-
AS: "task_id"
|
|
74
|
-
},
|
|
75
|
-
"$.idx": {
|
|
76
|
-
type: "NUMERIC",
|
|
77
|
-
AS: "idx"
|
|
78
|
-
},
|
|
79
|
-
"$.channel": {
|
|
80
|
-
type: "TAG",
|
|
81
|
-
AS: "channel"
|
|
82
|
-
},
|
|
83
|
-
"$.type": {
|
|
84
|
-
type: "TAG",
|
|
85
|
-
AS: "type"
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}];
|
|
89
|
-
var C = class w extends $ {
|
|
90
|
-
client;
|
|
91
|
-
ttlConfig;
|
|
92
|
-
constructor(t, e) {
|
|
93
|
-
super(), this.client = t, this.ttlConfig = e;
|
|
94
|
-
}
|
|
95
|
-
static async fromUrl(t, e) {
|
|
96
|
-
const i = T({ url: t });
|
|
97
|
-
await i.connect();
|
|
98
|
-
const n = new w(i, e);
|
|
99
|
-
return await n.ensureIndexes(), n;
|
|
100
|
-
}
|
|
101
|
-
async get(t) {
|
|
102
|
-
return (await this.getTuple(t))?.checkpoint;
|
|
103
|
-
}
|
|
104
|
-
async put(t, e, i, n) {
|
|
105
|
-
await this.ensureIndexes();
|
|
106
|
-
const s = t.configurable?.thread_id, c = t.configurable?.checkpoint_ns ?? "", r = t.configurable?.checkpoint_id;
|
|
107
|
-
if (!s) throw new Error("thread_id is required");
|
|
108
|
-
const a = e.id || g(0), l = `checkpoint:${s}:${c}:shallow`;
|
|
109
|
-
let h = null, p = null;
|
|
110
|
-
try {
|
|
111
|
-
h = await this.client.json.get(l), h && typeof h == "object" && (p = h.checkpoint_id);
|
|
112
|
-
} catch {
|
|
113
|
-
}
|
|
114
|
-
p && p !== a && await this.cleanupOldCheckpoint(s, c, p);
|
|
115
|
-
const o = {
|
|
116
|
-
...e,
|
|
117
|
-
channel_values: e.channel_values || {},
|
|
118
|
-
channel_blobs: void 0
|
|
119
|
-
}, d = {
|
|
120
|
-
thread_id: s,
|
|
121
|
-
checkpoint_ns: c,
|
|
122
|
-
checkpoint_id: a,
|
|
123
|
-
parent_checkpoint_id: r || null,
|
|
124
|
-
checkpoint: o,
|
|
125
|
-
metadata: this.sanitizeMetadata(i),
|
|
126
|
-
checkpoint_ts: Date.now(),
|
|
127
|
-
has_writes: "false"
|
|
128
|
-
};
|
|
129
|
-
return this.addSearchableMetadataFields(d, i), await this.client.json.set(l, "$", d), this.ttlConfig?.defaultTTL && await this.applyTTL(l), { configurable: {
|
|
130
|
-
thread_id: s,
|
|
131
|
-
checkpoint_ns: c,
|
|
132
|
-
checkpoint_id: a
|
|
133
|
-
} };
|
|
134
|
-
}
|
|
135
|
-
async getTuple(t) {
|
|
136
|
-
const e = t.configurable?.thread_id, i = t.configurable?.checkpoint_ns ?? "", n = t.configurable?.checkpoint_id;
|
|
137
|
-
if (!e) return;
|
|
138
|
-
const s = `checkpoint:${e}:${i}:shallow`, c = await this.client.json.get(s);
|
|
139
|
-
if (!c || n && c.checkpoint_id !== n) return;
|
|
140
|
-
this.ttlConfig?.refreshOnRead && this.ttlConfig?.defaultTTL && await this.applyTTL(s);
|
|
141
|
-
const r = await this.serde.loadsTyped("json", JSON.stringify(c.checkpoint));
|
|
142
|
-
let a;
|
|
143
|
-
return c.has_writes === "true" && (a = await this.loadPendingWrites(c.thread_id, c.checkpoint_ns, c.checkpoint_id)), await this.createCheckpointTuple(c, r, a);
|
|
144
|
-
}
|
|
145
|
-
async *list(t, e) {
|
|
146
|
-
if (await this.ensureIndexes(), t?.configurable?.thread_id) {
|
|
147
|
-
const i = await this.getTuple(t);
|
|
148
|
-
i && (e?.filter ? this.checkMetadataFilterMatch(i.metadata, e.filter) && (yield i) : yield i);
|
|
149
|
-
} else {
|
|
150
|
-
const i = [];
|
|
151
|
-
if (e?.filter)
|
|
152
|
-
for (const [c, r] of Object.entries(e.filter)) r === void 0 || r === null || (typeof r == "string" ? i.push(`(@${c}:{${r}})`) : typeof r == "number" && i.push(`(@${c}:[${r} ${r}])`));
|
|
153
|
-
i.length === 0 && i.push("*");
|
|
154
|
-
const n = i.join(" "), s = e?.limit ?? 10;
|
|
155
|
-
try {
|
|
156
|
-
const c = await this.client.ft.search("checkpoints", n, {
|
|
157
|
-
LIMIT: {
|
|
158
|
-
from: 0,
|
|
159
|
-
size: s * 2
|
|
160
|
-
},
|
|
161
|
-
SORTBY: {
|
|
162
|
-
BY: "checkpoint_ts",
|
|
163
|
-
DIRECTION: "DESC"
|
|
164
|
-
}
|
|
165
|
-
}), r = /* @__PURE__ */ new Set();
|
|
166
|
-
let a = 0;
|
|
167
|
-
for (const l of c.documents) {
|
|
168
|
-
if (a >= s) break;
|
|
169
|
-
const h = l.value, p = `${h.thread_id}:${h.checkpoint_ns}`;
|
|
170
|
-
if (r.has(p) || (r.add(p), e?.filter && !this.checkMetadataFilterMatch(h.metadata, e.filter)))
|
|
171
|
-
continue;
|
|
172
|
-
const o = await this.serde.loadsTyped("json", JSON.stringify(h.checkpoint));
|
|
173
|
-
yield await this.createCheckpointTuple(h, o), a++;
|
|
174
|
-
}
|
|
175
|
-
} catch (c) {
|
|
176
|
-
if (c.message?.includes("no such index")) {
|
|
177
|
-
const a = await this.client.keys("checkpoint:*:*:shallow");
|
|
178
|
-
if (a.length === 0) return;
|
|
179
|
-
a.sort().reverse();
|
|
180
|
-
const l = /* @__PURE__ */ new Set();
|
|
181
|
-
let h = 0;
|
|
182
|
-
const p = e?.limit ?? 10;
|
|
183
|
-
for (const o of a) {
|
|
184
|
-
if (h >= p) break;
|
|
185
|
-
const d = await this.client.json.get(o);
|
|
186
|
-
if (!d) continue;
|
|
187
|
-
const f = `${d.thread_id}:${d.checkpoint_ns}`;
|
|
188
|
-
if (l.has(f) || (l.add(f), e?.filter && !this.checkMetadataFilterMatch(d.metadata, e.filter)))
|
|
189
|
-
continue;
|
|
190
|
-
const y = await this.serde.loadsTyped("json", JSON.stringify(d.checkpoint));
|
|
191
|
-
yield await this.createCheckpointTuple(d, y), h++;
|
|
192
|
-
}
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
throw c;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
async putWrites(t, e, i) {
|
|
200
|
-
await this.ensureIndexes();
|
|
201
|
-
const n = t.configurable?.thread_id, s = t.configurable?.checkpoint_ns ?? "", c = t.configurable?.checkpoint_id;
|
|
202
|
-
if (!n || !c) throw new Error("thread_id and checkpoint_id are required");
|
|
203
|
-
const r = `checkpoint_write:${n}:${s}:${c}:${i}:*`, a = await this.client.keys(r);
|
|
204
|
-
a.length > 0 && await this.client.del(a);
|
|
205
|
-
const l = [];
|
|
206
|
-
for (let o = 0; o < e.length; o++) {
|
|
207
|
-
const [d, f] = e[o], y = `checkpoint_write:${n}:${s}:${c}:${i}:${o}`;
|
|
208
|
-
l.push(y);
|
|
209
|
-
const _ = {
|
|
210
|
-
thread_id: n,
|
|
211
|
-
checkpoint_ns: s,
|
|
212
|
-
checkpoint_id: c,
|
|
213
|
-
task_id: i,
|
|
214
|
-
idx: o,
|
|
215
|
-
channel: d,
|
|
216
|
-
type: typeof f == "object" ? "json" : "string",
|
|
217
|
-
value: f
|
|
218
|
-
};
|
|
219
|
-
await this.client.json.set(y, "$", _);
|
|
220
|
-
}
|
|
221
|
-
if (l.length > 0) {
|
|
222
|
-
const o = `write_keys_zset:${n}:${s}:${c}`, d = {};
|
|
223
|
-
l.forEach((f, y) => {
|
|
224
|
-
d[f] = y;
|
|
225
|
-
}), await this.client.zAdd(o, Object.entries(d).map(([f, y]) => ({
|
|
226
|
-
score: y,
|
|
227
|
-
value: f
|
|
228
|
-
}))), this.ttlConfig?.defaultTTL && await this.applyTTL(...l, o);
|
|
229
|
-
}
|
|
230
|
-
const h = `checkpoint:${n}:${s}:shallow`;
|
|
231
|
-
if (await this.client.exists(h)) {
|
|
232
|
-
const o = await this.client.json.get(h);
|
|
233
|
-
o && (o.has_writes = "true", await this.client.json.set(h, "$", o));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
async deleteThread(t) {
|
|
237
|
-
const e = `checkpoint:${t}:*:shallow`, i = await this.client.keys(e);
|
|
238
|
-
i.length > 0 && await this.client.del(i);
|
|
239
|
-
const n = `checkpoint_write:${t}:*`, s = await this.client.keys(n);
|
|
240
|
-
s.length > 0 && await this.client.del(s);
|
|
241
|
-
const c = `write_keys_zset:${t}:*`, r = await this.client.keys(c);
|
|
242
|
-
r.length > 0 && await this.client.del(r);
|
|
243
|
-
}
|
|
244
|
-
async end() {
|
|
245
|
-
await this.client.quit();
|
|
246
|
-
}
|
|
247
|
-
addSearchableMetadataFields(t, e) {
|
|
248
|
-
e && ("source" in e && (t.source = e.source), "step" in e && (t.step = e.step), "writes" in e && (t.writes = typeof e.writes == "object" ? JSON.stringify(e.writes) : e.writes), "score" in e && (t.score = e.score));
|
|
249
|
-
}
|
|
250
|
-
async createCheckpointTuple(t, e, i) {
|
|
251
|
-
const n = await this.serde.loadsTyped("json", JSON.stringify(t.metadata));
|
|
252
|
-
return {
|
|
253
|
-
config: { configurable: {
|
|
254
|
-
thread_id: t.thread_id,
|
|
255
|
-
checkpoint_ns: t.checkpoint_ns,
|
|
256
|
-
checkpoint_id: t.checkpoint_id
|
|
257
|
-
} },
|
|
258
|
-
checkpoint: e,
|
|
259
|
-
metadata: n,
|
|
260
|
-
parentConfig: t.parent_checkpoint_id ? { configurable: {
|
|
261
|
-
thread_id: t.thread_id,
|
|
262
|
-
checkpoint_ns: t.checkpoint_ns,
|
|
263
|
-
checkpoint_id: t.parent_checkpoint_id
|
|
264
|
-
} } : void 0,
|
|
265
|
-
pendingWrites: i
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
async applyTTL(...t) {
|
|
269
|
-
if (!this.ttlConfig?.defaultTTL) return;
|
|
270
|
-
const e = Math.floor(this.ttlConfig.defaultTTL * 60), i = await Promise.allSettled(t.map((n) => this.client.expire(n, e)));
|
|
271
|
-
for (let n = 0; n < i.length; n++) i[n].status === "rejected" && console.warn(`Failed to set TTL for key ${t[n]}:`, i[n].reason);
|
|
272
|
-
}
|
|
273
|
-
async loadPendingWrites(t, e, i) {
|
|
274
|
-
const n = `write_keys_zset:${t}:${e}:${i}`, s = await this.client.zRange(n, 0, -1);
|
|
275
|
-
if (s.length === 0) return;
|
|
276
|
-
const c = [];
|
|
277
|
-
for (const r of s) {
|
|
278
|
-
const a = await this.client.json.get(r);
|
|
279
|
-
if (a) {
|
|
280
|
-
const l = await this.serde.loadsTyped("json", JSON.stringify(a.value));
|
|
281
|
-
c.push([
|
|
282
|
-
a.task_id,
|
|
283
|
-
a.channel,
|
|
284
|
-
l
|
|
285
|
-
]);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return c;
|
|
289
|
-
}
|
|
290
|
-
checkMetadataFilterMatch(t, e) {
|
|
291
|
-
for (const [i, n] of Object.entries(e)) {
|
|
292
|
-
const s = t?.[i];
|
|
293
|
-
if (n === null) {
|
|
294
|
-
if (!(i in (t || {})) || s !== null) return !1;
|
|
295
|
-
} else if (typeof n == "object" && !Array.isArray(n)) {
|
|
296
|
-
if (typeof s != "object" || s === null || k(n) !== k(s)) return !1;
|
|
297
|
-
} else if (s !== n) return !1;
|
|
298
|
-
}
|
|
299
|
-
return !0;
|
|
300
|
-
}
|
|
301
|
-
async cleanupOldCheckpoint(t, e, i) {
|
|
302
|
-
const n = `checkpoint_write:${t}:${e}:${i}:*`, s = await this.client.keys(n);
|
|
303
|
-
s.length > 0 && await this.client.del(s);
|
|
304
|
-
const c = `write_keys_zset:${t}:${e}:${i}`;
|
|
305
|
-
await this.client.del(c);
|
|
306
|
-
const r = `checkpoint_blob:${t}:${e}:${i}:*`, a = await this.client.keys(r);
|
|
307
|
-
a.length > 0 && await this.client.del(a);
|
|
308
|
-
}
|
|
309
|
-
sanitizeMetadata(t) {
|
|
310
|
-
if (!t) return {};
|
|
311
|
-
const e = {};
|
|
312
|
-
for (const [i, n] of Object.entries(t)) {
|
|
313
|
-
const s = i.replace(/\x00/g, "");
|
|
314
|
-
e[s] = typeof n == "string" ? n.replace(/\x00/g, "") : n;
|
|
315
|
-
}
|
|
316
|
-
return e;
|
|
317
|
-
}
|
|
318
|
-
async ensureIndexes() {
|
|
319
|
-
for (const t of S) try {
|
|
320
|
-
await this.client.ft.create(t.index, t.schema, {
|
|
321
|
-
ON: "JSON",
|
|
322
|
-
PREFIX: t.prefix
|
|
323
|
-
});
|
|
324
|
-
} catch (e) {
|
|
325
|
-
e.message?.includes("Index already exists") || console.error(`Failed to create index ${t.index}:`, e.message);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
export {
|
|
330
|
-
C as ShallowRedisSaver
|
|
331
|
-
};
|