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,566 +0,0 @@
1
- import {
2
- toolOutputByteLength
3
- } from "./chunk-JH6IAAFA.js";
4
-
5
- // src/mcp/index.ts
6
- import { Buffer } from "buffer";
7
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
8
- import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
9
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
10
-
11
- // src/mcp/sse-to-json-fetch.ts
12
- function isBunRuntime() {
13
- return typeof globalThis.Bun !== "undefined";
14
- }
15
- function sseToJsonFetchIfNeeded() {
16
- return isBunRuntime() ? sseToJsonFetch() : void 0;
17
- }
18
- function sseToJsonFetch(baseFetch = fetch) {
19
- return async function sseToJsonWrappedFetch(input, init) {
20
- const response = await baseFetch(input, init);
21
- const method = (init?.method ?? "GET").toString().toUpperCase();
22
- if (method !== "POST")
23
- return response;
24
- const contentType = response.headers.get("content-type");
25
- if (!contentType || !contentType.includes("text/event-stream"))
26
- return response;
27
- if (!response.body)
28
- return response;
29
- let raw;
30
- try {
31
- raw = await response.text();
32
- } catch {
33
- return response;
34
- }
35
- const events = parseSseDataEvents(raw);
36
- const payload = events.length === 1 ? events[0] : events;
37
- return synthesizeJsonResponse(response, payload);
38
- };
39
- }
40
- function parseSseDataEvents(raw) {
41
- const events = [];
42
- for (const block of raw.split(/\r?\n\r?\n/)) {
43
- if (!block.trim())
44
- continue;
45
- const dataLines = [];
46
- let isMessageEvent = true;
47
- for (const line of block.split(/\r?\n/)) {
48
- if (line.startsWith(":"))
49
- continue;
50
- if (line.startsWith("event:")) {
51
- const eventType = line.slice("event:".length).trim();
52
- if (eventType && eventType !== "message")
53
- isMessageEvent = false;
54
- } else if (line.startsWith("data:")) {
55
- const value = line.slice("data:".length);
56
- dataLines.push(value.startsWith(" ") ? value.slice(1) : value);
57
- }
58
- }
59
- if (!isMessageEvent || dataLines.length === 0)
60
- continue;
61
- try {
62
- events.push(JSON.parse(dataLines.join("\n")));
63
- } catch {
64
- }
65
- }
66
- return events;
67
- }
68
- function synthesizeJsonResponse(original, payload) {
69
- const headers = new Headers(original.headers);
70
- headers.set("content-type", "application/json");
71
- return new Response(JSON.stringify(payload), {
72
- status: original.status,
73
- statusText: original.statusText,
74
- headers
75
- });
76
- }
77
-
78
- // src/mcp/tolerant-client.ts
79
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
80
- import { Protocol } from "@modelcontextprotocol/sdk/shared/protocol.js";
81
- import {
82
- InitializeResultSchema,
83
- LATEST_PROTOCOL_VERSION,
84
- SUPPORTED_PROTOCOL_VERSIONS
85
- } from "@modelcontextprotocol/sdk/types.js";
86
- var TolerantMcpClient = class extends Client {
87
- async connect(transport, options) {
88
- await Protocol.prototype.connect.call(this, transport);
89
- if (transport.sessionId !== void 0)
90
- return;
91
- const self = this;
92
- try {
93
- const result = await this.request(
94
- {
95
- method: "initialize",
96
- params: {
97
- protocolVersion: LATEST_PROTOCOL_VERSION,
98
- capabilities: self._capabilities,
99
- clientInfo: self._clientInfo
100
- }
101
- },
102
- InitializeResultSchema,
103
- options
104
- );
105
- if (result === void 0)
106
- throw new Error(`Server sent invalid initialize result: ${result}`);
107
- if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion))
108
- throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`);
109
- self._serverCapabilities = result.capabilities;
110
- self._serverVersion = result.serverInfo;
111
- const setProtocolVersion = transport.setProtocolVersion;
112
- if (setProtocolVersion)
113
- setProtocolVersion.call(transport, result.protocolVersion);
114
- self._instructions = result.instructions;
115
- try {
116
- await this.notification({ method: "notifications/initialized" });
117
- } catch (notifyError) {
118
- const msg = notifyError instanceof Error ? notifyError.message : String(notifyError);
119
- console.warn(`[zidane:mcp] server rejected notifications/initialized (continuing): ${msg}`);
120
- }
121
- if (self._pendingListChangedConfig) {
122
- self._setupListChangedHandlers(self._pendingListChangedConfig);
123
- self._pendingListChangedConfig = void 0;
124
- }
125
- } catch (error) {
126
- void this.close();
127
- throw error;
128
- }
129
- }
130
- };
131
-
132
- // src/mcp/index.ts
133
- var DEFAULT_MCP_BOOTSTRAP_TIMEOUT_MS = 1e4;
134
- function inferTransport(raw) {
135
- if (raw.transport === "stdio" || raw.transport === "sse" || raw.transport === "streamable-http")
136
- return raw.transport;
137
- if (raw.type === "stdio" || raw.type === "sse" || raw.type === "streamable-http" || raw.type === "http")
138
- return raw.type === "http" ? "streamable-http" : raw.type;
139
- if (raw.command)
140
- return "stdio";
141
- if (raw.httpUrl)
142
- return "streamable-http";
143
- if (raw.sseUrl)
144
- return "sse";
145
- if (raw.url)
146
- return "streamable-http";
147
- throw new Error(`Cannot infer MCP transport from config: ${JSON.stringify(raw)}`);
148
- }
149
- function normalizeOne(name, raw) {
150
- const transport = inferTransport(raw);
151
- const url = raw.url ?? raw.httpUrl ?? raw.sseUrl;
152
- const config = { name, transport };
153
- if (raw.command)
154
- config.command = raw.command;
155
- if (raw.args)
156
- config.args = raw.args;
157
- if (raw.env)
158
- config.env = raw.env;
159
- if (raw.strictEnv === true)
160
- config.strictEnv = true;
161
- if (url)
162
- config.url = url;
163
- if (raw.headers)
164
- config.headers = raw.headers;
165
- if (typeof raw.bootstrapTimeout === "number")
166
- config.bootstrapTimeout = raw.bootstrapTimeout;
167
- if (typeof raw.toolTimeout === "number")
168
- config.toolTimeout = raw.toolTimeout;
169
- if (Array.isArray(raw.enabledTools))
170
- config.enabledTools = raw.enabledTools;
171
- if (Array.isArray(raw.disabledTools))
172
- config.disabledTools = raw.disabledTools;
173
- if (typeof raw.toolFilter === "function")
174
- config.toolFilter = raw.toolFilter;
175
- return config;
176
- }
177
- function looksLikeSingleConfig(obj) {
178
- const singleConfigKeys = ["transport", "type", "command", "url", "httpUrl", "sseUrl"];
179
- return singleConfigKeys.some((key) => typeof obj[key] === "string");
180
- }
181
- function normalizeMcpServers(input) {
182
- if (input == null)
183
- return [];
184
- if (Array.isArray(input)) {
185
- return input.map((raw, idx) => {
186
- const obj = raw;
187
- const name = obj.name ?? `mcp_${idx}`;
188
- return normalizeOne(name, obj);
189
- });
190
- }
191
- if (typeof input === "object") {
192
- const obj = input;
193
- if (looksLikeSingleConfig(obj)) {
194
- const raw = obj;
195
- const name = raw.name ?? "mcp_0";
196
- return [normalizeOne(name, raw)];
197
- }
198
- return Object.entries(obj).map(
199
- ([name, raw]) => normalizeOne(name, raw ?? {})
200
- );
201
- }
202
- throw new Error(`Unsupported MCP server config shape: ${typeof input}`);
203
- }
204
- function resultToString(content) {
205
- if (!content || !Array.isArray(content))
206
- return "";
207
- return content.map((block) => {
208
- if (block && typeof block === "object" && block.type === "text") {
209
- const text = block.text;
210
- if (typeof text === "string")
211
- return text;
212
- }
213
- return JSON.stringify(block);
214
- }).join("\n");
215
- }
216
- function normalizeMcpBlocks(content) {
217
- if (!Array.isArray(content))
218
- return null;
219
- const out = [];
220
- for (const raw of content) {
221
- if (!raw || typeof raw !== "object")
222
- continue;
223
- const block = raw;
224
- if (block.type === "text" && typeof block.text === "string") {
225
- out.push({ type: "text", text: block.text });
226
- continue;
227
- }
228
- if (block.type === "image" && typeof block.data === "string") {
229
- const mediaType = typeof block.mimeType === "string" ? block.mimeType : typeof block.mediaType === "string" ? block.mediaType : "image/png";
230
- out.push({ type: "image", mediaType, data: block.data });
231
- continue;
232
- }
233
- if (block.type === "resource" && block.resource && typeof block.resource === "object") {
234
- const res = block.resource;
235
- if (typeof res.text === "string") {
236
- out.push({ type: "text", text: res.text });
237
- continue;
238
- }
239
- if (typeof res.blob === "string" && typeof res.mimeType === "string" && res.mimeType.startsWith("image/")) {
240
- out.push({ type: "image", mediaType: res.mimeType, data: res.blob });
241
- continue;
242
- }
243
- }
244
- out.push({ type: "text", text: JSON.stringify(block) });
245
- }
246
- return out;
247
- }
248
- function packMcpResult(content) {
249
- const normalized = normalizeMcpBlocks(content);
250
- if (!normalized || normalized.length === 0)
251
- return "";
252
- const parts = [];
253
- for (const block of normalized) {
254
- if (block.type !== "text")
255
- return normalized;
256
- parts.push(block.text);
257
- }
258
- return parts.join("\n");
259
- }
260
- function createTransport(config) {
261
- switch (config.transport) {
262
- case "stdio": {
263
- const mergedEnv = config.env && !config.strictEnv ? { ...getDefaultEnvironment(), ...config.env } : config.env;
264
- return new StdioClientTransport({
265
- command: config.command,
266
- args: config.args,
267
- env: mergedEnv
268
- });
269
- }
270
- case "sse":
271
- return new SSEClientTransport(new URL(config.url), {
272
- requestInit: config.headers ? { headers: config.headers } : void 0
273
- });
274
- case "streamable-http":
275
- return new StreamableHTTPClientTransport(new URL(config.url), {
276
- requestInit: config.headers ? { headers: config.headers } : void 0,
277
- fetch: sseToJsonFetchIfNeeded()
278
- });
279
- default:
280
- throw new Error(`Unknown MCP transport: ${config.transport}`);
281
- }
282
- }
283
- async function connectMcpServers(configs, _clientFactory, hooks) {
284
- const connections = [];
285
- const tools = {};
286
- const errors = [];
287
- let closed = false;
288
- const bootstrapResults = await Promise.all(configs.map((config) => bootstrapServer(config, _clientFactory, hooks)));
289
- for (const result of bootstrapResults) {
290
- if (!result.ok) {
291
- errors.push({ name: result.name, error: result.error });
292
- await hooks?.callHook("mcp:error", { name: result.name, error: result.error });
293
- continue;
294
- }
295
- connections.push({ name: result.name, client: result.client });
296
- const toolNames = [];
297
- for (const tool of result.tools) {
298
- const namespacedName = `mcp_${result.config.name}_${tool.name}`;
299
- toolNames.push(namespacedName);
300
- tools[namespacedName] = buildMcpToolDef(result.config, result.client, tool, namespacedName, hooks);
301
- }
302
- await hooks?.callHook("mcp:connect", {
303
- name: result.name,
304
- transport: result.config.transport,
305
- tools: toolNames
306
- });
307
- }
308
- if (errors.length > 0 && connections.length === 0) {
309
- const messages = errors.map((e) => `${e.name}: ${e.error.message}`).join(", ");
310
- throw new Error(`All MCP servers failed to connect: ${messages}`);
311
- }
312
- return {
313
- tools,
314
- close: async () => {
315
- if (closed)
316
- return;
317
- closed = true;
318
- await Promise.allSettled(
319
- connections.map(async ({ name, client }) => {
320
- await hooks?.callHook("mcp:close", { name });
321
- await client.close();
322
- })
323
- );
324
- }
325
- };
326
- }
327
- async function bootstrapServer(config, _clientFactory, hooks) {
328
- const start = Date.now();
329
- if (config.enabledTools && config.disabledTools) {
330
- const error = new Error(
331
- `MCP server "${config.name}": enabledTools and disabledTools are mutually exclusive \u2014 set one or the other, not both.`
332
- );
333
- await hooks?.callHook("mcp:bootstrap:start", { name: config.name, transport: config.transport });
334
- await hooks?.callHook("mcp:bootstrap:end", {
335
- name: config.name,
336
- transport: config.transport,
337
- durationMs: 0,
338
- ok: false,
339
- error
340
- });
341
- return { ok: false, name: config.name, error };
342
- }
343
- await hooks?.callHook("mcp:bootstrap:start", { name: config.name, transport: config.transport });
344
- let client = null;
345
- try {
346
- client = _clientFactory ? _clientFactory() : new TolerantMcpClient({ name: "zidane", version: "1.0.0" });
347
- const currentClient = client;
348
- const transport = createTransport(config);
349
- const bootstrapTimeout = config.bootstrapTimeout ?? DEFAULT_MCP_BOOTSTRAP_TIMEOUT_MS;
350
- const { tools: mcpTools } = await raceWithTimeout(
351
- async () => {
352
- await currentClient.connect(transport);
353
- return await currentClient.listTools();
354
- },
355
- bootstrapTimeout,
356
- `MCP server "${config.name}" bootstrap timed out after ${bootstrapTimeout}ms`
357
- );
358
- const filteredTools = await applyMcpToolFilters(config, mcpTools, hooks);
359
- const durationMs = Date.now() - start;
360
- await hooks?.callHook("mcp:bootstrap:end", {
361
- name: config.name,
362
- transport: config.transport,
363
- durationMs,
364
- ok: true,
365
- toolCount: filteredTools.length
366
- });
367
- return { ok: true, name: config.name, config, client: currentClient, tools: filteredTools };
368
- } catch (err) {
369
- const error = err instanceof Error ? err : new Error(String(err));
370
- await closeClientQuietly(client);
371
- const durationMs = Date.now() - start;
372
- await hooks?.callHook("mcp:bootstrap:end", {
373
- name: config.name,
374
- transport: config.transport,
375
- durationMs,
376
- ok: false,
377
- error
378
- });
379
- return { ok: false, name: config.name, error };
380
- }
381
- }
382
- async function applyMcpToolFilters(config, tools, hooks) {
383
- let filtered = tools;
384
- if (config.enabledTools && config.enabledTools.length > 0) {
385
- const allow = new Set(config.enabledTools);
386
- filtered = filtered.filter((t) => allow.has(t.name));
387
- }
388
- if (config.disabledTools && config.disabledTools.length > 0) {
389
- const deny = new Set(config.disabledTools);
390
- filtered = filtered.filter((t) => !deny.has(t.name));
391
- }
392
- if (config.toolFilter) {
393
- const predicate = config.toolFilter;
394
- filtered = filtered.filter((t) => predicate(t));
395
- }
396
- if (hooks) {
397
- const ctx = { server: config.name, transport: config.transport, tools: [...filtered] };
398
- await hooks.callHook("mcp:tools:filter", ctx);
399
- filtered = ctx.tools;
400
- }
401
- return filtered;
402
- }
403
- function buildMcpToolDef(config, client, tool, namespacedName, hooks) {
404
- return {
405
- spec: {
406
- name: namespacedName,
407
- description: tool.description || "",
408
- inputSchema: tool.inputSchema ?? { type: "object", properties: {} }
409
- },
410
- execute: async (input, ctx) => {
411
- const { turnId, callId, signal } = ctx;
412
- const displayName = ctx.toolAliases?.[namespacedName] ?? namespacedName;
413
- const gateCtx = {
414
- turnId,
415
- callId,
416
- server: config.name,
417
- tool: tool.name,
418
- displayName,
419
- input,
420
- block: false,
421
- reason: "MCP tool execution was blocked"
422
- };
423
- await hooks?.callHook("mcp:tool:gate", gateCtx);
424
- if (gateCtx.block)
425
- return `Blocked: ${gateCtx.reason}`;
426
- const effectiveInput = gateCtx.input;
427
- if (gateCtx.result !== void 0) {
428
- let substitute = gateCtx.result;
429
- const transformCtx = {
430
- turnId,
431
- callId,
432
- server: config.name,
433
- tool: tool.name,
434
- displayName,
435
- input: effectiveInput,
436
- result: substitute,
437
- outputBytes: toolOutputByteLength(substitute)
438
- };
439
- await hooks?.callHook("mcp:tool:transform", transformCtx);
440
- substitute = transformCtx.result;
441
- await hooks?.callHook("mcp:tool:after", {
442
- turnId,
443
- callId,
444
- server: config.name,
445
- tool: tool.name,
446
- displayName,
447
- input: effectiveInput,
448
- result: substitute,
449
- outputBytes: toolOutputByteLength(substitute)
450
- });
451
- return substitute;
452
- }
453
- await hooks?.callHook("mcp:tool:before", {
454
- turnId,
455
- callId,
456
- server: config.name,
457
- tool: tool.name,
458
- displayName,
459
- input: effectiveInput
460
- });
461
- const timeout = config.toolTimeout ?? 3e4;
462
- try {
463
- const result = await raceWithTimeoutAndSignal(
464
- () => client.callTool({ name: tool.name, arguments: effectiveInput }),
465
- timeout,
466
- `MCP tool "${tool.name}" on server "${config.name}" timed out after ${timeout}ms`,
467
- signal
468
- );
469
- let output = packMcpResult(result.content);
470
- const transformCtx = {
471
- turnId,
472
- callId,
473
- server: config.name,
474
- tool: tool.name,
475
- displayName,
476
- input: effectiveInput,
477
- result: output,
478
- outputBytes: toolOutputByteLength(output)
479
- };
480
- await hooks?.callHook("mcp:tool:transform", transformCtx);
481
- output = transformCtx.result;
482
- await hooks?.callHook("mcp:tool:after", {
483
- turnId,
484
- callId,
485
- server: config.name,
486
- tool: tool.name,
487
- displayName,
488
- input: effectiveInput,
489
- result: output,
490
- outputBytes: toolOutputByteLength(output)
491
- });
492
- return output;
493
- } catch (err) {
494
- const error = err instanceof Error ? err : new Error(String(err));
495
- await hooks?.callHook("mcp:tool:error", {
496
- turnId,
497
- callId,
498
- server: config.name,
499
- tool: tool.name,
500
- displayName,
501
- input: effectiveInput,
502
- error
503
- });
504
- await hooks?.callHook("mcp:tool:after", {
505
- turnId,
506
- callId,
507
- server: config.name,
508
- tool: tool.name,
509
- displayName,
510
- input: effectiveInput,
511
- result: error.message,
512
- outputBytes: Buffer.byteLength(error.message)
513
- });
514
- throw error;
515
- }
516
- }
517
- };
518
- }
519
- async function closeClientQuietly(client) {
520
- if (!client)
521
- return;
522
- try {
523
- await client.close();
524
- } catch {
525
- }
526
- }
527
- async function raceWithTimeout(task, timeoutMs, timeoutMessage) {
528
- let timer;
529
- try {
530
- return await new Promise((resolvePromise, rejectPromise) => {
531
- timer = setTimeout(() => rejectPromise(new Error(timeoutMessage)), timeoutMs);
532
- task().then(resolvePromise, rejectPromise);
533
- });
534
- } finally {
535
- if (timer)
536
- clearTimeout(timer);
537
- }
538
- }
539
- async function raceWithTimeoutAndSignal(task, timeoutMs, timeoutMessage, signal) {
540
- if (signal?.aborted)
541
- throw new Error("MCP tool call aborted");
542
- let timer;
543
- let onAbort;
544
- try {
545
- return await new Promise((resolvePromise, rejectPromise) => {
546
- timer = setTimeout(() => rejectPromise(new Error(timeoutMessage)), timeoutMs);
547
- if (signal) {
548
- onAbort = () => rejectPromise(new Error("MCP tool call aborted"));
549
- signal.addEventListener("abort", onAbort, { once: true });
550
- }
551
- task().then(resolvePromise, rejectPromise);
552
- });
553
- } finally {
554
- if (timer)
555
- clearTimeout(timer);
556
- if (signal && onAbort)
557
- signal.removeEventListener("abort", onAbort);
558
- }
559
- }
560
-
561
- export {
562
- normalizeMcpServers,
563
- resultToString,
564
- normalizeMcpBlocks,
565
- connectMcpServers
566
- };
@@ -1,37 +0,0 @@
1
- // src/stats.ts
2
- function flattenTurns(stats) {
3
- const out = [];
4
- collectTurns(stats, out);
5
- return out;
6
- }
7
- function collectTurns(stats, out) {
8
- if (stats.turnUsage)
9
- out.push(...stats.turnUsage);
10
- if (stats.children) {
11
- for (const child of stats.children)
12
- collectTurns(child.stats, out);
13
- }
14
- }
15
- function statsByModel(stats) {
16
- const out = /* @__PURE__ */ new Map();
17
- for (const turn of flattenTurns(stats)) {
18
- const key = turn.modelId ?? "(unknown)";
19
- let entry = out.get(key);
20
- if (!entry) {
21
- entry = { input: 0, output: 0, cost: 0, cacheRead: 0, cacheCreation: 0, turns: 0 };
22
- out.set(key, entry);
23
- }
24
- entry.input += turn.input;
25
- entry.output += turn.output;
26
- entry.cost += turn.cost ?? 0;
27
- entry.cacheRead += turn.cacheRead ?? 0;
28
- entry.cacheCreation += turn.cacheCreation ?? 0;
29
- entry.turns += 1;
30
- }
31
- return out;
32
- }
33
-
34
- export {
35
- flattenTurns,
36
- statsByModel
37
- };
@@ -1,22 +0,0 @@
1
- import {
2
- validateSkillForWrite
3
- } from "./chunk-6STZTA4N.js";
4
-
5
- // src/skills/index.ts
6
- function defineSkill(config) {
7
- const normalized = {
8
- ...config,
9
- source: config.source ?? "inline"
10
- };
11
- const result = validateSkillForWrite(normalized);
12
- if (!result.valid) {
13
- const summary = result.errors.map((e) => ` - [${e.code}] ${e.message}`).join("\n");
14
- throw new Error(`Invalid skill "${normalized.name}":
15
- ${summary}`);
16
- }
17
- return normalized;
18
- }
19
-
20
- export {
21
- defineSkill
22
- };
@@ -1,28 +0,0 @@
1
- // src/types.ts
2
- import { Buffer } from "buffer";
3
- function toolResultToText(content) {
4
- if (typeof content === "string")
5
- return content;
6
- return content.map((block) => {
7
- if (block.type === "text")
8
- return block.text;
9
- return `[image: ${block.mediaType} \u2014 ${block.data.length} b64 bytes]`;
10
- }).join("\n");
11
- }
12
- function toolOutputByteLength(content) {
13
- if (typeof content === "string")
14
- return Buffer.byteLength(content);
15
- let total = 0;
16
- for (const block of content) {
17
- if (block.type === "text")
18
- total += Buffer.byteLength(block.text);
19
- else
20
- total += block.data.length;
21
- }
22
- return total;
23
- }
24
-
25
- export {
26
- toolResultToText,
27
- toolOutputByteLength
28
- };