zen-code 4.6.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 (33) hide show
  1. package/dist/MultiLineTextInput-B4NEXnFm.mjs +23343 -0
  2. package/dist/devtools-BHqoL8a6.mjs +11653 -0
  3. package/dist/graphBuilder-B3IJ7dB2.mjs +2641 -0
  4. package/dist/{index-B6kFMamn.mjs → index-DEcMgCTj.mjs} +1 -1
  5. package/dist/{memories-DirsFRdm.mjs → memories-rSGKIPk5.mjs} +1 -1
  6. package/dist/nonInteractive.mjs +7 -6
  7. package/dist/{subTasks-Bt97OwvY.mjs → subTasks-5KLIr9iy.mjs} +2 -2
  8. package/dist/zen-code.mjs +8654 -2
  9. package/dist/zen-keyboard.mjs +7 -6
  10. package/package.json +7 -9
  11. package/dist/MultiLineTextInput-e7hD79Wp.mjs +0 -24631
  12. package/dist/app-CM8R0ZR6.mjs +0 -16249
  13. package/dist/assets/worker-I4QjJYba.js +0 -1
  14. package/dist/checkpoint-1sAx_j1E-DrVPlSLR.mjs +0 -319
  15. package/dist/checkpoint-DxiUsHMy-Cjy5WGNC.mjs +0 -394
  16. package/dist/chunk-YWE62C55-DID9N9eS.mjs +0 -193
  17. package/dist/devtools-CzaVuYnh.mjs +0 -2667
  18. package/dist/graphBuilder-mpLrx9tk.mjs +0 -49189
  19. package/dist/index-BUGHAUbY.mjs +0 -117
  20. package/dist/index-C5j-48Ft.mjs +0 -75
  21. package/dist/index-ChCbbHFS.mjs +0 -463
  22. package/dist/index-DS5HVciX.mjs +0 -216
  23. package/dist/index-FHDPQ2Qk.mjs +0 -211
  24. package/dist/kysely-Bchvsze0.mjs +0 -4316
  25. package/dist/load-Cjl9cJ0o.mjs +0 -105
  26. package/dist/migrator-BatO36Tk.mjs +0 -592
  27. package/dist/pg-adapter-BFtir1GE-BU2H39HC.mjs +0 -62
  28. package/dist/postgres-dialect-DaHvQ_AZ.mjs +0 -211
  29. package/dist/queue-Cu_nO_wt-ChzSaooi.mjs +0 -106
  30. package/dist/remote-threads-CrG03ZS7-C9duTCnB.mjs +0 -157
  31. package/dist/shallow-tfhh5rlz.mjs +0 -331
  32. package/dist/sql-CJsUpKEQ.mjs +0 -8106
  33. package/dist/sqlite-adapter-BKOLSdoL-BlGKN04G.mjs +0 -71
@@ -1,331 +0,0 @@
1
- import { B as $, u as g } from "./app-CM8R0ZR6.mjs";
2
- import "./graphBuilder-mpLrx9tk.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
- };