Skip to content

Conversation

@dcs-soni
Copy link
Contributor

@dcs-soni dcs-soni commented Oct 22, 2025

Description

Handle malformed data URLs in Bedrock, Anthropic, Gemini, and Ollama adapters. Currently, they use unsafe array destructuring when parsing data URLs, causing runtime crashes on malformed input or unexpected results even if the parsed data is not correct base64.

Data URLs can be malformed due to various reasons, like, copy/paste from applications generating invalid URLs, user provided code containing malformed base64 URLs or maybe a network connection during image uploads.

This fix:

  • Prevents runtime crashes on malformed image data.
  • Improves error handling and user experience.
  • Improved response from the providers if the image URLs are malformed.

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • I've read the contributing guide
  • [] The relevant docs, if any, have been updated or created
  • [] The relevant tests, if any, have been updated or created

Screen recording or screenshot

[ When applicable, please include a short screen recording or screenshot - this makes it much easier for us as contributors to review and understand your changes. See this PR as a good example. ]

Tests

[ What tests were added or updated to ensure the changes work as expected? ]


Summary by cubic

Improved image data URL parsing across providers to prevent crashes on malformed inputs. Centralizes parsing in the openai-adapters package with safer base64 extraction and MIME type handling.

  • Bug Fixes

    • Replaced unsafe split logic with parseDataUrl and extractBase64FromDataUrl helpers.
    • Updated Anthropic, Bedrock, Gemini, and Ollama adapters to handle invalid/missing image data gracefully.
    • Return clear errors or skip images instead of crashing on malformed data URLs.
  • Refactors

    • Moved URL parsing helpers to openai-adapters and re-exported via core/util/url for shared use.

Written for commit 1c7668c. Summary will update automatically on new commits.

@dcs-soni dcs-soni requested a review from a team as a code owner October 22, 2025 07:10
@dcs-soni dcs-soni requested review from RomneyDa and removed request for a team October 22, 2025 07:10
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 22, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="core/llm/llms/Ollama.ts">

<violation number="1" location="core/llm/llms/Ollama.ts:308">
Calling extractBase64FromDataUrl here will throw on malformed data URLs and bubble up, regressing the previous behavior that tolerated bad input; wrap this in error handling or preserve the non-throwing fallback so malformed URLs don’t crash message conversion.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcs-soni looks like some tests are failing and see cubic feedback!

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Nov 3, 2025
@dcs-soni dcs-soni force-pushed the fix/improve-url-parsing branch from 92ee1ac to 64f3e12 Compare November 4, 2025 10:32
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Nov 4, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 19, 2025

import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { fromStatic } from "@aws-sdk/token-providers";
import { parseDataUrl } from "../../../../core/util/url.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcs-soni openai-adapters doesn't have access to core but core has openai-adapters, you could put the util in openai-adapters and pull it from there within core!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is what is causing the lint failures)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Fixed this. Thanks!

@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Nov 19, 2025
@dcs-soni dcs-soni force-pushed the fix/improve-url-parsing branch from d3c2caa to b4526bf Compare November 21, 2025 06:31
@dcs-soni dcs-soni requested a review from RomneyDa November 21, 2025 07:54
@dcs-soni
Copy link
Contributor Author

Phew! Had some trouble running Continue locally on Windows. Would send PRs to improve the local development experience if I find good fixes.

Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcs-soni appreciate the updates and contribution!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 21, 2025
@RomneyDa RomneyDa merged commit 9448bd8 into continuedev:main Nov 21, 2025
54 of 56 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Nov 21, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2025
@RomneyDa
Copy link
Collaborator

@dcs-soni there's definitely room for improvement for local development especially for onboarding contributors! Any improvements appreciated

@sestinj
Copy link
Contributor

sestinj commented Nov 25, 2025

🎉 This PR is included in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sestinj
Copy link
Contributor

sestinj commented Nov 26, 2025

🎉 This PR is included in version 1.36.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer released size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants