zen-code 4.3.0 → 4.4.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.
@@ -1,4 +1,4 @@
1
- import { I as P, J as d, K as _ } from "./graphBuilder-2Ioob7L7.mjs";
1
+ import { I as P, J as d, K as _ } from "./graphBuilder-B0bC88R_.mjs";
2
2
  var v, m, g = 0, O = 0;
3
3
  function h(r, e, n) {
4
4
  var f = 0, t = e || new Array(16);
@@ -1,4 +1,4 @@
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-2Ioob7L7.mjs";
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-B0bC88R_.mjs";
2
2
  import { FileSystemSkillStore as y } from "./FileSystemSkillStore-yvEvcRxB.mjs";
3
3
  import { FileSystemPluginStore as F } from "./FileSystemPluginStore-ChortK7z.mjs";
4
4
  import "lowdb";
@@ -1,5 +1,5 @@
1
- import { l as n } from "./graphBuilder-2Ioob7L7.mjs";
2
- import { B as b, t as j, x as v, s as R, z as T, y as L, D as x, E as A, q as $, v as C, r as _, M as I, P as E, w as z, p as U, u as F, o as W, H as K, G as Y } from "./graphBuilder-2Ioob7L7.mjs";
1
+ import { l as n } from "./graphBuilder-B0bC88R_.mjs";
2
+ import { B as b, t as j, x as v, s as R, z as T, y as L, D as x, E as A, q as $, v as C, r as _, M as I, P as E, w as z, p as U, u as F, o as W, H as K, G as Y } from "./graphBuilder-B0bC88R_.mjs";
3
3
  import r from "node:fs/promises";
4
4
  import { join as m } from "node:path";
5
5
  import { l as d } from "./load-Cjl9cJ0o.mjs";
@@ -1,6 +1,6 @@
1
- import { u as C } from "./id-CxmtJIkV.mjs";
2
- import { B as v, c as x, T as $, m as I } from "./app-Dy9hkwWD.mjs";
3
- import "./graphBuilder-2Ioob7L7.mjs";
1
+ import { u as C } from "./id-Cu7CRpDw.mjs";
2
+ import { B as v, c as x, T as $, m as I } from "./app-CRslJvxg.mjs";
3
+ import "./graphBuilder-B0bC88R_.mjs";
4
4
  import { createClient as O, createCluster as N } from "redis";
5
5
  const W = [
6
6
  {
@@ -1,5 +1,5 @@
1
1
  import { l } from "./load-Bh8eo6qE.mjs";
2
- import { l as h } from "./graphBuilder-2Ioob7L7.mjs";
2
+ import { l as h } from "./graphBuilder-B0bC88R_.mjs";
3
3
  const M = `## Memory System
4
4
 
5
5
  你可以访问一个包含之前任务和经验知识的记忆库。
@@ -1,14 +1,12 @@
1
1
  import { HumanMessage as c } from "langchain";
2
- import { i as d, j as m, k as p } from "./graphBuilder-2Ioob7L7.mjs";
2
+ import { i as d, j as m, k as l } from "./graphBuilder-B0bC88R_.mjs";
3
3
  import "@langchain/langgraph";
4
4
  import "zod";
5
5
  import "@langchain/openai";
6
6
  import "@langchain/anthropic";
7
+ import "@langchain/google-genai";
7
8
  import "yaml";
8
- import "micromatch";
9
- import "lowdb";
10
- import "lowdb/node";
11
- async function l() {
9
+ async function p() {
12
10
  return new Promise((t, n) => {
13
11
  let r = "";
14
12
  process.stdin.setEncoding("utf8"), process.stdin.on("data", (e) => {
@@ -20,13 +18,13 @@ async function l() {
20
18
  });
21
19
  });
22
20
  }
23
- async function x(t, n = !1) {
21
+ async function y(t, n = !1) {
24
22
  await d();
25
23
  const r = await m();
26
24
  let e = t || "";
27
25
  if (n)
28
26
  try {
29
- e = (await l()).trim();
27
+ e = (await p()).trim();
30
28
  } catch (o) {
31
29
  throw console.error("❌ 读取 stdin 失败:", o), o;
32
30
  }
@@ -38,10 +36,10 @@ async function x(t, n = !1) {
38
36
  provider_id: r.provider_id,
39
37
  model_id: r.model_id,
40
38
  enable_thinking: r.enable_thinking
41
- }, i = await p.invoke(o, {
39
+ }, s = await l.invoke(o, {
42
40
  recursionLimit: 500
43
- }), s = i.messages || [], a = s[s.length - 1];
44
- return a && console.log(a.text), i;
41
+ }), i = s.messages || [], a = i[i.length - 1];
42
+ return a && console.log(a.text), s;
45
43
  } catch (o) {
46
44
  throw console.error(`
47
45
  ❌ 执行失败: ${o instanceof Error ? o.message : String(o)}
@@ -49,5 +47,5 @@ async function x(t, n = !1) {
49
47
  }
50
48
  }
51
49
  export {
52
- x as runNonInteractive
50
+ y as runNonInteractive
53
51
  };
@@ -0,0 +1,106 @@
1
+ import { a as h, C as d } from "./app-CRslJvxg.mjs";
2
+ import { createClient as m } from "redis";
3
+ class o extends h {
4
+ // 轮询间隔(毫秒)
5
+ constructor(e, t = !0, s = 300) {
6
+ super(e, !0, s), this.id = e, this.compressMessages = t, this.ttl = s, this.streamKey = `stream:${this.id}`, this.listKey = `queue:${this.id}`, this.redis = m({
7
+ url: process.env.REDIS_URL
8
+ }), this.cancelSignal = new AbortController(), this.redis.isOpen || this.redis.connect(), this.isConnected = !0;
9
+ }
10
+ redis;
11
+ streamKey;
12
+ listKey;
13
+ isConnected = !1;
14
+ cancelSignal;
15
+ lastStreamId = "0";
16
+ // 最后读取的 Stream ID
17
+ pollInterval = 100;
18
+ /**
19
+ * 推送消息到 Redis Stream 和 List
20
+ * - Stream: 用于实时推送(集群友好)
21
+ * - List: 用于 getAll() 批量获取历史数据
22
+ */
23
+ async push(e) {
24
+ const t = await this.encodeData(e), s = Buffer.from(t).toString("base64"), a = Buffer.from(t);
25
+ await this.redis.xAdd(this.streamKey, "*", { data: s }), await this.redis.expire(this.streamKey, this.ttl), await this.redis.rPush(this.listKey, a), await this.redis.expire(this.listKey, this.ttl), this.emit("dataChange", s);
26
+ }
27
+ /**
28
+ * 异步生成器:使用 Redis Streams XREAD 轮询消费队列数据
29
+ */
30
+ async *onDataReceive() {
31
+ let e = !1;
32
+ if (this.cancelSignal.signal.aborted)
33
+ return;
34
+ const t = () => {
35
+ e = !0;
36
+ };
37
+ this.cancelSignal.signal.addEventListener("abort", t);
38
+ try {
39
+ for (; !e && !this.cancelSignal.signal.aborted; ) {
40
+ const s = await this.redis.xRead([{ key: this.streamKey, id: this.lastStreamId }], {
41
+ BLOCK: this.pollInterval,
42
+ COUNT: 10
43
+ });
44
+ if (s && s.length > 0)
45
+ for (const a of s) {
46
+ for (const r of a.messages) {
47
+ this.lastStreamId = r.id;
48
+ const n = r.message.data, l = Buffer.from(n, "base64"), i = await this.decodeData(l);
49
+ if ((i.event === "__stream_end__" || i.event === "__stream_error__" || i.event === "__stream_cancel__") && (await new Promise((c) => setTimeout(c, 300)), e = !0, i.event === "__stream_cancel__" && await this.cancel()), yield i, e)
50
+ break;
51
+ }
52
+ if (e)
53
+ break;
54
+ }
55
+ !e && !this.cancelSignal.signal.aborted && await new Promise((a) => setTimeout(a, this.pollInterval));
56
+ }
57
+ } finally {
58
+ this.cancelSignal.signal.removeEventListener("abort", t);
59
+ }
60
+ }
61
+ /**
62
+ * 获取队列中的所有数据(从 List 获取历史数据)
63
+ */
64
+ async getAll() {
65
+ const e = await this.redis.lRange(this.listKey, 0, -1);
66
+ return !e || e.length === 0 ? [] : this.compressMessages ? await Promise.all(
67
+ e.map((t) => {
68
+ const s = typeof t == "string" ? Buffer.from(t, "binary") : t;
69
+ return this.decodeData(s);
70
+ })
71
+ ) : e.map((t) => JSON.parse(t));
72
+ }
73
+ /**
74
+ * 清空队列
75
+ */
76
+ clear() {
77
+ this.isConnected && (this.redis.del(this.streamKey), this.redis.del(this.listKey));
78
+ }
79
+ /**
80
+ * 取消操作
81
+ */
82
+ async cancel() {
83
+ this.cancelSignal.abort("user cancel this run"), await this.push(new d());
84
+ }
85
+ /**
86
+ * 复制队列到另一个队列
87
+ */
88
+ async copyToQueue(e, t) {
89
+ const s = new o(e, this.compressMessages, t ?? this.ttl);
90
+ await this.redis.copy(this.listKey, s.listKey), await this.redis.expire(s.listKey, t ?? this.ttl);
91
+ const a = await this.redis.xRange(this.streamKey, "-", "+");
92
+ if (a && a.length > 0) {
93
+ for (const r of a) {
94
+ const n = {};
95
+ for (const [l, i] of Object.entries(r.message))
96
+ n[l] = String(i);
97
+ await this.redis.xAdd(s.streamKey, "*", n);
98
+ }
99
+ await this.redis.expire(s.streamKey, t ?? this.ttl);
100
+ }
101
+ return s;
102
+ }
103
+ }
104
+ export {
105
+ o as RedisStreamQueue
106
+ };
@@ -0,0 +1,157 @@
1
+ var h = /* @__PURE__ */ ((a) => (a.NETWORK_ERROR = "NETWORK_ERROR", a.CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT", a.INTERNAL_ERROR = "INTERNAL_ERROR", a.THREAD_NOT_FOUND = "THREAD_NOT_FOUND", a.THREAD_BUSY = "THREAD_BUSY", a.RUN_NOT_FOUND = "RUN_NOT_FOUND", a.GRAPH_NOT_FOUND = "GRAPH_NOT_FOUND", a.INVALID_REQUEST = "INVALID_REQUEST", a))(h || {});
2
+ class d extends Error {
3
+ constructor(s, t, e) {
4
+ super(t), this.code = s, this.statusCode = e, this.name = "RemoteApiError";
5
+ }
6
+ }
7
+ async function c(a, s, t) {
8
+ try {
9
+ let e = a;
10
+ if (t?.query) {
11
+ const f = new URLSearchParams();
12
+ Object.entries(t.query).forEach(([v, N]) => {
13
+ f.append(v, String(N));
14
+ }), e += `?${f.toString()}`;
15
+ }
16
+ const i = await fetch(e, {
17
+ method: s,
18
+ headers: {
19
+ "Content-Type": "application/json"
20
+ },
21
+ body: t?.body ? JSON.stringify(t.body) : void 0
22
+ }), n = await i.json();
23
+ if (!i.ok || !n.success)
24
+ throw new d(
25
+ n.error?.code || h.INTERNAL_ERROR,
26
+ n.error?.message || "Unknown error",
27
+ i.status
28
+ );
29
+ return n;
30
+ } catch (e) {
31
+ throw e instanceof d ? e : new d(
32
+ h.NETWORK_ERROR,
33
+ `Network error: ${e instanceof Error ? e.message : "Unknown error"}`
34
+ );
35
+ }
36
+ }
37
+ async function o(a, s) {
38
+ return c(a, "GET", { query: s });
39
+ }
40
+ async function r(a, s, t) {
41
+ return c(a, "POST", { body: s, query: t });
42
+ }
43
+ async function l(a, s, t) {
44
+ return c(a, "PUT", { body: s, query: t });
45
+ }
46
+ async function O(a, s) {
47
+ return c(a, "DELETE", { query: s });
48
+ }
49
+ class p {
50
+ constructor(s, t) {
51
+ this.serverUrl = s, this.httpClient = t, this.serverUrl = s.replace(/\/$/, ""), this.httpClient = t || fetch;
52
+ }
53
+ /**
54
+ * 初始化数据库
55
+ */
56
+ async setup() {
57
+ await r(`${this.serverUrl}/setup`);
58
+ }
59
+ /**
60
+ * 创建线程
61
+ */
62
+ async create(s) {
63
+ return (await r(`${this.serverUrl}/threads`, s)).data;
64
+ }
65
+ /**
66
+ * 搜索线程
67
+ */
68
+ async search(s) {
69
+ const t = {};
70
+ return s?.ids !== void 0 && s.ids.length > 0 && (t.ids = JSON.stringify(s.ids)), s?.metadata !== void 0 && (t.metadata = JSON.stringify(s.metadata)), s?.limit !== void 0 && (t.limit = s.limit), s?.offset !== void 0 && (t.offset = s.offset), s?.status !== void 0 && (t.status = s.status), s?.sortBy !== void 0 && (t.sortBy = s.sortBy), s?.sortOrder !== void 0 && (t.sortOrder = s.sortOrder), s?.values !== void 0 && (t.values = JSON.stringify(s.values)), s?.select !== void 0 && (t.select = JSON.stringify(s.select)), s?.withoutDetails !== void 0 && (t.withoutDetails = s.withoutDetails), (await o(`${this.serverUrl}/threads`, t)).data;
71
+ }
72
+ /**
73
+ * 获取线程
74
+ */
75
+ async get(s) {
76
+ return (await o(`${this.serverUrl}/threads/${s}`)).data;
77
+ }
78
+ /**
79
+ * 更新线程
80
+ */
81
+ async set(s, t) {
82
+ await l(`${this.serverUrl}/threads/${s}`, t);
83
+ }
84
+ /**
85
+ * 删除线程
86
+ */
87
+ async delete(s) {
88
+ await O(`${this.serverUrl}/threads/${s}`);
89
+ }
90
+ /**
91
+ * 更新状态
92
+ */
93
+ async updateState(s, t) {
94
+ return (await r(
95
+ `${this.serverUrl}/threads/${s}/state`,
96
+ t
97
+ )).data;
98
+ }
99
+ /**
100
+ * 创建运行
101
+ */
102
+ async createRun(s, t, e) {
103
+ return (await r(`${this.serverUrl}/threads/${s}/runs`, e || {}, {
104
+ assistantId: t
105
+ })).data;
106
+ }
107
+ /**
108
+ * 列出运行
109
+ */
110
+ async listRuns(s, t) {
111
+ const e = {};
112
+ return t?.limit !== void 0 && (e.limit = t.limit), t?.offset !== void 0 && (e.offset = t.offset), t?.status !== void 0 && (e.status = t.status), (await o(`${this.serverUrl}/threads/${s}/runs`, e)).data;
113
+ }
114
+ /**
115
+ * 更新运行
116
+ */
117
+ async updateRun(s, t) {
118
+ await l(`${this.serverUrl}/runs/${s}`, t);
119
+ }
120
+ // New methods for Threads API
121
+ /**
122
+ * 计算线程数量
123
+ */
124
+ async count(s) {
125
+ const t = {};
126
+ return s?.ids !== void 0 && s.ids.length > 0 && (t.ids = JSON.stringify(s.ids)), s?.metadata !== void 0 && (t.metadata = JSON.stringify(s.metadata)), s?.status !== void 0 && (t.status = s.status), s?.values !== void 0 && (t.values = JSON.stringify(s.values)), (await o(`${this.serverUrl}/threads/count`, t)).data;
127
+ }
128
+ /**
129
+ * 更新线程元数据
130
+ */
131
+ async patch(s, t) {
132
+ return (await r(`${this.serverUrl}/threads/${s}`, t)).data;
133
+ }
134
+ /**
135
+ * 获取线程状态
136
+ */
137
+ async getState(s, t) {
138
+ const e = {};
139
+ return t?.subgraphs !== void 0 && (e.subgraphs = t.subgraphs), t?.checkpointId !== void 0 && (e.checkpointId = t.checkpointId), (await r(`${this.serverUrl}/threads/${s}/state`, e)).data;
140
+ }
141
+ /**
142
+ * 获取线程历史
143
+ */
144
+ async getStateHistory(s, t) {
145
+ const e = {};
146
+ return t?.limit !== void 0 && (e.limit = t.limit), t?.before !== void 0 && (e.before = t.before), (await r(`${this.serverUrl}/threads/${s}/history`, e)).data;
147
+ }
148
+ /**
149
+ * 复制线程
150
+ */
151
+ async copy(s) {
152
+ return (await r(`${this.serverUrl}/threads/${s}/copy`)).data;
153
+ }
154
+ }
155
+ export {
156
+ p as RemoteKyselyThreadsManager
157
+ };
@@ -1,6 +1,6 @@
1
- import { u as $ } from "./id-CxmtJIkV.mjs";
2
- import { B as g } from "./app-Dy9hkwWD.mjs";
3
- import "./graphBuilder-2Ioob7L7.mjs";
1
+ import { u as $ } from "./id-Cu7CRpDw.mjs";
2
+ import { B as g } from "./app-CRslJvxg.mjs";
3
+ import "./graphBuilder-B0bC88R_.mjs";
4
4
  import { createClient as T } from "redis";
5
5
  function k(u) {
6
6
  if (u === null || typeof u != "object") return JSON.stringify(u);
@@ -1,5 +1,5 @@
1
1
  import { F as e } from "./sql-CJsUpKEQ.mjs";
2
- class N {
2
+ class d {
3
3
  db;
4
4
  constructor(t) {
5
5
  this.db = t;
@@ -22,10 +22,14 @@ class N {
22
22
  }
23
23
  return t;
24
24
  }
25
- buildJsonQuery(t, T, a, r) {
26
- return e`json_extract(${e.ref(T)}, ${e.lit("$." + a)}) = ${e.lit(
27
- JSON.stringify(r)
28
- )}`;
25
+ buildJsonQuery(t, T, a, E) {
26
+ const r = JSON.stringify(E);
27
+ return e`(
28
+ json_extract(${e.ref(T)}, ${e.lit("$." + a)}) = ${e.lit(r)}
29
+ ) OR (
30
+ json_extract(${e.ref(T)}, ${e.lit("$." + a)}) IS NULL
31
+ AND ${e.lit(r)} IS NULL
32
+ )`;
29
33
  }
30
34
  now() {
31
35
  return (/* @__PURE__ */ new Date()).toISOString();
@@ -60,5 +64,5 @@ class N {
60
64
  }
61
65
  }
62
66
  export {
63
- N as SQLiteAdapter
67
+ d as SQLiteAdapter
64
68
  };
@@ -1,7 +1,7 @@
1
1
  import { tool as p, HumanMessage as d, SystemMessage as m } from "langchain";
2
2
  import { Command as f, Annotation as b } from "@langchain/langgraph";
3
3
  import { z as i } from "zod";
4
- import { m as w, n as y } from "./graphBuilder-2Ioob7L7.mjs";
4
+ import { m as w, n as y } from "./graphBuilder-B0bC88R_.mjs";
5
5
  import "@langchain/openai";
6
6
  const k = i.object({
7
7
  task_store: i.record(i.string(), i.any()).default({})
package/dist/zen-code.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import "./MultiLineTextInput-e7hD79Wp.mjs";
2
2
  import "chalk";
3
- import "./app-Dy9hkwWD.mjs";
3
+ import "./app-CRslJvxg.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-code",
3
- "version": "4.3.0",
3
+ "version": "4.4.1",
4
4
  "description": "",
5
5
  "main": "./dist/cli.mjs",
6
6
  "bin": "./dist/cli.mjs",
@@ -12,11 +12,13 @@
12
12
  "license": "Apache-2.0",
13
13
  "dependencies": {
14
14
  "@anthropic-ai/sdk": "^0.71.2",
15
+ "@google/generative-ai": "^0.24.1",
15
16
  "@langchain/anthropic": "1.3.10",
16
17
  "@langchain/core": "1.1.15",
18
+ "@langchain/google-genai": "^2.1.18",
17
19
  "@langchain/langgraph": "^1.1.0",
18
20
  "@langchain/openai": "1.1.3",
19
- "@langgraph-js/pure-graph": "^2.10.0",
21
+ "@langgraph-js/pure-graph": "^3.0.1",
20
22
  "chalk": "^5.6.2",
21
23
  "execa": "^9.6.1",
22
24
  "extract-zip": "^2.0.1",
@@ -38,11 +40,11 @@
38
40
  "@langgraph-js/standard-agent": "1.1.0"
39
41
  },
40
42
  "devDependencies": {
41
- "@tanstack/react-query": "^5.90.21",
42
43
  "@inkjs/ui": "^2.0.0",
43
44
  "@langchain/mcp-adapters": "^1.1.1",
44
- "@langgraph-js/sdk": "^4.4.0",
45
+ "@langgraph-js/sdk": "^4.6.1",
45
46
  "@nanostores/react": "^1.0.0",
47
+ "@tanstack/react-query": "^5.90.21",
46
48
  "@testing-library/react": "^16.3.2",
47
49
  "@testing-library/user-event": "^14.6.1",
48
50
  "@types/diff-match-patch": "^1.0.36",