@jaypie/llm 1.2.12 → 1.2.13

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/esm/index.js CHANGED
@@ -2095,7 +2095,17 @@ class GeminiAdapter extends BaseProviderAdapter {
2095
2095
  return JSON.parse(textContent);
2096
2096
  }
2097
2097
  catch {
2098
- // If parsing fails, return the original string
2098
+ // Strip markdown code fences and retry (Gemini sometimes wraps JSON in fences)
2099
+ const jsonMatch = textContent.match(/```(?:json)?\s*([\s\S]*?)\s*```/) ||
2100
+ textContent.match(/\{[\s\S]*\}/);
2101
+ if (jsonMatch) {
2102
+ try {
2103
+ return JSON.parse(jsonMatch[1] || jsonMatch[0]);
2104
+ }
2105
+ catch {
2106
+ // Fall through to return original string
2107
+ }
2108
+ }
2099
2109
  return textContent;
2100
2110
  }
2101
2111
  }
@@ -5141,6 +5151,17 @@ class GeminiProvider {
5141
5151
  return JSON.parse(text);
5142
5152
  }
5143
5153
  catch {
5154
+ // Strip markdown code fences and retry (Gemini sometimes wraps JSON in fences)
5155
+ const jsonMatch = text.match(/```(?:json)?\s*([\s\S]*?)\s*```/) ||
5156
+ text.match(/\{[\s\S]*\}/);
5157
+ if (jsonMatch) {
5158
+ try {
5159
+ return JSON.parse(jsonMatch[1] || jsonMatch[0]);
5160
+ }
5161
+ catch {
5162
+ // Fall through to return original text
5163
+ }
5164
+ }
5144
5165
  return text || "";
5145
5166
  }
5146
5167
  }