zen-code 4.6.0 → 4.6.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 (33) hide show
  1. package/dist/MultiLineTextInput-B4NEXnFm.mjs +23343 -0
  2. package/dist/devtools-BHqoL8a6.mjs +11653 -0
  3. package/dist/graphBuilder-B3IJ7dB2.mjs +2641 -0
  4. package/dist/{index-B6kFMamn.mjs → index-DEcMgCTj.mjs} +1 -1
  5. package/dist/{memories-DirsFRdm.mjs → memories-rSGKIPk5.mjs} +1 -1
  6. package/dist/nonInteractive.mjs +7 -6
  7. package/dist/{subTasks-Bt97OwvY.mjs → subTasks-5KLIr9iy.mjs} +2 -2
  8. package/dist/zen-code.mjs +8654 -2
  9. package/dist/zen-keyboard.mjs +7 -6
  10. package/package.json +7 -9
  11. package/dist/MultiLineTextInput-e7hD79Wp.mjs +0 -24631
  12. package/dist/app-CM8R0ZR6.mjs +0 -16249
  13. package/dist/assets/worker-I4QjJYba.js +0 -1
  14. package/dist/checkpoint-1sAx_j1E-DrVPlSLR.mjs +0 -319
  15. package/dist/checkpoint-DxiUsHMy-Cjy5WGNC.mjs +0 -394
  16. package/dist/chunk-YWE62C55-DID9N9eS.mjs +0 -193
  17. package/dist/devtools-CzaVuYnh.mjs +0 -2667
  18. package/dist/graphBuilder-mpLrx9tk.mjs +0 -49189
  19. package/dist/index-BUGHAUbY.mjs +0 -117
  20. package/dist/index-C5j-48Ft.mjs +0 -75
  21. package/dist/index-ChCbbHFS.mjs +0 -463
  22. package/dist/index-DS5HVciX.mjs +0 -216
  23. package/dist/index-FHDPQ2Qk.mjs +0 -211
  24. package/dist/kysely-Bchvsze0.mjs +0 -4316
  25. package/dist/load-Cjl9cJ0o.mjs +0 -105
  26. package/dist/migrator-BatO36Tk.mjs +0 -592
  27. package/dist/pg-adapter-BFtir1GE-BU2H39HC.mjs +0 -62
  28. package/dist/postgres-dialect-DaHvQ_AZ.mjs +0 -211
  29. package/dist/queue-Cu_nO_wt-ChzSaooi.mjs +0 -106
  30. package/dist/remote-threads-CrG03ZS7-C9duTCnB.mjs +0 -157
  31. package/dist/shallow-tfhh5rlz.mjs +0 -331
  32. package/dist/sql-CJsUpKEQ.mjs +0 -8106
  33. package/dist/sqlite-adapter-BKOLSdoL-BlGKN04G.mjs +0 -71
@@ -1,211 +0,0 @@
1
- import { aS as p, ah as h, F as r, bb as l, bi as d, bc as y, bj as w, c } from "./sql-CJsUpKEQ.mjs";
2
- import { D as g, b as _, c as f, a as b, C as o } from "./migrator-BatO36Tk.mjs";
3
- function i(n, e) {
4
- return p.createWithChildren([
5
- p.createWithSql(`${n} `),
6
- h.create(e)
7
- // ensures savepointName gets sanitized
8
- ]);
9
- }
10
- const T = /"/g;
11
- class E extends g {
12
- sanitizeIdentifier(e) {
13
- return e.replace(T, '""');
14
- }
15
- }
16
- class C {
17
- #e;
18
- constructor(e) {
19
- this.#e = e;
20
- }
21
- async getSchemas() {
22
- return (await this.#e.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map((a) => ({ name: a.nspname }));
23
- }
24
- async getTables(e = { withInternalKyselyTables: !1 }) {
25
- let a = this.#e.selectFrom("pg_catalog.pg_attribute as a").innerJoin("pg_catalog.pg_class as c", "a.attrelid", "c.oid").innerJoin("pg_catalog.pg_namespace as ns", "c.relnamespace", "ns.oid").innerJoin("pg_catalog.pg_type as typ", "a.atttypid", "typ.oid").innerJoin("pg_catalog.pg_namespace as dtns", "typ.typnamespace", "dtns.oid").select([
26
- "a.attname as column",
27
- "a.attnotnull as not_null",
28
- "a.atthasdef as has_default",
29
- "c.relname as table",
30
- "c.relkind as table_type",
31
- "ns.nspname as schema",
32
- "typ.typname as type",
33
- "dtns.nspname as type_schema",
34
- r`col_description(a.attrelid, a.attnum)`.as("column_description"),
35
- r`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as("auto_incrementing")
36
- ]).where("c.relkind", "in", [
37
- "r",
38
- "v",
39
- "p"
40
- ]).where("ns.nspname", "!~", "^pg_").where("ns.nspname", "!=", "information_schema").where("ns.nspname", "!=", "crdb_internal").where(r`has_schema_privilege(ns.nspname, 'USAGE')`).where("a.attnum", ">=", 0).where("a.attisdropped", "!=", !0).orderBy("ns.nspname").orderBy("c.relname").orderBy("a.attnum").$castTo();
41
- e.withInternalKyselyTables || (a = a.where("c.relname", "!=", _).where("c.relname", "!=", f));
42
- const t = await a.execute();
43
- return this.#a(t);
44
- }
45
- async getMetadata(e) {
46
- return {
47
- tables: await this.getTables(e)
48
- };
49
- }
50
- #a(e) {
51
- return e.reduce((a, t) => {
52
- let s = a.find((u) => u.name === t.table && u.schema === t.schema);
53
- return s || (s = l({
54
- name: t.table,
55
- isView: t.table_type === "v",
56
- schema: t.schema,
57
- columns: []
58
- }), a.push(s)), s.columns.push(l({
59
- name: t.column,
60
- dataType: t.type,
61
- dataTypeSchema: t.type_schema,
62
- isNullable: !t.not_null,
63
- isAutoIncrementing: t.auto_incrementing !== null,
64
- hasDefaultValue: t.has_default,
65
- comment: t.column_description ?? void 0
66
- })), a;
67
- }, []);
68
- }
69
- }
70
- const I = BigInt("3853314791062309107");
71
- class k extends b {
72
- get supportsTransactionalDdl() {
73
- return !0;
74
- }
75
- get supportsReturning() {
76
- return !0;
77
- }
78
- async acquireMigrationLock(e, a) {
79
- await r`select pg_advisory_xact_lock(${r.lit(I)})`.execute(e);
80
- }
81
- async releaseMigrationLock(e, a) {
82
- }
83
- }
84
- function v(n, e) {
85
- if (x(n) && e.stack) {
86
- const a = e.stack.split(`
87
- `).slice(1).join(`
88
- `);
89
- return n.stack += `
90
- ${a}`, n;
91
- }
92
- return n;
93
- }
94
- function x(n) {
95
- return d(n) && y(n.stack);
96
- }
97
- const m = /* @__PURE__ */ Symbol();
98
- class A {
99
- #e;
100
- #a = /* @__PURE__ */ new WeakMap();
101
- #t;
102
- constructor(e) {
103
- this.#e = l({ ...e });
104
- }
105
- async init() {
106
- this.#t = w(this.#e.pool) ? await this.#e.pool() : this.#e.pool;
107
- }
108
- async acquireConnection() {
109
- const e = await this.#t.connect();
110
- let a = this.#a.get(e);
111
- return a || (a = new D(e, {
112
- cursor: this.#e.cursor ?? null
113
- }), this.#a.set(e, a), this.#e.onCreateConnection && await this.#e.onCreateConnection(a)), this.#e.onReserveConnection && await this.#e.onReserveConnection(a), a;
114
- }
115
- async beginTransaction(e, a) {
116
- if (a.isolationLevel || a.accessMode) {
117
- let t = "start transaction";
118
- a.isolationLevel && (t += ` isolation level ${a.isolationLevel}`), a.accessMode && (t += ` ${a.accessMode}`), await e.executeQuery(o.raw(t));
119
- } else
120
- await e.executeQuery(o.raw("begin"));
121
- }
122
- async commitTransaction(e) {
123
- await e.executeQuery(o.raw("commit"));
124
- }
125
- async rollbackTransaction(e) {
126
- await e.executeQuery(o.raw("rollback"));
127
- }
128
- async savepoint(e, a, t) {
129
- await e.executeQuery(t(i("savepoint", a), c()));
130
- }
131
- async rollbackToSavepoint(e, a, t) {
132
- await e.executeQuery(t(i("rollback to", a), c()));
133
- }
134
- async releaseSavepoint(e, a, t) {
135
- await e.executeQuery(t(i("release", a), c()));
136
- }
137
- async releaseConnection(e) {
138
- e[m]();
139
- }
140
- async destroy() {
141
- if (this.#t) {
142
- const e = this.#t;
143
- this.#t = void 0, await e.end();
144
- }
145
- }
146
- }
147
- class D {
148
- #e;
149
- #a;
150
- constructor(e, a) {
151
- this.#e = e, this.#a = a;
152
- }
153
- async executeQuery(e) {
154
- try {
155
- const { command: a, rowCount: t, rows: s } = await this.#e.query(e.sql, [...e.parameters]);
156
- return {
157
- numAffectedRows: a === "INSERT" || a === "UPDATE" || a === "DELETE" || a === "MERGE" ? BigInt(t) : void 0,
158
- rows: s ?? []
159
- };
160
- } catch (a) {
161
- throw v(a, new Error());
162
- }
163
- }
164
- async *streamQuery(e, a) {
165
- if (!this.#a.cursor)
166
- throw new Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");
167
- if (!Number.isInteger(a) || a <= 0)
168
- throw new Error("chunkSize must be a positive integer");
169
- const t = this.#e.query(new this.#a.cursor(e.sql, e.parameters.slice()));
170
- try {
171
- for (; ; ) {
172
- const s = await t.read(a);
173
- if (s.length === 0)
174
- break;
175
- yield {
176
- rows: s
177
- };
178
- }
179
- } finally {
180
- await t.close();
181
- }
182
- }
183
- [m]() {
184
- this.#e.release();
185
- }
186
- }
187
- class L {
188
- #e;
189
- constructor(e) {
190
- this.#e = e;
191
- }
192
- createDriver() {
193
- return new A(this.#e);
194
- }
195
- createQueryCompiler() {
196
- return new E();
197
- }
198
- createAdapter() {
199
- return new k();
200
- }
201
- createIntrospector(e) {
202
- return new C(e);
203
- }
204
- }
205
- export {
206
- E as P,
207
- C as a,
208
- k as b,
209
- A as c,
210
- L as d
211
- };
@@ -1,106 +0,0 @@
1
- import { a as h, C as d } from "./app-CM8R0ZR6.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
- };
@@ -1,157 +0,0 @@
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
- };