zidane 3.3.4 → 3.3.6

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.
@@ -4,10 +4,132 @@ import {
4
4
 
5
5
  // src/mcp/index.ts
6
6
  import { Buffer } from "buffer";
7
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
7
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
9
8
  import { getDefaultEnvironment, StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
10
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
11
133
  var DEFAULT_MCP_BOOTSTRAP_TIMEOUT_MS = 1e4;
12
134
  function inferTransport(raw) {
13
135
  if (raw.transport === "stdio" || raw.transport === "sse" || raw.transport === "streamable-http")
@@ -151,7 +273,8 @@ function createTransport(config) {
151
273
  });
152
274
  case "streamable-http":
153
275
  return new StreamableHTTPClientTransport(new URL(config.url), {
154
- requestInit: config.headers ? { headers: config.headers } : void 0
276
+ requestInit: config.headers ? { headers: config.headers } : void 0,
277
+ fetch: sseToJsonFetchIfNeeded()
155
278
  });
156
279
  default:
157
280
  throw new Error(`Unknown MCP transport: ${config.transport}`);
@@ -220,7 +343,7 @@ async function bootstrapServer(config, _clientFactory, hooks) {
220
343
  await hooks?.callHook("mcp:bootstrap:start", { name: config.name, transport: config.transport });
221
344
  let client = null;
222
345
  try {
223
- client = _clientFactory ? _clientFactory() : new Client({ name: "zidane", version: "1.0.0" });
346
+ client = _clientFactory ? _clientFactory() : new TolerantMcpClient({ name: "zidane", version: "1.0.0" });
224
347
  const currentClient = client;
225
348
  const transport = createTransport(config);
226
349
  const bootstrapTimeout = config.bootstrapTimeout ?? DEFAULT_MCP_BOOTSTRAP_TIMEOUT_MS;
@@ -6,7 +6,7 @@ import {
6
6
  readFile,
7
7
  shell,
8
8
  writeFile
9
- } from "./chunk-LHCIHOCE.js";
9
+ } from "./chunk-OAIKGCZX.js";
10
10
 
11
11
  // src/presets/basic.ts
12
12
  var basicTools = { shell, readFile, writeFile, listFiles, edit, multiEdit };
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-UD25QF3H.js";
12
12
  import {
13
13
  connectMcpServers
14
- } from "./chunk-6Z4UMOV4.js";
14
+ } from "./chunk-7GQ7P6DM.js";
15
15
  import {
16
16
  toolOutputByteLength
17
17
  } from "./chunk-JH6IAAFA.js";
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  basicTools,
12
12
  basic_default,
13
13
  definePreset
14
- } from "./chunk-NYGFP4AV.js";
14
+ } from "./chunk-CZQGCVMH.js";
15
15
  import {
16
16
  createAgent,
17
17
  createInteractionTool,
@@ -24,7 +24,7 @@ import {
24
24
  grep,
25
25
  multiEdit,
26
26
  validateToolArgs
27
- } from "./chunk-LHCIHOCE.js";
27
+ } from "./chunk-OAIKGCZX.js";
28
28
  import {
29
29
  IMPLICITLY_ALLOWED_SKILL_TOOLS,
30
30
  buildCatalog,
@@ -53,7 +53,7 @@ import {
53
53
  normalizeMcpBlocks,
54
54
  normalizeMcpServers,
55
55
  resultToString
56
- } from "./chunk-6Z4UMOV4.js";
56
+ } from "./chunk-7GQ7P6DM.js";
57
57
  import {
58
58
  toolOutputByteLength,
59
59
  toolResultToText
package/dist/mcp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
+ import '@modelcontextprotocol/sdk/client/index.js';
1
2
  import 'hookable';
2
3
  export { M as McpConnection, p as McpServerConfig, ar as connectMcpServers, aC as normalizeMcpBlocks, aD as normalizeMcpServers, aH as resultToString } from './agent-LEf7zjw6.js';
3
- import '@modelcontextprotocol/sdk/client/index.js';
4
4
  import './types-vA1a_ZX7.js';
package/dist/mcp.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  normalizeMcpBlocks,
4
4
  normalizeMcpServers,
5
5
  resultToString
6
- } from "./chunk-6Z4UMOV4.js";
6
+ } from "./chunk-7GQ7P6DM.js";
7
7
  import "./chunk-JH6IAAFA.js";
8
8
  export {
9
9
  connectMcpServers,
package/dist/presets.js CHANGED
@@ -2,11 +2,11 @@ import {
2
2
  basicTools,
3
3
  basic_default,
4
4
  definePreset
5
- } from "./chunk-NYGFP4AV.js";
6
- import "./chunk-LHCIHOCE.js";
5
+ } from "./chunk-CZQGCVMH.js";
6
+ import "./chunk-OAIKGCZX.js";
7
7
  import "./chunk-X3VOTPVM.js";
8
8
  import "./chunk-UD25QF3H.js";
9
- import "./chunk-6Z4UMOV4.js";
9
+ import "./chunk-7GQ7P6DM.js";
10
10
  import "./chunk-JH6IAAFA.js";
11
11
  import "./chunk-LNN5UTS2.js";
12
12
  export {
package/dist/tools.js CHANGED
@@ -13,10 +13,10 @@ import {
13
13
  shell,
14
14
  validateToolArgs,
15
15
  writeFile
16
- } from "./chunk-LHCIHOCE.js";
16
+ } from "./chunk-OAIKGCZX.js";
17
17
  import "./chunk-X3VOTPVM.js";
18
18
  import "./chunk-UD25QF3H.js";
19
- import "./chunk-6Z4UMOV4.js";
19
+ import "./chunk-7GQ7P6DM.js";
20
20
  import "./chunk-JH6IAAFA.js";
21
21
  import "./chunk-LNN5UTS2.js";
22
22
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zidane",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "an agent that goes straight to the goal",
5
5
  "type": "module",
6
6
  "private": false,