@ycodium-ai/agent-grok 0.2.5921 → 0.2.5971
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 +193 -8
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
9
9
|
|
|
10
10
|
// ../../packages/plugin-api/src/version.ts
|
|
11
|
-
var PLUGIN_API_VERSION =
|
|
11
|
+
var PLUGIN_API_VERSION = 191;
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
14
|
import { registerEffectiveHomeCommand } from "@ycodium-ai/plugin-api/instance-config";
|
|
@@ -885,6 +885,7 @@ function canonicalItemTypeFromAcpToolKind(kind) {
|
|
|
885
885
|
|
|
886
886
|
// ../../packages/ycodium-acp-executor/src/tool-call-state.ts
|
|
887
887
|
var clearedIdentityFields = /* @__PURE__ */ new WeakMap();
|
|
888
|
+
var fallbackTitleStates = /* @__PURE__ */ new WeakSet();
|
|
888
889
|
function readToolCallIdentityFields(state, options) {
|
|
889
890
|
const cleared = clearedIdentityFields.get(state);
|
|
890
891
|
return {
|
|
@@ -1089,6 +1090,9 @@ function makeToolCallState(input2, options) {
|
|
|
1089
1090
|
...textContent ? { contentText: textContent } : {},
|
|
1090
1091
|
data
|
|
1091
1092
|
};
|
|
1093
|
+
if (title === void 0 && presentation?.summary === "Tool") {
|
|
1094
|
+
fallbackTitleStates.add(state);
|
|
1095
|
+
}
|
|
1092
1096
|
if (input2.name === null || input2.mcpServer === null || input2.mcpTool === null || negativeMcp || explicitPositiveMcp) {
|
|
1093
1097
|
clearedIdentityFields.set(state, {
|
|
1094
1098
|
...input2.name === null ? { name: null } : {},
|
|
@@ -1131,11 +1135,13 @@ function mergeToolCallState(previous, next) {
|
|
|
1131
1135
|
const replaced = { ...next, status: status2 };
|
|
1132
1136
|
const nextCleared2 = clearedIdentityFields.get(next);
|
|
1133
1137
|
if (nextCleared2 !== void 0) clearedIdentityFields.set(replaced, nextCleared2);
|
|
1138
|
+
if (fallbackTitleStates.has(next)) fallbackTitleStates.add(replaced);
|
|
1134
1139
|
return replaced;
|
|
1135
1140
|
}
|
|
1136
1141
|
const nextKind = typeof next.data["kind"] === "string" ? next.data["kind"] : void 0;
|
|
1137
1142
|
const kind = nextKind ?? previous?.kind;
|
|
1138
|
-
const
|
|
1143
|
+
const nextIsFallbackTitle = fallbackTitleStates.has(next);
|
|
1144
|
+
const title = nextIsFallbackTitle ? previous?.title ?? next.title : next.title ?? previous?.title;
|
|
1139
1145
|
const status = next.status ?? previous?.status;
|
|
1140
1146
|
const command = next.command ?? previous?.command;
|
|
1141
1147
|
const detail = next.detail ?? previous?.detail;
|
|
@@ -1169,6 +1175,9 @@ function mergeToolCallState(previous, next) {
|
|
|
1169
1175
|
} else if (nextPositiveMcp || prevCleared?.positiveMcp === true) {
|
|
1170
1176
|
clearedIdentityFields.set(merged, { positiveMcp: true });
|
|
1171
1177
|
}
|
|
1178
|
+
if (title === "Tool" && nextIsFallbackTitle && (previous === void 0 || fallbackTitleStates.has(previous))) {
|
|
1179
|
+
fallbackTitleStates.add(merged);
|
|
1180
|
+
}
|
|
1172
1181
|
return merged;
|
|
1173
1182
|
}
|
|
1174
1183
|
var TOOL_CALL_UPDATE_MIN_DETAIL_GROWTH_CHARS = 256;
|
|
@@ -29457,6 +29466,16 @@ function createAcpThreadOperations(options) {
|
|
|
29457
29466
|
};
|
|
29458
29467
|
}
|
|
29459
29468
|
|
|
29469
|
+
// ../../packages/ycodium-executor-common/src/redactDiagnostic.ts
|
|
29470
|
+
var PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi;
|
|
29471
|
+
var BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;
|
|
29472
|
+
var BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;
|
|
29473
|
+
var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
29474
|
+
var SECRET_TOKEN_PATTERN = /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;
|
|
29475
|
+
function redactDiagnostic(text4) {
|
|
29476
|
+
return text4.replace(PAIRING_URL_PATTERN, "[pairing-url]").replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]").replace(BASIC_AUTH_PATTERN, "Authorization: Basic [redacted]").replace(API_KEY_HEADER_PATTERN, "x-api-key: [redacted]").replace(SECRET_TOKEN_PATTERN, "[redacted]").trim();
|
|
29477
|
+
}
|
|
29478
|
+
|
|
29460
29479
|
// ../../packages/ycodium-executor-common/src/nodeStreams.ts
|
|
29461
29480
|
import * as NodeOS3 from "node:os";
|
|
29462
29481
|
import * as NodeStream2 from "node:stream";
|
|
@@ -29519,11 +29538,6 @@ function nodeWritableFromHandle(handle, errors = ownErrors) {
|
|
|
29519
29538
|
}
|
|
29520
29539
|
var STDERR_TAIL_MAX_CHARS = 4096;
|
|
29521
29540
|
var STDERR_SETTLE_MS = 500;
|
|
29522
|
-
var PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi;
|
|
29523
|
-
var BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;
|
|
29524
|
-
var BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;
|
|
29525
|
-
var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
29526
|
-
var SECRET_TOKEN_PATTERN = /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;
|
|
29527
29541
|
function redactStderrExcerpt(text4, environment = process.env) {
|
|
29528
29542
|
let result = text4.replaceAll("\0", "");
|
|
29529
29543
|
const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS3.homedir()].filter(
|
|
@@ -29532,7 +29546,7 @@ function redactStderrExcerpt(text4, environment = process.env) {
|
|
|
29532
29546
|
for (const home of new Set(homes)) {
|
|
29533
29547
|
result = result.split(home).join("~");
|
|
29534
29548
|
}
|
|
29535
|
-
return result
|
|
29549
|
+
return redactDiagnostic(result);
|
|
29536
29550
|
}
|
|
29537
29551
|
function drainStderrTail(stderr) {
|
|
29538
29552
|
let tail = "";
|
|
@@ -31481,6 +31495,175 @@ var grokPermissionStatement = ({
|
|
|
31481
31495
|
};
|
|
31482
31496
|
};
|
|
31483
31497
|
|
|
31498
|
+
// src/grokMcpTools.ts
|
|
31499
|
+
import {
|
|
31500
|
+
canonicalMcpToolPair,
|
|
31501
|
+
MCP_IDENTIFIER_MAX_CHARS,
|
|
31502
|
+
orderedMcpServerNames
|
|
31503
|
+
} from "@ycodium-ai/plugin-api/executor";
|
|
31504
|
+
var MAX_TRACKED_CALLS = 256;
|
|
31505
|
+
var isRecord12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31506
|
+
var isTerminalStatus = (status) => status === "completed" || status === "failed" || status === "cancelled" || status === "canceled";
|
|
31507
|
+
var callKey = (sessionId, toolCallId) => `${typeof sessionId === "string" ? sessionId : ""}\0${toolCallId}`;
|
|
31508
|
+
function splitGrokQualifiedName(rawName, servers) {
|
|
31509
|
+
if (typeof rawName !== "string") return void 0;
|
|
31510
|
+
const rawTrimmed = rawName.trim();
|
|
31511
|
+
if (rawTrimmed.length === 0 || rawTrimmed.length > MCP_IDENTIFIER_MAX_CHARS * 2 + 10) {
|
|
31512
|
+
return void 0;
|
|
31513
|
+
}
|
|
31514
|
+
const trimmed3 = rawTrimmed.startsWith("mcp__") && !servers.includes("mcp") ? rawTrimmed.slice("mcp__".length) : rawTrimmed;
|
|
31515
|
+
for (const server of servers) {
|
|
31516
|
+
const prefix = `${server}__`;
|
|
31517
|
+
if (!trimmed3.startsWith(prefix)) continue;
|
|
31518
|
+
const found = canonicalMcpToolPair(server, trimmed3.slice(prefix.length));
|
|
31519
|
+
if (found !== void 0) return found;
|
|
31520
|
+
}
|
|
31521
|
+
const sep = trimmed3.indexOf("__");
|
|
31522
|
+
if (sep <= 0 || sep + 2 >= trimmed3.length) return void 0;
|
|
31523
|
+
return canonicalMcpToolPair(trimmed3.slice(0, sep), trimmed3.slice(sep + 2));
|
|
31524
|
+
}
|
|
31525
|
+
function resolveFromRawOutput(rawOutput) {
|
|
31526
|
+
if (!isRecord12(rawOutput) || rawOutput["type"] !== "MCP") {
|
|
31527
|
+
return { mcp: void 0, text: void 0, isError: false };
|
|
31528
|
+
}
|
|
31529
|
+
const server = typeof rawOutput["server_name"] === "string" ? rawOutput["server_name"].trim() : "";
|
|
31530
|
+
const tool = typeof rawOutput["tool_name"] === "string" ? rawOutput["tool_name"].trim() : "";
|
|
31531
|
+
const mcp = canonicalMcpToolPair(server, tool);
|
|
31532
|
+
const output2 = isRecord12(rawOutput["output"]) ? rawOutput["output"] : void 0;
|
|
31533
|
+
if (typeof output2?.["OkayOutput"] === "string") {
|
|
31534
|
+
return { mcp, text: output2["OkayOutput"], isError: false };
|
|
31535
|
+
}
|
|
31536
|
+
if (typeof output2?.["ErrOutput"] === "string") {
|
|
31537
|
+
return { mcp, text: output2["ErrOutput"], isError: true };
|
|
31538
|
+
}
|
|
31539
|
+
return { mcp, text: void 0, isError: false };
|
|
31540
|
+
}
|
|
31541
|
+
function xaiToolKind(meta3) {
|
|
31542
|
+
if (!isRecord12(meta3)) return void 0;
|
|
31543
|
+
const xai = meta3["x.ai/tool"];
|
|
31544
|
+
if (!isRecord12(xai) || typeof xai["kind"] !== "string") return void 0;
|
|
31545
|
+
return xai["kind"].trim() || void 0;
|
|
31546
|
+
}
|
|
31547
|
+
function unwrapGrokUseToolRawInput(rawInput) {
|
|
31548
|
+
if (!isRecord12(rawInput)) return rawInput;
|
|
31549
|
+
if (isRecord12(rawInput["tool_input"])) return rawInput["tool_input"];
|
|
31550
|
+
return rawInput;
|
|
31551
|
+
}
|
|
31552
|
+
function createGrokMcpToolHooks(mcpServers) {
|
|
31553
|
+
const servers = orderedMcpServerNames((mcpServers ?? []).map((server) => server.name));
|
|
31554
|
+
const remembered = /* @__PURE__ */ new Map();
|
|
31555
|
+
const pendingApprovalOnly = /* @__PURE__ */ new Map();
|
|
31556
|
+
const remember = (key, value) => {
|
|
31557
|
+
remembered.delete(key);
|
|
31558
|
+
if (remembered.size >= MAX_TRACKED_CALLS) {
|
|
31559
|
+
const oldest = remembered.keys().next().value;
|
|
31560
|
+
if (oldest !== void 0) remembered.delete(oldest);
|
|
31561
|
+
}
|
|
31562
|
+
remembered.set(key, value);
|
|
31563
|
+
};
|
|
31564
|
+
return {
|
|
31565
|
+
transformSessionUpdate: (notification) => {
|
|
31566
|
+
const update = notification.update;
|
|
31567
|
+
const variant = update["sessionUpdate"];
|
|
31568
|
+
if (variant !== "tool_call" && variant !== "tool_call_update") {
|
|
31569
|
+
return notification;
|
|
31570
|
+
}
|
|
31571
|
+
const toolCallId = typeof update["toolCallId"] === "string" ? update["toolCallId"].trim() : "";
|
|
31572
|
+
const key = toolCallId ? callKey(notification.sessionId, toolCallId) : void 0;
|
|
31573
|
+
const isNew = variant === "tool_call";
|
|
31574
|
+
const terminal = isTerminalStatus(update["status"]);
|
|
31575
|
+
const kind = xaiToolKind(update["_meta"]);
|
|
31576
|
+
const fromOutput = resolveFromRawOutput(update["rawOutput"]);
|
|
31577
|
+
if (kind !== void 0 && kind !== "use_tool") {
|
|
31578
|
+
if (key !== void 0) remembered.delete(key);
|
|
31579
|
+
return {
|
|
31580
|
+
...notification,
|
|
31581
|
+
update: {
|
|
31582
|
+
...update,
|
|
31583
|
+
mcpServer: null,
|
|
31584
|
+
mcpTool: null
|
|
31585
|
+
}
|
|
31586
|
+
};
|
|
31587
|
+
}
|
|
31588
|
+
const rawInput = isRecord12(update["rawInput"]) ? update["rawInput"] : void 0;
|
|
31589
|
+
const fromInput = kind === "use_tool" ? splitGrokQualifiedName(rawInput?.["tool_name"] ?? update["title"], servers) : void 0;
|
|
31590
|
+
const inherited = !isNew && key !== void 0 ? remembered.get(key) : void 0;
|
|
31591
|
+
const resolved = fromInput ?? fromOutput.mcp ?? inherited;
|
|
31592
|
+
if (resolved === void 0) {
|
|
31593
|
+
if (terminal && key !== void 0) remembered.delete(key);
|
|
31594
|
+
return notification;
|
|
31595
|
+
}
|
|
31596
|
+
if (key !== void 0) {
|
|
31597
|
+
if (terminal) remembered.delete(key);
|
|
31598
|
+
else remember(key, resolved);
|
|
31599
|
+
}
|
|
31600
|
+
const unwrappedInput = unwrapGrokUseToolRawInput(update["rawInput"]);
|
|
31601
|
+
const nextContent = update["content"] === void 0 && fromOutput.text !== void 0 ? [{ type: "content", content: { type: "text", text: fromOutput.text } }] : update["content"];
|
|
31602
|
+
const nextRawOutput = fromOutput.text !== void 0 ? fromOutput.isError ? { isError: true, content: fromOutput.text } : fromOutput.text : update["rawOutput"];
|
|
31603
|
+
return {
|
|
31604
|
+
...notification,
|
|
31605
|
+
update: {
|
|
31606
|
+
...update,
|
|
31607
|
+
name: resolved.canonicalName,
|
|
31608
|
+
mcpServer: resolved.server,
|
|
31609
|
+
mcpTool: resolved.tool,
|
|
31610
|
+
title: resolved.canonicalName,
|
|
31611
|
+
...unwrappedInput !== void 0 ? { rawInput: unwrappedInput } : {},
|
|
31612
|
+
...nextContent !== void 0 ? { content: nextContent } : {},
|
|
31613
|
+
...nextRawOutput !== void 0 ? { rawOutput: nextRawOutput } : {}
|
|
31614
|
+
}
|
|
31615
|
+
};
|
|
31616
|
+
},
|
|
31617
|
+
transformPermissionRequest: (params, context) => {
|
|
31618
|
+
if (!isRecord12(params) || !isRecord12(params["toolCall"])) return params;
|
|
31619
|
+
const toolCall = params["toolCall"];
|
|
31620
|
+
const toolCallId = typeof toolCall["toolCallId"] === "string" ? toolCall["toolCallId"].trim() : "";
|
|
31621
|
+
const key = toolCallId ? callKey(params["sessionId"], toolCallId) : void 0;
|
|
31622
|
+
const kind = xaiToolKind(toolCall["_meta"]);
|
|
31623
|
+
if (kind !== void 0 && kind !== "use_tool") {
|
|
31624
|
+
return {
|
|
31625
|
+
...params,
|
|
31626
|
+
toolCall: {
|
|
31627
|
+
...toolCall,
|
|
31628
|
+
mcpServer: null,
|
|
31629
|
+
mcpTool: null
|
|
31630
|
+
}
|
|
31631
|
+
};
|
|
31632
|
+
}
|
|
31633
|
+
const rawInput = isRecord12(toolCall["rawInput"]) ? toolCall["rawInput"] : void 0;
|
|
31634
|
+
const fromReq = kind === "use_tool" ? splitGrokQualifiedName(rawInput?.["tool_name"] ?? toolCall["title"], servers) : void 0;
|
|
31635
|
+
const existing = key !== void 0 ? remembered.get(key) : void 0;
|
|
31636
|
+
const resolved = fromReq ?? existing;
|
|
31637
|
+
if (resolved === void 0) return params;
|
|
31638
|
+
if (key !== void 0 && existing === void 0) {
|
|
31639
|
+
remember(key, resolved);
|
|
31640
|
+
if (context?.requestId !== void 0) {
|
|
31641
|
+
pendingApprovalOnly.set(context.requestId, key);
|
|
31642
|
+
}
|
|
31643
|
+
}
|
|
31644
|
+
return {
|
|
31645
|
+
...params,
|
|
31646
|
+
toolCall: {
|
|
31647
|
+
...toolCall,
|
|
31648
|
+
name: resolved.canonicalName,
|
|
31649
|
+
mcpServer: resolved.server,
|
|
31650
|
+
mcpTool: resolved.tool,
|
|
31651
|
+
title: resolved.canonicalName,
|
|
31652
|
+
...toolCall["rawInput"] !== void 0 ? { rawInput: unwrapGrokUseToolRawInput(toolCall["rawInput"]) } : {}
|
|
31653
|
+
}
|
|
31654
|
+
};
|
|
31655
|
+
},
|
|
31656
|
+
onPermissionRequestSettled: ({ accepted, requestId }) => {
|
|
31657
|
+
if (requestId === void 0) return;
|
|
31658
|
+
const key = pendingApprovalOnly.get(requestId);
|
|
31659
|
+
pendingApprovalOnly.delete(requestId);
|
|
31660
|
+
if (!accepted && key !== void 0) {
|
|
31661
|
+
remembered.delete(key);
|
|
31662
|
+
}
|
|
31663
|
+
}
|
|
31664
|
+
};
|
|
31665
|
+
}
|
|
31666
|
+
|
|
31484
31667
|
// src/nativeSessions.ts
|
|
31485
31668
|
import * as NodeFS5 from "node:fs";
|
|
31486
31669
|
import * as NodeFSP from "node:fs/promises";
|
|
@@ -31934,6 +32117,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
31934
32117
|
const backgroundTasks = /* @__PURE__ */ new Map();
|
|
31935
32118
|
const subagents = createGrokSubagents();
|
|
31936
32119
|
const turnUsage = createGrokTurnUsageCollector(grokPromptSettlement);
|
|
32120
|
+
const mcpToolHooks = createGrokMcpToolHooks(input2.mcpServers);
|
|
31937
32121
|
const executor = createAcpExecutor({
|
|
31938
32122
|
readable,
|
|
31939
32123
|
writable,
|
|
@@ -31954,6 +32138,7 @@ var createGrokInstance = (config2, host) => {
|
|
|
31954
32138
|
// 播报的 `authMethods` 说了算(见 resolveGrokAuthMethodId)。
|
|
31955
32139
|
authMethodId: resolveGrokAuthMethodId,
|
|
31956
32140
|
hooks: {
|
|
32141
|
+
...mcpToolHooks,
|
|
31957
32142
|
permissionStatement: grokPermissionStatement,
|
|
31958
32143
|
promptSettlement: turnUsage.settlement,
|
|
31959
32144
|
// 运行中再收到的 prompt 由 grok 自己排队、在下一个工具调用结束时并进这一轮(配合上面写的配置)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-grok",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5971",
|
|
4
4
|
"description": "Grok executor: grok CLI over Agent Client Protocol stdio.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"@types/node": "24.12.4",
|
|
22
22
|
"esbuild": "0.28.1",
|
|
23
23
|
"vite-plus": "0.2.2",
|
|
24
|
-
"
|
|
25
|
-
"ycodium-
|
|
26
|
-
"ycodium-
|
|
27
|
-
"ycodium-
|
|
24
|
+
"ycodium-executor-testing": "0.0.0",
|
|
25
|
+
"@ycodium-ai/plugin-api": "0.2.5971",
|
|
26
|
+
"ycodium-acp-executor": "0.2.5971",
|
|
27
|
+
"ycodium-credential-account": "0.0.0"
|
|
28
28
|
},
|
|
29
29
|
"ycodium": {
|
|
30
30
|
"plugin": "./dist/index.js",
|