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.
Files changed (83) hide show
  1. package/dist/app.js +271 -0
  2. package/dist/chunk-0fhpz98a.js +2 -0
  3. package/dist/chunk-15smn69q.js +31 -0
  4. package/dist/chunk-3ep2tag7.js +2 -0
  5. package/dist/chunk-3jek9sxm.js +2 -0
  6. package/dist/chunk-3n2b4eb4.js +2 -0
  7. package/dist/chunk-3znrwnd8.js +1 -0
  8. package/dist/chunk-4b8yaknt.js +1 -0
  9. package/dist/chunk-5fqt5yg1.js +81 -0
  10. package/dist/chunk-5nzs0q25.js +1 -0
  11. package/dist/chunk-5wn1nfqy.js +6 -0
  12. package/dist/chunk-6ty22kkt.js +4 -0
  13. package/dist/chunk-70a0e941.js +1 -0
  14. package/dist/chunk-7dp8kq2f.js +2 -0
  15. package/dist/chunk-8nhayyat.js +1 -0
  16. package/dist/chunk-9k57afdm.js +2 -0
  17. package/dist/chunk-9kc9cea3.js +7 -0
  18. package/dist/chunk-bgpcx3bm.js +2 -0
  19. package/dist/chunk-bjywwcgn.js +26 -0
  20. package/dist/chunk-c9q11tk2.js +88 -0
  21. package/dist/chunk-cga0m5sy.js +1 -0
  22. package/dist/chunk-cze71w02.js +2 -0
  23. package/dist/chunk-czz2fs2w.js +7 -0
  24. package/dist/chunk-dh3jz71n.js +1 -0
  25. package/dist/chunk-e0sqjq2h.js +1 -0
  26. package/dist/chunk-efhkdw2z.js +1 -0
  27. package/dist/chunk-ew7249h9.js +1 -0
  28. package/dist/chunk-h5nnz4dy.js +1 -0
  29. package/dist/chunk-hww94vjn.js +1 -0
  30. package/dist/chunk-j1n8jp1w.js +253 -0
  31. package/dist/chunk-j204fejq.js +1 -0
  32. package/dist/chunk-jkbtx9va.js +2 -0
  33. package/dist/chunk-k67epfhc.js +1 -0
  34. package/dist/chunk-kbs4px1b.js +6 -0
  35. package/dist/chunk-keqk70wm.js +2 -0
  36. package/dist/chunk-kxk71nn0.js +1 -0
  37. package/dist/chunk-mg8zpgaz.js +1 -0
  38. package/dist/chunk-n1d8xx5k.js +2 -0
  39. package/dist/chunk-ndtwq2zx.js +2 -0
  40. package/dist/chunk-pdkbrds7.js +1 -0
  41. package/dist/chunk-q8arjxg1.js +23 -0
  42. package/dist/chunk-rdc9pxf6.js +1 -0
  43. package/dist/chunk-rrkzfahh.js +91 -0
  44. package/dist/chunk-s3fyfrka.js +2 -0
  45. package/dist/chunk-sft6ep0c.js +310 -0
  46. package/dist/chunk-vc384abg.js +3 -0
  47. package/dist/chunk-vjj00e3e.js +6 -0
  48. package/dist/chunk-vkng13p1.js +424 -0
  49. package/dist/chunk-wbn1hbxf.js +1 -0
  50. package/dist/chunk-wwn7gw8g.js +274 -0
  51. package/dist/chunk-yaa4eesd.js +2 -0
  52. package/dist/chunk-yvhq458c.js +25 -0
  53. package/dist/cli.js +2 -0
  54. package/dist/nonInteractive.js +4 -0
  55. package/dist/zen-keyboard.js +3 -0
  56. package/package.json +88 -87
  57. package/LICENSE +0 -201
  58. package/dist/FileSystemPluginStore-ChortK7z.mjs +0 -64
  59. package/dist/FileSystemSkillStore-Dl5briBv.mjs +0 -108
  60. package/dist/MultiLineTextInput-CL8nm9nv.mjs +0 -24492
  61. package/dist/_commonjsHelpers-DQNKXVTB.mjs +0 -33
  62. package/dist/app-CK3nD8Gj.mjs +0 -22428
  63. package/dist/checkpoint-C5AFBYE--CczNxXBB.mjs +0 -355
  64. package/dist/checkpoint-DxiUsHMy-B5iaccT2.mjs +0 -394
  65. package/dist/cli.mjs +0 -57
  66. package/dist/devtools-CzaVuYnh.mjs +0 -2667
  67. package/dist/graphBuilder-DJoMXf6J.mjs +0 -28909
  68. package/dist/index-BPG5Np-8.mjs +0 -144
  69. package/dist/index-Dxfhvdx8.mjs +0 -23
  70. package/dist/index-F6_SKYUd.mjs +0 -463
  71. package/dist/load-iYJqYrjn.mjs +0 -119
  72. package/dist/memories-CaHDnBK1.mjs +0 -115
  73. package/dist/metadata-XVTVXthy.mjs +0 -6
  74. package/dist/nonInteractive.mjs +0 -55
  75. package/dist/pg-adapter-BFtir1GE-BbUXBpaX.mjs +0 -60
  76. package/dist/queue-DySatFkr-CG2GdO4P.mjs +0 -106
  77. package/dist/remote-threads-CrG03ZS7-C9duTCnB.mjs +0 -157
  78. package/dist/shallow-G4eKoZ7M.mjs +0 -331
  79. package/dist/shallow-checkpoint-BEhTdp7z-DfHxnfoU.mjs +0 -383
  80. package/dist/sqlite-adapter-oBA95xba-BrBWorSV.mjs +0 -82
  81. package/dist/subTasks-DNjIN4eU.mjs +0 -18
  82. package/dist/zen-code.mjs +0 -3
  83. package/dist/zen-keyboard.mjs +0 -13
@@ -1,394 +0,0 @@
1
- import { T as l, B as N, W as k, m as y } from "./app-CK3nD8Gj.mjs";
2
- import "./graphBuilder-DJoMXf6J.mjs";
3
- import w from "pg";
4
- const S = (h) => [
5
- "checkpoints",
6
- "checkpoint_blobs",
7
- "checkpoint_migrations",
8
- "checkpoint_writes"
9
- ].reduce((t, i) => (t[i] = `${h}.${i}`, t), {}), b = (h) => {
10
- const e = S(h);
11
- return {
12
- SELECT_SQL: `select
13
- thread_id,
14
- checkpoint,
15
- checkpoint_ns,
16
- checkpoint_id,
17
- parent_checkpoint_id,
18
- metadata,
19
- (
20
- select array_agg(array[bl.channel::bytea, bl.type::bytea, bl.blob])
21
- from jsonb_each_text(checkpoint -> 'channel_versions')
22
- inner join ${e.checkpoint_blobs} bl
23
- on bl.thread_id = cp.thread_id
24
- and bl.checkpoint_ns = cp.checkpoint_ns
25
- and bl.channel = jsonb_each_text.key
26
- and bl.version = jsonb_each_text.value
27
- ) as channel_values,
28
- (
29
- select
30
- array_agg(array[cw.task_id::text::bytea, cw.channel::bytea, cw.type::bytea, cw.blob] order by cw.task_id, cw.idx)
31
- from ${e.checkpoint_writes} cw
32
- where cw.thread_id = cp.thread_id
33
- and cw.checkpoint_ns = cp.checkpoint_ns
34
- and cw.checkpoint_id = cp.checkpoint_id
35
- ) as pending_writes
36
- from ${e.checkpoints} cp `,
37
- SELECT_PENDING_SENDS_SQL: `select
38
- checkpoint_id,
39
- array_agg(array[cw.type::bytea, cw.blob] order by cw.task_id, cw.idx) as pending_sends
40
- from ${e.checkpoint_writes} cw
41
- where cw.thread_id = $1
42
- and cw.checkpoint_id = any($2)
43
- and cw.channel = '${l}'
44
- group by cw.checkpoint_id
45
- `,
46
- UPSERT_CHECKPOINT_BLOBS_SQL: `INSERT INTO ${e.checkpoint_blobs} (thread_id, checkpoint_ns, channel, version, type, blob)
47
- VALUES ($1, $2, $3, $4, $5, $6)
48
- ON CONFLICT (thread_id, checkpoint_ns, channel, version) DO NOTHING
49
- `,
50
- UPSERT_CHECKPOINTS_SQL: `INSERT INTO ${e.checkpoints} (thread_id, checkpoint_ns, checkpoint_id, parent_checkpoint_id, checkpoint, metadata)
51
- VALUES ($1, $2, $3, $4, $5, $6)
52
- ON CONFLICT (thread_id, checkpoint_ns, checkpoint_id)
53
- DO UPDATE SET
54
- checkpoint = EXCLUDED.checkpoint,
55
- metadata = EXCLUDED.metadata;
56
- `,
57
- UPSERT_CHECKPOINT_WRITES_SQL: `INSERT INTO ${e.checkpoint_writes} (thread_id, checkpoint_ns, checkpoint_id, task_id, idx, channel, type, blob)
58
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
59
- ON CONFLICT (thread_id, checkpoint_ns, checkpoint_id, task_id, idx) DO UPDATE SET
60
- channel = EXCLUDED.channel,
61
- type = EXCLUDED.type,
62
- blob = EXCLUDED.blob;
63
- `,
64
- INSERT_CHECKPOINT_WRITES_SQL: `INSERT INTO ${e.checkpoint_writes} (thread_id, checkpoint_ns, checkpoint_id, task_id, idx, channel, type, blob)
65
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
66
- ON CONFLICT (thread_id, checkpoint_ns, checkpoint_id, task_id, idx) DO NOTHING
67
- `,
68
- DELETE_CHECKPOINTS_SQL: `DELETE FROM ${e.checkpoints} WHERE thread_id = $1`,
69
- DELETE_CHECKPOINT_BLOBS_SQL: `DELETE FROM ${e.checkpoint_blobs} WHERE thread_id = $1`,
70
- DELETE_CHECKPOINT_WRITES_SQL: `DELETE FROM ${e.checkpoint_writes} WHERE thread_id = $1`
71
- };
72
- }, O = (h) => {
73
- const e = S(h);
74
- return [
75
- `CREATE TABLE IF NOT EXISTS ${e.checkpoint_migrations} (
76
- v INTEGER PRIMARY KEY
77
- );`,
78
- `CREATE TABLE IF NOT EXISTS ${e.checkpoints} (
79
- thread_id TEXT NOT NULL,
80
- checkpoint_ns TEXT NOT NULL DEFAULT '',
81
- checkpoint_id TEXT NOT NULL,
82
- parent_checkpoint_id TEXT,
83
- type TEXT,
84
- checkpoint JSONB NOT NULL,
85
- metadata JSONB NOT NULL DEFAULT '{}',
86
- PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id)
87
- );`,
88
- `CREATE TABLE IF NOT EXISTS ${e.checkpoint_blobs} (
89
- thread_id TEXT NOT NULL,
90
- checkpoint_ns TEXT NOT NULL DEFAULT '',
91
- channel TEXT NOT NULL,
92
- version TEXT NOT NULL,
93
- type TEXT NOT NULL,
94
- blob BYTEA,
95
- PRIMARY KEY (thread_id, checkpoint_ns, channel, version)
96
- );`,
97
- `CREATE TABLE IF NOT EXISTS ${e.checkpoint_writes} (
98
- thread_id TEXT NOT NULL,
99
- checkpoint_ns TEXT NOT NULL DEFAULT '',
100
- checkpoint_id TEXT NOT NULL,
101
- task_id TEXT NOT NULL,
102
- idx INTEGER NOT NULL,
103
- channel TEXT NOT NULL,
104
- type TEXT,
105
- blob BYTEA NOT NULL,
106
- PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id, task_id, idx)
107
- );`,
108
- `ALTER TABLE ${e.checkpoint_blobs} ALTER COLUMN blob DROP not null;`
109
- ];
110
- }, C = { schema: "public" }, g = (h) => ({
111
- ...h,
112
- schema: h?.schema ?? C.schema
113
- }), { Pool: I } = w;
114
- var $ = class L extends N {
115
- pool;
116
- options;
117
- SQL_STATEMENTS;
118
- isSetup;
119
- constructor(e, t, i) {
120
- super(t), this.pool = e, this.isSetup = !1, this.options = g(i), this.SQL_STATEMENTS = b(this.options.schema);
121
- }
122
- /**
123
- * Creates a new instance of PostgresSaver from a connection string.
124
- *
125
- * @param {string} connString - The connection string to connect to the Postgres database.
126
- * @param {PostgresSaverOptions} [options] - Optional configuration object.
127
- * @returns {PostgresSaver} A new instance of PostgresSaver.
128
- *
129
- * @example
130
- * const connString = "postgresql://user:password@localhost:5432/db";
131
- * const checkpointer = PostgresSaver.fromConnString(connString, {
132
- * schema: "custom_schema" // defaults to "public"
133
- * });
134
- * await checkpointer.setup();
135
- */
136
- static fromConnString(e, t) {
137
- const i = new I({ connectionString: e });
138
- return new L(i, void 0, t);
139
- }
140
- /**
141
- * Set up the checkpoint database asynchronously.
142
- *
143
- * This method creates the necessary tables in the Postgres database if they don't
144
- * already exist and runs database migrations. It MUST be called directly by the user
145
- * the first time checkpointer is used.
146
- */
147
- async setup() {
148
- const e = await this.pool.connect(), t = S(this.options.schema);
149
- try {
150
- await e.query(`CREATE SCHEMA IF NOT EXISTS ${this.options.schema}`);
151
- let i = -1;
152
- const c = O(this.options.schema);
153
- try {
154
- const n = await e.query(`SELECT v FROM ${t.checkpoint_migrations} ORDER BY v DESC LIMIT 1`);
155
- n.rows.length > 0 && (i = n.rows[0].v);
156
- } catch (n) {
157
- if (typeof n == "object" && n !== null && "code" in n && typeof n.code == "string" && n.code === "42P01") i = -1;
158
- else throw n;
159
- }
160
- for (let n = i + 1; n < c.length; n += 1)
161
- await e.query(c[n]), await e.query(`INSERT INTO ${t.checkpoint_migrations} (v) VALUES ($1)`, [n]);
162
- } finally {
163
- e.release();
164
- }
165
- }
166
- async _loadCheckpoint(e, t) {
167
- return {
168
- ...e,
169
- channel_values: await this._loadBlobs(t)
170
- };
171
- }
172
- async _loadBlobs(e) {
173
- if (!e || e.length === 0) return {};
174
- const t = new TextDecoder(), i = await Promise.all(e.filter(([, c]) => t.decode(c) !== "empty").map(async ([c, n, a]) => [t.decode(c), await this.serde.loadsTyped(t.decode(n), a)]));
175
- return Object.fromEntries(i);
176
- }
177
- async _loadMetadata(e) {
178
- const [t, i] = await this.serde.dumpsTyped(e);
179
- return this.serde.loadsTyped(t, i);
180
- }
181
- async _loadWrites(e) {
182
- const t = new TextDecoder();
183
- return e ? await Promise.all(e.map(async ([i, c, n, a]) => [
184
- t.decode(i),
185
- t.decode(c),
186
- await this.serde.loadsTyped(t.decode(n), a)
187
- ])) : [];
188
- }
189
- async _dumpBlobs(e, t, i, c) {
190
- return Object.keys(c).length === 0 ? [] : Promise.all(Object.entries(c).map(async ([n, a]) => {
191
- const [r, o] = n in i ? await this.serde.dumpsTyped(i[n]) : ["empty", null];
192
- return [
193
- e,
194
- t,
195
- n,
196
- a.toString(),
197
- r,
198
- o ? new Uint8Array(o) : void 0
199
- ];
200
- }));
201
- }
202
- _dumpCheckpoint(e) {
203
- const t = { ...e };
204
- return "channel_values" in t && delete t.channel_values, t;
205
- }
206
- async _dumpMetadata(e) {
207
- const [, t] = await this.serde.dumpsTyped(e);
208
- return JSON.parse(new TextDecoder().decode(t).replace(/\0/g, ""));
209
- }
210
- async _dumpWrites(e, t, i, c, n) {
211
- return Promise.all(n.map(async ([a, r], o) => {
212
- const [d, p] = await this.serde.dumpsTyped(r);
213
- return [
214
- e,
215
- t,
216
- i,
217
- c,
218
- k[a] ?? o,
219
- a,
220
- d,
221
- new Uint8Array(p)
222
- ];
223
- }));
224
- }
225
- /**
226
- * Return WHERE clause predicates for a given list() config, filter, cursor.
227
- *
228
- * This method returns a tuple of a string and a tuple of values. The string
229
- * is the parameterized WHERE clause predicate (including the WHERE keyword):
230
- * "WHERE column1 = $1 AND column2 IS $2". The list of values contains the
231
- * values for each of the corresponding parameters.
232
- */
233
- _searchWhere(e, t, i) {
234
- const c = [], n = [];
235
- return e?.configurable?.thread_id && (c.push(`thread_id = $${n.length + 1}`), n.push(e.configurable.thread_id)), e?.configurable?.checkpoint_ns !== void 0 && e?.configurable?.checkpoint_ns !== null && (c.push(`checkpoint_ns = $${n.length + 1}`), n.push(e.configurable.checkpoint_ns)), e?.configurable?.checkpoint_id && (c.push(`checkpoint_id = $${n.length + 1}`), n.push(e.configurable.checkpoint_id)), t && Object.keys(t).length > 0 && (c.push(`metadata @> $${n.length + 1}`), n.push(JSON.stringify(t))), i?.configurable?.checkpoint_id !== void 0 && (c.push(`checkpoint_id < $${n.length + 1}`), n.push(i.configurable.checkpoint_id)), [c.length > 0 ? `WHERE ${c.join(" AND ")}` : "", n];
236
- }
237
- /**
238
- * Get a checkpoint tuple from the database.
239
- * This method retrieves a checkpoint tuple from the Postgres database
240
- * based on the provided config. If the config's configurable field contains
241
- * a "checkpoint_id" key, the checkpoint with the matching thread_id and
242
- * namespace is retrieved. Otherwise, the latest checkpoint for the given
243
- * thread_id is retrieved.
244
- * @param config The config to use for retrieving the checkpoint.
245
- * @returns The retrieved checkpoint tuple, or undefined.
246
- */
247
- async getTuple(e) {
248
- const { thread_id: t, checkpoint_ns: i = "", checkpoint_id: c } = e.configurable ?? {};
249
- let n, a;
250
- c ? (a = "WHERE thread_id = $1 AND checkpoint_ns = $2 AND checkpoint_id = $3", n = [
251
- t,
252
- i,
253
- c
254
- ]) : (a = "WHERE thread_id = $1 AND checkpoint_ns = $2 ORDER BY checkpoint_id DESC LIMIT 1", n = [t, i]);
255
- const r = await this.pool.query(this.SQL_STATEMENTS.SELECT_SQL + a, n), [o] = r.rows;
256
- if (o === void 0) return;
257
- if (o.checkpoint.v < 4 && o.parent_checkpoint_id != null) {
258
- const T = await this.pool.query(this.SQL_STATEMENTS.SELECT_PENDING_SENDS_SQL, [t, [o.parent_checkpoint_id]]), [u] = T.rows;
259
- u != null && await this._migratePendingSends(u.pending_sends, o);
260
- }
261
- const d = await this._loadCheckpoint(o.checkpoint, o.channel_values), p = { configurable: {
262
- thread_id: t,
263
- checkpoint_ns: i,
264
- checkpoint_id: o.checkpoint_id
265
- } }, s = await this._loadMetadata(o.metadata), E = o.parent_checkpoint_id ? { configurable: {
266
- thread_id: t,
267
- checkpoint_ns: i,
268
- checkpoint_id: o.parent_checkpoint_id
269
- } } : void 0, _ = await this._loadWrites(o.pending_writes);
270
- return {
271
- config: p,
272
- checkpoint: d,
273
- metadata: s,
274
- parentConfig: E,
275
- pendingWrites: _
276
- };
277
- }
278
- /**
279
- * List checkpoints from the database.
280
- *
281
- * This method retrieves a list of checkpoint tuples from the Postgres database based
282
- * on the provided config. The checkpoints are ordered by checkpoint ID in descending order (newest first).
283
- */
284
- async *list(e, t) {
285
- const { filter: i, before: c, limit: n } = t ?? {}, [a, r] = this._searchWhere(e, i, c);
286
- let o = `${this.SQL_STATEMENTS.SELECT_SQL}${a} ORDER BY checkpoint_id DESC`;
287
- n !== void 0 && (o += ` LIMIT ${Number.parseInt(n.toString(), 10)}`);
288
- const d = await this.pool.query(o, r), p = d.rows.filter((s) => s.checkpoint.v < 4 && s.parent_checkpoint_id != null);
289
- if (p.length > 0) {
290
- const s = await this.pool.query(this.SQL_STATEMENTS.SELECT_PENDING_SENDS_SQL, [p[0].thread_id, p.map((_) => _.parent_checkpoint_id)]), E = p.reduce((_, T) => (T.parent_checkpoint_id && (_[T.parent_checkpoint_id] ??= [], _[T.parent_checkpoint_id].push(T)), _), {});
291
- for (const _ of s.rows) for (const T of E[_.checkpoint_id]) await this._migratePendingSends(_.pending_sends, T);
292
- }
293
- for (const s of d.rows) yield {
294
- config: { configurable: {
295
- thread_id: s.thread_id,
296
- checkpoint_ns: s.checkpoint_ns,
297
- checkpoint_id: s.checkpoint_id
298
- } },
299
- checkpoint: await this._loadCheckpoint(s.checkpoint, s.channel_values),
300
- metadata: await this._loadMetadata(s.metadata),
301
- parentConfig: s.parent_checkpoint_id ? { configurable: {
302
- thread_id: s.thread_id,
303
- checkpoint_ns: s.checkpoint_ns,
304
- checkpoint_id: s.parent_checkpoint_id
305
- } } : void 0,
306
- pendingWrites: await this._loadWrites(s.pending_writes)
307
- };
308
- }
309
- /** @internal */
310
- async _migratePendingSends(e, t) {
311
- const i = new TextEncoder(), c = new TextDecoder(), n = t, [a, r] = await this.serde.dumpsTyped(await Promise.all(e.map(([o, d]) => this.serde.loadsTyped(c.decode(o), d))));
312
- n.channel_values ??= [], n.channel_values.push([
313
- i.encode(l),
314
- i.encode(a),
315
- r
316
- ]), n.checkpoint.channel_versions[l] = Object.keys(t.checkpoint.channel_versions).length > 0 ? y(...Object.values(t.checkpoint.channel_versions)) : this.getNextVersion(void 0);
317
- }
318
- /**
319
- * Save a checkpoint to the database.
320
- *
321
- * This method saves a checkpoint to the Postgres database. The checkpoint is associated
322
- * with the provided config and its parent config (if any).
323
- * @param config
324
- * @param checkpoint
325
- * @param metadata
326
- * @returns
327
- */
328
- async put(e, t, i, c) {
329
- if (e.configurable === void 0) throw new Error('Missing "configurable" field in "config" param');
330
- const { thread_id: n, checkpoint_ns: a = "", checkpoint_id: r } = e.configurable, o = { configurable: {
331
- thread_id: n,
332
- checkpoint_ns: a,
333
- checkpoint_id: t.id
334
- } }, d = await this.pool.connect(), p = this._dumpCheckpoint(t);
335
- try {
336
- await d.query("BEGIN");
337
- const s = await this._dumpBlobs(n, a, t.channel_values, c);
338
- for (const E of s) await d.query(this.SQL_STATEMENTS.UPSERT_CHECKPOINT_BLOBS_SQL, E);
339
- await d.query(this.SQL_STATEMENTS.UPSERT_CHECKPOINTS_SQL, [
340
- n,
341
- a,
342
- t.id,
343
- r,
344
- p,
345
- await this._dumpMetadata(i)
346
- ]), await d.query("COMMIT");
347
- } catch (s) {
348
- throw await d.query("ROLLBACK"), s;
349
- } finally {
350
- d.release();
351
- }
352
- return o;
353
- }
354
- /**
355
- * Store intermediate writes linked to a checkpoint.
356
- *
357
- * This method saves intermediate writes associated with a checkpoint to the Postgres database.
358
- * @param config Configuration of the related checkpoint.
359
- * @param writes List of writes to store.
360
- * @param taskId Identifier for the task creating the writes.
361
- */
362
- async putWrites(e, t, i) {
363
- const c = t.every((r) => r[0] in k) ? this.SQL_STATEMENTS.UPSERT_CHECKPOINT_WRITES_SQL : this.SQL_STATEMENTS.INSERT_CHECKPOINT_WRITES_SQL, n = await this._dumpWrites(e.configurable?.thread_id, e.configurable?.checkpoint_ns, e.configurable?.checkpoint_id, i, t), a = await this.pool.connect();
364
- try {
365
- await a.query("BEGIN");
366
- for await (const r of n) await a.query(c, r);
367
- await a.query("COMMIT");
368
- } catch (r) {
369
- throw await a.query("ROLLBACK"), r;
370
- } finally {
371
- a.release();
372
- }
373
- }
374
- async end() {
375
- return this.pool.end();
376
- }
377
- async deleteThread(e) {
378
- const t = await this.pool.connect();
379
- try {
380
- await t.query("BEGIN"), await t.query(this.SQL_STATEMENTS.DELETE_CHECKPOINT_BLOBS_SQL, [e]), await t.query(this.SQL_STATEMENTS.DELETE_CHECKPOINTS_SQL, [e]), await t.query(this.SQL_STATEMENTS.DELETE_CHECKPOINT_WRITES_SQL, [e]), await t.query("COMMIT");
381
- } catch (i) {
382
- throw await t.query("ROLLBACK"), i;
383
- } finally {
384
- t.release();
385
- }
386
- }
387
- };
388
- const R = async () => {
389
- const h = $.fromConnString(process.env.DATABASE_URL);
390
- return process.env.DATABASE_INIT === "true" && (console.debug("LG | Initializing postgres checkpoint"), await h.setup()), h;
391
- };
392
- export {
393
- R as createPGCheckpoint
394
- };
package/dist/cli.mjs DELETED
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env node
2
- import c from "node:path";
3
- import l from "node:os";
4
- import o from "node:fs";
5
- import "node-notifier";
6
- import "./metadata-XVTVXthy.mjs";
7
- function u(e) {
8
- const s = e.replace(/^~/, l.homedir()), t = c.resolve(s), n = c.dirname(t);
9
- return o.existsSync(n) || o.mkdirSync(n, { recursive: !0 }), t;
10
- }
11
- function m(e, s) {
12
- if (!o.existsSync(e)) {
13
- process.env.DATABASE_INIT = "true";
14
- return;
15
- }
16
- const n = (process.env.SQLITE_MAX_SIZE_MB ? parseInt(process.env.SQLITE_MAX_SIZE_MB, 10) * 1024 * 1024 : void 0) ?? 100 * 1024 * 1024, r = o.statSync(e).size, a = r / (1024 * 1024);
17
- if (r > n) {
18
- const d = n / 1048576;
19
- console.warn(`⚠️ Database file is large: ${a.toFixed(2)}MB (limit: ${d.toFixed(2)}MB)`), console.warn(` Path: ${e}`), console.warn(" Set SQLITE_MAX_SIZE_MB to adjust limit");
20
- }
21
- }
22
- function p(e) {
23
- const s = u(e);
24
- return process.env.SQLITE_DATABASE_URI = s, m(s), s;
25
- }
26
- const i = process.argv.slice(2);
27
- async function f() {
28
- const e = i.indexOf("--yolo");
29
- if (e !== -1 && (process.env.YOLO_MODE = "true", i.splice(e, 1)), globalThis.Bun && p("~/.zen-code/data/sessions.db"), i[0] === "init")
30
- console.log("Please zen-code and use /m to configure models");
31
- else if (i[0] === "keyboard")
32
- import("./zen-keyboard.mjs");
33
- else if (i[0] === "-p" || i[0] === "--prompt") {
34
- const s = i.slice(1).join(" "), { runNonInteractive: t } = await import("./nonInteractive.mjs");
35
- await t(s, !1);
36
- } else if (await S()) {
37
- const { runNonInteractive: t } = await import("./nonInteractive.mjs");
38
- await t(void 0, !0);
39
- } else
40
- await import("./zen-code.mjs");
41
- }
42
- async function S() {
43
- return new Promise((e) => {
44
- if (process.stdin.isTTY) {
45
- e(!1);
46
- return;
47
- }
48
- const t = process.stdin.read();
49
- t ? (process.stdin.unshift(t), e(!0)) : setTimeout(() => {
50
- const n = process.stdin.read();
51
- n ? (process.stdin.unshift(n), e(!0)) : e(!1);
52
- }, 100);
53
- });
54
- }
55
- f().catch((e) => {
56
- console.error("❌ 执行失败:", e), process.exit(1);
57
- });