@fre4x/grok 1.0.50 → 1.0.51
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 +196 -104
- 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(
|
|
3233
|
-
let input =
|
|
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 [
|
|
3433
|
-
wsComponent.path =
|
|
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,
|
|
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,
|
|
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(
|
|
15656
|
-
if (!
|
|
15655
|
+
function lookup(path2) {
|
|
15656
|
+
if (!path2 || typeof path2 !== "string") {
|
|
15657
15657
|
return false;
|
|
15658
15658
|
}
|
|
15659
|
-
var extension2 = extname("x." +
|
|
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
|
|
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
|
|
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
|
-
|
|
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 =
|
|
16892
|
+
filename = path2.normalize(options.filepath).replace(/\\/g, "/");
|
|
16893
16893
|
} else if (options.filename || value && (value.name || value.path)) {
|
|
16894
|
-
filename =
|
|
16894
|
+
filename = path2.basename(options.filename || value && (value.name || value.path));
|
|
16895
16895
|
} else if (value && value.readable && hasOwn(value, "httpVersion")) {
|
|
16896
|
-
filename =
|
|
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,
|
|
19538
|
-
if (!
|
|
19539
|
+
function getElementAtPath(obj, path2) {
|
|
19540
|
+
if (!path2)
|
|
19539
19541
|
return obj;
|
|
19540
|
-
return
|
|
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(
|
|
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(
|
|
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,
|
|
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 = [...
|
|
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
|
|
20153
|
-
for (const seg of
|
|
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
|
|
32131
|
-
if (
|
|
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 (
|
|
32136
|
-
const key =
|
|
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 = [...
|
|
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,
|
|
33025
|
+
constructor(parent, value, path2, key) {
|
|
33024
33026
|
this._cachedPath = [];
|
|
33025
33027
|
this.parent = parent;
|
|
33026
33028
|
this.data = value;
|
|
33027
|
-
this._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(
|
|
40283
|
-
if (!
|
|
40284
|
-
return
|
|
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,
|
|
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(
|
|
40342
|
+
formData.append(renderKey(path2, key, dots), convertValue(value));
|
|
40341
40343
|
return false;
|
|
40342
40344
|
}
|
|
40343
|
-
if (value && !
|
|
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(
|
|
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,
|
|
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 " +
|
|
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,
|
|
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,
|
|
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,
|
|
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(
|
|
40623
|
-
let name =
|
|
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 >=
|
|
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(
|
|
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
|
|
42022
|
+
let path2;
|
|
42021
42023
|
try {
|
|
42022
|
-
|
|
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,
|
|
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(
|
|
42296
|
-
cookie.push(`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
|
|
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
|
-
|
|
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
|
|
44072
|
+
const media = await fetchMedia(imageUrl, "image", client);
|
|
44049
44073
|
if (!media) {
|
|
44050
44074
|
return void 0;
|
|
44051
44075
|
}
|
|
44052
44076
|
return {
|
|
44053
|
-
|
|
44054
|
-
|
|
44055
|
-
|
|
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
|
|
44086
|
+
const media = await fetchMedia(videoUrl, "video", client);
|
|
44060
44087
|
if (!media) {
|
|
44061
44088
|
return void 0;
|
|
44062
44089
|
}
|
|
44063
44090
|
return {
|
|
44064
|
-
|
|
44065
|
-
|
|
44066
|
-
|
|
44067
|
-
|
|
44068
|
-
|
|
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
|
-
|
|
44075
|
-
|
|
44076
|
-
|
|
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
|
-
|
|
44082
|
-
|
|
44083
|
-
|
|
44084
|
-
|
|
44085
|
-
|
|
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,26 @@ async function handleToolCall(name, args, client = xaiClient) {
|
|
|
44435
44478
|
offset,
|
|
44436
44479
|
normalizeXResults
|
|
44437
44480
|
);
|
|
44438
|
-
|
|
44481
|
+
let extraText = "";
|
|
44482
|
+
if (output_dir) {
|
|
44483
|
+
const fname = `grok-x-search-${Date.now()}.json`;
|
|
44484
|
+
const fpath = await saveFile(
|
|
44485
|
+
output_dir,
|
|
44486
|
+
fname,
|
|
44487
|
+
JSON.stringify(output, null, 2)
|
|
44488
|
+
);
|
|
44489
|
+
extraText = `
|
|
44490
|
+
|
|
44491
|
+
\u2705 Results saved to: ${fpath}`;
|
|
44492
|
+
}
|
|
44493
|
+
return toolResult(renderXSearch(output) + extraText, output);
|
|
44439
44494
|
}
|
|
44440
44495
|
case "grok_search_web": {
|
|
44441
44496
|
const parsed = parseArguments(name, webSearchSchema, args);
|
|
44442
44497
|
if ("error" in parsed) {
|
|
44443
44498
|
return parsed.error;
|
|
44444
44499
|
}
|
|
44445
|
-
const { query, allowed_domains, limit, offset } = parsed.data;
|
|
44500
|
+
const { query, allowed_domains, limit, offset, output_dir } = parsed.data;
|
|
44446
44501
|
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_search_web : (await client.post("/responses", {
|
|
44447
44502
|
model: "grok-4-1-fast-reasoning",
|
|
44448
44503
|
input: [{ role: "user", content: query }],
|
|
@@ -44460,14 +44515,26 @@ async function handleToolCall(name, args, client = xaiClient) {
|
|
|
44460
44515
|
offset,
|
|
44461
44516
|
normalizeWebResults
|
|
44462
44517
|
);
|
|
44463
|
-
|
|
44518
|
+
let extraText = "";
|
|
44519
|
+
if (output_dir) {
|
|
44520
|
+
const fname = `grok-web-search-${Date.now()}.json`;
|
|
44521
|
+
const fpath = await saveFile(
|
|
44522
|
+
output_dir,
|
|
44523
|
+
fname,
|
|
44524
|
+
JSON.stringify(output, null, 2)
|
|
44525
|
+
);
|
|
44526
|
+
extraText = `
|
|
44527
|
+
|
|
44528
|
+
\u2705 Results saved to: ${fpath}`;
|
|
44529
|
+
}
|
|
44530
|
+
return toolResult(renderWebSearch(output) + extraText, output);
|
|
44464
44531
|
}
|
|
44465
44532
|
case "grok_imagine": {
|
|
44466
44533
|
const parsed = parseArguments(name, imagineSchema, args);
|
|
44467
44534
|
if ("error" in parsed) {
|
|
44468
44535
|
return parsed.error;
|
|
44469
44536
|
}
|
|
44470
|
-
const { prompt, aspect_ratio } = parsed.data;
|
|
44537
|
+
const { prompt, aspect_ratio, output_dir } = parsed.data;
|
|
44471
44538
|
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_imagine : (await client.post("/images/generations", {
|
|
44472
44539
|
model: "grok-imagine-image",
|
|
44473
44540
|
prompt,
|
|
@@ -44479,14 +44546,35 @@ async function handleToolCall(name, args, client = xaiClient) {
|
|
|
44479
44546
|
prompt,
|
|
44480
44547
|
aspect_ratio
|
|
44481
44548
|
);
|
|
44482
|
-
const
|
|
44549
|
+
const mediaResults = IS_MOCK ? [buildMockImageContent()] : (await Promise.all(
|
|
44483
44550
|
output.images.map(
|
|
44484
44551
|
(image) => buildImageContent(image.url, client)
|
|
44485
44552
|
)
|
|
44486
44553
|
)).filter(
|
|
44487
44554
|
(item) => item !== void 0
|
|
44488
44555
|
);
|
|
44489
|
-
|
|
44556
|
+
const mediaContent = mediaResults.map((r) => r.content);
|
|
44557
|
+
let extraText = "";
|
|
44558
|
+
if (output_dir && mediaResults.length > 0) {
|
|
44559
|
+
const savedPaths = await Promise.all(
|
|
44560
|
+
mediaResults.map(
|
|
44561
|
+
(res, i) => saveFile(
|
|
44562
|
+
output_dir,
|
|
44563
|
+
`imagine-${Date.now()}-${i + 1}.png`,
|
|
44564
|
+
res.buffer
|
|
44565
|
+
)
|
|
44566
|
+
)
|
|
44567
|
+
);
|
|
44568
|
+
extraText = `
|
|
44569
|
+
|
|
44570
|
+
\u2705 Images saved to:
|
|
44571
|
+
${savedPaths.join("\n")}`;
|
|
44572
|
+
}
|
|
44573
|
+
return toolResult(
|
|
44574
|
+
renderImagine(output) + extraText,
|
|
44575
|
+
output,
|
|
44576
|
+
mediaContent
|
|
44577
|
+
);
|
|
44490
44578
|
}
|
|
44491
44579
|
case "grok_animate": {
|
|
44492
44580
|
const parsed = parseArguments(name, animateSchema, args);
|
|
@@ -44506,35 +44594,39 @@ async function handleToolCall(name, args, client = xaiClient) {
|
|
|
44506
44594
|
aspect_ratio,
|
|
44507
44595
|
image_url
|
|
44508
44596
|
);
|
|
44509
|
-
|
|
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
|
-
);
|
|
44597
|
+
return toolResult(renderVideoGeneration(output), output);
|
|
44519
44598
|
}
|
|
44520
44599
|
case "grok_check_video_status": {
|
|
44521
44600
|
const parsed = parseArguments(name, videoStatusSchema, args);
|
|
44522
44601
|
if ("error" in parsed) {
|
|
44523
44602
|
return parsed.error;
|
|
44524
44603
|
}
|
|
44525
|
-
const { request_id } = parsed.data;
|
|
44604
|
+
const { request_id, output_dir } = parsed.data;
|
|
44526
44605
|
const rawResponse = IS_MOCK ? MOCK_FIXTURES.grok_check_video_status : (await client.get(`/videos/${request_id}`)).data;
|
|
44527
44606
|
const output = normalizeVideoStatusResponse(
|
|
44528
44607
|
rawResponse,
|
|
44529
44608
|
request_id
|
|
44530
44609
|
);
|
|
44531
|
-
|
|
44532
|
-
|
|
44533
|
-
|
|
44534
|
-
(
|
|
44535
|
-
|
|
44610
|
+
let mediaContent = [];
|
|
44611
|
+
let extraText = "";
|
|
44612
|
+
if (output.video_url !== void 0) {
|
|
44613
|
+
const mediaRes = IS_MOCK ? buildMockVideoContent(output.video_url) : await buildVideoContent(output.video_url, client);
|
|
44614
|
+
if (mediaRes) {
|
|
44615
|
+
mediaContent = [mediaRes.content];
|
|
44616
|
+
if (output_dir) {
|
|
44617
|
+
const fpath = await saveFile(
|
|
44618
|
+
output_dir,
|
|
44619
|
+
`video-${Date.now()}.mp4`,
|
|
44620
|
+
mediaRes.buffer
|
|
44621
|
+
);
|
|
44622
|
+
extraText = `
|
|
44623
|
+
|
|
44624
|
+
\u2705 Video saved to: ${fpath}`;
|
|
44625
|
+
}
|
|
44626
|
+
}
|
|
44627
|
+
}
|
|
44536
44628
|
return toolResult(
|
|
44537
|
-
renderVideoStatus(output),
|
|
44629
|
+
renderVideoStatus(output) + extraText,
|
|
44538
44630
|
output,
|
|
44539
44631
|
mediaContent
|
|
44540
44632
|
);
|