@fre4x/grok 1.0.52 → 1.0.54
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/dist/index.js +2825 -656
- package/package.json +5 -6
package/dist/index.js
CHANGED
|
@@ -3229,8 +3229,8 @@ var require_utils = __commonJS({
|
|
|
3229
3229
|
}
|
|
3230
3230
|
return ind;
|
|
3231
3231
|
}
|
|
3232
|
-
function removeDotSegments(
|
|
3233
|
-
let input =
|
|
3232
|
+
function removeDotSegments(path3) {
|
|
3233
|
+
let input = path3;
|
|
3234
3234
|
const output = [];
|
|
3235
3235
|
let nextSlash = -1;
|
|
3236
3236
|
let len = 0;
|
|
@@ -3429,8 +3429,8 @@ var require_schemes = __commonJS({
|
|
|
3429
3429
|
wsComponent.secure = void 0;
|
|
3430
3430
|
}
|
|
3431
3431
|
if (wsComponent.resourceName) {
|
|
3432
|
-
const [
|
|
3433
|
-
wsComponent.path =
|
|
3432
|
+
const [path3, query] = wsComponent.resourceName.split("?");
|
|
3433
|
+
wsComponent.path = path3 && path3 !== "/" ? path3 : void 0;
|
|
3434
3434
|
wsComponent.query = query;
|
|
3435
3435
|
wsComponent.resourceName = void 0;
|
|
3436
3436
|
}
|
|
@@ -6792,12 +6792,12 @@ var require_dist = __commonJS({
|
|
|
6792
6792
|
throw new Error(`Unknown format "${name}"`);
|
|
6793
6793
|
return f;
|
|
6794
6794
|
};
|
|
6795
|
-
function addFormats(ajv, list,
|
|
6795
|
+
function addFormats(ajv, list, fs3, exportName) {
|
|
6796
6796
|
var _a2;
|
|
6797
6797
|
var _b;
|
|
6798
6798
|
(_a2 = (_b = ajv.opts.code).formats) !== null && _a2 !== void 0 ? _a2 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
|
|
6799
6799
|
for (const f of list)
|
|
6800
|
-
ajv.addFormat(f,
|
|
6800
|
+
ajv.addFormat(f, fs3[f]);
|
|
6801
6801
|
}
|
|
6802
6802
|
module.exports = exports = formatsPlugin;
|
|
6803
6803
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -15652,11 +15652,11 @@ var require_mime_types = __commonJS({
|
|
|
15652
15652
|
}
|
|
15653
15653
|
return exts[0];
|
|
15654
15654
|
}
|
|
15655
|
-
function lookup(
|
|
15656
|
-
if (!
|
|
15655
|
+
function lookup(path3) {
|
|
15656
|
+
if (!path3 || typeof path3 !== "string") {
|
|
15657
15657
|
return false;
|
|
15658
15658
|
}
|
|
15659
|
-
var extension2 = extname("x." +
|
|
15659
|
+
var extension2 = extname("x." + path3).toLowerCase().substr(1);
|
|
15660
15660
|
if (!extension2) {
|
|
15661
15661
|
return false;
|
|
15662
15662
|
}
|
|
@@ -16084,7 +16084,7 @@ var require_shams = __commonJS({
|
|
|
16084
16084
|
return true;
|
|
16085
16085
|
}
|
|
16086
16086
|
var obj = {};
|
|
16087
|
-
var sym = Symbol("test");
|
|
16087
|
+
var sym = /* @__PURE__ */ Symbol("test");
|
|
16088
16088
|
var symObj = Object(sym);
|
|
16089
16089
|
if (typeof sym === "string") {
|
|
16090
16090
|
return false;
|
|
@@ -16143,7 +16143,7 @@ var require_has_symbols = __commonJS({
|
|
|
16143
16143
|
if (typeof origSymbol("foo") !== "symbol") {
|
|
16144
16144
|
return false;
|
|
16145
16145
|
}
|
|
16146
|
-
if (typeof Symbol("bar") !== "symbol") {
|
|
16146
|
+
if (typeof /* @__PURE__ */ Symbol("bar") !== "symbol") {
|
|
16147
16147
|
return false;
|
|
16148
16148
|
}
|
|
16149
16149
|
return hasSymbolSham();
|
|
@@ -16761,13 +16761,13 @@ var require_form_data = __commonJS({
|
|
|
16761
16761
|
"use strict";
|
|
16762
16762
|
var CombinedStream = require_combined_stream();
|
|
16763
16763
|
var util4 = __require("util");
|
|
16764
|
-
var
|
|
16764
|
+
var path3 = __require("path");
|
|
16765
16765
|
var http3 = __require("http");
|
|
16766
16766
|
var https2 = __require("https");
|
|
16767
16767
|
var parseUrl = __require("url").parse;
|
|
16768
|
-
var
|
|
16768
|
+
var fs3 = __require("fs");
|
|
16769
16769
|
var Stream = __require("stream").Stream;
|
|
16770
|
-
var
|
|
16770
|
+
var crypto3 = __require("crypto");
|
|
16771
16771
|
var mime = require_mime_types();
|
|
16772
16772
|
var asynckit = require_asynckit();
|
|
16773
16773
|
var setToStringTag = require_es_set_tostringtag();
|
|
@@ -16832,7 +16832,7 @@ var require_form_data = __commonJS({
|
|
|
16832
16832
|
if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
|
|
16833
16833
|
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
16834
16834
|
} else {
|
|
16835
|
-
|
|
16835
|
+
fs3.stat(value.path, function(err, stat) {
|
|
16836
16836
|
if (err) {
|
|
16837
16837
|
callback(err);
|
|
16838
16838
|
return;
|
|
@@ -16889,11 +16889,11 @@ var require_form_data = __commonJS({
|
|
|
16889
16889
|
FormData3.prototype._getContentDisposition = function(value, options) {
|
|
16890
16890
|
var filename;
|
|
16891
16891
|
if (typeof options.filepath === "string") {
|
|
16892
|
-
filename =
|
|
16892
|
+
filename = path3.normalize(options.filepath).replace(/\\/g, "/");
|
|
16893
16893
|
} else if (options.filename || value && (value.name || value.path)) {
|
|
16894
|
-
filename =
|
|
16894
|
+
filename = path3.basename(options.filename || value && (value.name || value.path));
|
|
16895
16895
|
} else if (value && value.readable && hasOwn(value, "httpVersion")) {
|
|
16896
|
-
filename =
|
|
16896
|
+
filename = path3.basename(value.client._httpMessage.path || "");
|
|
16897
16897
|
}
|
|
16898
16898
|
if (filename) {
|
|
16899
16899
|
return 'filename="' + filename + '"';
|
|
@@ -16973,7 +16973,7 @@ var require_form_data = __commonJS({
|
|
|
16973
16973
|
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
|
16974
16974
|
};
|
|
16975
16975
|
FormData3.prototype._generateBoundary = function() {
|
|
16976
|
-
this._boundary = "--------------------------" +
|
|
16976
|
+
this._boundary = "--------------------------" + crypto3.randomBytes(12).toString("hex");
|
|
16977
16977
|
};
|
|
16978
16978
|
FormData3.prototype.getLengthSync = function() {
|
|
16979
16979
|
var knownLength = this._overheadLength + this._valueLength;
|
|
@@ -17624,7 +17624,7 @@ var require_has_flag = __commonJS({
|
|
|
17624
17624
|
var require_supports_color = __commonJS({
|
|
17625
17625
|
"../node_modules/supports-color/index.js"(exports, module) {
|
|
17626
17626
|
"use strict";
|
|
17627
|
-
var
|
|
17627
|
+
var os2 = __require("os");
|
|
17628
17628
|
var tty = __require("tty");
|
|
17629
17629
|
var hasFlag = require_has_flag();
|
|
17630
17630
|
var { env } = process;
|
|
@@ -17681,7 +17681,7 @@ var require_supports_color = __commonJS({
|
|
|
17681
17681
|
return min;
|
|
17682
17682
|
}
|
|
17683
17683
|
if (process.platform === "win32") {
|
|
17684
|
-
const osRelease =
|
|
17684
|
+
const osRelease = os2.release().split(".");
|
|
17685
17685
|
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
17686
17686
|
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
17687
17687
|
}
|
|
@@ -18437,8 +18437,8 @@ var require_follow_redirects = __commonJS({
|
|
|
18437
18437
|
|
|
18438
18438
|
// src/index.ts
|
|
18439
18439
|
import { realpathSync } from "node:fs";
|
|
18440
|
-
import * as
|
|
18441
|
-
import * as
|
|
18440
|
+
import * as fs2 from "node:fs/promises";
|
|
18441
|
+
import * as path2 from "node:path";
|
|
18442
18442
|
import { fileURLToPath } from "node:url";
|
|
18443
18443
|
|
|
18444
18444
|
// ../packages/shared/dist/errors.js
|
|
@@ -19344,7 +19344,7 @@ function $constructor(name, initializer3, params) {
|
|
|
19344
19344
|
Object.defineProperty(_, "name", { value: name });
|
|
19345
19345
|
return _;
|
|
19346
19346
|
}
|
|
19347
|
-
var $brand = Symbol("zod_brand");
|
|
19347
|
+
var $brand = /* @__PURE__ */ Symbol("zod_brand");
|
|
19348
19348
|
var $ZodAsyncError = class extends Error {
|
|
19349
19349
|
constructor() {
|
|
19350
19350
|
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
@@ -19491,7 +19491,7 @@ function floatSafeRemainder(val, step) {
|
|
|
19491
19491
|
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
19492
19492
|
return valInt % stepInt / 10 ** decCount;
|
|
19493
19493
|
}
|
|
19494
|
-
var EVALUATING = Symbol("evaluating");
|
|
19494
|
+
var EVALUATING = /* @__PURE__ */ Symbol("evaluating");
|
|
19495
19495
|
function defineLazy(object3, key, getter) {
|
|
19496
19496
|
let value = void 0;
|
|
19497
19497
|
Object.defineProperty(object3, key, {
|
|
@@ -19536,10 +19536,10 @@ function mergeDefs(...defs) {
|
|
|
19536
19536
|
function cloneDef(schema) {
|
|
19537
19537
|
return mergeDefs(schema._zod.def);
|
|
19538
19538
|
}
|
|
19539
|
-
function getElementAtPath(obj,
|
|
19540
|
-
if (!
|
|
19539
|
+
function getElementAtPath(obj, path3) {
|
|
19540
|
+
if (!path3)
|
|
19541
19541
|
return obj;
|
|
19542
|
-
return
|
|
19542
|
+
return path3.reduce((acc, key) => acc?.[key], obj);
|
|
19543
19543
|
}
|
|
19544
19544
|
function promiseAllObject(promisesObj) {
|
|
19545
19545
|
const keys = Object.keys(promisesObj);
|
|
@@ -19922,11 +19922,11 @@ function aborted(x, startIndex = 0) {
|
|
|
19922
19922
|
}
|
|
19923
19923
|
return false;
|
|
19924
19924
|
}
|
|
19925
|
-
function prefixIssues(
|
|
19925
|
+
function prefixIssues(path3, issues) {
|
|
19926
19926
|
return issues.map((iss) => {
|
|
19927
19927
|
var _a2;
|
|
19928
19928
|
(_a2 = iss).path ?? (_a2.path = []);
|
|
19929
|
-
iss.path.unshift(
|
|
19929
|
+
iss.path.unshift(path3);
|
|
19930
19930
|
return iss;
|
|
19931
19931
|
});
|
|
19932
19932
|
}
|
|
@@ -20109,7 +20109,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
|
|
|
20109
20109
|
}
|
|
20110
20110
|
function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
20111
20111
|
const result = { errors: [] };
|
|
20112
|
-
const processError = (error49,
|
|
20112
|
+
const processError = (error49, path3 = []) => {
|
|
20113
20113
|
var _a2, _b;
|
|
20114
20114
|
for (const issue2 of error49.issues) {
|
|
20115
20115
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -20119,7 +20119,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
|
20119
20119
|
} else if (issue2.code === "invalid_element") {
|
|
20120
20120
|
processError({ issues: issue2.issues }, issue2.path);
|
|
20121
20121
|
} else {
|
|
20122
|
-
const fullpath = [...
|
|
20122
|
+
const fullpath = [...path3, ...issue2.path];
|
|
20123
20123
|
if (fullpath.length === 0) {
|
|
20124
20124
|
result.errors.push(mapper(issue2));
|
|
20125
20125
|
continue;
|
|
@@ -20151,8 +20151,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
|
|
|
20151
20151
|
}
|
|
20152
20152
|
function toDotPath(_path) {
|
|
20153
20153
|
const segs = [];
|
|
20154
|
-
const
|
|
20155
|
-
for (const seg of
|
|
20154
|
+
const path3 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
20155
|
+
for (const seg of path3) {
|
|
20156
20156
|
if (typeof seg === "number")
|
|
20157
20157
|
segs.push(`[${seg}]`);
|
|
20158
20158
|
else if (typeof seg === "symbol")
|
|
@@ -28564,8 +28564,8 @@ function yo_default() {
|
|
|
28564
28564
|
|
|
28565
28565
|
// ../node_modules/zod/v4/core/registries.js
|
|
28566
28566
|
var _a;
|
|
28567
|
-
var $output = Symbol("ZodOutput");
|
|
28568
|
-
var $input = Symbol("ZodInput");
|
|
28567
|
+
var $output = /* @__PURE__ */ Symbol("ZodOutput");
|
|
28568
|
+
var $input = /* @__PURE__ */ Symbol("ZodInput");
|
|
28569
28569
|
var $ZodRegistry = class {
|
|
28570
28570
|
constructor() {
|
|
28571
28571
|
this._map = /* @__PURE__ */ new WeakMap();
|
|
@@ -32129,13 +32129,13 @@ function resolveRef(ref, ctx) {
|
|
|
32129
32129
|
if (!ref.startsWith("#")) {
|
|
32130
32130
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
32131
32131
|
}
|
|
32132
|
-
const
|
|
32133
|
-
if (
|
|
32132
|
+
const path3 = ref.slice(1).split("/").filter(Boolean);
|
|
32133
|
+
if (path3.length === 0) {
|
|
32134
32134
|
return ctx.rootSchema;
|
|
32135
32135
|
}
|
|
32136
32136
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
32137
|
-
if (
|
|
32138
|
-
const key =
|
|
32137
|
+
if (path3[0] === defsKey) {
|
|
32138
|
+
const key = path3[1];
|
|
32139
32139
|
if (!key || !ctx.defs[key]) {
|
|
32140
32140
|
throw new Error(`Reference not found: ${ref}`);
|
|
32141
32141
|
}
|
|
@@ -32547,6 +32547,88 @@ var paginationSchema = z2.object({
|
|
|
32547
32547
|
offset: z2.number().int().min(0).default(0).describe("Number of results to skip for pagination (default 0)")
|
|
32548
32548
|
});
|
|
32549
32549
|
|
|
32550
|
+
// ../packages/shared/dist/cache.js
|
|
32551
|
+
import * as fs from "node:fs/promises";
|
|
32552
|
+
import * as path from "node:path";
|
|
32553
|
+
import * as os from "node:os";
|
|
32554
|
+
import * as crypto from "node:crypto";
|
|
32555
|
+
var PersistentCache = class {
|
|
32556
|
+
cacheDir;
|
|
32557
|
+
memoryCache = /* @__PURE__ */ new Map();
|
|
32558
|
+
constructor(namespace) {
|
|
32559
|
+
const baseDir = process.env.FRE4X_CACHE_DIR || path.join(os.homedir(), ".fre4x-cache");
|
|
32560
|
+
this.cacheDir = path.join(baseDir, namespace);
|
|
32561
|
+
}
|
|
32562
|
+
async ensureDir() {
|
|
32563
|
+
await fs.mkdir(this.cacheDir, { recursive: true });
|
|
32564
|
+
}
|
|
32565
|
+
getFilePath(key) {
|
|
32566
|
+
const safeKey = crypto.createHash("sha256").update(key).digest("hex");
|
|
32567
|
+
return path.join(this.cacheDir, `${safeKey}.json`);
|
|
32568
|
+
}
|
|
32569
|
+
async get(key) {
|
|
32570
|
+
const now = Date.now();
|
|
32571
|
+
const memEntry = this.memoryCache.get(key);
|
|
32572
|
+
if (memEntry) {
|
|
32573
|
+
if (now - memEntry.timestamp < memEntry.ttlMs) {
|
|
32574
|
+
return memEntry.data;
|
|
32575
|
+
}
|
|
32576
|
+
this.memoryCache.delete(key);
|
|
32577
|
+
}
|
|
32578
|
+
const fpath = this.getFilePath(key);
|
|
32579
|
+
try {
|
|
32580
|
+
const raw = await fs.readFile(fpath, "utf8");
|
|
32581
|
+
const entry = JSON.parse(raw);
|
|
32582
|
+
if (now - entry.timestamp < entry.ttlMs) {
|
|
32583
|
+
this.memoryCache.set(key, entry);
|
|
32584
|
+
return entry.data;
|
|
32585
|
+
}
|
|
32586
|
+
await fs.unlink(fpath).catch(() => {
|
|
32587
|
+
});
|
|
32588
|
+
} catch {
|
|
32589
|
+
}
|
|
32590
|
+
return null;
|
|
32591
|
+
}
|
|
32592
|
+
async set(key, data, ttlMs) {
|
|
32593
|
+
const entry = {
|
|
32594
|
+
data,
|
|
32595
|
+
timestamp: Date.now(),
|
|
32596
|
+
ttlMs
|
|
32597
|
+
};
|
|
32598
|
+
this.memoryCache.set(key, entry);
|
|
32599
|
+
try {
|
|
32600
|
+
await this.ensureDir();
|
|
32601
|
+
const fpath = this.getFilePath(key);
|
|
32602
|
+
await fs.writeFile(fpath, JSON.stringify(entry), "utf8");
|
|
32603
|
+
} catch (error48) {
|
|
32604
|
+
console.error(`[Cache] Failed to save to disk: ${error48}`);
|
|
32605
|
+
}
|
|
32606
|
+
}
|
|
32607
|
+
async wrap(key, ttlMs, fetchFn) {
|
|
32608
|
+
const cached2 = await this.get(key);
|
|
32609
|
+
if (cached2 !== null)
|
|
32610
|
+
return cached2;
|
|
32611
|
+
const data = await fetchFn();
|
|
32612
|
+
await this.set(key, data, ttlMs);
|
|
32613
|
+
return data;
|
|
32614
|
+
}
|
|
32615
|
+
async clear() {
|
|
32616
|
+
this.memoryCache.clear();
|
|
32617
|
+
try {
|
|
32618
|
+
await fs.rm(this.cacheDir, { recursive: true, force: true });
|
|
32619
|
+
} catch {
|
|
32620
|
+
}
|
|
32621
|
+
}
|
|
32622
|
+
};
|
|
32623
|
+
|
|
32624
|
+
// ../packages/shared/dist/package.js
|
|
32625
|
+
import { createRequire as createJsonRequire } from "node:module";
|
|
32626
|
+
function getPackageVersion(moduleUrl) {
|
|
32627
|
+
const require2 = createJsonRequire(moduleUrl);
|
|
32628
|
+
const packageJson = require2("../package.json");
|
|
32629
|
+
return packageJson.version ?? "0.0.0";
|
|
32630
|
+
}
|
|
32631
|
+
|
|
32550
32632
|
// ../node_modules/zod/v3/helpers/util.js
|
|
32551
32633
|
var util;
|
|
32552
32634
|
(function(util4) {
|
|
@@ -32906,8 +32988,8 @@ function getErrorMap2() {
|
|
|
32906
32988
|
|
|
32907
32989
|
// ../node_modules/zod/v3/helpers/parseUtil.js
|
|
32908
32990
|
var makeIssue = (params) => {
|
|
32909
|
-
const { data, path:
|
|
32910
|
-
const fullPath = [...
|
|
32991
|
+
const { data, path: path3, errorMaps, issueData } = params;
|
|
32992
|
+
const fullPath = [...path3, ...issueData.path || []];
|
|
32911
32993
|
const fullIssue = {
|
|
32912
32994
|
...issueData,
|
|
32913
32995
|
path: fullPath
|
|
@@ -33022,11 +33104,11 @@ var errorUtil;
|
|
|
33022
33104
|
|
|
33023
33105
|
// ../node_modules/zod/v3/types.js
|
|
33024
33106
|
var ParseInputLazyPath = class {
|
|
33025
|
-
constructor(parent, value,
|
|
33107
|
+
constructor(parent, value, path3, key) {
|
|
33026
33108
|
this._cachedPath = [];
|
|
33027
33109
|
this.parent = parent;
|
|
33028
33110
|
this.data = value;
|
|
33029
|
-
this._path =
|
|
33111
|
+
this._path = path3;
|
|
33030
33112
|
this._key = key;
|
|
33031
33113
|
}
|
|
33032
33114
|
get path() {
|
|
@@ -36255,7 +36337,6 @@ ZodNaN2.create = (params) => {
|
|
|
36255
36337
|
...processCreateParams(params)
|
|
36256
36338
|
});
|
|
36257
36339
|
};
|
|
36258
|
-
var BRAND = Symbol("zod_brand");
|
|
36259
36340
|
var ZodBranded = class extends ZodType2 {
|
|
36260
36341
|
_parse(input) {
|
|
36261
36342
|
const { ctx } = this._processInputParams(input);
|
|
@@ -36424,11 +36505,67 @@ var nullableType = ZodNullable2.create;
|
|
|
36424
36505
|
var preprocessType = ZodEffects.createWithPreprocess;
|
|
36425
36506
|
var pipelineType = ZodPipeline.create;
|
|
36426
36507
|
|
|
36508
|
+
// ../node_modules/zod/v4/mini/schemas.js
|
|
36509
|
+
var ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
|
|
36510
|
+
if (!inst._zod)
|
|
36511
|
+
throw new Error("Uninitialized schema in ZodMiniType.");
|
|
36512
|
+
$ZodType.init(inst, def);
|
|
36513
|
+
inst.def = def;
|
|
36514
|
+
inst.type = def.type;
|
|
36515
|
+
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
36516
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
36517
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
36518
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
36519
|
+
inst.check = (...checks) => {
|
|
36520
|
+
return inst.clone({
|
|
36521
|
+
...def,
|
|
36522
|
+
checks: [
|
|
36523
|
+
...def.checks ?? [],
|
|
36524
|
+
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch)
|
|
36525
|
+
]
|
|
36526
|
+
}, { parent: true });
|
|
36527
|
+
};
|
|
36528
|
+
inst.with = inst.check;
|
|
36529
|
+
inst.clone = (_def, params) => clone(inst, _def, params);
|
|
36530
|
+
inst.brand = () => inst;
|
|
36531
|
+
inst.register = ((reg, meta3) => {
|
|
36532
|
+
reg.add(inst, meta3);
|
|
36533
|
+
return inst;
|
|
36534
|
+
});
|
|
36535
|
+
inst.apply = (fn) => fn(inst);
|
|
36536
|
+
});
|
|
36537
|
+
var ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
|
|
36538
|
+
$ZodObject.init(inst, def);
|
|
36539
|
+
ZodMiniType.init(inst, def);
|
|
36540
|
+
defineLazy(inst, "shape", () => def.shape);
|
|
36541
|
+
});
|
|
36542
|
+
// @__NO_SIDE_EFFECTS__
|
|
36543
|
+
function object2(shape, params) {
|
|
36544
|
+
const def = {
|
|
36545
|
+
type: "object",
|
|
36546
|
+
shape: shape ?? {},
|
|
36547
|
+
...normalizeParams(params)
|
|
36548
|
+
};
|
|
36549
|
+
return new ZodMiniObject(def);
|
|
36550
|
+
}
|
|
36551
|
+
|
|
36427
36552
|
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
36428
36553
|
function isZ4Schema(s) {
|
|
36429
36554
|
const schema = s;
|
|
36430
36555
|
return !!schema._zod;
|
|
36431
36556
|
}
|
|
36557
|
+
function objectFromShape(shape) {
|
|
36558
|
+
const values = Object.values(shape);
|
|
36559
|
+
if (values.length === 0)
|
|
36560
|
+
return object2({});
|
|
36561
|
+
const allV4 = values.every(isZ4Schema);
|
|
36562
|
+
const allV3 = values.every((s) => !isZ4Schema(s));
|
|
36563
|
+
if (allV4)
|
|
36564
|
+
return object2(shape);
|
|
36565
|
+
if (allV3)
|
|
36566
|
+
return objectType(shape);
|
|
36567
|
+
throw new Error("Mixed Zod versions detected in object shape.");
|
|
36568
|
+
}
|
|
36432
36569
|
function safeParse3(schema, data) {
|
|
36433
36570
|
if (isZ4Schema(schema)) {
|
|
36434
36571
|
const result2 = safeParse(schema, data);
|
|
@@ -36438,6 +36575,15 @@ function safeParse3(schema, data) {
|
|
|
36438
36575
|
const result = v3Schema.safeParse(data);
|
|
36439
36576
|
return result;
|
|
36440
36577
|
}
|
|
36578
|
+
async function safeParseAsync3(schema, data) {
|
|
36579
|
+
if (isZ4Schema(schema)) {
|
|
36580
|
+
const result2 = await safeParseAsync(schema, data);
|
|
36581
|
+
return result2;
|
|
36582
|
+
}
|
|
36583
|
+
const v3Schema = schema;
|
|
36584
|
+
const result = await v3Schema.safeParseAsync(data);
|
|
36585
|
+
return result;
|
|
36586
|
+
}
|
|
36441
36587
|
function getObjectShape(schema) {
|
|
36442
36588
|
if (!schema)
|
|
36443
36589
|
return void 0;
|
|
@@ -36460,6 +36606,66 @@ function getObjectShape(schema) {
|
|
|
36460
36606
|
}
|
|
36461
36607
|
return rawShape;
|
|
36462
36608
|
}
|
|
36609
|
+
function normalizeObjectSchema(schema) {
|
|
36610
|
+
if (!schema)
|
|
36611
|
+
return void 0;
|
|
36612
|
+
if (typeof schema === "object") {
|
|
36613
|
+
const asV3 = schema;
|
|
36614
|
+
const asV4 = schema;
|
|
36615
|
+
if (!asV3._def && !asV4._zod) {
|
|
36616
|
+
const values = Object.values(schema);
|
|
36617
|
+
if (values.length > 0 && values.every((v) => typeof v === "object" && v !== null && (v._def !== void 0 || v._zod !== void 0 || typeof v.parse === "function"))) {
|
|
36618
|
+
return objectFromShape(schema);
|
|
36619
|
+
}
|
|
36620
|
+
}
|
|
36621
|
+
}
|
|
36622
|
+
if (isZ4Schema(schema)) {
|
|
36623
|
+
const v4Schema = schema;
|
|
36624
|
+
const def = v4Schema._zod?.def;
|
|
36625
|
+
if (def && (def.type === "object" || def.shape !== void 0)) {
|
|
36626
|
+
return schema;
|
|
36627
|
+
}
|
|
36628
|
+
} else {
|
|
36629
|
+
const v3Schema = schema;
|
|
36630
|
+
if (v3Schema.shape !== void 0) {
|
|
36631
|
+
return schema;
|
|
36632
|
+
}
|
|
36633
|
+
}
|
|
36634
|
+
return void 0;
|
|
36635
|
+
}
|
|
36636
|
+
function getParseErrorMessage(error48) {
|
|
36637
|
+
if (error48 && typeof error48 === "object") {
|
|
36638
|
+
if ("message" in error48 && typeof error48.message === "string") {
|
|
36639
|
+
return error48.message;
|
|
36640
|
+
}
|
|
36641
|
+
if ("issues" in error48 && Array.isArray(error48.issues) && error48.issues.length > 0) {
|
|
36642
|
+
const firstIssue = error48.issues[0];
|
|
36643
|
+
if (firstIssue && typeof firstIssue === "object" && "message" in firstIssue) {
|
|
36644
|
+
return String(firstIssue.message);
|
|
36645
|
+
}
|
|
36646
|
+
}
|
|
36647
|
+
try {
|
|
36648
|
+
return JSON.stringify(error48);
|
|
36649
|
+
} catch {
|
|
36650
|
+
return String(error48);
|
|
36651
|
+
}
|
|
36652
|
+
}
|
|
36653
|
+
return String(error48);
|
|
36654
|
+
}
|
|
36655
|
+
function getSchemaDescription(schema) {
|
|
36656
|
+
return schema.description;
|
|
36657
|
+
}
|
|
36658
|
+
function isSchemaOptional(schema) {
|
|
36659
|
+
if (isZ4Schema(schema)) {
|
|
36660
|
+
const v4Schema = schema;
|
|
36661
|
+
return v4Schema._zod?.def?.type === "optional";
|
|
36662
|
+
}
|
|
36663
|
+
const v3Schema = schema;
|
|
36664
|
+
if (typeof schema.isOptional === "function") {
|
|
36665
|
+
return schema.isOptional();
|
|
36666
|
+
}
|
|
36667
|
+
return v3Schema._def?.typeName === "ZodOptional";
|
|
36668
|
+
}
|
|
36463
36669
|
function getLiteralValue(schema) {
|
|
36464
36670
|
if (isZ4Schema(schema)) {
|
|
36465
36671
|
const v4Schema = schema;
|
|
@@ -37848,6 +38054,18 @@ var CompleteRequestSchema = RequestSchema.extend({
|
|
|
37848
38054
|
method: literal("completion/complete"),
|
|
37849
38055
|
params: CompleteRequestParamsSchema
|
|
37850
38056
|
});
|
|
38057
|
+
function assertCompleteRequestPrompt(request) {
|
|
38058
|
+
if (request.params.ref.type !== "ref/prompt") {
|
|
38059
|
+
throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`);
|
|
38060
|
+
}
|
|
38061
|
+
void request;
|
|
38062
|
+
}
|
|
38063
|
+
function assertCompleteRequestResourceTemplate(request) {
|
|
38064
|
+
if (request.params.ref.type !== "ref/resource") {
|
|
38065
|
+
throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`);
|
|
38066
|
+
}
|
|
38067
|
+
void request;
|
|
38068
|
+
}
|
|
37851
38069
|
var CompleteResultSchema = ResultSchema.extend({
|
|
37852
38070
|
completion: looseObject({
|
|
37853
38071
|
/**
|
|
@@ -37999,12 +38217,1311 @@ function isTerminal(status) {
|
|
|
37999
38217
|
}
|
|
38000
38218
|
|
|
38001
38219
|
// ../node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
38002
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
38220
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
38221
|
+
var defaultOptions = {
|
|
38222
|
+
name: void 0,
|
|
38223
|
+
$refStrategy: "root",
|
|
38224
|
+
basePath: ["#"],
|
|
38225
|
+
effectStrategy: "input",
|
|
38226
|
+
pipeStrategy: "all",
|
|
38227
|
+
dateStrategy: "format:date-time",
|
|
38228
|
+
mapStrategy: "entries",
|
|
38229
|
+
removeAdditionalStrategy: "passthrough",
|
|
38230
|
+
allowedAdditionalProperties: true,
|
|
38231
|
+
rejectedAdditionalProperties: false,
|
|
38232
|
+
definitionPath: "definitions",
|
|
38233
|
+
target: "jsonSchema7",
|
|
38234
|
+
strictUnions: false,
|
|
38235
|
+
definitions: {},
|
|
38236
|
+
errorMessages: false,
|
|
38237
|
+
markdownDescription: false,
|
|
38238
|
+
patternStrategy: "escape",
|
|
38239
|
+
applyRegexFlags: false,
|
|
38240
|
+
emailStrategy: "format:email",
|
|
38241
|
+
base64Strategy: "contentEncoding:base64",
|
|
38242
|
+
nameStrategy: "ref",
|
|
38243
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
38244
|
+
};
|
|
38245
|
+
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
38246
|
+
...defaultOptions,
|
|
38247
|
+
name: options
|
|
38248
|
+
} : {
|
|
38249
|
+
...defaultOptions,
|
|
38250
|
+
...options
|
|
38251
|
+
};
|
|
38252
|
+
|
|
38253
|
+
// ../node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
38254
|
+
var getRefs = (options) => {
|
|
38255
|
+
const _options = getDefaultOptions(options);
|
|
38256
|
+
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
38257
|
+
return {
|
|
38258
|
+
..._options,
|
|
38259
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
38260
|
+
currentPath,
|
|
38261
|
+
propertyPath: void 0,
|
|
38262
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
38263
|
+
def._def,
|
|
38264
|
+
{
|
|
38265
|
+
def: def._def,
|
|
38266
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
38267
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
38268
|
+
jsonSchema: void 0
|
|
38269
|
+
}
|
|
38270
|
+
]))
|
|
38271
|
+
};
|
|
38272
|
+
};
|
|
38273
|
+
|
|
38274
|
+
// ../node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
38275
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
38276
|
+
if (!refs?.errorMessages)
|
|
38277
|
+
return;
|
|
38278
|
+
if (errorMessage) {
|
|
38279
|
+
res.errorMessage = {
|
|
38280
|
+
...res.errorMessage,
|
|
38281
|
+
[key]: errorMessage
|
|
38282
|
+
};
|
|
38283
|
+
}
|
|
38284
|
+
}
|
|
38285
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
38286
|
+
res[key] = value;
|
|
38287
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
38288
|
+
}
|
|
38289
|
+
|
|
38290
|
+
// ../node_modules/zod-to-json-schema/dist/esm/getRelativePath.js
|
|
38291
|
+
var getRelativePath = (pathA, pathB) => {
|
|
38292
|
+
let i = 0;
|
|
38293
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
38294
|
+
if (pathA[i] !== pathB[i])
|
|
38295
|
+
break;
|
|
38296
|
+
}
|
|
38297
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
38298
|
+
};
|
|
38299
|
+
|
|
38300
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
38301
|
+
function parseAnyDef(refs) {
|
|
38302
|
+
if (refs.target !== "openAi") {
|
|
38303
|
+
return {};
|
|
38304
|
+
}
|
|
38305
|
+
const anyDefinitionPath = [
|
|
38306
|
+
...refs.basePath,
|
|
38307
|
+
refs.definitionPath,
|
|
38308
|
+
refs.openAiAnyTypeName
|
|
38309
|
+
];
|
|
38310
|
+
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
38311
|
+
return {
|
|
38312
|
+
$ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
38313
|
+
};
|
|
38314
|
+
}
|
|
38315
|
+
|
|
38316
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
38317
|
+
function parseArrayDef(def, refs) {
|
|
38318
|
+
const res = {
|
|
38319
|
+
type: "array"
|
|
38320
|
+
};
|
|
38321
|
+
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind2.ZodAny) {
|
|
38322
|
+
res.items = parseDef(def.type._def, {
|
|
38323
|
+
...refs,
|
|
38324
|
+
currentPath: [...refs.currentPath, "items"]
|
|
38325
|
+
});
|
|
38326
|
+
}
|
|
38327
|
+
if (def.minLength) {
|
|
38328
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
38329
|
+
}
|
|
38330
|
+
if (def.maxLength) {
|
|
38331
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
38332
|
+
}
|
|
38333
|
+
if (def.exactLength) {
|
|
38334
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
38335
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
38336
|
+
}
|
|
38337
|
+
return res;
|
|
38338
|
+
}
|
|
38339
|
+
|
|
38340
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
38341
|
+
function parseBigintDef(def, refs) {
|
|
38342
|
+
const res = {
|
|
38343
|
+
type: "integer",
|
|
38344
|
+
format: "int64"
|
|
38345
|
+
};
|
|
38346
|
+
if (!def.checks)
|
|
38347
|
+
return res;
|
|
38348
|
+
for (const check2 of def.checks) {
|
|
38349
|
+
switch (check2.kind) {
|
|
38350
|
+
case "min":
|
|
38351
|
+
if (refs.target === "jsonSchema7") {
|
|
38352
|
+
if (check2.inclusive) {
|
|
38353
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
38354
|
+
} else {
|
|
38355
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check2.value, check2.message, refs);
|
|
38356
|
+
}
|
|
38357
|
+
} else {
|
|
38358
|
+
if (!check2.inclusive) {
|
|
38359
|
+
res.exclusiveMinimum = true;
|
|
38360
|
+
}
|
|
38361
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
38362
|
+
}
|
|
38363
|
+
break;
|
|
38364
|
+
case "max":
|
|
38365
|
+
if (refs.target === "jsonSchema7") {
|
|
38366
|
+
if (check2.inclusive) {
|
|
38367
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
38368
|
+
} else {
|
|
38369
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check2.value, check2.message, refs);
|
|
38370
|
+
}
|
|
38371
|
+
} else {
|
|
38372
|
+
if (!check2.inclusive) {
|
|
38373
|
+
res.exclusiveMaximum = true;
|
|
38374
|
+
}
|
|
38375
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
38376
|
+
}
|
|
38377
|
+
break;
|
|
38378
|
+
case "multipleOf":
|
|
38379
|
+
setResponseValueAndErrors(res, "multipleOf", check2.value, check2.message, refs);
|
|
38380
|
+
break;
|
|
38381
|
+
}
|
|
38382
|
+
}
|
|
38383
|
+
return res;
|
|
38384
|
+
}
|
|
38385
|
+
|
|
38386
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
38387
|
+
function parseBooleanDef() {
|
|
38388
|
+
return {
|
|
38389
|
+
type: "boolean"
|
|
38390
|
+
};
|
|
38391
|
+
}
|
|
38392
|
+
|
|
38393
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
38394
|
+
function parseBrandedDef(_def, refs) {
|
|
38395
|
+
return parseDef(_def.type._def, refs);
|
|
38396
|
+
}
|
|
38397
|
+
|
|
38398
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
38399
|
+
var parseCatchDef = (def, refs) => {
|
|
38400
|
+
return parseDef(def.innerType._def, refs);
|
|
38401
|
+
};
|
|
38402
|
+
|
|
38403
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
38404
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
38405
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
38406
|
+
if (Array.isArray(strategy)) {
|
|
38407
|
+
return {
|
|
38408
|
+
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
38409
|
+
};
|
|
38410
|
+
}
|
|
38411
|
+
switch (strategy) {
|
|
38412
|
+
case "string":
|
|
38413
|
+
case "format:date-time":
|
|
38414
|
+
return {
|
|
38415
|
+
type: "string",
|
|
38416
|
+
format: "date-time"
|
|
38417
|
+
};
|
|
38418
|
+
case "format:date":
|
|
38419
|
+
return {
|
|
38420
|
+
type: "string",
|
|
38421
|
+
format: "date"
|
|
38422
|
+
};
|
|
38423
|
+
case "integer":
|
|
38424
|
+
return integerDateParser(def, refs);
|
|
38425
|
+
}
|
|
38426
|
+
}
|
|
38427
|
+
var integerDateParser = (def, refs) => {
|
|
38428
|
+
const res = {
|
|
38429
|
+
type: "integer",
|
|
38430
|
+
format: "unix-time"
|
|
38431
|
+
};
|
|
38432
|
+
if (refs.target === "openApi3") {
|
|
38433
|
+
return res;
|
|
38434
|
+
}
|
|
38435
|
+
for (const check2 of def.checks) {
|
|
38436
|
+
switch (check2.kind) {
|
|
38437
|
+
case "min":
|
|
38438
|
+
setResponseValueAndErrors(
|
|
38439
|
+
res,
|
|
38440
|
+
"minimum",
|
|
38441
|
+
check2.value,
|
|
38442
|
+
// This is in milliseconds
|
|
38443
|
+
check2.message,
|
|
38444
|
+
refs
|
|
38445
|
+
);
|
|
38446
|
+
break;
|
|
38447
|
+
case "max":
|
|
38448
|
+
setResponseValueAndErrors(
|
|
38449
|
+
res,
|
|
38450
|
+
"maximum",
|
|
38451
|
+
check2.value,
|
|
38452
|
+
// This is in milliseconds
|
|
38453
|
+
check2.message,
|
|
38454
|
+
refs
|
|
38455
|
+
);
|
|
38456
|
+
break;
|
|
38457
|
+
}
|
|
38458
|
+
}
|
|
38459
|
+
return res;
|
|
38460
|
+
};
|
|
38461
|
+
|
|
38462
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
38463
|
+
function parseDefaultDef(_def, refs) {
|
|
38464
|
+
return {
|
|
38465
|
+
...parseDef(_def.innerType._def, refs),
|
|
38466
|
+
default: _def.defaultValue()
|
|
38467
|
+
};
|
|
38468
|
+
}
|
|
38469
|
+
|
|
38470
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
38471
|
+
function parseEffectsDef(_def, refs) {
|
|
38472
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef(refs);
|
|
38473
|
+
}
|
|
38474
|
+
|
|
38475
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
38476
|
+
function parseEnumDef(def) {
|
|
38477
|
+
return {
|
|
38478
|
+
type: "string",
|
|
38479
|
+
enum: Array.from(def.values)
|
|
38480
|
+
};
|
|
38481
|
+
}
|
|
38482
|
+
|
|
38483
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
38484
|
+
var isJsonSchema7AllOfType = (type) => {
|
|
38485
|
+
if ("type" in type && type.type === "string")
|
|
38486
|
+
return false;
|
|
38487
|
+
return "allOf" in type;
|
|
38488
|
+
};
|
|
38489
|
+
function parseIntersectionDef(def, refs) {
|
|
38490
|
+
const allOf = [
|
|
38491
|
+
parseDef(def.left._def, {
|
|
38492
|
+
...refs,
|
|
38493
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
38494
|
+
}),
|
|
38495
|
+
parseDef(def.right._def, {
|
|
38496
|
+
...refs,
|
|
38497
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
38498
|
+
})
|
|
38499
|
+
].filter((x) => !!x);
|
|
38500
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
38501
|
+
const mergedAllOf = [];
|
|
38502
|
+
allOf.forEach((schema) => {
|
|
38503
|
+
if (isJsonSchema7AllOfType(schema)) {
|
|
38504
|
+
mergedAllOf.push(...schema.allOf);
|
|
38505
|
+
if (schema.unevaluatedProperties === void 0) {
|
|
38506
|
+
unevaluatedProperties = void 0;
|
|
38507
|
+
}
|
|
38508
|
+
} else {
|
|
38509
|
+
let nestedSchema = schema;
|
|
38510
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
38511
|
+
const { additionalProperties, ...rest } = schema;
|
|
38512
|
+
nestedSchema = rest;
|
|
38513
|
+
} else {
|
|
38514
|
+
unevaluatedProperties = void 0;
|
|
38515
|
+
}
|
|
38516
|
+
mergedAllOf.push(nestedSchema);
|
|
38517
|
+
}
|
|
38518
|
+
});
|
|
38519
|
+
return mergedAllOf.length ? {
|
|
38520
|
+
allOf: mergedAllOf,
|
|
38521
|
+
...unevaluatedProperties
|
|
38522
|
+
} : void 0;
|
|
38523
|
+
}
|
|
38524
|
+
|
|
38525
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
38526
|
+
function parseLiteralDef(def, refs) {
|
|
38527
|
+
const parsedType2 = typeof def.value;
|
|
38528
|
+
if (parsedType2 !== "bigint" && parsedType2 !== "number" && parsedType2 !== "boolean" && parsedType2 !== "string") {
|
|
38529
|
+
return {
|
|
38530
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
38531
|
+
};
|
|
38532
|
+
}
|
|
38533
|
+
if (refs.target === "openApi3") {
|
|
38534
|
+
return {
|
|
38535
|
+
type: parsedType2 === "bigint" ? "integer" : parsedType2,
|
|
38536
|
+
enum: [def.value]
|
|
38537
|
+
};
|
|
38538
|
+
}
|
|
38539
|
+
return {
|
|
38540
|
+
type: parsedType2 === "bigint" ? "integer" : parsedType2,
|
|
38541
|
+
const: def.value
|
|
38542
|
+
};
|
|
38543
|
+
}
|
|
38003
38544
|
|
|
38004
38545
|
// ../node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
38546
|
+
var emojiRegex2 = void 0;
|
|
38547
|
+
var zodPatterns = {
|
|
38548
|
+
/**
|
|
38549
|
+
* `c` was changed to `[cC]` to replicate /i flag
|
|
38550
|
+
*/
|
|
38551
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
38552
|
+
cuid2: /^[0-9a-z]+$/,
|
|
38553
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
38554
|
+
/**
|
|
38555
|
+
* `a-z` was added to replicate /i flag
|
|
38556
|
+
*/
|
|
38557
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
38558
|
+
/**
|
|
38559
|
+
* Constructed a valid Unicode RegExp
|
|
38560
|
+
*
|
|
38561
|
+
* Lazily instantiate since this type of regex isn't supported
|
|
38562
|
+
* in all envs (e.g. React Native).
|
|
38563
|
+
*
|
|
38564
|
+
* See:
|
|
38565
|
+
* https://github.com/colinhacks/zod/issues/2433
|
|
38566
|
+
* Fix in Zod:
|
|
38567
|
+
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
38568
|
+
*/
|
|
38569
|
+
emoji: () => {
|
|
38570
|
+
if (emojiRegex2 === void 0) {
|
|
38571
|
+
emojiRegex2 = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
38572
|
+
}
|
|
38573
|
+
return emojiRegex2;
|
|
38574
|
+
},
|
|
38575
|
+
/**
|
|
38576
|
+
* Unused
|
|
38577
|
+
*/
|
|
38578
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
38579
|
+
/**
|
|
38580
|
+
* Unused
|
|
38581
|
+
*/
|
|
38582
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
38583
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
38584
|
+
/**
|
|
38585
|
+
* Unused
|
|
38586
|
+
*/
|
|
38587
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
38588
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
38589
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
38590
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
38591
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
38592
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
38593
|
+
};
|
|
38594
|
+
function parseStringDef(def, refs) {
|
|
38595
|
+
const res = {
|
|
38596
|
+
type: "string"
|
|
38597
|
+
};
|
|
38598
|
+
if (def.checks) {
|
|
38599
|
+
for (const check2 of def.checks) {
|
|
38600
|
+
switch (check2.kind) {
|
|
38601
|
+
case "min":
|
|
38602
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value, check2.message, refs);
|
|
38603
|
+
break;
|
|
38604
|
+
case "max":
|
|
38605
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value, check2.message, refs);
|
|
38606
|
+
break;
|
|
38607
|
+
case "email":
|
|
38608
|
+
switch (refs.emailStrategy) {
|
|
38609
|
+
case "format:email":
|
|
38610
|
+
addFormat(res, "email", check2.message, refs);
|
|
38611
|
+
break;
|
|
38612
|
+
case "format:idn-email":
|
|
38613
|
+
addFormat(res, "idn-email", check2.message, refs);
|
|
38614
|
+
break;
|
|
38615
|
+
case "pattern:zod":
|
|
38616
|
+
addPattern(res, zodPatterns.email, check2.message, refs);
|
|
38617
|
+
break;
|
|
38618
|
+
}
|
|
38619
|
+
break;
|
|
38620
|
+
case "url":
|
|
38621
|
+
addFormat(res, "uri", check2.message, refs);
|
|
38622
|
+
break;
|
|
38623
|
+
case "uuid":
|
|
38624
|
+
addFormat(res, "uuid", check2.message, refs);
|
|
38625
|
+
break;
|
|
38626
|
+
case "regex":
|
|
38627
|
+
addPattern(res, check2.regex, check2.message, refs);
|
|
38628
|
+
break;
|
|
38629
|
+
case "cuid":
|
|
38630
|
+
addPattern(res, zodPatterns.cuid, check2.message, refs);
|
|
38631
|
+
break;
|
|
38632
|
+
case "cuid2":
|
|
38633
|
+
addPattern(res, zodPatterns.cuid2, check2.message, refs);
|
|
38634
|
+
break;
|
|
38635
|
+
case "startsWith":
|
|
38636
|
+
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check2.value, refs)}`), check2.message, refs);
|
|
38637
|
+
break;
|
|
38638
|
+
case "endsWith":
|
|
38639
|
+
addPattern(res, RegExp(`${escapeLiteralCheckValue(check2.value, refs)}$`), check2.message, refs);
|
|
38640
|
+
break;
|
|
38641
|
+
case "datetime":
|
|
38642
|
+
addFormat(res, "date-time", check2.message, refs);
|
|
38643
|
+
break;
|
|
38644
|
+
case "date":
|
|
38645
|
+
addFormat(res, "date", check2.message, refs);
|
|
38646
|
+
break;
|
|
38647
|
+
case "time":
|
|
38648
|
+
addFormat(res, "time", check2.message, refs);
|
|
38649
|
+
break;
|
|
38650
|
+
case "duration":
|
|
38651
|
+
addFormat(res, "duration", check2.message, refs);
|
|
38652
|
+
break;
|
|
38653
|
+
case "length":
|
|
38654
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value, check2.message, refs);
|
|
38655
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value, check2.message, refs);
|
|
38656
|
+
break;
|
|
38657
|
+
case "includes": {
|
|
38658
|
+
addPattern(res, RegExp(escapeLiteralCheckValue(check2.value, refs)), check2.message, refs);
|
|
38659
|
+
break;
|
|
38660
|
+
}
|
|
38661
|
+
case "ip": {
|
|
38662
|
+
if (check2.version !== "v6") {
|
|
38663
|
+
addFormat(res, "ipv4", check2.message, refs);
|
|
38664
|
+
}
|
|
38665
|
+
if (check2.version !== "v4") {
|
|
38666
|
+
addFormat(res, "ipv6", check2.message, refs);
|
|
38667
|
+
}
|
|
38668
|
+
break;
|
|
38669
|
+
}
|
|
38670
|
+
case "base64url":
|
|
38671
|
+
addPattern(res, zodPatterns.base64url, check2.message, refs);
|
|
38672
|
+
break;
|
|
38673
|
+
case "jwt":
|
|
38674
|
+
addPattern(res, zodPatterns.jwt, check2.message, refs);
|
|
38675
|
+
break;
|
|
38676
|
+
case "cidr": {
|
|
38677
|
+
if (check2.version !== "v6") {
|
|
38678
|
+
addPattern(res, zodPatterns.ipv4Cidr, check2.message, refs);
|
|
38679
|
+
}
|
|
38680
|
+
if (check2.version !== "v4") {
|
|
38681
|
+
addPattern(res, zodPatterns.ipv6Cidr, check2.message, refs);
|
|
38682
|
+
}
|
|
38683
|
+
break;
|
|
38684
|
+
}
|
|
38685
|
+
case "emoji":
|
|
38686
|
+
addPattern(res, zodPatterns.emoji(), check2.message, refs);
|
|
38687
|
+
break;
|
|
38688
|
+
case "ulid": {
|
|
38689
|
+
addPattern(res, zodPatterns.ulid, check2.message, refs);
|
|
38690
|
+
break;
|
|
38691
|
+
}
|
|
38692
|
+
case "base64": {
|
|
38693
|
+
switch (refs.base64Strategy) {
|
|
38694
|
+
case "format:binary": {
|
|
38695
|
+
addFormat(res, "binary", check2.message, refs);
|
|
38696
|
+
break;
|
|
38697
|
+
}
|
|
38698
|
+
case "contentEncoding:base64": {
|
|
38699
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check2.message, refs);
|
|
38700
|
+
break;
|
|
38701
|
+
}
|
|
38702
|
+
case "pattern:zod": {
|
|
38703
|
+
addPattern(res, zodPatterns.base64, check2.message, refs);
|
|
38704
|
+
break;
|
|
38705
|
+
}
|
|
38706
|
+
}
|
|
38707
|
+
break;
|
|
38708
|
+
}
|
|
38709
|
+
case "nanoid": {
|
|
38710
|
+
addPattern(res, zodPatterns.nanoid, check2.message, refs);
|
|
38711
|
+
}
|
|
38712
|
+
case "toLowerCase":
|
|
38713
|
+
case "toUpperCase":
|
|
38714
|
+
case "trim":
|
|
38715
|
+
break;
|
|
38716
|
+
default:
|
|
38717
|
+
/* @__PURE__ */ ((_) => {
|
|
38718
|
+
})(check2);
|
|
38719
|
+
}
|
|
38720
|
+
}
|
|
38721
|
+
}
|
|
38722
|
+
return res;
|
|
38723
|
+
}
|
|
38724
|
+
function escapeLiteralCheckValue(literal2, refs) {
|
|
38725
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal2) : literal2;
|
|
38726
|
+
}
|
|
38005
38727
|
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
38728
|
+
function escapeNonAlphaNumeric(source) {
|
|
38729
|
+
let result = "";
|
|
38730
|
+
for (let i = 0; i < source.length; i++) {
|
|
38731
|
+
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
38732
|
+
result += "\\";
|
|
38733
|
+
}
|
|
38734
|
+
result += source[i];
|
|
38735
|
+
}
|
|
38736
|
+
return result;
|
|
38737
|
+
}
|
|
38738
|
+
function addFormat(schema, value, message, refs) {
|
|
38739
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
38740
|
+
if (!schema.anyOf) {
|
|
38741
|
+
schema.anyOf = [];
|
|
38742
|
+
}
|
|
38743
|
+
if (schema.format) {
|
|
38744
|
+
schema.anyOf.push({
|
|
38745
|
+
format: schema.format,
|
|
38746
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
38747
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
38748
|
+
}
|
|
38749
|
+
});
|
|
38750
|
+
delete schema.format;
|
|
38751
|
+
if (schema.errorMessage) {
|
|
38752
|
+
delete schema.errorMessage.format;
|
|
38753
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
38754
|
+
delete schema.errorMessage;
|
|
38755
|
+
}
|
|
38756
|
+
}
|
|
38757
|
+
}
|
|
38758
|
+
schema.anyOf.push({
|
|
38759
|
+
format: value,
|
|
38760
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
38761
|
+
});
|
|
38762
|
+
} else {
|
|
38763
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
38764
|
+
}
|
|
38765
|
+
}
|
|
38766
|
+
function addPattern(schema, regex, message, refs) {
|
|
38767
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
38768
|
+
if (!schema.allOf) {
|
|
38769
|
+
schema.allOf = [];
|
|
38770
|
+
}
|
|
38771
|
+
if (schema.pattern) {
|
|
38772
|
+
schema.allOf.push({
|
|
38773
|
+
pattern: schema.pattern,
|
|
38774
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
38775
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
38776
|
+
}
|
|
38777
|
+
});
|
|
38778
|
+
delete schema.pattern;
|
|
38779
|
+
if (schema.errorMessage) {
|
|
38780
|
+
delete schema.errorMessage.pattern;
|
|
38781
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
38782
|
+
delete schema.errorMessage;
|
|
38783
|
+
}
|
|
38784
|
+
}
|
|
38785
|
+
}
|
|
38786
|
+
schema.allOf.push({
|
|
38787
|
+
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
38788
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
38789
|
+
});
|
|
38790
|
+
} else {
|
|
38791
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
38792
|
+
}
|
|
38793
|
+
}
|
|
38794
|
+
function stringifyRegExpWithFlags(regex, refs) {
|
|
38795
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
38796
|
+
return regex.source;
|
|
38797
|
+
}
|
|
38798
|
+
const flags = {
|
|
38799
|
+
i: regex.flags.includes("i"),
|
|
38800
|
+
m: regex.flags.includes("m"),
|
|
38801
|
+
s: regex.flags.includes("s")
|
|
38802
|
+
// `.` matches newlines
|
|
38803
|
+
};
|
|
38804
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
38805
|
+
let pattern = "";
|
|
38806
|
+
let isEscaped = false;
|
|
38807
|
+
let inCharGroup = false;
|
|
38808
|
+
let inCharRange = false;
|
|
38809
|
+
for (let i = 0; i < source.length; i++) {
|
|
38810
|
+
if (isEscaped) {
|
|
38811
|
+
pattern += source[i];
|
|
38812
|
+
isEscaped = false;
|
|
38813
|
+
continue;
|
|
38814
|
+
}
|
|
38815
|
+
if (flags.i) {
|
|
38816
|
+
if (inCharGroup) {
|
|
38817
|
+
if (source[i].match(/[a-z]/)) {
|
|
38818
|
+
if (inCharRange) {
|
|
38819
|
+
pattern += source[i];
|
|
38820
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
38821
|
+
inCharRange = false;
|
|
38822
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
38823
|
+
pattern += source[i];
|
|
38824
|
+
inCharRange = true;
|
|
38825
|
+
} else {
|
|
38826
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
38827
|
+
}
|
|
38828
|
+
continue;
|
|
38829
|
+
}
|
|
38830
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
38831
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
38832
|
+
continue;
|
|
38833
|
+
}
|
|
38834
|
+
}
|
|
38835
|
+
if (flags.m) {
|
|
38836
|
+
if (source[i] === "^") {
|
|
38837
|
+
pattern += `(^|(?<=[\r
|
|
38838
|
+
]))`;
|
|
38839
|
+
continue;
|
|
38840
|
+
} else if (source[i] === "$") {
|
|
38841
|
+
pattern += `($|(?=[\r
|
|
38842
|
+
]))`;
|
|
38843
|
+
continue;
|
|
38844
|
+
}
|
|
38845
|
+
}
|
|
38846
|
+
if (flags.s && source[i] === ".") {
|
|
38847
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
38848
|
+
` : `[${source[i]}\r
|
|
38849
|
+
]`;
|
|
38850
|
+
continue;
|
|
38851
|
+
}
|
|
38852
|
+
pattern += source[i];
|
|
38853
|
+
if (source[i] === "\\") {
|
|
38854
|
+
isEscaped = true;
|
|
38855
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
38856
|
+
inCharGroup = false;
|
|
38857
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
38858
|
+
inCharGroup = true;
|
|
38859
|
+
}
|
|
38860
|
+
}
|
|
38861
|
+
try {
|
|
38862
|
+
new RegExp(pattern);
|
|
38863
|
+
} catch {
|
|
38864
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
38865
|
+
return regex.source;
|
|
38866
|
+
}
|
|
38867
|
+
return pattern;
|
|
38868
|
+
}
|
|
38869
|
+
|
|
38870
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
38871
|
+
function parseRecordDef(def, refs) {
|
|
38872
|
+
if (refs.target === "openAi") {
|
|
38873
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
38874
|
+
}
|
|
38875
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
38876
|
+
return {
|
|
38877
|
+
type: "object",
|
|
38878
|
+
required: def.keyType._def.values,
|
|
38879
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
38880
|
+
...acc,
|
|
38881
|
+
[key]: parseDef(def.valueType._def, {
|
|
38882
|
+
...refs,
|
|
38883
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
38884
|
+
}) ?? parseAnyDef(refs)
|
|
38885
|
+
}), {}),
|
|
38886
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
38887
|
+
};
|
|
38888
|
+
}
|
|
38889
|
+
const schema = {
|
|
38890
|
+
type: "object",
|
|
38891
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
38892
|
+
...refs,
|
|
38893
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
38894
|
+
}) ?? refs.allowedAdditionalProperties
|
|
38895
|
+
};
|
|
38896
|
+
if (refs.target === "openApi3") {
|
|
38897
|
+
return schema;
|
|
38898
|
+
}
|
|
38899
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
38900
|
+
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
38901
|
+
return {
|
|
38902
|
+
...schema,
|
|
38903
|
+
propertyNames: keyType
|
|
38904
|
+
};
|
|
38905
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
38906
|
+
return {
|
|
38907
|
+
...schema,
|
|
38908
|
+
propertyNames: {
|
|
38909
|
+
enum: def.keyType._def.values
|
|
38910
|
+
}
|
|
38911
|
+
};
|
|
38912
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
38913
|
+
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
38914
|
+
return {
|
|
38915
|
+
...schema,
|
|
38916
|
+
propertyNames: keyType
|
|
38917
|
+
};
|
|
38918
|
+
}
|
|
38919
|
+
return schema;
|
|
38920
|
+
}
|
|
38921
|
+
|
|
38922
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
38923
|
+
function parseMapDef(def, refs) {
|
|
38924
|
+
if (refs.mapStrategy === "record") {
|
|
38925
|
+
return parseRecordDef(def, refs);
|
|
38926
|
+
}
|
|
38927
|
+
const keys = parseDef(def.keyType._def, {
|
|
38928
|
+
...refs,
|
|
38929
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
38930
|
+
}) || parseAnyDef(refs);
|
|
38931
|
+
const values = parseDef(def.valueType._def, {
|
|
38932
|
+
...refs,
|
|
38933
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
38934
|
+
}) || parseAnyDef(refs);
|
|
38935
|
+
return {
|
|
38936
|
+
type: "array",
|
|
38937
|
+
maxItems: 125,
|
|
38938
|
+
items: {
|
|
38939
|
+
type: "array",
|
|
38940
|
+
items: [keys, values],
|
|
38941
|
+
minItems: 2,
|
|
38942
|
+
maxItems: 2
|
|
38943
|
+
}
|
|
38944
|
+
};
|
|
38945
|
+
}
|
|
38946
|
+
|
|
38947
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
38948
|
+
function parseNativeEnumDef(def) {
|
|
38949
|
+
const object3 = def.values;
|
|
38950
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
38951
|
+
return typeof object3[object3[key]] !== "number";
|
|
38952
|
+
});
|
|
38953
|
+
const actualValues = actualKeys.map((key) => object3[key]);
|
|
38954
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
38955
|
+
return {
|
|
38956
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
38957
|
+
enum: actualValues
|
|
38958
|
+
};
|
|
38959
|
+
}
|
|
38960
|
+
|
|
38961
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
38962
|
+
function parseNeverDef(refs) {
|
|
38963
|
+
return refs.target === "openAi" ? void 0 : {
|
|
38964
|
+
not: parseAnyDef({
|
|
38965
|
+
...refs,
|
|
38966
|
+
currentPath: [...refs.currentPath, "not"]
|
|
38967
|
+
})
|
|
38968
|
+
};
|
|
38969
|
+
}
|
|
38970
|
+
|
|
38971
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
38972
|
+
function parseNullDef(refs) {
|
|
38973
|
+
return refs.target === "openApi3" ? {
|
|
38974
|
+
enum: ["null"],
|
|
38975
|
+
nullable: true
|
|
38976
|
+
} : {
|
|
38977
|
+
type: "null"
|
|
38978
|
+
};
|
|
38979
|
+
}
|
|
38980
|
+
|
|
38981
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
38982
|
+
var primitiveMappings = {
|
|
38983
|
+
ZodString: "string",
|
|
38984
|
+
ZodNumber: "number",
|
|
38985
|
+
ZodBigInt: "integer",
|
|
38986
|
+
ZodBoolean: "boolean",
|
|
38987
|
+
ZodNull: "null"
|
|
38988
|
+
};
|
|
38989
|
+
function parseUnionDef(def, refs) {
|
|
38990
|
+
if (refs.target === "openApi3")
|
|
38991
|
+
return asAnyOf(def, refs);
|
|
38992
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
38993
|
+
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
38994
|
+
const types = options.reduce((types2, x) => {
|
|
38995
|
+
const type = primitiveMappings[x._def.typeName];
|
|
38996
|
+
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
38997
|
+
}, []);
|
|
38998
|
+
return {
|
|
38999
|
+
type: types.length > 1 ? types : types[0]
|
|
39000
|
+
};
|
|
39001
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
39002
|
+
const types = options.reduce((acc, x) => {
|
|
39003
|
+
const type = typeof x._def.value;
|
|
39004
|
+
switch (type) {
|
|
39005
|
+
case "string":
|
|
39006
|
+
case "number":
|
|
39007
|
+
case "boolean":
|
|
39008
|
+
return [...acc, type];
|
|
39009
|
+
case "bigint":
|
|
39010
|
+
return [...acc, "integer"];
|
|
39011
|
+
case "object":
|
|
39012
|
+
if (x._def.value === null)
|
|
39013
|
+
return [...acc, "null"];
|
|
39014
|
+
case "symbol":
|
|
39015
|
+
case "undefined":
|
|
39016
|
+
case "function":
|
|
39017
|
+
default:
|
|
39018
|
+
return acc;
|
|
39019
|
+
}
|
|
39020
|
+
}, []);
|
|
39021
|
+
if (types.length === options.length) {
|
|
39022
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
39023
|
+
return {
|
|
39024
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
39025
|
+
enum: options.reduce((acc, x) => {
|
|
39026
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
39027
|
+
}, [])
|
|
39028
|
+
};
|
|
39029
|
+
}
|
|
39030
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
39031
|
+
return {
|
|
39032
|
+
type: "string",
|
|
39033
|
+
enum: options.reduce((acc, x) => [
|
|
39034
|
+
...acc,
|
|
39035
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
39036
|
+
], [])
|
|
39037
|
+
};
|
|
39038
|
+
}
|
|
39039
|
+
return asAnyOf(def, refs);
|
|
39040
|
+
}
|
|
39041
|
+
var asAnyOf = (def, refs) => {
|
|
39042
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
39043
|
+
...refs,
|
|
39044
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
39045
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
39046
|
+
return anyOf.length ? { anyOf } : void 0;
|
|
39047
|
+
};
|
|
39048
|
+
|
|
39049
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
39050
|
+
function parseNullableDef(def, refs) {
|
|
39051
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
39052
|
+
if (refs.target === "openApi3") {
|
|
39053
|
+
return {
|
|
39054
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
39055
|
+
nullable: true
|
|
39056
|
+
};
|
|
39057
|
+
}
|
|
39058
|
+
return {
|
|
39059
|
+
type: [
|
|
39060
|
+
primitiveMappings[def.innerType._def.typeName],
|
|
39061
|
+
"null"
|
|
39062
|
+
]
|
|
39063
|
+
};
|
|
39064
|
+
}
|
|
39065
|
+
if (refs.target === "openApi3") {
|
|
39066
|
+
const base2 = parseDef(def.innerType._def, {
|
|
39067
|
+
...refs,
|
|
39068
|
+
currentPath: [...refs.currentPath]
|
|
39069
|
+
});
|
|
39070
|
+
if (base2 && "$ref" in base2)
|
|
39071
|
+
return { allOf: [base2], nullable: true };
|
|
39072
|
+
return base2 && { ...base2, nullable: true };
|
|
39073
|
+
}
|
|
39074
|
+
const base = parseDef(def.innerType._def, {
|
|
39075
|
+
...refs,
|
|
39076
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
39077
|
+
});
|
|
39078
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
39079
|
+
}
|
|
39080
|
+
|
|
39081
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
39082
|
+
function parseNumberDef(def, refs) {
|
|
39083
|
+
const res = {
|
|
39084
|
+
type: "number"
|
|
39085
|
+
};
|
|
39086
|
+
if (!def.checks)
|
|
39087
|
+
return res;
|
|
39088
|
+
for (const check2 of def.checks) {
|
|
39089
|
+
switch (check2.kind) {
|
|
39090
|
+
case "int":
|
|
39091
|
+
res.type = "integer";
|
|
39092
|
+
addErrorMessage(res, "type", check2.message, refs);
|
|
39093
|
+
break;
|
|
39094
|
+
case "min":
|
|
39095
|
+
if (refs.target === "jsonSchema7") {
|
|
39096
|
+
if (check2.inclusive) {
|
|
39097
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
39098
|
+
} else {
|
|
39099
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check2.value, check2.message, refs);
|
|
39100
|
+
}
|
|
39101
|
+
} else {
|
|
39102
|
+
if (!check2.inclusive) {
|
|
39103
|
+
res.exclusiveMinimum = true;
|
|
39104
|
+
}
|
|
39105
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
39106
|
+
}
|
|
39107
|
+
break;
|
|
39108
|
+
case "max":
|
|
39109
|
+
if (refs.target === "jsonSchema7") {
|
|
39110
|
+
if (check2.inclusive) {
|
|
39111
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
39112
|
+
} else {
|
|
39113
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check2.value, check2.message, refs);
|
|
39114
|
+
}
|
|
39115
|
+
} else {
|
|
39116
|
+
if (!check2.inclusive) {
|
|
39117
|
+
res.exclusiveMaximum = true;
|
|
39118
|
+
}
|
|
39119
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
39120
|
+
}
|
|
39121
|
+
break;
|
|
39122
|
+
case "multipleOf":
|
|
39123
|
+
setResponseValueAndErrors(res, "multipleOf", check2.value, check2.message, refs);
|
|
39124
|
+
break;
|
|
39125
|
+
}
|
|
39126
|
+
}
|
|
39127
|
+
return res;
|
|
39128
|
+
}
|
|
39129
|
+
|
|
39130
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
39131
|
+
function parseObjectDef(def, refs) {
|
|
39132
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
39133
|
+
const result = {
|
|
39134
|
+
type: "object",
|
|
39135
|
+
properties: {}
|
|
39136
|
+
};
|
|
39137
|
+
const required2 = [];
|
|
39138
|
+
const shape = def.shape();
|
|
39139
|
+
for (const propName in shape) {
|
|
39140
|
+
let propDef = shape[propName];
|
|
39141
|
+
if (propDef === void 0 || propDef._def === void 0) {
|
|
39142
|
+
continue;
|
|
39143
|
+
}
|
|
39144
|
+
let propOptional = safeIsOptional(propDef);
|
|
39145
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
39146
|
+
if (propDef._def.typeName === "ZodOptional") {
|
|
39147
|
+
propDef = propDef._def.innerType;
|
|
39148
|
+
}
|
|
39149
|
+
if (!propDef.isNullable()) {
|
|
39150
|
+
propDef = propDef.nullable();
|
|
39151
|
+
}
|
|
39152
|
+
propOptional = false;
|
|
39153
|
+
}
|
|
39154
|
+
const parsedDef = parseDef(propDef._def, {
|
|
39155
|
+
...refs,
|
|
39156
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
39157
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
39158
|
+
});
|
|
39159
|
+
if (parsedDef === void 0) {
|
|
39160
|
+
continue;
|
|
39161
|
+
}
|
|
39162
|
+
result.properties[propName] = parsedDef;
|
|
39163
|
+
if (!propOptional) {
|
|
39164
|
+
required2.push(propName);
|
|
39165
|
+
}
|
|
39166
|
+
}
|
|
39167
|
+
if (required2.length) {
|
|
39168
|
+
result.required = required2;
|
|
39169
|
+
}
|
|
39170
|
+
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
39171
|
+
if (additionalProperties !== void 0) {
|
|
39172
|
+
result.additionalProperties = additionalProperties;
|
|
39173
|
+
}
|
|
39174
|
+
return result;
|
|
39175
|
+
}
|
|
39176
|
+
function decideAdditionalProperties(def, refs) {
|
|
39177
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
39178
|
+
return parseDef(def.catchall._def, {
|
|
39179
|
+
...refs,
|
|
39180
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
39181
|
+
});
|
|
39182
|
+
}
|
|
39183
|
+
switch (def.unknownKeys) {
|
|
39184
|
+
case "passthrough":
|
|
39185
|
+
return refs.allowedAdditionalProperties;
|
|
39186
|
+
case "strict":
|
|
39187
|
+
return refs.rejectedAdditionalProperties;
|
|
39188
|
+
case "strip":
|
|
39189
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
39190
|
+
}
|
|
39191
|
+
}
|
|
39192
|
+
function safeIsOptional(schema) {
|
|
39193
|
+
try {
|
|
39194
|
+
return schema.isOptional();
|
|
39195
|
+
} catch {
|
|
39196
|
+
return true;
|
|
39197
|
+
}
|
|
39198
|
+
}
|
|
39199
|
+
|
|
39200
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
39201
|
+
var parseOptionalDef = (def, refs) => {
|
|
39202
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
39203
|
+
return parseDef(def.innerType._def, refs);
|
|
39204
|
+
}
|
|
39205
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
39206
|
+
...refs,
|
|
39207
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
39208
|
+
});
|
|
39209
|
+
return innerSchema ? {
|
|
39210
|
+
anyOf: [
|
|
39211
|
+
{
|
|
39212
|
+
not: parseAnyDef(refs)
|
|
39213
|
+
},
|
|
39214
|
+
innerSchema
|
|
39215
|
+
]
|
|
39216
|
+
} : parseAnyDef(refs);
|
|
39217
|
+
};
|
|
39218
|
+
|
|
39219
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
39220
|
+
var parsePipelineDef = (def, refs) => {
|
|
39221
|
+
if (refs.pipeStrategy === "input") {
|
|
39222
|
+
return parseDef(def.in._def, refs);
|
|
39223
|
+
} else if (refs.pipeStrategy === "output") {
|
|
39224
|
+
return parseDef(def.out._def, refs);
|
|
39225
|
+
}
|
|
39226
|
+
const a = parseDef(def.in._def, {
|
|
39227
|
+
...refs,
|
|
39228
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
39229
|
+
});
|
|
39230
|
+
const b = parseDef(def.out._def, {
|
|
39231
|
+
...refs,
|
|
39232
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
39233
|
+
});
|
|
39234
|
+
return {
|
|
39235
|
+
allOf: [a, b].filter((x) => x !== void 0)
|
|
39236
|
+
};
|
|
39237
|
+
};
|
|
39238
|
+
|
|
39239
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
39240
|
+
function parsePromiseDef(def, refs) {
|
|
39241
|
+
return parseDef(def.type._def, refs);
|
|
39242
|
+
}
|
|
39243
|
+
|
|
39244
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
39245
|
+
function parseSetDef(def, refs) {
|
|
39246
|
+
const items = parseDef(def.valueType._def, {
|
|
39247
|
+
...refs,
|
|
39248
|
+
currentPath: [...refs.currentPath, "items"]
|
|
39249
|
+
});
|
|
39250
|
+
const schema = {
|
|
39251
|
+
type: "array",
|
|
39252
|
+
uniqueItems: true,
|
|
39253
|
+
items
|
|
39254
|
+
};
|
|
39255
|
+
if (def.minSize) {
|
|
39256
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
39257
|
+
}
|
|
39258
|
+
if (def.maxSize) {
|
|
39259
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
39260
|
+
}
|
|
39261
|
+
return schema;
|
|
39262
|
+
}
|
|
39263
|
+
|
|
39264
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
39265
|
+
function parseTupleDef(def, refs) {
|
|
39266
|
+
if (def.rest) {
|
|
39267
|
+
return {
|
|
39268
|
+
type: "array",
|
|
39269
|
+
minItems: def.items.length,
|
|
39270
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
39271
|
+
...refs,
|
|
39272
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
39273
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
39274
|
+
additionalItems: parseDef(def.rest._def, {
|
|
39275
|
+
...refs,
|
|
39276
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
39277
|
+
})
|
|
39278
|
+
};
|
|
39279
|
+
} else {
|
|
39280
|
+
return {
|
|
39281
|
+
type: "array",
|
|
39282
|
+
minItems: def.items.length,
|
|
39283
|
+
maxItems: def.items.length,
|
|
39284
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
39285
|
+
...refs,
|
|
39286
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
39287
|
+
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
39288
|
+
};
|
|
39289
|
+
}
|
|
39290
|
+
}
|
|
39291
|
+
|
|
39292
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
39293
|
+
function parseUndefinedDef(refs) {
|
|
39294
|
+
return {
|
|
39295
|
+
not: parseAnyDef(refs)
|
|
39296
|
+
};
|
|
39297
|
+
}
|
|
39298
|
+
|
|
39299
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
39300
|
+
function parseUnknownDef(refs) {
|
|
39301
|
+
return parseAnyDef(refs);
|
|
39302
|
+
}
|
|
39303
|
+
|
|
39304
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
39305
|
+
var parseReadonlyDef = (def, refs) => {
|
|
39306
|
+
return parseDef(def.innerType._def, refs);
|
|
39307
|
+
};
|
|
39308
|
+
|
|
39309
|
+
// ../node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
39310
|
+
var selectParser = (def, typeName, refs) => {
|
|
39311
|
+
switch (typeName) {
|
|
39312
|
+
case ZodFirstPartyTypeKind2.ZodString:
|
|
39313
|
+
return parseStringDef(def, refs);
|
|
39314
|
+
case ZodFirstPartyTypeKind2.ZodNumber:
|
|
39315
|
+
return parseNumberDef(def, refs);
|
|
39316
|
+
case ZodFirstPartyTypeKind2.ZodObject:
|
|
39317
|
+
return parseObjectDef(def, refs);
|
|
39318
|
+
case ZodFirstPartyTypeKind2.ZodBigInt:
|
|
39319
|
+
return parseBigintDef(def, refs);
|
|
39320
|
+
case ZodFirstPartyTypeKind2.ZodBoolean:
|
|
39321
|
+
return parseBooleanDef();
|
|
39322
|
+
case ZodFirstPartyTypeKind2.ZodDate:
|
|
39323
|
+
return parseDateDef(def, refs);
|
|
39324
|
+
case ZodFirstPartyTypeKind2.ZodUndefined:
|
|
39325
|
+
return parseUndefinedDef(refs);
|
|
39326
|
+
case ZodFirstPartyTypeKind2.ZodNull:
|
|
39327
|
+
return parseNullDef(refs);
|
|
39328
|
+
case ZodFirstPartyTypeKind2.ZodArray:
|
|
39329
|
+
return parseArrayDef(def, refs);
|
|
39330
|
+
case ZodFirstPartyTypeKind2.ZodUnion:
|
|
39331
|
+
case ZodFirstPartyTypeKind2.ZodDiscriminatedUnion:
|
|
39332
|
+
return parseUnionDef(def, refs);
|
|
39333
|
+
case ZodFirstPartyTypeKind2.ZodIntersection:
|
|
39334
|
+
return parseIntersectionDef(def, refs);
|
|
39335
|
+
case ZodFirstPartyTypeKind2.ZodTuple:
|
|
39336
|
+
return parseTupleDef(def, refs);
|
|
39337
|
+
case ZodFirstPartyTypeKind2.ZodRecord:
|
|
39338
|
+
return parseRecordDef(def, refs);
|
|
39339
|
+
case ZodFirstPartyTypeKind2.ZodLiteral:
|
|
39340
|
+
return parseLiteralDef(def, refs);
|
|
39341
|
+
case ZodFirstPartyTypeKind2.ZodEnum:
|
|
39342
|
+
return parseEnumDef(def);
|
|
39343
|
+
case ZodFirstPartyTypeKind2.ZodNativeEnum:
|
|
39344
|
+
return parseNativeEnumDef(def);
|
|
39345
|
+
case ZodFirstPartyTypeKind2.ZodNullable:
|
|
39346
|
+
return parseNullableDef(def, refs);
|
|
39347
|
+
case ZodFirstPartyTypeKind2.ZodOptional:
|
|
39348
|
+
return parseOptionalDef(def, refs);
|
|
39349
|
+
case ZodFirstPartyTypeKind2.ZodMap:
|
|
39350
|
+
return parseMapDef(def, refs);
|
|
39351
|
+
case ZodFirstPartyTypeKind2.ZodSet:
|
|
39352
|
+
return parseSetDef(def, refs);
|
|
39353
|
+
case ZodFirstPartyTypeKind2.ZodLazy:
|
|
39354
|
+
return () => def.getter()._def;
|
|
39355
|
+
case ZodFirstPartyTypeKind2.ZodPromise:
|
|
39356
|
+
return parsePromiseDef(def, refs);
|
|
39357
|
+
case ZodFirstPartyTypeKind2.ZodNaN:
|
|
39358
|
+
case ZodFirstPartyTypeKind2.ZodNever:
|
|
39359
|
+
return parseNeverDef(refs);
|
|
39360
|
+
case ZodFirstPartyTypeKind2.ZodEffects:
|
|
39361
|
+
return parseEffectsDef(def, refs);
|
|
39362
|
+
case ZodFirstPartyTypeKind2.ZodAny:
|
|
39363
|
+
return parseAnyDef(refs);
|
|
39364
|
+
case ZodFirstPartyTypeKind2.ZodUnknown:
|
|
39365
|
+
return parseUnknownDef(refs);
|
|
39366
|
+
case ZodFirstPartyTypeKind2.ZodDefault:
|
|
39367
|
+
return parseDefaultDef(def, refs);
|
|
39368
|
+
case ZodFirstPartyTypeKind2.ZodBranded:
|
|
39369
|
+
return parseBrandedDef(def, refs);
|
|
39370
|
+
case ZodFirstPartyTypeKind2.ZodReadonly:
|
|
39371
|
+
return parseReadonlyDef(def, refs);
|
|
39372
|
+
case ZodFirstPartyTypeKind2.ZodCatch:
|
|
39373
|
+
return parseCatchDef(def, refs);
|
|
39374
|
+
case ZodFirstPartyTypeKind2.ZodPipeline:
|
|
39375
|
+
return parsePipelineDef(def, refs);
|
|
39376
|
+
case ZodFirstPartyTypeKind2.ZodFunction:
|
|
39377
|
+
case ZodFirstPartyTypeKind2.ZodVoid:
|
|
39378
|
+
case ZodFirstPartyTypeKind2.ZodSymbol:
|
|
39379
|
+
return void 0;
|
|
39380
|
+
default:
|
|
39381
|
+
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
39382
|
+
}
|
|
39383
|
+
};
|
|
39384
|
+
|
|
39385
|
+
// ../node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
39386
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
39387
|
+
const seenItem = refs.seen.get(def);
|
|
39388
|
+
if (refs.override) {
|
|
39389
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
39390
|
+
if (overrideResult !== ignoreOverride) {
|
|
39391
|
+
return overrideResult;
|
|
39392
|
+
}
|
|
39393
|
+
}
|
|
39394
|
+
if (seenItem && !forceResolution) {
|
|
39395
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
39396
|
+
if (seenSchema !== void 0) {
|
|
39397
|
+
return seenSchema;
|
|
39398
|
+
}
|
|
39399
|
+
}
|
|
39400
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
39401
|
+
refs.seen.set(def, newItem);
|
|
39402
|
+
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
39403
|
+
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
39404
|
+
if (jsonSchema) {
|
|
39405
|
+
addMeta(def, refs, jsonSchema);
|
|
39406
|
+
}
|
|
39407
|
+
if (refs.postProcess) {
|
|
39408
|
+
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
39409
|
+
newItem.jsonSchema = jsonSchema;
|
|
39410
|
+
return postProcessResult;
|
|
39411
|
+
}
|
|
39412
|
+
newItem.jsonSchema = jsonSchema;
|
|
39413
|
+
return jsonSchema;
|
|
39414
|
+
}
|
|
39415
|
+
var get$ref = (item, refs) => {
|
|
39416
|
+
switch (refs.$refStrategy) {
|
|
39417
|
+
case "root":
|
|
39418
|
+
return { $ref: item.path.join("/") };
|
|
39419
|
+
case "relative":
|
|
39420
|
+
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
39421
|
+
case "none":
|
|
39422
|
+
case "seen": {
|
|
39423
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
39424
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
39425
|
+
return parseAnyDef(refs);
|
|
39426
|
+
}
|
|
39427
|
+
return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
|
|
39428
|
+
}
|
|
39429
|
+
}
|
|
39430
|
+
};
|
|
39431
|
+
var addMeta = (def, refs, jsonSchema) => {
|
|
39432
|
+
if (def.description) {
|
|
39433
|
+
jsonSchema.description = def.description;
|
|
39434
|
+
if (refs.markdownDescription) {
|
|
39435
|
+
jsonSchema.markdownDescription = def.description;
|
|
39436
|
+
}
|
|
39437
|
+
}
|
|
39438
|
+
return jsonSchema;
|
|
39439
|
+
};
|
|
39440
|
+
|
|
39441
|
+
// ../node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
39442
|
+
var zodToJsonSchema = (schema, options) => {
|
|
39443
|
+
const refs = getRefs(options);
|
|
39444
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
39445
|
+
...acc,
|
|
39446
|
+
[name2]: parseDef(schema2._def, {
|
|
39447
|
+
...refs,
|
|
39448
|
+
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
39449
|
+
}, true) ?? parseAnyDef(refs)
|
|
39450
|
+
}), {}) : void 0;
|
|
39451
|
+
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
39452
|
+
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
39453
|
+
...refs,
|
|
39454
|
+
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
39455
|
+
}, false) ?? parseAnyDef(refs);
|
|
39456
|
+
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
39457
|
+
if (title !== void 0) {
|
|
39458
|
+
main.title = title;
|
|
39459
|
+
}
|
|
39460
|
+
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
39461
|
+
if (!definitions) {
|
|
39462
|
+
definitions = {};
|
|
39463
|
+
}
|
|
39464
|
+
if (!definitions[refs.openAiAnyTypeName]) {
|
|
39465
|
+
definitions[refs.openAiAnyTypeName] = {
|
|
39466
|
+
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
39467
|
+
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
39468
|
+
items: {
|
|
39469
|
+
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
39470
|
+
...refs.basePath,
|
|
39471
|
+
refs.definitionPath,
|
|
39472
|
+
refs.openAiAnyTypeName
|
|
39473
|
+
].join("/")
|
|
39474
|
+
}
|
|
39475
|
+
};
|
|
39476
|
+
}
|
|
39477
|
+
}
|
|
39478
|
+
const combined = name === void 0 ? definitions ? {
|
|
39479
|
+
...main,
|
|
39480
|
+
[refs.definitionPath]: definitions
|
|
39481
|
+
} : main : {
|
|
39482
|
+
$ref: [
|
|
39483
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
39484
|
+
refs.definitionPath,
|
|
39485
|
+
name
|
|
39486
|
+
].join("/"),
|
|
39487
|
+
[refs.definitionPath]: {
|
|
39488
|
+
...definitions,
|
|
39489
|
+
[name]: main
|
|
39490
|
+
}
|
|
39491
|
+
};
|
|
39492
|
+
if (refs.target === "jsonSchema7") {
|
|
39493
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
39494
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
39495
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
39496
|
+
}
|
|
39497
|
+
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
39498
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
39499
|
+
}
|
|
39500
|
+
return combined;
|
|
39501
|
+
};
|
|
38006
39502
|
|
|
38007
39503
|
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
|
|
39504
|
+
function mapMiniTarget(t) {
|
|
39505
|
+
if (!t)
|
|
39506
|
+
return "draft-7";
|
|
39507
|
+
if (t === "jsonSchema7" || t === "draft-7")
|
|
39508
|
+
return "draft-7";
|
|
39509
|
+
if (t === "jsonSchema2019-09" || t === "draft-2020-12")
|
|
39510
|
+
return "draft-2020-12";
|
|
39511
|
+
return "draft-7";
|
|
39512
|
+
}
|
|
39513
|
+
function toJsonSchemaCompat(schema, opts) {
|
|
39514
|
+
if (isZ4Schema(schema)) {
|
|
39515
|
+
return toJSONSchema(schema, {
|
|
39516
|
+
target: mapMiniTarget(opts?.target),
|
|
39517
|
+
io: opts?.pipeStrategy ?? "input"
|
|
39518
|
+
});
|
|
39519
|
+
}
|
|
39520
|
+
return zodToJsonSchema(schema, {
|
|
39521
|
+
strictUnions: opts?.strictUnions ?? true,
|
|
39522
|
+
pipeStrategy: opts?.pipeStrategy ?? "input"
|
|
39523
|
+
});
|
|
39524
|
+
}
|
|
38008
39525
|
function getMethodLiteral(schema) {
|
|
38009
39526
|
const shape = getObjectShape(schema);
|
|
38010
39527
|
const methodSchema = shape?.method;
|
|
@@ -39669,6 +41186,879 @@ var Server = class extends Protocol {
|
|
|
39669
41186
|
}
|
|
39670
41187
|
};
|
|
39671
41188
|
|
|
41189
|
+
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
|
|
41190
|
+
var COMPLETABLE_SYMBOL = /* @__PURE__ */ Symbol.for("mcp.completable");
|
|
41191
|
+
function isCompletable(schema) {
|
|
41192
|
+
return !!schema && typeof schema === "object" && COMPLETABLE_SYMBOL in schema;
|
|
41193
|
+
}
|
|
41194
|
+
function getCompleter(schema) {
|
|
41195
|
+
const meta3 = schema[COMPLETABLE_SYMBOL];
|
|
41196
|
+
return meta3?.complete;
|
|
41197
|
+
}
|
|
41198
|
+
var McpZodTypeKind;
|
|
41199
|
+
(function(McpZodTypeKind2) {
|
|
41200
|
+
McpZodTypeKind2["Completable"] = "McpCompletable";
|
|
41201
|
+
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
41202
|
+
|
|
41203
|
+
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
|
|
41204
|
+
var TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
|
|
41205
|
+
function validateToolName(name) {
|
|
41206
|
+
const warnings = [];
|
|
41207
|
+
if (name.length === 0) {
|
|
41208
|
+
return {
|
|
41209
|
+
isValid: false,
|
|
41210
|
+
warnings: ["Tool name cannot be empty"]
|
|
41211
|
+
};
|
|
41212
|
+
}
|
|
41213
|
+
if (name.length > 128) {
|
|
41214
|
+
return {
|
|
41215
|
+
isValid: false,
|
|
41216
|
+
warnings: [`Tool name exceeds maximum length of 128 characters (current: ${name.length})`]
|
|
41217
|
+
};
|
|
41218
|
+
}
|
|
41219
|
+
if (name.includes(" ")) {
|
|
41220
|
+
warnings.push("Tool name contains spaces, which may cause parsing issues");
|
|
41221
|
+
}
|
|
41222
|
+
if (name.includes(",")) {
|
|
41223
|
+
warnings.push("Tool name contains commas, which may cause parsing issues");
|
|
41224
|
+
}
|
|
41225
|
+
if (name.startsWith("-") || name.endsWith("-")) {
|
|
41226
|
+
warnings.push("Tool name starts or ends with a dash, which may cause parsing issues in some contexts");
|
|
41227
|
+
}
|
|
41228
|
+
if (name.startsWith(".") || name.endsWith(".")) {
|
|
41229
|
+
warnings.push("Tool name starts or ends with a dot, which may cause parsing issues in some contexts");
|
|
41230
|
+
}
|
|
41231
|
+
if (!TOOL_NAME_REGEX.test(name)) {
|
|
41232
|
+
const invalidChars = name.split("").filter((char) => !/[A-Za-z0-9._-]/.test(char)).filter((char, index, arr) => arr.indexOf(char) === index);
|
|
41233
|
+
warnings.push(`Tool name contains invalid characters: ${invalidChars.map((c) => `"${c}"`).join(", ")}`, "Allowed characters are: A-Z, a-z, 0-9, underscore (_), dash (-), and dot (.)");
|
|
41234
|
+
return {
|
|
41235
|
+
isValid: false,
|
|
41236
|
+
warnings
|
|
41237
|
+
};
|
|
41238
|
+
}
|
|
41239
|
+
return {
|
|
41240
|
+
isValid: true,
|
|
41241
|
+
warnings
|
|
41242
|
+
};
|
|
41243
|
+
}
|
|
41244
|
+
function issueToolNameWarning(name, warnings) {
|
|
41245
|
+
if (warnings.length > 0) {
|
|
41246
|
+
console.warn(`Tool name validation warning for "${name}":`);
|
|
41247
|
+
for (const warning of warnings) {
|
|
41248
|
+
console.warn(` - ${warning}`);
|
|
41249
|
+
}
|
|
41250
|
+
console.warn("Tool registration will proceed, but this may cause compatibility issues.");
|
|
41251
|
+
console.warn("Consider updating the tool name to conform to the MCP tool naming standard.");
|
|
41252
|
+
console.warn("See SEP: Specify Format for Tool Names (https://github.com/modelcontextprotocol/modelcontextprotocol/issues/986) for more details.");
|
|
41253
|
+
}
|
|
41254
|
+
}
|
|
41255
|
+
function validateAndWarnToolName(name) {
|
|
41256
|
+
const result = validateToolName(name);
|
|
41257
|
+
issueToolNameWarning(name, result.warnings);
|
|
41258
|
+
return result.isValid;
|
|
41259
|
+
}
|
|
41260
|
+
|
|
41261
|
+
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js
|
|
41262
|
+
var ExperimentalMcpServerTasks = class {
|
|
41263
|
+
constructor(_mcpServer) {
|
|
41264
|
+
this._mcpServer = _mcpServer;
|
|
41265
|
+
}
|
|
41266
|
+
registerToolTask(name, config2, handler) {
|
|
41267
|
+
const execution = { taskSupport: "required", ...config2.execution };
|
|
41268
|
+
if (execution.taskSupport === "forbidden") {
|
|
41269
|
+
throw new Error(`Cannot register task-based tool '${name}' with taskSupport 'forbidden'. Use registerTool() instead.`);
|
|
41270
|
+
}
|
|
41271
|
+
const mcpServerInternal = this._mcpServer;
|
|
41272
|
+
return mcpServerInternal._createRegisteredTool(name, config2.title, config2.description, config2.inputSchema, config2.outputSchema, config2.annotations, execution, config2._meta, handler);
|
|
41273
|
+
}
|
|
41274
|
+
};
|
|
41275
|
+
|
|
41276
|
+
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
|
|
41277
|
+
var McpServer = class {
|
|
41278
|
+
constructor(serverInfo, options) {
|
|
41279
|
+
this._registeredResources = {};
|
|
41280
|
+
this._registeredResourceTemplates = {};
|
|
41281
|
+
this._registeredTools = {};
|
|
41282
|
+
this._registeredPrompts = {};
|
|
41283
|
+
this._toolHandlersInitialized = false;
|
|
41284
|
+
this._completionHandlerInitialized = false;
|
|
41285
|
+
this._resourceHandlersInitialized = false;
|
|
41286
|
+
this._promptHandlersInitialized = false;
|
|
41287
|
+
this.server = new Server(serverInfo, options);
|
|
41288
|
+
}
|
|
41289
|
+
/**
|
|
41290
|
+
* Access experimental features.
|
|
41291
|
+
*
|
|
41292
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
41293
|
+
*
|
|
41294
|
+
* @experimental
|
|
41295
|
+
*/
|
|
41296
|
+
get experimental() {
|
|
41297
|
+
if (!this._experimental) {
|
|
41298
|
+
this._experimental = {
|
|
41299
|
+
tasks: new ExperimentalMcpServerTasks(this)
|
|
41300
|
+
};
|
|
41301
|
+
}
|
|
41302
|
+
return this._experimental;
|
|
41303
|
+
}
|
|
41304
|
+
/**
|
|
41305
|
+
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
41306
|
+
*
|
|
41307
|
+
* The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
|
41308
|
+
*/
|
|
41309
|
+
async connect(transport) {
|
|
41310
|
+
return await this.server.connect(transport);
|
|
41311
|
+
}
|
|
41312
|
+
/**
|
|
41313
|
+
* Closes the connection.
|
|
41314
|
+
*/
|
|
41315
|
+
async close() {
|
|
41316
|
+
await this.server.close();
|
|
41317
|
+
}
|
|
41318
|
+
setToolRequestHandlers() {
|
|
41319
|
+
if (this._toolHandlersInitialized) {
|
|
41320
|
+
return;
|
|
41321
|
+
}
|
|
41322
|
+
this.server.assertCanSetRequestHandler(getMethodValue(ListToolsRequestSchema));
|
|
41323
|
+
this.server.assertCanSetRequestHandler(getMethodValue(CallToolRequestSchema));
|
|
41324
|
+
this.server.registerCapabilities({
|
|
41325
|
+
tools: {
|
|
41326
|
+
listChanged: true
|
|
41327
|
+
}
|
|
41328
|
+
});
|
|
41329
|
+
this.server.setRequestHandler(ListToolsRequestSchema, () => ({
|
|
41330
|
+
tools: Object.entries(this._registeredTools).filter(([, tool]) => tool.enabled).map(([name, tool]) => {
|
|
41331
|
+
const toolDefinition = {
|
|
41332
|
+
name,
|
|
41333
|
+
title: tool.title,
|
|
41334
|
+
description: tool.description,
|
|
41335
|
+
inputSchema: (() => {
|
|
41336
|
+
const obj = normalizeObjectSchema(tool.inputSchema);
|
|
41337
|
+
return obj ? toJsonSchemaCompat(obj, {
|
|
41338
|
+
strictUnions: true,
|
|
41339
|
+
pipeStrategy: "input"
|
|
41340
|
+
}) : EMPTY_OBJECT_JSON_SCHEMA;
|
|
41341
|
+
})(),
|
|
41342
|
+
annotations: tool.annotations,
|
|
41343
|
+
execution: tool.execution,
|
|
41344
|
+
_meta: tool._meta
|
|
41345
|
+
};
|
|
41346
|
+
if (tool.outputSchema) {
|
|
41347
|
+
const obj = normalizeObjectSchema(tool.outputSchema);
|
|
41348
|
+
if (obj) {
|
|
41349
|
+
toolDefinition.outputSchema = toJsonSchemaCompat(obj, {
|
|
41350
|
+
strictUnions: true,
|
|
41351
|
+
pipeStrategy: "output"
|
|
41352
|
+
});
|
|
41353
|
+
}
|
|
41354
|
+
}
|
|
41355
|
+
return toolDefinition;
|
|
41356
|
+
})
|
|
41357
|
+
}));
|
|
41358
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
41359
|
+
try {
|
|
41360
|
+
const tool = this._registeredTools[request.params.name];
|
|
41361
|
+
if (!tool) {
|
|
41362
|
+
throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
|
|
41363
|
+
}
|
|
41364
|
+
if (!tool.enabled) {
|
|
41365
|
+
throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
|
|
41366
|
+
}
|
|
41367
|
+
const isTaskRequest = !!request.params.task;
|
|
41368
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
41369
|
+
const isTaskHandler = "createTask" in tool.handler;
|
|
41370
|
+
if ((taskSupport === "required" || taskSupport === "optional") && !isTaskHandler) {
|
|
41371
|
+
throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
|
|
41372
|
+
}
|
|
41373
|
+
if (taskSupport === "required" && !isTaskRequest) {
|
|
41374
|
+
throw new McpError(ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`);
|
|
41375
|
+
}
|
|
41376
|
+
if (taskSupport === "optional" && !isTaskRequest && isTaskHandler) {
|
|
41377
|
+
return await this.handleAutomaticTaskPolling(tool, request, extra);
|
|
41378
|
+
}
|
|
41379
|
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
|
41380
|
+
const result = await this.executeToolHandler(tool, args, extra);
|
|
41381
|
+
if (isTaskRequest) {
|
|
41382
|
+
return result;
|
|
41383
|
+
}
|
|
41384
|
+
await this.validateToolOutput(tool, result, request.params.name);
|
|
41385
|
+
return result;
|
|
41386
|
+
} catch (error48) {
|
|
41387
|
+
if (error48 instanceof McpError) {
|
|
41388
|
+
if (error48.code === ErrorCode.UrlElicitationRequired) {
|
|
41389
|
+
throw error48;
|
|
41390
|
+
}
|
|
41391
|
+
}
|
|
41392
|
+
return this.createToolError(error48 instanceof Error ? error48.message : String(error48));
|
|
41393
|
+
}
|
|
41394
|
+
});
|
|
41395
|
+
this._toolHandlersInitialized = true;
|
|
41396
|
+
}
|
|
41397
|
+
/**
|
|
41398
|
+
* Creates a tool error result.
|
|
41399
|
+
*
|
|
41400
|
+
* @param errorMessage - The error message.
|
|
41401
|
+
* @returns The tool error result.
|
|
41402
|
+
*/
|
|
41403
|
+
createToolError(errorMessage) {
|
|
41404
|
+
return {
|
|
41405
|
+
content: [
|
|
41406
|
+
{
|
|
41407
|
+
type: "text",
|
|
41408
|
+
text: errorMessage
|
|
41409
|
+
}
|
|
41410
|
+
],
|
|
41411
|
+
isError: true
|
|
41412
|
+
};
|
|
41413
|
+
}
|
|
41414
|
+
/**
|
|
41415
|
+
* Validates tool input arguments against the tool's input schema.
|
|
41416
|
+
*/
|
|
41417
|
+
async validateToolInput(tool, args, toolName) {
|
|
41418
|
+
if (!tool.inputSchema) {
|
|
41419
|
+
return void 0;
|
|
41420
|
+
}
|
|
41421
|
+
const inputObj = normalizeObjectSchema(tool.inputSchema);
|
|
41422
|
+
const schemaToParse = inputObj ?? tool.inputSchema;
|
|
41423
|
+
const parseResult = await safeParseAsync3(schemaToParse, args);
|
|
41424
|
+
if (!parseResult.success) {
|
|
41425
|
+
const error48 = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
41426
|
+
const errorMessage = getParseErrorMessage(error48);
|
|
41427
|
+
throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`);
|
|
41428
|
+
}
|
|
41429
|
+
return parseResult.data;
|
|
41430
|
+
}
|
|
41431
|
+
/**
|
|
41432
|
+
* Validates tool output against the tool's output schema.
|
|
41433
|
+
*/
|
|
41434
|
+
async validateToolOutput(tool, result, toolName) {
|
|
41435
|
+
if (!tool.outputSchema) {
|
|
41436
|
+
return;
|
|
41437
|
+
}
|
|
41438
|
+
if (!("content" in result)) {
|
|
41439
|
+
return;
|
|
41440
|
+
}
|
|
41441
|
+
if (result.isError) {
|
|
41442
|
+
return;
|
|
41443
|
+
}
|
|
41444
|
+
if (!result.structuredContent) {
|
|
41445
|
+
throw new McpError(ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`);
|
|
41446
|
+
}
|
|
41447
|
+
const outputObj = normalizeObjectSchema(tool.outputSchema);
|
|
41448
|
+
const parseResult = await safeParseAsync3(outputObj, result.structuredContent);
|
|
41449
|
+
if (!parseResult.success) {
|
|
41450
|
+
const error48 = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
41451
|
+
const errorMessage = getParseErrorMessage(error48);
|
|
41452
|
+
throw new McpError(ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`);
|
|
41453
|
+
}
|
|
41454
|
+
}
|
|
41455
|
+
/**
|
|
41456
|
+
* Executes a tool handler (either regular or task-based).
|
|
41457
|
+
*/
|
|
41458
|
+
async executeToolHandler(tool, args, extra) {
|
|
41459
|
+
const handler = tool.handler;
|
|
41460
|
+
const isTaskHandler = "createTask" in handler;
|
|
41461
|
+
if (isTaskHandler) {
|
|
41462
|
+
if (!extra.taskStore) {
|
|
41463
|
+
throw new Error("No task store provided.");
|
|
41464
|
+
}
|
|
41465
|
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
|
41466
|
+
if (tool.inputSchema) {
|
|
41467
|
+
const typedHandler = handler;
|
|
41468
|
+
return await Promise.resolve(typedHandler.createTask(args, taskExtra));
|
|
41469
|
+
} else {
|
|
41470
|
+
const typedHandler = handler;
|
|
41471
|
+
return await Promise.resolve(typedHandler.createTask(taskExtra));
|
|
41472
|
+
}
|
|
41473
|
+
}
|
|
41474
|
+
if (tool.inputSchema) {
|
|
41475
|
+
const typedHandler = handler;
|
|
41476
|
+
return await Promise.resolve(typedHandler(args, extra));
|
|
41477
|
+
} else {
|
|
41478
|
+
const typedHandler = handler;
|
|
41479
|
+
return await Promise.resolve(typedHandler(extra));
|
|
41480
|
+
}
|
|
41481
|
+
}
|
|
41482
|
+
/**
|
|
41483
|
+
* Handles automatic task polling for tools with taskSupport 'optional'.
|
|
41484
|
+
*/
|
|
41485
|
+
async handleAutomaticTaskPolling(tool, request, extra) {
|
|
41486
|
+
if (!extra.taskStore) {
|
|
41487
|
+
throw new Error("No task store provided for task-capable tool.");
|
|
41488
|
+
}
|
|
41489
|
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
|
41490
|
+
const handler = tool.handler;
|
|
41491
|
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
|
41492
|
+
const createTaskResult = args ? await Promise.resolve(handler.createTask(args, taskExtra)) : (
|
|
41493
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41494
|
+
await Promise.resolve(handler.createTask(taskExtra))
|
|
41495
|
+
);
|
|
41496
|
+
const taskId = createTaskResult.task.taskId;
|
|
41497
|
+
let task = createTaskResult.task;
|
|
41498
|
+
const pollInterval = task.pollInterval ?? 5e3;
|
|
41499
|
+
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
41500
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
41501
|
+
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
41502
|
+
if (!updatedTask) {
|
|
41503
|
+
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
41504
|
+
}
|
|
41505
|
+
task = updatedTask;
|
|
41506
|
+
}
|
|
41507
|
+
return await extra.taskStore.getTaskResult(taskId);
|
|
41508
|
+
}
|
|
41509
|
+
setCompletionRequestHandler() {
|
|
41510
|
+
if (this._completionHandlerInitialized) {
|
|
41511
|
+
return;
|
|
41512
|
+
}
|
|
41513
|
+
this.server.assertCanSetRequestHandler(getMethodValue(CompleteRequestSchema));
|
|
41514
|
+
this.server.registerCapabilities({
|
|
41515
|
+
completions: {}
|
|
41516
|
+
});
|
|
41517
|
+
this.server.setRequestHandler(CompleteRequestSchema, async (request) => {
|
|
41518
|
+
switch (request.params.ref.type) {
|
|
41519
|
+
case "ref/prompt":
|
|
41520
|
+
assertCompleteRequestPrompt(request);
|
|
41521
|
+
return this.handlePromptCompletion(request, request.params.ref);
|
|
41522
|
+
case "ref/resource":
|
|
41523
|
+
assertCompleteRequestResourceTemplate(request);
|
|
41524
|
+
return this.handleResourceCompletion(request, request.params.ref);
|
|
41525
|
+
default:
|
|
41526
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`);
|
|
41527
|
+
}
|
|
41528
|
+
});
|
|
41529
|
+
this._completionHandlerInitialized = true;
|
|
41530
|
+
}
|
|
41531
|
+
async handlePromptCompletion(request, ref) {
|
|
41532
|
+
const prompt = this._registeredPrompts[ref.name];
|
|
41533
|
+
if (!prompt) {
|
|
41534
|
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${ref.name} not found`);
|
|
41535
|
+
}
|
|
41536
|
+
if (!prompt.enabled) {
|
|
41537
|
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${ref.name} disabled`);
|
|
41538
|
+
}
|
|
41539
|
+
if (!prompt.argsSchema) {
|
|
41540
|
+
return EMPTY_COMPLETION_RESULT;
|
|
41541
|
+
}
|
|
41542
|
+
const promptShape = getObjectShape(prompt.argsSchema);
|
|
41543
|
+
const field = promptShape?.[request.params.argument.name];
|
|
41544
|
+
if (!isCompletable(field)) {
|
|
41545
|
+
return EMPTY_COMPLETION_RESULT;
|
|
41546
|
+
}
|
|
41547
|
+
const completer = getCompleter(field);
|
|
41548
|
+
if (!completer) {
|
|
41549
|
+
return EMPTY_COMPLETION_RESULT;
|
|
41550
|
+
}
|
|
41551
|
+
const suggestions = await completer(request.params.argument.value, request.params.context);
|
|
41552
|
+
return createCompletionResult(suggestions);
|
|
41553
|
+
}
|
|
41554
|
+
async handleResourceCompletion(request, ref) {
|
|
41555
|
+
const template = Object.values(this._registeredResourceTemplates).find((t) => t.resourceTemplate.uriTemplate.toString() === ref.uri);
|
|
41556
|
+
if (!template) {
|
|
41557
|
+
if (this._registeredResources[ref.uri]) {
|
|
41558
|
+
return EMPTY_COMPLETION_RESULT;
|
|
41559
|
+
}
|
|
41560
|
+
throw new McpError(ErrorCode.InvalidParams, `Resource template ${request.params.ref.uri} not found`);
|
|
41561
|
+
}
|
|
41562
|
+
const completer = template.resourceTemplate.completeCallback(request.params.argument.name);
|
|
41563
|
+
if (!completer) {
|
|
41564
|
+
return EMPTY_COMPLETION_RESULT;
|
|
41565
|
+
}
|
|
41566
|
+
const suggestions = await completer(request.params.argument.value, request.params.context);
|
|
41567
|
+
return createCompletionResult(suggestions);
|
|
41568
|
+
}
|
|
41569
|
+
setResourceRequestHandlers() {
|
|
41570
|
+
if (this._resourceHandlersInitialized) {
|
|
41571
|
+
return;
|
|
41572
|
+
}
|
|
41573
|
+
this.server.assertCanSetRequestHandler(getMethodValue(ListResourcesRequestSchema));
|
|
41574
|
+
this.server.assertCanSetRequestHandler(getMethodValue(ListResourceTemplatesRequestSchema));
|
|
41575
|
+
this.server.assertCanSetRequestHandler(getMethodValue(ReadResourceRequestSchema));
|
|
41576
|
+
this.server.registerCapabilities({
|
|
41577
|
+
resources: {
|
|
41578
|
+
listChanged: true
|
|
41579
|
+
}
|
|
41580
|
+
});
|
|
41581
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async (request, extra) => {
|
|
41582
|
+
const resources = Object.entries(this._registeredResources).filter(([_, resource]) => resource.enabled).map(([uri, resource]) => ({
|
|
41583
|
+
uri,
|
|
41584
|
+
name: resource.name,
|
|
41585
|
+
...resource.metadata
|
|
41586
|
+
}));
|
|
41587
|
+
const templateResources = [];
|
|
41588
|
+
for (const template of Object.values(this._registeredResourceTemplates)) {
|
|
41589
|
+
if (!template.resourceTemplate.listCallback) {
|
|
41590
|
+
continue;
|
|
41591
|
+
}
|
|
41592
|
+
const result = await template.resourceTemplate.listCallback(extra);
|
|
41593
|
+
for (const resource of result.resources) {
|
|
41594
|
+
templateResources.push({
|
|
41595
|
+
...template.metadata,
|
|
41596
|
+
// the defined resource metadata should override the template metadata if present
|
|
41597
|
+
...resource
|
|
41598
|
+
});
|
|
41599
|
+
}
|
|
41600
|
+
}
|
|
41601
|
+
return { resources: [...resources, ...templateResources] };
|
|
41602
|
+
});
|
|
41603
|
+
this.server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
|
|
41604
|
+
const resourceTemplates = Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({
|
|
41605
|
+
name,
|
|
41606
|
+
uriTemplate: template.resourceTemplate.uriTemplate.toString(),
|
|
41607
|
+
...template.metadata
|
|
41608
|
+
}));
|
|
41609
|
+
return { resourceTemplates };
|
|
41610
|
+
});
|
|
41611
|
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request, extra) => {
|
|
41612
|
+
const uri = new URL(request.params.uri);
|
|
41613
|
+
const resource = this._registeredResources[uri.toString()];
|
|
41614
|
+
if (resource) {
|
|
41615
|
+
if (!resource.enabled) {
|
|
41616
|
+
throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} disabled`);
|
|
41617
|
+
}
|
|
41618
|
+
return resource.readCallback(uri, extra);
|
|
41619
|
+
}
|
|
41620
|
+
for (const template of Object.values(this._registeredResourceTemplates)) {
|
|
41621
|
+
const variables = template.resourceTemplate.uriTemplate.match(uri.toString());
|
|
41622
|
+
if (variables) {
|
|
41623
|
+
return template.readCallback(uri, variables, extra);
|
|
41624
|
+
}
|
|
41625
|
+
}
|
|
41626
|
+
throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} not found`);
|
|
41627
|
+
});
|
|
41628
|
+
this._resourceHandlersInitialized = true;
|
|
41629
|
+
}
|
|
41630
|
+
setPromptRequestHandlers() {
|
|
41631
|
+
if (this._promptHandlersInitialized) {
|
|
41632
|
+
return;
|
|
41633
|
+
}
|
|
41634
|
+
this.server.assertCanSetRequestHandler(getMethodValue(ListPromptsRequestSchema));
|
|
41635
|
+
this.server.assertCanSetRequestHandler(getMethodValue(GetPromptRequestSchema));
|
|
41636
|
+
this.server.registerCapabilities({
|
|
41637
|
+
prompts: {
|
|
41638
|
+
listChanged: true
|
|
41639
|
+
}
|
|
41640
|
+
});
|
|
41641
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, () => ({
|
|
41642
|
+
prompts: Object.entries(this._registeredPrompts).filter(([, prompt]) => prompt.enabled).map(([name, prompt]) => {
|
|
41643
|
+
return {
|
|
41644
|
+
name,
|
|
41645
|
+
title: prompt.title,
|
|
41646
|
+
description: prompt.description,
|
|
41647
|
+
arguments: prompt.argsSchema ? promptArgumentsFromSchema(prompt.argsSchema) : void 0
|
|
41648
|
+
};
|
|
41649
|
+
})
|
|
41650
|
+
}));
|
|
41651
|
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request, extra) => {
|
|
41652
|
+
const prompt = this._registeredPrompts[request.params.name];
|
|
41653
|
+
if (!prompt) {
|
|
41654
|
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${request.params.name} not found`);
|
|
41655
|
+
}
|
|
41656
|
+
if (!prompt.enabled) {
|
|
41657
|
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${request.params.name} disabled`);
|
|
41658
|
+
}
|
|
41659
|
+
if (prompt.argsSchema) {
|
|
41660
|
+
const argsObj = normalizeObjectSchema(prompt.argsSchema);
|
|
41661
|
+
const parseResult = await safeParseAsync3(argsObj, request.params.arguments);
|
|
41662
|
+
if (!parseResult.success) {
|
|
41663
|
+
const error48 = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
41664
|
+
const errorMessage = getParseErrorMessage(error48);
|
|
41665
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`);
|
|
41666
|
+
}
|
|
41667
|
+
const args = parseResult.data;
|
|
41668
|
+
const cb = prompt.callback;
|
|
41669
|
+
return await Promise.resolve(cb(args, extra));
|
|
41670
|
+
} else {
|
|
41671
|
+
const cb = prompt.callback;
|
|
41672
|
+
return await Promise.resolve(cb(extra));
|
|
41673
|
+
}
|
|
41674
|
+
});
|
|
41675
|
+
this._promptHandlersInitialized = true;
|
|
41676
|
+
}
|
|
41677
|
+
resource(name, uriOrTemplate, ...rest) {
|
|
41678
|
+
let metadata;
|
|
41679
|
+
if (typeof rest[0] === "object") {
|
|
41680
|
+
metadata = rest.shift();
|
|
41681
|
+
}
|
|
41682
|
+
const readCallback = rest[0];
|
|
41683
|
+
if (typeof uriOrTemplate === "string") {
|
|
41684
|
+
if (this._registeredResources[uriOrTemplate]) {
|
|
41685
|
+
throw new Error(`Resource ${uriOrTemplate} is already registered`);
|
|
41686
|
+
}
|
|
41687
|
+
const registeredResource = this._createRegisteredResource(name, void 0, uriOrTemplate, metadata, readCallback);
|
|
41688
|
+
this.setResourceRequestHandlers();
|
|
41689
|
+
this.sendResourceListChanged();
|
|
41690
|
+
return registeredResource;
|
|
41691
|
+
} else {
|
|
41692
|
+
if (this._registeredResourceTemplates[name]) {
|
|
41693
|
+
throw new Error(`Resource template ${name} is already registered`);
|
|
41694
|
+
}
|
|
41695
|
+
const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, void 0, uriOrTemplate, metadata, readCallback);
|
|
41696
|
+
this.setResourceRequestHandlers();
|
|
41697
|
+
this.sendResourceListChanged();
|
|
41698
|
+
return registeredResourceTemplate;
|
|
41699
|
+
}
|
|
41700
|
+
}
|
|
41701
|
+
registerResource(name, uriOrTemplate, config2, readCallback) {
|
|
41702
|
+
if (typeof uriOrTemplate === "string") {
|
|
41703
|
+
if (this._registeredResources[uriOrTemplate]) {
|
|
41704
|
+
throw new Error(`Resource ${uriOrTemplate} is already registered`);
|
|
41705
|
+
}
|
|
41706
|
+
const registeredResource = this._createRegisteredResource(name, config2.title, uriOrTemplate, config2, readCallback);
|
|
41707
|
+
this.setResourceRequestHandlers();
|
|
41708
|
+
this.sendResourceListChanged();
|
|
41709
|
+
return registeredResource;
|
|
41710
|
+
} else {
|
|
41711
|
+
if (this._registeredResourceTemplates[name]) {
|
|
41712
|
+
throw new Error(`Resource template ${name} is already registered`);
|
|
41713
|
+
}
|
|
41714
|
+
const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config2.title, uriOrTemplate, config2, readCallback);
|
|
41715
|
+
this.setResourceRequestHandlers();
|
|
41716
|
+
this.sendResourceListChanged();
|
|
41717
|
+
return registeredResourceTemplate;
|
|
41718
|
+
}
|
|
41719
|
+
}
|
|
41720
|
+
_createRegisteredResource(name, title, uri, metadata, readCallback) {
|
|
41721
|
+
const registeredResource = {
|
|
41722
|
+
name,
|
|
41723
|
+
title,
|
|
41724
|
+
metadata,
|
|
41725
|
+
readCallback,
|
|
41726
|
+
enabled: true,
|
|
41727
|
+
disable: () => registeredResource.update({ enabled: false }),
|
|
41728
|
+
enable: () => registeredResource.update({ enabled: true }),
|
|
41729
|
+
remove: () => registeredResource.update({ uri: null }),
|
|
41730
|
+
update: (updates) => {
|
|
41731
|
+
if (typeof updates.uri !== "undefined" && updates.uri !== uri) {
|
|
41732
|
+
delete this._registeredResources[uri];
|
|
41733
|
+
if (updates.uri)
|
|
41734
|
+
this._registeredResources[updates.uri] = registeredResource;
|
|
41735
|
+
}
|
|
41736
|
+
if (typeof updates.name !== "undefined")
|
|
41737
|
+
registeredResource.name = updates.name;
|
|
41738
|
+
if (typeof updates.title !== "undefined")
|
|
41739
|
+
registeredResource.title = updates.title;
|
|
41740
|
+
if (typeof updates.metadata !== "undefined")
|
|
41741
|
+
registeredResource.metadata = updates.metadata;
|
|
41742
|
+
if (typeof updates.callback !== "undefined")
|
|
41743
|
+
registeredResource.readCallback = updates.callback;
|
|
41744
|
+
if (typeof updates.enabled !== "undefined")
|
|
41745
|
+
registeredResource.enabled = updates.enabled;
|
|
41746
|
+
this.sendResourceListChanged();
|
|
41747
|
+
}
|
|
41748
|
+
};
|
|
41749
|
+
this._registeredResources[uri] = registeredResource;
|
|
41750
|
+
return registeredResource;
|
|
41751
|
+
}
|
|
41752
|
+
_createRegisteredResourceTemplate(name, title, template, metadata, readCallback) {
|
|
41753
|
+
const registeredResourceTemplate = {
|
|
41754
|
+
resourceTemplate: template,
|
|
41755
|
+
title,
|
|
41756
|
+
metadata,
|
|
41757
|
+
readCallback,
|
|
41758
|
+
enabled: true,
|
|
41759
|
+
disable: () => registeredResourceTemplate.update({ enabled: false }),
|
|
41760
|
+
enable: () => registeredResourceTemplate.update({ enabled: true }),
|
|
41761
|
+
remove: () => registeredResourceTemplate.update({ name: null }),
|
|
41762
|
+
update: (updates) => {
|
|
41763
|
+
if (typeof updates.name !== "undefined" && updates.name !== name) {
|
|
41764
|
+
delete this._registeredResourceTemplates[name];
|
|
41765
|
+
if (updates.name)
|
|
41766
|
+
this._registeredResourceTemplates[updates.name] = registeredResourceTemplate;
|
|
41767
|
+
}
|
|
41768
|
+
if (typeof updates.title !== "undefined")
|
|
41769
|
+
registeredResourceTemplate.title = updates.title;
|
|
41770
|
+
if (typeof updates.template !== "undefined")
|
|
41771
|
+
registeredResourceTemplate.resourceTemplate = updates.template;
|
|
41772
|
+
if (typeof updates.metadata !== "undefined")
|
|
41773
|
+
registeredResourceTemplate.metadata = updates.metadata;
|
|
41774
|
+
if (typeof updates.callback !== "undefined")
|
|
41775
|
+
registeredResourceTemplate.readCallback = updates.callback;
|
|
41776
|
+
if (typeof updates.enabled !== "undefined")
|
|
41777
|
+
registeredResourceTemplate.enabled = updates.enabled;
|
|
41778
|
+
this.sendResourceListChanged();
|
|
41779
|
+
}
|
|
41780
|
+
};
|
|
41781
|
+
this._registeredResourceTemplates[name] = registeredResourceTemplate;
|
|
41782
|
+
const variableNames = template.uriTemplate.variableNames;
|
|
41783
|
+
const hasCompleter = Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v));
|
|
41784
|
+
if (hasCompleter) {
|
|
41785
|
+
this.setCompletionRequestHandler();
|
|
41786
|
+
}
|
|
41787
|
+
return registeredResourceTemplate;
|
|
41788
|
+
}
|
|
41789
|
+
_createRegisteredPrompt(name, title, description, argsSchema, callback) {
|
|
41790
|
+
const registeredPrompt = {
|
|
41791
|
+
title,
|
|
41792
|
+
description,
|
|
41793
|
+
argsSchema: argsSchema === void 0 ? void 0 : objectFromShape(argsSchema),
|
|
41794
|
+
callback,
|
|
41795
|
+
enabled: true,
|
|
41796
|
+
disable: () => registeredPrompt.update({ enabled: false }),
|
|
41797
|
+
enable: () => registeredPrompt.update({ enabled: true }),
|
|
41798
|
+
remove: () => registeredPrompt.update({ name: null }),
|
|
41799
|
+
update: (updates) => {
|
|
41800
|
+
if (typeof updates.name !== "undefined" && updates.name !== name) {
|
|
41801
|
+
delete this._registeredPrompts[name];
|
|
41802
|
+
if (updates.name)
|
|
41803
|
+
this._registeredPrompts[updates.name] = registeredPrompt;
|
|
41804
|
+
}
|
|
41805
|
+
if (typeof updates.title !== "undefined")
|
|
41806
|
+
registeredPrompt.title = updates.title;
|
|
41807
|
+
if (typeof updates.description !== "undefined")
|
|
41808
|
+
registeredPrompt.description = updates.description;
|
|
41809
|
+
if (typeof updates.argsSchema !== "undefined")
|
|
41810
|
+
registeredPrompt.argsSchema = objectFromShape(updates.argsSchema);
|
|
41811
|
+
if (typeof updates.callback !== "undefined")
|
|
41812
|
+
registeredPrompt.callback = updates.callback;
|
|
41813
|
+
if (typeof updates.enabled !== "undefined")
|
|
41814
|
+
registeredPrompt.enabled = updates.enabled;
|
|
41815
|
+
this.sendPromptListChanged();
|
|
41816
|
+
}
|
|
41817
|
+
};
|
|
41818
|
+
this._registeredPrompts[name] = registeredPrompt;
|
|
41819
|
+
if (argsSchema) {
|
|
41820
|
+
const hasCompletable = Object.values(argsSchema).some((field) => {
|
|
41821
|
+
const inner = field instanceof ZodOptional ? field._def?.innerType : field;
|
|
41822
|
+
return isCompletable(inner);
|
|
41823
|
+
});
|
|
41824
|
+
if (hasCompletable) {
|
|
41825
|
+
this.setCompletionRequestHandler();
|
|
41826
|
+
}
|
|
41827
|
+
}
|
|
41828
|
+
return registeredPrompt;
|
|
41829
|
+
}
|
|
41830
|
+
_createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) {
|
|
41831
|
+
validateAndWarnToolName(name);
|
|
41832
|
+
const registeredTool = {
|
|
41833
|
+
title,
|
|
41834
|
+
description,
|
|
41835
|
+
inputSchema: getZodSchemaObject(inputSchema),
|
|
41836
|
+
outputSchema: getZodSchemaObject(outputSchema),
|
|
41837
|
+
annotations,
|
|
41838
|
+
execution,
|
|
41839
|
+
_meta,
|
|
41840
|
+
handler,
|
|
41841
|
+
enabled: true,
|
|
41842
|
+
disable: () => registeredTool.update({ enabled: false }),
|
|
41843
|
+
enable: () => registeredTool.update({ enabled: true }),
|
|
41844
|
+
remove: () => registeredTool.update({ name: null }),
|
|
41845
|
+
update: (updates) => {
|
|
41846
|
+
if (typeof updates.name !== "undefined" && updates.name !== name) {
|
|
41847
|
+
if (typeof updates.name === "string") {
|
|
41848
|
+
validateAndWarnToolName(updates.name);
|
|
41849
|
+
}
|
|
41850
|
+
delete this._registeredTools[name];
|
|
41851
|
+
if (updates.name)
|
|
41852
|
+
this._registeredTools[updates.name] = registeredTool;
|
|
41853
|
+
}
|
|
41854
|
+
if (typeof updates.title !== "undefined")
|
|
41855
|
+
registeredTool.title = updates.title;
|
|
41856
|
+
if (typeof updates.description !== "undefined")
|
|
41857
|
+
registeredTool.description = updates.description;
|
|
41858
|
+
if (typeof updates.paramsSchema !== "undefined")
|
|
41859
|
+
registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
|
|
41860
|
+
if (typeof updates.outputSchema !== "undefined")
|
|
41861
|
+
registeredTool.outputSchema = objectFromShape(updates.outputSchema);
|
|
41862
|
+
if (typeof updates.callback !== "undefined")
|
|
41863
|
+
registeredTool.handler = updates.callback;
|
|
41864
|
+
if (typeof updates.annotations !== "undefined")
|
|
41865
|
+
registeredTool.annotations = updates.annotations;
|
|
41866
|
+
if (typeof updates._meta !== "undefined")
|
|
41867
|
+
registeredTool._meta = updates._meta;
|
|
41868
|
+
if (typeof updates.enabled !== "undefined")
|
|
41869
|
+
registeredTool.enabled = updates.enabled;
|
|
41870
|
+
this.sendToolListChanged();
|
|
41871
|
+
}
|
|
41872
|
+
};
|
|
41873
|
+
this._registeredTools[name] = registeredTool;
|
|
41874
|
+
this.setToolRequestHandlers();
|
|
41875
|
+
this.sendToolListChanged();
|
|
41876
|
+
return registeredTool;
|
|
41877
|
+
}
|
|
41878
|
+
/**
|
|
41879
|
+
* tool() implementation. Parses arguments passed to overrides defined above.
|
|
41880
|
+
*/
|
|
41881
|
+
tool(name, ...rest) {
|
|
41882
|
+
if (this._registeredTools[name]) {
|
|
41883
|
+
throw new Error(`Tool ${name} is already registered`);
|
|
41884
|
+
}
|
|
41885
|
+
let description;
|
|
41886
|
+
let inputSchema;
|
|
41887
|
+
let outputSchema;
|
|
41888
|
+
let annotations;
|
|
41889
|
+
if (typeof rest[0] === "string") {
|
|
41890
|
+
description = rest.shift();
|
|
41891
|
+
}
|
|
41892
|
+
if (rest.length > 1) {
|
|
41893
|
+
const firstArg = rest[0];
|
|
41894
|
+
if (isZodRawShapeCompat(firstArg)) {
|
|
41895
|
+
inputSchema = rest.shift();
|
|
41896
|
+
if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShapeCompat(rest[0])) {
|
|
41897
|
+
annotations = rest.shift();
|
|
41898
|
+
}
|
|
41899
|
+
} else if (typeof firstArg === "object" && firstArg !== null) {
|
|
41900
|
+
annotations = rest.shift();
|
|
41901
|
+
}
|
|
41902
|
+
}
|
|
41903
|
+
const callback = rest[0];
|
|
41904
|
+
return this._createRegisteredTool(name, void 0, description, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, void 0, callback);
|
|
41905
|
+
}
|
|
41906
|
+
/**
|
|
41907
|
+
* Registers a tool with a config object and callback.
|
|
41908
|
+
*/
|
|
41909
|
+
registerTool(name, config2, cb) {
|
|
41910
|
+
if (this._registeredTools[name]) {
|
|
41911
|
+
throw new Error(`Tool ${name} is already registered`);
|
|
41912
|
+
}
|
|
41913
|
+
const { title, description, inputSchema, outputSchema, annotations, _meta } = config2;
|
|
41914
|
+
return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, { taskSupport: "forbidden" }, _meta, cb);
|
|
41915
|
+
}
|
|
41916
|
+
prompt(name, ...rest) {
|
|
41917
|
+
if (this._registeredPrompts[name]) {
|
|
41918
|
+
throw new Error(`Prompt ${name} is already registered`);
|
|
41919
|
+
}
|
|
41920
|
+
let description;
|
|
41921
|
+
if (typeof rest[0] === "string") {
|
|
41922
|
+
description = rest.shift();
|
|
41923
|
+
}
|
|
41924
|
+
let argsSchema;
|
|
41925
|
+
if (rest.length > 1) {
|
|
41926
|
+
argsSchema = rest.shift();
|
|
41927
|
+
}
|
|
41928
|
+
const cb = rest[0];
|
|
41929
|
+
const registeredPrompt = this._createRegisteredPrompt(name, void 0, description, argsSchema, cb);
|
|
41930
|
+
this.setPromptRequestHandlers();
|
|
41931
|
+
this.sendPromptListChanged();
|
|
41932
|
+
return registeredPrompt;
|
|
41933
|
+
}
|
|
41934
|
+
/**
|
|
41935
|
+
* Registers a prompt with a config object and callback.
|
|
41936
|
+
*/
|
|
41937
|
+
registerPrompt(name, config2, cb) {
|
|
41938
|
+
if (this._registeredPrompts[name]) {
|
|
41939
|
+
throw new Error(`Prompt ${name} is already registered`);
|
|
41940
|
+
}
|
|
41941
|
+
const { title, description, argsSchema } = config2;
|
|
41942
|
+
const registeredPrompt = this._createRegisteredPrompt(name, title, description, argsSchema, cb);
|
|
41943
|
+
this.setPromptRequestHandlers();
|
|
41944
|
+
this.sendPromptListChanged();
|
|
41945
|
+
return registeredPrompt;
|
|
41946
|
+
}
|
|
41947
|
+
/**
|
|
41948
|
+
* Checks if the server is connected to a transport.
|
|
41949
|
+
* @returns True if the server is connected
|
|
41950
|
+
*/
|
|
41951
|
+
isConnected() {
|
|
41952
|
+
return this.server.transport !== void 0;
|
|
41953
|
+
}
|
|
41954
|
+
/**
|
|
41955
|
+
* Sends a logging message to the client, if connected.
|
|
41956
|
+
* Note: You only need to send the parameters object, not the entire JSON RPC message
|
|
41957
|
+
* @see LoggingMessageNotification
|
|
41958
|
+
* @param params
|
|
41959
|
+
* @param sessionId optional for stateless and backward compatibility
|
|
41960
|
+
*/
|
|
41961
|
+
async sendLoggingMessage(params, sessionId) {
|
|
41962
|
+
return this.server.sendLoggingMessage(params, sessionId);
|
|
41963
|
+
}
|
|
41964
|
+
/**
|
|
41965
|
+
* Sends a resource list changed event to the client, if connected.
|
|
41966
|
+
*/
|
|
41967
|
+
sendResourceListChanged() {
|
|
41968
|
+
if (this.isConnected()) {
|
|
41969
|
+
this.server.sendResourceListChanged();
|
|
41970
|
+
}
|
|
41971
|
+
}
|
|
41972
|
+
/**
|
|
41973
|
+
* Sends a tool list changed event to the client, if connected.
|
|
41974
|
+
*/
|
|
41975
|
+
sendToolListChanged() {
|
|
41976
|
+
if (this.isConnected()) {
|
|
41977
|
+
this.server.sendToolListChanged();
|
|
41978
|
+
}
|
|
41979
|
+
}
|
|
41980
|
+
/**
|
|
41981
|
+
* Sends a prompt list changed event to the client, if connected.
|
|
41982
|
+
*/
|
|
41983
|
+
sendPromptListChanged() {
|
|
41984
|
+
if (this.isConnected()) {
|
|
41985
|
+
this.server.sendPromptListChanged();
|
|
41986
|
+
}
|
|
41987
|
+
}
|
|
41988
|
+
};
|
|
41989
|
+
var EMPTY_OBJECT_JSON_SCHEMA = {
|
|
41990
|
+
type: "object",
|
|
41991
|
+
properties: {}
|
|
41992
|
+
};
|
|
41993
|
+
function isZodTypeLike(value) {
|
|
41994
|
+
return value !== null && typeof value === "object" && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
41995
|
+
}
|
|
41996
|
+
function isZodSchemaInstance(obj) {
|
|
41997
|
+
return "_def" in obj || "_zod" in obj || isZodTypeLike(obj);
|
|
41998
|
+
}
|
|
41999
|
+
function isZodRawShapeCompat(obj) {
|
|
42000
|
+
if (typeof obj !== "object" || obj === null) {
|
|
42001
|
+
return false;
|
|
42002
|
+
}
|
|
42003
|
+
if (isZodSchemaInstance(obj)) {
|
|
42004
|
+
return false;
|
|
42005
|
+
}
|
|
42006
|
+
if (Object.keys(obj).length === 0) {
|
|
42007
|
+
return true;
|
|
42008
|
+
}
|
|
42009
|
+
return Object.values(obj).some(isZodTypeLike);
|
|
42010
|
+
}
|
|
42011
|
+
function getZodSchemaObject(schema) {
|
|
42012
|
+
if (!schema) {
|
|
42013
|
+
return void 0;
|
|
42014
|
+
}
|
|
42015
|
+
if (isZodRawShapeCompat(schema)) {
|
|
42016
|
+
return objectFromShape(schema);
|
|
42017
|
+
}
|
|
42018
|
+
return schema;
|
|
42019
|
+
}
|
|
42020
|
+
function promptArgumentsFromSchema(schema) {
|
|
42021
|
+
const shape = getObjectShape(schema);
|
|
42022
|
+
if (!shape)
|
|
42023
|
+
return [];
|
|
42024
|
+
return Object.entries(shape).map(([name, field]) => {
|
|
42025
|
+
const description = getSchemaDescription(field);
|
|
42026
|
+
const isOptional = isSchemaOptional(field);
|
|
42027
|
+
return {
|
|
42028
|
+
name,
|
|
42029
|
+
description,
|
|
42030
|
+
required: !isOptional
|
|
42031
|
+
};
|
|
42032
|
+
});
|
|
42033
|
+
}
|
|
42034
|
+
function getMethodValue(schema) {
|
|
42035
|
+
const shape = getObjectShape(schema);
|
|
42036
|
+
const methodSchema = shape?.method;
|
|
42037
|
+
if (!methodSchema) {
|
|
42038
|
+
throw new Error("Schema is missing a method literal");
|
|
42039
|
+
}
|
|
42040
|
+
const value = getLiteralValue(methodSchema);
|
|
42041
|
+
if (typeof value === "string") {
|
|
42042
|
+
return value;
|
|
42043
|
+
}
|
|
42044
|
+
throw new Error("Schema method literal must be a string");
|
|
42045
|
+
}
|
|
42046
|
+
function createCompletionResult(suggestions) {
|
|
42047
|
+
return {
|
|
42048
|
+
completion: {
|
|
42049
|
+
values: suggestions.slice(0, 100),
|
|
42050
|
+
total: suggestions.length,
|
|
42051
|
+
hasMore: suggestions.length > 100
|
|
42052
|
+
}
|
|
42053
|
+
};
|
|
42054
|
+
}
|
|
42055
|
+
var EMPTY_COMPLETION_RESULT = {
|
|
42056
|
+
completion: {
|
|
42057
|
+
values: [],
|
|
42058
|
+
hasMore: false
|
|
42059
|
+
}
|
|
42060
|
+
};
|
|
42061
|
+
|
|
39672
42062
|
// ../node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
39673
42063
|
import process3 from "node:process";
|
|
39674
42064
|
|
|
@@ -39772,9 +42162,9 @@ function bind(fn, thisArg) {
|
|
|
39772
42162
|
var { toString } = Object.prototype;
|
|
39773
42163
|
var { getPrototypeOf } = Object;
|
|
39774
42164
|
var { iterator, toStringTag } = Symbol;
|
|
39775
|
-
var kindOf = /* @__PURE__ */ ((
|
|
42165
|
+
var kindOf = /* @__PURE__ */ ((cache2) => (thing) => {
|
|
39776
42166
|
const str = toString.call(thing);
|
|
39777
|
-
return
|
|
42167
|
+
return cache2[str] || (cache2[str] = str.slice(8, -1).toLowerCase());
|
|
39778
42168
|
})(/* @__PURE__ */ Object.create(null));
|
|
39779
42169
|
var kindOfTest = (type) => {
|
|
39780
42170
|
type = type.toLowerCase();
|
|
@@ -40281,9 +42671,9 @@ function isVisitable(thing) {
|
|
|
40281
42671
|
function removeBrackets(key) {
|
|
40282
42672
|
return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
|
|
40283
42673
|
}
|
|
40284
|
-
function renderKey(
|
|
40285
|
-
if (!
|
|
40286
|
-
return
|
|
42674
|
+
function renderKey(path3, key, dots) {
|
|
42675
|
+
if (!path3) return key;
|
|
42676
|
+
return path3.concat(key).map(function each(token, i) {
|
|
40287
42677
|
token = removeBrackets(token);
|
|
40288
42678
|
return !dots && i ? "[" + token + "]" : token;
|
|
40289
42679
|
}).join(dots ? "." : "");
|
|
@@ -40336,13 +42726,13 @@ function toFormData(obj, formData, options) {
|
|
|
40336
42726
|
}
|
|
40337
42727
|
return value;
|
|
40338
42728
|
}
|
|
40339
|
-
function defaultVisitor(value, key,
|
|
42729
|
+
function defaultVisitor(value, key, path3) {
|
|
40340
42730
|
let arr = value;
|
|
40341
42731
|
if (utils_default.isReactNative(formData) && utils_default.isReactNativeBlob(value)) {
|
|
40342
|
-
formData.append(renderKey(
|
|
42732
|
+
formData.append(renderKey(path3, key, dots), convertValue(value));
|
|
40343
42733
|
return false;
|
|
40344
42734
|
}
|
|
40345
|
-
if (value && !
|
|
42735
|
+
if (value && !path3 && typeof value === "object") {
|
|
40346
42736
|
if (utils_default.endsWith(key, "{}")) {
|
|
40347
42737
|
key = metaTokens ? key : key.slice(0, -2);
|
|
40348
42738
|
value = JSON.stringify(value);
|
|
@@ -40361,7 +42751,7 @@ function toFormData(obj, formData, options) {
|
|
|
40361
42751
|
if (isVisitable(value)) {
|
|
40362
42752
|
return true;
|
|
40363
42753
|
}
|
|
40364
|
-
formData.append(renderKey(
|
|
42754
|
+
formData.append(renderKey(path3, key, dots), convertValue(value));
|
|
40365
42755
|
return false;
|
|
40366
42756
|
}
|
|
40367
42757
|
const stack = [];
|
|
@@ -40370,16 +42760,16 @@ function toFormData(obj, formData, options) {
|
|
|
40370
42760
|
convertValue,
|
|
40371
42761
|
isVisitable
|
|
40372
42762
|
});
|
|
40373
|
-
function build(value,
|
|
42763
|
+
function build(value, path3) {
|
|
40374
42764
|
if (utils_default.isUndefined(value)) return;
|
|
40375
42765
|
if (stack.indexOf(value) !== -1) {
|
|
40376
|
-
throw Error("Circular reference detected in " +
|
|
42766
|
+
throw Error("Circular reference detected in " + path3.join("."));
|
|
40377
42767
|
}
|
|
40378
42768
|
stack.push(value);
|
|
40379
42769
|
utils_default.forEach(value, function each(el, key) {
|
|
40380
|
-
const result = !(utils_default.isUndefined(el) || el === null) && visitor.call(formData, el, utils_default.isString(key) ? key.trim() : key,
|
|
42770
|
+
const result = !(utils_default.isUndefined(el) || el === null) && visitor.call(formData, el, utils_default.isString(key) ? key.trim() : key, path3, exposedHelpers);
|
|
40381
42771
|
if (result === true) {
|
|
40382
|
-
build(el,
|
|
42772
|
+
build(el, path3 ? path3.concat(key) : [key]);
|
|
40383
42773
|
}
|
|
40384
42774
|
});
|
|
40385
42775
|
stack.pop();
|
|
@@ -40528,7 +42918,7 @@ var transitional_default = {
|
|
|
40528
42918
|
};
|
|
40529
42919
|
|
|
40530
42920
|
// ../node_modules/axios/lib/platform/node/index.js
|
|
40531
|
-
import
|
|
42921
|
+
import crypto2 from "crypto";
|
|
40532
42922
|
|
|
40533
42923
|
// ../node_modules/axios/lib/platform/node/classes/URLSearchParams.js
|
|
40534
42924
|
import url2 from "url";
|
|
@@ -40546,7 +42936,7 @@ var generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
40546
42936
|
let str = "";
|
|
40547
42937
|
const { length } = alphabet;
|
|
40548
42938
|
const randomValues = new Uint32Array(size);
|
|
40549
|
-
|
|
42939
|
+
crypto2.randomFillSync(randomValues);
|
|
40550
42940
|
for (let i = 0; i < size; i++) {
|
|
40551
42941
|
str += alphabet[randomValues[i] % length];
|
|
40552
42942
|
}
|
|
@@ -40591,7 +42981,7 @@ var platform_default = {
|
|
|
40591
42981
|
// ../node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
40592
42982
|
function toURLEncodedForm(data, options) {
|
|
40593
42983
|
return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
|
|
40594
|
-
visitor: function(value, key,
|
|
42984
|
+
visitor: function(value, key, path3, helpers) {
|
|
40595
42985
|
if (platform_default.isNode && utils_default.isBuffer(value)) {
|
|
40596
42986
|
this.append(key, value.toString("base64"));
|
|
40597
42987
|
return false;
|
|
@@ -40621,11 +43011,11 @@ function arrayToObject(arr) {
|
|
|
40621
43011
|
return obj;
|
|
40622
43012
|
}
|
|
40623
43013
|
function formDataToJSON(formData) {
|
|
40624
|
-
function buildPath(
|
|
40625
|
-
let name =
|
|
43014
|
+
function buildPath(path3, value, target, index) {
|
|
43015
|
+
let name = path3[index++];
|
|
40626
43016
|
if (name === "__proto__") return true;
|
|
40627
43017
|
const isNumericKey = Number.isFinite(+name);
|
|
40628
|
-
const isLast = index >=
|
|
43018
|
+
const isLast = index >= path3.length;
|
|
40629
43019
|
name = !name && utils_default.isArray(target) ? target.length : name;
|
|
40630
43020
|
if (isLast) {
|
|
40631
43021
|
if (utils_default.hasOwnProp(target, name)) {
|
|
@@ -40638,7 +43028,7 @@ function formDataToJSON(formData) {
|
|
|
40638
43028
|
if (!target[name] || !utils_default.isObject(target[name])) {
|
|
40639
43029
|
target[name] = [];
|
|
40640
43030
|
}
|
|
40641
|
-
const result = buildPath(
|
|
43031
|
+
const result = buildPath(path3, value, target[name], index);
|
|
40642
43032
|
if (result && utils_default.isArray(target[name])) {
|
|
40643
43033
|
target[name] = arrayToObject(target[name]);
|
|
40644
43034
|
}
|
|
@@ -40814,7 +43204,7 @@ var parseHeaders_default = (rawHeaders) => {
|
|
|
40814
43204
|
};
|
|
40815
43205
|
|
|
40816
43206
|
// ../node_modules/axios/lib/core/AxiosHeaders.js
|
|
40817
|
-
var $internals = Symbol("internals");
|
|
43207
|
+
var $internals = /* @__PURE__ */ Symbol("internals");
|
|
40818
43208
|
function normalizeHeader(header) {
|
|
40819
43209
|
return header && String(header).trim().toLowerCase();
|
|
40820
43210
|
}
|
|
@@ -41178,7 +43568,7 @@ import stream3 from "stream";
|
|
|
41178
43568
|
|
|
41179
43569
|
// ../node_modules/axios/lib/helpers/AxiosTransformStream.js
|
|
41180
43570
|
import stream from "stream";
|
|
41181
|
-
var kInternals = Symbol("internals");
|
|
43571
|
+
var kInternals = /* @__PURE__ */ Symbol("internals");
|
|
41182
43572
|
var AxiosTransformStream = class extends stream.Transform {
|
|
41183
43573
|
constructor(options) {
|
|
41184
43574
|
options = utils_default.toFlatObject(
|
|
@@ -42019,9 +44409,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
|
|
|
42019
44409
|
auth = urlUsername + ":" + urlPassword;
|
|
42020
44410
|
}
|
|
42021
44411
|
auth && headers.delete("authorization");
|
|
42022
|
-
let
|
|
44412
|
+
let path3;
|
|
42023
44413
|
try {
|
|
42024
|
-
|
|
44414
|
+
path3 = buildURL(
|
|
42025
44415
|
parsed.pathname + parsed.search,
|
|
42026
44416
|
config2.params,
|
|
42027
44417
|
config2.paramsSerializer
|
|
@@ -42039,7 +44429,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
|
|
|
42039
44429
|
false
|
|
42040
44430
|
);
|
|
42041
44431
|
const options = {
|
|
42042
|
-
path:
|
|
44432
|
+
path: path3,
|
|
42043
44433
|
method,
|
|
42044
44434
|
headers: headers.toJSON(),
|
|
42045
44435
|
agents: { http: config2.httpAgent, https: config2.httpsAgent },
|
|
@@ -42288,14 +44678,14 @@ var isURLSameOrigin_default = platform_default.hasStandardBrowserEnv ? /* @__PUR
|
|
|
42288
44678
|
var cookies_default = platform_default.hasStandardBrowserEnv ? (
|
|
42289
44679
|
// Standard browser envs support document.cookie
|
|
42290
44680
|
{
|
|
42291
|
-
write(name, value, expires,
|
|
44681
|
+
write(name, value, expires, path3, domain2, secure, sameSite) {
|
|
42292
44682
|
if (typeof document === "undefined") return;
|
|
42293
44683
|
const cookie = [`${name}=${encodeURIComponent(value)}`];
|
|
42294
44684
|
if (utils_default.isNumber(expires)) {
|
|
42295
44685
|
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
|
42296
44686
|
}
|
|
42297
|
-
if (utils_default.isString(
|
|
42298
|
-
cookie.push(`path=${
|
|
44687
|
+
if (utils_default.isString(path3)) {
|
|
44688
|
+
cookie.push(`path=${path3}`);
|
|
42299
44689
|
}
|
|
42300
44690
|
if (utils_default.isString(domain2)) {
|
|
42301
44691
|
cookie.push(`domain=${domain2}`);
|
|
@@ -43635,8 +46025,11 @@ var MOCK_FIXTURES = {
|
|
|
43635
46025
|
// src/index.ts
|
|
43636
46026
|
var z3 = external_exports || zod_default || zod_exports;
|
|
43637
46027
|
var XAI_API_KEY = process.env.XAI_API_KEY;
|
|
46028
|
+
var PACKAGE_VERSION = getPackageVersion(import.meta.url);
|
|
46029
|
+
var GROK_SEARCH_MODEL = process.env.GROK_SEARCH_MODEL || "grok-4-1-fast-reasoning";
|
|
46030
|
+
var GROK_IMAGE_MODEL = process.env.GROK_IMAGE_MODEL || "grok-imagine-image";
|
|
46031
|
+
var GROK_VIDEO_MODEL = process.env.GROK_VIDEO_MODEL || "grok-imagine-video";
|
|
43638
46032
|
var aspectRatioValues = ["1:1", "16:9", "9:16"];
|
|
43639
|
-
var MAX_SEARCH_RESULTS = 100;
|
|
43640
46033
|
var MAX_EMBEDDED_MEDIA_BYTES = Number.parseInt(
|
|
43641
46034
|
process.env.GROK_MAX_EMBEDDED_MEDIA_BYTES || "5242880",
|
|
43642
46035
|
10
|
|
@@ -43673,314 +46066,6 @@ var videoStatusSchema = z3.object({
|
|
|
43673
46066
|
request_id: z3.string().min(1).max(200),
|
|
43674
46067
|
output_dir: z3.string().optional()
|
|
43675
46068
|
}).strict();
|
|
43676
|
-
var TOOL_DEFINITIONS = [
|
|
43677
|
-
{
|
|
43678
|
-
name: "grok_search_x",
|
|
43679
|
-
description: "Search X posts and threads via Grok.",
|
|
43680
|
-
inputSchema: {
|
|
43681
|
-
type: "object",
|
|
43682
|
-
additionalProperties: false,
|
|
43683
|
-
properties: {
|
|
43684
|
-
query: {
|
|
43685
|
-
type: "string",
|
|
43686
|
-
minLength: 1,
|
|
43687
|
-
maxLength: 500,
|
|
43688
|
-
description: "Search query for X content"
|
|
43689
|
-
},
|
|
43690
|
-
allowed_handles: {
|
|
43691
|
-
type: "array",
|
|
43692
|
-
items: { type: "string", minLength: 1, maxLength: 50 },
|
|
43693
|
-
maxItems: 10,
|
|
43694
|
-
description: "Optional X handles to search"
|
|
43695
|
-
},
|
|
43696
|
-
from_date: {
|
|
43697
|
-
type: "string",
|
|
43698
|
-
format: "date-time",
|
|
43699
|
-
description: "Optional inclusive start time"
|
|
43700
|
-
},
|
|
43701
|
-
to_date: {
|
|
43702
|
-
type: "string",
|
|
43703
|
-
format: "date-time",
|
|
43704
|
-
description: "Optional inclusive end time"
|
|
43705
|
-
},
|
|
43706
|
-
limit: {
|
|
43707
|
-
type: "integer",
|
|
43708
|
-
minimum: 1,
|
|
43709
|
-
maximum: MAX_SEARCH_RESULTS,
|
|
43710
|
-
default: 20,
|
|
43711
|
-
description: "Maximum results to return"
|
|
43712
|
-
},
|
|
43713
|
-
offset: {
|
|
43714
|
-
type: "integer",
|
|
43715
|
-
minimum: 0,
|
|
43716
|
-
default: 0,
|
|
43717
|
-
description: "Results to skip first"
|
|
43718
|
-
},
|
|
43719
|
-
output_dir: {
|
|
43720
|
-
type: "string",
|
|
43721
|
-
description: "Optional directory to save search results"
|
|
43722
|
-
}
|
|
43723
|
-
},
|
|
43724
|
-
required: ["query"]
|
|
43725
|
-
},
|
|
43726
|
-
outputSchema: {
|
|
43727
|
-
type: "object",
|
|
43728
|
-
additionalProperties: false,
|
|
43729
|
-
properties: {
|
|
43730
|
-
query: { type: "string" },
|
|
43731
|
-
summary: { type: "string" },
|
|
43732
|
-
results: {
|
|
43733
|
-
type: "array",
|
|
43734
|
-
items: {
|
|
43735
|
-
type: "object",
|
|
43736
|
-
additionalProperties: false,
|
|
43737
|
-
properties: {
|
|
43738
|
-
id: { type: "string" },
|
|
43739
|
-
text: { type: "string" },
|
|
43740
|
-
author: { type: "string" },
|
|
43741
|
-
created_at: { type: "string" },
|
|
43742
|
-
url: { type: "string" }
|
|
43743
|
-
},
|
|
43744
|
-
required: ["text"]
|
|
43745
|
-
}
|
|
43746
|
-
},
|
|
43747
|
-
citations: {
|
|
43748
|
-
type: "array",
|
|
43749
|
-
items: {
|
|
43750
|
-
type: "object",
|
|
43751
|
-
additionalProperties: false,
|
|
43752
|
-
properties: {
|
|
43753
|
-
url: { type: "string" },
|
|
43754
|
-
title: { type: "string" }
|
|
43755
|
-
},
|
|
43756
|
-
required: ["url"]
|
|
43757
|
-
}
|
|
43758
|
-
},
|
|
43759
|
-
total: { type: "integer" },
|
|
43760
|
-
offset: { type: "integer" },
|
|
43761
|
-
limit: { type: "integer" },
|
|
43762
|
-
has_more: { type: "boolean" }
|
|
43763
|
-
},
|
|
43764
|
-
required: [
|
|
43765
|
-
"query",
|
|
43766
|
-
"summary",
|
|
43767
|
-
"results",
|
|
43768
|
-
"citations",
|
|
43769
|
-
"total",
|
|
43770
|
-
"offset",
|
|
43771
|
-
"limit",
|
|
43772
|
-
"has_more"
|
|
43773
|
-
]
|
|
43774
|
-
}
|
|
43775
|
-
},
|
|
43776
|
-
{
|
|
43777
|
-
name: "grok_search_web",
|
|
43778
|
-
description: "Search the public web via Grok.",
|
|
43779
|
-
inputSchema: {
|
|
43780
|
-
type: "object",
|
|
43781
|
-
additionalProperties: false,
|
|
43782
|
-
properties: {
|
|
43783
|
-
query: {
|
|
43784
|
-
type: "string",
|
|
43785
|
-
minLength: 1,
|
|
43786
|
-
maxLength: 500,
|
|
43787
|
-
description: "Search query for web search"
|
|
43788
|
-
},
|
|
43789
|
-
allowed_domains: {
|
|
43790
|
-
type: "array",
|
|
43791
|
-
items: { type: "string", minLength: 1, maxLength: 255 },
|
|
43792
|
-
maxItems: 20,
|
|
43793
|
-
description: "Optional domains to allow"
|
|
43794
|
-
},
|
|
43795
|
-
limit: {
|
|
43796
|
-
type: "integer",
|
|
43797
|
-
minimum: 1,
|
|
43798
|
-
maximum: MAX_SEARCH_RESULTS,
|
|
43799
|
-
default: 20,
|
|
43800
|
-
description: "Maximum results to return"
|
|
43801
|
-
},
|
|
43802
|
-
offset: {
|
|
43803
|
-
type: "integer",
|
|
43804
|
-
minimum: 0,
|
|
43805
|
-
default: 0,
|
|
43806
|
-
description: "Results to skip first"
|
|
43807
|
-
},
|
|
43808
|
-
output_dir: {
|
|
43809
|
-
type: "string",
|
|
43810
|
-
description: "Optional directory to save search results"
|
|
43811
|
-
}
|
|
43812
|
-
},
|
|
43813
|
-
required: ["query"]
|
|
43814
|
-
},
|
|
43815
|
-
outputSchema: {
|
|
43816
|
-
type: "object",
|
|
43817
|
-
additionalProperties: false,
|
|
43818
|
-
properties: {
|
|
43819
|
-
query: { type: "string" },
|
|
43820
|
-
summary: { type: "string" },
|
|
43821
|
-
results: {
|
|
43822
|
-
type: "array",
|
|
43823
|
-
items: {
|
|
43824
|
-
type: "object",
|
|
43825
|
-
additionalProperties: false,
|
|
43826
|
-
properties: {
|
|
43827
|
-
title: { type: "string" },
|
|
43828
|
-
url: { type: "string" },
|
|
43829
|
-
snippet: { type: "string" }
|
|
43830
|
-
},
|
|
43831
|
-
required: ["title", "url"]
|
|
43832
|
-
}
|
|
43833
|
-
},
|
|
43834
|
-
citations: {
|
|
43835
|
-
type: "array",
|
|
43836
|
-
items: {
|
|
43837
|
-
type: "object",
|
|
43838
|
-
additionalProperties: false,
|
|
43839
|
-
properties: {
|
|
43840
|
-
url: { type: "string" },
|
|
43841
|
-
title: { type: "string" }
|
|
43842
|
-
},
|
|
43843
|
-
required: ["url"]
|
|
43844
|
-
}
|
|
43845
|
-
},
|
|
43846
|
-
total: { type: "integer" },
|
|
43847
|
-
offset: { type: "integer" },
|
|
43848
|
-
limit: { type: "integer" },
|
|
43849
|
-
has_more: { type: "boolean" }
|
|
43850
|
-
},
|
|
43851
|
-
required: [
|
|
43852
|
-
"query",
|
|
43853
|
-
"summary",
|
|
43854
|
-
"results",
|
|
43855
|
-
"citations",
|
|
43856
|
-
"total",
|
|
43857
|
-
"offset",
|
|
43858
|
-
"limit",
|
|
43859
|
-
"has_more"
|
|
43860
|
-
]
|
|
43861
|
-
}
|
|
43862
|
-
},
|
|
43863
|
-
{
|
|
43864
|
-
name: "grok_imagine",
|
|
43865
|
-
description: "Generate images from a text prompt.",
|
|
43866
|
-
inputSchema: {
|
|
43867
|
-
type: "object",
|
|
43868
|
-
additionalProperties: false,
|
|
43869
|
-
properties: {
|
|
43870
|
-
prompt: {
|
|
43871
|
-
type: "string",
|
|
43872
|
-
minLength: 1,
|
|
43873
|
-
maxLength: 2e3,
|
|
43874
|
-
description: "Prompt for image generation"
|
|
43875
|
-
},
|
|
43876
|
-
aspect_ratio: {
|
|
43877
|
-
type: "string",
|
|
43878
|
-
enum: [...aspectRatioValues],
|
|
43879
|
-
default: "1:1",
|
|
43880
|
-
description: "Image aspect ratio"
|
|
43881
|
-
},
|
|
43882
|
-
output_dir: {
|
|
43883
|
-
type: "string",
|
|
43884
|
-
description: "Optional directory to save generated images"
|
|
43885
|
-
}
|
|
43886
|
-
},
|
|
43887
|
-
required: ["prompt"]
|
|
43888
|
-
},
|
|
43889
|
-
outputSchema: {
|
|
43890
|
-
type: "object",
|
|
43891
|
-
additionalProperties: false,
|
|
43892
|
-
properties: {
|
|
43893
|
-
prompt: { type: "string" },
|
|
43894
|
-
aspect_ratio: { type: "string" },
|
|
43895
|
-
images: {
|
|
43896
|
-
type: "array",
|
|
43897
|
-
items: {
|
|
43898
|
-
type: "object",
|
|
43899
|
-
additionalProperties: false,
|
|
43900
|
-
properties: {
|
|
43901
|
-
url: { type: "string" },
|
|
43902
|
-
revised_prompt: { type: "string" }
|
|
43903
|
-
},
|
|
43904
|
-
required: ["url"]
|
|
43905
|
-
}
|
|
43906
|
-
}
|
|
43907
|
-
},
|
|
43908
|
-
required: ["prompt", "aspect_ratio", "images"]
|
|
43909
|
-
}
|
|
43910
|
-
},
|
|
43911
|
-
{
|
|
43912
|
-
name: "grok_animate",
|
|
43913
|
-
description: "Start a Grok video generation task.",
|
|
43914
|
-
inputSchema: {
|
|
43915
|
-
type: "object",
|
|
43916
|
-
additionalProperties: false,
|
|
43917
|
-
properties: {
|
|
43918
|
-
prompt: {
|
|
43919
|
-
type: "string",
|
|
43920
|
-
minLength: 1,
|
|
43921
|
-
maxLength: 2e3,
|
|
43922
|
-
description: "Prompt for video generation"
|
|
43923
|
-
},
|
|
43924
|
-
image_url: {
|
|
43925
|
-
type: "string",
|
|
43926
|
-
format: "uri",
|
|
43927
|
-
description: "Optional source image URL"
|
|
43928
|
-
},
|
|
43929
|
-
aspect_ratio: {
|
|
43930
|
-
type: "string",
|
|
43931
|
-
enum: [...aspectRatioValues],
|
|
43932
|
-
default: "16:9",
|
|
43933
|
-
description: "Video aspect ratio"
|
|
43934
|
-
}
|
|
43935
|
-
},
|
|
43936
|
-
required: ["prompt"]
|
|
43937
|
-
},
|
|
43938
|
-
outputSchema: {
|
|
43939
|
-
type: "object",
|
|
43940
|
-
additionalProperties: false,
|
|
43941
|
-
properties: {
|
|
43942
|
-
prompt: { type: "string" },
|
|
43943
|
-
aspect_ratio: { type: "string" },
|
|
43944
|
-
request_id: { type: "string" },
|
|
43945
|
-
status: { type: "string" },
|
|
43946
|
-
image_url: { type: "string" },
|
|
43947
|
-
video_url: { type: "string" }
|
|
43948
|
-
},
|
|
43949
|
-
required: ["prompt", "aspect_ratio", "request_id", "status"]
|
|
43950
|
-
}
|
|
43951
|
-
},
|
|
43952
|
-
{
|
|
43953
|
-
name: "grok_check_video_status",
|
|
43954
|
-
description: "Check a Grok video task status.",
|
|
43955
|
-
inputSchema: {
|
|
43956
|
-
type: "object",
|
|
43957
|
-
additionalProperties: false,
|
|
43958
|
-
properties: {
|
|
43959
|
-
request_id: {
|
|
43960
|
-
type: "string",
|
|
43961
|
-
minLength: 1,
|
|
43962
|
-
maxLength: 200,
|
|
43963
|
-
description: "Video request identifier"
|
|
43964
|
-
},
|
|
43965
|
-
output_dir: {
|
|
43966
|
-
type: "string",
|
|
43967
|
-
description: "Optional directory to save the generated video"
|
|
43968
|
-
}
|
|
43969
|
-
},
|
|
43970
|
-
required: ["request_id"]
|
|
43971
|
-
},
|
|
43972
|
-
outputSchema: {
|
|
43973
|
-
type: "object",
|
|
43974
|
-
additionalProperties: false,
|
|
43975
|
-
properties: {
|
|
43976
|
-
request_id: { type: "string" },
|
|
43977
|
-
status: { type: "string" },
|
|
43978
|
-
video_url: { type: "string" }
|
|
43979
|
-
},
|
|
43980
|
-
required: ["request_id", "status"]
|
|
43981
|
-
}
|
|
43982
|
-
}
|
|
43983
|
-
];
|
|
43984
46069
|
if (!XAI_API_KEY && !IS_MOCK) {
|
|
43985
46070
|
console.error(
|
|
43986
46071
|
"XAI_API_KEY environment variable is required. Set MOCK=true to run without a key."
|
|
@@ -43990,6 +46075,8 @@ if (!XAI_API_KEY && !IS_MOCK) {
|
|
|
43990
46075
|
if (IS_MOCK) {
|
|
43991
46076
|
console.error("[grok] Running in MOCK mode \u2014 no real API calls.");
|
|
43992
46077
|
}
|
|
46078
|
+
var cache = new PersistentCache("grok");
|
|
46079
|
+
var SEARCH_CACHE_TTL = 30 * 60 * 1e3;
|
|
43993
46080
|
var xaiClient = axios_default.create({
|
|
43994
46081
|
baseURL: "https://api.x.ai/v1",
|
|
43995
46082
|
headers: {
|
|
@@ -43997,16 +46084,358 @@ var xaiClient = axios_default.create({
|
|
|
43997
46084
|
"Content-Type": "application/json"
|
|
43998
46085
|
}
|
|
43999
46086
|
});
|
|
44000
|
-
var server = new
|
|
44001
|
-
|
|
44002
|
-
|
|
44003
|
-
|
|
44004
|
-
|
|
44005
|
-
{
|
|
44006
|
-
|
|
44007
|
-
|
|
46087
|
+
var server = new McpServer({
|
|
46088
|
+
name: "grok-mcp-server",
|
|
46089
|
+
version: PACKAGE_VERSION
|
|
46090
|
+
});
|
|
46091
|
+
var TOOL_DEFINITIONS = [
|
|
46092
|
+
{ name: "grok_search_x" },
|
|
46093
|
+
{ name: "grok_search_web" },
|
|
46094
|
+
{ name: "grok_imagine" },
|
|
46095
|
+
{ name: "grok_animate" },
|
|
46096
|
+
{ name: "grok_check_video_status" }
|
|
46097
|
+
];
|
|
46098
|
+
function getValidationResult(error48) {
|
|
46099
|
+
const issue2 = error48.issues[0];
|
|
46100
|
+
const field = issue2?.path.join(".") || "input";
|
|
46101
|
+
return createValidationError(field, issue2?.message || "invalid input");
|
|
46102
|
+
}
|
|
46103
|
+
async function handleGrokSearchX(params, client = xaiClient) {
|
|
46104
|
+
const {
|
|
46105
|
+
query,
|
|
46106
|
+
allowed_handles,
|
|
46107
|
+
from_date,
|
|
46108
|
+
to_date,
|
|
46109
|
+
limit,
|
|
46110
|
+
offset,
|
|
46111
|
+
output_dir
|
|
46112
|
+
} = params;
|
|
46113
|
+
try {
|
|
46114
|
+
if (from_date && to_date && from_date > to_date) {
|
|
46115
|
+
return createValidationError(
|
|
46116
|
+
"from_date",
|
|
46117
|
+
"must be earlier than or equal to to_date"
|
|
46118
|
+
);
|
|
46119
|
+
}
|
|
46120
|
+
const cacheKey = JSON.stringify({
|
|
46121
|
+
tool: "grok_search_x",
|
|
46122
|
+
query,
|
|
46123
|
+
allowed_handles,
|
|
46124
|
+
from_date,
|
|
46125
|
+
to_date
|
|
46126
|
+
});
|
|
46127
|
+
const rawResponse = await cache.wrap(
|
|
46128
|
+
cacheKey,
|
|
46129
|
+
SEARCH_CACHE_TTL,
|
|
46130
|
+
async () => {
|
|
46131
|
+
if (IS_MOCK) return MOCK_FIXTURES.grok_search_x;
|
|
46132
|
+
const { data } = await client.post("/responses", {
|
|
46133
|
+
model: GROK_SEARCH_MODEL,
|
|
46134
|
+
input: [{ role: "user", content: query }],
|
|
46135
|
+
tools: [
|
|
46136
|
+
{
|
|
46137
|
+
type: "x_search",
|
|
46138
|
+
x_search: {
|
|
46139
|
+
allowed_x_handles: allowed_handles,
|
|
46140
|
+
from_date,
|
|
46141
|
+
to_date
|
|
46142
|
+
}
|
|
46143
|
+
}
|
|
46144
|
+
]
|
|
46145
|
+
});
|
|
46146
|
+
return data;
|
|
46147
|
+
}
|
|
46148
|
+
);
|
|
46149
|
+
const output = normalizeSearchResponse(
|
|
46150
|
+
rawResponse,
|
|
46151
|
+
query,
|
|
46152
|
+
limit,
|
|
46153
|
+
offset,
|
|
46154
|
+
normalizeXResults
|
|
46155
|
+
);
|
|
46156
|
+
let extraText = "";
|
|
46157
|
+
if (output_dir) {
|
|
46158
|
+
try {
|
|
46159
|
+
const fname = `grok-x-search-${Date.now()}.json`;
|
|
46160
|
+
const fpath = await saveFile(
|
|
46161
|
+
output_dir,
|
|
46162
|
+
fname,
|
|
46163
|
+
JSON.stringify(output, null, 2)
|
|
46164
|
+
);
|
|
46165
|
+
extraText = `
|
|
46166
|
+
|
|
46167
|
+
\u2705 Results saved to: ${fpath}`;
|
|
46168
|
+
} catch (error48) {
|
|
46169
|
+
extraText = `
|
|
46170
|
+
|
|
46171
|
+
\u26A0\uFE0F Failed to save results: ${error48.message}`;
|
|
46172
|
+
}
|
|
46173
|
+
}
|
|
46174
|
+
return toolResult(renderXSearch(output) + extraText, output);
|
|
46175
|
+
} catch (error48) {
|
|
46176
|
+
if (axios_default.isAxiosError(error48)) {
|
|
46177
|
+
return createApiError(
|
|
46178
|
+
isRecord(error48.response?.data) && isRecord(error48.response?.data.error) && asString(error48.response?.data.error.message) || error48.message,
|
|
46179
|
+
error48.response?.status
|
|
46180
|
+
);
|
|
46181
|
+
}
|
|
46182
|
+
return createInternalError(error48);
|
|
46183
|
+
}
|
|
46184
|
+
}
|
|
46185
|
+
async function handleGrokSearchWeb(params, client = xaiClient) {
|
|
46186
|
+
const { query, allowed_domains, limit, offset, output_dir } = params;
|
|
46187
|
+
try {
|
|
46188
|
+
const cacheKey = JSON.stringify({
|
|
46189
|
+
tool: "grok_search_web",
|
|
46190
|
+
query,
|
|
46191
|
+
allowed_domains
|
|
46192
|
+
});
|
|
46193
|
+
const rawResponse = await cache.wrap(
|
|
46194
|
+
cacheKey,
|
|
46195
|
+
SEARCH_CACHE_TTL,
|
|
46196
|
+
async () => {
|
|
46197
|
+
if (IS_MOCK) return MOCK_FIXTURES.grok_search_web;
|
|
46198
|
+
const { data } = await client.post("/responses", {
|
|
46199
|
+
model: GROK_SEARCH_MODEL,
|
|
46200
|
+
input: [
|
|
46201
|
+
{
|
|
46202
|
+
role: "user",
|
|
46203
|
+
content: `Search the web for: ${query}. Use the web_search tool.`
|
|
46204
|
+
}
|
|
46205
|
+
],
|
|
46206
|
+
tools: [
|
|
46207
|
+
{
|
|
46208
|
+
type: "web_search",
|
|
46209
|
+
web_search: { allowed_domains }
|
|
46210
|
+
}
|
|
46211
|
+
]
|
|
46212
|
+
});
|
|
46213
|
+
return data;
|
|
46214
|
+
}
|
|
46215
|
+
);
|
|
46216
|
+
const output = normalizeSearchResponse(
|
|
46217
|
+
rawResponse,
|
|
46218
|
+
query,
|
|
46219
|
+
limit,
|
|
46220
|
+
offset,
|
|
46221
|
+
normalizeWebResults
|
|
46222
|
+
);
|
|
46223
|
+
let extraText = "";
|
|
46224
|
+
if (output_dir) {
|
|
46225
|
+
try {
|
|
46226
|
+
const fname = `grok-web-search-${Date.now()}.json`;
|
|
46227
|
+
const fpath = await saveFile(
|
|
46228
|
+
output_dir,
|
|
46229
|
+
fname,
|
|
46230
|
+
JSON.stringify(output, null, 2)
|
|
46231
|
+
);
|
|
46232
|
+
extraText = `
|
|
46233
|
+
|
|
46234
|
+
\u2705 Results saved to: ${fpath}`;
|
|
46235
|
+
} catch (error48) {
|
|
46236
|
+
extraText = `
|
|
46237
|
+
|
|
46238
|
+
\u26A0\uFE0F Failed to save results: ${error48.message}`;
|
|
46239
|
+
}
|
|
46240
|
+
}
|
|
46241
|
+
return toolResult(renderWebSearch(output) + extraText, output);
|
|
46242
|
+
} catch (error48) {
|
|
46243
|
+
if (axios_default.isAxiosError(error48)) {
|
|
46244
|
+
return createApiError(
|
|
46245
|
+
isRecord(error48.response?.data) && isRecord(error48.response?.data.error) && asString(error48.response?.data.error.message) || error48.message,
|
|
46246
|
+
error48.response?.status
|
|
46247
|
+
);
|
|
44008
46248
|
}
|
|
46249
|
+
return createInternalError(error48);
|
|
44009
46250
|
}
|
|
46251
|
+
}
|
|
46252
|
+
async function handleGrokImagine(params, client = xaiClient) {
|
|
46253
|
+
const { prompt, aspect_ratio, output_dir } = params;
|
|
46254
|
+
try {
|
|
46255
|
+
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_imagine : (await client.post("/images/generations", {
|
|
46256
|
+
model: GROK_IMAGE_MODEL,
|
|
46257
|
+
prompt,
|
|
46258
|
+
aspect_ratio,
|
|
46259
|
+
response_format: "url"
|
|
46260
|
+
})).data;
|
|
46261
|
+
const output = normalizeImagineResponse(
|
|
46262
|
+
rawResponse,
|
|
46263
|
+
prompt,
|
|
46264
|
+
aspect_ratio
|
|
46265
|
+
);
|
|
46266
|
+
const mediaResults = IS_MOCK ? [buildMockImageContent()] : (await Promise.all(
|
|
46267
|
+
output.images.map(
|
|
46268
|
+
(image) => buildImageContent(image.url, client)
|
|
46269
|
+
)
|
|
46270
|
+
)).filter(
|
|
46271
|
+
(item) => item !== void 0
|
|
46272
|
+
);
|
|
46273
|
+
const mediaContent = mediaResults.map((r) => r.content);
|
|
46274
|
+
let extraText = "";
|
|
46275
|
+
if (output_dir && mediaResults.length > 0) {
|
|
46276
|
+
try {
|
|
46277
|
+
const savedPaths = await Promise.all(
|
|
46278
|
+
mediaResults.map(
|
|
46279
|
+
(res, i) => saveFile(
|
|
46280
|
+
output_dir,
|
|
46281
|
+
`imagine-${Date.now()}-${i + 1}.png`,
|
|
46282
|
+
res.buffer
|
|
46283
|
+
)
|
|
46284
|
+
)
|
|
46285
|
+
);
|
|
46286
|
+
extraText = `
|
|
46287
|
+
|
|
46288
|
+
\u2705 Images saved to:
|
|
46289
|
+
${savedPaths.join("\n")}`;
|
|
46290
|
+
} catch (error48) {
|
|
46291
|
+
extraText = `
|
|
46292
|
+
|
|
46293
|
+
\u26A0\uFE0F Failed to save images: ${error48.message}`;
|
|
46294
|
+
}
|
|
46295
|
+
}
|
|
46296
|
+
return toolResult(
|
|
46297
|
+
renderImagine(output) + extraText,
|
|
46298
|
+
output,
|
|
46299
|
+
mediaContent
|
|
46300
|
+
);
|
|
46301
|
+
} catch (error48) {
|
|
46302
|
+
if (axios_default.isAxiosError(error48)) {
|
|
46303
|
+
return createApiError(
|
|
46304
|
+
isRecord(error48.response?.data) && isRecord(error48.response?.data.error) && asString(error48.response?.data.error.message) || error48.message,
|
|
46305
|
+
error48.response?.status
|
|
46306
|
+
);
|
|
46307
|
+
}
|
|
46308
|
+
return createInternalError(error48);
|
|
46309
|
+
}
|
|
46310
|
+
}
|
|
46311
|
+
async function handleGrokAnimate(params, client = xaiClient) {
|
|
46312
|
+
const { prompt, image_url, aspect_ratio } = params;
|
|
46313
|
+
try {
|
|
46314
|
+
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_animate : (await client.post("/videos/generations", {
|
|
46315
|
+
model: GROK_VIDEO_MODEL,
|
|
46316
|
+
prompt,
|
|
46317
|
+
image_url,
|
|
46318
|
+
aspect_ratio
|
|
46319
|
+
})).data;
|
|
46320
|
+
const output = normalizeVideoGenerationResponse(
|
|
46321
|
+
rawResponse,
|
|
46322
|
+
prompt,
|
|
46323
|
+
aspect_ratio,
|
|
46324
|
+
image_url
|
|
46325
|
+
);
|
|
46326
|
+
return toolResult(renderVideoGeneration(output), output);
|
|
46327
|
+
} catch (error48) {
|
|
46328
|
+
if (axios_default.isAxiosError(error48)) {
|
|
46329
|
+
return createApiError(
|
|
46330
|
+
isRecord(error48.response?.data) && isRecord(error48.response?.data.error) && asString(error48.response?.data.error.message) || error48.message,
|
|
46331
|
+
error48.response?.status
|
|
46332
|
+
);
|
|
46333
|
+
}
|
|
46334
|
+
return createInternalError(error48);
|
|
46335
|
+
}
|
|
46336
|
+
}
|
|
46337
|
+
async function handleGrokVideoStatus(params, client = xaiClient) {
|
|
46338
|
+
const { request_id, output_dir } = params;
|
|
46339
|
+
try {
|
|
46340
|
+
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_check_video_status : (await client.get(`/videos/${request_id}`)).data;
|
|
46341
|
+
const output = normalizeVideoStatusResponse(rawResponse, request_id);
|
|
46342
|
+
let mediaContent = [];
|
|
46343
|
+
let extraText = "";
|
|
46344
|
+
if (output.video_url !== void 0) {
|
|
46345
|
+
const mediaRes = IS_MOCK ? buildMockVideoContent(output.video_url) : await buildVideoContent(
|
|
46346
|
+
output.video_url,
|
|
46347
|
+
client
|
|
46348
|
+
);
|
|
46349
|
+
if (mediaRes) {
|
|
46350
|
+
mediaContent = [mediaRes.content];
|
|
46351
|
+
if (output_dir) {
|
|
46352
|
+
try {
|
|
46353
|
+
const fpath = await saveFile(
|
|
46354
|
+
output_dir,
|
|
46355
|
+
`video-${Date.now()}.mp4`,
|
|
46356
|
+
mediaRes.buffer
|
|
46357
|
+
);
|
|
46358
|
+
extraText = `
|
|
46359
|
+
|
|
46360
|
+
\u2705 Video saved to: ${fpath}`;
|
|
46361
|
+
} catch (error48) {
|
|
46362
|
+
extraText = `
|
|
46363
|
+
|
|
46364
|
+
\u26A0\uFE0F Failed to save video: ${error48.message}`;
|
|
46365
|
+
}
|
|
46366
|
+
}
|
|
46367
|
+
}
|
|
46368
|
+
}
|
|
46369
|
+
return toolResult(
|
|
46370
|
+
renderVideoStatus(output) + extraText,
|
|
46371
|
+
output,
|
|
46372
|
+
mediaContent
|
|
46373
|
+
);
|
|
46374
|
+
} catch (error48) {
|
|
46375
|
+
if (axios_default.isAxiosError(error48)) {
|
|
46376
|
+
return createApiError(
|
|
46377
|
+
isRecord(error48.response?.data) && isRecord(error48.response?.data.error) && asString(error48.response?.data.error.message) || error48.message,
|
|
46378
|
+
error48.response?.status
|
|
46379
|
+
);
|
|
46380
|
+
}
|
|
46381
|
+
return createInternalError(error48);
|
|
46382
|
+
}
|
|
46383
|
+
}
|
|
46384
|
+
async function handleToolCall(name, args, client = xaiClient) {
|
|
46385
|
+
switch (name) {
|
|
46386
|
+
case "grok_search_x": {
|
|
46387
|
+
const parsed = xSearchSchema.safeParse(args);
|
|
46388
|
+
return parsed.success ? handleGrokSearchX(parsed.data, client) : getValidationResult(parsed.error);
|
|
46389
|
+
}
|
|
46390
|
+
case "grok_search_web": {
|
|
46391
|
+
const parsed = webSearchSchema.safeParse(args);
|
|
46392
|
+
return parsed.success ? handleGrokSearchWeb(parsed.data, client) : getValidationResult(parsed.error);
|
|
46393
|
+
}
|
|
46394
|
+
case "grok_imagine": {
|
|
46395
|
+
const parsed = imagineSchema.safeParse(args);
|
|
46396
|
+
return parsed.success ? handleGrokImagine(parsed.data, client) : getValidationResult(parsed.error);
|
|
46397
|
+
}
|
|
46398
|
+
case "grok_animate": {
|
|
46399
|
+
const parsed = animateSchema.safeParse(args);
|
|
46400
|
+
return parsed.success ? handleGrokAnimate(parsed.data, client) : getValidationResult(parsed.error);
|
|
46401
|
+
}
|
|
46402
|
+
case "grok_check_video_status": {
|
|
46403
|
+
const parsed = videoStatusSchema.safeParse(args);
|
|
46404
|
+
return parsed.success ? handleGrokVideoStatus(parsed.data, client) : getValidationResult(parsed.error);
|
|
46405
|
+
}
|
|
46406
|
+
default:
|
|
46407
|
+
throw { code: -32601, message: `Unknown tool: ${name}` };
|
|
46408
|
+
}
|
|
46409
|
+
}
|
|
46410
|
+
server.tool(
|
|
46411
|
+
"grok_search_x",
|
|
46412
|
+
"Search X posts and threads via Grok.",
|
|
46413
|
+
xSearchSchema.shape,
|
|
46414
|
+
async (args) => handleGrokSearchX(args)
|
|
46415
|
+
);
|
|
46416
|
+
server.tool(
|
|
46417
|
+
"grok_search_web",
|
|
46418
|
+
"Search the public web via Grok.",
|
|
46419
|
+
webSearchSchema.shape,
|
|
46420
|
+
async (args) => handleGrokSearchWeb(args)
|
|
46421
|
+
);
|
|
46422
|
+
server.tool(
|
|
46423
|
+
"grok_imagine",
|
|
46424
|
+
"Generate images from a text prompt.",
|
|
46425
|
+
imagineSchema.shape,
|
|
46426
|
+
async (args) => handleGrokImagine(args)
|
|
46427
|
+
);
|
|
46428
|
+
server.tool(
|
|
46429
|
+
"grok_animate",
|
|
46430
|
+
"Start a Grok video generation task.",
|
|
46431
|
+
animateSchema.shape,
|
|
46432
|
+
async (args) => handleGrokAnimate(args)
|
|
46433
|
+
);
|
|
46434
|
+
server.tool(
|
|
46435
|
+
"grok_check_video_status",
|
|
46436
|
+
"Check a Grok video task status.",
|
|
46437
|
+
videoStatusSchema.shape,
|
|
46438
|
+
async (args) => handleGrokVideoStatus(args)
|
|
44010
46439
|
);
|
|
44011
46440
|
function isRecord(value) {
|
|
44012
46441
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -44331,28 +46760,6 @@ function renderVideoStatus(output) {
|
|
|
44331
46760
|
]);
|
|
44332
46761
|
return truncateToLimit(formatMarkdownSection("Grok Video Status", body));
|
|
44333
46762
|
}
|
|
44334
|
-
function parseArguments(toolName, schema, args) {
|
|
44335
|
-
const parsed = schema.safeParse(args ?? {});
|
|
44336
|
-
if (!parsed.success) {
|
|
44337
|
-
const issue2 = parsed.error.issues[0];
|
|
44338
|
-
const field = issue2?.path.length ? issue2.path.join(".") : toolName;
|
|
44339
|
-
return {
|
|
44340
|
-
error: createValidationError(
|
|
44341
|
-
field,
|
|
44342
|
-
issue2?.message || parsed.error.message
|
|
44343
|
-
)
|
|
44344
|
-
};
|
|
44345
|
-
}
|
|
44346
|
-
if (isRecord(parsed.data) && typeof parsed.data.from_date === "string" && typeof parsed.data.to_date === "string" && parsed.data.from_date > parsed.data.to_date) {
|
|
44347
|
-
return {
|
|
44348
|
-
error: createValidationError(
|
|
44349
|
-
"from_date",
|
|
44350
|
-
"must be earlier than or equal to to_date"
|
|
44351
|
-
)
|
|
44352
|
-
};
|
|
44353
|
-
}
|
|
44354
|
-
return { data: parsed.data };
|
|
44355
|
-
}
|
|
44356
46763
|
function toolResult(text, structuredContent, extraContent = []) {
|
|
44357
46764
|
return {
|
|
44358
46765
|
content: [
|
|
@@ -44363,9 +46770,9 @@ function toolResult(text, structuredContent, extraContent = []) {
|
|
|
44363
46770
|
};
|
|
44364
46771
|
}
|
|
44365
46772
|
async function saveFile(outputDir, filename, data) {
|
|
44366
|
-
await
|
|
44367
|
-
const fpath =
|
|
44368
|
-
await
|
|
46773
|
+
await fs2.mkdir(outputDir, { recursive: true });
|
|
46774
|
+
const fpath = path2.join(outputDir, filename);
|
|
46775
|
+
await fs2.writeFile(fpath, data);
|
|
44369
46776
|
return fpath;
|
|
44370
46777
|
}
|
|
44371
46778
|
function normalizeSearchResponse(raw, query, limit, offset, normalizer) {
|
|
@@ -44440,245 +46847,6 @@ function normalizeVideoStatusResponse(raw, requestId) {
|
|
|
44440
46847
|
video_url: extractVideoUrl(raw)
|
|
44441
46848
|
};
|
|
44442
46849
|
}
|
|
44443
|
-
async function handleToolCall(name, args, client = xaiClient) {
|
|
44444
|
-
try {
|
|
44445
|
-
switch (name) {
|
|
44446
|
-
case "grok_search_x": {
|
|
44447
|
-
const parsed = parseArguments(name, xSearchSchema, args);
|
|
44448
|
-
if ("error" in parsed) {
|
|
44449
|
-
return parsed.error;
|
|
44450
|
-
}
|
|
44451
|
-
const {
|
|
44452
|
-
query,
|
|
44453
|
-
allowed_handles,
|
|
44454
|
-
from_date,
|
|
44455
|
-
to_date,
|
|
44456
|
-
limit,
|
|
44457
|
-
offset,
|
|
44458
|
-
output_dir
|
|
44459
|
-
} = parsed.data;
|
|
44460
|
-
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_search_x : (await client.post("/responses", {
|
|
44461
|
-
model: "grok-4-1-fast-reasoning",
|
|
44462
|
-
input: [{ role: "user", content: query }],
|
|
44463
|
-
tools: [
|
|
44464
|
-
{
|
|
44465
|
-
type: "x_search",
|
|
44466
|
-
x_search: {
|
|
44467
|
-
allowed_x_handles: allowed_handles,
|
|
44468
|
-
from_date,
|
|
44469
|
-
to_date
|
|
44470
|
-
}
|
|
44471
|
-
}
|
|
44472
|
-
]
|
|
44473
|
-
})).data;
|
|
44474
|
-
const output = normalizeSearchResponse(
|
|
44475
|
-
rawResponse,
|
|
44476
|
-
query,
|
|
44477
|
-
limit,
|
|
44478
|
-
offset,
|
|
44479
|
-
normalizeXResults
|
|
44480
|
-
);
|
|
44481
|
-
let extraText = "";
|
|
44482
|
-
if (output_dir) {
|
|
44483
|
-
try {
|
|
44484
|
-
const fname = `grok-x-search-${Date.now()}.json`;
|
|
44485
|
-
const fpath = await saveFile(
|
|
44486
|
-
output_dir,
|
|
44487
|
-
fname,
|
|
44488
|
-
JSON.stringify(output, null, 2)
|
|
44489
|
-
);
|
|
44490
|
-
extraText = `
|
|
44491
|
-
|
|
44492
|
-
\u2705 Results saved to: ${fpath}`;
|
|
44493
|
-
} catch (error48) {
|
|
44494
|
-
extraText = `
|
|
44495
|
-
|
|
44496
|
-
\u26A0\uFE0F Failed to save results: ${error48.message}`;
|
|
44497
|
-
}
|
|
44498
|
-
}
|
|
44499
|
-
return toolResult(renderXSearch(output) + extraText, output);
|
|
44500
|
-
}
|
|
44501
|
-
case "grok_search_web": {
|
|
44502
|
-
const parsed = parseArguments(name, webSearchSchema, args);
|
|
44503
|
-
if ("error" in parsed) {
|
|
44504
|
-
return parsed.error;
|
|
44505
|
-
}
|
|
44506
|
-
const { query, allowed_domains, limit, offset, output_dir } = parsed.data;
|
|
44507
|
-
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_search_web : (await client.post("/responses", {
|
|
44508
|
-
model: "grok-4-1-fast-reasoning",
|
|
44509
|
-
input: [{ role: "user", content: query }],
|
|
44510
|
-
tools: [
|
|
44511
|
-
{
|
|
44512
|
-
type: "web_search",
|
|
44513
|
-
web_search: { allowed_domains }
|
|
44514
|
-
}
|
|
44515
|
-
]
|
|
44516
|
-
})).data;
|
|
44517
|
-
const output = normalizeSearchResponse(
|
|
44518
|
-
rawResponse,
|
|
44519
|
-
query,
|
|
44520
|
-
limit,
|
|
44521
|
-
offset,
|
|
44522
|
-
normalizeWebResults
|
|
44523
|
-
);
|
|
44524
|
-
let extraText = "";
|
|
44525
|
-
if (output_dir) {
|
|
44526
|
-
try {
|
|
44527
|
-
const fname = `grok-web-search-${Date.now()}.json`;
|
|
44528
|
-
const fpath = await saveFile(
|
|
44529
|
-
output_dir,
|
|
44530
|
-
fname,
|
|
44531
|
-
JSON.stringify(output, null, 2)
|
|
44532
|
-
);
|
|
44533
|
-
extraText = `
|
|
44534
|
-
|
|
44535
|
-
\u2705 Results saved to: ${fpath}`;
|
|
44536
|
-
} catch (error48) {
|
|
44537
|
-
extraText = `
|
|
44538
|
-
|
|
44539
|
-
\u26A0\uFE0F Failed to save results: ${error48.message}`;
|
|
44540
|
-
}
|
|
44541
|
-
}
|
|
44542
|
-
return toolResult(renderWebSearch(output) + extraText, output);
|
|
44543
|
-
}
|
|
44544
|
-
case "grok_imagine": {
|
|
44545
|
-
const parsed = parseArguments(name, imagineSchema, args);
|
|
44546
|
-
if ("error" in parsed) {
|
|
44547
|
-
return parsed.error;
|
|
44548
|
-
}
|
|
44549
|
-
const { prompt, aspect_ratio, output_dir } = parsed.data;
|
|
44550
|
-
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_imagine : (await client.post("/images/generations", {
|
|
44551
|
-
model: "grok-imagine-image",
|
|
44552
|
-
prompt,
|
|
44553
|
-
aspect_ratio,
|
|
44554
|
-
response_format: "url"
|
|
44555
|
-
})).data;
|
|
44556
|
-
const output = normalizeImagineResponse(
|
|
44557
|
-
rawResponse,
|
|
44558
|
-
prompt,
|
|
44559
|
-
aspect_ratio
|
|
44560
|
-
);
|
|
44561
|
-
const mediaResults = IS_MOCK ? [buildMockImageContent()] : (await Promise.all(
|
|
44562
|
-
output.images.map(
|
|
44563
|
-
(image) => buildImageContent(image.url, client)
|
|
44564
|
-
)
|
|
44565
|
-
)).filter(
|
|
44566
|
-
(item) => item !== void 0
|
|
44567
|
-
);
|
|
44568
|
-
const mediaContent = mediaResults.map((r) => r.content);
|
|
44569
|
-
let extraText = "";
|
|
44570
|
-
if (output_dir && mediaResults.length > 0) {
|
|
44571
|
-
try {
|
|
44572
|
-
const savedPaths = await Promise.all(
|
|
44573
|
-
mediaResults.map(
|
|
44574
|
-
(res, i) => saveFile(
|
|
44575
|
-
output_dir,
|
|
44576
|
-
`imagine-${Date.now()}-${i + 1}.png`,
|
|
44577
|
-
res.buffer
|
|
44578
|
-
)
|
|
44579
|
-
)
|
|
44580
|
-
);
|
|
44581
|
-
extraText = `
|
|
44582
|
-
|
|
44583
|
-
\u2705 Images saved to:
|
|
44584
|
-
${savedPaths.join("\n")}`;
|
|
44585
|
-
} catch (error48) {
|
|
44586
|
-
extraText = `
|
|
44587
|
-
|
|
44588
|
-
\u26A0\uFE0F Failed to save images: ${error48.message}`;
|
|
44589
|
-
}
|
|
44590
|
-
}
|
|
44591
|
-
return toolResult(
|
|
44592
|
-
renderImagine(output) + extraText,
|
|
44593
|
-
output,
|
|
44594
|
-
mediaContent
|
|
44595
|
-
);
|
|
44596
|
-
}
|
|
44597
|
-
case "grok_animate": {
|
|
44598
|
-
const parsed = parseArguments(name, animateSchema, args);
|
|
44599
|
-
if ("error" in parsed) {
|
|
44600
|
-
return parsed.error;
|
|
44601
|
-
}
|
|
44602
|
-
const { prompt, image_url, aspect_ratio } = parsed.data;
|
|
44603
|
-
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_animate : (await client.post("/videos/generations", {
|
|
44604
|
-
model: "grok-imagine-video",
|
|
44605
|
-
prompt,
|
|
44606
|
-
image_url,
|
|
44607
|
-
aspect_ratio
|
|
44608
|
-
})).data;
|
|
44609
|
-
const output = normalizeVideoGenerationResponse(
|
|
44610
|
-
rawResponse,
|
|
44611
|
-
prompt,
|
|
44612
|
-
aspect_ratio,
|
|
44613
|
-
image_url
|
|
44614
|
-
);
|
|
44615
|
-
return toolResult(renderVideoGeneration(output), output);
|
|
44616
|
-
}
|
|
44617
|
-
case "grok_check_video_status": {
|
|
44618
|
-
const parsed = parseArguments(name, videoStatusSchema, args);
|
|
44619
|
-
if ("error" in parsed) {
|
|
44620
|
-
return parsed.error;
|
|
44621
|
-
}
|
|
44622
|
-
const { request_id, output_dir } = parsed.data;
|
|
44623
|
-
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_check_video_status : (await client.get(`/videos/${request_id}`)).data;
|
|
44624
|
-
const output = normalizeVideoStatusResponse(
|
|
44625
|
-
rawResponse,
|
|
44626
|
-
request_id
|
|
44627
|
-
);
|
|
44628
|
-
let mediaContent = [];
|
|
44629
|
-
let extraText = "";
|
|
44630
|
-
if (output.video_url !== void 0) {
|
|
44631
|
-
const mediaRes = IS_MOCK ? buildMockVideoContent(output.video_url) : await buildVideoContent(output.video_url, client);
|
|
44632
|
-
if (mediaRes) {
|
|
44633
|
-
mediaContent = [mediaRes.content];
|
|
44634
|
-
if (output_dir) {
|
|
44635
|
-
try {
|
|
44636
|
-
const fpath = await saveFile(
|
|
44637
|
-
output_dir,
|
|
44638
|
-
`video-${Date.now()}.mp4`,
|
|
44639
|
-
mediaRes.buffer
|
|
44640
|
-
);
|
|
44641
|
-
extraText = `
|
|
44642
|
-
|
|
44643
|
-
\u2705 Video saved to: ${fpath}`;
|
|
44644
|
-
} catch (error48) {
|
|
44645
|
-
extraText = `
|
|
44646
|
-
|
|
44647
|
-
\u26A0\uFE0F Failed to save video: ${error48.message}`;
|
|
44648
|
-
}
|
|
44649
|
-
}
|
|
44650
|
-
}
|
|
44651
|
-
}
|
|
44652
|
-
return toolResult(
|
|
44653
|
-
renderVideoStatus(output) + extraText,
|
|
44654
|
-
output,
|
|
44655
|
-
mediaContent
|
|
44656
|
-
);
|
|
44657
|
-
}
|
|
44658
|
-
default:
|
|
44659
|
-
throw new McpError(
|
|
44660
|
-
ErrorCode.MethodNotFound,
|
|
44661
|
-
`Unknown tool: ${name}`
|
|
44662
|
-
);
|
|
44663
|
-
}
|
|
44664
|
-
} catch (error48) {
|
|
44665
|
-
if (error48 instanceof McpError) {
|
|
44666
|
-
throw error48;
|
|
44667
|
-
}
|
|
44668
|
-
if (axios_default.isAxiosError(error48)) {
|
|
44669
|
-
const message = isRecord(error48.response?.data) && isRecord(error48.response?.data.error) && asString(error48.response?.data.error.message) || error48.message;
|
|
44670
|
-
return createApiError(message, error48.response?.status);
|
|
44671
|
-
}
|
|
44672
|
-
return createInternalError(error48);
|
|
44673
|
-
}
|
|
44674
|
-
}
|
|
44675
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
44676
|
-
tools: [...TOOL_DEFINITIONS]
|
|
44677
|
-
}));
|
|
44678
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
44679
|
-
const { name, arguments: args } = request.params;
|
|
44680
|
-
return handleToolCall(name, args);
|
|
44681
|
-
});
|
|
44682
46850
|
async function runServer() {
|
|
44683
46851
|
const transport = new StdioServerTransport();
|
|
44684
46852
|
await server.connect(transport);
|
|
@@ -44704,7 +46872,8 @@ if (isMainModule(import.meta.url)) {
|
|
|
44704
46872
|
export {
|
|
44705
46873
|
TOOL_DEFINITIONS,
|
|
44706
46874
|
handleToolCall,
|
|
44707
|
-
runServer
|
|
46875
|
+
runServer,
|
|
46876
|
+
server
|
|
44708
46877
|
};
|
|
44709
46878
|
/*! Bundled license information:
|
|
44710
46879
|
|