zen-code 4.6.2 → 4.7.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/README.md +52 -27
- package/dist/FileSystemSkillStore-Dl5briBv.mjs +108 -0
- package/dist/{app-Cynj004J.mjs → app-CcnStH9S.mjs} +4963 -4152
- package/dist/{checkpoint-1sAx_j1E-DMtqyBT9.mjs → checkpoint-C5AFBYE--BbnaceZj.mjs} +160 -123
- package/dist/{checkpoint-DxiUsHMy-DqfBiLDW.mjs → checkpoint-DxiUsHMy-Cep4XMTK.mjs} +2 -2
- package/dist/{graphBuilder-mpLrx9tk.mjs → graphBuilder-skVEY6RJ.mjs} +12044 -26952
- package/dist/{index-BW3-KScB.mjs → index-BeLj9JYN.mjs} +2 -2
- package/dist/{index-B6kFMamn.mjs → index-D_dnZWV3.mjs} +2 -2
- package/dist/{load-Bh8eo6qE.mjs → load-iYJqYrjn.mjs} +1 -1
- package/dist/{memories-DirsFRdm.mjs → memories-CSOPZKuJ.mjs} +2 -2
- package/dist/nonInteractive.mjs +26 -22
- package/dist/{queue-Cu_nO_wt-DVTcONlE.mjs → queue-DySatFkr-DjaRbjhM.mjs} +1 -1
- package/dist/{shallow-BQy_8shO.mjs → shallow-CqCGqQDo.mjs} +2 -2
- package/dist/shallow-checkpoint-BEhTdp7z-CquyGG0C.mjs +383 -0
- package/dist/{sqlite-adapter-BKOLSdoL-5XOA6_0i.mjs → sqlite-adapter-oBA95xba-BrBWorSV.mjs} +22 -11
- package/dist/subTasks-DEZYN-F3.mjs +18 -0
- package/dist/zen-code.mjs +1 -1
- package/package.json +4 -4
- package/dist/FileSystemSkillStore-yvEvcRxB.mjs +0 -94
- package/dist/index-FHDPQ2Qk.mjs +0 -211
- package/dist/load-Cjl9cJ0o.mjs +0 -105
- package/dist/subTasks-Bt97OwvY.mjs +0 -209
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as C, u as v, c as x, T as $, m as I } from "./app-
|
|
2
|
-
import "./graphBuilder-
|
|
1
|
+
import { B as C, u as v, c as x, T as $, m as I } from "./app-CcnStH9S.mjs";
|
|
2
|
+
import "./graphBuilder-skVEY6RJ.mjs";
|
|
3
3
|
import { createClient as O, createCluster as N } from "redis";
|
|
4
4
|
const W = [
|
|
5
5
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
2
|
-
import { FileSystemSkillStore as y } from "./FileSystemSkillStore-
|
|
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-skVEY6RJ.mjs";
|
|
2
|
+
import { FileSystemSkillStore as y } from "./FileSystemSkillStore-Dl5briBv.mjs";
|
|
3
3
|
import { FileSystemPluginStore as F } from "./FileSystemPluginStore-ChortK7z.mjs";
|
|
4
4
|
import "lowdb";
|
|
5
5
|
import "lowdb/node";
|
|
@@ -22,7 +22,7 @@ function I(t, o) {
|
|
|
22
22
|
const n = k(t);
|
|
23
23
|
if (n.size > Y)
|
|
24
24
|
return console.warn(`Skipping ${t}: file too large (${n.size} bytes)`), null;
|
|
25
|
-
const i = x(t, "utf-8"), e = /^---\s*\n(
|
|
25
|
+
const i = x(t, "utf-8"), e = /^---\s*\n([\s\S]*?)\n---\s*\n/, a = i.match(e);
|
|
26
26
|
if (!a)
|
|
27
27
|
return console.warn(`Skipping ${t}: no valid YAML frontmatter found`), null;
|
|
28
28
|
const c = a[1];
|
package/dist/nonInteractive.mjs
CHANGED
|
@@ -1,45 +1,49 @@
|
|
|
1
1
|
import { HumanMessage as c } from "langchain";
|
|
2
|
-
import { i as
|
|
2
|
+
import { i as m, j as d, k as p } from "./graphBuilder-skVEY6RJ.mjs";
|
|
3
3
|
import "@langchain/langgraph";
|
|
4
4
|
import "zod";
|
|
5
5
|
import "@langchain/openai";
|
|
6
6
|
import "@langchain/anthropic";
|
|
7
7
|
import "@langchain/google-genai";
|
|
8
8
|
import "yaml";
|
|
9
|
-
|
|
9
|
+
import "@langgraph-js/standard-agent";
|
|
10
|
+
import "micromatch";
|
|
11
|
+
import "lowdb";
|
|
12
|
+
import "lowdb/node";
|
|
13
|
+
async function l() {
|
|
10
14
|
return new Promise((t, n) => {
|
|
11
|
-
let
|
|
12
|
-
process.stdin.setEncoding("utf8"), process.stdin.on("data", (
|
|
13
|
-
|
|
15
|
+
let e = "";
|
|
16
|
+
process.stdin.setEncoding("utf8"), process.stdin.on("data", (r) => {
|
|
17
|
+
e += r;
|
|
14
18
|
}), process.stdin.on("end", () => {
|
|
15
|
-
t(
|
|
16
|
-
}), process.stdin.on("error", (
|
|
17
|
-
n(
|
|
19
|
+
t(e);
|
|
20
|
+
}), process.stdin.on("error", (r) => {
|
|
21
|
+
n(r);
|
|
18
22
|
});
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
|
-
async function
|
|
22
|
-
await
|
|
23
|
-
const
|
|
24
|
-
let
|
|
25
|
+
async function S(t, n = !1) {
|
|
26
|
+
await m();
|
|
27
|
+
const e = await d();
|
|
28
|
+
let r = t || "";
|
|
25
29
|
if (n)
|
|
26
30
|
try {
|
|
27
|
-
|
|
31
|
+
r = (await l()).trim();
|
|
28
32
|
} catch (o) {
|
|
29
33
|
throw console.error("❌ 读取 stdin 失败:", o), o;
|
|
30
34
|
}
|
|
31
|
-
|
|
35
|
+
r || (console.error("❌ 错误: 未提供输入内容"), console.error(`
|
|
32
36
|
用法:`), console.error(' zen-code -p "你的任务描述"'), console.error(' echo "内容" | zen-code'), process.exit(1));
|
|
33
37
|
try {
|
|
34
38
|
const o = {
|
|
35
|
-
messages: [new c(
|
|
36
|
-
provider_id:
|
|
37
|
-
model_id:
|
|
38
|
-
enable_thinking:
|
|
39
|
-
},
|
|
39
|
+
messages: [new c(r)],
|
|
40
|
+
provider_id: e.provider_id,
|
|
41
|
+
model_id: e.model_id,
|
|
42
|
+
enable_thinking: e.enable_thinking
|
|
43
|
+
}, i = await p.invoke(o, {
|
|
40
44
|
recursionLimit: 500
|
|
41
|
-
}),
|
|
42
|
-
return a && console.log(a.text),
|
|
45
|
+
}), s = i.messages || [], a = s[s.length - 1];
|
|
46
|
+
return a && console.log(a.text), i;
|
|
43
47
|
} catch (o) {
|
|
44
48
|
throw console.error(`
|
|
45
49
|
❌ 执行失败: ${o instanceof Error ? o.message : String(o)}
|
|
@@ -47,5 +51,5 @@ async function y(t, n = !1) {
|
|
|
47
51
|
}
|
|
48
52
|
}
|
|
49
53
|
export {
|
|
50
|
-
|
|
54
|
+
S as runNonInteractive
|
|
51
55
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as $, u as g } from "./app-
|
|
2
|
-
import "./graphBuilder-
|
|
1
|
+
import { B as $, u as g } from "./app-CcnStH9S.mjs";
|
|
2
|
+
import "./graphBuilder-skVEY6RJ.mjs";
|
|
3
3
|
import { createClient as T } from "redis";
|
|
4
4
|
function k(u) {
|
|
5
5
|
if (u === null || typeof u != "object") return JSON.stringify(u);
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { Kysely as L, sql as p } from "kysely";
|
|
2
|
+
import { B as S, g as x, T as f, u as O, c as R, W as v, m as C } from "./app-CcnStH9S.mjs";
|
|
3
|
+
import "./graphBuilder-skVEY6RJ.mjs";
|
|
4
|
+
const u = {
|
|
5
|
+
maxRetries: 3,
|
|
6
|
+
baseDelayMs: 100,
|
|
7
|
+
isRetryableError: (h) => {
|
|
8
|
+
const e = h?.message?.toLowerCase() || "";
|
|
9
|
+
return e.includes("sqlite_busy") || e.includes("database is locked") || e.includes("database disk image is malformed") || e === "sqlite_busy" || e === "database is locked";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
async function b(h, e) {
|
|
13
|
+
let s = null;
|
|
14
|
+
for (let c = 0; c < u.maxRetries; c++)
|
|
15
|
+
try {
|
|
16
|
+
return await h();
|
|
17
|
+
} catch (t) {
|
|
18
|
+
if (s = t, !u.isRetryableError(t))
|
|
19
|
+
throw t;
|
|
20
|
+
if (c < u.maxRetries - 1) {
|
|
21
|
+
const n = u.baseDelayMs * Math.pow(2, c);
|
|
22
|
+
console.warn(
|
|
23
|
+
`SQLite lock detected${e ? ` (${e})` : ""}, retrying in ${n}ms (attempt ${c + 1}/${u.maxRetries})`
|
|
24
|
+
), await new Promise((i) => setTimeout(i, n));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw s;
|
|
28
|
+
}
|
|
29
|
+
function g(h) {
|
|
30
|
+
if (h === null || typeof h != "object")
|
|
31
|
+
return JSON.stringify(h);
|
|
32
|
+
if (Array.isArray(h))
|
|
33
|
+
return JSON.stringify(h.map((c) => g(c)));
|
|
34
|
+
const e = {}, s = Object.keys(h).sort();
|
|
35
|
+
for (const c of s)
|
|
36
|
+
e[c] = h[c];
|
|
37
|
+
return JSON.stringify(e, (c, t) => {
|
|
38
|
+
if (t !== null && typeof t == "object" && !Array.isArray(t)) {
|
|
39
|
+
const n = {}, i = Object.keys(t).sort();
|
|
40
|
+
for (const r of i)
|
|
41
|
+
n[r] = t[r];
|
|
42
|
+
return n;
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
class N extends S {
|
|
48
|
+
db;
|
|
49
|
+
isSetup;
|
|
50
|
+
constructor(e, s) {
|
|
51
|
+
super(s), this.db = new L({
|
|
52
|
+
dialect: e
|
|
53
|
+
}), this.isSetup = !1;
|
|
54
|
+
}
|
|
55
|
+
static async fromConnStringAsync(e) {
|
|
56
|
+
let s;
|
|
57
|
+
if (globalThis.Bun) {
|
|
58
|
+
console.log("LG | Using BunWorkerDialect " + e);
|
|
59
|
+
const { BunWorkerDialect: c } = await import("kysely-bun-worker");
|
|
60
|
+
s = new N(new c({ url: e }));
|
|
61
|
+
} else {
|
|
62
|
+
console.log("LG | Using NodeWasmDialect");
|
|
63
|
+
const { default: c } = await import("node-sqlite3-wasm"), { NodeWasmDialect: t } = await import("kysely-wasm");
|
|
64
|
+
console.log(e);
|
|
65
|
+
const n = new t({
|
|
66
|
+
database: new c.Database(e)
|
|
67
|
+
});
|
|
68
|
+
s = new N(n);
|
|
69
|
+
}
|
|
70
|
+
return await s.setup(), s;
|
|
71
|
+
}
|
|
72
|
+
async setup() {
|
|
73
|
+
this.isSetup || (await p`PRAGMA busy_timeout = 5000`.execute(this.db), await p`PRAGMA journal_mode = WAL`.execute(this.db), await p`PRAGMA synchronous = NORMAL`.execute(this.db), await p`PRAGMA wal_autocheckpoint = 1000`.execute(this.db), await p`
|
|
74
|
+
CREATE TABLE IF NOT EXISTS shallow_checkpoints (
|
|
75
|
+
thread_id TEXT NOT NULL,
|
|
76
|
+
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
77
|
+
checkpoint_id TEXT NOT NULL,
|
|
78
|
+
parent_checkpoint_id TEXT,
|
|
79
|
+
type TEXT,
|
|
80
|
+
checkpoint BLOB,
|
|
81
|
+
metadata BLOB,
|
|
82
|
+
checkpoint_ts INTEGER NOT NULL DEFAULT 0,
|
|
83
|
+
PRIMARY KEY (thread_id, checkpoint_ns)
|
|
84
|
+
)`.execute(this.db), await p`
|
|
85
|
+
CREATE INDEX IF NOT EXISTS idx_shallow_checkpoints_ts
|
|
86
|
+
ON shallow_checkpoints(checkpoint_ts DESC)`.execute(this.db), await p`
|
|
87
|
+
CREATE TABLE IF NOT EXISTS writes (
|
|
88
|
+
thread_id TEXT NOT NULL,
|
|
89
|
+
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
90
|
+
checkpoint_id TEXT NOT NULL,
|
|
91
|
+
task_id TEXT NOT NULL,
|
|
92
|
+
idx INTEGER NOT NULL,
|
|
93
|
+
channel TEXT NOT NULL,
|
|
94
|
+
type TEXT,
|
|
95
|
+
value BLOB,
|
|
96
|
+
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id, task_id, idx)
|
|
97
|
+
)`.execute(this.db), this.isSetup = !0);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 获取 checkpoint(便捷方法)
|
|
101
|
+
*/
|
|
102
|
+
async get(e) {
|
|
103
|
+
return (await this.getTuple(e))?.checkpoint;
|
|
104
|
+
}
|
|
105
|
+
async getTuple(e) {
|
|
106
|
+
await this.setup();
|
|
107
|
+
const s = e.configurable?.thread_id, c = e.configurable?.checkpoint_ns ?? "", t = x(e);
|
|
108
|
+
if (s === void 0)
|
|
109
|
+
return;
|
|
110
|
+
let n = this.db.selectFrom("shallow_checkpoints").select([
|
|
111
|
+
"thread_id",
|
|
112
|
+
"checkpoint_ns",
|
|
113
|
+
"checkpoint_id",
|
|
114
|
+
"parent_checkpoint_id",
|
|
115
|
+
"type",
|
|
116
|
+
"checkpoint",
|
|
117
|
+
"metadata",
|
|
118
|
+
"checkpoint_ts",
|
|
119
|
+
p`(
|
|
120
|
+
SELECT json_group_array(
|
|
121
|
+
json_object(
|
|
122
|
+
'task_id', pw.task_id,
|
|
123
|
+
'channel', pw.channel,
|
|
124
|
+
'type', pw.type,
|
|
125
|
+
'value', CAST(pw.value AS TEXT)
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
FROM writes as pw
|
|
129
|
+
WHERE pw.thread_id = shallow_checkpoints.thread_id
|
|
130
|
+
AND pw.checkpoint_ns = shallow_checkpoints.checkpoint_ns
|
|
131
|
+
AND pw.checkpoint_id = shallow_checkpoints.checkpoint_id
|
|
132
|
+
)`.as("pending_writes"),
|
|
133
|
+
p`(
|
|
134
|
+
SELECT json_group_array(
|
|
135
|
+
json_object(
|
|
136
|
+
'type', ps.type,
|
|
137
|
+
'value', CAST(ps.value AS TEXT)
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
FROM writes as ps
|
|
141
|
+
WHERE ps.thread_id = shallow_checkpoints.thread_id
|
|
142
|
+
AND ps.checkpoint_ns = shallow_checkpoints.checkpoint_ns
|
|
143
|
+
AND ps.checkpoint_id = shallow_checkpoints.parent_checkpoint_id
|
|
144
|
+
AND ps.channel = ${f}
|
|
145
|
+
ORDER BY ps.idx
|
|
146
|
+
)`.as("pending_sends")
|
|
147
|
+
]).where("thread_id", "=", s).where("checkpoint_ns", "=", c);
|
|
148
|
+
t && (n = n.where("checkpoint_id", "=", t));
|
|
149
|
+
const i = await n.executeTakeFirst();
|
|
150
|
+
if (!i || t && i.checkpoint_id !== t)
|
|
151
|
+
return;
|
|
152
|
+
const r = await Promise.all(
|
|
153
|
+
JSON.parse(i.pending_writes || "[]").map(async (d) => [
|
|
154
|
+
d.task_id,
|
|
155
|
+
d.channel,
|
|
156
|
+
await this.serde.loadsTyped(d.type ?? "json", d.value ?? "")
|
|
157
|
+
])
|
|
158
|
+
), a = await this.serde.loadsTyped(
|
|
159
|
+
i.type ?? "json",
|
|
160
|
+
new TextDecoder().decode(i.checkpoint)
|
|
161
|
+
);
|
|
162
|
+
a.v < 4 && i.parent_checkpoint_id != null && await this.migratePendingSends(a, i.thread_id, i.parent_checkpoint_id);
|
|
163
|
+
const _ = {
|
|
164
|
+
configurable: {
|
|
165
|
+
thread_id: i.thread_id,
|
|
166
|
+
checkpoint_ns: i.checkpoint_ns,
|
|
167
|
+
checkpoint_id: i.checkpoint_id
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
checkpoint: a,
|
|
172
|
+
config: _,
|
|
173
|
+
metadata: await this.serde.loadsTyped(
|
|
174
|
+
i.type ?? "json",
|
|
175
|
+
new TextDecoder().decode(i.metadata)
|
|
176
|
+
),
|
|
177
|
+
parentConfig: i.parent_checkpoint_id ? {
|
|
178
|
+
configurable: {
|
|
179
|
+
thread_id: i.thread_id,
|
|
180
|
+
checkpoint_ns: i.checkpoint_ns,
|
|
181
|
+
checkpoint_id: i.parent_checkpoint_id
|
|
182
|
+
}
|
|
183
|
+
} : void 0,
|
|
184
|
+
pendingWrites: r
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async *list(e, s) {
|
|
188
|
+
await this.setup();
|
|
189
|
+
const { limit: c, before: t, filter: n } = s ?? {}, i = e.configurable?.thread_id, r = e.configurable?.checkpoint_ns;
|
|
190
|
+
let a = this.db.selectFrom("shallow_checkpoints").select([
|
|
191
|
+
"thread_id",
|
|
192
|
+
"checkpoint_ns",
|
|
193
|
+
"checkpoint_id",
|
|
194
|
+
"parent_checkpoint_id",
|
|
195
|
+
"type",
|
|
196
|
+
"checkpoint",
|
|
197
|
+
"metadata",
|
|
198
|
+
"checkpoint_ts",
|
|
199
|
+
p`(
|
|
200
|
+
SELECT json_group_array(
|
|
201
|
+
json_object(
|
|
202
|
+
'task_id', pw.task_id,
|
|
203
|
+
'channel', pw.channel,
|
|
204
|
+
'type', pw.type,
|
|
205
|
+
'value', CAST(pw.value AS TEXT)
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
FROM writes as pw
|
|
209
|
+
WHERE pw.thread_id = shallow_checkpoints.thread_id
|
|
210
|
+
AND pw.checkpoint_ns = shallow_checkpoints.checkpoint_ns
|
|
211
|
+
AND pw.checkpoint_id = shallow_checkpoints.checkpoint_id
|
|
212
|
+
)`.as("pending_writes")
|
|
213
|
+
]);
|
|
214
|
+
i && (a = a.where("thread_id", "=", i)), r != null && (a = a.where("checkpoint_ns", "=", r)), t?.configurable?.checkpoint_id !== void 0 && (a = a.where("checkpoint_id", "<", t.configurable.checkpoint_id)), a = a.orderBy("checkpoint_ts", "desc");
|
|
215
|
+
const _ = await a.execute();
|
|
216
|
+
let d = 0;
|
|
217
|
+
for (const o of _) {
|
|
218
|
+
const w = await this.serde.loadsTyped(
|
|
219
|
+
o.type ?? "json",
|
|
220
|
+
new TextDecoder().decode(o.metadata)
|
|
221
|
+
);
|
|
222
|
+
if (n && !this._checkMetadataFilterMatch(w, n))
|
|
223
|
+
continue;
|
|
224
|
+
if (c !== void 0 && d >= c)
|
|
225
|
+
return;
|
|
226
|
+
const y = await Promise.all(
|
|
227
|
+
JSON.parse(o.pending_writes || "[]").map(async (l) => [
|
|
228
|
+
l.task_id,
|
|
229
|
+
l.channel,
|
|
230
|
+
await this.serde.loadsTyped(l.type ?? "json", l.value ?? "")
|
|
231
|
+
])
|
|
232
|
+
), k = await this.serde.loadsTyped(
|
|
233
|
+
o.type ?? "json",
|
|
234
|
+
new TextDecoder().decode(o.checkpoint)
|
|
235
|
+
);
|
|
236
|
+
k.v < 4 && o.parent_checkpoint_id != null && await this.migratePendingSends(k, o.thread_id, o.parent_checkpoint_id), d++, yield {
|
|
237
|
+
config: {
|
|
238
|
+
configurable: {
|
|
239
|
+
thread_id: o.thread_id,
|
|
240
|
+
checkpoint_ns: o.checkpoint_ns,
|
|
241
|
+
checkpoint_id: o.checkpoint_id
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
checkpoint: k,
|
|
245
|
+
metadata: w,
|
|
246
|
+
parentConfig: o.parent_checkpoint_id ? {
|
|
247
|
+
configurable: {
|
|
248
|
+
thread_id: o.thread_id,
|
|
249
|
+
checkpoint_ns: o.checkpoint_ns,
|
|
250
|
+
checkpoint_id: o.parent_checkpoint_id
|
|
251
|
+
}
|
|
252
|
+
} : void 0,
|
|
253
|
+
pendingWrites: y
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Check metadata filter matches (with deep comparison support)
|
|
259
|
+
* Matches ShallowMemorySaver behavior
|
|
260
|
+
*/
|
|
261
|
+
_checkMetadataFilterMatch(e, s) {
|
|
262
|
+
for (const [c, t] of Object.entries(s)) {
|
|
263
|
+
const n = e?.[c];
|
|
264
|
+
if (t === null) {
|
|
265
|
+
if (!(c in (e || {})) || n !== null)
|
|
266
|
+
return !1;
|
|
267
|
+
} else if (typeof t == "object" && !Array.isArray(t)) {
|
|
268
|
+
if (typeof n != "object" || n === null || g(t) !== g(n))
|
|
269
|
+
return !1;
|
|
270
|
+
} else if (n !== t)
|
|
271
|
+
return !1;
|
|
272
|
+
}
|
|
273
|
+
return !0;
|
|
274
|
+
}
|
|
275
|
+
async put(e, s, c, t) {
|
|
276
|
+
await this.setup();
|
|
277
|
+
const n = e.configurable?.thread_id, i = e.configurable?.checkpoint_ns ?? "", r = e.configurable?.checkpoint_id;
|
|
278
|
+
if (!n)
|
|
279
|
+
throw new Error("thread_id is required");
|
|
280
|
+
const a = s.id || O(0), _ = R(s), [[d, o], [w, y]] = await Promise.all([
|
|
281
|
+
this.serde.dumpsTyped(_),
|
|
282
|
+
this.serde.dumpsTyped(c)
|
|
283
|
+
]);
|
|
284
|
+
if (d !== w)
|
|
285
|
+
throw new Error("Failed to serialize checkpoint and metadata to the same type.");
|
|
286
|
+
const k = n, l = i, T = a;
|
|
287
|
+
return await b(
|
|
288
|
+
async () => {
|
|
289
|
+
await this.db.transaction().execute(async (m) => {
|
|
290
|
+
const E = await m.selectFrom("shallow_checkpoints").select(["checkpoint_id"]).where("thread_id", "=", k).where("checkpoint_ns", "=", l).executeTakeFirst();
|
|
291
|
+
E && E.checkpoint_id !== T && await m.deleteFrom("writes").where("thread_id", "=", k).where("checkpoint_ns", "=", l).where("checkpoint_id", "=", E.checkpoint_id).execute(), await m.insertInto("shallow_checkpoints").values({
|
|
292
|
+
thread_id: k,
|
|
293
|
+
checkpoint_ns: l,
|
|
294
|
+
checkpoint_id: T,
|
|
295
|
+
parent_checkpoint_id: r ?? null,
|
|
296
|
+
type: d,
|
|
297
|
+
checkpoint: new Uint8Array(Buffer.from(o)),
|
|
298
|
+
metadata: new Uint8Array(Buffer.from(y)),
|
|
299
|
+
checkpoint_ts: Date.now()
|
|
300
|
+
}).onConflict(
|
|
301
|
+
(A) => A.columns(["thread_id", "checkpoint_ns"]).doUpdateSet({
|
|
302
|
+
checkpoint_id: T,
|
|
303
|
+
parent_checkpoint_id: r ?? null,
|
|
304
|
+
type: d,
|
|
305
|
+
checkpoint: new Uint8Array(Buffer.from(o)),
|
|
306
|
+
metadata: new Uint8Array(Buffer.from(y)),
|
|
307
|
+
checkpoint_ts: Date.now()
|
|
308
|
+
})
|
|
309
|
+
).execute();
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
`put(${n}/${a})`
|
|
313
|
+
), {
|
|
314
|
+
configurable: {
|
|
315
|
+
thread_id: n,
|
|
316
|
+
checkpoint_ns: i,
|
|
317
|
+
checkpoint_id: a
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
async putWrites(e, s, c) {
|
|
322
|
+
await this.setup();
|
|
323
|
+
const t = e.configurable?.thread_id, n = e.configurable?.checkpoint_ns ?? "", i = e.configurable?.checkpoint_id;
|
|
324
|
+
if (!t || !i)
|
|
325
|
+
throw new Error("thread_id and checkpoint_id are required");
|
|
326
|
+
const r = await Promise.all(
|
|
327
|
+
s.map(async (a, _) => {
|
|
328
|
+
const [d, o] = await this.serde.dumpsTyped(a[1]);
|
|
329
|
+
return {
|
|
330
|
+
thread_id: t,
|
|
331
|
+
checkpoint_ns: n,
|
|
332
|
+
checkpoint_id: i,
|
|
333
|
+
task_id: c,
|
|
334
|
+
idx: v[a[0]] ?? _,
|
|
335
|
+
channel: a[0],
|
|
336
|
+
type: d,
|
|
337
|
+
value: new Uint8Array(Buffer.from(o))
|
|
338
|
+
};
|
|
339
|
+
})
|
|
340
|
+
);
|
|
341
|
+
r.length !== 0 && await b(
|
|
342
|
+
async () => {
|
|
343
|
+
await this.db.transaction().execute(async (a) => {
|
|
344
|
+
await a.deleteFrom("writes").where("thread_id", "=", t).where("checkpoint_ns", "=", n).where("checkpoint_id", "=", i).where("task_id", "=", c).execute();
|
|
345
|
+
for (const _ of r)
|
|
346
|
+
await a.insertInto("writes").values(_).execute();
|
|
347
|
+
});
|
|
348
|
+
},
|
|
349
|
+
`putWrites(${t}/${i}/${c})`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
async deleteThread(e) {
|
|
353
|
+
await b(
|
|
354
|
+
async () => {
|
|
355
|
+
await this.db.transaction().execute(async (s) => {
|
|
356
|
+
await s.deleteFrom("shallow_checkpoints").where("thread_id", "=", e).execute(), await s.deleteFrom("writes").where("thread_id", "=", e).execute();
|
|
357
|
+
});
|
|
358
|
+
},
|
|
359
|
+
`deleteThread(${e})`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
async migratePendingSends(e, s, c) {
|
|
363
|
+
const t = await this.db.selectFrom("writes as ps").select([
|
|
364
|
+
"ps.checkpoint_id",
|
|
365
|
+
p`json_group_array(
|
|
366
|
+
json_object(
|
|
367
|
+
'type', ps.type,
|
|
368
|
+
'value', CAST(ps.value AS TEXT)
|
|
369
|
+
)
|
|
370
|
+
)`.as("pending_sends")
|
|
371
|
+
]).where("ps.thread_id", "=", s).where("ps.checkpoint_id", "=", c).where("ps.channel", "=", f).orderBy("ps.idx").executeTakeFirst();
|
|
372
|
+
if (!t) return;
|
|
373
|
+
const n = e;
|
|
374
|
+
n.channel_values ??= {}, n.channel_values[f] = await Promise.all(
|
|
375
|
+
JSON.parse(t.pending_sends || "[]").map(
|
|
376
|
+
({ type: i, value: r }) => this.serde.loadsTyped(i, r)
|
|
377
|
+
)
|
|
378
|
+
), n.channel_versions[f] = Object.keys(e.channel_versions).length > 0 ? C(...Object.values(e.channel_versions)) : this.getNextVersion(void 0);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
export {
|
|
382
|
+
N as SqliteShallowSaver
|
|
383
|
+
};
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { sql as e } from "kysely";
|
|
2
|
-
class
|
|
2
|
+
class N {
|
|
3
3
|
db;
|
|
4
|
+
pragmaPromise = null;
|
|
4
5
|
constructor(t) {
|
|
5
6
|
this.db = t;
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* 设置 SQLite PRAGMA 配置,解决锁问题
|
|
10
|
+
* 使用 Promise 缓存确保并发安全且只执行一次
|
|
11
|
+
*/
|
|
12
|
+
ensurePragma() {
|
|
13
|
+
return this.pragmaPromise || (this.pragmaPromise = this.doEnsurePragma()), this.pragmaPromise;
|
|
14
|
+
}
|
|
15
|
+
async doEnsurePragma() {
|
|
16
|
+
await e`PRAGMA busy_timeout = 5000`.execute(this.db), await e`PRAGMA journal_mode = WAL`.execute(this.db), await e`PRAGMA synchronous = NORMAL`.execute(this.db), await e`PRAGMA wal_autocheckpoint = 1000`.execute(this.db);
|
|
17
|
+
}
|
|
7
18
|
dateToDb(t) {
|
|
8
19
|
return t.toISOString();
|
|
9
20
|
}
|
|
@@ -22,23 +33,23 @@ class L {
|
|
|
22
33
|
}
|
|
23
34
|
return t;
|
|
24
35
|
}
|
|
25
|
-
buildJsonQuery(t,
|
|
26
|
-
const
|
|
27
|
-
let
|
|
28
|
-
if (typeof
|
|
29
|
-
const
|
|
36
|
+
buildJsonQuery(t, T, r, a) {
|
|
37
|
+
const i = `$.${r.includes("-") || r.includes(".") || r.includes(" ") ? `"${r}"` : r}`;
|
|
38
|
+
let s;
|
|
39
|
+
if (typeof a == "string" || typeof a == "number" ? s = a : typeof a == "boolean" ? s = a ? 1 : 0 : a === null ? s = null : s = JSON.stringify(a), a === null) {
|
|
40
|
+
const E = `"${r}":null`;
|
|
30
41
|
return e`
|
|
31
|
-
json_extract(${e.ref(
|
|
32
|
-
AND ${e.ref(
|
|
42
|
+
json_extract(${e.ref(T)}, ${e.lit(i)}) IS NULL
|
|
43
|
+
AND ${e.ref(T)} LIKE ${e.lit(`%${E}%`)}
|
|
33
44
|
`;
|
|
34
45
|
}
|
|
35
|
-
return e`json_extract(${e.ref(
|
|
46
|
+
return e`json_extract(${e.ref(T)}, ${e.lit(i)}) = ${e.lit(s)}`;
|
|
36
47
|
}
|
|
37
48
|
now() {
|
|
38
49
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
39
50
|
}
|
|
40
51
|
async createTables(t) {
|
|
41
|
-
await e`
|
|
52
|
+
await this.ensurePragma(), await e`
|
|
42
53
|
CREATE TABLE IF NOT EXISTS threads (
|
|
43
54
|
thread_id TEXT PRIMARY KEY,
|
|
44
55
|
created_at TEXT NOT NULL,
|
|
@@ -67,5 +78,5 @@ class L {
|
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
80
|
export {
|
|
70
|
-
|
|
81
|
+
N as SQLiteAdapter
|
|
71
82
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getAgentListFromPackage as s, SubAgentsMiddleware as g } from "@langgraph-js/standard-agent";
|
|
2
|
+
import { SubAgentsMiddleware as w, getAgentListFromPackage as S } from "@langgraph-js/standard-agent";
|
|
3
|
+
import { l as i, m as o } from "./graphBuilder-skVEY6RJ.mjs";
|
|
4
|
+
async function m(e) {
|
|
5
|
+
const t = await s(e);
|
|
6
|
+
return new g({
|
|
7
|
+
agents: t,
|
|
8
|
+
stateSchema: i,
|
|
9
|
+
async createAgent(a, r, n) {
|
|
10
|
+
return await o(r.subagent_id, e, n, {}, { parent_id: a });
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
w as SubAgentsMiddleware,
|
|
16
|
+
m as createSubAgentsMiddleware,
|
|
17
|
+
S as getAgentListFromPackage
|
|
18
|
+
};
|
package/dist/zen-code.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zen-code",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/cli.mjs",
|
|
6
6
|
"bin": "./dist/cli.mjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@langchain/langgraph": "^1.1.0",
|
|
20
20
|
"@langchain/mcp-adapters": "^1.1.1",
|
|
21
21
|
"@langchain/openai": "1.1.3",
|
|
22
|
-
"@langgraph-js/pure-graph": "^3.
|
|
22
|
+
"@langgraph-js/pure-graph": "^3.2.0",
|
|
23
23
|
"chalk": "^5.6.2",
|
|
24
24
|
"diff-match-patch": "^1.0.5",
|
|
25
25
|
"execa": "^9.6.1",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"xdg-basedir": "^5.1.0",
|
|
43
43
|
"yaml": "^2.8.2",
|
|
44
44
|
"zod": "^4.3.5",
|
|
45
|
-
"@langgraph-js/standard-agent": "1.1
|
|
45
|
+
"@langgraph-js/standard-agent": "1.2.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@inkjs/ui": "^2.0.0",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"vite-bundle-analyzer": "^1.3.2",
|
|
68
68
|
"vite-plugin-static-copy": "^3.1.4",
|
|
69
69
|
"vitest": "^4.0.18",
|
|
70
|
-
"@codegraph/union-client": "1.0.0",
|
|
71
70
|
"@codegraph/agent": "1.0.0",
|
|
72
71
|
"@codegraph/config": "1.0.0",
|
|
72
|
+
"@codegraph/union-client": "1.0.0",
|
|
73
73
|
"ink-pro": "1.1.0"
|
|
74
74
|
},
|
|
75
75
|
"babel": {
|