@mcowger/pi-plexus 1.3.4 → 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.
package/README.md CHANGED
@@ -13,6 +13,7 @@ Exposes models from a self-hosted [Plexus](https://github.com/mcowger/plexus) AI
13
13
  ## Prerequisites
14
14
 
15
15
  - A running Plexus instance
16
+ - pi 0.81.0 or later (for `plexus-pi`)
16
17
 
17
18
  ## Installation
18
19
 
package/dist/extension.js CHANGED
@@ -441,35 +441,103 @@ 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}";
447
521
  var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
448
522
  var PLACEHOLDER_BASE_URL = "http://localhost/v1";
449
523
  var currentModels = [];
450
- async function plexusExtension(pi) {
524
+ function plexusExtension(pi) {
451
525
  const envApiKey = getEnvApiKey();
452
526
  const startupBaseUrl = getBaseUrl();
453
- const modelsUrl = getModelsUrl();
454
527
  log("startup", { baseUrl: startupBaseUrl, hasEnvApiKey: !!envApiKey });
455
- let startupModels = [];
456
- if (envApiKey && modelsUrl && startupBaseUrl && process.env.PI_OFFLINE === undefined) {
457
- try {
458
- const { models: apiModels, raw } = await fetchPlexusModels(envApiKey, modelsUrl);
459
- startupModels = convertDescriptors(apiModels, startupBaseUrl).map(descriptorToPiModel);
460
- currentModels = startupModels;
461
- await writeRawResponse(raw);
462
- log("startup: fetched", { count: startupModels.length });
463
- } catch (error) {
464
- log("startup: fetch failed", { error: String(error) });
465
- }
466
- }
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
+ });
467
535
  pi.registerProvider(PROVIDER_NAME, {
468
536
  api: "openai-completions",
469
537
  ...envApiKey ? { apiKey: PROVIDER_API_KEY_TEMPLATE } : {},
470
538
  authHeader: true,
471
539
  baseUrl: startupBaseUrl ?? PLACEHOLDER_BASE_URL,
472
- models: startupModels,
540
+ models: [],
473
541
  refreshModels: refreshPlexusModels,
474
542
  oauth: createPlexusLoginProvider()
475
543
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [
@@ -25,12 +25,12 @@
25
25
  "build": "bun run build.ts"
26
26
  },
27
27
  "peerDependencies": {
28
- "@earendil-works/pi-ai": ">=0.80.8",
29
- "@earendil-works/pi-coding-agent": ">=0.80.8"
28
+ "@earendil-works/pi-ai": ">=0.81.0",
29
+ "@earendil-works/pi-coding-agent": ">=0.81.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@earendil-works/pi-ai": "^0.80.9",
33
- "@earendil-works/pi-coding-agent": "^0.80.9",
32
+ "@earendil-works/pi-ai": "^0.81.0",
33
+ "@earendil-works/pi-coding-agent": "^0.81.0",
34
34
  "@types/bun": "latest"
35
35
  },
36
36
  "repository": {