@fre4x/grok 1.0.53 → 1.0.55
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 +159 -103
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16767,7 +16767,7 @@ var require_form_data = __commonJS({
|
|
|
16767
16767
|
var parseUrl = __require("url").parse;
|
|
16768
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();
|
|
@@ -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;
|
|
@@ -32551,6 +32551,7 @@ var paginationSchema = z2.object({
|
|
|
32551
32551
|
import * as fs from "node:fs/promises";
|
|
32552
32552
|
import * as path from "node:path";
|
|
32553
32553
|
import * as os from "node:os";
|
|
32554
|
+
import * as crypto from "node:crypto";
|
|
32554
32555
|
var PersistentCache = class {
|
|
32555
32556
|
cacheDir;
|
|
32556
32557
|
memoryCache = /* @__PURE__ */ new Map();
|
|
@@ -32562,7 +32563,7 @@ var PersistentCache = class {
|
|
|
32562
32563
|
await fs.mkdir(this.cacheDir, { recursive: true });
|
|
32563
32564
|
}
|
|
32564
32565
|
getFilePath(key) {
|
|
32565
|
-
const safeKey =
|
|
32566
|
+
const safeKey = crypto.createHash("sha256").update(key).digest("hex");
|
|
32566
32567
|
return path.join(this.cacheDir, `${safeKey}.json`);
|
|
32567
32568
|
}
|
|
32568
32569
|
async get(key) {
|
|
@@ -42917,7 +42918,7 @@ var transitional_default = {
|
|
|
42917
42918
|
};
|
|
42918
42919
|
|
|
42919
42920
|
// ../node_modules/axios/lib/platform/node/index.js
|
|
42920
|
-
import
|
|
42921
|
+
import crypto2 from "crypto";
|
|
42921
42922
|
|
|
42922
42923
|
// ../node_modules/axios/lib/platform/node/classes/URLSearchParams.js
|
|
42923
42924
|
import url2 from "url";
|
|
@@ -42935,7 +42936,7 @@ var generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
42935
42936
|
let str = "";
|
|
42936
42937
|
const { length } = alphabet;
|
|
42937
42938
|
const randomValues = new Uint32Array(size);
|
|
42938
|
-
|
|
42939
|
+
crypto2.randomFillSync(randomValues);
|
|
42939
42940
|
for (let i = 0; i < size; i++) {
|
|
42940
42941
|
str += alphabet[randomValues[i] % length];
|
|
42941
42942
|
}
|
|
@@ -45931,72 +45932,94 @@ var {
|
|
|
45931
45932
|
var IS_MOCK = process.env.MOCK === "true" || process.env.GROK_MOCK === "true";
|
|
45932
45933
|
var MOCK_FIXTURES = {
|
|
45933
45934
|
grok_search_x: {
|
|
45934
|
-
|
|
45935
|
-
|
|
45935
|
+
id: "mock_resp_1",
|
|
45936
|
+
model: "grok-4-1-fast-reasoning",
|
|
45937
|
+
output: [
|
|
45936
45938
|
{
|
|
45937
|
-
|
|
45938
|
-
|
|
45939
|
-
|
|
45940
|
-
}
|
|
45941
|
-
|
|
45939
|
+
type: "server_tool_use",
|
|
45940
|
+
call_id: "call_search1",
|
|
45941
|
+
server_tool_name: "x_search",
|
|
45942
|
+
input: { query: "Grok MCP" }
|
|
45943
|
+
},
|
|
45944
|
+
{
|
|
45945
|
+
type: "server_tool_result",
|
|
45946
|
+
call_id: "call_search1",
|
|
45947
|
+
output: [
|
|
45942
45948
|
{
|
|
45943
|
-
|
|
45944
|
-
|
|
45949
|
+
type: "server_tool_result_content",
|
|
45950
|
+
content: JSON.stringify({
|
|
45951
|
+
results: [
|
|
45952
|
+
{
|
|
45953
|
+
id: "123456789",
|
|
45954
|
+
text: "Grok is now available via MCP! #xAI #Grok #MCP",
|
|
45955
|
+
author: "xAI",
|
|
45956
|
+
created_at: "2026-03-04T12:00:00Z",
|
|
45957
|
+
url: "https://x.com/xai/status/123456789"
|
|
45958
|
+
},
|
|
45959
|
+
{
|
|
45960
|
+
id: "123456790",
|
|
45961
|
+
text: "Testing Grok MCP today and the mock mode is handy.",
|
|
45962
|
+
author: "dev_agent",
|
|
45963
|
+
created_at: "2026-03-04T14:30:00Z",
|
|
45964
|
+
url: "https://x.com/dev_agent/status/123456790"
|
|
45965
|
+
}
|
|
45966
|
+
]
|
|
45967
|
+
})
|
|
45945
45968
|
}
|
|
45946
|
-
]
|
|
45947
|
-
|
|
45969
|
+
]
|
|
45970
|
+
},
|
|
45971
|
+
{
|
|
45972
|
+
type: "message",
|
|
45973
|
+
role: "assistant",
|
|
45974
|
+
content: [
|
|
45948
45975
|
{
|
|
45949
|
-
type: "
|
|
45950
|
-
|
|
45951
|
-
{
|
|
45952
|
-
id: "123456789",
|
|
45953
|
-
text: "Grok is now available via MCP! #xAI #Grok #MCP",
|
|
45954
|
-
author: "xAI",
|
|
45955
|
-
created_at: "2026-03-04T12:00:00Z",
|
|
45956
|
-
url: "https://x.com/xai/status/123456789"
|
|
45957
|
-
},
|
|
45958
|
-
{
|
|
45959
|
-
id: "123456790",
|
|
45960
|
-
text: "Testing Grok MCP today and the mock mode is handy.",
|
|
45961
|
-
author: "dev_agent",
|
|
45962
|
-
created_at: "2026-03-04T14:30:00Z",
|
|
45963
|
-
url: "https://x.com/dev_agent/status/123456790"
|
|
45964
|
-
}
|
|
45965
|
-
]
|
|
45976
|
+
type: "output_text",
|
|
45977
|
+
text: "Recent posts discuss Grok MCP availability and positive early feedback."
|
|
45966
45978
|
}
|
|
45967
45979
|
]
|
|
45968
45980
|
}
|
|
45969
45981
|
]
|
|
45970
45982
|
},
|
|
45971
45983
|
grok_search_web: {
|
|
45972
|
-
|
|
45973
|
-
|
|
45984
|
+
id: "mock_resp_2",
|
|
45985
|
+
model: "grok-4-1-fast-reasoning",
|
|
45986
|
+
output: [
|
|
45974
45987
|
{
|
|
45975
|
-
|
|
45976
|
-
|
|
45977
|
-
|
|
45978
|
-
}
|
|
45979
|
-
|
|
45988
|
+
type: "server_tool_use",
|
|
45989
|
+
call_id: "call_web1",
|
|
45990
|
+
server_tool_name: "web_search",
|
|
45991
|
+
input: { query: "MCP Documentation" }
|
|
45992
|
+
},
|
|
45993
|
+
{
|
|
45994
|
+
type: "server_tool_result",
|
|
45995
|
+
call_id: "call_web1",
|
|
45996
|
+
output: [
|
|
45980
45997
|
{
|
|
45981
|
-
|
|
45982
|
-
|
|
45998
|
+
type: "server_tool_result_content",
|
|
45999
|
+
content: JSON.stringify({
|
|
46000
|
+
results: [
|
|
46001
|
+
{
|
|
46002
|
+
title: "Model Context Protocol Documentation",
|
|
46003
|
+
url: "https://modelcontextprotocol.io",
|
|
46004
|
+
snippet: "MCP is an open standard that enables AI models to connect to external tools."
|
|
46005
|
+
},
|
|
46006
|
+
{
|
|
46007
|
+
title: "Tools - MCP Specification",
|
|
46008
|
+
url: "https://modelcontextprotocol.io/specification/draft/server/tools",
|
|
46009
|
+
snippet: "Servers expose tools through tools/list and tools/call with JSON Schema metadata."
|
|
46010
|
+
}
|
|
46011
|
+
]
|
|
46012
|
+
})
|
|
45983
46013
|
}
|
|
45984
|
-
]
|
|
45985
|
-
|
|
46014
|
+
]
|
|
46015
|
+
},
|
|
46016
|
+
{
|
|
46017
|
+
type: "message",
|
|
46018
|
+
role: "assistant",
|
|
46019
|
+
content: [
|
|
45986
46020
|
{
|
|
45987
|
-
type: "
|
|
45988
|
-
|
|
45989
|
-
{
|
|
45990
|
-
title: "Model Context Protocol Documentation",
|
|
45991
|
-
url: "https://modelcontextprotocol.io",
|
|
45992
|
-
snippet: "MCP is an open standard that enables AI models to connect to external tools."
|
|
45993
|
-
},
|
|
45994
|
-
{
|
|
45995
|
-
title: "Tools - MCP Specification",
|
|
45996
|
-
url: "https://modelcontextprotocol.io/specification/draft/server/tools",
|
|
45997
|
-
snippet: "Servers expose tools through tools/list and tools/call with JSON Schema metadata."
|
|
45998
|
-
}
|
|
45999
|
-
]
|
|
46021
|
+
type: "output_text",
|
|
46022
|
+
text: "The MCP documentation is the primary reference and includes tool, resource, and prompt specs."
|
|
46000
46023
|
}
|
|
46001
46024
|
]
|
|
46002
46025
|
}
|
|
@@ -46039,6 +46062,9 @@ var MEDIA_FETCH_TIMEOUT_MS = Number.parseInt(
|
|
|
46039
46062
|
);
|
|
46040
46063
|
var MOCK_IMAGE_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
46041
46064
|
var MOCK_VIDEO_BASE64 = "AAAAHGZ0eXBpc29tAAAAAGlzb21pc28yYXZjMQ==";
|
|
46065
|
+
function getErrorMessage(error48) {
|
|
46066
|
+
return error48 instanceof Error ? error48.message : String(error48);
|
|
46067
|
+
}
|
|
46042
46068
|
var xSearchSchema = paginationSchema.extend({
|
|
46043
46069
|
query: z3.string().min(1).max(500),
|
|
46044
46070
|
allowed_handles: z3.array(z3.string().min(1).max(50)).max(10).optional(),
|
|
@@ -46134,11 +46160,10 @@ async function handleGrokSearchX(params, client = xaiClient) {
|
|
|
46134
46160
|
tools: [
|
|
46135
46161
|
{
|
|
46136
46162
|
type: "x_search",
|
|
46137
|
-
|
|
46138
|
-
|
|
46139
|
-
|
|
46140
|
-
|
|
46141
|
-
}
|
|
46163
|
+
query,
|
|
46164
|
+
allowed_x_handles: allowed_handles,
|
|
46165
|
+
from_date,
|
|
46166
|
+
to_date
|
|
46142
46167
|
}
|
|
46143
46168
|
]
|
|
46144
46169
|
});
|
|
@@ -46167,7 +46192,7 @@ async function handleGrokSearchX(params, client = xaiClient) {
|
|
|
46167
46192
|
} catch (error48) {
|
|
46168
46193
|
extraText = `
|
|
46169
46194
|
|
|
46170
|
-
\u26A0\uFE0F Failed to save results: ${error48
|
|
46195
|
+
\u26A0\uFE0F Failed to save results: ${getErrorMessage(error48)}`;
|
|
46171
46196
|
}
|
|
46172
46197
|
}
|
|
46173
46198
|
return toolResult(renderXSearch(output) + extraText, output);
|
|
@@ -46205,7 +46230,8 @@ async function handleGrokSearchWeb(params, client = xaiClient) {
|
|
|
46205
46230
|
tools: [
|
|
46206
46231
|
{
|
|
46207
46232
|
type: "web_search",
|
|
46208
|
-
|
|
46233
|
+
query,
|
|
46234
|
+
allowed_domains
|
|
46209
46235
|
}
|
|
46210
46236
|
]
|
|
46211
46237
|
});
|
|
@@ -46234,7 +46260,7 @@ async function handleGrokSearchWeb(params, client = xaiClient) {
|
|
|
46234
46260
|
} catch (error48) {
|
|
46235
46261
|
extraText = `
|
|
46236
46262
|
|
|
46237
|
-
\u26A0\uFE0F Failed to save results: ${error48
|
|
46263
|
+
\u26A0\uFE0F Failed to save results: ${getErrorMessage(error48)}`;
|
|
46238
46264
|
}
|
|
46239
46265
|
}
|
|
46240
46266
|
return toolResult(renderWebSearch(output) + extraText, output);
|
|
@@ -46289,7 +46315,7 @@ ${savedPaths.join("\n")}`;
|
|
|
46289
46315
|
} catch (error48) {
|
|
46290
46316
|
extraText = `
|
|
46291
46317
|
|
|
46292
|
-
\u26A0\uFE0F Failed to save images: ${error48
|
|
46318
|
+
\u26A0\uFE0F Failed to save images: ${getErrorMessage(error48)}`;
|
|
46293
46319
|
}
|
|
46294
46320
|
}
|
|
46295
46321
|
return toolResult(
|
|
@@ -46360,7 +46386,7 @@ async function handleGrokVideoStatus(params, client = xaiClient) {
|
|
|
46360
46386
|
} catch (error48) {
|
|
46361
46387
|
extraText = `
|
|
46362
46388
|
|
|
46363
|
-
\u26A0\uFE0F Failed to save video: ${error48
|
|
46389
|
+
\u26A0\uFE0F Failed to save video: ${getErrorMessage(error48)}`;
|
|
46364
46390
|
}
|
|
46365
46391
|
}
|
|
46366
46392
|
}
|
|
@@ -46550,18 +46576,6 @@ function buildMockVideoContent(videoUrl) {
|
|
|
46550
46576
|
buffer: Buffer.from(MOCK_VIDEO_BASE64, "base64")
|
|
46551
46577
|
};
|
|
46552
46578
|
}
|
|
46553
|
-
function extractNestedText(value) {
|
|
46554
|
-
if (typeof value === "string") {
|
|
46555
|
-
return value.trim() ? [value.trim()] : [];
|
|
46556
|
-
}
|
|
46557
|
-
if (Array.isArray(value)) {
|
|
46558
|
-
return value.flatMap((item) => extractNestedText(item));
|
|
46559
|
-
}
|
|
46560
|
-
if (isRecord(value)) {
|
|
46561
|
-
return Object.values(value).flatMap((item) => extractNestedText(item));
|
|
46562
|
-
}
|
|
46563
|
-
return [];
|
|
46564
|
-
}
|
|
46565
46579
|
function dedupeByKey(items, keyFn) {
|
|
46566
46580
|
const seen = /* @__PURE__ */ new Set();
|
|
46567
46581
|
const result = [];
|
|
@@ -46591,40 +46605,82 @@ function getResponseSummary(raw) {
|
|
|
46591
46605
|
if (!isRecord(raw)) {
|
|
46592
46606
|
return "";
|
|
46593
46607
|
}
|
|
46594
|
-
const
|
|
46595
|
-
|
|
46596
|
-
|
|
46608
|
+
const outputItems = asArray(raw.output);
|
|
46609
|
+
const summaries = [];
|
|
46610
|
+
for (const item of outputItems) {
|
|
46611
|
+
if (!isRecord(item)) continue;
|
|
46612
|
+
if (asString(item.type) === "message" && asString(item.role) === "assistant") {
|
|
46613
|
+
const content = asArray(item.content);
|
|
46614
|
+
for (const part of content) {
|
|
46615
|
+
if (isRecord(part) && asString(part.type) === "output_text") {
|
|
46616
|
+
const text = asString(part.text);
|
|
46617
|
+
if (text) {
|
|
46618
|
+
summaries.push(text);
|
|
46619
|
+
}
|
|
46620
|
+
}
|
|
46621
|
+
}
|
|
46622
|
+
}
|
|
46597
46623
|
}
|
|
46598
|
-
|
|
46599
|
-
return choiceMessages.join("\n").trim();
|
|
46624
|
+
return summaries.join("\n").trim();
|
|
46600
46625
|
}
|
|
46601
|
-
function getToolOutputs(raw,
|
|
46626
|
+
function getToolOutputs(raw, _toolType) {
|
|
46602
46627
|
if (!isRecord(raw)) {
|
|
46603
46628
|
return [];
|
|
46604
46629
|
}
|
|
46605
|
-
const
|
|
46606
|
-
|
|
46607
|
-
|
|
46630
|
+
const outputItems = asArray(raw.output);
|
|
46631
|
+
const results = [];
|
|
46632
|
+
for (const item of outputItems) {
|
|
46633
|
+
if (!isRecord(item)) continue;
|
|
46634
|
+
const itemType = asString(item.type);
|
|
46635
|
+
if (itemType === "server_tool_result") {
|
|
46636
|
+
const itemOutput = asArray(item.output);
|
|
46637
|
+
for (const outPart of itemOutput) {
|
|
46638
|
+
if (!isRecord(outPart)) continue;
|
|
46639
|
+
const outType = asString(outPart.type);
|
|
46640
|
+
if (outType !== "server_tool_result_content") continue;
|
|
46641
|
+
const content = asString(outPart.content);
|
|
46642
|
+
if (!content) continue;
|
|
46643
|
+
try {
|
|
46644
|
+
const parsed = JSON.parse(content);
|
|
46645
|
+
results.push(parsed);
|
|
46646
|
+
} catch {
|
|
46647
|
+
}
|
|
46648
|
+
}
|
|
46608
46649
|
}
|
|
46609
|
-
|
|
46610
|
-
|
|
46611
|
-
return [...choiceToolCalls, ...messageToolCalls];
|
|
46612
|
-
});
|
|
46613
|
-
return toolCalls.filter(
|
|
46614
|
-
(call) => isRecord(call) && asString(call.type) === toolType && Array.isArray(call.outputs)
|
|
46615
|
-
).flatMap((call) => asArray(call.outputs));
|
|
46650
|
+
}
|
|
46651
|
+
return results;
|
|
46616
46652
|
}
|
|
46617
46653
|
function getCitations(raw) {
|
|
46618
46654
|
const candidates = [];
|
|
46619
|
-
|
|
46620
|
-
|
|
46621
|
-
|
|
46622
|
-
|
|
46655
|
+
if (!isRecord(raw)) {
|
|
46656
|
+
return [];
|
|
46657
|
+
}
|
|
46658
|
+
const outputItems = asArray(raw.output);
|
|
46659
|
+
for (const item of outputItems) {
|
|
46660
|
+
if (!isRecord(item)) continue;
|
|
46661
|
+
if (asString(item.type) !== "server_tool_result") continue;
|
|
46662
|
+
const itemOutput = asArray(item.output);
|
|
46663
|
+
for (const outPart of itemOutput) {
|
|
46664
|
+
if (!isRecord(outPart)) continue;
|
|
46665
|
+
if (asString(outPart.type) !== "server_tool_result_content")
|
|
46666
|
+
continue;
|
|
46667
|
+
const content = asString(outPart.content);
|
|
46668
|
+
if (!content) continue;
|
|
46669
|
+
try {
|
|
46670
|
+
const parsed = JSON.parse(content);
|
|
46671
|
+
const records = collectRecords(parsed);
|
|
46672
|
+
for (const record2 of records) {
|
|
46673
|
+
const url3 = asString(record2.url);
|
|
46674
|
+
if (url3) {
|
|
46675
|
+
candidates.push({
|
|
46676
|
+
url: url3,
|
|
46677
|
+
title: asString(record2.title)
|
|
46678
|
+
});
|
|
46679
|
+
}
|
|
46680
|
+
}
|
|
46681
|
+
} catch {
|
|
46682
|
+
}
|
|
46623
46683
|
}
|
|
46624
|
-
candidates.push({
|
|
46625
|
-
url: url3,
|
|
46626
|
-
title: asString(citation.title)
|
|
46627
|
-
});
|
|
46628
46684
|
}
|
|
46629
46685
|
return dedupeByKey(candidates, (citation) => citation.url);
|
|
46630
46686
|
}
|