zidane 4.0.2 → 4.1.4

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 (77) hide show
  1. package/README.md +196 -614
  2. package/dist/agent-BoV5Twdl.d.ts +2347 -0
  3. package/dist/agent-BoV5Twdl.d.ts.map +1 -0
  4. package/dist/contexts-3Arvn7yR.js +321 -0
  5. package/dist/contexts-3Arvn7yR.js.map +1 -0
  6. package/dist/contexts.d.ts +2 -25
  7. package/dist/contexts.js +2 -10
  8. package/dist/errors-D1lhd6mX.js +118 -0
  9. package/dist/errors-D1lhd6mX.js.map +1 -0
  10. package/dist/index-28otmfLX.d.ts +400 -0
  11. package/dist/index-28otmfLX.d.ts.map +1 -0
  12. package/dist/index-BfSdALzk.d.ts +113 -0
  13. package/dist/index-BfSdALzk.d.ts.map +1 -0
  14. package/dist/index-DPsd0qwm.d.ts +254 -0
  15. package/dist/index-DPsd0qwm.d.ts.map +1 -0
  16. package/dist/index.d.ts +5 -95
  17. package/dist/index.js +141 -271
  18. package/dist/index.js.map +1 -0
  19. package/dist/interpolate-CukJwP2G.js +887 -0
  20. package/dist/interpolate-CukJwP2G.js.map +1 -0
  21. package/dist/mcp-8wClKY-3.js +771 -0
  22. package/dist/mcp-8wClKY-3.js.map +1 -0
  23. package/dist/mcp.d.ts +2 -4
  24. package/dist/mcp.js +2 -13
  25. package/dist/messages-z5Pq20p7.js +1020 -0
  26. package/dist/messages-z5Pq20p7.js.map +1 -0
  27. package/dist/presets-Cs7_CsMk.js +39 -0
  28. package/dist/presets-Cs7_CsMk.js.map +1 -0
  29. package/dist/presets.d.ts +2 -43
  30. package/dist/presets.js +2 -17
  31. package/dist/providers-CX-R-Oy-.js +969 -0
  32. package/dist/providers-CX-R-Oy-.js.map +1 -0
  33. package/dist/providers.d.ts +2 -4
  34. package/dist/providers.js +3 -23
  35. package/dist/session/sqlite.d.ts +7 -12
  36. package/dist/session/sqlite.d.ts.map +1 -0
  37. package/dist/session/sqlite.js +67 -79
  38. package/dist/session/sqlite.js.map +1 -0
  39. package/dist/session-Cn68UASv.js +440 -0
  40. package/dist/session-Cn68UASv.js.map +1 -0
  41. package/dist/session.d.ts +2 -4
  42. package/dist/session.js +3 -27
  43. package/dist/skills.d.ts +3 -322
  44. package/dist/skills.js +24 -47
  45. package/dist/skills.js.map +1 -0
  46. package/dist/stats-DoKUtF5T.js +58 -0
  47. package/dist/stats-DoKUtF5T.js.map +1 -0
  48. package/dist/tools-DpeWKzP1.js +3941 -0
  49. package/dist/tools-DpeWKzP1.js.map +1 -0
  50. package/dist/tools.d.ts +3 -95
  51. package/dist/tools.js +2 -40
  52. package/dist/tui.d.ts +533 -0
  53. package/dist/tui.d.ts.map +1 -0
  54. package/dist/tui.js +2004 -0
  55. package/dist/tui.js.map +1 -0
  56. package/dist/types-Bx_F8jet.js +39 -0
  57. package/dist/types-Bx_F8jet.js.map +1 -0
  58. package/dist/types.d.ts +4 -55
  59. package/dist/types.js +4 -28
  60. package/package.json +38 -4
  61. package/dist/agent-BAHrGtqu.d.ts +0 -2425
  62. package/dist/chunk-4ILGBQ23.js +0 -803
  63. package/dist/chunk-4LPBN547.js +0 -3540
  64. package/dist/chunk-64LLNY7F.js +0 -28
  65. package/dist/chunk-6STZTA4N.js +0 -830
  66. package/dist/chunk-7GQ7P6DM.js +0 -566
  67. package/dist/chunk-IC7FT4OD.js +0 -37
  68. package/dist/chunk-JCOB6IYO.js +0 -22
  69. package/dist/chunk-JH6IAAFA.js +0 -28
  70. package/dist/chunk-LNN5UTS2.js +0 -97
  71. package/dist/chunk-PMCQOMV4.js +0 -490
  72. package/dist/chunk-UD25QF3H.js +0 -304
  73. package/dist/chunk-W57VY6DJ.js +0 -834
  74. package/dist/sandbox-D7v6Wy62.d.ts +0 -28
  75. package/dist/skills-use-DwZrNmcw.d.ts +0 -80
  76. package/dist/types-Bai5rKpa.d.ts +0 -89
  77. package/dist/validation-Pm--dQEU.d.ts +0 -185
@@ -1,97 +0,0 @@
1
- // src/errors.ts
2
- var AgentContextExceededError = class extends Error {
3
- code = "context_exceeded";
4
- provider;
5
- providerCode;
6
- constructor(message, options) {
7
- super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
8
- this.name = "AgentContextExceededError";
9
- this.provider = options.provider;
10
- this.providerCode = options.providerCode;
11
- }
12
- };
13
- var AgentProviderError = class extends Error {
14
- code = "provider_error";
15
- provider;
16
- providerCode;
17
- /**
18
- * Whether a retry with backoff is likely to succeed. See
19
- * {@link ClassifiedError.retryable}. Absent when the provider did not
20
- * classify the error — callers should treat absent as "don't retry".
21
- */
22
- retryable;
23
- constructor(message, options) {
24
- super(message, options.cause !== void 0 ? { cause: options.cause } : void 0);
25
- this.name = "AgentProviderError";
26
- this.provider = options.provider;
27
- this.providerCode = options.providerCode;
28
- this.retryable = options.retryable;
29
- }
30
- };
31
- var AgentAbortedError = class extends Error {
32
- code = "aborted";
33
- constructor(message = "Agent run aborted", options) {
34
- super(message, options?.cause !== void 0 ? { cause: options.cause } : void 0);
35
- this.name = "AgentAbortedError";
36
- }
37
- };
38
- var AgentToolNotAllowedError = class extends Error {
39
- code = "tool_not_allowed";
40
- /** Canonical tool name the agent tried to call. */
41
- toolName;
42
- /** Aliased / wire name the LLM saw. */
43
- displayName;
44
- /** Flattened union of `allowedTools` patterns across active skills. */
45
- allowedUnion;
46
- /** Names of the skills currently active when the block fired. */
47
- activeSkills;
48
- constructor(options) {
49
- const msg = `Tool "${options.displayName}" is not in the allowed-tools union of the active skill(s) [${options.activeSkills.join(", ")}]. Union: [${options.allowedUnion.join(" ")}].`;
50
- super(msg, options.cause !== void 0 ? { cause: options.cause } : void 0);
51
- this.name = "AgentToolNotAllowedError";
52
- this.toolName = options.toolName;
53
- this.displayName = options.displayName;
54
- this.allowedUnion = options.allowedUnion;
55
- this.activeSkills = options.activeSkills;
56
- }
57
- };
58
- var CONTEXT_EXCEEDED_MESSAGE_PATTERNS = [
59
- /context[_\s]length[_\s]exceeded/i,
60
- /maximum context length/i,
61
- /prompt is too long/i,
62
- /context window/i
63
- ];
64
- function matchesContextExceeded(message) {
65
- if (typeof message !== "string" || message.length === 0)
66
- return false;
67
- return CONTEXT_EXCEEDED_MESSAGE_PATTERNS.some((re) => re.test(message));
68
- }
69
- function toTypedError(classification, provider, cause) {
70
- const message = classification.message ?? (cause instanceof Error ? cause.message : String(cause));
71
- if (classification.kind === "context_exceeded") {
72
- return new AgentContextExceededError(message, {
73
- provider,
74
- providerCode: classification.providerCode,
75
- cause
76
- });
77
- }
78
- if (classification.kind === "aborted") {
79
- return new AgentAbortedError(message, { cause });
80
- }
81
- return new AgentProviderError(message, {
82
- provider,
83
- providerCode: classification.providerCode,
84
- retryable: classification.retryable,
85
- cause
86
- });
87
- }
88
-
89
- export {
90
- AgentContextExceededError,
91
- AgentProviderError,
92
- AgentAbortedError,
93
- AgentToolNotAllowedError,
94
- CONTEXT_EXCEEDED_MESSAGE_PATTERNS,
95
- matchesContextExceeded,
96
- toTypedError
97
- };
@@ -1,490 +0,0 @@
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
-
159
- // src/session/memory.ts
160
- function createMemoryStore() {
161
- const sessions = /* @__PURE__ */ new Map();
162
- return {
163
- async load(sessionId) {
164
- const data = sessions.get(sessionId);
165
- return data ? structuredClone(data) : null;
166
- },
167
- async save(session) {
168
- sessions.set(session.id, structuredClone(session));
169
- },
170
- async delete(sessionId) {
171
- sessions.delete(sessionId);
172
- },
173
- async list(filter) {
174
- let ids = Array.from(sessions.keys());
175
- if (filter?.agentId) {
176
- ids = ids.filter((id) => sessions.get(id)?.agentId === filter.agentId);
177
- }
178
- if (filter?.limit) {
179
- ids = ids.slice(0, filter.limit);
180
- }
181
- return ids;
182
- },
183
- async appendTurns(sessionId, turns) {
184
- const data = sessions.get(sessionId);
185
- if (data) {
186
- data.turns.push(...structuredClone(turns));
187
- data.updatedAt = Date.now();
188
- }
189
- },
190
- async getTurns(sessionId, from = 0, limit) {
191
- const data = sessions.get(sessionId);
192
- if (!data)
193
- return [];
194
- const sliced = data.turns.slice(from, limit !== void 0 ? from + limit : void 0);
195
- return structuredClone(sliced);
196
- },
197
- async updateRun(sessionId, run) {
198
- const data = sessions.get(sessionId);
199
- if (data) {
200
- const idx = data.runs.findIndex((r) => r.id === run.id);
201
- if (idx >= 0) {
202
- data.runs[idx] = structuredClone(run);
203
- }
204
- data.updatedAt = Date.now();
205
- }
206
- },
207
- async updateStatus(sessionId, status) {
208
- const data = sessions.get(sessionId);
209
- if (data) {
210
- data.status = status;
211
- data.updatedAt = Date.now();
212
- }
213
- }
214
- };
215
- }
216
-
217
- // src/session/remote.ts
218
- var TRAILING_SLASH = /\/$/;
219
- function createRemoteStore(options) {
220
- const baseUrl = options.url.replace(TRAILING_SLASH, "");
221
- const defaultHeaders = {
222
- "Content-Type": "application/json",
223
- ...options.headers
224
- };
225
- async function request(path, init) {
226
- const url = `${baseUrl}${path}`;
227
- const res = await fetch(url, {
228
- ...init,
229
- headers: { ...defaultHeaders, ...init?.headers }
230
- });
231
- return res;
232
- }
233
- return {
234
- async load(sessionId) {
235
- const res = await request(`/sessions/${encodeURIComponent(sessionId)}`);
236
- if (!res.ok) {
237
- if (res.status === 404)
238
- return null;
239
- throw new Error(`Remote session load failed: ${res.status} ${res.statusText}`);
240
- }
241
- return await res.json();
242
- },
243
- async save(session) {
244
- const res = await request(`/sessions/${encodeURIComponent(session.id)}`, {
245
- method: "PUT",
246
- body: JSON.stringify(session)
247
- });
248
- if (!res.ok) {
249
- throw new Error(`Remote session save failed: ${res.status} ${res.statusText}`);
250
- }
251
- },
252
- async delete(sessionId) {
253
- const res = await request(`/sessions/${encodeURIComponent(sessionId)}`, {
254
- method: "DELETE"
255
- });
256
- if (!res.ok && res.status !== 404) {
257
- throw new Error(`Remote session delete failed: ${res.status} ${res.statusText}`);
258
- }
259
- },
260
- async list(filter) {
261
- const params = new URLSearchParams();
262
- if (filter?.agentId)
263
- params.set("agentId", filter.agentId);
264
- if (filter?.limit)
265
- params.set("limit", String(filter.limit));
266
- const query = params.toString();
267
- const path = query ? `/sessions?${query}` : "/sessions";
268
- const res = await request(path);
269
- if (!res.ok) {
270
- throw new Error(`Remote session list failed: ${res.status} ${res.statusText}`);
271
- }
272
- const body = await res.json();
273
- return body.ids;
274
- },
275
- async appendTurns(sessionId, turns) {
276
- const res = await request(`/sessions/${encodeURIComponent(sessionId)}/turns`, {
277
- method: "POST",
278
- body: JSON.stringify(turns)
279
- });
280
- if (!res.ok) {
281
- throw new Error(`Remote appendTurns failed: ${res.status} ${res.statusText}`);
282
- }
283
- },
284
- async getTurns(sessionId, from = 0, limit) {
285
- const params = new URLSearchParams();
286
- if (from)
287
- params.set("from", String(from));
288
- if (limit !== void 0)
289
- params.set("limit", String(limit));
290
- const query = params.toString();
291
- const path = `/sessions/${encodeURIComponent(sessionId)}/turns${query ? `?${query}` : ""}`;
292
- const res = await request(path);
293
- if (!res.ok) {
294
- throw new Error(`Remote getTurns failed: ${res.status} ${res.statusText}`);
295
- }
296
- return await res.json();
297
- },
298
- async updateRun(sessionId, run) {
299
- const res = await request(
300
- `/sessions/${encodeURIComponent(sessionId)}/runs/${encodeURIComponent(run.id)}`,
301
- {
302
- method: "PUT",
303
- body: JSON.stringify(run)
304
- }
305
- );
306
- if (!res.ok) {
307
- throw new Error(`Remote updateRun failed: ${res.status} ${res.statusText}`);
308
- }
309
- },
310
- async updateStatus(sessionId, status) {
311
- const res = await request(`/sessions/${encodeURIComponent(sessionId)}`, {
312
- method: "PATCH",
313
- body: JSON.stringify({ status })
314
- });
315
- if (!res.ok) {
316
- throw new Error(`Remote updateStatus failed: ${res.status} ${res.statusText}`);
317
- }
318
- }
319
- };
320
- }
321
-
322
- // src/session/index.ts
323
- async function createSession(options = {}) {
324
- const store = options.store;
325
- const now = Date.now();
326
- let sessionId = options.id;
327
- if (!sessionId && store?.generateSessionId) {
328
- sessionId = await store.generateSessionId();
329
- }
330
- if (!sessionId) {
331
- sessionId = generateId();
332
- }
333
- const data = options._data ?? {
334
- id: sessionId,
335
- agentId: options.agentId,
336
- turns: [],
337
- runs: [],
338
- status: "idle",
339
- metadata: options.metadata ?? {},
340
- createdAt: now,
341
- updatedAt: now
342
- };
343
- function touch() {
344
- data.updatedAt = Date.now();
345
- }
346
- function findRun(runId) {
347
- return data.runs.find((r) => r.id === runId);
348
- }
349
- const session = {
350
- get id() {
351
- return data.id;
352
- },
353
- get agentId() {
354
- return data.agentId;
355
- },
356
- get turns() {
357
- return data.turns;
358
- },
359
- get isEmpty() {
360
- return data.turns.length === 0;
361
- },
362
- get status() {
363
- return data.status;
364
- },
365
- get runs() {
366
- return data.runs;
367
- },
368
- get metadata() {
369
- return data.metadata;
370
- },
371
- startRun(runId, prompt, extras) {
372
- data.runs.push({
373
- id: runId,
374
- startedAt: Date.now(),
375
- prompt: prompt ?? "",
376
- status: "running",
377
- ...extras?.parentRunId ? { parentRunId: extras.parentRunId } : {},
378
- ...typeof extras?.depth === "number" ? { depth: extras.depth } : {}
379
- });
380
- touch();
381
- },
382
- completeRun(runId, stats) {
383
- const run = findRun(runId);
384
- if (run) {
385
- run.status = "completed";
386
- run.endedAt = Date.now();
387
- run.turns = stats.turns;
388
- run.tokensIn = stats.tokensIn;
389
- run.tokensOut = stats.tokensOut;
390
- if (stats.turnUsage) {
391
- run.turnUsage = stats.turnUsage;
392
- const total = stats.turnUsage.reduce((acc, t) => ({
393
- input: acc.input + t.input,
394
- output: acc.output + t.output,
395
- cacheCreation: (acc.cacheCreation ?? 0) + (t.cacheCreation ?? 0),
396
- cacheRead: (acc.cacheRead ?? 0) + (t.cacheRead ?? 0),
397
- thinking: (acc.thinking ?? 0) + (t.thinking ?? 0)
398
- }), { input: 0, output: 0, cacheCreation: 0, cacheRead: 0, thinking: 0 });
399
- run.totalUsage = {
400
- input: total.input,
401
- output: total.output,
402
- ...total.cacheCreation ? { cacheCreation: total.cacheCreation } : {},
403
- ...total.cacheRead ? { cacheRead: total.cacheRead } : {},
404
- ...total.thinking ? { thinking: total.thinking } : {}
405
- };
406
- }
407
- if (stats.cost !== void 0)
408
- run.cost = stats.cost;
409
- }
410
- touch();
411
- },
412
- abortRun(runId) {
413
- const run = findRun(runId);
414
- if (run) {
415
- run.status = "aborted";
416
- run.endedAt = Date.now();
417
- }
418
- touch();
419
- },
420
- errorRun(runId, error) {
421
- const run = findRun(runId);
422
- if (run) {
423
- run.status = "error";
424
- run.endedAt = Date.now();
425
- run.error = error;
426
- }
427
- touch();
428
- },
429
- async appendTurns(turns) {
430
- data.turns.push(...turns);
431
- touch();
432
- if (store) {
433
- await store.appendTurns(data.id, turns);
434
- }
435
- },
436
- setTurns(turns) {
437
- data.turns = turns;
438
- touch();
439
- },
440
- async updateStatus(status) {
441
- data.status = status;
442
- touch();
443
- if (store) {
444
- await store.updateStatus(data.id, status);
445
- }
446
- },
447
- async updateRun(run) {
448
- if (store) {
449
- await store.updateRun(data.id, run);
450
- }
451
- },
452
- generateTurnId() {
453
- if (store?.generateTurnId) {
454
- return store.generateTurnId();
455
- }
456
- return crypto.randomUUID();
457
- },
458
- setMeta(key, value) {
459
- data.metadata[key] = value;
460
- touch();
461
- },
462
- async save() {
463
- if (!store) {
464
- throw new Error("No SessionStore configured. Pass a store to createSession() to enable persistence.");
465
- }
466
- await store.save(data);
467
- },
468
- toJSON() {
469
- return structuredClone(data);
470
- }
471
- };
472
- return session;
473
- }
474
- async function loadSession(store, sessionId) {
475
- const loaded = await store.load(sessionId);
476
- if (!loaded)
477
- return null;
478
- return createSession({ store, _data: loaded });
479
- }
480
- function generateId() {
481
- return `ses_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
482
- }
483
-
484
- export {
485
- createFileMapStore,
486
- createMemoryStore,
487
- createRemoteStore,
488
- createSession,
489
- loadSession
490
- };