Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

fix(selection): retain notice on provider errors

Emre Sokullu81f9e51278aa
diff --git a/src/chrome/src/background.js b/src/chrome/src/background.js
index 8610cecd0..938d5ff72 100644
--- a/src/chrome/src/background.js
+++ b/src/chrome/src/background.js
@@ -1835,7 +1835,8 @@ async function answerInlineSelection(msg) {
...(notice ? { notice } : {}),
};
}
- return { ok: false, error: String(error?.message || error).slice(0, 300) };
+ const notice = inlineCostNotice(error);
+ return { ok: false, error: String(error?.message || error).slice(0, 300), ...(notice ? { notice } : {}) };
} finally {
clearTimeout(timer);
if (jobId && inlineSelectionJobs.get(jobId) === controller) inlineSelectionJobs.delete(jobId);
diff --git a/src/firefox/src/background.js b/src/firefox/src/background.js
index b701cb7b0..89e42202b 100644
--- a/src/firefox/src/background.js
+++ b/src/firefox/src/background.js
@@ -1586,7 +1586,8 @@ async function answerInlineSelection(msg) {
...(notice ? { notice } : {}),
};
}
- return { ok: false, error: String(error?.message || error).slice(0, 300) };
+ const notice = inlineCostNotice(error);
+ return { ok: false, error: String(error?.message || error).slice(0, 300), ...(notice ? { notice } : {}) };
} finally {
clearTimeout(timer);
if (jobId && inlineSelectionJobs.get(jobId) === controller) inlineSelectionJobs.delete(jobId);
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index a7191c8fe..9a078aa99 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -2608,6 +2608,23 @@ for (const [label, sourcePath, manualOpen] of [
}
});
+ test(`${label}: an inline error preserves its cost allowance notice`, async (page) => {
+ await setupSelectionShortcut(page, sourcePath, { requiresManualOpen: manualOpen });
+ const notice = 'Cloud cost allowance reached: total cloud/router usage is $5.00 against the $5.00 limit.';
+ await page.evaluate((text) => {
+ window.__selectionInlineHandler = async () => ({
+ ok: false,
+ notice: text,
+ error: 'The provider filtered the response.',
+ });
+ }, notice);
+ await openInlineCard(page, 'explain');
+ const state = await waitForCardStatus(page, 'error');
+ if (state.cardNotice !== notice || state.cardError !== 'The provider filtered the response.') {
+ throw new Error(`an inline error should show its allowance notice: ${JSON.stringify(state)}`);
+ }
+ });
+
test(`${label}: an answer beyond the card limit is cut, flagged and carried whole to the side panel`, async (page) => {
await setupSelectionShortcut(page, sourcePath, { requiresManualOpen: manualOpen });
await page.evaluate(() => {