@ycodium-ai/agent-grok 0.2.4351 → 0.2.4368

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 +110 -16
  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 = 110;
11
+ var PLUGIN_API_VERSION = 112;
12
12
 
13
13
  // src/index.ts
14
14
  import {
@@ -28017,24 +28017,40 @@ function createExecutorUpdates({
28017
28017
  return;
28018
28018
  }
28019
28019
  };
28020
- const emitTaskEvents = (taskEvents) => {
28021
- for (const taskEvent of taskEvents ?? []) {
28020
+ const emitHookEvents = (hookEvents) => {
28021
+ for (const hookEvent of hookEvents ?? []) {
28022
+ if (hookEvent.type === "runtime.warning") {
28023
+ const message = hookEvent.payload.message.trim();
28024
+ if (message.length === 0) continue;
28025
+ emit({
28026
+ type: "runtime.warning",
28027
+ ...stamp(),
28028
+ provider: options.provider,
28029
+ threadId: options.threadId,
28030
+ ...hookEvent.turnId !== void 0 ? { turnId: hookEvent.turnId } : {},
28031
+ payload: {
28032
+ message,
28033
+ ...hookEvent.payload.detail !== void 0 ? { detail: hookEvent.payload.detail } : {}
28034
+ }
28035
+ });
28036
+ continue;
28037
+ }
28022
28038
  emit({
28023
- type: taskEvent.type,
28039
+ type: hookEvent.type,
28024
28040
  ...stamp(),
28025
28041
  provider: options.provider,
28026
28042
  threadId: options.threadId,
28027
- ...taskEvent.turnId !== void 0 ? { turnId: taskEvent.turnId } : {},
28028
- payload: taskEvent.payload
28043
+ ...hookEvent.turnId !== void 0 ? { turnId: hookEvent.turnId } : {},
28044
+ payload: hookEvent.payload
28029
28045
  });
28030
28046
  }
28031
28047
  };
28032
28048
  const toolSubagents = hooks.toolSubagents === void 0 ? void 0 : createToolSubagentTracker(hooks.toolSubagents);
28033
- const settleToolSubagents = (settlement, turnId) => emitTaskEvents(toolSubagents?.settle(settlement, turnId));
28049
+ const settleToolSubagents = (settlement, turnId) => emitHookEvents(toolSubagents?.settle(settlement, turnId));
28034
28050
  const settleSessionEnded = () => {
28035
28051
  settleToolSubagents("session-ended");
28036
- emitTaskEvents(subagentSessions?.settleSessionEnded());
28037
- emitTaskEvents(hooks.onSessionEnded?.());
28052
+ emitHookEvents(subagentSessions?.settleSessionEnded());
28053
+ emitHookEvents(hooks.onSessionEnded?.());
28038
28054
  };
28039
28055
  const observeContext = () => ({
28040
28056
  turnId: shared.activeTurnId,
@@ -28096,7 +28112,7 @@ function createExecutorUpdates({
28096
28112
  };
28097
28113
  const hookResult = call === void 0 ? void 0 : toolSubagents?.onToolCallUpdated(call) ?? hooks.onToolCallUpdated?.(call);
28098
28114
  const handledByHook = hookResult !== void 0 && "events" in hookResult && hookResult.handled === true;
28099
- emitTaskEvents(
28115
+ emitHookEvents(
28100
28116
  hookResult === void 0 ? [] : "events" in hookResult ? hookResult.events : hookResult
28101
28117
  );
28102
28118
  if (nextToolCall.status === "completed" && hookResult && "artifacts" in hookResult)
@@ -28193,7 +28209,7 @@ function createExecutorUpdates({
28193
28209
  };
28194
28210
  const receiveSessionUpdate = (params) => {
28195
28211
  const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
28196
- emitTaskEvents(
28212
+ emitHookEvents(
28197
28213
  subagentSessions?.observe(params, {
28198
28214
  turnId: shared.activeTurnId,
28199
28215
  foreign,
@@ -28203,7 +28219,7 @@ function createExecutorUpdates({
28203
28219
  );
28204
28220
  if (!shared.sessionLoadInFlight) {
28205
28221
  if (hooks.onSessionUpdate) {
28206
- emitTaskEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
28222
+ emitHookEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
28207
28223
  }
28208
28224
  }
28209
28225
  if (!foreign) handleSessionUpdate(params);
@@ -28211,7 +28227,7 @@ function createExecutorUpdates({
28211
28227
  const receiveExtensionNotification = (method, params) => {
28212
28228
  if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
28213
28229
  const result = hooks.onExtensionNotification(method, params, observeContext());
28214
- if (Array.isArray(result)) emitTaskEvents(result);
28230
+ if (Array.isArray(result)) emitHookEvents(result);
28215
28231
  };
28216
28232
  return {
28217
28233
  emitCompactionState,
@@ -29676,6 +29692,7 @@ var NOTIFICATION_METHODS = /* @__PURE__ */ new Set([
29676
29692
  "x.ai/session_notification",
29677
29693
  "x.ai/session/update"
29678
29694
  ]);
29695
+ var isGrokSessionNotification = (method) => NOTIFICATION_METHODS.has(method.startsWith("_") ? method.slice(1) : method);
29679
29696
  var record3 = (value) => isRecord10(value) ? value : {};
29680
29697
  var text3 = trimmed2;
29681
29698
  var count2 = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
@@ -29911,7 +29928,7 @@ function createGrokSubagents() {
29911
29928
  }
29912
29929
  };
29913
29930
  return {
29914
- onExtensionNotification: (method, params, ctx) => NOTIFICATION_METHODS.has(method.startsWith("_") ? method.slice(1) : method) ? fromEnvelope(params, ctx) : void 0,
29931
+ onExtensionNotification: (method, params, ctx) => isGrokSessionNotification(method) ? fromEnvelope(params, ctx) : void 0,
29915
29932
  onSessionUpdate: (notification, ctx) => ctx.foreign ? void 0 : fromEnvelope(notification, ctx),
29916
29933
  handlesToolCall: (input2) => {
29917
29934
  if (!spawnCalls.has(input2.toolCallId) && (record3(record3(input2.meta)["x.ai/tool"])["name"] === SPAWN_TOOL || record3(input2.rawInput)["variant"] === "Task")) {
@@ -29936,6 +29953,83 @@ function createGrokSubagents() {
29936
29953
  };
29937
29954
  }
29938
29955
 
29956
+ // src/grokRetryNotices.ts
29957
+ var GROK_RETRYING_CODE = "grok-retrying";
29958
+ var ERROR_TYPE_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
29959
+ var SEEN_EVENT_ID_LIMIT = 64;
29960
+ var RETRY_PHASE_ENDS = /* @__PURE__ */ new Set(["response_completed", "turn_completed"]);
29961
+ var positiveInteger = (value) => typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
29962
+ var retryMessage = (errorType, attempt, maxRetries) => {
29963
+ const cause = errorType === "rate_limited" ? "Grok is rate limited." : "Grok request failed temporarily.";
29964
+ return `${cause} Retrying (attempt ${attempt} of ${maxRetries})`;
29965
+ };
29966
+ function grokObservationHooks(subagents) {
29967
+ const retryNotices = createGrokRetryNotices();
29968
+ return {
29969
+ onExtensionNotification: (method, params, ctx) => [
29970
+ ...subagents.onExtensionNotification(method, params, ctx) ?? [],
29971
+ ...isGrokSessionNotification(method) ? retryNotices.observe(params, ctx) : []
29972
+ ],
29973
+ onSessionUpdate: (notification, ctx) => [
29974
+ ...subagents.onSessionUpdate(notification, ctx) ?? [],
29975
+ ...retryNotices.observe(notification, ctx)
29976
+ ]
29977
+ };
29978
+ }
29979
+ function createGrokRetryNotices() {
29980
+ const seenEventIds = /* @__PURE__ */ new Set();
29981
+ let phase;
29982
+ return {
29983
+ observe: (envelope, ctx) => {
29984
+ if (!isRecord10(envelope) || !isRecord10(envelope["update"])) return [];
29985
+ if (ctx.sessionId === void 0 || envelope["sessionId"] !== ctx.sessionId) return [];
29986
+ const update = envelope["update"];
29987
+ if (update["sessionUpdate"] !== "retry_state") {
29988
+ if (RETRY_PHASE_ENDS.has(update["sessionUpdate"])) phase = void 0;
29989
+ return [];
29990
+ }
29991
+ if (update["type"] !== "retrying") {
29992
+ phase = void 0;
29993
+ return [];
29994
+ }
29995
+ const meta3 = isRecord10(envelope["_meta"]) ? envelope["_meta"] : {};
29996
+ if (meta3["isReplay"] === true) return [];
29997
+ const turnId = ctx.turnId;
29998
+ if (turnId === void 0) return [];
29999
+ const attempt = positiveInteger(update["attempt"]);
30000
+ const maxRetries = positiveInteger(update["max_retries"]);
30001
+ if (attempt === void 0 || maxRetries === void 0 || attempt > maxRetries) return [];
30002
+ const eventId = typeof meta3["eventId"] === "string" && meta3["eventId"].length > 0 ? meta3["eventId"] : void 0;
30003
+ if (eventId !== void 0) {
30004
+ if (seenEventIds.has(eventId)) return [];
30005
+ seenEventIds.add(eventId);
30006
+ if (seenEventIds.size > SEEN_EVENT_ID_LIMIT) {
30007
+ seenEventIds.delete(seenEventIds.values().next().value);
30008
+ }
30009
+ } else if (phase?.turnId === turnId && phase.attempt === attempt) {
30010
+ return [];
30011
+ }
30012
+ phase = { turnId, attempt };
30013
+ const errorType = typeof update["error_type"] === "string" && ERROR_TYPE_PATTERN.test(update["error_type"]) ? update["error_type"] : void 0;
30014
+ return [
30015
+ {
30016
+ type: "runtime.warning",
30017
+ turnId,
30018
+ payload: {
30019
+ message: retryMessage(errorType, attempt, maxRetries),
30020
+ detail: {
30021
+ code: GROK_RETRYING_CODE,
30022
+ attempt,
30023
+ maxRetries,
30024
+ ...errorType === void 0 ? {} : { errorType }
30025
+ }
30026
+ }
30027
+ }
30028
+ ];
30029
+ }
30030
+ };
30031
+ }
30032
+
29939
30033
  // src/grokSupport.ts
29940
30034
  import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
29941
30035
  var GROK_NATIVE_MODE_BY_RUNTIME_MODE = {
@@ -30881,8 +30975,8 @@ var createGrokInstance = (config2, host) => {
30881
30975
  artifacts: grokImageArtifacts(update.rawOutput),
30882
30976
  ...subagents.handlesToolCall(update) ? { handled: true } : {}
30883
30977
  }),
30884
- onExtensionNotification: subagents.onExtensionNotification,
30885
- onSessionUpdate: subagents.onSessionUpdate,
30978
+ // 子 agent 名单与 CLI 自己重试(限流、容量不足)时的本轮提示。
30979
+ ...grokObservationHooks(subagents),
30886
30980
  onSessionEnded: subagents.onSessionEnded,
30887
30981
  onExtensionRequest: async (method, params, ctx) => {
30888
30982
  if (XAI_EXIT_PLAN_MODE_METHODS.includes(method)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-grok",
3
- "version": "0.2.4351",
3
+ "version": "0.2.4368",
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.4351",
24
+ "@ycodium-ai/plugin-api": "0.2.4368",
25
25
  "ycodium-executor-testing": "0.0.0",
26
- "ycodium-acp-executor": "0.2.4351"
26
+ "ycodium-acp-executor": "0.2.4368"
27
27
  },
28
28
  "ycodium": {
29
29
  "plugin": "./dist/index.js",