@fre4x/grok 1.0.54 → 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 +153 -98
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -45932,72 +45932,94 @@ var {
|
|
|
45932
45932
|
var IS_MOCK = process.env.MOCK === "true" || process.env.GROK_MOCK === "true";
|
|
45933
45933
|
var MOCK_FIXTURES = {
|
|
45934
45934
|
grok_search_x: {
|
|
45935
|
-
|
|
45936
|
-
|
|
45935
|
+
id: "mock_resp_1",
|
|
45936
|
+
model: "grok-4-1-fast-reasoning",
|
|
45937
|
+
output: [
|
|
45937
45938
|
{
|
|
45938
|
-
|
|
45939
|
-
|
|
45940
|
-
|
|
45941
|
-
}
|
|
45942
|
-
|
|
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: [
|
|
45943
45948
|
{
|
|
45944
|
-
|
|
45945
|
-
|
|
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
|
+
})
|
|
45946
45968
|
}
|
|
45947
|
-
]
|
|
45948
|
-
|
|
45969
|
+
]
|
|
45970
|
+
},
|
|
45971
|
+
{
|
|
45972
|
+
type: "message",
|
|
45973
|
+
role: "assistant",
|
|
45974
|
+
content: [
|
|
45949
45975
|
{
|
|
45950
|
-
type: "
|
|
45951
|
-
|
|
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
|
-
]
|
|
45976
|
+
type: "output_text",
|
|
45977
|
+
text: "Recent posts discuss Grok MCP availability and positive early feedback."
|
|
45967
45978
|
}
|
|
45968
45979
|
]
|
|
45969
45980
|
}
|
|
45970
45981
|
]
|
|
45971
45982
|
},
|
|
45972
45983
|
grok_search_web: {
|
|
45973
|
-
|
|
45974
|
-
|
|
45984
|
+
id: "mock_resp_2",
|
|
45985
|
+
model: "grok-4-1-fast-reasoning",
|
|
45986
|
+
output: [
|
|
45975
45987
|
{
|
|
45976
|
-
|
|
45977
|
-
|
|
45978
|
-
|
|
45979
|
-
}
|
|
45980
|
-
|
|
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: [
|
|
45981
45997
|
{
|
|
45982
|
-
|
|
45983
|
-
|
|
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
|
+
})
|
|
45984
46013
|
}
|
|
45985
|
-
]
|
|
45986
|
-
|
|
46014
|
+
]
|
|
46015
|
+
},
|
|
46016
|
+
{
|
|
46017
|
+
type: "message",
|
|
46018
|
+
role: "assistant",
|
|
46019
|
+
content: [
|
|
45987
46020
|
{
|
|
45988
|
-
type: "
|
|
45989
|
-
|
|
45990
|
-
{
|
|
45991
|
-
title: "Model Context Protocol Documentation",
|
|
45992
|
-
url: "https://modelcontextprotocol.io",
|
|
45993
|
-
snippet: "MCP is an open standard that enables AI models to connect to external tools."
|
|
45994
|
-
},
|
|
45995
|
-
{
|
|
45996
|
-
title: "Tools - MCP Specification",
|
|
45997
|
-
url: "https://modelcontextprotocol.io/specification/draft/server/tools",
|
|
45998
|
-
snippet: "Servers expose tools through tools/list and tools/call with JSON Schema metadata."
|
|
45999
|
-
}
|
|
46000
|
-
]
|
|
46021
|
+
type: "output_text",
|
|
46022
|
+
text: "The MCP documentation is the primary reference and includes tool, resource, and prompt specs."
|
|
46001
46023
|
}
|
|
46002
46024
|
]
|
|
46003
46025
|
}
|
|
@@ -46040,6 +46062,9 @@ var MEDIA_FETCH_TIMEOUT_MS = Number.parseInt(
|
|
|
46040
46062
|
);
|
|
46041
46063
|
var MOCK_IMAGE_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
46042
46064
|
var MOCK_VIDEO_BASE64 = "AAAAHGZ0eXBpc29tAAAAAGlzb21pc28yYXZjMQ==";
|
|
46065
|
+
function getErrorMessage(error48) {
|
|
46066
|
+
return error48 instanceof Error ? error48.message : String(error48);
|
|
46067
|
+
}
|
|
46043
46068
|
var xSearchSchema = paginationSchema.extend({
|
|
46044
46069
|
query: z3.string().min(1).max(500),
|
|
46045
46070
|
allowed_handles: z3.array(z3.string().min(1).max(50)).max(10).optional(),
|
|
@@ -46135,11 +46160,10 @@ async function handleGrokSearchX(params, client = xaiClient) {
|
|
|
46135
46160
|
tools: [
|
|
46136
46161
|
{
|
|
46137
46162
|
type: "x_search",
|
|
46138
|
-
|
|
46139
|
-
|
|
46140
|
-
|
|
46141
|
-
|
|
46142
|
-
}
|
|
46163
|
+
query,
|
|
46164
|
+
allowed_x_handles: allowed_handles,
|
|
46165
|
+
from_date,
|
|
46166
|
+
to_date
|
|
46143
46167
|
}
|
|
46144
46168
|
]
|
|
46145
46169
|
});
|
|
@@ -46168,7 +46192,7 @@ async function handleGrokSearchX(params, client = xaiClient) {
|
|
|
46168
46192
|
} catch (error48) {
|
|
46169
46193
|
extraText = `
|
|
46170
46194
|
|
|
46171
|
-
\u26A0\uFE0F Failed to save results: ${error48
|
|
46195
|
+
\u26A0\uFE0F Failed to save results: ${getErrorMessage(error48)}`;
|
|
46172
46196
|
}
|
|
46173
46197
|
}
|
|
46174
46198
|
return toolResult(renderXSearch(output) + extraText, output);
|
|
@@ -46206,7 +46230,8 @@ async function handleGrokSearchWeb(params, client = xaiClient) {
|
|
|
46206
46230
|
tools: [
|
|
46207
46231
|
{
|
|
46208
46232
|
type: "web_search",
|
|
46209
|
-
|
|
46233
|
+
query,
|
|
46234
|
+
allowed_domains
|
|
46210
46235
|
}
|
|
46211
46236
|
]
|
|
46212
46237
|
});
|
|
@@ -46235,7 +46260,7 @@ async function handleGrokSearchWeb(params, client = xaiClient) {
|
|
|
46235
46260
|
} catch (error48) {
|
|
46236
46261
|
extraText = `
|
|
46237
46262
|
|
|
46238
|
-
\u26A0\uFE0F Failed to save results: ${error48
|
|
46263
|
+
\u26A0\uFE0F Failed to save results: ${getErrorMessage(error48)}`;
|
|
46239
46264
|
}
|
|
46240
46265
|
}
|
|
46241
46266
|
return toolResult(renderWebSearch(output) + extraText, output);
|
|
@@ -46290,7 +46315,7 @@ ${savedPaths.join("\n")}`;
|
|
|
46290
46315
|
} catch (error48) {
|
|
46291
46316
|
extraText = `
|
|
46292
46317
|
|
|
46293
|
-
\u26A0\uFE0F Failed to save images: ${error48
|
|
46318
|
+
\u26A0\uFE0F Failed to save images: ${getErrorMessage(error48)}`;
|
|
46294
46319
|
}
|
|
46295
46320
|
}
|
|
46296
46321
|
return toolResult(
|
|
@@ -46361,7 +46386,7 @@ async function handleGrokVideoStatus(params, client = xaiClient) {
|
|
|
46361
46386
|
} catch (error48) {
|
|
46362
46387
|
extraText = `
|
|
46363
46388
|
|
|
46364
|
-
\u26A0\uFE0F Failed to save video: ${error48
|
|
46389
|
+
\u26A0\uFE0F Failed to save video: ${getErrorMessage(error48)}`;
|
|
46365
46390
|
}
|
|
46366
46391
|
}
|
|
46367
46392
|
}
|
|
@@ -46551,18 +46576,6 @@ function buildMockVideoContent(videoUrl) {
|
|
|
46551
46576
|
buffer: Buffer.from(MOCK_VIDEO_BASE64, "base64")
|
|
46552
46577
|
};
|
|
46553
46578
|
}
|
|
46554
|
-
function extractNestedText(value) {
|
|
46555
|
-
if (typeof value === "string") {
|
|
46556
|
-
return value.trim() ? [value.trim()] : [];
|
|
46557
|
-
}
|
|
46558
|
-
if (Array.isArray(value)) {
|
|
46559
|
-
return value.flatMap((item) => extractNestedText(item));
|
|
46560
|
-
}
|
|
46561
|
-
if (isRecord(value)) {
|
|
46562
|
-
return Object.values(value).flatMap((item) => extractNestedText(item));
|
|
46563
|
-
}
|
|
46564
|
-
return [];
|
|
46565
|
-
}
|
|
46566
46579
|
function dedupeByKey(items, keyFn) {
|
|
46567
46580
|
const seen = /* @__PURE__ */ new Set();
|
|
46568
46581
|
const result = [];
|
|
@@ -46592,40 +46605,82 @@ function getResponseSummary(raw) {
|
|
|
46592
46605
|
if (!isRecord(raw)) {
|
|
46593
46606
|
return "";
|
|
46594
46607
|
}
|
|
46595
|
-
const
|
|
46596
|
-
|
|
46597
|
-
|
|
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
|
+
}
|
|
46598
46623
|
}
|
|
46599
|
-
|
|
46600
|
-
return choiceMessages.join("\n").trim();
|
|
46624
|
+
return summaries.join("\n").trim();
|
|
46601
46625
|
}
|
|
46602
|
-
function getToolOutputs(raw,
|
|
46626
|
+
function getToolOutputs(raw, _toolType) {
|
|
46603
46627
|
if (!isRecord(raw)) {
|
|
46604
46628
|
return [];
|
|
46605
46629
|
}
|
|
46606
|
-
const
|
|
46607
|
-
|
|
46608
|
-
|
|
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
|
+
}
|
|
46609
46649
|
}
|
|
46610
|
-
|
|
46611
|
-
|
|
46612
|
-
return [...choiceToolCalls, ...messageToolCalls];
|
|
46613
|
-
});
|
|
46614
|
-
return toolCalls.filter(
|
|
46615
|
-
(call) => isRecord(call) && asString(call.type) === toolType && Array.isArray(call.outputs)
|
|
46616
|
-
).flatMap((call) => asArray(call.outputs));
|
|
46650
|
+
}
|
|
46651
|
+
return results;
|
|
46617
46652
|
}
|
|
46618
46653
|
function getCitations(raw) {
|
|
46619
46654
|
const candidates = [];
|
|
46620
|
-
|
|
46621
|
-
|
|
46622
|
-
|
|
46623
|
-
|
|
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
|
+
}
|
|
46624
46683
|
}
|
|
46625
|
-
candidates.push({
|
|
46626
|
-
url: url3,
|
|
46627
|
-
title: asString(citation.title)
|
|
46628
|
-
});
|
|
46629
46684
|
}
|
|
46630
46685
|
return dedupeByKey(candidates, (citation) => citation.url);
|
|
46631
46686
|
}
|