@vibe-lark/larkpal 0.1.81 → 0.1.82

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/main.mjs +30 -13
  2. package/package.json +1 -1
package/dist/main.mjs CHANGED
@@ -893,7 +893,7 @@ var CCStreamParser = class extends EventEmitter {
893
893
  displayName: getToolDisplayName(block.name),
894
894
  toolUseId: block.id
895
895
  });
896
- this.emit("toolUseStart", block.name, block.input ?? {});
896
+ this.emit("toolUseStart", block.name, block.input ?? {}, block.id);
897
897
  }
898
898
  break;
899
899
  }
@@ -941,7 +941,7 @@ var CCStreamParser = class extends EventEmitter {
941
941
  displayName: getToolDisplayName(block.name),
942
942
  toolUseId: block.id
943
943
  });
944
- this.emit("toolUseStart", block.name, block.input ?? {});
944
+ this.emit("toolUseStart", block.name, block.input ?? {}, block.id);
945
945
  }
946
946
  }
947
947
  this.emit("assistant", msg);
@@ -1756,8 +1756,8 @@ var SessionProcessManager = class {
1756
1756
  }
1757
1757
  getCallbacks()?.onThinkingDelta?.(text);
1758
1758
  });
1759
- parser.on("toolUseStart", (toolName, toolInput) => {
1760
- getCallbacks()?.onToolUseStart?.(toolName, toolInput);
1759
+ parser.on("toolUseStart", (toolName, toolInput, toolUseId) => {
1760
+ getCallbacks()?.onToolUseStart?.(toolName, toolInput, toolUseId);
1761
1761
  });
1762
1762
  parser.on("toolResult", (toolUseId, result) => {
1763
1763
  getCallbacks()?.onToolResult?.(toolUseId, result);
@@ -4778,6 +4778,14 @@ function normalizeRuntimeResult(result) {
4778
4778
  error
4779
4779
  };
4780
4780
  }
4781
+ function shouldTreatUnknownToolErrorAsRecovered(run, normalizedResult, result) {
4782
+ if (!normalizedResult.isError || normalizedResult.finalStatus !== "error_during_execution") return false;
4783
+ if (!run.unknownToolCallCount || run.lastToolError !== void 0) return false;
4784
+ if (!run.lastToolName || run.lastToolName === run.lastUnknownToolName) return false;
4785
+ const terminalText = normalizeWhitespace(result.result || "");
4786
+ if (terminalText && /\bNo such tool available\b/i.test(terminalText)) return false;
4787
+ return Boolean(run.text.trim() || terminalText);
4788
+ }
4781
4789
  function buildRuntimeErrorSummary(subtype, result) {
4782
4790
  const message = normalizeWhitespace(result || `Runtime execution failed: ${subtype}`);
4783
4791
  const httpStatus = extractHttpStatus(message);
@@ -4873,6 +4881,11 @@ function readBooleanField(value, key) {
4873
4881
  const field = value[key];
4874
4882
  return typeof field === "boolean" ? field : void 0;
4875
4883
  }
4884
+ function isUnknownToolResult(result) {
4885
+ const summary = readStringField(result, "resultSummary") ?? "";
4886
+ const content = readStringField(result, "content") ?? "";
4887
+ return /\bNo such tool available\b/i.test(`${summary}\n${content}`);
4888
+ }
4876
4889
  /**
4877
4890
  * 创建 Chat 流式对话 + 历史查询路由
4878
4891
  *
@@ -5193,10 +5206,11 @@ function createChatRouter(config) {
5193
5206
  recordRunEvent(run, "thinking-delta");
5194
5207
  broadcastRunEvent(run, "thinking-delta", { text });
5195
5208
  },
5196
- onToolUseStart: (toolName, toolInput) => {
5209
+ onToolUseStart: (toolName, toolInput, toolUseId) => {
5197
5210
  if (run.status !== "running") return;
5198
5211
  recordRunEvent(run, "tool-use-start", { toolName });
5199
5212
  if (runtimeConfig.requestContext) logChatAudit(buildAuditEvent(runtimeConfig.requestContext, "tool_call_started", {
5213
+ toolCallId: toolUseId,
5200
5214
  toolName,
5201
5215
  inputSummary: summarizeForAudit(toolInput)
5202
5216
  }));
@@ -5214,11 +5228,13 @@ function createChatRouter(config) {
5214
5228
  traceId,
5215
5229
  scenarioId,
5216
5230
  runtimeEventType: "tool-use-start",
5231
+ toolCallId: toolUseId,
5217
5232
  toolName
5218
5233
  }
5219
5234
  }, "[stream] 保存 tool 消息失败");
5220
5235
  broadcastRunEvent(run, "tool-use-start", {
5221
5236
  toolName,
5237
+ toolUseId,
5222
5238
  input: toolInput
5223
5239
  });
5224
5240
  },
@@ -5228,7 +5244,8 @@ function createChatRouter(config) {
5228
5244
  const resultSummary = summarizeForAudit(result);
5229
5245
  const toolName = readStringField(result, "toolName") || run.lastToolName;
5230
5246
  const isError = readBooleanField(result, "isError");
5231
- if (isError) run.lastToolError = resultSummary;
5247
+ if (isError && !isUnknownToolResult(result)) run.lastToolError = resultSummary;
5248
+ else if (!isError) run.lastToolError = void 0;
5232
5249
  if (runtimeConfig.requestContext) logChatAudit(buildAuditEvent(runtimeConfig.requestContext, "tool_call_finished", {
5233
5250
  toolCallId: toolUseId,
5234
5251
  toolName,
@@ -5266,12 +5283,6 @@ function createChatRouter(config) {
5266
5283
  if (run.status !== "running") return;
5267
5284
  run.unknownToolCallCount = (run.unknownToolCallCount ?? 0) + 1;
5268
5285
  run.lastUnknownToolName = toolName;
5269
- run.lastToolError = {
5270
- isError: true,
5271
- reasonCode: "UNKNOWN_TOOL_CALL",
5272
- toolName,
5273
- toolCallId: toolUseId
5274
- };
5275
5286
  recordRunEvent(run, "unknown-tool-use", { toolName });
5276
5287
  broadcastRunEvent(run, "runtime-event", {
5277
5288
  type: "unknown-tool-use",
@@ -5297,8 +5308,14 @@ function createChatRouter(config) {
5297
5308
  onResult: async (result) => {
5298
5309
  if (run.status !== "running") return;
5299
5310
  recordRunEvent(run, "result");
5300
- const normalizedResult = normalizeRuntimeResult(result);
5311
+ let normalizedResult = normalizeRuntimeResult(result);
5301
5312
  const partialText = run.text.trim() ? run.text : void 0;
5313
+ if (shouldTreatUnknownToolErrorAsRecovered(run, normalizedResult, result)) normalizedResult = {
5314
+ status: "completed",
5315
+ finalStatus: "completed_with_warnings",
5316
+ isError: false,
5317
+ finalText: partialText || result.result
5318
+ };
5302
5319
  const finalText = normalizedResult.isError ? normalizedResult.finalText || partialText || "" : partialText || normalizedResult.finalText || "";
5303
5320
  run.text = finalText;
5304
5321
  run.runtimeError = normalizedResult.error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-lark/larkpal",
3
- "version": "0.1.81",
3
+ "version": "0.1.82",
4
4
  "description": "LarkPal - Lark/Feishu bot service",
5
5
  "type": "module",
6
6
  "main": "./dist/main.mjs",