@ycodium-ai/agent-grok 0.2.5921 → 0.2.5939

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 +182 -2
  2. package/package.json +3 -3
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 = 187;
11
+ var PLUGIN_API_VERSION = 189;
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 title = next.title ?? previous?.title;
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;
@@ -31481,6 +31490,175 @@ var grokPermissionStatement = ({
31481
31490
  };
31482
31491
  };
31483
31492
 
31493
+ // src/grokMcpTools.ts
31494
+ import {
31495
+ canonicalMcpToolPair,
31496
+ MCP_IDENTIFIER_MAX_CHARS,
31497
+ orderedMcpServerNames
31498
+ } from "@ycodium-ai/plugin-api/executor";
31499
+ var MAX_TRACKED_CALLS = 256;
31500
+ var isRecord12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
31501
+ var isTerminalStatus = (status) => status === "completed" || status === "failed" || status === "cancelled" || status === "canceled";
31502
+ var callKey = (sessionId, toolCallId) => `${typeof sessionId === "string" ? sessionId : ""}\0${toolCallId}`;
31503
+ function splitGrokQualifiedName(rawName, servers) {
31504
+ if (typeof rawName !== "string") return void 0;
31505
+ const rawTrimmed = rawName.trim();
31506
+ if (rawTrimmed.length === 0 || rawTrimmed.length > MCP_IDENTIFIER_MAX_CHARS * 2 + 10) {
31507
+ return void 0;
31508
+ }
31509
+ const trimmed3 = rawTrimmed.startsWith("mcp__") && !servers.includes("mcp") ? rawTrimmed.slice("mcp__".length) : rawTrimmed;
31510
+ for (const server of servers) {
31511
+ const prefix = `${server}__`;
31512
+ if (!trimmed3.startsWith(prefix)) continue;
31513
+ const found = canonicalMcpToolPair(server, trimmed3.slice(prefix.length));
31514
+ if (found !== void 0) return found;
31515
+ }
31516
+ const sep = trimmed3.indexOf("__");
31517
+ if (sep <= 0 || sep + 2 >= trimmed3.length) return void 0;
31518
+ return canonicalMcpToolPair(trimmed3.slice(0, sep), trimmed3.slice(sep + 2));
31519
+ }
31520
+ function resolveFromRawOutput(rawOutput) {
31521
+ if (!isRecord12(rawOutput) || rawOutput["type"] !== "MCP") {
31522
+ return { mcp: void 0, text: void 0, isError: false };
31523
+ }
31524
+ const server = typeof rawOutput["server_name"] === "string" ? rawOutput["server_name"].trim() : "";
31525
+ const tool = typeof rawOutput["tool_name"] === "string" ? rawOutput["tool_name"].trim() : "";
31526
+ const mcp = canonicalMcpToolPair(server, tool);
31527
+ const output2 = isRecord12(rawOutput["output"]) ? rawOutput["output"] : void 0;
31528
+ if (typeof output2?.["OkayOutput"] === "string") {
31529
+ return { mcp, text: output2["OkayOutput"], isError: false };
31530
+ }
31531
+ if (typeof output2?.["ErrOutput"] === "string") {
31532
+ return { mcp, text: output2["ErrOutput"], isError: true };
31533
+ }
31534
+ return { mcp, text: void 0, isError: false };
31535
+ }
31536
+ function xaiToolKind(meta3) {
31537
+ if (!isRecord12(meta3)) return void 0;
31538
+ const xai = meta3["x.ai/tool"];
31539
+ if (!isRecord12(xai) || typeof xai["kind"] !== "string") return void 0;
31540
+ return xai["kind"].trim() || void 0;
31541
+ }
31542
+ function unwrapGrokUseToolRawInput(rawInput) {
31543
+ if (!isRecord12(rawInput)) return rawInput;
31544
+ if (isRecord12(rawInput["tool_input"])) return rawInput["tool_input"];
31545
+ return rawInput;
31546
+ }
31547
+ function createGrokMcpToolHooks(mcpServers) {
31548
+ const servers = orderedMcpServerNames((mcpServers ?? []).map((server) => server.name));
31549
+ const remembered = /* @__PURE__ */ new Map();
31550
+ const pendingApprovalOnly = /* @__PURE__ */ new Map();
31551
+ const remember = (key, value) => {
31552
+ remembered.delete(key);
31553
+ if (remembered.size >= MAX_TRACKED_CALLS) {
31554
+ const oldest = remembered.keys().next().value;
31555
+ if (oldest !== void 0) remembered.delete(oldest);
31556
+ }
31557
+ remembered.set(key, value);
31558
+ };
31559
+ return {
31560
+ transformSessionUpdate: (notification) => {
31561
+ const update = notification.update;
31562
+ const variant = update["sessionUpdate"];
31563
+ if (variant !== "tool_call" && variant !== "tool_call_update") {
31564
+ return notification;
31565
+ }
31566
+ const toolCallId = typeof update["toolCallId"] === "string" ? update["toolCallId"].trim() : "";
31567
+ const key = toolCallId ? callKey(notification.sessionId, toolCallId) : void 0;
31568
+ const isNew = variant === "tool_call";
31569
+ const terminal = isTerminalStatus(update["status"]);
31570
+ const kind = xaiToolKind(update["_meta"]);
31571
+ const fromOutput = resolveFromRawOutput(update["rawOutput"]);
31572
+ if (kind !== void 0 && kind !== "use_tool") {
31573
+ if (key !== void 0) remembered.delete(key);
31574
+ return {
31575
+ ...notification,
31576
+ update: {
31577
+ ...update,
31578
+ mcpServer: null,
31579
+ mcpTool: null
31580
+ }
31581
+ };
31582
+ }
31583
+ const rawInput = isRecord12(update["rawInput"]) ? update["rawInput"] : void 0;
31584
+ const fromInput = kind === "use_tool" ? splitGrokQualifiedName(rawInput?.["tool_name"] ?? update["title"], servers) : void 0;
31585
+ const inherited = !isNew && key !== void 0 ? remembered.get(key) : void 0;
31586
+ const resolved = fromInput ?? fromOutput.mcp ?? inherited;
31587
+ if (resolved === void 0) {
31588
+ if (terminal && key !== void 0) remembered.delete(key);
31589
+ return notification;
31590
+ }
31591
+ if (key !== void 0) {
31592
+ if (terminal) remembered.delete(key);
31593
+ else remember(key, resolved);
31594
+ }
31595
+ const unwrappedInput = unwrapGrokUseToolRawInput(update["rawInput"]);
31596
+ const nextContent = update["content"] === void 0 && fromOutput.text !== void 0 ? [{ type: "content", content: { type: "text", text: fromOutput.text } }] : update["content"];
31597
+ const nextRawOutput = fromOutput.text !== void 0 ? fromOutput.isError ? { isError: true, content: fromOutput.text } : fromOutput.text : update["rawOutput"];
31598
+ return {
31599
+ ...notification,
31600
+ update: {
31601
+ ...update,
31602
+ name: resolved.canonicalName,
31603
+ mcpServer: resolved.server,
31604
+ mcpTool: resolved.tool,
31605
+ title: resolved.canonicalName,
31606
+ ...unwrappedInput !== void 0 ? { rawInput: unwrappedInput } : {},
31607
+ ...nextContent !== void 0 ? { content: nextContent } : {},
31608
+ ...nextRawOutput !== void 0 ? { rawOutput: nextRawOutput } : {}
31609
+ }
31610
+ };
31611
+ },
31612
+ transformPermissionRequest: (params, context) => {
31613
+ if (!isRecord12(params) || !isRecord12(params["toolCall"])) return params;
31614
+ const toolCall = params["toolCall"];
31615
+ const toolCallId = typeof toolCall["toolCallId"] === "string" ? toolCall["toolCallId"].trim() : "";
31616
+ const key = toolCallId ? callKey(params["sessionId"], toolCallId) : void 0;
31617
+ const kind = xaiToolKind(toolCall["_meta"]);
31618
+ if (kind !== void 0 && kind !== "use_tool") {
31619
+ return {
31620
+ ...params,
31621
+ toolCall: {
31622
+ ...toolCall,
31623
+ mcpServer: null,
31624
+ mcpTool: null
31625
+ }
31626
+ };
31627
+ }
31628
+ const rawInput = isRecord12(toolCall["rawInput"]) ? toolCall["rawInput"] : void 0;
31629
+ const fromReq = kind === "use_tool" ? splitGrokQualifiedName(rawInput?.["tool_name"] ?? toolCall["title"], servers) : void 0;
31630
+ const existing = key !== void 0 ? remembered.get(key) : void 0;
31631
+ const resolved = fromReq ?? existing;
31632
+ if (resolved === void 0) return params;
31633
+ if (key !== void 0 && existing === void 0) {
31634
+ remember(key, resolved);
31635
+ if (context?.requestId !== void 0) {
31636
+ pendingApprovalOnly.set(context.requestId, key);
31637
+ }
31638
+ }
31639
+ return {
31640
+ ...params,
31641
+ toolCall: {
31642
+ ...toolCall,
31643
+ name: resolved.canonicalName,
31644
+ mcpServer: resolved.server,
31645
+ mcpTool: resolved.tool,
31646
+ title: resolved.canonicalName,
31647
+ ...toolCall["rawInput"] !== void 0 ? { rawInput: unwrapGrokUseToolRawInput(toolCall["rawInput"]) } : {}
31648
+ }
31649
+ };
31650
+ },
31651
+ onPermissionRequestSettled: ({ accepted, requestId }) => {
31652
+ if (requestId === void 0) return;
31653
+ const key = pendingApprovalOnly.get(requestId);
31654
+ pendingApprovalOnly.delete(requestId);
31655
+ if (!accepted && key !== void 0) {
31656
+ remembered.delete(key);
31657
+ }
31658
+ }
31659
+ };
31660
+ }
31661
+
31484
31662
  // src/nativeSessions.ts
31485
31663
  import * as NodeFS5 from "node:fs";
31486
31664
  import * as NodeFSP from "node:fs/promises";
@@ -31934,6 +32112,7 @@ var createGrokInstance = (config2, host) => {
31934
32112
  const backgroundTasks = /* @__PURE__ */ new Map();
31935
32113
  const subagents = createGrokSubagents();
31936
32114
  const turnUsage = createGrokTurnUsageCollector(grokPromptSettlement);
32115
+ const mcpToolHooks = createGrokMcpToolHooks(input2.mcpServers);
31937
32116
  const executor = createAcpExecutor({
31938
32117
  readable,
31939
32118
  writable,
@@ -31954,6 +32133,7 @@ var createGrokInstance = (config2, host) => {
31954
32133
  // 播报的 `authMethods` 说了算(见 resolveGrokAuthMethodId)。
31955
32134
  authMethodId: resolveGrokAuthMethodId,
31956
32135
  hooks: {
32136
+ ...mcpToolHooks,
31957
32137
  permissionStatement: grokPermissionStatement,
31958
32138
  promptSettlement: turnUsage.settlement,
31959
32139
  // 运行中再收到的 prompt 由 grok 自己排队、在下一个工具调用结束时并进这一轮(配合上面写的配置)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-grok",
3
- "version": "0.2.5921",
3
+ "version": "0.2.5939",
4
4
  "description": "Grok executor: grok CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,9 +21,9 @@
21
21
  "@types/node": "24.12.4",
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
- "@ycodium-ai/plugin-api": "0.2.5921",
25
- "ycodium-acp-executor": "0.2.5921",
24
+ "@ycodium-ai/plugin-api": "0.2.5939",
26
25
  "ycodium-credential-account": "0.0.0",
26
+ "ycodium-acp-executor": "0.2.5939",
27
27
  "ycodium-executor-testing": "0.0.0"
28
28
  },
29
29
  "ycodium": {