zen-code 4.7.3 → 4.8.0
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
package/dist/index-BPG5Np-8.mjs
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
const g = (a = 0) => (e) => `\x1B[${e + a}m`, u = (a = 0) => (e) => `\x1B[${38 + a};5;${e}m`, b = (a = 0) => (e, n, t) => `\x1B[${38 + a};2;${e};${n};${t}m`, r = {
|
|
2
|
-
modifier: {
|
|
3
|
-
reset: [0, 0],
|
|
4
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
5
|
-
bold: [1, 22],
|
|
6
|
-
dim: [2, 22],
|
|
7
|
-
italic: [3, 23],
|
|
8
|
-
underline: [4, 24],
|
|
9
|
-
overline: [53, 55],
|
|
10
|
-
inverse: [7, 27],
|
|
11
|
-
hidden: [8, 28],
|
|
12
|
-
strikethrough: [9, 29]
|
|
13
|
-
},
|
|
14
|
-
color: {
|
|
15
|
-
black: [30, 39],
|
|
16
|
-
red: [31, 39],
|
|
17
|
-
green: [32, 39],
|
|
18
|
-
yellow: [33, 39],
|
|
19
|
-
blue: [34, 39],
|
|
20
|
-
magenta: [35, 39],
|
|
21
|
-
cyan: [36, 39],
|
|
22
|
-
white: [37, 39],
|
|
23
|
-
// Bright color
|
|
24
|
-
blackBright: [90, 39],
|
|
25
|
-
gray: [90, 39],
|
|
26
|
-
// Alias of `blackBright`
|
|
27
|
-
grey: [90, 39],
|
|
28
|
-
// Alias of `blackBright`
|
|
29
|
-
redBright: [91, 39],
|
|
30
|
-
greenBright: [92, 39],
|
|
31
|
-
yellowBright: [93, 39],
|
|
32
|
-
blueBright: [94, 39],
|
|
33
|
-
magentaBright: [95, 39],
|
|
34
|
-
cyanBright: [96, 39],
|
|
35
|
-
whiteBright: [97, 39]
|
|
36
|
-
},
|
|
37
|
-
bgColor: {
|
|
38
|
-
bgBlack: [40, 49],
|
|
39
|
-
bgRed: [41, 49],
|
|
40
|
-
bgGreen: [42, 49],
|
|
41
|
-
bgYellow: [43, 49],
|
|
42
|
-
bgBlue: [44, 49],
|
|
43
|
-
bgMagenta: [45, 49],
|
|
44
|
-
bgCyan: [46, 49],
|
|
45
|
-
bgWhite: [47, 49],
|
|
46
|
-
// Bright color
|
|
47
|
-
bgBlackBright: [100, 49],
|
|
48
|
-
bgGray: [100, 49],
|
|
49
|
-
// Alias of `bgBlackBright`
|
|
50
|
-
bgGrey: [100, 49],
|
|
51
|
-
// Alias of `bgBlackBright`
|
|
52
|
-
bgRedBright: [101, 49],
|
|
53
|
-
bgGreenBright: [102, 49],
|
|
54
|
-
bgYellowBright: [103, 49],
|
|
55
|
-
bgBlueBright: [104, 49],
|
|
56
|
-
bgMagentaBright: [105, 49],
|
|
57
|
-
bgCyanBright: [106, 49],
|
|
58
|
-
bgWhiteBright: [107, 49]
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
Object.keys(r.modifier);
|
|
62
|
-
const h = Object.keys(r.color), c = Object.keys(r.bgColor);
|
|
63
|
-
[...h, ...c];
|
|
64
|
-
function f() {
|
|
65
|
-
const a = /* @__PURE__ */ new Map();
|
|
66
|
-
for (const [e, n] of Object.entries(r)) {
|
|
67
|
-
for (const [t, o] of Object.entries(n))
|
|
68
|
-
r[t] = {
|
|
69
|
-
open: `\x1B[${o[0]}m`,
|
|
70
|
-
close: `\x1B[${o[1]}m`
|
|
71
|
-
}, n[t] = r[t], a.set(o[0], o[1]);
|
|
72
|
-
Object.defineProperty(r, e, {
|
|
73
|
-
value: n,
|
|
74
|
-
enumerable: !1
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return Object.defineProperty(r, "codes", {
|
|
78
|
-
value: a,
|
|
79
|
-
enumerable: !1
|
|
80
|
-
}), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = g(), r.color.ansi256 = u(), r.color.ansi16m = b(), r.bgColor.ansi = g(10), r.bgColor.ansi256 = u(10), r.bgColor.ansi16m = b(10), Object.defineProperties(r, {
|
|
81
|
-
rgbToAnsi256: {
|
|
82
|
-
value(e, n, t) {
|
|
83
|
-
return e === n && n === t ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 * Math.round(n / 255 * 5) + Math.round(t / 255 * 5);
|
|
84
|
-
},
|
|
85
|
-
enumerable: !1
|
|
86
|
-
},
|
|
87
|
-
hexToRgb: {
|
|
88
|
-
value(e) {
|
|
89
|
-
const n = /[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));
|
|
90
|
-
if (!n)
|
|
91
|
-
return [0, 0, 0];
|
|
92
|
-
let [t] = n;
|
|
93
|
-
t.length === 3 && (t = [...t].map((l) => l + l).join(""));
|
|
94
|
-
const o = Number.parseInt(t, 16);
|
|
95
|
-
return [
|
|
96
|
-
/* eslint-disable no-bitwise */
|
|
97
|
-
o >> 16 & 255,
|
|
98
|
-
o >> 8 & 255,
|
|
99
|
-
o & 255
|
|
100
|
-
/* eslint-enable no-bitwise */
|
|
101
|
-
];
|
|
102
|
-
},
|
|
103
|
-
enumerable: !1
|
|
104
|
-
},
|
|
105
|
-
hexToAnsi256: {
|
|
106
|
-
value: (e) => r.rgbToAnsi256(...r.hexToRgb(e)),
|
|
107
|
-
enumerable: !1
|
|
108
|
-
},
|
|
109
|
-
ansi256ToAnsi: {
|
|
110
|
-
value(e) {
|
|
111
|
-
if (e < 8)
|
|
112
|
-
return 30 + e;
|
|
113
|
-
if (e < 16)
|
|
114
|
-
return 90 + (e - 8);
|
|
115
|
-
let n, t, o;
|
|
116
|
-
if (e >= 232)
|
|
117
|
-
n = ((e - 232) * 10 + 8) / 255, t = n, o = n;
|
|
118
|
-
else {
|
|
119
|
-
e -= 16;
|
|
120
|
-
const s = e % 36;
|
|
121
|
-
n = Math.floor(e / 36) / 5, t = Math.floor(s / 6) / 5, o = s % 6 / 5;
|
|
122
|
-
}
|
|
123
|
-
const l = Math.max(n, t, o) * 2;
|
|
124
|
-
if (l === 0)
|
|
125
|
-
return 30;
|
|
126
|
-
let i = 30 + (Math.round(o) << 2 | Math.round(t) << 1 | Math.round(n));
|
|
127
|
-
return l === 2 && (i += 60), i;
|
|
128
|
-
},
|
|
129
|
-
enumerable: !1
|
|
130
|
-
},
|
|
131
|
-
rgbToAnsi: {
|
|
132
|
-
value: (e, n, t) => r.ansi256ToAnsi(r.rgbToAnsi256(e, n, t)),
|
|
133
|
-
enumerable: !1
|
|
134
|
-
},
|
|
135
|
-
hexToAnsi: {
|
|
136
|
-
value: (e) => r.ansi256ToAnsi(r.hexToAnsi256(e)),
|
|
137
|
-
enumerable: !1
|
|
138
|
-
}
|
|
139
|
-
}), r;
|
|
140
|
-
}
|
|
141
|
-
const m = f();
|
|
142
|
-
export {
|
|
143
|
-
m as a
|
|
144
|
-
};
|
package/dist/index-Dxfhvdx8.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { A as s, C as m, F as o, e as c, S as i, a as p, d as h, b as k, h as n, f as g, g as T, T as f, c as l } from "./graphBuilder-DJoMXf6J.mjs";
|
|
2
|
-
import { FileSystemSkillStore as y } from "./FileSystemSkillStore-Dl5briBv.mjs";
|
|
3
|
-
import { FileSystemPluginStore as F } from "./FileSystemPluginStore-ChortK7z.mjs";
|
|
4
|
-
import "lowdb";
|
|
5
|
-
import "lowdb/node";
|
|
6
|
-
import "micromatch";
|
|
7
|
-
export {
|
|
8
|
-
s as AgentTypeSchema,
|
|
9
|
-
m as ConfigManager,
|
|
10
|
-
o as FileSystemConfigStore,
|
|
11
|
-
F as FileSystemPluginStore,
|
|
12
|
-
y as FileSystemSkillStore,
|
|
13
|
-
c as SparkItemSchema,
|
|
14
|
-
i as SparkItemTypeSchema,
|
|
15
|
-
p as SparkPrioritySchema,
|
|
16
|
-
h as SparkSourceSchema,
|
|
17
|
-
k as SparkStatusSchema,
|
|
18
|
-
n as TaskExecutionRecordSchema,
|
|
19
|
-
g as TaskExecutionSchema,
|
|
20
|
-
T as TaskNodeSchema,
|
|
21
|
-
f as TaskStatusSchema,
|
|
22
|
-
l as createFSManager
|
|
23
|
-
};
|
package/dist/index-F6_SKYUd.mjs
DELETED
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import { B as C, u as v, c as x, T as $, m as I } from "./app-CK3nD8Gj.mjs";
|
|
2
|
-
import "./graphBuilder-DJoMXf6J.mjs";
|
|
3
|
-
import { createClient as O, createCluster as N } from "redis";
|
|
4
|
-
const W = [
|
|
5
|
-
{
|
|
6
|
-
index: "checkpoints",
|
|
7
|
-
prefix: "checkpoint:",
|
|
8
|
-
schema: {
|
|
9
|
-
"$.thread_id": {
|
|
10
|
-
type: "TAG",
|
|
11
|
-
AS: "thread_id"
|
|
12
|
-
},
|
|
13
|
-
"$.checkpoint_ns": {
|
|
14
|
-
type: "TAG",
|
|
15
|
-
AS: "checkpoint_ns"
|
|
16
|
-
},
|
|
17
|
-
"$.checkpoint_id": {
|
|
18
|
-
type: "TAG",
|
|
19
|
-
AS: "checkpoint_id"
|
|
20
|
-
},
|
|
21
|
-
"$.parent_checkpoint_id": {
|
|
22
|
-
type: "TAG",
|
|
23
|
-
AS: "parent_checkpoint_id"
|
|
24
|
-
},
|
|
25
|
-
"$.checkpoint_ts": {
|
|
26
|
-
type: "NUMERIC",
|
|
27
|
-
AS: "checkpoint_ts"
|
|
28
|
-
},
|
|
29
|
-
"$.has_writes": {
|
|
30
|
-
type: "TAG",
|
|
31
|
-
AS: "has_writes"
|
|
32
|
-
},
|
|
33
|
-
"$.source": {
|
|
34
|
-
type: "TAG",
|
|
35
|
-
AS: "source"
|
|
36
|
-
},
|
|
37
|
-
"$.step": {
|
|
38
|
-
type: "NUMERIC",
|
|
39
|
-
AS: "step"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
index: "checkpoint_blobs",
|
|
45
|
-
prefix: "checkpoint_blob:",
|
|
46
|
-
schema: {
|
|
47
|
-
"$.thread_id": {
|
|
48
|
-
type: "TAG",
|
|
49
|
-
AS: "thread_id"
|
|
50
|
-
},
|
|
51
|
-
"$.checkpoint_ns": {
|
|
52
|
-
type: "TAG",
|
|
53
|
-
AS: "checkpoint_ns"
|
|
54
|
-
},
|
|
55
|
-
"$.checkpoint_id": {
|
|
56
|
-
type: "TAG",
|
|
57
|
-
AS: "checkpoint_id"
|
|
58
|
-
},
|
|
59
|
-
"$.channel": {
|
|
60
|
-
type: "TAG",
|
|
61
|
-
AS: "channel"
|
|
62
|
-
},
|
|
63
|
-
"$.version": {
|
|
64
|
-
type: "TAG",
|
|
65
|
-
AS: "version"
|
|
66
|
-
},
|
|
67
|
-
"$.type": {
|
|
68
|
-
type: "TAG",
|
|
69
|
-
AS: "type"
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
index: "checkpoint_writes",
|
|
75
|
-
prefix: "checkpoint_write:",
|
|
76
|
-
schema: {
|
|
77
|
-
"$.thread_id": {
|
|
78
|
-
type: "TAG",
|
|
79
|
-
AS: "thread_id"
|
|
80
|
-
},
|
|
81
|
-
"$.checkpoint_ns": {
|
|
82
|
-
type: "TAG",
|
|
83
|
-
AS: "checkpoint_ns"
|
|
84
|
-
},
|
|
85
|
-
"$.checkpoint_id": {
|
|
86
|
-
type: "TAG",
|
|
87
|
-
AS: "checkpoint_id"
|
|
88
|
-
},
|
|
89
|
-
"$.task_id": {
|
|
90
|
-
type: "TAG",
|
|
91
|
-
AS: "task_id"
|
|
92
|
-
},
|
|
93
|
-
"$.idx": {
|
|
94
|
-
type: "NUMERIC",
|
|
95
|
-
AS: "idx"
|
|
96
|
-
},
|
|
97
|
-
"$.channel": {
|
|
98
|
-
type: "TAG",
|
|
99
|
-
AS: "channel"
|
|
100
|
-
},
|
|
101
|
-
"$.type": {
|
|
102
|
-
type: "TAG",
|
|
103
|
-
AS: "type"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
];
|
|
108
|
-
var E = class T extends C {
|
|
109
|
-
client;
|
|
110
|
-
ttlConfig;
|
|
111
|
-
constructor(e, t) {
|
|
112
|
-
super(), this.client = e, this.ttlConfig = t;
|
|
113
|
-
}
|
|
114
|
-
static async fromUrl(e, t) {
|
|
115
|
-
const s = O({ url: e });
|
|
116
|
-
await s.connect();
|
|
117
|
-
const i = new T(s, t);
|
|
118
|
-
return await i.ensureIndexes(), i;
|
|
119
|
-
}
|
|
120
|
-
static async fromCluster(e, t) {
|
|
121
|
-
const s = N({ rootNodes: e });
|
|
122
|
-
await s.connect();
|
|
123
|
-
const i = new T(s, t);
|
|
124
|
-
return await i.ensureIndexes(), i;
|
|
125
|
-
}
|
|
126
|
-
async get(e) {
|
|
127
|
-
return (await this.getTuple(e))?.checkpoint;
|
|
128
|
-
}
|
|
129
|
-
async getTuple(e) {
|
|
130
|
-
const t = e.configurable?.thread_id, s = e.configurable?.checkpoint_ns ?? "", i = e.configurable?.checkpoint_id;
|
|
131
|
-
if (!t) return;
|
|
132
|
-
let c, o;
|
|
133
|
-
if (i)
|
|
134
|
-
c = `checkpoint:${t}:${s}:${i}`, o = await this.client.json.get(c);
|
|
135
|
-
else {
|
|
136
|
-
const r = `checkpoint:${t}:${s}:*`, p = await this.client.keys(r);
|
|
137
|
-
if (p.length === 0) return;
|
|
138
|
-
p.sort(), c = p[p.length - 1], o = await this.client.json.get(c);
|
|
139
|
-
}
|
|
140
|
-
if (!o) return;
|
|
141
|
-
this.ttlConfig?.refreshOnRead && this.ttlConfig?.defaultTTL && await this.applyTTL(c);
|
|
142
|
-
const { checkpoint: f, pendingWrites: n } = await this.loadCheckpointWithWrites(o);
|
|
143
|
-
return await this.createCheckpointTuple(o, f, n);
|
|
144
|
-
}
|
|
145
|
-
async put(e, t, s, i) {
|
|
146
|
-
await this.ensureIndexes();
|
|
147
|
-
const c = e.configurable?.thread_id, o = e.configurable?.checkpoint_ns ?? "", f = e.configurable?.checkpoint_id;
|
|
148
|
-
if (!c) throw new Error("thread_id is required");
|
|
149
|
-
const n = t.id || v(0), r = `checkpoint:${c}:${o}:${n}`, p = x(t);
|
|
150
|
-
if (p.channel_values && i !== void 0) if (Object.keys(i).length === 0) p.channel_values = {};
|
|
151
|
-
else {
|
|
152
|
-
const u = {};
|
|
153
|
-
for (const a of Object.keys(i)) a in p.channel_values && (u[a] = p.channel_values[a]);
|
|
154
|
-
p.channel_values = u;
|
|
155
|
-
}
|
|
156
|
-
const l = {
|
|
157
|
-
thread_id: c,
|
|
158
|
-
checkpoint_ns: o === "" ? "__empty__" : o,
|
|
159
|
-
checkpoint_id: n,
|
|
160
|
-
parent_checkpoint_id: f || null,
|
|
161
|
-
checkpoint: p,
|
|
162
|
-
metadata: s,
|
|
163
|
-
checkpoint_ts: Date.now(),
|
|
164
|
-
has_writes: "false"
|
|
165
|
-
};
|
|
166
|
-
return this.addSearchableMetadataFields(l, s), await this.client.json.set(r, "$", l), this.ttlConfig?.defaultTTL && await this.applyTTL(r), { configurable: {
|
|
167
|
-
thread_id: c,
|
|
168
|
-
checkpoint_ns: o,
|
|
169
|
-
checkpoint_id: n
|
|
170
|
-
} };
|
|
171
|
-
}
|
|
172
|
-
async *list(e, t) {
|
|
173
|
-
if (await this.ensureIndexes(), t?.filter !== void 0) {
|
|
174
|
-
const i = Object.values(t.filter).some((n) => n === null), c = [];
|
|
175
|
-
if (e?.configurable?.thread_id) {
|
|
176
|
-
const n = e.configurable.thread_id.replace(/[-.@]/g, "\\$&");
|
|
177
|
-
c.push(`(@thread_id:{${n}})`);
|
|
178
|
-
}
|
|
179
|
-
if (e?.configurable?.checkpoint_ns !== void 0) {
|
|
180
|
-
const n = e.configurable.checkpoint_ns;
|
|
181
|
-
if (n === "") c.push("(@checkpoint_ns:{__empty__})");
|
|
182
|
-
else {
|
|
183
|
-
const r = n.replace(/[-.@]/g, "\\$&");
|
|
184
|
-
c.push(`(@checkpoint_ns:{${r}})`);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (!t?.before && t?.filter)
|
|
188
|
-
for (const [n, r] of Object.entries(t.filter)) r === void 0 || r === null || (typeof r == "string" ? c.push(`(@${n}:{${r}})`) : typeof r == "number" ? c.push(`(@${n}:[${r} ${r}])`) : typeof r == "object" && Object.keys(r).length);
|
|
189
|
-
c.length === 0 && c.push("*");
|
|
190
|
-
const o = c.join(" "), f = t?.limit ?? 10;
|
|
191
|
-
try {
|
|
192
|
-
const n = t?.before && !e?.configurable?.thread_id ? 1e3 : t?.before ? f * 10 : f;
|
|
193
|
-
let p = (await this.client.ft.search("checkpoints", o, {
|
|
194
|
-
LIMIT: {
|
|
195
|
-
from: 0,
|
|
196
|
-
size: n
|
|
197
|
-
},
|
|
198
|
-
SORTBY: {
|
|
199
|
-
BY: "checkpoint_ts",
|
|
200
|
-
DIRECTION: "DESC"
|
|
201
|
-
}
|
|
202
|
-
})).documents, l = 0;
|
|
203
|
-
for (const u of p) {
|
|
204
|
-
if (l >= f) break;
|
|
205
|
-
if (t?.before?.configurable?.checkpoint_id) {
|
|
206
|
-
const k = u.value.checkpoint_id, d = t.before.configurable.checkpoint_id;
|
|
207
|
-
if (k >= d) continue;
|
|
208
|
-
}
|
|
209
|
-
const a = u.value;
|
|
210
|
-
let h = !0;
|
|
211
|
-
if ((i || t?.before) && t?.filter) {
|
|
212
|
-
for (const [k, d] of Object.entries(t.filter)) if (d === null) {
|
|
213
|
-
if (a.metadata?.[k] !== null) {
|
|
214
|
-
h = !1;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
} else if (d !== void 0) {
|
|
218
|
-
const b = a.metadata?.[k];
|
|
219
|
-
if (typeof d == "object" && d !== null) {
|
|
220
|
-
if (g(b) !== g(d)) {
|
|
221
|
-
h = !1;
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
} else if (b !== d) {
|
|
225
|
-
h = !1;
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (!h) continue;
|
|
230
|
-
}
|
|
231
|
-
const { checkpoint: y, pendingWrites: _ } = await this.loadCheckpointWithWrites(a);
|
|
232
|
-
yield await this.createCheckpointTuple(a, y, _), l++;
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
235
|
-
} catch (n) {
|
|
236
|
-
if (!n.message?.includes("no such index")) throw n;
|
|
237
|
-
}
|
|
238
|
-
if (e?.configurable?.thread_id) {
|
|
239
|
-
const n = e.configurable.thread_id, r = e.configurable.checkpoint_ns ?? "", p = `checkpoint:${n}:${r}:*`, l = await this.client.keys(p);
|
|
240
|
-
l.sort().reverse();
|
|
241
|
-
let u = l;
|
|
242
|
-
if (t?.before?.configurable?.checkpoint_id) {
|
|
243
|
-
const y = t.before.configurable.thread_id || n, _ = t.before.configurable.checkpoint_ns ?? r, k = `checkpoint:${y}:${_}:${t.before.configurable.checkpoint_id}`, d = l.indexOf(k);
|
|
244
|
-
d > 0 ? u = l.slice(d + 1) : d === 0 && (u = []);
|
|
245
|
-
}
|
|
246
|
-
const a = t?.limit ?? 10, h = u.slice(0, a);
|
|
247
|
-
for (const y of h) {
|
|
248
|
-
const _ = await this.client.json.get(y);
|
|
249
|
-
if (_) {
|
|
250
|
-
let k = !0;
|
|
251
|
-
for (const [S, m] of Object.entries(t.filter)) {
|
|
252
|
-
const A = _.metadata?.[S];
|
|
253
|
-
if (m === null) {
|
|
254
|
-
if (A !== null) {
|
|
255
|
-
k = !1;
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
} else if (A !== m) {
|
|
259
|
-
k = !1;
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (!k) continue;
|
|
264
|
-
const { checkpoint: d, pendingWrites: b } = await this.loadCheckpointWithWrites(_);
|
|
265
|
-
yield await this.createCheckpointTuple(_, d, b);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
} else {
|
|
269
|
-
const n = e?.configurable?.checkpoint_ns !== void 0 ? `checkpoint:*:${e.configurable.checkpoint_ns === "" ? "__empty__" : e.configurable.checkpoint_ns}:*` : "checkpoint:*", r = await this.client.keys(n), p = [];
|
|
270
|
-
for (const a of r) {
|
|
271
|
-
const h = await this.client.json.get(a);
|
|
272
|
-
h && p.push({
|
|
273
|
-
key: a,
|
|
274
|
-
doc: h
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
p.sort((a, h) => h.doc.checkpoint_ts - a.doc.checkpoint_ts);
|
|
278
|
-
let l = 0;
|
|
279
|
-
const u = t?.limit ?? 10;
|
|
280
|
-
for (const { doc: a } of p) {
|
|
281
|
-
if (l >= u) break;
|
|
282
|
-
if (t?.before?.configurable?.checkpoint_id) {
|
|
283
|
-
const k = a.checkpoint_id, d = t.before.configurable.checkpoint_id;
|
|
284
|
-
if (k >= d) continue;
|
|
285
|
-
}
|
|
286
|
-
let h = !0;
|
|
287
|
-
if (t?.filter) {
|
|
288
|
-
for (const [k, d] of Object.entries(t.filter)) if (d === null) {
|
|
289
|
-
if (a.metadata?.[k] !== null) {
|
|
290
|
-
h = !1;
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
} else if (d !== void 0) {
|
|
294
|
-
const b = a.metadata?.[k];
|
|
295
|
-
if (typeof d == "object" && d !== null) {
|
|
296
|
-
if (g(b) !== g(d)) {
|
|
297
|
-
h = !1;
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
} else if (b !== d) {
|
|
301
|
-
h = !1;
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
if (!h) continue;
|
|
306
|
-
}
|
|
307
|
-
const { checkpoint: y, pendingWrites: _ } = await this.loadCheckpointWithWrites(a);
|
|
308
|
-
yield await this.createCheckpointTuple(a, y, _), l++;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const s = {
|
|
314
|
-
...t,
|
|
315
|
-
filter: {}
|
|
316
|
-
};
|
|
317
|
-
yield* this.list(e, s);
|
|
318
|
-
}
|
|
319
|
-
async putWrites(e, t, s) {
|
|
320
|
-
await this.ensureIndexes();
|
|
321
|
-
const i = e.configurable?.thread_id, c = e.configurable?.checkpoint_ns ?? "", o = e.configurable?.checkpoint_id;
|
|
322
|
-
if (!i || !o) throw new Error("thread_id and checkpoint_id are required");
|
|
323
|
-
const f = [], n = performance.now() * 1e3;
|
|
324
|
-
for (let l = 0; l < t.length; l++) {
|
|
325
|
-
const [u, a] = t[l], h = `checkpoint_write:${i}:${c}:${o}:${s}:${l}`;
|
|
326
|
-
f.push(h);
|
|
327
|
-
const y = {
|
|
328
|
-
thread_id: i,
|
|
329
|
-
checkpoint_ns: c,
|
|
330
|
-
checkpoint_id: o,
|
|
331
|
-
task_id: s,
|
|
332
|
-
idx: l,
|
|
333
|
-
channel: u,
|
|
334
|
-
type: typeof a == "object" ? "json" : "string",
|
|
335
|
-
value: a,
|
|
336
|
-
timestamp: n,
|
|
337
|
-
global_idx: n + l
|
|
338
|
-
};
|
|
339
|
-
await this.client.json.set(h, "$", y);
|
|
340
|
-
}
|
|
341
|
-
if (f.length > 0) {
|
|
342
|
-
const l = `write_keys_zset:${i}:${c}:${o}`, u = {};
|
|
343
|
-
f.forEach((a, h) => {
|
|
344
|
-
u[a] = n + h;
|
|
345
|
-
}), await this.client.zAdd(l, Object.entries(u).map(([a, h]) => ({
|
|
346
|
-
score: h,
|
|
347
|
-
value: a
|
|
348
|
-
}))), this.ttlConfig?.defaultTTL && await this.applyTTL(...f, l);
|
|
349
|
-
}
|
|
350
|
-
const r = `checkpoint:${i}:${c}:${o}`;
|
|
351
|
-
if (await this.client.exists(r)) {
|
|
352
|
-
const l = await this.client.json.get(r);
|
|
353
|
-
l && (l.has_writes = "true", await this.client.json.set(r, "$", l));
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
async deleteThread(e) {
|
|
357
|
-
const t = `checkpoint:${e}:*`, s = await this.client.keys(t);
|
|
358
|
-
s.length > 0 && await this.client.del(s);
|
|
359
|
-
const i = `writes:${e}:*`, c = await this.client.keys(i);
|
|
360
|
-
c.length > 0 && await this.client.del(c);
|
|
361
|
-
}
|
|
362
|
-
async end() {
|
|
363
|
-
await this.client.quit();
|
|
364
|
-
}
|
|
365
|
-
async loadPendingWrites(e, t, s) {
|
|
366
|
-
const i = `checkpoint_write:${e}:${t}:${s}:*`, c = await this.client.keys(i);
|
|
367
|
-
if (c.length === 0) return;
|
|
368
|
-
const o = [];
|
|
369
|
-
for (const n of c) {
|
|
370
|
-
const r = await this.client.json.get(n);
|
|
371
|
-
r && o.push(r);
|
|
372
|
-
}
|
|
373
|
-
o.sort((n, r) => (n.global_idx || 0) - (r.global_idx || 0));
|
|
374
|
-
const f = [];
|
|
375
|
-
for (const n of o) {
|
|
376
|
-
const r = await this.serde.loadsTyped("json", JSON.stringify(n.value));
|
|
377
|
-
f.push([
|
|
378
|
-
n.task_id,
|
|
379
|
-
n.channel,
|
|
380
|
-
r
|
|
381
|
-
]);
|
|
382
|
-
}
|
|
383
|
-
return f;
|
|
384
|
-
}
|
|
385
|
-
async loadCheckpointWithWrites(e) {
|
|
386
|
-
const t = await this.serde.loadsTyped("json", JSON.stringify(e.checkpoint));
|
|
387
|
-
if (t.v < 4 && e.parent_checkpoint_id != null) {
|
|
388
|
-
const i = e.checkpoint_ns === "__empty__" ? "" : e.checkpoint_ns;
|
|
389
|
-
await this.migratePendingSends(t, e.thread_id, i, e.parent_checkpoint_id);
|
|
390
|
-
}
|
|
391
|
-
let s;
|
|
392
|
-
if (e.has_writes === "true") {
|
|
393
|
-
const i = e.checkpoint_ns === "__empty__" ? "" : e.checkpoint_ns;
|
|
394
|
-
s = await this.loadPendingWrites(e.thread_id, i, e.checkpoint_id);
|
|
395
|
-
}
|
|
396
|
-
return {
|
|
397
|
-
checkpoint: t,
|
|
398
|
-
pendingWrites: s
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
async migratePendingSends(e, t, s, i) {
|
|
402
|
-
const c = await this.loadPendingWrites(t, s, i);
|
|
403
|
-
if (!c || c.length === 0) return;
|
|
404
|
-
const o = c.filter(([, n]) => n === $);
|
|
405
|
-
if (o.length === 0) return;
|
|
406
|
-
const f = [];
|
|
407
|
-
for (const [, , n] of o) f.push(n);
|
|
408
|
-
e.channel_values ??= {}, e.channel_values[$] = f, e.channel_versions[$] = Object.keys(e.channel_versions).length > 0 ? I(...Object.values(e.channel_versions)) : 1;
|
|
409
|
-
}
|
|
410
|
-
async createCheckpointTuple(e, t, s) {
|
|
411
|
-
const i = e.checkpoint_ns === "__empty__" ? "" : e.checkpoint_ns, c = await this.serde.loadsTyped("json", JSON.stringify(e.metadata));
|
|
412
|
-
return {
|
|
413
|
-
config: { configurable: {
|
|
414
|
-
thread_id: e.thread_id,
|
|
415
|
-
checkpoint_ns: i,
|
|
416
|
-
checkpoint_id: e.checkpoint_id
|
|
417
|
-
} },
|
|
418
|
-
checkpoint: t,
|
|
419
|
-
metadata: c,
|
|
420
|
-
parentConfig: e.parent_checkpoint_id ? { configurable: {
|
|
421
|
-
thread_id: e.thread_id,
|
|
422
|
-
checkpoint_ns: i,
|
|
423
|
-
checkpoint_id: e.parent_checkpoint_id
|
|
424
|
-
} } : void 0,
|
|
425
|
-
pendingWrites: s
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
addSearchableMetadataFields(e, t) {
|
|
429
|
-
t && ("source" in t && (e.source = t.source), "step" in t && (e.step = t.step), "writes" in t && (e.writes = typeof t.writes == "object" ? JSON.stringify(t.writes) : t.writes), "score" in t && (e.score = t.score));
|
|
430
|
-
}
|
|
431
|
-
async applyTTL(...e) {
|
|
432
|
-
if (!this.ttlConfig?.defaultTTL) return;
|
|
433
|
-
const t = Math.floor(this.ttlConfig.defaultTTL * 60), s = await Promise.allSettled(e.map((i) => this.client.expire(i, t)));
|
|
434
|
-
for (let i = 0; i < s.length; i++) s[i].status === "rejected" && console.warn(`Failed to set TTL for key ${e[i]}:`, s[i].reason);
|
|
435
|
-
}
|
|
436
|
-
async ensureIndexes() {
|
|
437
|
-
for (const e of W) try {
|
|
438
|
-
await this.client.ft.create(e.index, e.schema, {
|
|
439
|
-
ON: "JSON",
|
|
440
|
-
PREFIX: e.prefix
|
|
441
|
-
});
|
|
442
|
-
} catch (t) {
|
|
443
|
-
t.message?.includes("Index already exists") || console.error(`Failed to create index ${e.index}:`, t.message);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
function g(w) {
|
|
448
|
-
if (w === null || typeof w != "object") return JSON.stringify(w);
|
|
449
|
-
if (Array.isArray(w)) return JSON.stringify(w.map((s) => g(s)));
|
|
450
|
-
const e = {}, t = Object.keys(w).sort();
|
|
451
|
-
for (const s of t) e[s] = w[s];
|
|
452
|
-
return JSON.stringify(e, (s, i) => {
|
|
453
|
-
if (i !== null && typeof i == "object" && !Array.isArray(i)) {
|
|
454
|
-
const c = {}, o = Object.keys(i).sort();
|
|
455
|
-
for (const f of o) c[f] = i[f];
|
|
456
|
-
return c;
|
|
457
|
-
}
|
|
458
|
-
return i;
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
export {
|
|
462
|
-
E as RedisSaver
|
|
463
|
-
};
|