@mcowger/pi-plexus 1.3.6 → 1.3.7

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/extension.js +38 -0
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -515,6 +515,43 @@ function createGeminiToolCallIdFixer() {
515
515
  return { onContext, onBeforeProviderRequest };
516
516
  }
517
517
 
518
+ // src/gemini-malformed-retry.ts
519
+ var MALFORMED_LEAK_PATTERN = /(?:print\()?call:\s*default_api[.:]|default_api\.\w+\s*\(/;
520
+ var MALFORMED_DIAGNOSTIC_PATTERN = /\bmalformed[\s_-]?function[\s_-]?call\b/i;
521
+ var NORMALIZED_PREFIX = "MALFORMED_FUNCTION_CALL:";
522
+ var NORMALIZED_MESSAGE = `${NORMALIZED_PREFIX} Gemini emitted a malformed tool call (its internal ` + `function-call syntax leaked as text). This is a transient model failure \u2014 ` + `please retry your request.`;
523
+ function hasLeakedFunctionCall(content) {
524
+ if (!Array.isArray(content))
525
+ return false;
526
+ for (const block of content) {
527
+ if (block?.type === "text" && typeof block.text === "string" && MALFORMED_LEAK_PATTERN.test(block.text)) {
528
+ return true;
529
+ }
530
+ }
531
+ return false;
532
+ }
533
+ function hasToolCall(content) {
534
+ return Array.isArray(content) && content.some((block) => block?.type === "toolCall");
535
+ }
536
+ function normalizeMalformedFunctionCall(message, providerName) {
537
+ if (!message || message.role !== "assistant" || message.provider !== providerName || message.stopReason !== "error") {
538
+ return;
539
+ }
540
+ if (typeof message.errorMessage === "string" && message.errorMessage.startsWith(NORMALIZED_PREFIX)) {
541
+ return;
542
+ }
543
+ if (hasToolCall(message.content))
544
+ return;
545
+ const via = hasLeakedFunctionCall(message.content) ? "leak" : typeof message.errorMessage === "string" && MALFORMED_DIAGNOSTIC_PATTERN.test(message.errorMessage) ? "diagnostic" : undefined;
546
+ if (!via)
547
+ return;
548
+ log("gemini-malformed-retry: retagged MALFORMED_FUNCTION_CALL for retry", {
549
+ model: message.model,
550
+ via
551
+ });
552
+ return { message: { ...message, errorMessage: NORMALIZED_MESSAGE } };
553
+ }
554
+
518
555
  // src/extension.ts
519
556
  var PROVIDER_NAME = "plexus";
520
557
  var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
@@ -532,6 +569,7 @@ function plexusExtension(pi) {
532
569
  pi.on("before_provider_request", (event) => {
533
570
  return geminiToolCallIdFixer.onBeforeProviderRequest(event.payload);
534
571
  });
572
+ pi.on("message_end", (event) => normalizeMalformedFunctionCall(event.message, PROVIDER_NAME));
535
573
  pi.registerProvider(PROVIDER_NAME, {
536
574
  api: "openai-completions",
537
575
  ...envApiKey ? { apiKey: PROVIDER_API_KEY_TEMPLATE } : {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [