zen-code 4.5.0 → 4.6.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.
Files changed (37) hide show
  1. package/dist/MultiLineTextInput-B4NEXnFm.mjs +23343 -0
  2. package/dist/cli.mjs +44 -20
  3. package/dist/devtools-BHqoL8a6.mjs +11653 -0
  4. package/dist/graphBuilder-B3IJ7dB2.mjs +2641 -0
  5. package/dist/{index-BHwkVemt.mjs → index-DEcMgCTj.mjs} +1 -1
  6. package/dist/{memories-B8HqG014.mjs → memories-rSGKIPk5.mjs} +1 -1
  7. package/dist/metadata-XVTVXthy.mjs +6 -0
  8. package/dist/nonInteractive.mjs +7 -6
  9. package/dist/{subTasks-BTMXARkP.mjs → subTasks-5KLIr9iy.mjs} +47 -48
  10. package/dist/zen-code.mjs +8654 -2
  11. package/dist/zen-keyboard.mjs +7 -6
  12. package/package.json +7 -9
  13. package/dist/MultiLineTextInput-e7hD79Wp.mjs +0 -24631
  14. package/dist/app-DtYW5k3J.mjs +0 -16061
  15. package/dist/assets/worker-I4QjJYba.js +0 -1
  16. package/dist/checkpoint-1sAx_j1E-4BdN8r-w.mjs +0 -319
  17. package/dist/checkpoint-DxiUsHMy-BV-8KBKD.mjs +0 -394
  18. package/dist/chunk-YWE62C55-DID9N9eS.mjs +0 -193
  19. package/dist/devtools-CzaVuYnh.mjs +0 -2667
  20. package/dist/graphBuilder-B0bC88R_.mjs +0 -48756
  21. package/dist/id-Cu7CRpDw.mjs +0 -79
  22. package/dist/index-BUGHAUbY.mjs +0 -117
  23. package/dist/index-Bgm_TqjU.mjs +0 -212
  24. package/dist/index-C5j-48Ft.mjs +0 -75
  25. package/dist/index-CSvPIzA-.mjs +0 -464
  26. package/dist/index-DS5HVciX.mjs +0 -216
  27. package/dist/kysely-Bchvsze0.mjs +0 -4316
  28. package/dist/load-Cjl9cJ0o.mjs +0 -105
  29. package/dist/migrator-BatO36Tk.mjs +0 -592
  30. package/dist/pg-adapter-BFtir1GE-BU2H39HC.mjs +0 -62
  31. package/dist/postgres-dialect-DaHvQ_AZ.mjs +0 -211
  32. package/dist/queue-Bfg-8ehP-Lko1egu-.mjs +0 -106
  33. package/dist/remote-threads-CrG03ZS7-C9duTCnB.mjs +0 -157
  34. package/dist/shallow-DAx5vVov.mjs +0 -332
  35. package/dist/sql-CJsUpKEQ.mjs +0 -8106
  36. package/dist/sqlite-adapter-Bbonr5S5-DQLjfvyu.mjs +0 -68
  37. package/dist/zen-init.mjs +0 -1
@@ -1,332 +0,0 @@
1
- import { u as $ } from "./id-Cu7CRpDw.mjs";
2
- import { B as g } from "./app-DtYW5k3J.mjs";
3
- import "./graphBuilder-B0bC88R_.mjs";
4
- import { createClient as T } from "redis";
5
- function k(u) {
6
- if (u === null || typeof u != "object") return JSON.stringify(u);
7
- if (Array.isArray(u)) return JSON.stringify(u.map((i) => k(i)));
8
- const t = {}, e = Object.keys(u).sort();
9
- for (const i of e) t[i] = u[i];
10
- return JSON.stringify(t, (i, n) => {
11
- if (n !== null && typeof n == "object" && !Array.isArray(n)) {
12
- const s = {}, c = Object.keys(n).sort();
13
- for (const r of c) s[r] = n[r];
14
- return s;
15
- }
16
- return n;
17
- });
18
- }
19
- const S = [{
20
- index: "checkpoints",
21
- prefix: "checkpoint:",
22
- schema: {
23
- "$.thread_id": {
24
- type: "TAG",
25
- AS: "thread_id"
26
- },
27
- "$.checkpoint_ns": {
28
- type: "TAG",
29
- AS: "checkpoint_ns"
30
- },
31
- "$.checkpoint_id": {
32
- type: "TAG",
33
- AS: "checkpoint_id"
34
- },
35
- "$.parent_checkpoint_id": {
36
- type: "TAG",
37
- AS: "parent_checkpoint_id"
38
- },
39
- "$.checkpoint_ts": {
40
- type: "NUMERIC",
41
- AS: "checkpoint_ts"
42
- },
43
- "$.has_writes": {
44
- type: "TAG",
45
- AS: "has_writes"
46
- },
47
- "$.source": {
48
- type: "TAG",
49
- AS: "source"
50
- },
51
- "$.step": {
52
- type: "NUMERIC",
53
- AS: "step"
54
- }
55
- }
56
- }, {
57
- index: "checkpoint_writes",
58
- prefix: "checkpoint_write:",
59
- schema: {
60
- "$.thread_id": {
61
- type: "TAG",
62
- AS: "thread_id"
63
- },
64
- "$.checkpoint_ns": {
65
- type: "TAG",
66
- AS: "checkpoint_ns"
67
- },
68
- "$.checkpoint_id": {
69
- type: "TAG",
70
- AS: "checkpoint_id"
71
- },
72
- "$.task_id": {
73
- type: "TAG",
74
- AS: "task_id"
75
- },
76
- "$.idx": {
77
- type: "NUMERIC",
78
- AS: "idx"
79
- },
80
- "$.channel": {
81
- type: "TAG",
82
- AS: "channel"
83
- },
84
- "$.type": {
85
- type: "TAG",
86
- AS: "type"
87
- }
88
- }
89
- }];
90
- var O = class w extends g {
91
- client;
92
- ttlConfig;
93
- constructor(t, e) {
94
- super(), this.client = t, this.ttlConfig = e;
95
- }
96
- static async fromUrl(t, e) {
97
- const i = T({ url: t });
98
- await i.connect();
99
- const n = new w(i, e);
100
- return await n.ensureIndexes(), n;
101
- }
102
- async get(t) {
103
- return (await this.getTuple(t))?.checkpoint;
104
- }
105
- async put(t, e, i, n) {
106
- await this.ensureIndexes();
107
- const s = t.configurable?.thread_id, c = t.configurable?.checkpoint_ns ?? "", r = t.configurable?.checkpoint_id;
108
- if (!s) throw new Error("thread_id is required");
109
- const a = e.id || $(0), l = `checkpoint:${s}:${c}:shallow`;
110
- let h = null, p = null;
111
- try {
112
- h = await this.client.json.get(l), h && typeof h == "object" && (p = h.checkpoint_id);
113
- } catch {
114
- }
115
- p && p !== a && await this.cleanupOldCheckpoint(s, c, p);
116
- const o = {
117
- ...e,
118
- channel_values: e.channel_values || {},
119
- channel_blobs: void 0
120
- }, d = {
121
- thread_id: s,
122
- checkpoint_ns: c,
123
- checkpoint_id: a,
124
- parent_checkpoint_id: r || null,
125
- checkpoint: o,
126
- metadata: this.sanitizeMetadata(i),
127
- checkpoint_ts: Date.now(),
128
- has_writes: "false"
129
- };
130
- return this.addSearchableMetadataFields(d, i), await this.client.json.set(l, "$", d), this.ttlConfig?.defaultTTL && await this.applyTTL(l), { configurable: {
131
- thread_id: s,
132
- checkpoint_ns: c,
133
- checkpoint_id: a
134
- } };
135
- }
136
- async getTuple(t) {
137
- const e = t.configurable?.thread_id, i = t.configurable?.checkpoint_ns ?? "", n = t.configurable?.checkpoint_id;
138
- if (!e) return;
139
- const s = `checkpoint:${e}:${i}:shallow`, c = await this.client.json.get(s);
140
- if (!c || n && c.checkpoint_id !== n) return;
141
- this.ttlConfig?.refreshOnRead && this.ttlConfig?.defaultTTL && await this.applyTTL(s);
142
- const r = await this.serde.loadsTyped("json", JSON.stringify(c.checkpoint));
143
- let a;
144
- return c.has_writes === "true" && (a = await this.loadPendingWrites(c.thread_id, c.checkpoint_ns, c.checkpoint_id)), await this.createCheckpointTuple(c, r, a);
145
- }
146
- async *list(t, e) {
147
- if (await this.ensureIndexes(), t?.configurable?.thread_id) {
148
- const i = await this.getTuple(t);
149
- i && (e?.filter ? this.checkMetadataFilterMatch(i.metadata, e.filter) && (yield i) : yield i);
150
- } else {
151
- const i = [];
152
- if (e?.filter)
153
- 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}])`));
154
- i.length === 0 && i.push("*");
155
- const n = i.join(" "), s = e?.limit ?? 10;
156
- try {
157
- const c = await this.client.ft.search("checkpoints", n, {
158
- LIMIT: {
159
- from: 0,
160
- size: s * 2
161
- },
162
- SORTBY: {
163
- BY: "checkpoint_ts",
164
- DIRECTION: "DESC"
165
- }
166
- }), r = /* @__PURE__ */ new Set();
167
- let a = 0;
168
- for (const l of c.documents) {
169
- if (a >= s) break;
170
- const h = l.value, p = `${h.thread_id}:${h.checkpoint_ns}`;
171
- if (r.has(p) || (r.add(p), e?.filter && !this.checkMetadataFilterMatch(h.metadata, e.filter)))
172
- continue;
173
- const o = await this.serde.loadsTyped("json", JSON.stringify(h.checkpoint));
174
- yield await this.createCheckpointTuple(h, o), a++;
175
- }
176
- } catch (c) {
177
- if (c.message?.includes("no such index")) {
178
- const a = await this.client.keys("checkpoint:*:*:shallow");
179
- if (a.length === 0) return;
180
- a.sort().reverse();
181
- const l = /* @__PURE__ */ new Set();
182
- let h = 0;
183
- const p = e?.limit ?? 10;
184
- for (const o of a) {
185
- if (h >= p) break;
186
- const d = await this.client.json.get(o);
187
- if (!d) continue;
188
- const f = `${d.thread_id}:${d.checkpoint_ns}`;
189
- if (l.has(f) || (l.add(f), e?.filter && !this.checkMetadataFilterMatch(d.metadata, e.filter)))
190
- continue;
191
- const y = await this.serde.loadsTyped("json", JSON.stringify(d.checkpoint));
192
- yield await this.createCheckpointTuple(d, y), h++;
193
- }
194
- return;
195
- }
196
- throw c;
197
- }
198
- }
199
- }
200
- async putWrites(t, e, i) {
201
- await this.ensureIndexes();
202
- const n = t.configurable?.thread_id, s = t.configurable?.checkpoint_ns ?? "", c = t.configurable?.checkpoint_id;
203
- if (!n || !c) throw new Error("thread_id and checkpoint_id are required");
204
- const r = `checkpoint_write:${n}:${s}:${c}:${i}:*`, a = await this.client.keys(r);
205
- a.length > 0 && await this.client.del(a);
206
- const l = [];
207
- for (let o = 0; o < e.length; o++) {
208
- const [d, f] = e[o], y = `checkpoint_write:${n}:${s}:${c}:${i}:${o}`;
209
- l.push(y);
210
- const _ = {
211
- thread_id: n,
212
- checkpoint_ns: s,
213
- checkpoint_id: c,
214
- task_id: i,
215
- idx: o,
216
- channel: d,
217
- type: typeof f == "object" ? "json" : "string",
218
- value: f
219
- };
220
- await this.client.json.set(y, "$", _);
221
- }
222
- if (l.length > 0) {
223
- const o = `write_keys_zset:${n}:${s}:${c}`, d = {};
224
- l.forEach((f, y) => {
225
- d[f] = y;
226
- }), await this.client.zAdd(o, Object.entries(d).map(([f, y]) => ({
227
- score: y,
228
- value: f
229
- }))), this.ttlConfig?.defaultTTL && await this.applyTTL(...l, o);
230
- }
231
- const h = `checkpoint:${n}:${s}:shallow`;
232
- if (await this.client.exists(h)) {
233
- const o = await this.client.json.get(h);
234
- o && (o.has_writes = "true", await this.client.json.set(h, "$", o));
235
- }
236
- }
237
- async deleteThread(t) {
238
- const e = `checkpoint:${t}:*:shallow`, i = await this.client.keys(e);
239
- i.length > 0 && await this.client.del(i);
240
- const n = `checkpoint_write:${t}:*`, s = await this.client.keys(n);
241
- s.length > 0 && await this.client.del(s);
242
- const c = `write_keys_zset:${t}:*`, r = await this.client.keys(c);
243
- r.length > 0 && await this.client.del(r);
244
- }
245
- async end() {
246
- await this.client.quit();
247
- }
248
- addSearchableMetadataFields(t, e) {
249
- 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));
250
- }
251
- async createCheckpointTuple(t, e, i) {
252
- const n = await this.serde.loadsTyped("json", JSON.stringify(t.metadata));
253
- return {
254
- config: { configurable: {
255
- thread_id: t.thread_id,
256
- checkpoint_ns: t.checkpoint_ns,
257
- checkpoint_id: t.checkpoint_id
258
- } },
259
- checkpoint: e,
260
- metadata: n,
261
- parentConfig: t.parent_checkpoint_id ? { configurable: {
262
- thread_id: t.thread_id,
263
- checkpoint_ns: t.checkpoint_ns,
264
- checkpoint_id: t.parent_checkpoint_id
265
- } } : void 0,
266
- pendingWrites: i
267
- };
268
- }
269
- async applyTTL(...t) {
270
- if (!this.ttlConfig?.defaultTTL) return;
271
- const e = Math.floor(this.ttlConfig.defaultTTL * 60), i = await Promise.allSettled(t.map((n) => this.client.expire(n, e)));
272
- 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);
273
- }
274
- async loadPendingWrites(t, e, i) {
275
- const n = `write_keys_zset:${t}:${e}:${i}`, s = await this.client.zRange(n, 0, -1);
276
- if (s.length === 0) return;
277
- const c = [];
278
- for (const r of s) {
279
- const a = await this.client.json.get(r);
280
- if (a) {
281
- const l = await this.serde.loadsTyped("json", JSON.stringify(a.value));
282
- c.push([
283
- a.task_id,
284
- a.channel,
285
- l
286
- ]);
287
- }
288
- }
289
- return c;
290
- }
291
- checkMetadataFilterMatch(t, e) {
292
- for (const [i, n] of Object.entries(e)) {
293
- const s = t?.[i];
294
- if (n === null) {
295
- if (!(i in (t || {})) || s !== null) return !1;
296
- } else if (typeof n == "object" && !Array.isArray(n)) {
297
- if (typeof s != "object" || s === null || k(n) !== k(s)) return !1;
298
- } else if (s !== n) return !1;
299
- }
300
- return !0;
301
- }
302
- async cleanupOldCheckpoint(t, e, i) {
303
- const n = `checkpoint_write:${t}:${e}:${i}:*`, s = await this.client.keys(n);
304
- s.length > 0 && await this.client.del(s);
305
- const c = `write_keys_zset:${t}:${e}:${i}`;
306
- await this.client.del(c);
307
- const r = `checkpoint_blob:${t}:${e}:${i}:*`, a = await this.client.keys(r);
308
- a.length > 0 && await this.client.del(a);
309
- }
310
- sanitizeMetadata(t) {
311
- if (!t) return {};
312
- const e = {};
313
- for (const [i, n] of Object.entries(t)) {
314
- const s = i.replace(/\x00/g, "");
315
- e[s] = typeof n == "string" ? n.replace(/\x00/g, "") : n;
316
- }
317
- return e;
318
- }
319
- async ensureIndexes() {
320
- for (const t of S) try {
321
- await this.client.ft.create(t.index, t.schema, {
322
- ON: "JSON",
323
- PREFIX: t.prefix
324
- });
325
- } catch (e) {
326
- e.message?.includes("Index already exists") || console.error(`Failed to create index ${t.index}:`, e.message);
327
- }
328
- }
329
- };
330
- export {
331
- O as ShallowRedisSaver
332
- };