zen-code 2.2.0 → 2.4.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.
@@ -1,4 +1,4 @@
1
- import { r as P, u as d, p as _ } from "./graph-DDkv1rqg.mjs";
1
+ import { r as P, u as d, p as _ } from "./graph-aTwGGPhX.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,6 +1,6 @@
1
- import { u as C } from "./id-CzaxLw8O.mjs";
2
- import { B as v, c as x, T as $, m as I } from "./app-DSomQ6O6.mjs";
3
- import "./graph-DDkv1rqg.mjs";
1
+ import { u as C } from "./id-D-r9rdKn.mjs";
2
+ import { B as v, c as x, T as $, m as I } from "./app-lHPjGHmt.mjs";
3
+ import "./graph-aTwGGPhX.mjs";
4
4
  import { createClient as O, createCluster as N } from "redis";
5
5
  const W = [
6
6
  {
@@ -0,0 +1,23 @@
1
+ import { Low as s } from "lowdb";
2
+ import { JSONFile as c } from "lowdb/node";
3
+ import d from "node:os";
4
+ import i from "node:path";
5
+ import e from "node:fs";
6
+ const n = {
7
+ config: {
8
+ main_model: "claude-sonnet-4-5",
9
+ model_provider: "openai"
10
+ }
11
+ }, f = d.homedir(), o = i.join(f, ".zen-code"), _ = i.join(o, "settings.json"), p = new c(_), a = new s(p, n), w = async () => {
12
+ await e.promises.mkdir(o, { recursive: !0 }), await a.read(), (!a.data || !a.data.config) && (a.data = n, await a.write()), t();
13
+ }, E = () => a.data.config, t = () => {
14
+ a.data.config.model_provider && (process.env.MODEL_PROVIDER = a.data.config.model_provider), a.data.config.openai_api_key && (process.env.OPENAI_API_KEY = a.data.config.openai_api_key), a.data.config.openai_base_url && (process.env.OPENAI_BASE_URL = a.data.config.openai_base_url), a.data.config.anthropic_api_key && (process.env.ANTHROPIC_API_KEY = a.data.config.anthropic_api_key), a.data.config.anthropic_base_url && (process.env.ANTHROPIC_BASE_URL = a.data.config.anthropic_base_url);
15
+ }, b = async (r) => {
16
+ await e.promises.mkdir(o, { recursive: !0 }), Object.assign(a.data.config, r), await a.write(), t();
17
+ };
18
+ export {
19
+ _ as d,
20
+ E as g,
21
+ w as i,
22
+ b as u
23
+ };
@@ -1,6 +1,6 @@
1
1
  import { HumanMessage as c } from "langchain";
2
- import { g as l } from "./graph-DDkv1rqg.mjs";
3
- import { i as m, g } from "./index-B5v_6qaq.mjs";
2
+ import { g as l } from "./graph-aTwGGPhX.mjs";
3
+ import { i as m, g } from "./index-DpsJ-2by.mjs";
4
4
  async function d() {
5
5
  return new Promise((r, t) => {
6
6
  let o = "";
@@ -1,11 +1,11 @@
1
- import { a as u, C as h } from "./app-DSomQ6O6.mjs";
2
- import { createClient as n } from "redis";
3
- class r extends u {
1
+ import { a as h, C as u } from "./app-lHPjGHmt.mjs";
2
+ import { createClient as c } from "redis";
3
+ class n extends h {
4
4
  constructor(s, e = !0, i = 300) {
5
- super(s, !0, i), this.id = s, this.compressMessages = e, this.ttl = i, this.queueKey = `queue:${this.id}`, this.channelKey = `channel:${this.id}`, this.redis = r.redis, this.subscriberRedis = r.subscriberRedis, this.cancelSignal = new AbortController(), this.redis.isOpen || this.redis.connect(), this.subscriberRedis.isOpen || this.subscriberRedis.connect(), this.isConnected = !0;
5
+ super(s, !0, i), this.id = s, this.compressMessages = e, this.ttl = i, this.queueKey = `queue:${this.id}`, this.channelKey = `channel:${this.id}`, this.redis = n.redis, this.subscriberRedis = n.subscriberRedis, this.cancelSignal = new AbortController(), this.redis.isOpen || this.redis.connect(), this.subscriberRedis.isOpen || this.subscriberRedis.connect(), this.isConnected = !0;
6
6
  }
7
- static redis = n({ url: process.env.REDIS_URL });
8
- static subscriberRedis = n({ url: process.env.REDIS_URL });
7
+ static redis = c({ url: process.env.REDIS_URL });
8
+ static subscriberRedis = c({ url: process.env.REDIS_URL });
9
9
  static isQueueExist(s) {
10
10
  return this.redis.exists(`queue:${s}`).then((e) => e > 0);
11
11
  }
@@ -27,17 +27,23 @@ class r extends u {
27
27
  */
28
28
  async *onDataReceive() {
29
29
  let s = [], e = null, i = !1;
30
- const c = async (t) => {
30
+ if (this.cancelSignal.signal.aborted)
31
+ return;
32
+ const l = async (t) => {
31
33
  const a = await this.decodeData(t);
32
34
  s.push(a), (a.event === "__stream_end__" || a.event === "__stream_error__" || a.event === "__stream_cancel__") && (setTimeout(() => {
33
35
  i = !0, e && (e(), e = null);
34
- }, 300), a.event === "__stream_cancel__" && this.cancel()), e && (e(), e = null);
36
+ }, 300), a.event === "__stream_cancel__" && await this.cancel()), e && (e(), e = null);
35
37
  };
36
38
  await this.subscriberRedis.subscribe(this.channelKey, (t) => {
37
- c(t);
39
+ l(t);
38
40
  });
41
+ const r = () => {
42
+ i = !0, e && (e(), e = null);
43
+ };
44
+ this.cancelSignal.signal.addEventListener("abort", r);
39
45
  try {
40
- for (; !i; )
46
+ for (; !i && !this.cancelSignal.signal.aborted; )
41
47
  if (s.length > 0) {
42
48
  for (const t of s)
43
49
  yield t;
@@ -47,7 +53,7 @@ class r extends u {
47
53
  e = t;
48
54
  });
49
55
  } finally {
50
- await this.subscriberRedis.unsubscribe(this.channelKey);
56
+ await this.subscriberRedis.unsubscribe(this.channelKey), this.cancelSignal.signal.removeEventListener("abort", r);
51
57
  }
52
58
  }
53
59
  /**
@@ -68,14 +74,14 @@ class r extends u {
68
74
  /**
69
75
  * 取消操作
70
76
  */
71
- cancel() {
72
- this.push(new h()), this.cancelSignal.abort("user cancel this run");
77
+ async cancel() {
78
+ this.cancelSignal.abort("user cancel this run"), await this.push(new u());
73
79
  }
74
80
  async copyToQueue(s, e) {
75
- const i = new r(s, this.compressMessages, e ?? this.ttl);
81
+ const i = new n(s, this.compressMessages, e ?? this.ttl);
76
82
  return await this.redis.copy(this.queueKey, i.queueKey), await this.redis.expire(i.queueKey, e ?? this.ttl), i;
77
83
  }
78
84
  }
79
85
  export {
80
- r as RedisStreamQueue
86
+ n as RedisStreamQueue
81
87
  };
@@ -1,6 +1,6 @@
1
- import { u as $ } from "./id-CzaxLw8O.mjs";
2
- import { B as g } from "./app-DSomQ6O6.mjs";
3
- import "./graph-DDkv1rqg.mjs";
1
+ import { u as $ } from "./id-D-r9rdKn.mjs";
2
+ import { B as g } from "./app-lHPjGHmt.mjs";
3
+ import "./graph-aTwGGPhX.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);