@mcowger/pi-plexus 1.3.5 → 1.3.6

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 +81 -0
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -441,6 +441,80 @@ function descriptorToPiModel(descriptor) {
441
441
  };
442
442
  }
443
443
 
444
+ // src/gemini-toolcall-id.ts
445
+ var GEMINI_3_PATTERN = /gemini-(?:live-)?3(?:\.\d+)?[-.]/i;
446
+ var GEMINI_3_ALIASES = new Set(["gemini-flash-latest", "gemini-flash-lite-latest"]);
447
+ function isGemini3Model(modelId) {
448
+ return GEMINI_3_ALIASES.has(modelId) || GEMINI_3_PATTERN.test(modelId);
449
+ }
450
+ function createGeminiToolCallIdFixer() {
451
+ let functionCallIds = [];
452
+ let functionResponseIds = [];
453
+ function onContext(messages) {
454
+ const calls = [];
455
+ const responses = [];
456
+ for (const msg of messages) {
457
+ if (msg.role === "assistant" && Array.isArray(msg.content)) {
458
+ for (const block of msg.content) {
459
+ if (block?.type === "toolCall" && typeof block.id === "string") {
460
+ calls.push(block.id);
461
+ }
462
+ }
463
+ } else if (msg.role === "toolResult" && typeof msg.toolCallId === "string") {
464
+ responses.push({ id: msg.toolCallId, name: msg.toolName ?? "" });
465
+ }
466
+ }
467
+ functionCallIds = calls;
468
+ functionResponseIds = responses;
469
+ }
470
+ function onBeforeProviderRequest(payload) {
471
+ const google = payload;
472
+ if (!google || typeof google !== "object" || !Array.isArray(google.contents)) {
473
+ return payload;
474
+ }
475
+ if (typeof google.model !== "string" || !isGemini3Model(google.model)) {
476
+ return payload;
477
+ }
478
+ let callCursor = 0;
479
+ let responseCursor = 0;
480
+ let missing = 0;
481
+ for (const content of google.contents) {
482
+ if (!Array.isArray(content?.parts))
483
+ continue;
484
+ for (const part of content.parts) {
485
+ if (part.functionCall && part.functionCall.id === undefined) {
486
+ const id = functionCallIds[callCursor++];
487
+ if (id !== undefined) {
488
+ part.functionCall.id = id;
489
+ } else {
490
+ missing++;
491
+ }
492
+ } else if (part.functionResponse && part.functionResponse.id === undefined) {
493
+ const entry = functionResponseIds[responseCursor++];
494
+ if (entry !== undefined) {
495
+ part.functionResponse.id = entry.id;
496
+ if (part.functionResponse.name === undefined && entry.name) {
497
+ part.functionResponse.name = entry.name;
498
+ }
499
+ } else {
500
+ missing++;
501
+ }
502
+ }
503
+ }
504
+ }
505
+ if (missing > 0) {
506
+ log("gemini-toolcall-id: fewer captured ids than parts", {
507
+ model: google.model,
508
+ missing,
509
+ capturedCalls: functionCallIds.length,
510
+ capturedResponses: functionResponseIds.length
511
+ });
512
+ }
513
+ return payload;
514
+ }
515
+ return { onContext, onBeforeProviderRequest };
516
+ }
517
+
444
518
  // src/extension.ts
445
519
  var PROVIDER_NAME = "plexus";
446
520
  var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
@@ -451,6 +525,13 @@ function plexusExtension(pi) {
451
525
  const envApiKey = getEnvApiKey();
452
526
  const startupBaseUrl = getBaseUrl();
453
527
  log("startup", { baseUrl: startupBaseUrl, hasEnvApiKey: !!envApiKey });
528
+ const geminiToolCallIdFixer = createGeminiToolCallIdFixer();
529
+ pi.on("context", (event) => {
530
+ geminiToolCallIdFixer.onContext(event.messages);
531
+ });
532
+ pi.on("before_provider_request", (event) => {
533
+ return geminiToolCallIdFixer.onBeforeProviderRequest(event.payload);
534
+ });
454
535
  pi.registerProvider(PROVIDER_NAME, {
455
536
  api: "openai-completions",
456
537
  ...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.5",
3
+ "version": "1.3.6",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [