ai 4.1.60 → 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 +18 -0
- package/dist/index.d.mts +153 -17
- package/dist/index.d.ts +153 -17
- package/dist/index.js +68 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -246
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -5
- package/rsc/dist/index.d.ts +4 -0
- package/rsc/dist/rsc-server.d.mts +4 -0
- package/rsc/dist/rsc-server.mjs +2 -0
- package/rsc/dist/rsc-server.mjs.map +1 -1
package/dist/index.mjs
CHANGED
@@ -1,11 +1,4 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
4
|
-
}) : x)(function(x) {
|
5
|
-
if (typeof require !== "undefined")
|
6
|
-
return require.apply(this, arguments);
|
7
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
8
|
-
});
|
9
2
|
var __export = (target, all) => {
|
10
3
|
for (var name17 in all)
|
11
4
|
__defProp(target, name17, { get: all[name17], enumerable: true });
|
@@ -1332,6 +1325,7 @@ function convertPartToLanguageModelPart(part, downloadedAssets) {
|
|
1332
1325
|
return {
|
1333
1326
|
type: "file",
|
1334
1327
|
data: normalizedData instanceof Uint8Array ? convertDataContentToBase64String(normalizedData) : normalizedData,
|
1328
|
+
filename: part.filename,
|
1335
1329
|
mimeType,
|
1336
1330
|
providerMetadata: (_d = part.providerOptions) != null ? _d : part.experimental_providerMetadata
|
1337
1331
|
};
|
@@ -1850,6 +1844,7 @@ var imagePartSchema = z5.object({
|
|
1850
1844
|
var filePartSchema = z5.object({
|
1851
1845
|
type: z5.literal("file"),
|
1852
1846
|
data: z5.union([dataContentSchema, z5.instanceof(URL)]),
|
1847
|
+
filename: z5.string().optional(),
|
1853
1848
|
mimeType: z5.string(),
|
1854
1849
|
providerOptions: providerMetadataSchema.optional(),
|
1855
1850
|
experimental_providerMetadata: providerMetadataSchema.optional()
|
@@ -6629,79 +6624,11 @@ function tool(tool2) {
|
|
6629
6624
|
return tool2;
|
6630
6625
|
}
|
6631
6626
|
|
6632
|
-
// core/tool/mcp/
|
6633
|
-
|
6634
|
-
|
6635
|
-
|
6636
|
-
|
6637
|
-
throw new MCPClientError({
|
6638
|
-
message: "Attempted to use child_process module outside of Node.js environment"
|
6639
|
-
});
|
6640
|
-
}
|
6641
|
-
let childProcess;
|
6642
|
-
const nodePrefix = "node:";
|
6643
|
-
try {
|
6644
|
-
childProcess = await import(`${nodePrefix}child_process`);
|
6645
|
-
} catch (error) {
|
6646
|
-
try {
|
6647
|
-
childProcess = __require(`${nodePrefix}child_process`);
|
6648
|
-
} catch (innerError) {
|
6649
|
-
throw new MCPClientError({
|
6650
|
-
message: "Failed to load child_process module dynamically",
|
6651
|
-
cause: innerError
|
6652
|
-
});
|
6653
|
-
}
|
6654
|
-
}
|
6655
|
-
const { spawn } = childProcess;
|
6656
|
-
return spawn(config.command, (_a17 = config.args) != null ? _a17 : [], {
|
6657
|
-
env: (_b = config.env) != null ? _b : getDefaultEnvironment(),
|
6658
|
-
stdio: ["pipe", "pipe", (_c = config.stderr) != null ? _c : "inherit"],
|
6659
|
-
shell: false,
|
6660
|
-
signal,
|
6661
|
-
windowsHide: globalThis.process.platform === "win32" && isElectron(),
|
6662
|
-
cwd: config.cwd
|
6663
|
-
});
|
6664
|
-
}
|
6665
|
-
function detectRuntime() {
|
6666
|
-
var _a17, _b;
|
6667
|
-
if (typeof window !== "undefined") {
|
6668
|
-
return "browser";
|
6669
|
-
}
|
6670
|
-
if (((_b = (_a17 = globalThis.process) == null ? void 0 : _a17.release) == null ? void 0 : _b.name) === "node") {
|
6671
|
-
return "node";
|
6672
|
-
}
|
6673
|
-
return null;
|
6674
|
-
}
|
6675
|
-
function getDefaultEnvironment() {
|
6676
|
-
const DEFAULT_INHERITED_ENV_VARS = globalThis.process.platform === "win32" ? [
|
6677
|
-
"APPDATA",
|
6678
|
-
"HOMEDRIVE",
|
6679
|
-
"HOMEPATH",
|
6680
|
-
"LOCALAPPDATA",
|
6681
|
-
"PATH",
|
6682
|
-
"PROCESSOR_ARCHITECTURE",
|
6683
|
-
"SYSTEMDRIVE",
|
6684
|
-
"SYSTEMROOT",
|
6685
|
-
"TEMP",
|
6686
|
-
"USERNAME",
|
6687
|
-
"USERPROFILE"
|
6688
|
-
] : ["HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER"];
|
6689
|
-
const env = {};
|
6690
|
-
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
6691
|
-
const value = globalThis.process.env[key];
|
6692
|
-
if (value === void 0) {
|
6693
|
-
continue;
|
6694
|
-
}
|
6695
|
-
if (value.startsWith("()")) {
|
6696
|
-
continue;
|
6697
|
-
}
|
6698
|
-
env[key] = value;
|
6699
|
-
}
|
6700
|
-
return env;
|
6701
|
-
}
|
6702
|
-
function isElectron() {
|
6703
|
-
return "type" in globalThis.process;
|
6704
|
-
}
|
6627
|
+
// core/tool/mcp/mcp-sse-transport.ts
|
6628
|
+
import { EventSourceParserStream } from "eventsource-parser/stream";
|
6629
|
+
|
6630
|
+
// core/tool/mcp/json-rpc-message.ts
|
6631
|
+
import { z as z9 } from "zod";
|
6705
6632
|
|
6706
6633
|
// core/tool/mcp/types.ts
|
6707
6634
|
import { z as z8 } from "zod";
|
@@ -6710,7 +6637,6 @@ var SUPPORTED_PROTOCOL_VERSIONS = [
|
|
6710
6637
|
LATEST_PROTOCOL_VERSION,
|
6711
6638
|
"2024-10-07"
|
6712
6639
|
];
|
6713
|
-
var JSONRPC_VERSION = "2.0";
|
6714
6640
|
var ClientOrServerImplementationSchema = z8.object({
|
6715
6641
|
name: z8.string(),
|
6716
6642
|
version: z8.string()
|
@@ -6718,43 +6644,11 @@ var ClientOrServerImplementationSchema = z8.object({
|
|
6718
6644
|
var BaseParamsSchema = z8.object({
|
6719
6645
|
_meta: z8.optional(z8.object({}).passthrough())
|
6720
6646
|
}).passthrough();
|
6721
|
-
var RequestSchema = z8.object({
|
6722
|
-
method: z8.string(),
|
6723
|
-
params: z8.optional(BaseParamsSchema)
|
6724
|
-
});
|
6725
6647
|
var ResultSchema = BaseParamsSchema;
|
6726
|
-
var
|
6648
|
+
var RequestSchema = z8.object({
|
6727
6649
|
method: z8.string(),
|
6728
6650
|
params: z8.optional(BaseParamsSchema)
|
6729
6651
|
});
|
6730
|
-
var RequestIdSchema = z8.union([z8.string(), z8.number().int()]);
|
6731
|
-
var JSONRPCRequestSchema = z8.object({
|
6732
|
-
jsonrpc: z8.literal(JSONRPC_VERSION),
|
6733
|
-
id: RequestIdSchema
|
6734
|
-
}).merge(RequestSchema).strict();
|
6735
|
-
var JSONRPCResponseSchema = z8.object({
|
6736
|
-
jsonrpc: z8.literal(JSONRPC_VERSION),
|
6737
|
-
id: RequestIdSchema,
|
6738
|
-
result: ResultSchema
|
6739
|
-
}).strict();
|
6740
|
-
var JSONRPCErrorSchema = z8.object({
|
6741
|
-
jsonrpc: z8.literal(JSONRPC_VERSION),
|
6742
|
-
id: RequestIdSchema,
|
6743
|
-
error: z8.object({
|
6744
|
-
code: z8.number().int(),
|
6745
|
-
message: z8.string(),
|
6746
|
-
data: z8.optional(z8.unknown())
|
6747
|
-
})
|
6748
|
-
}).strict();
|
6749
|
-
var JSONRPCNotificationSchema = z8.object({
|
6750
|
-
jsonrpc: z8.literal(JSONRPC_VERSION)
|
6751
|
-
}).merge(NotificationSchema).strict();
|
6752
|
-
var JSONRPCMessageSchema = z8.union([
|
6753
|
-
JSONRPCRequestSchema,
|
6754
|
-
JSONRPCNotificationSchema,
|
6755
|
-
JSONRPCResponseSchema,
|
6756
|
-
JSONRPCErrorSchema
|
6757
|
-
]);
|
6758
6652
|
var ServerCapabilitiesSchema = z8.object({
|
6759
6653
|
experimental: z8.optional(z8.object({}).passthrough()),
|
6760
6654
|
logging: z8.optional(z8.object({}).passthrough()),
|
@@ -6835,127 +6729,43 @@ var CallToolResultSchema = ResultSchema.extend({
|
|
6835
6729
|
})
|
6836
6730
|
);
|
6837
6731
|
|
6838
|
-
// core/tool/mcp/
|
6839
|
-
var
|
6840
|
-
|
6841
|
-
|
6842
|
-
|
6843
|
-
|
6844
|
-
|
6845
|
-
|
6846
|
-
|
6847
|
-
|
6848
|
-
|
6849
|
-
|
6850
|
-
|
6851
|
-
|
6852
|
-
|
6853
|
-
|
6854
|
-
|
6855
|
-
|
6856
|
-
|
6857
|
-
|
6858
|
-
|
6859
|
-
|
6860
|
-
|
6861
|
-
|
6862
|
-
|
6863
|
-
|
6864
|
-
|
6865
|
-
|
6866
|
-
|
6867
|
-
|
6868
|
-
|
6869
|
-
|
6870
|
-
|
6871
|
-
|
6872
|
-
var _a18;
|
6873
|
-
this.process = void 0;
|
6874
|
-
(_a18 = this.onClose) == null ? void 0 : _a18.call(this);
|
6875
|
-
});
|
6876
|
-
(_a17 = this.process.stdin) == null ? void 0 : _a17.on("error", (error) => {
|
6877
|
-
var _a18;
|
6878
|
-
(_a18 = this.onError) == null ? void 0 : _a18.call(this, error);
|
6879
|
-
});
|
6880
|
-
(_b = this.process.stdout) == null ? void 0 : _b.on("data", (chunk) => {
|
6881
|
-
this.readBuffer.append(chunk);
|
6882
|
-
this.processReadBuffer();
|
6883
|
-
});
|
6884
|
-
(_c = this.process.stdout) == null ? void 0 : _c.on("error", (error) => {
|
6885
|
-
var _a18;
|
6886
|
-
(_a18 = this.onError) == null ? void 0 : _a18.call(this, error);
|
6887
|
-
});
|
6888
|
-
} catch (error) {
|
6889
|
-
reject(error);
|
6890
|
-
(_d = this.onError) == null ? void 0 : _d.call(this, error);
|
6891
|
-
}
|
6892
|
-
});
|
6893
|
-
}
|
6894
|
-
processReadBuffer() {
|
6895
|
-
var _a17, _b;
|
6896
|
-
while (true) {
|
6897
|
-
try {
|
6898
|
-
const message = this.readBuffer.readMessage();
|
6899
|
-
if (message === null) {
|
6900
|
-
break;
|
6901
|
-
}
|
6902
|
-
(_a17 = this.onMessage) == null ? void 0 : _a17.call(this, message);
|
6903
|
-
} catch (error) {
|
6904
|
-
(_b = this.onError) == null ? void 0 : _b.call(this, error);
|
6905
|
-
}
|
6906
|
-
}
|
6907
|
-
}
|
6908
|
-
async close() {
|
6909
|
-
this.abortController.abort();
|
6910
|
-
this.process = void 0;
|
6911
|
-
this.readBuffer.clear();
|
6912
|
-
}
|
6913
|
-
send(message) {
|
6914
|
-
return new Promise((resolve) => {
|
6915
|
-
var _a17;
|
6916
|
-
if (!((_a17 = this.process) == null ? void 0 : _a17.stdin)) {
|
6917
|
-
throw new MCPClientError({
|
6918
|
-
message: "StdioClientTransport not connected"
|
6919
|
-
});
|
6920
|
-
}
|
6921
|
-
const json = serializeMessage(message);
|
6922
|
-
if (this.process.stdin.write(json)) {
|
6923
|
-
resolve();
|
6924
|
-
} else {
|
6925
|
-
this.process.stdin.once("drain", resolve);
|
6926
|
-
}
|
6927
|
-
});
|
6928
|
-
}
|
6929
|
-
};
|
6930
|
-
var ReadBuffer = class {
|
6931
|
-
append(chunk) {
|
6932
|
-
this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;
|
6933
|
-
}
|
6934
|
-
readMessage() {
|
6935
|
-
if (!this.buffer)
|
6936
|
-
return null;
|
6937
|
-
const index = this.buffer.indexOf("\n");
|
6938
|
-
if (index === -1) {
|
6939
|
-
return null;
|
6940
|
-
}
|
6941
|
-
const line = this.buffer.toString("utf8", 0, index);
|
6942
|
-
this.buffer = this.buffer.subarray(index + 1);
|
6943
|
-
return deserializeMessage(line);
|
6944
|
-
}
|
6945
|
-
clear() {
|
6946
|
-
this.buffer = void 0;
|
6947
|
-
}
|
6948
|
-
};
|
6949
|
-
function serializeMessage(message) {
|
6950
|
-
return JSON.stringify(message) + "\n";
|
6951
|
-
}
|
6952
|
-
function deserializeMessage(line) {
|
6953
|
-
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
6954
|
-
}
|
6732
|
+
// core/tool/mcp/json-rpc-message.ts
|
6733
|
+
var JSONRPC_VERSION = "2.0";
|
6734
|
+
var JSONRPCRequestSchema = z9.object({
|
6735
|
+
jsonrpc: z9.literal(JSONRPC_VERSION),
|
6736
|
+
id: z9.union([z9.string(), z9.number().int()])
|
6737
|
+
}).merge(RequestSchema).strict();
|
6738
|
+
var JSONRPCResponseSchema = z9.object({
|
6739
|
+
jsonrpc: z9.literal(JSONRPC_VERSION),
|
6740
|
+
id: z9.union([z9.string(), z9.number().int()]),
|
6741
|
+
result: ResultSchema
|
6742
|
+
}).strict();
|
6743
|
+
var JSONRPCErrorSchema = z9.object({
|
6744
|
+
jsonrpc: z9.literal(JSONRPC_VERSION),
|
6745
|
+
id: z9.union([z9.string(), z9.number().int()]),
|
6746
|
+
error: z9.object({
|
6747
|
+
code: z9.number().int(),
|
6748
|
+
message: z9.string(),
|
6749
|
+
data: z9.optional(z9.unknown())
|
6750
|
+
})
|
6751
|
+
}).strict();
|
6752
|
+
var JSONRPCNotificationSchema = z9.object({
|
6753
|
+
jsonrpc: z9.literal(JSONRPC_VERSION)
|
6754
|
+
}).merge(
|
6755
|
+
z9.object({
|
6756
|
+
method: z9.string(),
|
6757
|
+
params: z9.optional(BaseParamsSchema)
|
6758
|
+
})
|
6759
|
+
).strict();
|
6760
|
+
var JSONRPCMessageSchema = z9.union([
|
6761
|
+
JSONRPCRequestSchema,
|
6762
|
+
JSONRPCNotificationSchema,
|
6763
|
+
JSONRPCResponseSchema,
|
6764
|
+
JSONRPCErrorSchema
|
6765
|
+
]);
|
6955
6766
|
|
6956
6767
|
// core/tool/mcp/mcp-sse-transport.ts
|
6957
|
-
|
6958
|
-
var SSEClientTransport = class {
|
6768
|
+
var SseMCPTransport = class {
|
6959
6769
|
constructor({ url }) {
|
6960
6770
|
this.connected = false;
|
6961
6771
|
this.url = new URL(url);
|
@@ -6979,7 +6789,7 @@ var SSEClientTransport = class {
|
|
6979
6789
|
const error = new MCPClientError({
|
6980
6790
|
message: `MCP SSE Transport Error: ${response.status} ${response.statusText}`
|
6981
6791
|
});
|
6982
|
-
(_b = this.
|
6792
|
+
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
6983
6793
|
return reject(error);
|
6984
6794
|
}
|
6985
6795
|
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
|
@@ -7013,13 +6823,13 @@ var SSEClientTransport = class {
|
|
7013
6823
|
const message = JSONRPCMessageSchema.parse(
|
7014
6824
|
JSON.parse(data)
|
7015
6825
|
);
|
7016
|
-
(_a18 = this.
|
6826
|
+
(_a18 = this.onmessage) == null ? void 0 : _a18.call(this, message);
|
7017
6827
|
} catch (error) {
|
7018
6828
|
const e = new MCPClientError({
|
7019
6829
|
message: "MCP SSE Transport Error: Failed to parse message",
|
7020
6830
|
cause: error
|
7021
6831
|
});
|
7022
|
-
(_b2 = this.
|
6832
|
+
(_b2 = this.onerror) == null ? void 0 : _b2.call(this, e);
|
7023
6833
|
}
|
7024
6834
|
}
|
7025
6835
|
}
|
@@ -7027,7 +6837,7 @@ var SSEClientTransport = class {
|
|
7027
6837
|
if (error instanceof Error && error.name === "AbortError") {
|
7028
6838
|
return;
|
7029
6839
|
}
|
7030
|
-
(_c2 = this.
|
6840
|
+
(_c2 = this.onerror) == null ? void 0 : _c2.call(this, error);
|
7031
6841
|
reject(error);
|
7032
6842
|
}
|
7033
6843
|
};
|
@@ -7039,7 +6849,7 @@ var SSEClientTransport = class {
|
|
7039
6849
|
if (error instanceof Error && error.name === "AbortError") {
|
7040
6850
|
return;
|
7041
6851
|
}
|
7042
|
-
(_c = this.
|
6852
|
+
(_c = this.onerror) == null ? void 0 : _c.call(this, error);
|
7043
6853
|
reject(error);
|
7044
6854
|
}
|
7045
6855
|
};
|
@@ -7051,7 +6861,7 @@ var SSEClientTransport = class {
|
|
7051
6861
|
this.connected = false;
|
7052
6862
|
(_a17 = this.sseConnection) == null ? void 0 : _a17.close();
|
7053
6863
|
(_b = this.abortController) == null ? void 0 : _b.abort();
|
7054
|
-
(_c = this.
|
6864
|
+
(_c = this.onclose) == null ? void 0 : _c.call(this);
|
7055
6865
|
}
|
7056
6866
|
async send(message) {
|
7057
6867
|
var _a17, _b, _c;
|
@@ -7075,11 +6885,11 @@ var SSEClientTransport = class {
|
|
7075
6885
|
const error = new MCPClientError({
|
7076
6886
|
message: `MCP SSE Transport Error: POSTing to endpoint (HTTP ${response.status}): ${text2}`
|
7077
6887
|
});
|
7078
|
-
(_b = this.
|
6888
|
+
(_b = this.onerror) == null ? void 0 : _b.call(this, error);
|
7079
6889
|
return;
|
7080
6890
|
}
|
7081
6891
|
} catch (error) {
|
7082
|
-
(_c = this.
|
6892
|
+
(_c = this.onerror) == null ? void 0 : _c.call(this, error);
|
7083
6893
|
return;
|
7084
6894
|
}
|
7085
6895
|
}
|
@@ -7087,7 +6897,15 @@ var SSEClientTransport = class {
|
|
7087
6897
|
|
7088
6898
|
// core/tool/mcp/mcp-transport.ts
|
7089
6899
|
function createMcpTransport(config) {
|
7090
|
-
|
6900
|
+
if (config.type !== "sse") {
|
6901
|
+
throw new MCPClientError({
|
6902
|
+
message: "Unsupported or invalid transport configuration. If you are using a custom transport, make sure it implements the MCPTransport interface."
|
6903
|
+
});
|
6904
|
+
}
|
6905
|
+
return new SseMCPTransport(config);
|
6906
|
+
}
|
6907
|
+
function isCustomMcpTransport(transport) {
|
6908
|
+
return "start" in transport && typeof transport.start === "function" && "send" in transport && typeof transport.send === "function" && "close" in transport && typeof transport.close === "function";
|
7091
6909
|
}
|
7092
6910
|
|
7093
6911
|
// core/tool/mcp/mcp-client.ts
|
@@ -7108,10 +6926,14 @@ var MCPClient = class {
|
|
7108
6926
|
this.serverCapabilities = {};
|
7109
6927
|
this.isClosed = true;
|
7110
6928
|
this.onUncaughtError = onUncaughtError;
|
7111
|
-
|
7112
|
-
|
7113
|
-
|
7114
|
-
|
6929
|
+
if (isCustomMcpTransport(transportConfig)) {
|
6930
|
+
this.transport = transportConfig;
|
6931
|
+
} else {
|
6932
|
+
this.transport = createMcpTransport(transportConfig);
|
6933
|
+
}
|
6934
|
+
this.transport.onclose = () => this.onClose();
|
6935
|
+
this.transport.onerror = (error) => this.onError(error);
|
6936
|
+
this.transport.onmessage = (message) => {
|
7115
6937
|
if ("method" in message) {
|
7116
6938
|
this.onError(
|
7117
6939
|
new MCPClientError({
|