zidane 1.7.0 → 1.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.
@@ -1,3 +1,161 @@
1
+ // src/session/file-map.ts
2
+ function toMeta(data) {
3
+ return {
4
+ id: data.id,
5
+ agentId: data.agentId,
6
+ runs: data.runs,
7
+ status: data.status,
8
+ metadata: data.metadata,
9
+ createdAt: data.createdAt,
10
+ updatedAt: data.updatedAt
11
+ };
12
+ }
13
+ function toData(meta, turns) {
14
+ return {
15
+ id: meta.id,
16
+ agentId: meta.agentId,
17
+ turns,
18
+ runs: meta.runs,
19
+ status: meta.status,
20
+ metadata: meta.metadata,
21
+ createdAt: meta.createdAt,
22
+ updatedAt: meta.updatedAt
23
+ };
24
+ }
25
+ function parseTurnsJsonl(jsonl) {
26
+ if (!jsonl)
27
+ return [];
28
+ const turns = [];
29
+ for (const line of jsonl.split("\n")) {
30
+ const trimmed = line.trim();
31
+ if (!trimmed)
32
+ continue;
33
+ try {
34
+ turns.push(JSON.parse(trimmed));
35
+ } catch {
36
+ }
37
+ }
38
+ return turns;
39
+ }
40
+ function serializeTurnsJsonl(turns) {
41
+ if (turns.length === 0)
42
+ return "";
43
+ return `${turns.map((t) => JSON.stringify(t)).join("\n")}
44
+ `;
45
+ }
46
+ function createFileMapStore(adapter, options = {}) {
47
+ const turnsFile = options.turnsFile ?? "turns.jsonl";
48
+ const metaFile = options.metaFile ?? "meta.json";
49
+ let cached = null;
50
+ let hydrated = false;
51
+ async function hydrate() {
52
+ if (hydrated)
53
+ return;
54
+ const { files } = await adapter.get();
55
+ const metaRaw = files[metaFile];
56
+ if (metaRaw) {
57
+ let meta = null;
58
+ try {
59
+ meta = JSON.parse(metaRaw);
60
+ } catch {
61
+ meta = null;
62
+ }
63
+ if (meta) {
64
+ cached = toData(meta, parseTurnsJsonl(files[turnsFile] ?? ""));
65
+ }
66
+ }
67
+ hydrated = true;
68
+ }
69
+ async function persist(data) {
70
+ const meta = toMeta(data);
71
+ await adapter.save({
72
+ [metaFile]: JSON.stringify(meta, null, 2),
73
+ [turnsFile]: serializeTurnsJsonl(data.turns)
74
+ });
75
+ }
76
+ async function ensureCachedFor(sessionId) {
77
+ await hydrate();
78
+ if (cached) {
79
+ return cached.id === sessionId;
80
+ }
81
+ const now = Date.now();
82
+ cached = {
83
+ id: sessionId,
84
+ turns: [],
85
+ runs: [],
86
+ status: "idle",
87
+ metadata: {},
88
+ createdAt: now,
89
+ updatedAt: now
90
+ };
91
+ hydrated = true;
92
+ return true;
93
+ }
94
+ return {
95
+ async load(sessionId) {
96
+ await hydrate();
97
+ if (!cached || cached.id !== sessionId)
98
+ return null;
99
+ return structuredClone(cached);
100
+ },
101
+ async save(data) {
102
+ cached = structuredClone(data);
103
+ hydrated = true;
104
+ await persist(cached);
105
+ },
106
+ async delete(sessionId) {
107
+ await hydrate();
108
+ if (cached && cached.id !== sessionId)
109
+ return;
110
+ cached = null;
111
+ await adapter.delete();
112
+ },
113
+ async list(filter) {
114
+ await hydrate();
115
+ if (!cached)
116
+ return [];
117
+ if (filter?.agentId && cached.agentId !== filter.agentId)
118
+ return [];
119
+ return [cached.id];
120
+ },
121
+ async appendTurns(sessionId, turns) {
122
+ const ok = await ensureCachedFor(sessionId);
123
+ if (!ok)
124
+ return;
125
+ cached.turns.push(...structuredClone(turns));
126
+ cached.updatedAt = Date.now();
127
+ await persist(cached);
128
+ },
129
+ async getTurns(sessionId, from = 0, limit) {
130
+ await hydrate();
131
+ if (!cached || cached.id !== sessionId)
132
+ return [];
133
+ const slice = cached.turns.slice(from, limit !== void 0 ? from + limit : void 0);
134
+ return structuredClone(slice);
135
+ },
136
+ async updateRun(sessionId, run) {
137
+ const ok = await ensureCachedFor(sessionId);
138
+ if (!ok)
139
+ return;
140
+ const idx = cached.runs.findIndex((r) => r.id === run.id);
141
+ if (idx >= 0)
142
+ cached.runs[idx] = structuredClone(run);
143
+ else
144
+ cached.runs.push(structuredClone(run));
145
+ cached.updatedAt = Date.now();
146
+ await persist(cached);
147
+ },
148
+ async updateStatus(sessionId, status) {
149
+ const ok = await ensureCachedFor(sessionId);
150
+ if (!ok)
151
+ return;
152
+ cached.status = status;
153
+ cached.updatedAt = Date.now();
154
+ await persist(cached);
155
+ }
156
+ };
157
+ }
158
+
1
159
  // src/session/memory.ts
2
160
  function createMemoryStore() {
3
161
  const sessions = /* @__PURE__ */ new Map();
@@ -294,6 +452,9 @@ async function createSession(options = {}) {
294
452
  get turns() {
295
453
  return data.turns;
296
454
  },
455
+ get isEmpty() {
456
+ return data.turns.length === 0;
457
+ },
297
458
  get status() {
298
459
  return data.status;
299
460
  },
@@ -415,6 +576,7 @@ function generateId() {
415
576
  }
416
577
 
417
578
  export {
579
+ createFileMapStore,
418
580
  createMemoryStore,
419
581
  createRemoteStore,
420
582
  createSqliteStore,
@@ -4,7 +4,7 @@ import {
4
4
  shell,
5
5
  spawn,
6
6
  writeFile
7
- } from "./chunk-O4QCBJQF.js";
7
+ } from "./chunk-4N5ADW7A.js";
8
8
 
9
9
  // src/harnesses/basic.ts
10
10
  var basicTools = { shell, readFile, writeFile, listFiles };