ai 4.1.61 → 4.1.62
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.
- package/CHANGELOG.md +7 -0
- package/dist/index.d.mts +149 -17
- package/dist/index.d.ts +149 -17
- package/dist/index.js +66 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -246
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
@@ -6673,79 +6673,11 @@ function tool(tool2) {
|
|
6673
6673
|
return tool2;
|
6674
6674
|
}
|
6675
6675
|
|
6676
|
-
// core/tool/mcp/
|
6677
|
-
|
6678
|
-
|
6679
|
-
|
6680
|
-
|
6681
|
-
throw new MCPClientError({
|
6682
|
-
message: "Attempted to use child_process module outside of Node.js environment"
|
6683
|
-
});
|
6684
|
-
}
|
6685
|
-
let childProcess;
|
6686
|
-
const nodePrefix = "node:";
|
6687
|
-
try {
|
6688
|
-
childProcess = await import(`${nodePrefix}child_process`);
|
6689
|
-
} catch (error) {
|
6690
|
-
try {
|
6691
|
-
childProcess = require(`${nodePrefix}child_process`);
|
6692
|
-
} catch (innerError) {
|
6693
|
-
throw new MCPClientError({
|
6694
|
-
message: "Failed to load child_process module dynamically",
|
6695
|
-
cause: innerError
|
6696
|
-
});
|
6697
|
-
}
|
6698
|
-
}
|
6699
|
-
const { spawn } = childProcess;
|
6700
|
-
return spawn(config.command, (_a17 = config.args) != null ? _a17 : [], {
|
6701
|
-
env: (_b = config.env) != null ? _b : getDefaultEnvironment(),
|
6702
|
-
stdio: ["pipe", "pipe", (_c = config.stderr) != null ? _c : "inherit"],
|
6703
|
-
shell: false,
|
6704
|
-
signal,
|
6705
|
-
windowsHide: globalThis.process.platform === "win32" && isElectron(),
|
6706
|
-
cwd: config.cwd
|
6707
|
-
});
|
6708
|
-
}
|
6709
|
-
function detectRuntime() {
|
6710
|
-
var _a17, _b;
|
6711
|
-
if (typeof window !== "undefined") {
|
6712
|
-
return "browser";
|
6713
|
-
}
|
6714
|
-
if (((_b = (_a17 = globalThis.process) == null ? void 0 : _a17.release) == null ? void 0 : _b.name) === "node") {
|
6715
|
-
return "node";
|
6716
|
-
}
|
6717
|
-
return null;
|
6718
|
-
}
|
6719
|
-
function getDefaultEnvironment() {
|
6720
|
-
const DEFAULT_INHERITED_ENV_VARS = globalThis.process.platform === "win32" ? [
|
6721
|
-
"APPDATA",
|
6722
|
-
"HOMEDRIVE",
|
6723
|
-
"HOMEPATH",
|
6724
|
-
"LOCALAPPDATA",
|
6725
|
-
"PATH",
|
6726
|
-
"PROCESSOR_ARCHITECTURE",
|
6727
|
-
"SYSTEMDRIVE",
|
6728
|
-
"SYSTEMROOT",
|
6729
|
-
"TEMP",
|
6730
|
-
"USERNAME",
|
6731
|
-
"USERPROFILE"
|
6732
|
-
] : ["HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER"];
|
6733
|
-
const env = {};
|
6734
|
-
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
6735
|
-
const value = globalThis.process.env[key];
|
6736
|
-
if (value === void 0) {
|
6737
|
-
continue;
|
6738
|
-
}
|
6739
|
-
if (value.startsWith("()")) {
|
6740
|
-
continue;
|
6741
|
-
}
|
6742
|
-
env[key] = value;
|
6743
|
-
}
|
6744
|
-
return env;
|
6745
|
-
}
|
6746
|
-
function isElectron() {
|
6747
|
-
return "type" in globalThis.process;
|
6748
|
-
}
|
6676
|
+
// core/tool/mcp/mcp-sse-transport.ts
|
6677
|
+
var import_stream = require("eventsource-parser/stream");
|
6678
|
+
|
6679
|
+
// core/tool/mcp/json-rpc-message.ts
|
6680
|
+
var import_zod9 = require("zod");
|
6749
6681
|
|
6750
6682
|
// core/tool/mcp/types.ts
|
6751
6683
|
var import_zod8 = require("zod");
|
@@ -6754,7 +6686,6 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
6754
6686
|
LATEST_PROTOCOL_VERSION,
|
6755
6687
|
"2024-10-07"
|
6756
6688
|
];
|
6757
|
-
var JSONRPC_VERSION = "2.0";
|
6758
6689
|
var ClientOrServerImplementationSchema = import_zod8.z.object({
|
6759
6690
|
name: import_zod8.z.string(),
|
6760
6691
|
version: import_zod8.z.string()
|
@@ -6762,43 +6693,11 @@ var ClientOrServerImplementationSchema = import_zod8.z.object({
|
|
6762
6693
|
var BaseParamsSchema = import_zod8.z.object({
|
6763
6694
|
_meta: import_zod8.z.optional(import_zod8.z.object({}).passthrough())
|
6764
6695
|
}).passthrough();
|
6765
|
-
var RequestSchema = import_zod8.z.object({
|
6766
|
-
method: import_zod8.z.string(),
|
6767
|
-
params: import_zod8.z.optional(BaseParamsSchema)
|
6768
|
-
});
|
6769
6696
|
var ResultSchema = BaseParamsSchema;
|
6770
|
-
var
|
6697
|
+
var RequestSchema = import_zod8.z.object({
|
6771
6698
|
method: import_zod8.z.string(),
|
6772
6699
|
params: import_zod8.z.optional(BaseParamsSchema)
|
6773
6700
|
});
|
6774
|
-
var RequestIdSchema = import_zod8.z.union([import_zod8.z.string(), import_zod8.z.number().int()]);
|
6775
|
-
var JSONRPCRequestSchema = import_zod8.z.object({
|
6776
|
-
jsonrpc: import_zod8.z.literal(JSONRPC_VERSION),
|
6777
|
-
id: RequestIdSchema
|
6778
|
-
}).merge(RequestSchema).strict();
|
6779
|
-
var JSONRPCResponseSchema = import_zod8.z.object({
|
6780
|
-
jsonrpc: import_zod8.z.literal(JSONRPC_VERSION),
|
6781
|
-
id: RequestIdSchema,
|
6782
|
-
result: ResultSchema
|
6783
|
-
}).strict();
|
6784
|
-
var JSONRPCErrorSchema = import_zod8.z.object({
|
6785
|
-
jsonrpc: import_zod8.z.literal(JSONRPC_VERSION),
|
6786
|
-
id: RequestIdSchema,
|
6787
|
-
error: import_zod8.z.object({
|
6788
|
-
code: import_zod8.z.number().int(),
|
6789
|
-
message: import_zod8.z.string(),
|
6790
|
-
data: import_zod8.z.optional(import_zod8.z.unknown())
|
6791
|
-
})
|
6792
|
-
}).strict();
|
6793
|
-
var JSONRPCNotificationSchema = import_zod8.z.object({
|
6794
|
-
jsonrpc: import_zod8.z.literal(JSONRPC_VERSION)
|
6795
|
-
}).merge(NotificationSchema).strict();
|
6796
|
-
var JSONRPCMessageSchema = import_zod8.z.union([
|
6797
|
-
JSONRPCRequestSchema,
|
6798
|
-
JSONRPCNotificationSchema,
|
6799
|
-
JSONRPCResponseSchema,
|
6800
|
-
JSONRPCErrorSchema
|
6801
|
-
]);
|
6802
6701
|
var ServerCapabilitiesSchema = import_zod8.z.object({
|
6803
6702
|
experimental: import_zod8.z.optional(import_zod8.z.object({}).passthrough()),
|
6804
6703
|
logging: import_zod8.z.optional(import_zod8.z.object({}).passthrough()),
|
@@ -6879,127 +6778,43 @@ var CallToolResultSchema = ResultSchema.extend({
|
|
6879
6778
|
})
|
6880
6779
|
);
|
6881
6780
|
|
6882
|
-
// core/tool/mcp/
|
6883
|
-
var
|
6884
|
-
|
6885
|
-
|
6886
|
-
|
6887
|
-
|
6888
|
-
|
6889
|
-
|
6890
|
-
|
6891
|
-
|
6892
|
-
|
6893
|
-
|
6894
|
-
|
6895
|
-
|
6896
|
-
|
6897
|
-
|
6898
|
-
|
6899
|
-
|
6900
|
-
|
6901
|
-
|
6902
|
-
|
6903
|
-
|
6904
|
-
|
6905
|
-
|
6906
|
-
|
6907
|
-
|
6908
|
-
|
6909
|
-
|
6910
|
-
|
6911
|
-
|
6912
|
-
|
6913
|
-
|
6914
|
-
|
6915
|
-
|
6916
|
-
var _a18;
|
6917
|
-
this.process = void 0;
|
6918
|
-
(_a18 = this.onClose) == null ? void 0 : _a18.call(this);
|
6919
|
-
});
|
6920
|
-
(_a17 = this.process.stdin) == null ? void 0 : _a17.on("error", (error) => {
|
6921
|
-
var _a18;
|
6922
|
-
(_a18 = this.onError) == null ? void 0 : _a18.call(this, error);
|
6923
|
-
});
|
6924
|
-
(_b = this.process.stdout) == null ? void 0 : _b.on("data", (chunk) => {
|
6925
|
-
this.readBuffer.append(chunk);
|
6926
|
-
this.processReadBuffer();
|
6927
|
-
});
|
6928
|
-
(_c = this.process.stdout) == null ? void 0 : _c.on("error", (error) => {
|
6929
|
-
var _a18;
|
6930
|
-
(_a18 = this.onError) == null ? void 0 : _a18.call(this, error);
|
6931
|
-
});
|
6932
|
-
} catch (error) {
|
6933
|
-
reject(error);
|
6934
|
-
(_d = this.onError) == null ? void 0 : _d.call(this, error);
|
6935
|
-
}
|
6936
|
-
});
|
6937
|
-
}
|
6938
|
-
processReadBuffer() {
|
6939
|
-
var _a17, _b;
|
6940
|
-
while (true) {
|
6941
|
-
try {
|
6942
|
-
const message = this.readBuffer.readMessage();
|
6943
|
-
if (message === null) {
|
6944
|
-
break;
|
6945
|
-
}
|
6946
|
-
(_a17 = this.onMessage) == null ? void 0 : _a17.call(this, message);
|
6947
|
-
} catch (error) {
|
6948
|
-
(_b = this.onError) == null ? void 0 : _b.call(this, error);
|
6949
|
-
}
|
6950
|
-
}
|
6951
|
-
}
|
6952
|
-
async close() {
|
6953
|
-
this.abortController.abort();
|
6954
|
-
this.process = void 0;
|
6955
|
-
this.readBuffer.clear();
|
6956
|
-
}
|
6957
|
-
send(message) {
|
6958
|
-
return new Promise((resolve) => {
|
6959
|
-
var _a17;
|
6960
|
-
if (!((_a17 = this.process) == null ? void 0 : _a17.stdin)) {
|
6961
|
-
throw new MCPClientError({
|
6962
|
-
message: "StdioClientTransport not connected"
|
6963
|
-
});
|
6964
|
-
}
|
6965
|
-
const json = serializeMessage(message);
|
6966
|
-
if (this.process.stdin.write(json)) {
|
6967
|
-
resolve();
|
6968
|
-
} else {
|
6969
|
-
this.process.stdin.once("drain", resolve);
|
6970
|
-
}
|
6971
|
-
});
|
6972
|
-
}
|
6973
|
-
};
|
6974
|
-
var ReadBuffer = class {
|
6975
|
-
append(chunk) {
|
6976
|
-
this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;
|
6977
|
-
}
|
6978
|
-
readMessage() {
|
6979
|
-
if (!this.buffer)
|
6980
|
-
return null;
|
6981
|
-
const index = this.buffer.indexOf("\n");
|
6982
|
-
if (index === -1) {
|
6983
|
-
return null;
|
6984
|
-
}
|
6985
|
-
const line = this.buffer.toString("utf8", 0, index);
|
6986
|
-
this.buffer = this.buffer.subarray(index + 1);
|
6987
|
-
return deserializeMessage(line);
|
6988
|
-
}
|
6989
|
-
clear() {
|
6990
|
-
this.buffer = void 0;
|
6991
|
-
}
|
6992
|
-
};
|
6993
|
-
function serializeMessage(message) {
|
6994
|
-
return JSON.stringify(message) + "\n";
|
6995
|
-
}
|
6996
|
-
function deserializeMessage(line) {
|
6997
|
-
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
6998
|
-
}
|
6781
|
+
// core/tool/mcp/json-rpc-message.ts
|
6782
|
+
var JSONRPC_VERSION = "2.0";
|
6783
|
+
var JSONRPCRequestSchema = import_zod9.z.object({
|
6784
|
+
jsonrpc: import_zod9.z.literal(JSONRPC_VERSION),
|
6785
|
+
id: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number().int()])
|
6786
|
+
}).merge(RequestSchema).strict();
|
6787
|
+
var JSONRPCResponseSchema = import_zod9.z.object({
|
6788
|
+
jsonrpc: import_zod9.z.literal(JSONRPC_VERSION),
|
6789
|
+
id: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number().int()]),
|
6790
|
+
result: ResultSchema
|
6791
|
+
}).strict();
|
6792
|
+
var JSONRPCErrorSchema = import_zod9.z.object({
|
6793
|
+
jsonrpc: import_zod9.z.literal(JSONRPC_VERSION),
|
6794
|
+
id: import_zod9.z.union([import_zod9.z.string(), import_zod9.z.number().int()]),
|
6795
|
+
error: import_zod9.z.object({
|
6796
|
+
code: import_zod9.z.number().int(),
|
6797
|
+
message: import_zod9.z.string(),
|
6798
|
+
data: import_zod9.z.optional(import_zod9.z.unknown())
|
6799
|
+
})
|
6800
|
+
}).strict();
|
6801
|
+
var JSONRPCNotificationSchema = import_zod9.z.object({
|
6802
|
+
jsonrpc: import_zod9.z.literal(JSONRPC_VERSION)
|
6803
|
+
}).merge(
|
6804
|
+
import_zod9.z.object({
|
6805
|
+
method: import_zod9.z.string(),
|
6806
|
+
params: import_zod9.z.optional(BaseParamsSchema)
|
6807
|
+
})
|
6808
|
+
).strict();
|
6809
|
+
var JSONRPCMessageSchema = import_zod9.z.union([
|
6810
|
+
JSONRPCRequestSchema,
|
6811
|
+
JSONRPCNotificationSchema,
|
6812
|
+
JSONRPCResponseSchema,
|
6813
|
+
JSONRPCErrorSchema
|
6814
|
+
]);
|
6999
6815
|
|
7000
6816
|
// core/tool/mcp/mcp-sse-transport.ts
|
7001
|
-
var
|
7002
|
-
var SSEClientTransport = class {
|
6817
|
+
var SseMCPTransport = class {
|
7003
6818
|
constructor({ url }) {
|
7004
6819
|
this.connected = false;
|
7005
6820
|
this.url = new URL(url);
|
@@ -7023,7 +6838,7 @@ var SSEClientTransport = class {
|
|
7023
6838
|
const error = new MCPClientError({
|
7024
6839
|
message: `MCP SSE Transport Error: ${response.status} ${response.statusText}`
|
7025
6840
|
});
|
7026
|
-
(_b = this.
|
6841
|
+
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
7027
6842
|
return reject(error);
|
7028
6843
|
}
|
7029
6844
|
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_stream.EventSourceParserStream());
|
@@ -7057,13 +6872,13 @@ var SSEClientTransport = class {
|
|
7057
6872
|
const message = JSONRPCMessageSchema.parse(
|
7058
6873
|
JSON.parse(data)
|
7059
6874
|
);
|
7060
|
-
(_a18 = this.
|
6875
|
+
(_a18 = this.onmessage) == null ? void 0 : _a18.call(this, message);
|
7061
6876
|
} catch (error) {
|
7062
6877
|
const e = new MCPClientError({
|
7063
6878
|
message: "MCP SSE Transport Error: Failed to parse message",
|
7064
6879
|
cause: error
|
7065
6880
|
});
|
7066
|
-
(_b2 = this.
|
6881
|
+
(_b2 = this.onerror) == null ? void 0 : _b2.call(this, e);
|
7067
6882
|
}
|
7068
6883
|
}
|
7069
6884
|
}
|
@@ -7071,7 +6886,7 @@ var SSEClientTransport = class {
|
|
7071
6886
|
if (error instanceof Error && error.name === "AbortError") {
|
7072
6887
|
return;
|
7073
6888
|
}
|
7074
|
-
(_c2 = this.
|
6889
|
+
(_c2 = this.onerror) == null ? void 0 : _c2.call(this, error);
|
7075
6890
|
reject(error);
|
7076
6891
|
}
|
7077
6892
|
};
|
@@ -7083,7 +6898,7 @@ var SSEClientTransport = class {
|
|
7083
6898
|
if (error instanceof Error && error.name === "AbortError") {
|
7084
6899
|
return;
|
7085
6900
|
}
|
7086
|
-
(_c = this.
|
6901
|
+
(_c = this.onerror) == null ? void 0 : _c.call(this, error);
|
7087
6902
|
reject(error);
|
7088
6903
|
}
|
7089
6904
|
};
|
@@ -7095,7 +6910,7 @@ var SSEClientTransport = class {
|
|
7095
6910
|
this.connected = false;
|
7096
6911
|
(_a17 = this.sseConnection) == null ? void 0 : _a17.close();
|
7097
6912
|
(_b = this.abortController) == null ? void 0 : _b.abort();
|
7098
|
-
(_c = this.
|
6913
|
+
(_c = this.onclose) == null ? void 0 : _c.call(this);
|
7099
6914
|
}
|
7100
6915
|
async send(message) {
|
7101
6916
|
var _a17, _b, _c;
|
@@ -7119,11 +6934,11 @@ var SSEClientTransport = class {
|
|
7119
6934
|
const error = new MCPClientError({
|
7120
6935
|
message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`
|
7121
6936
|
});
|
7122
|
-
(_b = this.
|
6937
|
+
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
7123
6938
|
return;
|
7124
6939
|
}
|
7125
6940
|
} catch (error) {
|
7126
|
-
(_c = this.
|
6941
|
+
(_c = this.onerror) == null ? void 0 : _c.call(this, error);
|
7127
6942
|
return;
|
7128
6943
|
}
|
7129
6944
|
}
|
@@ -7131,7 +6946,15 @@ var SSEClientTransport = class {
|
|
7131
6946
|
|
7132
6947
|
// core/tool/mcp/mcp-transport.ts
|
7133
6948
|
function createMcpTransport(config) {
|
7134
|
-
|
6949
|
+
if (config.type !== "sse") {
|
6950
|
+
throw new MCPClientError({
|
6951
|
+
message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
|
6952
|
+
});
|
6953
|
+
}
|
6954
|
+
return new SseMCPTransport(config);
|
6955
|
+
}
|
6956
|
+
function isCustomMcpTransport(transport) {
|
6957
|
+
return "start" in transport && typeof transport.start === "function" && "send" in transport && typeof transport.send === "function" && "close" in transport && typeof transport.close === "function";
|
7135
6958
|
}
|
7136
6959
|
|
7137
6960
|
// core/tool/mcp/mcp-client.ts
|
@@ -7152,10 +6975,14 @@ var MCPClient = class {
|
|
7152
6975
|
this.serverCapabilities = {};
|
7153
6976
|
this.isClosed = true;
|
7154
6977
|
this.onUncaughtError = onUncaughtError;
|
7155
|
-
|
7156
|
-
|
7157
|
-
|
7158
|
-
|
6978
|
+
if (isCustomMcpTransport(transportConfig)) {
|
6979
|
+
this.transport = transportConfig;
|
6980
|
+
} else {
|
6981
|
+
this.transport = createMcpTransport(transportConfig);
|
6982
|
+
}
|
6983
|
+
this.transport.onclose = () => this.onClose();
|
6984
|
+
this.transport.onerror = (error) => this.onError(error);
|
6985
|
+
this.transport.onmessage = (message) => {
|
7159
6986
|
if ("method" in message) {
|
7160
6987
|
this.onError(
|
7161
6988
|
new MCPClientError({
|