@mcowger/pi-plexus 1.4.10 → 1.4.12
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/dist/extension.js +15 -4
- package/package.json +1 -1
package/dist/extension.js
CHANGED
|
@@ -50,7 +50,7 @@ function matchesPattern(id, name, shortId, pattern) {
|
|
|
50
50
|
}
|
|
51
51
|
// ../plexus-models/src/convert.ts
|
|
52
52
|
var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
|
|
53
|
-
var NON_CHAT_PATTERN = /(?:^|[\W_])(?:embed(?:ding|dings)?|transcri(?:be[ds]?|ptions?)|whisper|speech[\W_]*to[\W_]*text|stt|text[\W_]*to[\W_]*speech|tts|image[\W_]*(?:gen(?:eration)?|\d+)
|
|
53
|
+
var NON_CHAT_PATTERN = /(?:^|[\W_])(?:embed(?:ding|dings)?|transcri(?:be[ds]?|ptions?)|whisper|speech[\W_]*to[\W_]*text|stt|text[\W_]*to[\W_]*speech|tts|image(?:[\W_]*(?:gen(?:eration)?|\d+))?|diffusion|dall[\W_]*e|stable[\W_]*diffusion|sdxl|dream)(?:$|[\W_])/i;
|
|
54
54
|
var API_DIALECT_MAP = {
|
|
55
55
|
chat_completions: "openai-completions",
|
|
56
56
|
"openai-completions": "openai-completions",
|
|
@@ -174,15 +174,17 @@ function isChatModel(model) {
|
|
|
174
174
|
return false;
|
|
175
175
|
}
|
|
176
176
|
const outputModalities = model.architecture?.output_modalities;
|
|
177
|
-
if (outputModalities !== undefined &&
|
|
177
|
+
if (outputModalities !== undefined && (outputModalities.length === 0 || outputModalities.some((m) => m !== "text"))) {
|
|
178
178
|
return false;
|
|
179
|
+
}
|
|
179
180
|
const modality = model.architecture?.modality;
|
|
180
181
|
if (modality?.includes("->")) {
|
|
181
182
|
const input = modality.split("->")[0] ?? "";
|
|
182
183
|
if (!input.toLowerCase().includes("text"))
|
|
183
184
|
return false;
|
|
184
185
|
const output = modality.split("->").at(-1) ?? "";
|
|
185
|
-
|
|
186
|
+
const outputTokens = output.toLowerCase().split(/[+,]/).map((t) => t.trim()).filter((t) => t.length > 0);
|
|
187
|
+
if (outputTokens.length === 0 || outputTokens.some((t) => t !== "text"))
|
|
186
188
|
return false;
|
|
187
189
|
}
|
|
188
190
|
const apiHints = Array.isArray(model.preferred_api) ? model.preferred_api.join(" ") : model.preferred_api ?? "";
|
|
@@ -677,8 +679,11 @@ function descriptorToPiModel(descriptor) {
|
|
|
677
679
|
// src/gemini-malformed-retry.ts
|
|
678
680
|
var MALFORMED_LEAK_PATTERN = /(?:print\()?call:\s*default_api[.:]|default_api\.\w+\s*\(/;
|
|
679
681
|
var MALFORMED_DIAGNOSTIC_PATTERN = /\bmalformed[\s_-]?function[\s_-]?call\b/i;
|
|
682
|
+
var TRUNCATED_JSON_PATTERN = /\bUnexpected end of JSON input\b/i;
|
|
680
683
|
var NORMALIZED_PREFIX = "MALFORMED_FUNCTION_CALL:";
|
|
684
|
+
var TRUNCATED_JSON_PREFIX = "TRUNCATED_JSON_RESPONSE:";
|
|
681
685
|
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.`;
|
|
686
|
+
var TRUNCATED_JSON_MESSAGE = `${TRUNCATED_JSON_PREFIX} Unexpected end of JSON input. The upstream provider ` + `returned a truncated JSON response. This is a transient provider failure \u2014 ` + `please retry your request.`;
|
|
682
687
|
function hasLeakedFunctionCall(content) {
|
|
683
688
|
if (!Array.isArray(content))
|
|
684
689
|
return false;
|
|
@@ -696,11 +701,17 @@ function normalizeMalformedFunctionCall(message, providerName) {
|
|
|
696
701
|
if (!message || message.role !== "assistant" || message.provider !== providerName || message.stopReason !== "error") {
|
|
697
702
|
return;
|
|
698
703
|
}
|
|
699
|
-
if (typeof message.errorMessage === "string" && message.errorMessage.startsWith(NORMALIZED_PREFIX)) {
|
|
704
|
+
if (typeof message.errorMessage === "string" && (message.errorMessage.startsWith(NORMALIZED_PREFIX) || message.errorMessage.startsWith(TRUNCATED_JSON_PREFIX))) {
|
|
700
705
|
return;
|
|
701
706
|
}
|
|
702
707
|
if (hasToolCall(message.content))
|
|
703
708
|
return;
|
|
709
|
+
if (typeof message.errorMessage === "string" && TRUNCATED_JSON_PATTERN.test(message.errorMessage)) {
|
|
710
|
+
log("retryable-error: retagged truncated JSON response for retry", {
|
|
711
|
+
model: message.model
|
|
712
|
+
});
|
|
713
|
+
return { message: { ...message, errorMessage: TRUNCATED_JSON_MESSAGE } };
|
|
714
|
+
}
|
|
704
715
|
const via = hasLeakedFunctionCall(message.content) ? "leak" : typeof message.errorMessage === "string" && MALFORMED_DIAGNOSTIC_PATTERN.test(message.errorMessage) ? "diagnostic" : undefined;
|
|
705
716
|
if (!via)
|
|
706
717
|
return;
|