@fre4x/grok 1.0.50 → 1.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +220 -104
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3229,8 +3229,8 @@ var require_utils = __commonJS({
3229
3229
  }
3230
3230
  return ind;
3231
3231
  }
3232
- function removeDotSegments(path) {
3233
- let input = path;
3232
+ function removeDotSegments(path2) {
3233
+ let input = path2;
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 [path, query] = wsComponent.resourceName.split("?");
3433
- wsComponent.path = path && path !== "/" ? path : void 0;
3432
+ const [path2, query] = wsComponent.resourceName.split("?");
3433
+ wsComponent.path = path2 && path2 !== "/" ? path2 : 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, fs, exportName) {
6795
+ function addFormats(ajv, list, fs2, 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, fs[f]);
6800
+ ajv.addFormat(f, fs2[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(path) {
15656
- if (!path || typeof path !== "string") {
15655
+ function lookup(path2) {
15656
+ if (!path2 || typeof path2 !== "string") {
15657
15657
  return false;
15658
15658
  }
15659
- var extension2 = extname("x." + path).toLowerCase().substr(1);
15659
+ var extension2 = extname("x." + path2).toLowerCase().substr(1);
15660
15660
  if (!extension2) {
15661
15661
  return false;
15662
15662
  }
@@ -16761,11 +16761,11 @@ var require_form_data = __commonJS({
16761
16761
  "use strict";
16762
16762
  var CombinedStream = require_combined_stream();
16763
16763
  var util4 = __require("util");
16764
- var path = __require("path");
16764
+ var path2 = __require("path");
16765
16765
  var http3 = __require("http");
16766
16766
  var https2 = __require("https");
16767
16767
  var parseUrl = __require("url").parse;
16768
- var fs = __require("fs");
16768
+ var fs2 = __require("fs");
16769
16769
  var Stream = __require("stream").Stream;
16770
16770
  var crypto2 = __require("crypto");
16771
16771
  var mime = require_mime_types();
@@ -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
- fs.stat(value.path, function(err, stat) {
16835
+ fs2.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 = path.normalize(options.filepath).replace(/\\/g, "/");
16892
+ filename = path2.normalize(options.filepath).replace(/\\/g, "/");
16893
16893
  } else if (options.filename || value && (value.name || value.path)) {
16894
- filename = path.basename(options.filename || value && (value.name || value.path));
16894
+ filename = path2.basename(options.filename || value && (value.name || value.path));
16895
16895
  } else if (value && value.readable && hasOwn(value, "httpVersion")) {
16896
- filename = path.basename(value.client._httpMessage.path || "");
16896
+ filename = path2.basename(value.client._httpMessage.path || "");
16897
16897
  }
16898
16898
  if (filename) {
16899
16899
  return 'filename="' + filename + '"';
@@ -18437,6 +18437,8 @@ var require_follow_redirects = __commonJS({
18437
18437
 
18438
18438
  // src/index.ts
18439
18439
  import { realpathSync } from "node:fs";
18440
+ import * as fs from "node:fs/promises";
18441
+ import * as path from "node:path";
18440
18442
  import { fileURLToPath } from "node:url";
18441
18443
 
18442
18444
  // ../packages/shared/dist/errors.js
@@ -19534,10 +19536,10 @@ function mergeDefs(...defs) {
19534
19536
  function cloneDef(schema) {
19535
19537
  return mergeDefs(schema._zod.def);
19536
19538
  }
19537
- function getElementAtPath(obj, path) {
19538
- if (!path)
19539
+ function getElementAtPath(obj, path2) {
19540
+ if (!path2)
19539
19541
  return obj;
19540
- return path.reduce((acc, key) => acc?.[key], obj);
19542
+ return path2.reduce((acc, key) => acc?.[key], obj);
19541
19543
  }
19542
19544
  function promiseAllObject(promisesObj) {
19543
19545
  const keys = Object.keys(promisesObj);
@@ -19920,11 +19922,11 @@ function aborted(x, startIndex = 0) {
19920
19922
  }
19921
19923
  return false;
19922
19924
  }
19923
- function prefixIssues(path, issues) {
19925
+ function prefixIssues(path2, issues) {
19924
19926
  return issues.map((iss) => {
19925
19927
  var _a2;
19926
19928
  (_a2 = iss).path ?? (_a2.path = []);
19927
- iss.path.unshift(path);
19929
+ iss.path.unshift(path2);
19928
19930
  return iss;
19929
19931
  });
19930
19932
  }
@@ -20107,7 +20109,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
20107
20109
  }
20108
20110
  function treeifyError(error48, mapper = (issue2) => issue2.message) {
20109
20111
  const result = { errors: [] };
20110
- const processError = (error49, path = []) => {
20112
+ const processError = (error49, path2 = []) => {
20111
20113
  var _a2, _b;
20112
20114
  for (const issue2 of error49.issues) {
20113
20115
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -20117,7 +20119,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
20117
20119
  } else if (issue2.code === "invalid_element") {
20118
20120
  processError({ issues: issue2.issues }, issue2.path);
20119
20121
  } else {
20120
- const fullpath = [...path, ...issue2.path];
20122
+ const fullpath = [...path2, ...issue2.path];
20121
20123
  if (fullpath.length === 0) {
20122
20124
  result.errors.push(mapper(issue2));
20123
20125
  continue;
@@ -20149,8 +20151,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
20149
20151
  }
20150
20152
  function toDotPath(_path) {
20151
20153
  const segs = [];
20152
- const path = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
20153
- for (const seg of path) {
20154
+ const path2 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
20155
+ for (const seg of path2) {
20154
20156
  if (typeof seg === "number")
20155
20157
  segs.push(`[${seg}]`);
20156
20158
  else if (typeof seg === "symbol")
@@ -32127,13 +32129,13 @@ function resolveRef(ref, ctx) {
32127
32129
  if (!ref.startsWith("#")) {
32128
32130
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
32129
32131
  }
32130
- const path = ref.slice(1).split("/").filter(Boolean);
32131
- if (path.length === 0) {
32132
+ const path2 = ref.slice(1).split("/").filter(Boolean);
32133
+ if (path2.length === 0) {
32132
32134
  return ctx.rootSchema;
32133
32135
  }
32134
32136
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
32135
- if (path[0] === defsKey) {
32136
- const key = path[1];
32137
+ if (path2[0] === defsKey) {
32138
+ const key = path2[1];
32137
32139
  if (!key || !ctx.defs[key]) {
32138
32140
  throw new Error(`Reference not found: ${ref}`);
32139
32141
  }
@@ -32904,8 +32906,8 @@ function getErrorMap2() {
32904
32906
 
32905
32907
  // ../node_modules/zod/v3/helpers/parseUtil.js
32906
32908
  var makeIssue = (params) => {
32907
- const { data, path, errorMaps, issueData } = params;
32908
- const fullPath = [...path, ...issueData.path || []];
32909
+ const { data, path: path2, errorMaps, issueData } = params;
32910
+ const fullPath = [...path2, ...issueData.path || []];
32909
32911
  const fullIssue = {
32910
32912
  ...issueData,
32911
32913
  path: fullPath
@@ -33020,11 +33022,11 @@ var errorUtil;
33020
33022
 
33021
33023
  // ../node_modules/zod/v3/types.js
33022
33024
  var ParseInputLazyPath = class {
33023
- constructor(parent, value, path, key) {
33025
+ constructor(parent, value, path2, key) {
33024
33026
  this._cachedPath = [];
33025
33027
  this.parent = parent;
33026
33028
  this.data = value;
33027
- this._path = path;
33029
+ this._path = path2;
33028
33030
  this._key = key;
33029
33031
  }
33030
33032
  get path() {
@@ -40279,9 +40281,9 @@ function isVisitable(thing) {
40279
40281
  function removeBrackets(key) {
40280
40282
  return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
40281
40283
  }
40282
- function renderKey(path, key, dots) {
40283
- if (!path) return key;
40284
- return path.concat(key).map(function each(token, i) {
40284
+ function renderKey(path2, key, dots) {
40285
+ if (!path2) return key;
40286
+ return path2.concat(key).map(function each(token, i) {
40285
40287
  token = removeBrackets(token);
40286
40288
  return !dots && i ? "[" + token + "]" : token;
40287
40289
  }).join(dots ? "." : "");
@@ -40334,13 +40336,13 @@ function toFormData(obj, formData, options) {
40334
40336
  }
40335
40337
  return value;
40336
40338
  }
40337
- function defaultVisitor(value, key, path) {
40339
+ function defaultVisitor(value, key, path2) {
40338
40340
  let arr = value;
40339
40341
  if (utils_default.isReactNative(formData) && utils_default.isReactNativeBlob(value)) {
40340
- formData.append(renderKey(path, key, dots), convertValue(value));
40342
+ formData.append(renderKey(path2, key, dots), convertValue(value));
40341
40343
  return false;
40342
40344
  }
40343
- if (value && !path && typeof value === "object") {
40345
+ if (value && !path2 && typeof value === "object") {
40344
40346
  if (utils_default.endsWith(key, "{}")) {
40345
40347
  key = metaTokens ? key : key.slice(0, -2);
40346
40348
  value = JSON.stringify(value);
@@ -40359,7 +40361,7 @@ function toFormData(obj, formData, options) {
40359
40361
  if (isVisitable(value)) {
40360
40362
  return true;
40361
40363
  }
40362
- formData.append(renderKey(path, key, dots), convertValue(value));
40364
+ formData.append(renderKey(path2, key, dots), convertValue(value));
40363
40365
  return false;
40364
40366
  }
40365
40367
  const stack = [];
@@ -40368,16 +40370,16 @@ function toFormData(obj, formData, options) {
40368
40370
  convertValue,
40369
40371
  isVisitable
40370
40372
  });
40371
- function build(value, path) {
40373
+ function build(value, path2) {
40372
40374
  if (utils_default.isUndefined(value)) return;
40373
40375
  if (stack.indexOf(value) !== -1) {
40374
- throw Error("Circular reference detected in " + path.join("."));
40376
+ throw Error("Circular reference detected in " + path2.join("."));
40375
40377
  }
40376
40378
  stack.push(value);
40377
40379
  utils_default.forEach(value, function each(el, key) {
40378
- const result = !(utils_default.isUndefined(el) || el === null) && visitor.call(formData, el, utils_default.isString(key) ? key.trim() : key, path, exposedHelpers);
40380
+ const result = !(utils_default.isUndefined(el) || el === null) && visitor.call(formData, el, utils_default.isString(key) ? key.trim() : key, path2, exposedHelpers);
40379
40381
  if (result === true) {
40380
- build(el, path ? path.concat(key) : [key]);
40382
+ build(el, path2 ? path2.concat(key) : [key]);
40381
40383
  }
40382
40384
  });
40383
40385
  stack.pop();
@@ -40589,7 +40591,7 @@ var platform_default = {
40589
40591
  // ../node_modules/axios/lib/helpers/toURLEncodedForm.js
40590
40592
  function toURLEncodedForm(data, options) {
40591
40593
  return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
40592
- visitor: function(value, key, path, helpers) {
40594
+ visitor: function(value, key, path2, helpers) {
40593
40595
  if (platform_default.isNode && utils_default.isBuffer(value)) {
40594
40596
  this.append(key, value.toString("base64"));
40595
40597
  return false;
@@ -40619,11 +40621,11 @@ function arrayToObject(arr) {
40619
40621
  return obj;
40620
40622
  }
40621
40623
  function formDataToJSON(formData) {
40622
- function buildPath(path, value, target, index) {
40623
- let name = path[index++];
40624
+ function buildPath(path2, value, target, index) {
40625
+ let name = path2[index++];
40624
40626
  if (name === "__proto__") return true;
40625
40627
  const isNumericKey = Number.isFinite(+name);
40626
- const isLast = index >= path.length;
40628
+ const isLast = index >= path2.length;
40627
40629
  name = !name && utils_default.isArray(target) ? target.length : name;
40628
40630
  if (isLast) {
40629
40631
  if (utils_default.hasOwnProp(target, name)) {
@@ -40636,7 +40638,7 @@ function formDataToJSON(formData) {
40636
40638
  if (!target[name] || !utils_default.isObject(target[name])) {
40637
40639
  target[name] = [];
40638
40640
  }
40639
- const result = buildPath(path, value, target[name], index);
40641
+ const result = buildPath(path2, value, target[name], index);
40640
40642
  if (result && utils_default.isArray(target[name])) {
40641
40643
  target[name] = arrayToObject(target[name]);
40642
40644
  }
@@ -42017,9 +42019,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
42017
42019
  auth = urlUsername + ":" + urlPassword;
42018
42020
  }
42019
42021
  auth && headers.delete("authorization");
42020
- let path;
42022
+ let path2;
42021
42023
  try {
42022
- path = buildURL(
42024
+ path2 = buildURL(
42023
42025
  parsed.pathname + parsed.search,
42024
42026
  config2.params,
42025
42027
  config2.paramsSerializer
@@ -42037,7 +42039,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
42037
42039
  false
42038
42040
  );
42039
42041
  const options = {
42040
- path,
42042
+ path: path2,
42041
42043
  method,
42042
42044
  headers: headers.toJSON(),
42043
42045
  agents: { http: config2.httpAgent, https: config2.httpsAgent },
@@ -42286,14 +42288,14 @@ var isURLSameOrigin_default = platform_default.hasStandardBrowserEnv ? /* @__PUR
42286
42288
  var cookies_default = platform_default.hasStandardBrowserEnv ? (
42287
42289
  // Standard browser envs support document.cookie
42288
42290
  {
42289
- write(name, value, expires, path, domain2, secure, sameSite) {
42291
+ write(name, value, expires, path2, domain2, secure, sameSite) {
42290
42292
  if (typeof document === "undefined") return;
42291
42293
  const cookie = [`${name}=${encodeURIComponent(value)}`];
42292
42294
  if (utils_default.isNumber(expires)) {
42293
42295
  cookie.push(`expires=${new Date(expires).toUTCString()}`);
42294
42296
  }
42295
- if (utils_default.isString(path)) {
42296
- cookie.push(`path=${path}`);
42297
+ if (utils_default.isString(path2)) {
42298
+ cookie.push(`path=${path2}`);
42297
42299
  }
42298
42300
  if (utils_default.isString(domain2)) {
42299
42301
  cookie.push(`domain=${domain2}`);
@@ -43649,15 +43651,18 @@ var xSearchSchema = paginationSchema.extend({
43649
43651
  query: z3.string().min(1).max(500),
43650
43652
  allowed_handles: z3.array(z3.string().min(1).max(50)).max(10).optional(),
43651
43653
  from_date: z3.string().datetime({ offset: true }).optional(),
43652
- to_date: z3.string().datetime({ offset: true }).optional()
43654
+ to_date: z3.string().datetime({ offset: true }).optional(),
43655
+ output_dir: z3.string().optional()
43653
43656
  }).strict();
43654
43657
  var webSearchSchema = paginationSchema.extend({
43655
43658
  query: z3.string().min(1).max(500),
43656
- allowed_domains: z3.array(z3.string().min(1).max(255)).max(20).optional()
43659
+ allowed_domains: z3.array(z3.string().min(1).max(255)).max(20).optional(),
43660
+ output_dir: z3.string().optional()
43657
43661
  }).strict();
43658
43662
  var imagineSchema = z3.object({
43659
43663
  prompt: z3.string().min(1).max(2e3),
43660
- aspect_ratio: z3.enum(aspectRatioValues).default("1:1")
43664
+ aspect_ratio: z3.enum(aspectRatioValues).default("1:1"),
43665
+ output_dir: z3.string().optional()
43661
43666
  }).strict();
43662
43667
  var animateSchema = z3.object({
43663
43668
  prompt: z3.string().min(1).max(2e3),
@@ -43665,7 +43670,8 @@ var animateSchema = z3.object({
43665
43670
  aspect_ratio: z3.enum(aspectRatioValues).default("16:9")
43666
43671
  }).strict();
43667
43672
  var videoStatusSchema = z3.object({
43668
- request_id: z3.string().min(1).max(200)
43673
+ request_id: z3.string().min(1).max(200),
43674
+ output_dir: z3.string().optional()
43669
43675
  }).strict();
43670
43676
  var TOOL_DEFINITIONS = [
43671
43677
  {
@@ -43709,6 +43715,10 @@ var TOOL_DEFINITIONS = [
43709
43715
  minimum: 0,
43710
43716
  default: 0,
43711
43717
  description: "Results to skip first"
43718
+ },
43719
+ output_dir: {
43720
+ type: "string",
43721
+ description: "Optional directory to save search results"
43712
43722
  }
43713
43723
  },
43714
43724
  required: ["query"]
@@ -43794,6 +43804,10 @@ var TOOL_DEFINITIONS = [
43794
43804
  minimum: 0,
43795
43805
  default: 0,
43796
43806
  description: "Results to skip first"
43807
+ },
43808
+ output_dir: {
43809
+ type: "string",
43810
+ description: "Optional directory to save search results"
43797
43811
  }
43798
43812
  },
43799
43813
  required: ["query"]
@@ -43864,6 +43878,10 @@ var TOOL_DEFINITIONS = [
43864
43878
  enum: [...aspectRatioValues],
43865
43879
  default: "1:1",
43866
43880
  description: "Image aspect ratio"
43881
+ },
43882
+ output_dir: {
43883
+ type: "string",
43884
+ description: "Optional directory to save generated images"
43867
43885
  }
43868
43886
  },
43869
43887
  required: ["prompt"]
@@ -43943,6 +43961,10 @@ var TOOL_DEFINITIONS = [
43943
43961
  minLength: 1,
43944
43962
  maxLength: 200,
43945
43963
  description: "Video request identifier"
43964
+ },
43965
+ output_dir: {
43966
+ type: "string",
43967
+ description: "Optional directory to save the generated video"
43946
43968
  }
43947
43969
  },
43948
43970
  required: ["request_id"]
@@ -44020,7 +44042,7 @@ function normalizeMediaMimeType(value, kind, sourceUrl) {
44020
44042
  }
44021
44043
  return inferMimeTypeFromUrl(sourceUrl, kind) || "application/octet-stream";
44022
44044
  }
44023
- async function fetchMediaAsBase64(sourceUrl, kind, client = axios_default) {
44045
+ async function fetchMedia(sourceUrl, kind, client = axios_default) {
44024
44046
  try {
44025
44047
  const response = await client.get(sourceUrl, {
44026
44048
  responseType: "arraybuffer",
@@ -44032,8 +44054,10 @@ async function fetchMediaAsBase64(sourceUrl, kind, client = axios_default) {
44032
44054
  if (buffer.byteLength === 0 || buffer.byteLength > MAX_EMBEDDED_MEDIA_BYTES) {
44033
44055
  return void 0;
44034
44056
  }
44057
+ const data = buffer.toString("base64");
44035
44058
  return {
44036
- data: buffer.toString("base64"),
44059
+ buffer,
44060
+ data,
44037
44061
  mimeType: normalizeMediaMimeType(
44038
44062
  response.headers["content-type"],
44039
44063
  kind,
@@ -44045,45 +44069,57 @@ async function fetchMediaAsBase64(sourceUrl, kind, client = axios_default) {
44045
44069
  }
44046
44070
  }
44047
44071
  async function buildImageContent(imageUrl, client = axios_default) {
44048
- const media = await fetchMediaAsBase64(imageUrl, "image", client);
44072
+ const media = await fetchMedia(imageUrl, "image", client);
44049
44073
  if (!media) {
44050
44074
  return void 0;
44051
44075
  }
44052
44076
  return {
44053
- type: "image",
44054
- data: media.data,
44055
- mimeType: media.mimeType
44077
+ content: {
44078
+ type: "image",
44079
+ data: media.data,
44080
+ mimeType: media.mimeType
44081
+ },
44082
+ buffer: media.buffer
44056
44083
  };
44057
44084
  }
44058
44085
  async function buildVideoContent(videoUrl, client = axios_default) {
44059
- const media = await fetchMediaAsBase64(videoUrl, "video", client);
44086
+ const media = await fetchMedia(videoUrl, "video", client);
44060
44087
  if (!media) {
44061
44088
  return void 0;
44062
44089
  }
44063
44090
  return {
44064
- type: "resource",
44065
- resource: {
44066
- uri: videoUrl,
44067
- mimeType: media.mimeType,
44068
- blob: media.data
44069
- }
44091
+ content: {
44092
+ type: "resource",
44093
+ resource: {
44094
+ uri: videoUrl,
44095
+ mimeType: media.mimeType,
44096
+ blob: media.data
44097
+ }
44098
+ },
44099
+ buffer: media.buffer
44070
44100
  };
44071
44101
  }
44072
44102
  function buildMockImageContent() {
44073
44103
  return {
44074
- type: "image",
44075
- data: MOCK_IMAGE_BASE64,
44076
- mimeType: "image/png"
44104
+ content: {
44105
+ type: "image",
44106
+ data: MOCK_IMAGE_BASE64,
44107
+ mimeType: "image/png"
44108
+ },
44109
+ buffer: Buffer.from(MOCK_IMAGE_BASE64, "base64")
44077
44110
  };
44078
44111
  }
44079
44112
  function buildMockVideoContent(videoUrl) {
44080
44113
  return {
44081
- type: "resource",
44082
- resource: {
44083
- uri: videoUrl,
44084
- mimeType: "video/mp4",
44085
- blob: MOCK_VIDEO_BASE64
44086
- }
44114
+ content: {
44115
+ type: "resource",
44116
+ resource: {
44117
+ uri: videoUrl,
44118
+ mimeType: "video/mp4",
44119
+ blob: MOCK_VIDEO_BASE64
44120
+ }
44121
+ },
44122
+ buffer: Buffer.from(MOCK_VIDEO_BASE64, "base64")
44087
44123
  };
44088
44124
  }
44089
44125
  function extractNestedText(value) {
@@ -44326,6 +44362,12 @@ function toolResult(text, structuredContent, extraContent = []) {
44326
44362
  structuredContent
44327
44363
  };
44328
44364
  }
44365
+ async function saveFile(outputDir, filename, data) {
44366
+ await fs.mkdir(outputDir, { recursive: true });
44367
+ const fpath = path.join(outputDir, filename);
44368
+ await fs.writeFile(fpath, data);
44369
+ return fpath;
44370
+ }
44329
44371
  function normalizeSearchResponse(raw, query, limit, offset, normalizer) {
44330
44372
  const summary = getResponseSummary(raw);
44331
44373
  const citations = getCitations(raw);
@@ -44412,7 +44454,8 @@ async function handleToolCall(name, args, client = xaiClient) {
44412
44454
  from_date,
44413
44455
  to_date,
44414
44456
  limit,
44415
- offset
44457
+ offset,
44458
+ output_dir
44416
44459
  } = parsed.data;
44417
44460
  const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_search_x : (await client.post("/responses", {
44418
44461
  model: "grok-4-1-fast-reasoning",
@@ -44435,14 +44478,32 @@ async function handleToolCall(name, args, client = xaiClient) {
44435
44478
  offset,
44436
44479
  normalizeXResults
44437
44480
  );
44438
- return toolResult(renderXSearch(output), output);
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);
44439
44500
  }
44440
44501
  case "grok_search_web": {
44441
44502
  const parsed = parseArguments(name, webSearchSchema, args);
44442
44503
  if ("error" in parsed) {
44443
44504
  return parsed.error;
44444
44505
  }
44445
- const { query, allowed_domains, limit, offset } = parsed.data;
44506
+ const { query, allowed_domains, limit, offset, output_dir } = parsed.data;
44446
44507
  const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_search_web : (await client.post("/responses", {
44447
44508
  model: "grok-4-1-fast-reasoning",
44448
44509
  input: [{ role: "user", content: query }],
@@ -44460,14 +44521,32 @@ async function handleToolCall(name, args, client = xaiClient) {
44460
44521
  offset,
44461
44522
  normalizeWebResults
44462
44523
  );
44463
- return toolResult(renderWebSearch(output), output);
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);
44464
44543
  }
44465
44544
  case "grok_imagine": {
44466
44545
  const parsed = parseArguments(name, imagineSchema, args);
44467
44546
  if ("error" in parsed) {
44468
44547
  return parsed.error;
44469
44548
  }
44470
- const { prompt, aspect_ratio } = parsed.data;
44549
+ const { prompt, aspect_ratio, output_dir } = parsed.data;
44471
44550
  const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_imagine : (await client.post("/images/generations", {
44472
44551
  model: "grok-imagine-image",
44473
44552
  prompt,
@@ -44479,14 +44558,41 @@ async function handleToolCall(name, args, client = xaiClient) {
44479
44558
  prompt,
44480
44559
  aspect_ratio
44481
44560
  );
44482
- const mediaContent = IS_MOCK ? [buildMockImageContent()] : (await Promise.all(
44561
+ const mediaResults = IS_MOCK ? [buildMockImageContent()] : (await Promise.all(
44483
44562
  output.images.map(
44484
44563
  (image) => buildImageContent(image.url, client)
44485
44564
  )
44486
44565
  )).filter(
44487
44566
  (item) => item !== void 0
44488
44567
  );
44489
- return toolResult(renderImagine(output), output, mediaContent);
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
+ );
44490
44596
  }
44491
44597
  case "grok_animate": {
44492
44598
  const parsed = parseArguments(name, animateSchema, args);
@@ -44506,35 +44612,45 @@ async function handleToolCall(name, args, client = xaiClient) {
44506
44612
  aspect_ratio,
44507
44613
  image_url
44508
44614
  );
44509
- const mediaContent = output.video_url === void 0 ? [] : IS_MOCK ? [buildMockVideoContent(output.video_url)] : (await Promise.all([
44510
- buildVideoContent(output.video_url, client)
44511
- ])).filter(
44512
- (item) => item !== void 0
44513
- );
44514
- return toolResult(
44515
- renderVideoGeneration(output),
44516
- output,
44517
- mediaContent
44518
- );
44615
+ return toolResult(renderVideoGeneration(output), output);
44519
44616
  }
44520
44617
  case "grok_check_video_status": {
44521
44618
  const parsed = parseArguments(name, videoStatusSchema, args);
44522
44619
  if ("error" in parsed) {
44523
44620
  return parsed.error;
44524
44621
  }
44525
- const { request_id } = parsed.data;
44622
+ const { request_id, output_dir } = parsed.data;
44526
44623
  const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_check_video_status : (await client.get(`/videos/${request_id}`)).data;
44527
44624
  const output = normalizeVideoStatusResponse(
44528
44625
  rawResponse,
44529
44626
  request_id
44530
44627
  );
44531
- const mediaContent = output.video_url === void 0 ? [] : IS_MOCK ? [buildMockVideoContent(output.video_url)] : (await Promise.all([
44532
- buildVideoContent(output.video_url, client)
44533
- ])).filter(
44534
- (item) => item !== void 0
44535
- );
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
+ }
44536
44652
  return toolResult(
44537
- renderVideoStatus(output),
44653
+ renderVideoStatus(output) + extraText,
44538
44654
  output,
44539
44655
  mediaContent
44540
44656
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fre4x/grok",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "An MCP server for xAI (Grok) with search and generation capabilities.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",